RANetwork.m 404 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946
  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 "RANetwork.h"
  9. #import "RAUtils.h"
  10. #import "RASingleton.h"
  11. #ifdef GOOGLE_ANALYTICS
  12. #import "GoogleAnalyst.h"
  13. #endif
  14. #import "ERPUtils.h"
  15. #import "RAConvertor.h"
  16. #import "ActiveViewController.h"
  17. #import "ZipArchive.h"
  18. #import "RADataProvider.h"
  19. #import "FileCache.h"
  20. NSString *const kScreenName = @"kScreenName";
  21. NSString *const kAction = @"kAction";
  22. NSString *const kExtra = @"kExtra";
  23. NSString *const ScreenCodeLoginView = @"Login Screen";
  24. NSString *const ScreenCodeHomeView = @"Home Screen";
  25. NSString *const ScreenCodeCategory = @"Category Screen";
  26. NSString *const ScreenCodeCart = @"Cart Sceen";
  27. NSString *const ScreenCodeOrderList = @"Order History Screen";
  28. NSString *const ScreenCodeSearch = @"Search Screen";
  29. NSString *const ScreenCodeAccount = @"Account Screen";
  30. NSString *const ScreenCodeWishList = @"Wish List Screen";
  31. NSString *const ScreenCodePortfolio = @"Portfolio Screen";
  32. NSString *const ScreenCodeViewPortfolios = @"View Portfolios Screen";
  33. NSString *const ScreenCodeCamScan = @"Cam Scan Screen";
  34. NSString *const ScreenCodeScannerSetting = @"Scanner Setting Screen";
  35. NSString *const ScreenCodeOfflineSetting = @"Offline Setting Screen";
  36. NSString *const ScreenCodePlaceOrder = @"Place Order Screen";
  37. NSString *const ScreenCodeCustomerInfo = @"Customer Information Screen";
  38. NSString *const ScreenCodeNewCustomer = @"New Customer Screen";
  39. NSString *const ScreenCodeEditCustomer = @"Edit Customer Information Screen";
  40. NSString *const ScreenCodeModelInfo = @"Model Information Screen";
  41. NSString *const ScreenCodeOrderInfo = @"Order Information Screeen";
  42. NSString *const ScreenCodeUserSign = @"User Sign Screen";
  43. NSString *const ScreenCodeNewAddress = @"New Address Screen";
  44. NSString *const ScreenCodeAdvanceSearch = @"Account Advance Search Screen";
  45. NSString *const ScreenCodeCreatePortfolio = @"Create Portfolio Screen";
  46. NSString *const ScreenCodeParticularCategory = @"Particular Category Screen";
  47. NSString *const ScreenCodeEditPortfolio = @"Edit Portfolio Screen";
  48. NSString *const ScreenCodePriceSetting = @"Price Setting Screen";
  49. NSString *const ScreenCodeCategoryPrice = @"Category Price Screen";
  50. NSString *const ScreenCodeSetCatetoryPrice = @"Set Category Price Screen";
  51. NSString *const ScreenCodeUploadImage = @"Upload Image Screen";
  52. NSString *const ScreenCodeOfflineSync = @"Offline Sync Screen";
  53. @implementation RANetwork
  54. +(NSMutableDictionary*) prepare_additional_params:(NSMutableDictionary* ) params
  55. {
  56. // AppDelegate *appDelegate = nil;
  57. //some UI methods ej
  58. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  59. // if(RASingleton.sharedInstance.user!=nil)
  60. // [params setValue:[AESCrypt AES128Encrypt:RASingleton.sharedInstance.user key:@"usai"] forKey:@"user"];
  61. // if(RASingleton.sharedInstance.password!=nil)
  62. // [params setValue:[AESCrypt AES128Encrypt:RASingleton.sharedInstance.password key:@"usai"] forKey:@"password"];
  63. //
  64. //
  65. //
  66. // if(RASingleton.sharedInstance.user!=nil)
  67. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  68. //
  69. // if(appDelegate.contact_id!=nil)
  70. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  71. // if(RASingleton.sharedInstance.password!=nil)
  72. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  73. //
  74. // [params setValue:RASingleton.sharedInstance.build forKey:@"app_ver"];
  75. //
  76. // NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  77. // NSString* short_version =[infoDict objectForKey:@"CFBundleShortVersionString"];
  78. // [params setValue:short_version forKey:@"app_short_ver"];
  79. //
  80. //
  81. //
  82. //#if TARGET_IPHONE_SIMULATOR//模拟器
  83. // [params setValue:@"simulator_uuid" forKey:@"deviceid"];
  84. //#elif TARGET_OS_IPHONE//真机
  85. // UIDevice * dev = [UIDevice currentDevice];
  86. // NSUUID* uuid =dev.identifierForVendor;
  87. // [params setValue:uuid.UUIDString forKey:@"deviceid"];
  88. //#endif
  89. if(RASingleton.sharedInstance.duid!=nil && params[@"udid"]==nil)
  90. params[@"udid"]=RASingleton.sharedInstance.duid;
  91. #if TARGET_IPHONE_SIMULATOR//模拟器
  92. params[@"udid"]=@"simulator";
  93. #endif
  94. # ifdef DEBUG
  95. [params setValue:@"true" forKey:@"is_debug"];
  96. # endif
  97. if(RASingleton.sharedInstance.user!=nil && params[@"user"]==nil)
  98. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  99. if(RASingleton.sharedInstance.password!=nil&& params[@"password"]==nil)
  100. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  101. if(RASingleton.sharedInstance.ipad_perm!=nil)
  102. [params setValue:RASingleton.sharedInstance.ipad_perm forKey:@"ipad_perm"];
  103. [params setValue:RASingleton.sharedInstance.build forKey:@"app_ver"];
  104. NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  105. NSString* short_version =[infoDict objectForKey:@"CFBundleShortVersionString"];
  106. [params setValue:short_version forKey:@"app_short_ver"];
  107. #if TARGET_IPHONE_SIMULATOR//模拟器
  108. [params setValue:@"simulator_uuid" forKey:@"idfv"];
  109. #elif TARGET_OS_IPHONE//真机
  110. UIDevice * dev = [UIDevice currentDevice];
  111. NSUUID* uuid =dev.identifierForVendor;
  112. [params setValue:uuid.UUIDString forKey:@"idfv"];
  113. #endif
  114. //
  115. // NSString *userAction = [params valueForKey:kAction];
  116. // NSMutableDictionary *extra = [[params valueForKey:kExtra] mutableCopy];
  117. // if ([userAction isEqualToString:@"Login"]) {
  118. // if (!extra) {
  119. // extra = [NSMutableDictionary dictionary];
  120. // }
  121. // [extra setObject:[params objectForKey:@"user"] forKey:@"user"];
  122. // }
  123. return params;
  124. }
  125. +(NSData*)get_json : (NSString*) url parameters:(NSMutableDictionary *) params file:(NSString *) file //delegate:(id < NSURLConnectionDelegate >)delegate
  126. {
  127. // NSString* e=[AESCrypt AES128Encrypt:@"密码学中的高级加密标准(Advanced Encryption Standard,AES),又称 高级加密标准Rijndael加密法,是美国联邦政府采用的一种区块加密标准。这个标准用来替代原先的DES,已经被多方分析且广为全世界所使用。经过五年的甄选流程,高级加密标准由美国国家标准与技术研究院 (NIST)于2001年11月26日发布于FIPS PUB 197,并在2002年5月26日成为有效的标准。2006年,高级加密标准已然成为对称密钥加密中最流行的算法之一。 " key:@"usai2010"];
  128. // DebugLog(e);
  129. // NSString* d=[AESCrypt decrypt:@"VzB4+lENfbzWX7ggHh2Os1P69l5YBzKmM51yqA37AfoKgPY8bJgdK8M4WvF+wDyOsLWP\/o8H5+bHMivQp1u8wM2QV7SYzgzPwV85QKtYWIzEgLe9T0HO69EdutWz7k1rdAT\/mftsRin0Hy5SHk7txTZT\/zPH5X+FQiExCTFm5Zus39HYvp+VxCX4+kYeymn8B63AUd3mRQyscUvDjfgU2olKR\/TP8PV3g+VQMZxpKfol3P1iOtz3XQlHZV0pM6SAf+SwT0sPfrdn6CZFfNQlrKA9QjMrnBdMeSCquSIWXnmLv6okzvnlJnT0SjvJuUeqNdBC5EZ0ACnhI0MrXVZEsq1EuM9al7oPzvU5EZbjZpmx+fSFIkMzTT8bYClTnG1bsL1MCcU4pSODDorUj8zalA==" password:@"usai2010"];
  130. params = [self prepare_additional_params:params];
  131. DebugLog(@"\n++++++++++++++++++++++Request++++++++++++++++++++++\n%@\n++++++++++++++++++++++Params++++++++++++++++++++++\n%@\n",url,[RAConvertor dict2string:params]);
  132. return [super get_json:url parameters:params file:(NSString*)file err_recorder:URL_ERR_LOG result_handler:^NSMutableDictionary *(NSMutableDictionary *jsobj) {
  133. int result=[[jsobj valueForKey:@"result"] intValue];
  134. // UIApplication * app = [UIApplication sharedApplication];
  135. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  136. switch (result) {
  137. case 0:
  138. [jsobj setValue:MSG_USERAUTH_ERROR forKey:@"err_msg"];
  139. break;
  140. case 1:
  141. [jsobj setValue:MSG_ERROR forKey:@"err_msg"];
  142. break;
  143. case 2:
  144. [jsobj setValue:MSG_SUCCESS forKey:@"err_msg"];
  145. break;
  146. case 8:
  147. [jsobj setValue:[jsobj valueForKey:@"msg"] forKey:@"err_msg"];
  148. break;
  149. case 9:
  150. [jsobj setValue:[jsobj valueForKey:@"msg"] forKey:@"err_msg"];
  151. break;
  152. case 99:
  153. [jsobj setValue:MSG_TIMEOUT forKey:@"err_msg"];
  154. break;
  155. default:
  156. [jsobj setValue:MSG_ERROR forKey:@"err_msg"];
  157. break;
  158. }
  159. // if([RASingleton.sharedInstance.build intValue]< [[jsobj valueForKey:@"min_ver"]intValue])
  160. // {
  161. // [jsobj setValue:@"9" forKey:@"result"];
  162. // [jsobj setValue:MSG_VER_LOW forKey:@"err_msg"];
  163. // }
  164. return jsobj;
  165. } decrypt_handler:^NSMutableDictionary *(NSMutableDictionary *jsobj) {
  166. return nil;
  167. // NSString* base64str = jsobj[@"str"];
  168. // NSString* decryptstr=[AESCrypt AES128Decrypt:base64str key:@"usai2010"];
  169. // jsobj=[[RAUtils string2dict:decryptstr] mutableCopy];
  170. // return jsobj;
  171. }];
  172. /*
  173. */
  174. return nil;
  175. }
  176. +(void) LoadImage:(NSString*) url into:(UIImageView*) container
  177. {
  178. DebugLog(@"LoadImage:(NSString*) url in:(UIImageView*) container");
  179. NSString* file_name=[url lastPathComponent];
  180. NSData* img_data = [FileCache load_cached_img:file_name loadFrom:url];
  181. if(img_data==nil)
  182. {
  183. DebugLog(@"IMG NOT CACHED %@",file_name);
  184. img_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
  185. [FileCache cache_img:img_data filename:file_name saveTo:url];
  186. //load from internet;
  187. }
  188. if(img_data!=nil)
  189. {
  190. UIImage * img =[UIImage imageWithData:img_data];
  191. if(img==nil)
  192. DebugLog(@"UIIMAGE IS NIL! %@",file_name);
  193. else
  194. dispatch_async(dispatch_get_main_queue(), ^{
  195. container.image =img;
  196. });
  197. }
  198. else
  199. {
  200. DebugLog(@"IMG DOWNLOAD FAILED! %@",file_name);
  201. }
  202. }
  203. //+(NSData*)fake_json:(NSString*) url
  204. //{
  205. // NSString* jsonfile = nil;
  206. // if([url isEqualToString:URL_UPDATE_AUTH])
  207. // {
  208. // jsonfile=@"login";
  209. //
  210. // }
  211. // else if([url isEqualToString:URL_REQUEST_CATMENU])
  212. // {
  213. // jsonfile=@"categorymenu";
  214. // }
  215. // else if([url isEqualToString:URL_LOAD_HOME])
  216. // {
  217. // jsonfile=@"homepage";
  218. // }
  219. // else if([url isEqualToString:URL_SEARCH])
  220. // {
  221. // jsonfile=@"search";
  222. // }
  223. // else if([url isEqualToString:URL_CATEGORY_LOADMORE])
  224. // {
  225. // jsonfile=@"category_more";
  226. // }else if([url isEqualToString:URL_ITEM_DETAIL])
  227. // {
  228. // jsonfile=@"detail";
  229. // }else if([url isEqualToString:URL_CART])
  230. // {
  231. // jsonfile=@"cart";
  232. // }else if([url isEqualToString:URL_ORDER_LIST])
  233. // {
  234. // jsonfile=@"orderlist";
  235. // }
  236. //// else if([url isEqualToString:URL_ORDER_INFO])
  237. //// {
  238. //// jsonfile=@"orderinfo";
  239. //// }
  240. //// else if([url isEqualToString:URL_ORDER_INFO])
  241. //// {
  242. //// jsonfile=@"orderinfo2label";
  243. //// }
  244. //
  245. //
  246. //
  247. // NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:jsonfile ofType:@"json" ]];
  248. // NSMutableString *result = [[NSMutableString alloc] initWithData:json encoding:NSUTF8StringEncoding];
  249. //
  250. // DebugLog(@"result: \n%@",result);
  251. // return json;
  252. //}
  253. +(NSData*)get_json : (NSString*) url parameters:(NSMutableDictionary *) params //delegate:(id < NSURLConnectionDelegate >)delegate
  254. {
  255. NSString *userAction = [params valueForKey:kAction];
  256. NSMutableDictionary *extra = [[params valueForKey:kExtra] mutableCopy];
  257. if ([userAction isEqualToString:@"Login"]) {
  258. if (!extra) {
  259. extra = [NSMutableDictionary dictionary];
  260. }
  261. [extra setObject:[params objectForKey:@"user"] forKey:@"user"];
  262. }
  263. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)
  264. NSString *screenName = [params valueForKey:kScreenName];
  265. [ERPUtils googleAnalyticsSendRequestString:url WithScreen:screenName Action:userAction Extra:extra];
  266. #endif
  267. return [self get_json:url parameters:params file:nil];
  268. }
  269. //+(NSDictionary*)request_Editor:(NSString*) sourceid editor:(NSString*)editor
  270. //{
  271. //
  272. //}
  273. +(NSDictionary*) delete_portfoliolist:(NSString* ) listid
  274. {
  275. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  276. __block AppDelegate *appDelegate = nil;
  277. dispatch_sync(dispatch_get_main_queue(), ^{
  278. //some UI methods ej
  279. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  280. });
  281. if(RASingleton.sharedInstance.user!=nil)
  282. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  283. if(appDelegate.contact_id!=nil)
  284. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  285. if(RASingleton.sharedInstance.password!=nil)
  286. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  287. [params setValue:listid forKey:@"tearsheetsId"];
  288. // [params setValue:editor forKey:@"editor"];
  289. [params setValue:ScreenCodeViewPortfolios forKey:kScreenName];
  290. // [params setValue:@"Delete Portfolio" forKey:kAction];
  291. NSData* json = nil;
  292. if(appDelegate.offline_mode)
  293. {
  294. json = [OLDataProvider offline_removePDF:params];
  295. } else {
  296. if(![self IsNetworkAvailable])
  297. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  298. json=[self get_json:URL_PORTFOLIOLIST_REMOVE parameters:params];
  299. }
  300. if(json!=nil)
  301. {
  302. NSError *error=nil;
  303. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  304. return jsobj;
  305. }
  306. else
  307. return nil;
  308. }
  309. +(NSDictionary*) portfolio_remove:(NSString* ) item_ids
  310. {
  311. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  312. __block AppDelegate *appDelegate = nil;
  313. dispatch_sync(dispatch_get_main_queue(), ^{
  314. //some UI methods ej
  315. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  316. });
  317. if(RASingleton.sharedInstance.user!=nil)
  318. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  319. if(appDelegate.contact_id!=nil)
  320. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  321. if(RASingleton.sharedInstance.password!=nil)
  322. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  323. [params setValue:item_ids forKey:@"portfolioId"];
  324. // [params setValue:editor forKey:@"editor"];
  325. [params setValue:ScreenCodePortfolio forKey:kScreenName];
  326. NSData* json = nil;
  327. if(appDelegate.offline_mode)
  328. {
  329. json = [OLDataProvider offline_removePortfolio:params];
  330. } else {
  331. if(![self IsNetworkAvailable])
  332. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  333. json=[self get_json:URL_PORTFOLIO_REMOVE parameters:params];
  334. }
  335. if(json!=nil)
  336. {
  337. NSError *error=nil;
  338. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  339. int result = [[jsobj valueForKey:@"result"] intValue];
  340. if (result==2)
  341. {
  342. appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  343. [appDelegate update_count_mark];
  344. }
  345. return jsobj;
  346. }
  347. else
  348. return nil;
  349. }
  350. //+(NSDictionary*) watchlist_remove:(NSString* ) item_ids
  351. //{
  352. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  353. // __block AppDelegate *appDelegate = nil;
  354. //
  355. // dispatch_sync(dispatch_get_main_queue(), ^{
  356. // //some UI methods ej
  357. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  358. // });
  359. // if(RASingleton.sharedInstance.user!=nil)
  360. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  361. // if(appDelegate.contact_id!=nil)
  362. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  363. // if(RASingleton.sharedInstance.password!=nil)
  364. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  365. // [params setValue:item_ids forKey:@"collectId"];
  366. // // [params setValue:editor forKey:@"editor"];
  367. //
  368. // [params setValue:ScreenCodeWishList forKey:kScreenName];
  369. //
  370. // if(appDelegate.offline_mode)
  371. // {
  372. // return [OLDataProvider offline_deletewishlist:params];
  373. // }
  374. // if(![self IsNetworkAvailable])
  375. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  376. //
  377. // NSData* json=[self get_json:URL_WATCHLIST_REMOVE parameters:params];
  378. // if(json!=nil)
  379. // {
  380. // NSError *error=nil;
  381. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  382. // int result = [[jsobj valueForKey:@"result"] intValue];
  383. //
  384. // if (result==2)
  385. // {
  386. //
  387. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  388. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  389. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  390. //
  391. // [appDelegate update_count_mark];
  392. // }
  393. // return jsobj;
  394. // }
  395. // else
  396. // return nil;
  397. //}
  398. //+(NSDictionary*) move_cart2wish:(NSString* ) item_ids
  399. //{
  400. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  401. // __block AppDelegate *appDelegate = nil;
  402. //
  403. // dispatch_sync(dispatch_get_main_queue(), ^{
  404. // //some UI methods ej
  405. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  406. // });
  407. // if(RASingleton.sharedInstance.user!=nil)
  408. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  409. // if(appDelegate.contact_id!=nil)
  410. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  411. // if(RASingleton.sharedInstance.password!=nil)
  412. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  413. // if(appDelegate.order_code!=nil)
  414. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  415. // [params setValue:item_ids forKey:@"cartItemId"];
  416. // // [params setValue:editor forKey:@"editor"];
  417. //
  418. // [params setValue:ScreenCodeCart forKey:kScreenName];
  419. // // [params setValue:@"Cart Move To Wish List" forKey:kAction];
  420. //
  421. // NSData* json = nil;
  422. // if(appDelegate.offline_mode)
  423. // {
  424. // json= [OLDataProvider offline_movecart2wish:params];
  425. // }
  426. // else
  427. // {
  428. // if(![self IsNetworkAvailable])
  429. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  430. //
  431. // json=[self get_json:URL_CART2WISH parameters:params];
  432. // }
  433. // if(json!=nil)
  434. // {
  435. // NSError *error=nil;
  436. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  437. // int result = [[jsobj valueForKey:@"result"] intValue];
  438. //
  439. // if (result==2)
  440. // {
  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. //
  446. // [appDelegate update_count_mark];
  447. // }
  448. // return jsobj;
  449. // }
  450. // else
  451. // return nil;
  452. //}
  453. //+(NSDictionary*) move_wish2cart:(NSString* ) item_ids
  454. //{
  455. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  456. // __block AppDelegate *appDelegate = nil;
  457. //
  458. // dispatch_sync(dispatch_get_main_queue(), ^{
  459. // //some UI methods ej
  460. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  461. // });
  462. // if(RASingleton.sharedInstance.user!=nil)
  463. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  464. // if(appDelegate.contact_id!=nil)
  465. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  466. // if(RASingleton.sharedInstance.password!=nil)
  467. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  468. // if(appDelegate.order_code!=nil)
  469. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  470. // [params setValue:item_ids forKey:@"collectId"];
  471. // // [params setValue:editor forKey:@"editor"];
  472. //
  473. // [params setValue:ScreenCodeWishList forKey:kScreenName];
  474. // [params setValue:@"Move To Cart" forKey:kAction];
  475. //
  476. // NSData *json = nil;
  477. // if(appDelegate.offline_mode)
  478. // {
  479. // json = [OLDataProvider offline_movewish2cart:params];
  480. // } else {
  481. // if(![self IsNetworkAvailable])
  482. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  483. //
  484. // json=[self get_json:URL_WISH2CART parameters:params];
  485. // }
  486. //
  487. // if(json!=nil)
  488. // {
  489. // NSError *error=nil;
  490. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  491. // int result = [[jsobj valueForKey:@"result"] intValue];
  492. //
  493. // if (result==2)
  494. // {
  495. //
  496. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  497. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  498. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  499. //
  500. // [appDelegate update_count_mark];
  501. // }
  502. // return jsobj;
  503. // }
  504. // else
  505. // return nil;
  506. //}
  507. //+(NSDictionary*) cart_remove:(NSString* ) item_ids
  508. //{
  509. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  510. // __block AppDelegate *appDelegate = nil;
  511. //
  512. // dispatch_sync(dispatch_get_main_queue(), ^{
  513. // //some UI methods ej
  514. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  515. // });
  516. // if(RASingleton.sharedInstance.user!=nil)
  517. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  518. // if(appDelegate.contact_id!=nil)
  519. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  520. // if(RASingleton.sharedInstance.password!=nil)
  521. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  522. //
  523. // if(appDelegate.order_code!=nil)
  524. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  525. // [params setValue:item_ids forKey:@"cartItemId"];
  526. // // [params setValue:editor forKey:@"editor"];
  527. //
  528. // [params setValue:ScreenCodeCart forKey:kScreenName];
  529. // // [params setValue:@"" forKey:kAction];
  530. //
  531. // NSData* json=nil;
  532. // if(appDelegate.offline_mode)
  533. // {
  534. // json= [OLDataProvider offline_cartremove:params];
  535. // }
  536. // else
  537. // {
  538. // if(![self IsNetworkAvailable])
  539. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  540. //
  541. // json=[self get_json:URL_CART_REMOVE parameters:params];
  542. // }
  543. // if(json!=nil)
  544. // {
  545. // NSError *error=nil;
  546. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  547. //
  548. // int result = [[jsobj valueForKey:@"result"] intValue];
  549. //
  550. // if (result==2)
  551. // {
  552. //
  553. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  554. //
  555. //
  556. // [appDelegate update_count_mark];
  557. // }
  558. // return jsobj;
  559. // }
  560. // else
  561. // return nil;
  562. //}
  563. //+(NSDictionary*) cart_check:(NSString* ) item_ids
  564. //{
  565. // return nil;
  566. // if(![self IsNetworkAvailable])
  567. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  568. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  569. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  570. // if(RASingleton.sharedInstance.user!=nil)
  571. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  572. // if(appDelegate.contact_id!=nil)
  573. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  574. // if(RASingleton.sharedInstance.password!=nil)
  575. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  576. // [params setValue:item_ids forKey:@"cartItemId"];
  577. // // [params setValue:editor forKey:@"editor"];
  578. // if(appDelegate.offline_mode)
  579. // {
  580. // return [OLDataProvider offline_notimpl];
  581. // }
  582. // NSData* json=[self get_json:URL_CART_CHECK parameters:params];
  583. // if(json!=nil)
  584. // {
  585. // NSError *error=nil;
  586. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  587. // return jsobj;
  588. // }
  589. // else
  590. // return nil;
  591. //}
  592. +(NSDictionary*)create_Address:(NSMutableDictionary*)params
  593. {
  594. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  595. __block AppDelegate *appDelegate = nil;
  596. dispatch_sync(dispatch_get_main_queue(), ^{
  597. //some UI methods ej
  598. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  599. });
  600. if(RASingleton.sharedInstance.user!=nil)
  601. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  602. if(appDelegate.contact_id!=nil)
  603. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  604. if(RASingleton.sharedInstance.password!=nil)
  605. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  606. // [params setValue:sourceid forKey:@"sourceid"];
  607. // [params setValue:editor forKey:@"editor"];
  608. [params setValue:ScreenCodeNewAddress forKey:kScreenName];
  609. NSData* json=nil;
  610. if(appDelegate.offline_mode)
  611. {
  612. json= [OLDataProvider offline_saveaddr:params];
  613. }
  614. else
  615. {
  616. if(![self IsNetworkAvailable])
  617. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  618. json =[self get_json:URL_ADDRESS_SAVE parameters:params];
  619. }
  620. if(json!=nil)
  621. {
  622. NSError *error=nil;
  623. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  624. return jsobj;
  625. }
  626. else
  627. return nil;
  628. }
  629. +(NSDictionary*)copy_Order:(NSString*) order_code
  630. {
  631. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  632. __block AppDelegate *appDelegate = nil;
  633. dispatch_sync(dispatch_get_main_queue(), ^{
  634. //some UI methods ej
  635. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  636. });
  637. if(RASingleton.sharedInstance.user!=nil)
  638. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  639. if(appDelegate.contact_id!=nil)
  640. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  641. if(RASingleton.sharedInstance.password!=nil)
  642. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  643. // NSString* ssaved = @"false";
  644. // if(saved)
  645. // ssaved=@"true";
  646. // [params setValue:@"true" forKey:@"saved"];
  647. [params setValue:order_code forKey:@"code"];
  648. // [params setValue:sourceid forKey:@"sourceid"];
  649. // [params setValue:editor forKey:@"editor"];
  650. [params setValue:ScreenCodeOrderInfo forKey:kScreenName];
  651. NSData* json=nil;
  652. if(appDelegate.offline_mode)
  653. {
  654. json= [OLDataProvider offline_copyorder:params];
  655. }
  656. else
  657. {
  658. if(![self IsNetworkAvailable])
  659. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  660. json=[self get_json:URL_COPY_ORDER parameters:params];
  661. }
  662. if(json!=nil)
  663. {
  664. NSError *error=nil;
  665. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  666. return jsobj;
  667. }
  668. else
  669. return nil;
  670. }
  671. +(NSDictionary*)sign_Order:(NSString*) order_code path:(NSString*)path
  672. {
  673. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  674. __block AppDelegate *appDelegate = nil;
  675. dispatch_sync(dispatch_get_main_queue(), ^{
  676. //some UI methods ej
  677. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  678. });
  679. if(RASingleton.sharedInstance.user!=nil)
  680. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  681. if(appDelegate.contact_id!=nil)
  682. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  683. if(RASingleton.sharedInstance.password!=nil)
  684. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  685. // NSString* ssaved = @"false";
  686. // if(saved)
  687. // ssaved=@"true";
  688. // [params setValue:@"true" forKey:@"saved"];
  689. [params setValue:order_code forKey:@"orderCode"];
  690. [params setValue:path forKey:@"picpath"];
  691. // [params setValue:sourceid forKey:@"sourceid"];
  692. // [params setValue:editor forKey:@"editor"];
  693. [params setValue:ScreenCodeUserSign forKey:kScreenName];
  694. NSData* json=nil;
  695. if(appDelegate.offline_mode)
  696. {
  697. json= [OLDataProvider offline_signorder:params];
  698. }
  699. else
  700. {
  701. if(![self IsNetworkAvailable])
  702. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  703. json=[self get_json:URL_SIGN_ORDER parameters:params];
  704. }
  705. if(json!=nil)
  706. {
  707. NSError *error=nil;
  708. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  709. return jsobj;
  710. }
  711. else
  712. return nil;
  713. }
  714. +(NSDictionary*)commit_Order:(NSString*) order_code //saved:(bool) saved
  715. {
  716. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  717. __block AppDelegate *appDelegate = nil;
  718. dispatch_sync(dispatch_get_main_queue(), ^{
  719. //some UI methods ej
  720. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  721. });
  722. if(RASingleton.sharedInstance.user!=nil)
  723. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  724. if(appDelegate.contact_id!=nil)
  725. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  726. if(RASingleton.sharedInstance.password!=nil)
  727. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  728. // NSString* ssaved = @"false";
  729. // if(saved)
  730. // ssaved=@"true";
  731. [params setValue:@"true" forKey:@"saved"];
  732. [params setValue:order_code forKey:@"orderCode"];
  733. // [params setValue:sourceid forKey:@"sourceid"];
  734. // [params setValue:editor forKey:@"editor"];
  735. [params setValue:ScreenCodePlaceOrder forKey:kScreenName];
  736. NSData* json = nil;
  737. if(appDelegate.offline_mode)
  738. {
  739. json= [OLDataProvider offline_submitorder:params];
  740. }
  741. else
  742. {
  743. if(![self IsNetworkAvailable])
  744. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  745. json=[self get_json:URL_COMMIT_ORDER parameters:params];
  746. }
  747. if(json!=nil)
  748. {
  749. NSError *error=nil;
  750. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  751. return jsobj;
  752. }
  753. else
  754. return nil;
  755. }
  756. //+(NSDictionary*)open_Order:(NSString*) order_code
  757. //{
  758. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  759. // __block AppDelegate *appDelegate = nil;
  760. //
  761. // dispatch_sync(dispatch_get_main_queue(), ^{
  762. // //some UI methods ej
  763. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  764. // });
  765. // if(RASingleton.sharedInstance.user!=nil)
  766. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  767. // // if(appDelegate.contact_id!=nil)
  768. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  769. // if(RASingleton.sharedInstance.password!=nil)
  770. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  771. //
  772. // [params setValue:order_code forKey:@"orderCode"];
  773. // // [params setValue:sourceid forKey:@"sourceid"];
  774. // // [params setValue:editor forKey:@"editor"];
  775. //
  776. // [params setValue:ScreenCodeOrderInfo forKey:kScreenName];
  777. //
  778. // NSData* json=nil;
  779. // if(appDelegate.offline_mode)
  780. // {
  781. // json=[OLDataProvider offline_editorder:params];
  782. //
  783. // }
  784. // else
  785. // {
  786. // if(![self IsNetworkAvailable])
  787. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  788. //
  789. // json=[self get_json:URL_OPEN_ORDER parameters:params];
  790. // }
  791. // if(json!=nil)
  792. // {
  793. // NSError *error=nil;
  794. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  795. // int result = [[jsobj valueForKey:@"result"] intValue];
  796. //
  797. // if (result==2)
  798. // {
  799. //
  800. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  801. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  802. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  803. //
  804. // [appDelegate update_count_mark];
  805. //
  806. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  807. // [Singleton sharedInstance].currentOrderIsMerged = [[jsobj valueForKey:@"is_merged_order"] boolValue];
  808. // }
  809. //
  810. // }
  811. //
  812. // return jsobj;
  813. // }
  814. // else
  815. // return nil;
  816. //}
  817. +(NSDictionary*)delete_Order:(NSString*) order_id
  818. {
  819. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  820. __block AppDelegate *appDelegate = nil;
  821. dispatch_sync(dispatch_get_main_queue(), ^{
  822. //some UI methods ej
  823. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  824. });
  825. if(RASingleton.sharedInstance.user!=nil)
  826. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  827. // if(appDelegate.contact_id!=nil)
  828. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  829. if(RASingleton.sharedInstance.password!=nil)
  830. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  831. [params setValue:order_id forKey:@"orderId"];
  832. // [params setValue:sourceid forKey:@"sourceid"];
  833. // [params setValue:editor forKey:@"editor"];
  834. [params setValue:ScreenCodeOrderList forKey:kScreenName];
  835. if(appDelegate.offline_mode)
  836. {
  837. return [OLDataProvider offline_notimpl];
  838. }
  839. if(![self IsNetworkAvailable])
  840. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  841. NSData* json=[self get_json:URL_DELETE_ORDER parameters:params];
  842. if(json!=nil)
  843. {
  844. NSError *error=nil;
  845. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  846. return jsobj;
  847. }
  848. else
  849. return nil;
  850. }
  851. +(NSDictionary*)cancel_Order:(NSString*) order_id order_code:(NSString*) order_code
  852. {
  853. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  854. __block AppDelegate *appDelegate = nil;
  855. dispatch_sync(dispatch_get_main_queue(), ^{
  856. //some UI methods ej
  857. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  858. });
  859. if(RASingleton.sharedInstance.user!=nil)
  860. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  861. // if(appDelegate.contact_id!=nil)
  862. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  863. if(RASingleton.sharedInstance.password!=nil)
  864. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  865. [params setValue:order_id forKey:@"orderId"];
  866. [params setValue:order_code forKey:@"orderCode"];
  867. // [params setValue:sourceid forKey:@"sourceid"];
  868. // [params setValue:editor forKey:@"editor"];
  869. [params setValue:ScreenCodeOrderList forKey:kScreenName];
  870. NSData* json=nil;
  871. if(appDelegate.offline_mode)
  872. {
  873. json=[OLDataProvider offline_cancelorder:params];
  874. }
  875. else
  876. {
  877. if(![self IsNetworkAvailable])
  878. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  879. json=[self get_json:URL_CANCEL_ORDER parameters:params];
  880. }
  881. if(json!=nil)
  882. {
  883. NSError *error=nil;
  884. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  885. return jsobj;
  886. }
  887. else
  888. return nil;
  889. }
  890. +(NSDictionary*)release_Order:(NSString*) order_code withScreen:(NSString *)screenName
  891. {
  892. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  893. __block AppDelegate *appDelegate = nil;
  894. dispatch_sync(dispatch_get_main_queue(), ^{
  895. //some UI methods ej
  896. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  897. });
  898. if(RASingleton.sharedInstance.user!=nil)
  899. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  900. // if(appDelegate.contact_id!=nil)
  901. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  902. if(RASingleton.sharedInstance.password!=nil)
  903. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  904. [params setValue:order_code forKey:@"orderCode"];
  905. // [params setValue:sourceid forKey:@"sourceid"];
  906. // [params setValue:editor forKey:@"editor"];
  907. if (screenName) {
  908. [params setValue:screenName forKey:kScreenName];
  909. }
  910. NSData* json=nil;
  911. if(appDelegate.offline_mode)
  912. {
  913. json= [OLDataProvider offline_resetorder:params];
  914. }
  915. else
  916. {
  917. if(![self IsNetworkAvailable])
  918. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  919. json=[self get_json:URL_RELEASE_ORDER parameters:params];
  920. }
  921. if(json!=nil)
  922. {
  923. NSError *error=nil;
  924. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  925. if([[jsobj valueForKey:@"result"]intValue]==2)
  926. { [appDelegate SetSo:nil];
  927. appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  928. //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  929. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  930. [appDelegate update_count_mark];
  931. }
  932. return jsobj;
  933. }
  934. else
  935. return nil;
  936. }
  937. +(NSDictionary*)update_OrderCustomer:(NSString*) order_code customerinfo:(NSMutableDictionary*)info
  938. {
  939. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  940. __block AppDelegate *appDelegate = nil;
  941. dispatch_sync(dispatch_get_main_queue(), ^{
  942. //some UI methods ej
  943. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  944. });
  945. if(RASingleton.sharedInstance.user!=nil)
  946. [info setValue:RASingleton.sharedInstance.user forKey:@"user"];
  947. // if(appDelegate.contact_id!=nil)
  948. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  949. if(RASingleton.sharedInstance.password!=nil)
  950. [info setValue:RASingleton.sharedInstance.password forKey:@"password"];
  951. [info setObject:ScreenCodeEditCustomer forKey:kScreenName];
  952. [info setValue:order_code forKey:@"orderCode"];
  953. // [params setValue:sourceid forKey:@"sourceid"];
  954. // [params setValue:editor forKey:@"editor"];
  955. if(appDelegate.offline_mode)
  956. {
  957. return [OLDataProvider offline_notimpl];
  958. }
  959. if(![self IsNetworkAvailable])
  960. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  961. NSData* json=[self get_json:URL_UPDATE_ORDERCUSTOMER parameters:info];
  962. if(json!=nil)
  963. {
  964. NSError *error=nil;
  965. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  966. return jsobj;
  967. }
  968. else
  969. return nil;
  970. }
  971. //+(NSDictionary*)commoneditor_partialrefresh: (NSMutableDictionary*)params url:(NSString*)url
  972. //{
  973. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  974. // __block AppDelegate *appDelegate = nil;
  975. //
  976. // dispatch_sync(dispatch_get_main_queue(), ^{
  977. // //some UI methods ej
  978. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  979. // });
  980. // if(RASingleton.sharedInstance.user!=nil)
  981. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  982. // if(appDelegate.contact_id!=nil)
  983. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  984. // if(RASingleton.sharedInstance.password!=nil)
  985. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  986. //
  987. // // if(appDelegate.order_code!=nil)
  988. // // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  989. //
  990. // // NSDictionary* customerinfo= appDelegate.customerInfo;
  991. // //
  992. // // NSArray* keys=[customerinfo allKeys];
  993. // // for(int i=0;i<keys.count;i++)
  994. // // {
  995. // // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  996. // // }
  997. // //
  998. // // [params setValue:sourceid forKey:@"sourceid"];
  999. // // [params setValue:editor forKey:@"editor"];
  1000. //
  1001. // [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  1002. //
  1003. // if(appDelegate.offline_mode)
  1004. // {
  1005. // params[@"offline_Command"]=url;
  1006. // return [OLDataProvider offline_commoneditor_partialrefresh:params];
  1007. // }
  1008. //
  1009. // if(![self IsNetworkAvailable])
  1010. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1011. //
  1012. // NSData* json=[self get_json:url parameters:params];
  1013. // if(json!=nil)
  1014. // {
  1015. // NSError *error=nil;
  1016. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1017. // if([[jsobj valueForKey:@"result"]intValue]==2)
  1018. // [appDelegate SetSo:nil];
  1019. //
  1020. //
  1021. // return jsobj;
  1022. // }
  1023. // else
  1024. // return nil;
  1025. //}
  1026. +(NSDictionary*)saveandcommit_Order:(NSMutableDictionary*)params
  1027. {
  1028. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1029. __block AppDelegate *appDelegate = nil;
  1030. dispatch_sync(dispatch_get_main_queue(), ^{
  1031. //some UI methods ej
  1032. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1033. });
  1034. if(RASingleton.sharedInstance.user!=nil)
  1035. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  1036. if(appDelegate.contact_id!=nil)
  1037. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1038. if(RASingleton.sharedInstance.password!=nil)
  1039. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  1040. if(appDelegate.order_code!=nil)
  1041. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1042. // NSDictionary* customerinfo= appDelegate.customerInfo;
  1043. //
  1044. // NSArray* keys=[customerinfo allKeys];
  1045. // for(int i=0;i<keys.count;i++)
  1046. // {
  1047. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1048. // }
  1049. //
  1050. // [params setValue:sourceid forKey:@"sourceid"];
  1051. // [params setValue:editor forKey:@"editor"];
  1052. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  1053. NSData* json=nil;
  1054. if(appDelegate.offline_mode)
  1055. {
  1056. json=[OLDataProvider offline_submitorder:params];
  1057. }
  1058. else
  1059. {
  1060. if(![self IsNetworkAvailable])
  1061. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1062. json=[self get_json:URL_COMMIT_ORDER parameters:params];
  1063. }
  1064. if(json!=nil)
  1065. {
  1066. NSError *error=nil;
  1067. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1068. if([[jsobj valueForKey:@"result"]intValue]==2)
  1069. [appDelegate SetSo:nil];
  1070. return jsobj;
  1071. }
  1072. else
  1073. return nil;
  1074. }
  1075. +(NSDictionary*)update_Customer:(NSMutableDictionary*)params
  1076. {
  1077. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1078. __block AppDelegate *appDelegate = nil;
  1079. dispatch_sync(dispatch_get_main_queue(), ^{
  1080. //some UI methods ej
  1081. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1082. });
  1083. if(RASingleton.sharedInstance.user!=nil)
  1084. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  1085. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1086. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1087. // else
  1088. if(appDelegate.contact_id!=nil)
  1089. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1090. if(RASingleton.sharedInstance.password!=nil)
  1091. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  1092. // NSDictionary* customerinfo=nil;
  1093. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  1094. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1095. // else
  1096. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1097. //
  1098. // appDelegate.customerInfo;
  1099. // NSArray* keys=[customerinfo allKeys];
  1100. // for(int i=0;i<keys.count;i++)
  1101. // {
  1102. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1103. // }
  1104. // [params setValue:sourceid forKey:@"sourceid"];
  1105. // [params setValue:editor forKey:@"editor"];
  1106. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  1107. NSData* json=nil;
  1108. if(appDelegate.offline_mode)
  1109. {
  1110. json= [OLDataProvider offline_saveContact:params];
  1111. }
  1112. else
  1113. {
  1114. if(![self IsNetworkAvailable])
  1115. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1116. json=[self get_json:URL_CUSTOMER_UPDATE parameters:params];
  1117. }
  1118. if(json!=nil)
  1119. {
  1120. NSError *error=nil;
  1121. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1122. return jsobj;
  1123. }
  1124. else
  1125. return nil;
  1126. }
  1127. +(NSDictionary*)save_newCustomer:(NSMutableDictionary*)params
  1128. {
  1129. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1130. __block AppDelegate *appDelegate = nil;
  1131. dispatch_sync(dispatch_get_main_queue(), ^{
  1132. //some UI methods ej
  1133. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1134. });
  1135. if(RASingleton.sharedInstance.user!=nil)
  1136. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  1137. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1138. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1139. // else
  1140. if(appDelegate.contact_id!=nil)
  1141. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1142. if(RASingleton.sharedInstance.password!=nil)
  1143. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  1144. // NSDictionary* customerinfo=nil;
  1145. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  1146. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1147. // else
  1148. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1149. //
  1150. // appDelegate.customerInfo;
  1151. // NSArray* keys=[customerinfo allKeys];
  1152. // for(int i=0;i<keys.count;i++)
  1153. // {
  1154. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1155. // }
  1156. // [params setValue:sourceid forKey:@"sourceid"];
  1157. // [params setValue:editor forKey:@"editor"];
  1158. [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
  1159. NSData* json=nil;
  1160. if(appDelegate.offline_mode)
  1161. {
  1162. json= [OLDataProvider offline_saveNewContact:params];
  1163. }
  1164. else
  1165. {
  1166. if(![self IsNetworkAvailable])
  1167. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1168. json=[self get_json:URL_CUSTOMER_SAVE parameters:params];
  1169. }
  1170. if(json!=nil)
  1171. {
  1172. NSError *error=nil;
  1173. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1174. return jsobj;
  1175. }
  1176. else
  1177. return nil;
  1178. }
  1179. +(NSDictionary*)save_Order:(NSMutableDictionary*)params
  1180. {
  1181. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1182. __block AppDelegate *appDelegate = nil;
  1183. dispatch_sync(dispatch_get_main_queue(), ^{
  1184. //some UI methods ej
  1185. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1186. });
  1187. if(RASingleton.sharedInstance.user!=nil)
  1188. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  1189. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1190. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1191. // else
  1192. if(appDelegate.contact_id!=nil)
  1193. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1194. if(RASingleton.sharedInstance.password!=nil)
  1195. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  1196. if(appDelegate.order_code!=nil)
  1197. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1198. // NSDictionary* customerinfo=nil;
  1199. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  1200. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1201. // else
  1202. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1203. //
  1204. // appDelegate.customerInfo;
  1205. // NSArray* keys=[customerinfo allKeys];
  1206. // for(int i=0;i<keys.count;i++)
  1207. // {
  1208. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1209. // }
  1210. // [params setValue:sourceid forKey:@"sourceid"];
  1211. // [params setValue:editor forKey:@"editor"];
  1212. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  1213. NSData* json=nil;
  1214. if(appDelegate.offline_mode)
  1215. {
  1216. json= [OLDataProvider offline_saveorder:params];
  1217. }
  1218. else
  1219. {
  1220. if(![self IsNetworkAvailable])
  1221. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1222. json=[self get_json:URL_SAVE_ORDER parameters:params];
  1223. }
  1224. if(json!=nil)
  1225. {
  1226. NSError *error=nil;
  1227. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1228. NSString *so = [jsobj valueForKey:@"so#"];
  1229. if (so) {
  1230. [appDelegate SetSo:so];
  1231. }
  1232. return jsobj;
  1233. }
  1234. else
  1235. return nil;
  1236. }
  1237. //+(NSDictionary*)request_Editor:(NSString*) request_url params:(NSMutableDictionary*)params
  1238. //{
  1239. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1240. // __block AppDelegate *appDelegate = nil;
  1241. //
  1242. // dispatch_sync(dispatch_get_main_queue(), ^{
  1243. // //some UI methods ej
  1244. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1245. // });
  1246. // if(RASingleton.sharedInstance.user!=nil)
  1247. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  1248. //
  1249. //
  1250. // // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1251. // // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1252. // // else
  1253. //
  1254. // if(appDelegate.contact_id!=nil)
  1255. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1256. // if(RASingleton.sharedInstance.password!=nil)
  1257. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  1258. //
  1259. // if(appDelegate.order_code!=nil)
  1260. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1261. // // [params setValue:sourceid forKey:@"sourceid"];
  1262. // // [params setValue:editor forKey:@"editor"];
  1263. // DebugLog(@"request editor url:%@",request_url);
  1264. //
  1265. //
  1266. // if([request_url isEqualToString:URL_NEW_CUSTOMER])
  1267. // {
  1268. // [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
  1269. // }
  1270. // else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
  1271. // {
  1272. // [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  1273. // }
  1274. // else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
  1275. // {
  1276. // [params setObject:ScreenCodeAdvanceSearch forKey:kScreenName];
  1277. // }
  1278. // else if([request_url isEqualToString:URL_CARTDELIVERY])
  1279. // {
  1280. // [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  1281. // }
  1282. // else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
  1283. // {
  1284. // [params setObject:ScreenCodeNewAddress forKey:kScreenName];
  1285. // }
  1286. // else if ([request_url isEqualToString:URL_DM_PARAMS]){
  1287. // [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  1288. // }
  1289. //
  1290. // NSData* json = nil;
  1291. // if(appDelegate.offline_mode)
  1292. // {
  1293. // if([request_url isEqualToString:URL_NEW_CUSTOMER])
  1294. // {
  1295. // json= [OLDataProvider offline_createContact:params];
  1296. // }
  1297. // else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
  1298. // {
  1299. // json= [OLDataProvider offline_editContact:params];
  1300. // }
  1301. // else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
  1302. // {
  1303. // json= [OLDataProvider offline_contactAdvancedSearch:params];
  1304. // }
  1305. // else if([request_url isEqualToString:URL_CARTDELIVERY])
  1306. // {
  1307. // json= [OLDataProvider offline_placeorder:params];
  1308. // }
  1309. // else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
  1310. // {
  1311. // json= [OLDataProvider offline_addreditor:params];
  1312. // }
  1313. // else if ([request_url isEqualToString:URL_DM_PARAMS]){
  1314. // json = [OLDataProvider offline_createTearSheet:params];
  1315. // }
  1316. //
  1317. // else
  1318. // return [OLDataProvider offline_notimpl];
  1319. // }
  1320. // else
  1321. // {
  1322. // if(![self IsNetworkAvailable])
  1323. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1324. //
  1325. // if([request_url isEqualToString:URL_CARTDELIVERY])
  1326. // {
  1327. // NSError *error=nil;
  1328. //
  1329. // NSString * uuid= [[NSUUID UUID] UUIDString];
  1330. // params[@"resultSerial"]=uuid;
  1331. //
  1332. // for(int i=0;i<150;i++)
  1333. // {
  1334. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  1335. // // result_params[@"resultSerial"]=uuid;
  1336. // json=[self get_json:request_url parameters:params];
  1337. // if(json!=nil)
  1338. // {
  1339. //
  1340. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1341. // if([jsobj[@"result"] intValue]==2 || [jsobj[@"result"] intValue] == 8)
  1342. // {
  1343. // break;
  1344. // }
  1345. // }
  1346. // sleep(2);
  1347. // }
  1348. // }
  1349. // else
  1350. // json =[self get_json:request_url parameters:params];
  1351. // }
  1352. // if(json!=nil)
  1353. // {
  1354. // NSError *error=nil;
  1355. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1356. // return jsobj;
  1357. // }
  1358. // else
  1359. // return nil;
  1360. //}
  1361. //+(NSDictionary*)request_OrderInfo:(NSString*) orderid
  1362. //{
  1363. // if(![self IsNetworkAvailable])
  1364. // return nil;
  1365. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1366. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1367. // if(RASingleton.sharedInstance.user!=nil)
  1368. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  1369. // if(RASingleton.sharedInstance.password!=nil)
  1370. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  1371. // [params setValue:orderid forKey:@"orderid"];
  1372. // NSData* json=[self get_json:URL_ORDER_INFO parameters:params];
  1373. // NSError *error=nil;
  1374. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1375. // return jsobj;
  1376. //}
  1377. +(NSDictionary*)request_OrderList:(int ) offset limit :(int)limit keywords :(NSString* ) keywords status:(NSString*) status_code customer:(NSString*) customer is_merged:(BOOL) isMerged
  1378. {
  1379. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1380. __block AppDelegate *appDelegate = nil;
  1381. dispatch_sync(dispatch_get_main_queue(), ^{
  1382. //some UI methods ej
  1383. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1384. });
  1385. if(RASingleton.sharedInstance.user!=nil)
  1386. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  1387. if(appDelegate.contact_id!=nil)
  1388. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1389. if(RASingleton.sharedInstance.password!=nil)
  1390. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  1391. [params setValue:[NSString stringWithFormat:@"%d",offset ] forKey:@"offset"];
  1392. [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  1393. [params setValue:keywords forKey:@"keyWord"];
  1394. [params setValue:customer forKey:@"customer_filter"];
  1395. [params setValue:[NSNumber numberWithBool:isMerged] forKey:@"isMerged"];
  1396. [params setValue:status_code forKey:@"orderStatus"];
  1397. [params setObject:ScreenCodeOrderList forKey:kScreenName];
  1398. if (keywords) {
  1399. [params setObject:@"Search" forKey:kAction];
  1400. }
  1401. NSData* json=nil;
  1402. if(appDelegate.offline_mode)
  1403. {
  1404. json= [OLDataProvider offline_orderlist:params];
  1405. }
  1406. else
  1407. {
  1408. if(![self IsNetworkAvailable])
  1409. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1410. json=[self get_json:URL_ORDER_LIST parameters:params];
  1411. }
  1412. if(json==nil)
  1413. return nil;
  1414. NSError *error=nil;
  1415. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1416. return jsobj;
  1417. }
  1418. +(NSDictionary*)request_PDFList:(int ) offset limit:(int)limit keywords:(NSString* ) keywords
  1419. {
  1420. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1421. __block AppDelegate *appDelegate = nil;
  1422. dispatch_sync(dispatch_get_main_queue(), ^{
  1423. //some UI methods ej
  1424. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1425. });
  1426. if(RASingleton.sharedInstance.user!=nil)
  1427. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  1428. if(appDelegate.contact_id!=nil)
  1429. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1430. if(RASingleton.sharedInstance.password!=nil)
  1431. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  1432. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  1433. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  1434. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  1435. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  1436. // [params setValue:filter forKey:@"filter"];
  1437. [params setValue:keywords forKey:@"keyWord"];
  1438. [params setValue:[NSString stringWithFormat:@"%d",limit] forKey:@"limit"];
  1439. [params setValue:[NSString stringWithFormat:@"%d",offset] forKey:@"offset"];
  1440. [params setObject:ScreenCodeViewPortfolios forKey:kScreenName];
  1441. if (keywords) {
  1442. [params setObject:@"Search" forKey:kAction];
  1443. }
  1444. NSData* json = nil;
  1445. if(appDelegate.offline_mode)
  1446. {
  1447. json = [OLDataProvider offline_pdfList:params];
  1448. } else {
  1449. if(![self IsNetworkAvailable])
  1450. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1451. json=[self get_json:URL_DM_LIST parameters:params];
  1452. }
  1453. if(json==nil)
  1454. return nil;
  1455. NSError *error=nil;
  1456. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1457. return jsobj;
  1458. }
  1459. +(NSDictionary*)err_log:(NSString*) up_params result:(NSString*)result module:(NSString*) module code:(int) code//device:(NSString*) device
  1460. {
  1461. #ifdef ERR_LOG
  1462. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1463. __block AppDelegate *appDelegate = nil;
  1464. dispatch_sync(dispatch_get_main_queue(), ^{
  1465. //some UI methods ej
  1466. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1467. });
  1468. if(RASingleton.sharedInstance.user!=nil)
  1469. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  1470. [params setValue:up_params forKey:@"upparam"];
  1471. [params setValue:[NSNumber numberWithInt:code ] forKey:@"code"];
  1472. [params setValue:result forKey:@"result"];
  1473. [params setValue:module forKey:@"interfac"];
  1474. [params setValue:[RAUtils base64en:[RAConvertor dict2string: [RAUtils device_info]]] forKey:@"device"];
  1475. // [params setValue:module forKey:@"module"];
  1476. // [[UIDevice currentDevice] name];
  1477. // if(appDelegate.offline_mode)
  1478. // {
  1479. // return [OLDataProvider offline_notimpl];
  1480. // }
  1481. if(![self IsNetworkAvailable])
  1482. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1483. NSData* json=[self get_json:URL_ERR_LOG parameters:params];
  1484. if(json==nil)
  1485. return nil;
  1486. NSError *error=nil;
  1487. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1488. return jsobj;
  1489. #else
  1490. return nil;
  1491. #endif
  1492. }
  1493. //+(NSDictionary*)request_ContactList:(int) offset limit:(int)limit keywords:(NSString*) keywords type:(NSString*) contact_type adv_search:(NSDictionary*)upparams
  1494. //{
  1495. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1496. //
  1497. // if(upparams!=nil)
  1498. // params = [upparams mutableCopy];
  1499. // __block AppDelegate *appDelegate = nil;
  1500. //
  1501. // dispatch_sync(dispatch_get_main_queue(), ^{
  1502. // //some UI methods ej
  1503. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1504. // });
  1505. // if(RASingleton.sharedInstance.user!=nil)
  1506. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  1507. //
  1508. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1509. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1510. // else
  1511. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1512. //
  1513. // if(RASingleton.sharedInstance.password!=nil)
  1514. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  1515. //
  1516. // [params setValue:[NSString stringWithFormat:@"%d",offset ] forKey:@"offset"];
  1517. // [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  1518. // [params setValue:contact_type forKey:@"contactType"];
  1519. // [params setValue:keywords forKey:@"keyword"];
  1520. //
  1521. // [params setObject:ScreenCodeAccount forKey:kScreenName];
  1522. // if (keywords) {
  1523. // [params setObject:@"Search" forKey:kAction];
  1524. // }
  1525. // if (upparams) {
  1526. // [params setObject:@"Advance Search" forKey:kAction];
  1527. // }
  1528. //
  1529. // NSString* url=nil;
  1530. // if([contact_type isEqualToString:@"Sales_Order_Ship_To"])
  1531. // url=URL_SHIPTO_LIST;
  1532. // else
  1533. // url=URL_CONTACT_LIST;
  1534. //
  1535. // if(appDelegate.offline_mode)
  1536. // return [OLDataProvider offline_contactlist:params];
  1537. //
  1538. // if(![self IsNetworkAvailable])
  1539. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1540. //
  1541. // NSData* json=[self get_json:url parameters:params];
  1542. // if(json==nil)
  1543. // return nil;
  1544. // NSError *error=nil;
  1545. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1546. // return jsobj;
  1547. //}
  1548. //+(NSDictionary*)request_OrderDetail:(NSMutableDictionary *) params
  1549. //{
  1550. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1551. // if (params == nil) {
  1552. // params = [[NSMutableDictionary alloc] init];
  1553. // }
  1554. // __block AppDelegate *appDelegate = nil;
  1555. //
  1556. // dispatch_sync(dispatch_get_main_queue(), ^{
  1557. // //some UI methods ej
  1558. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1559. // });
  1560. // if(RASingleton.sharedInstance.user!=nil)
  1561. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  1562. // if(appDelegate.contact_id!=nil)
  1563. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1564. // if(RASingleton.sharedInstance.password!=nil)
  1565. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  1566. //
  1567. //
  1568. // // [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  1569. //
  1570. // [params setObject:ScreenCodeOrderInfo forKey:kScreenName];
  1571. //
  1572. // NSData* json=nil;
  1573. // if(appDelegate.offline_mode)
  1574. // {
  1575. // json= [OLDataProvider offline_orderdetail:params];
  1576. // }
  1577. // else
  1578. // {
  1579. // if(![self IsNetworkAvailable])
  1580. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1581. //
  1582. // NSError *error=nil;
  1583. //
  1584. // NSString * uuid= [[NSUUID UUID] UUIDString];
  1585. // params[@"resultSerial"]=uuid;
  1586. //
  1587. // for(int i=0;i<150;i++)
  1588. // {
  1589. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  1590. // // result_params[@"resultSerial"]=uuid;
  1591. // json=[self get_json:URL_ORDER_DETAIL parameters:params];
  1592. // if(json!=nil)
  1593. // {
  1594. //
  1595. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1596. // int resultCode = [jsobj[@"result"] intValue];
  1597. // if(resultCode==2 || resultCode == 8)
  1598. // {
  1599. // break;
  1600. // }
  1601. // }
  1602. // sleep(2);
  1603. // }
  1604. //
  1605. //
  1606. // }
  1607. // if(json==nil)
  1608. // return nil;
  1609. // NSError *error=nil;
  1610. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1611. // return jsobj;
  1612. //}
  1613. //+(NSDictionary*) add_toCart:(NSString* ) item_id count:(int) count name:(NSString *)name
  1614. //{
  1615. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1616. // __block AppDelegate *appDelegate = nil;
  1617. //
  1618. // dispatch_sync(dispatch_get_main_queue(), ^{
  1619. // //some UI methods ej
  1620. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1621. // });
  1622. // if(RASingleton.sharedInstance.user!=nil)
  1623. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  1624. // if(appDelegate.contact_id!=nil)
  1625. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1626. // if(RASingleton.sharedInstance.password!=nil)
  1627. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  1628. //
  1629. // if(appDelegate.order_code!=nil)
  1630. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1631. // [params setValue:item_id forKey:@"product_id"];
  1632. // [params setValue:[NSString stringWithFormat:@"%d",count] forKey:@"count"];
  1633. //
  1634. // [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  1635. // [params setObject:@"Add To Cart" forKey:kAction];
  1636. // if (name) {
  1637. // NSDictionary *extra = @{@"ModelName" : name,@"Count" : @(count)};
  1638. // [params setObject:extra forKey:kExtra];
  1639. // }
  1640. //
  1641. // NSDictionary* customerinfo= appDelegate.customerInfo;
  1642. //
  1643. // NSArray* keys=[customerinfo allKeys];
  1644. // for(int i=0;i<keys.count;i++)
  1645. // {
  1646. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1647. // }
  1648. //
  1649. // NSData* json=nil;
  1650. // if(appDelegate.offline_mode)
  1651. // {
  1652. // json=[OLDataProvider offline_add2cart:params];
  1653. // }
  1654. // else
  1655. // {
  1656. // if(![self IsNetworkAvailable])
  1657. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1658. //
  1659. // json=[self get_json:URL_ADD_TO_CART parameters:params];
  1660. // }
  1661. // if(json==nil)
  1662. // return nil;
  1663. // NSError *error=nil;
  1664. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1665. //
  1666. //
  1667. //
  1668. // int result = [[jsobj valueForKey:@"result"] intValue];
  1669. //
  1670. // if (result==2)
  1671. // {
  1672. //
  1673. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  1674. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  1675. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  1676. //
  1677. // [appDelegate update_count_mark];
  1678. // }
  1679. //
  1680. // return jsobj;
  1681. //}
  1682. //+(NSDictionary*) add_toCart_byName:(NSString* ) model_name withScreen:(NSString *)screenName
  1683. //{
  1684. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1685. // __block AppDelegate *appDelegate = nil;
  1686. //
  1687. // dispatch_sync(dispatch_get_main_queue(), ^{
  1688. // //some UI methods ej
  1689. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1690. // });
  1691. // if(RASingleton.sharedInstance.user!=nil)
  1692. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  1693. // if(appDelegate.contact_id!=nil)
  1694. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1695. // if(RASingleton.sharedInstance.password!=nil)
  1696. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  1697. //
  1698. // if(appDelegate.order_code!=nil)
  1699. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1700. // [params setValue:model_name forKey:@"product_name"];
  1701. // [params setValue:[NSString stringWithFormat:@"%d",-1] forKey:@"count"];
  1702. //
  1703. // [params setObject:screenName forKey:kScreenName];
  1704. // [params setObject:@"Add To Cart" forKey:kAction];
  1705. // if (!model_name) {
  1706. // model_name = @"";
  1707. // }
  1708. // [params setObject:@{@"ModelName" : model_name} forKey:kExtra];
  1709. //
  1710. // NSDictionary* customerinfo= appDelegate.customerInfo;
  1711. //
  1712. // NSArray* keys=[customerinfo allKeys];
  1713. // for(int i=0;i<keys.count;i++)
  1714. // {
  1715. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1716. // }
  1717. // NSData* json=nil;
  1718. // if(appDelegate.offline_mode)
  1719. // {
  1720. // json= [OLDataProvider offline_add2cartbyname:params];
  1721. // }
  1722. // else
  1723. // {
  1724. // if(![self IsNetworkAvailable])
  1725. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1726. //
  1727. // json=[self get_json:URL_ADD_TO_CART parameters:params];
  1728. // }
  1729. // if(json==nil)
  1730. // return nil;
  1731. // NSError *error=nil;
  1732. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1733. //
  1734. //
  1735. //
  1736. // int result = [[jsobj valueForKey:@"result"] intValue];
  1737. //
  1738. // if (result==2||result==8)
  1739. // {
  1740. //
  1741. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  1742. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  1743. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  1744. //
  1745. // [appDelegate update_count_mark];
  1746. // }
  1747. //
  1748. // return jsobj;
  1749. //}
  1750. //+(NSDictionary*) new_Customer
  1751. //{
  1752. // if(![self IsNetworkAvailable])
  1753. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1754. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1755. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1756. // if(RASingleton.sharedInstance.user!=nil)
  1757. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  1758. //// if(appDelegate.contact_id!=nil)
  1759. //// [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1760. // if(RASingleton.sharedInstance.password!=nil)
  1761. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  1762. //
  1763. //// if(appDelegate.order_code!=nil)
  1764. //// [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1765. //
  1766. //
  1767. // NSDictionary* customerinfo= appDelegate.customerInfo;
  1768. //
  1769. // NSArray* keys=[customerinfo allKeys];
  1770. // for(int i=0;i<keys.count;i++)
  1771. // {
  1772. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1773. // }
  1774. //
  1775. // NSData* json=[self get_json:URL_CUSTOMER_EDIT parameters:params];
  1776. // if(json==nil)
  1777. // return nil;
  1778. // NSError *error=nil;
  1779. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1780. // return jsobj;
  1781. //}
  1782. //+(NSDictionary*) new_Order
  1783. //{
  1784. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1785. // __block AppDelegate *appDelegate = nil;
  1786. //
  1787. // dispatch_sync(dispatch_get_main_queue(), ^{
  1788. // //some UI methods ej
  1789. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1790. // });
  1791. // if(RASingleton.sharedInstance.user!=nil)
  1792. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  1793. // if(appDelegate.contact_id!=nil)
  1794. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1795. // if(RASingleton.sharedInstance.password!=nil)
  1796. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  1797. //
  1798. // if(appDelegate.order_code!=nil)
  1799. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1800. //
  1801. //
  1802. // [params setObject:ScreenCodeOrderList forKey:kScreenName];
  1803. //
  1804. // NSDictionary* customerinfo= appDelegate.customerInfo;
  1805. //
  1806. // NSArray* keys=[customerinfo allKeys];
  1807. // for(int i=0;i<keys.count;i++)
  1808. // {
  1809. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1810. // }
  1811. //
  1812. // NSData* json = nil;
  1813. // if(appDelegate.offline_mode)
  1814. // {
  1815. // json= [OLDataProvider offline_createorder:params];
  1816. // }
  1817. // else
  1818. // {
  1819. // if(![self IsNetworkAvailable])
  1820. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1821. //
  1822. // json=[self get_json:URL_NEW_ORDER parameters:params];
  1823. // }
  1824. // if(json==nil)
  1825. // return nil;
  1826. // NSError *error=nil;
  1827. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1828. // int result = [[jsobj valueForKey:@"result"] intValue];
  1829. //
  1830. // if (result==2)
  1831. // {
  1832. //
  1833. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  1834. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  1835. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  1836. //
  1837. // [appDelegate update_count_mark];
  1838. // }
  1839. //
  1840. // [appDelegate SetSo:[jsobj valueForKey:@"soId"]];
  1841. //
  1842. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  1843. // [Singleton sharedInstance].currentOrderIsMerged = NO;
  1844. // }
  1845. //
  1846. // return jsobj;
  1847. //}
  1848. +(NSDictionary*) add_toPortfolio:(NSString* ) item_id withScreen:(NSString *)screenName
  1849. {
  1850. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1851. __block AppDelegate *appDelegate = nil;
  1852. dispatch_sync(dispatch_get_main_queue(), ^{
  1853. //some UI methods ej
  1854. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1855. });
  1856. if(RASingleton.sharedInstance.user!=nil)
  1857. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  1858. if(appDelegate.contact_id!=nil)
  1859. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1860. if(RASingleton.sharedInstance.password!=nil)
  1861. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  1862. [params setValue:item_id forKey:@"product_id"];
  1863. [params setObject:screenName forKey:kScreenName];
  1864. NSData* json = nil;
  1865. if(appDelegate.offline_mode)
  1866. {
  1867. json = [OLDataProvider offline_add2Portfolio:params];
  1868. } else {
  1869. if(![self IsNetworkAvailable])
  1870. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1871. json=[self get_json:URL_ADD_TO_PORTFOLIO parameters:params];
  1872. }
  1873. if(json==nil)
  1874. return nil;
  1875. NSError *error=nil;
  1876. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1877. int result = [[jsobj valueForKey:@"result"] intValue];
  1878. if (result==2)
  1879. {
  1880. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  1881. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  1882. appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  1883. [appDelegate update_count_mark];
  1884. }
  1885. return jsobj;
  1886. }
  1887. //+(NSDictionary*) add_toWatchList:(NSString* ) item_id withScreen:(NSString *)screenName
  1888. //{
  1889. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1890. // __block AppDelegate *appDelegate = nil;
  1891. //
  1892. // dispatch_sync(dispatch_get_main_queue(), ^{
  1893. // //some UI methods ej
  1894. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1895. // });
  1896. // if(RASingleton.sharedInstance.user!=nil)
  1897. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  1898. // if(appDelegate.contact_id!=nil)
  1899. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1900. // if(RASingleton.sharedInstance.password!=nil)
  1901. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  1902. //
  1903. //
  1904. // [params setValue:item_id forKey:@"product_id"];
  1905. //
  1906. // [params setObject:screenName forKey:kScreenName];
  1907. //
  1908. // if(appDelegate.offline_mode)
  1909. // {
  1910. // return [OLDataProvider offline_add2wishlist:params];
  1911. // }
  1912. // if(![self IsNetworkAvailable])
  1913. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1914. //
  1915. // NSData* json=[self get_json:URL_ADD_TO_WATCHLIST parameters:params];
  1916. // if(json==nil)
  1917. // return nil;
  1918. // NSError *error=nil;
  1919. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1920. // int result = [[jsobj valueForKey:@"result"] intValue];
  1921. //
  1922. // if (result==2)
  1923. // {
  1924. //
  1925. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  1926. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  1927. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  1928. //
  1929. // [appDelegate update_count_mark];
  1930. // }
  1931. // return jsobj;
  1932. //}
  1933. //+(NSDictionary*) cart_setPrice:(NSString*) cart_id price:(float) price discount:(float) discount notes:(NSString*) notes
  1934. //{
  1935. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1936. // __block AppDelegate *appDelegate = nil;
  1937. //
  1938. // dispatch_sync(dispatch_get_main_queue(), ^{
  1939. // //some UI methods ej
  1940. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1941. // });
  1942. // if(RASingleton.sharedInstance.user!=nil)
  1943. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  1944. // if(appDelegate.contact_id!=nil)
  1945. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1946. // if(RASingleton.sharedInstance.password!=nil)
  1947. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  1948. //
  1949. // [params setValue:cart_id forKey:@"cartitem_id"];
  1950. // [params setValue:notes forKey:@"item_note"];
  1951. //
  1952. // [params setValue:[NSString stringWithFormat:@"%f",price] forKey:@"price"];
  1953. //
  1954. // [params setValue:[NSString stringWithFormat:@"%f",discount] forKey:@"discount"];
  1955. //
  1956. // [params setObject:ScreenCodeCart forKey:kScreenName];
  1957. //
  1958. // NSData* json= nil;
  1959. // if(appDelegate.offline_mode)
  1960. // {
  1961. // json=[OLDataProvider offline_cartsetprice:params];
  1962. // }
  1963. // else
  1964. // {
  1965. // if(![self IsNetworkAvailable])
  1966. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1967. //
  1968. // json=[self get_json:URL_CART_SET_PRICE parameters:params];
  1969. // }
  1970. // if(json==nil)
  1971. // return nil;
  1972. // NSError *error=nil;
  1973. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1974. // return jsobj;
  1975. //}
  1976. //+(NSDictionary*) portfolio_setQTY:(NSString*) watchlist_id QTY:(int)qty
  1977. //{
  1978. // if(![self IsNetworkAvailable])
  1979. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1980. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1981. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1982. // if(RASingleton.sharedInstance.user!=nil)
  1983. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  1984. // if(appDelegate.contact_id!=nil)
  1985. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1986. // if(RASingleton.sharedInstance.password!=nil)
  1987. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  1988. //
  1989. // [params setValue:watchlist_id forKey:@"item_id"];
  1990. //
  1991. // [params setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"available_qty"];
  1992. //
  1993. //
  1994. //
  1995. // NSData* json=[self get_json:URL_DM_SET_QTY parameters:params];
  1996. // if(json==nil)
  1997. // return nil;
  1998. // NSError *error=nil;
  1999. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2000. // return jsobj;
  2001. //}
  2002. +(NSDictionary*) portfolio_setPrice:(NSString*) watchlist_id price:(float) price discount:(float) discount QTY:(int)qty qty_p:(float) qty_p notes:(NSString*)notes
  2003. {
  2004. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2005. __block AppDelegate *appDelegate = nil;
  2006. dispatch_sync(dispatch_get_main_queue(), ^{
  2007. //some UI methods ej
  2008. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2009. });
  2010. if(RASingleton.sharedInstance.user!=nil)
  2011. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  2012. if(appDelegate.contact_id!=nil)
  2013. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2014. if(RASingleton.sharedInstance.password!=nil)
  2015. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  2016. [params setValue:watchlist_id forKey:@"item_id"];
  2017. // if(notes.length>0)
  2018. // [params setValue:notes forKey:@"notes"];
  2019. if(notes)
  2020. [params setValue:notes forKey:@"notes"];
  2021. if(price != -MAXFLOAT)
  2022. [params setValue:[NSString stringWithFormat:@"%f",price] forKey:@"price"];
  2023. if (discount != -MAXFLOAT)
  2024. [params setValue:[NSString stringWithFormat:@"%f",discount] forKey:@"discount"];
  2025. if(qty_p != -MAXFLOAT)
  2026. [params setValue:[NSString stringWithFormat:@"%f",qty_p] forKey:@"available_percent"];
  2027. if(qty != -INT32_MAX)
  2028. [params setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"available_qty"];
  2029. [params setObject:ScreenCodePortfolio forKey:kScreenName];
  2030. NSData* json = nil;
  2031. if(appDelegate.offline_mode)
  2032. {
  2033. json = [OLDataProvider offline_editPortfolio:params];
  2034. } else {
  2035. if(![self IsNetworkAvailable])
  2036. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2037. json = [self get_json:URL_PORTFOLIO_SET_PRICE parameters:params];
  2038. }
  2039. if(json==nil)
  2040. return nil;
  2041. NSError *error=nil;
  2042. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2043. return jsobj;
  2044. }
  2045. //+(NSDictionary*) cart_setGeneralNote:(NSString*) order_code notes:(NSString*) notes
  2046. //{
  2047. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2048. // __block AppDelegate *appDelegate = nil;
  2049. //
  2050. // dispatch_sync(dispatch_get_main_queue(), ^{
  2051. // //some UI methods ej
  2052. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2053. // });
  2054. // if(RASingleton.sharedInstance.user!=nil)
  2055. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  2056. // if(appDelegate.contact_id!=nil)
  2057. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2058. // if(RASingleton.sharedInstance.password!=nil)
  2059. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  2060. //
  2061. // [params setValue:order_code forKey:@"orderCode"];
  2062. //
  2063. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2064. //
  2065. // if(notes.length==0)
  2066. // notes=@"";
  2067. //
  2068. //
  2069. // [params setValue:notes forKey:@"comments"];
  2070. // NSData* json=nil;
  2071. // if(appDelegate.offline_mode)
  2072. // {
  2073. // json= [OLDataProvider offline_updategnotes:params];
  2074. // }
  2075. // else
  2076. // {
  2077. // if(![self IsNetworkAvailable])
  2078. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2079. //
  2080. // json=[self get_json:URL_CART_GENERAL_NOTES parameters:params];
  2081. // }
  2082. // if(json==nil)
  2083. // return nil;
  2084. // NSError *error=nil;
  2085. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2086. // return jsobj;
  2087. //}
  2088. //+(NSDictionary*) cart_setItemNote:(NSString*) cart_id notes:(NSString*) notes
  2089. //{
  2090. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2091. // __block AppDelegate *appDelegate = nil;
  2092. //
  2093. // dispatch_sync(dispatch_get_main_queue(), ^{
  2094. // //some UI methods ej
  2095. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2096. // });
  2097. // if(RASingleton.sharedInstance.user!=nil)
  2098. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  2099. // if(appDelegate.contact_id!=nil)
  2100. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2101. // if(RASingleton.sharedInstance.password!=nil)
  2102. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  2103. //
  2104. // [params setValue:cart_id forKey:@"cartitem_id"];
  2105. //
  2106. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2107. //
  2108. // if(notes.length==0)
  2109. // notes=@"";
  2110. //
  2111. //
  2112. // [params setValue:notes forKey:@"notes"];
  2113. // NSData* json=nil;
  2114. // if(appDelegate.offline_mode)
  2115. // {
  2116. // json= [OLDataProvider offline_cartsetlnotes:params];
  2117. // }
  2118. // else
  2119. // {
  2120. // if(![self IsNetworkAvailable])
  2121. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2122. //
  2123. // json=[self get_json:URL_CART_ITEM_NOTES parameters:params];
  2124. // }
  2125. // if(json==nil)
  2126. // return nil;
  2127. // NSError *error=nil;
  2128. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2129. // return jsobj;
  2130. //}
  2131. //+(NSDictionary*) cart_setFree:(NSString*) cart_id isfree:(bool) isfree
  2132. //{
  2133. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2134. // __block AppDelegate *appDelegate = nil;
  2135. //
  2136. // dispatch_sync(dispatch_get_main_queue(), ^{
  2137. // //some UI methods ej
  2138. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2139. // });
  2140. // if(RASingleton.sharedInstance.user!=nil)
  2141. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  2142. // if(appDelegate.contact_id!=nil)
  2143. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2144. // if(RASingleton.sharedInstance.password!=nil)
  2145. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  2146. //
  2147. // [params setValue:cart_id forKey:@"cartitem_id"];
  2148. //
  2149. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2150. //
  2151. // NSString* free=nil;
  2152. //
  2153. // if(isfree)
  2154. // free=@"true";
  2155. // else
  2156. // free=@"false";
  2157. //
  2158. // [params setValue:free forKey:@"free_giveaway"];
  2159. //
  2160. // if(appDelegate.offline_mode)
  2161. // {
  2162. // return [OLDataProvider offline_notimpl];
  2163. // }
  2164. // if(![self IsNetworkAvailable])
  2165. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2166. //
  2167. // NSData* json=[self get_json:URL_CART_SET_PRICE parameters:params];
  2168. // if(json==nil)
  2169. // return nil;
  2170. // NSError *error=nil;
  2171. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2172. // return jsobj;
  2173. //}
  2174. //+(NSDictionary*) cart_setQTY:(NSString*) cart_id value:(int) value
  2175. //{
  2176. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2177. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2178. // if(RASingleton.sharedInstance.user!=nil)
  2179. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  2180. // if(appDelegate.contact_id!=nil)
  2181. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2182. // if(RASingleton.sharedInstance.password!=nil)
  2183. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  2184. //
  2185. // [params setValue:cart_id forKey:@"cartitem_id"];
  2186. //
  2187. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2188. //
  2189. // [params setValue:[NSString stringWithFormat:@"%d",value] forKey:@"inputInt"];
  2190. //
  2191. // NSData* json=nil;
  2192. // if(appDelegate.offline_mode)
  2193. // {
  2194. // json= [OLDataProvider offline_cartsetqty:params];
  2195. // }
  2196. // else
  2197. // {
  2198. // if(![self IsNetworkAvailable])
  2199. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2200. //
  2201. // json=[self get_json:URL_CART_INCRESEMENT parameters:params];
  2202. // }
  2203. // if(json==nil)
  2204. // return nil;
  2205. // NSError *error=nil;
  2206. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2207. // return jsobj;
  2208. //
  2209. //}
  2210. //+(NSDictionary*) cart_incresement:(NSString*) cart_id increse:(bool) increse
  2211. //{
  2212. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2213. // __block AppDelegate *appDelegate = nil;
  2214. //
  2215. // dispatch_sync(dispatch_get_main_queue(), ^{
  2216. // //some UI methods ej
  2217. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2218. // });
  2219. // if(RASingleton.sharedInstance.user!=nil)
  2220. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  2221. // if(appDelegate.contact_id!=nil)
  2222. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2223. // if(RASingleton.sharedInstance.password!=nil)
  2224. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  2225. //
  2226. // [params setValue:cart_id forKey:@"cartitem_id"];
  2227. //
  2228. // if(increse)
  2229. // [params setValue:@"1" forKey:@"incrementType"];
  2230. // else
  2231. // [params setValue:@"0" forKey:@"incrementType"];
  2232. //
  2233. //
  2234. //
  2235. // if(appDelegate.offline_mode)
  2236. // {
  2237. // return [OLDataProvider offline_notimpl];
  2238. // }
  2239. // if(![self IsNetworkAvailable])
  2240. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2241. //
  2242. // NSData* json=[self get_json:URL_CART_INCRESEMENT parameters:params];
  2243. // if(json==nil)
  2244. // return nil;
  2245. // NSError *error=nil;
  2246. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2247. // return jsobj;
  2248. //}
  2249. +(NSDictionary*) finish_download_Offline:(NSString* )vid
  2250. {
  2251. if(![self IsNetworkAvailable])
  2252. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2253. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2254. [params setObject:ScreenCodeOfflineSetting forKey:kScreenName];
  2255. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2256. // if(RASingleton.sharedInstance.user!=nil)
  2257. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  2258. // // if(appDelegate.contact_id!=nil)
  2259. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2260. // if(RASingleton.sharedInstance.password!=nil)
  2261. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  2262. [params setValue:vid forKey:@"downSerial"];
  2263. NSData* json=[self get_json:URL_FINISH_DOWNLOAD_OFFLINE parameters:params];
  2264. if(json==nil)
  2265. return nil;
  2266. NSError *error=nil;
  2267. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2268. // int result = [[jsobj valueForKey:@"result"] intValue];
  2269. //
  2270. // if (result==2)
  2271. // {
  2272. //
  2273. //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2274. //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2275. //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2276. ////
  2277. //// [appDelegate update_count_mark];
  2278. // }
  2279. return jsobj;
  2280. }
  2281. +(NSDictionary*) download_Offline:(NSString* )vid
  2282. {
  2283. if(![self IsNetworkAvailable])
  2284. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2285. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2286. [params setObject:ScreenCodeOfflineSync forKey:kScreenName];
  2287. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2288. // if(RASingleton.sharedInstance.user!=nil)
  2289. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  2290. // // if(appDelegate.contact_id!=nil)
  2291. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2292. // if(RASingleton.sharedInstance.password!=nil)
  2293. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  2294. [params setValue:vid forKey:@"downSerial"];
  2295. NSData* json=[self get_json:URL_DOWNLOAD_OFFLINE parameters:params];
  2296. if(json==nil)
  2297. return nil;
  2298. NSError *error=nil;
  2299. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2300. // int result = [[jsobj valueForKey:@"result"] intValue];
  2301. //
  2302. // if (result==2)
  2303. // {
  2304. //
  2305. //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2306. //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2307. //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2308. ////
  2309. //// [appDelegate update_count_mark];
  2310. // }
  2311. return jsobj;
  2312. }
  2313. +(NSDictionary*) check_Offline:(NSString* )ver useInternalAddress:(bool)buseinternaladdress vid:(NSString*)vid
  2314. {
  2315. if(![self IsNetworkAvailable])
  2316. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2317. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2318. __block AppDelegate *appDelegate = nil;
  2319. dispatch_sync(dispatch_get_main_queue(), ^{
  2320. //some UI methods ej
  2321. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2322. });
  2323. if(RASingleton.sharedInstance.user!=nil)
  2324. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  2325. // if(appDelegate.contact_id!=nil)
  2326. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2327. if(RASingleton.sharedInstance.password!=nil)
  2328. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  2329. [params setValue:ver forKey:@"ver"];
  2330. [params setValue:vid forKey:@"vid"];
  2331. if(buseinternaladdress)
  2332. [params setValue:@"true" forKey:@"internal_address"];
  2333. else
  2334. [params setValue:@"false" forKey:@"internal_address"];
  2335. [params setObject:ScreenCodeOfflineSync forKey:kScreenName];
  2336. NSData* json=[self get_json:URL_CHECK_OFFLINE parameters:params];
  2337. if(json==nil)
  2338. return nil;
  2339. NSError *error=nil;
  2340. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2341. // int result = [[jsobj valueForKey:@"result"] intValue];
  2342. //
  2343. // if (result==2)
  2344. // {
  2345. //
  2346. //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2347. //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2348. //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2349. ////
  2350. //// [appDelegate update_count_mark];
  2351. // }
  2352. return jsobj;
  2353. }
  2354. //+(NSDictionary*)request_Cart:(int)sort
  2355. //{
  2356. //
  2357. // DebugLog(@"iSalesNetwork::request_Cart");
  2358. //
  2359. //
  2360. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2361. // __block AppDelegate *appDelegate = nil;
  2362. //
  2363. // dispatch_sync(dispatch_get_main_queue(), ^{
  2364. // //some UI methods ej
  2365. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2366. // });
  2367. // if(RASingleton.sharedInstance.user!=nil)
  2368. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  2369. // // if(appDelegate.contact_id!=nil)
  2370. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2371. // if(RASingleton.sharedInstance.password!=nil)
  2372. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  2373. //
  2374. // if(appDelegate.order_code!=nil)
  2375. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2376. //
  2377. // [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  2378. //
  2379. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2380. //
  2381. // NSData* json=nil;
  2382. // if(appDelegate.offline_mode)
  2383. // {
  2384. // json= [OLDataProvider offline_requestcart:params];
  2385. // }
  2386. // else
  2387. // {
  2388. // if(![self IsNetworkAvailable])
  2389. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2390. //
  2391. // NSError *error=nil;
  2392. //
  2393. // NSString * uuid= [[NSUUID UUID] UUIDString];
  2394. // params[@"resultSerial"]=uuid;
  2395. //
  2396. // for(int i=0;i<150;i++)
  2397. // {
  2398. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  2399. // // result_params[@"resultSerial"]=uuid;
  2400. // json=[self get_json:URL_CART parameters:params];
  2401. // if(json!=nil)
  2402. // {
  2403. //
  2404. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2405. // if([jsobj[@"result"] intValue]==2)
  2406. // {
  2407. // break;
  2408. // }
  2409. // }
  2410. // sleep(2);
  2411. // }
  2412. //
  2413. // }
  2414. // if(json==nil)
  2415. // return nil;
  2416. // NSError *error=nil;
  2417. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2418. // int result = [[jsobj valueForKey:@"result"] intValue];
  2419. //
  2420. // if (result==2)
  2421. // {
  2422. //
  2423. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2424. // //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2425. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2426. //
  2427. // [appDelegate update_count_mark];
  2428. // }
  2429. // return jsobj;
  2430. //}
  2431. //+(NSDictionary*)request_Portfolio:(int)sort
  2432. //{
  2433. //
  2434. //
  2435. //
  2436. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2437. // __block AppDelegate *appDelegate = nil;
  2438. //
  2439. // dispatch_sync(dispatch_get_main_queue(), ^{
  2440. // //some UI methods ej
  2441. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2442. // });
  2443. // if(RASingleton.sharedInstance.user!=nil)
  2444. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  2445. // if(appDelegate.contact_id!=nil)
  2446. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2447. // if(RASingleton.sharedInstance.password!=nil)
  2448. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  2449. //
  2450. // [params setValue:[NSString stringWithFormat:@"%d",0 ] forKey:@"offset"];
  2451. // [params setValue:[NSString stringWithFormat:@"%d",INT_MAX ] forKey:@"limit"];
  2452. // [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  2453. //
  2454. // [params setObject:ScreenCodePortfolio forKey:kScreenName];
  2455. //
  2456. // NSData* json = nil;
  2457. // if(appDelegate.offline_mode)
  2458. // {
  2459. // json = [OLDataProvider offline_portfolioList:params];
  2460. // } else {
  2461. // if(![self IsNetworkAvailable])
  2462. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2463. //
  2464. // json = [self get_json:URL_PORTFOLIO parameters:params];
  2465. // }
  2466. //
  2467. //
  2468. // if(json==nil)
  2469. // return nil;
  2470. // NSError *error=nil;
  2471. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2472. // int result = [[jsobj valueForKey:@"result"] intValue];
  2473. //
  2474. // if (result==2)
  2475. // {
  2476. //
  2477. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2478. // //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2479. // appDelegate.port_count =[[jsobj valueForKey:@"count"] intValue];
  2480. //
  2481. // [appDelegate update_count_mark];
  2482. // }
  2483. // return jsobj;
  2484. //}
  2485. //+(NSDictionary*)request_WatchList:(int)sort
  2486. //{
  2487. //
  2488. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2489. // __block AppDelegate *appDelegate = nil;
  2490. //
  2491. // dispatch_sync(dispatch_get_main_queue(), ^{
  2492. // //some UI methods ej
  2493. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2494. // });
  2495. // if(RASingleton.sharedInstance.user!=nil)
  2496. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  2497. // if(appDelegate.contact_id!=nil)
  2498. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2499. // if(RASingleton.sharedInstance.password!=nil)
  2500. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  2501. //
  2502. // [params setValue:[NSString stringWithFormat:@"%d",0 ] forKey:@"offset"];
  2503. // [params setValue:[NSString stringWithFormat:@"%d",INT_MAX ] forKey:@"limit"];
  2504. //
  2505. // [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  2506. //
  2507. // [params setObject:ScreenCodeWishList forKey:kScreenName];
  2508. //
  2509. // if(appDelegate.offline_mode)
  2510. // {
  2511. // return [OLDataProvider offline_wishlist:params];
  2512. // }
  2513. // if(![self IsNetworkAvailable])
  2514. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2515. //
  2516. // NSData* json=[self get_json:URL_WATCHLIST parameters:params];
  2517. // if(json==nil)
  2518. // return nil;
  2519. // NSError *error=nil;
  2520. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2521. // int result = [[jsobj valueForKey:@"result"] intValue];
  2522. //
  2523. // if (result==2)
  2524. // {
  2525. //
  2526. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2527. // appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2528. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2529. //
  2530. // [appDelegate update_count_mark];
  2531. // }
  2532. // return jsobj;
  2533. //}
  2534. //+(NSDictionary*)request_ItemDetail: (NSString* ) item_id model_name:(NSString*) model_name category_id:(NSString*) category_id use_name :(bool) use_name groupName:(NSString *)groupName
  2535. //{
  2536. //
  2537. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2538. // __block AppDelegate *appDelegate = nil;
  2539. //
  2540. // dispatch_sync(dispatch_get_main_queue(), ^{
  2541. // //some UI methods ej
  2542. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2543. // });
  2544. // if(RASingleton.sharedInstance.user!=nil)
  2545. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  2546. // if(appDelegate.contact_id!=nil)
  2547. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2548. // if(RASingleton.sharedInstance.password!=nil)
  2549. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  2550. // if(appDelegate.order_code!=nil)
  2551. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2552. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2553. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2554. // if(use_name)
  2555. // [params setValue:model_name forKey:@"product_name"];
  2556. // else
  2557. // [params setValue:item_id forKey:@"product_id"];
  2558. //
  2559. //
  2560. // [params setValue:category_id forKey:@"category"];
  2561. //
  2562. // [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  2563. // [params setObject:@"Open A Model" forKey:kAction];
  2564. // if (model_name) {
  2565. // NSDictionary *extra = @{@"ModelName" : model_name};
  2566. // [params setObject:extra forKey:kExtra];
  2567. // }
  2568. //
  2569. // if (groupName.length > 0) {
  2570. // [params setObject:groupName forKey:@"groupName"];
  2571. // }
  2572. //
  2573. // if(appDelegate.offline_mode)
  2574. // return [OLDataProvider offline_model:params];
  2575. //
  2576. // if(![self IsNetworkAvailable])
  2577. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2578. //
  2579. // NSData* json=[self get_json:URL_ITEM_DETAIL parameters:params];
  2580. // if(json==nil)
  2581. // return nil;
  2582. // NSError *error=nil;
  2583. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2584. // return jsobj;
  2585. //}
  2586. //+(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
  2587. //{
  2588. // if(![self IsNetworkAvailable])
  2589. // return nil;
  2590. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2591. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2592. // if(RASingleton.sharedInstance.user!=nil)
  2593. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  2594. // if(appDelegate.contact_id!=nil)
  2595. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2596. // if(RASingleton.sharedInstance.password!=nil)
  2597. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  2598. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2599. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2600. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  2601. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2602. // [params setValue:[NSString stringWithFormat:@"%d",offset] forKey:@"offset"];
  2603. // [params setValue:filter forKey:@"filter"];
  2604. // [params setValue:keyword forKey:@"keyword"];
  2605. //
  2606. //
  2607. // NSData* json=[self get_json:URL_CATEGORY_LOADMORE parameters:params];
  2608. // if(json==nil)
  2609. // return nil;
  2610. // NSError *error=nil;
  2611. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2612. // return jsobj;
  2613. //
  2614. //}
  2615. //+(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
  2616. //
  2617. //{
  2618. //
  2619. //
  2620. // __block AppDelegate *appDelegate = nil;
  2621. //
  2622. // dispatch_sync(dispatch_get_main_queue(), ^{
  2623. // //some UI methods ej
  2624. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2625. // });
  2626. //
  2627. //
  2628. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2629. //
  2630. // if(RASingleton.sharedInstance.user!=nil)
  2631. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  2632. // if(appDelegate.contact_id!=nil)
  2633. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2634. // if(RASingleton.sharedInstance.password!=nil)
  2635. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  2636. // if(appDelegate.order_code!=nil)
  2637. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2638. //
  2639. // [params setValue:addTo forKey:@"addTo"];
  2640. // [params setValue:orderCode forKey:@"orderCode"];
  2641. // [params setValue:alert forKey:@"alert"];
  2642. // [params setValue:qty forKey:@"sold_by_qty"];
  2643. // [params setValue:available forKey:@"available"];
  2644. // [params setValue:price forKey:@"price"];
  2645. // [params setValue:bestseller forKey:@"bestseller"];
  2646. // [params setValue:modelname forKey:@"modelName"];
  2647. // [params setValue:modeldescrip forKey:@"modelDescription"];
  2648. //
  2649. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2650. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2651. // [params setValue:category forKey:@"category"];
  2652. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2653. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2654. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  2655. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  2656. // [params setValue:filter forKey:@"filter"];
  2657. // [params setValue:keyword forKey:@"keyword"];
  2658. //
  2659. // [params setObject:ScreenCodeCategory forKey:kScreenName];
  2660. // if ([addTo isEqualToString:@"cart"]) {
  2661. // [params setObject:@"Add To Cart" forKey:kAction];
  2662. // }
  2663. //
  2664. //
  2665. // NSData* json= nil;
  2666. //
  2667. // if(appDelegate.offline_mode)
  2668. // {
  2669. // json= [OLDataProvider offline_categoryaddall:params];
  2670. // }
  2671. // else
  2672. // {
  2673. // if(![self IsNetworkAvailable])
  2674. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2675. //
  2676. //
  2677. // NSError *error=nil;
  2678. //
  2679. // NSString * uuid= [[NSUUID UUID] UUIDString];
  2680. // params[@"resultSerial"]=uuid;
  2681. //
  2682. // for(int i=0;i<150;i++)
  2683. // {
  2684. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  2685. // // result_params[@"resultSerial"]=uuid;
  2686. // json=[self get_json:URL_CATEGORYADDALL parameters:params];
  2687. // if(json!=nil)
  2688. // {
  2689. //
  2690. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2691. // int resultInt = [jsobj[@"result"] intValue];
  2692. // if(resultInt == 2 || resultInt == 8)
  2693. // {
  2694. // break;
  2695. // }
  2696. // }
  2697. // sleep(2);
  2698. // }
  2699. //
  2700. //
  2701. //
  2702. // }
  2703. // if(json==nil)
  2704. // return nil;
  2705. // NSError *error=nil;
  2706. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2707. // return jsobj;
  2708. //
  2709. //}
  2710. //+(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
  2711. //{
  2712. //
  2713. //
  2714. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2715. //
  2716. //
  2717. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2718. //
  2719. // if(RASingleton.sharedInstance.user!=nil)
  2720. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  2721. // if(appDelegate.contact_id!=nil)
  2722. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2723. // if(RASingleton.sharedInstance.password!=nil)
  2724. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  2725. // if(appDelegate.order_code!=nil)
  2726. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2727. //
  2728. // [params setValue:alert forKey:@"alert"];
  2729. // [params setValue:qty forKey:@"sold_by_qty"];
  2730. // [params setValue:available forKey:@"available"];
  2731. // [params setValue:price forKey:@"price"];
  2732. // [params setValue:bestseller forKey:@"bestseller"];
  2733. // [params setValue:modelname forKey:@"modelName"];
  2734. // [params setValue:modeldescrip forKey:@"modelDescription"];
  2735. //
  2736. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2737. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2738. // [params setValue:category forKey:@"category"];
  2739. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2740. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2741. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  2742. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  2743. // [params setValue:filter forKey:@"filter"];
  2744. // [params setValue:keyword forKey:@"keyword"];
  2745. //
  2746. //
  2747. //
  2748. // if(appDelegate.offline_mode)
  2749. // return [OLDataProvider offline_category:params];
  2750. // if(![self IsNetworkAvailable])
  2751. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2752. //
  2753. // NSData* json=[self get_json:URL_ADDALL2PORTFOLIO parameters:params];
  2754. // if(json==nil)
  2755. // return nil;
  2756. // NSError *error=nil;
  2757. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2758. // return jsobj;
  2759. //
  2760. //}
  2761. //+(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
  2762. //{
  2763. //
  2764. //
  2765. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2766. //
  2767. //
  2768. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2769. //
  2770. // if(RASingleton.sharedInstance.user!=nil)
  2771. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  2772. // if(appDelegate.contact_id!=nil)
  2773. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2774. // if(RASingleton.sharedInstance.password!=nil)
  2775. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  2776. // if(appDelegate.order_code!=nil)
  2777. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2778. //
  2779. // [params setValue:alert forKey:@"alert"];
  2780. // [params setValue:qty forKey:@"sold_by_qty"];
  2781. // [params setValue:available forKey:@"available"];
  2782. // [params setValue:price forKey:@"price"];
  2783. // [params setValue:bestseller forKey:@"bestseller"];
  2784. // [params setValue:modelname forKey:@"modelName"];
  2785. // [params setValue:modeldescrip forKey:@"modelDescription"];
  2786. //
  2787. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2788. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2789. // [params setValue:category forKey:@"category"];
  2790. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2791. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2792. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  2793. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  2794. // [params setValue:filter forKey:@"filter"];
  2795. // [params setValue:keyword forKey:@"keyword"];
  2796. //
  2797. //
  2798. //
  2799. // if(appDelegate.offline_mode)
  2800. // return [OLDataProvider offline_category:params];
  2801. // if(![self IsNetworkAvailable])
  2802. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2803. //
  2804. // NSData* json=[self get_json:URL_ADDALL2WISH parameters:params];
  2805. // if(json==nil)
  2806. // return nil;
  2807. // NSError *error=nil;
  2808. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2809. // return jsobj;
  2810. //
  2811. //}
  2812. //+(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
  2813. //{
  2814. //
  2815. //
  2816. // __block AppDelegate *appDelegate = nil;
  2817. //
  2818. // dispatch_sync(dispatch_get_main_queue(), ^{
  2819. // //some UI methods ej
  2820. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2821. // });
  2822. //
  2823. //
  2824. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2825. //
  2826. // if(RASingleton.sharedInstance.user!=nil)
  2827. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  2828. // if(appDelegate.contact_id!=nil)
  2829. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2830. // if(RASingleton.sharedInstance.password!=nil)
  2831. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  2832. // if(appDelegate.order_code!=nil)
  2833. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2834. //
  2835. // [params setValue:alert forKey:@"alert"];
  2836. // [params setValue:qty forKey:@"sold_by_qty"];
  2837. // [params setValue:available forKey:@"available"];
  2838. // [params setValue:price forKey:@"price"];
  2839. // [params setValue:bestseller forKey:@"bestseller"];
  2840. // [params setValue:modelname forKey:@"modelName"];
  2841. // [params setValue:modeldescrip forKey:@"modelDescription"];
  2842. //
  2843. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2844. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2845. // [params setValue:category forKey:@"category"];
  2846. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2847. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2848. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  2849. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  2850. // [params setValue:filter forKey:@"filter"];
  2851. // [params setValue:keyword forKey:@"keyword"];
  2852. //
  2853. // [params setObject:ScreenCodeCategory forKey:kScreenName];
  2854. // if (alert) {
  2855. // [params setObject:@"Filter" forKey:kAction];
  2856. // }
  2857. // if ([Singleton sharedInstance].homeItemClick) {
  2858. // [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
  2859. // [Singleton sharedInstance].homeItemClick = NO;
  2860. //
  2861. // NSDictionary *extra = @{@"CoverName" : [Singleton sharedInstance].homeClickedItemName};
  2862. // [Singleton sharedInstance].homeClickedItemName = nil;
  2863. // [params setObject:extra forKey:kExtra];
  2864. //
  2865. // }
  2866. //
  2867. //
  2868. // if(appDelegate.offline_mode)
  2869. // return [OLDataProvider offline_category:params];
  2870. // if(![self IsNetworkAvailable])
  2871. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2872. //
  2873. // NSData* json=[self get_json:URL_CATEGORY parameters:params];
  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. //}
  2881. //+(NSDictionary*)Search_addall:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull orderCode:(NSString*) orderCode addTo:(NSString*) addTo
  2882. //{
  2883. //
  2884. //
  2885. //
  2886. //
  2887. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2888. // __block AppDelegate *appDelegate = nil;
  2889. //
  2890. // dispatch_sync(dispatch_get_main_queue(), ^{
  2891. // //some UI methods ej
  2892. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2893. // });
  2894. // if(RASingleton.sharedInstance.user!=nil)
  2895. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  2896. // if(appDelegate.contact_id!=nil)
  2897. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2898. // if(RASingleton.sharedInstance.password!=nil)
  2899. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  2900. // if(appDelegate.order_code!=nil)
  2901. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2902. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2903. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2904. // // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  2905. // // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2906. // // [params setValue:filter forKey:@"filter"];
  2907. // [params setValue:keywords forKey:@"keyword"];
  2908. // [params setValue:addTo forKey:@"addTo"];
  2909. //
  2910. // [params setValue:orderCode forKey:@"orderCode"];
  2911. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  2912. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  2913. // if(matchfull)
  2914. // [params setValue:@"true" forKey:@"exactMatch"];
  2915. // else
  2916. // [params setValue:@"false" forKey:@"exactMatch"];
  2917. //
  2918. // [params setObject:ScreenCodeSearch forKey:kScreenName];
  2919. // if ([addTo isEqualToString:@"cart"]) {
  2920. // [params setObject:@"Add To Cart" forKey:kAction];
  2921. // }
  2922. //
  2923. // NSData* json=nil;
  2924. // if(appDelegate.offline_mode)
  2925. // {
  2926. // json=[OLDataProvider offline_searchaddall:params];
  2927. // }
  2928. // else
  2929. // {
  2930. // if(![self IsNetworkAvailable])
  2931. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2932. //
  2933. // NSError *error=nil;
  2934. //
  2935. // NSString * uuid= [[NSUUID UUID] UUIDString];
  2936. // params[@"resultSerial"]=uuid;
  2937. //
  2938. // for(int i=0;i<150;i++)
  2939. // {
  2940. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  2941. // // result_params[@"resultSerial"]=uuid;
  2942. // json=[self get_json:URL_SEARCHADDALL parameters:params];
  2943. // if(json!=nil)
  2944. // {
  2945. //
  2946. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2947. // if([jsobj[@"result"] intValue]==2)
  2948. // {
  2949. // break;
  2950. // }
  2951. // }
  2952. // sleep(2);
  2953. // }
  2954. // }
  2955. // if(json==nil)
  2956. // return nil;
  2957. // NSError *error=nil;
  2958. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2959. // return jsobj;
  2960. //
  2961. //}
  2962. //+(NSDictionary*)Search:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull
  2963. //{
  2964. //
  2965. //
  2966. //
  2967. //
  2968. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2969. // __block AppDelegate *appDelegate = nil;
  2970. //
  2971. // dispatch_sync(dispatch_get_main_queue(), ^{
  2972. // //some UI methods ej
  2973. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2974. // });
  2975. // if(RASingleton.sharedInstance.user!=nil)
  2976. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  2977. // if(appDelegate.contact_id!=nil)
  2978. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2979. // if(RASingleton.sharedInstance.password!=nil)
  2980. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  2981. // if(appDelegate.order_code!=nil)
  2982. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2983. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2984. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2985. // // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  2986. // // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2987. // // [params setValue:filter forKey:@"filter"];
  2988. // [params setValue:keywords forKey:@"keyword"];
  2989. //
  2990. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  2991. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  2992. // if(matchfull)
  2993. // [params setValue:@"true" forKey:@"exactMatch"];
  2994. // else
  2995. // [params setValue:@"false" forKey:@"exactMatch"];
  2996. //
  2997. // [params setObject:ScreenCodeSearch forKey:kScreenName];
  2998. // if (keywords) {
  2999. // [params setObject:@"Search" forKey:kAction];
  3000. // }
  3001. //
  3002. // if(appDelegate.offline_mode)
  3003. // {
  3004. // return [OLDataProvider offline_search:params];
  3005. // }
  3006. // if(![self IsNetworkAvailable])
  3007. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3008. //
  3009. // NSData* json=[self get_json:URL_SEARCH parameters:params];
  3010. // if(json==nil)
  3011. // return nil;
  3012. // NSError *error=nil;
  3013. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3014. // return jsobj;
  3015. //}
  3016. //+(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
  3017. //{
  3018. // // for debug
  3019. // // return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
  3020. // //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3021. //
  3022. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3023. // __block AppDelegate *appDelegate = nil;
  3024. //
  3025. // dispatch_sync(dispatch_get_main_queue(), ^{
  3026. // //some UI methods ej
  3027. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3028. // });
  3029. // if(RASingleton.sharedInstance.user!=nil)
  3030. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  3031. // if(appDelegate.contact_id!=nil)
  3032. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3033. // if(RASingleton.sharedInstance.password!=nil)
  3034. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  3035. // if(appDelegate.order_code!=nil)
  3036. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3037. //
  3038. // [params setValue:addTo forKey:@"addTo"];
  3039. //
  3040. // [params setValue:orderCode forKey:@"orderCode"];
  3041. //
  3042. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3043. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3044. // // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3045. // // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3046. // // [params setValue:filter forKey:@"filter"];
  3047. // [params setValue:covertype forKey:@"covertype"];
  3048. // [params setValue:ctgid forKey:@"ctgId"];
  3049. // [params setValue:modelname forKey:@"modelName"];
  3050. // [params setValue:modeldescrip forKey:@"modelDescription"];
  3051. // [params setValue:alert forKey:@"alert"];
  3052. // [params setValue:qty forKey:@"sold_by_qty"];
  3053. // [params setValue:available forKey:@"available"];
  3054. // [params setValue:price forKey:@"price"];
  3055. // [params setValue:bestseller forKey:@"bestseller"];
  3056. //
  3057. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3058. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3059. //
  3060. // [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
  3061. // if ([addTo isEqualToString:@"cart"]) {
  3062. // [params setObject:@"Add To Cart" forKey:kAction];
  3063. // }
  3064. //
  3065. // NSData* json = nil;
  3066. //
  3067. // if(appDelegate.offline_mode)
  3068. // {
  3069. // json= [OLDataProvider offline_itemsearchaddall:params];
  3070. // }
  3071. // else
  3072. // {
  3073. // if(![self IsNetworkAvailable])
  3074. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3075. // NSError *error=nil;
  3076. //
  3077. // NSString * uuid= [[NSUUID UUID] UUIDString];
  3078. // params[@"resultSerial"]=uuid;
  3079. //
  3080. // for(int i=0;i<150;i++)
  3081. // {
  3082. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  3083. // // result_params[@"resultSerial"]=uuid;
  3084. // json=[self get_json:URL_ITEMSEARCHADDALL parameters:params];
  3085. // if(json!=nil)
  3086. // {
  3087. //
  3088. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3089. // if([jsobj[@"result"] intValue]==2)
  3090. // {
  3091. // break;
  3092. // }
  3093. // }
  3094. // sleep(2);
  3095. // }
  3096. // }
  3097. // if(json==nil)
  3098. // return nil;
  3099. // NSError *error=nil;
  3100. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3101. // return jsobj;
  3102. //}
  3103. //+(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
  3104. //{
  3105. //
  3106. // // for debug
  3107. // // return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
  3108. // //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3109. //
  3110. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3111. // __block AppDelegate *appDelegate = nil;
  3112. //
  3113. // dispatch_sync(dispatch_get_main_queue(), ^{
  3114. // //some UI methods ej
  3115. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3116. // });
  3117. // if(RASingleton.sharedInstance.user!=nil)
  3118. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  3119. // if(appDelegate.contact_id!=nil)
  3120. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3121. // if(RASingleton.sharedInstance.password!=nil)
  3122. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  3123. // if(appDelegate.order_code!=nil)
  3124. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3125. //
  3126. //
  3127. // [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
  3128. // if (alert && qty && available && price && bestseller) {
  3129. // [params setObject:@"Filter" forKey:kAction];
  3130. // }
  3131. // if ([Singleton sharedInstance].homeItemClick) {
  3132. // [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
  3133. // [Singleton sharedInstance].homeItemClick = NO;
  3134. //
  3135. // NSDictionary *extra = @{@"CoverName" : [Singleton sharedInstance].homeClickedItemName};
  3136. // [Singleton sharedInstance].homeClickedItemName = nil;
  3137. // [params setObject:extra forKey:kExtra];
  3138. // }
  3139. //
  3140. //
  3141. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3142. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3143. // // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3144. // // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3145. // // [params setValue:filter forKey:@"filter"];
  3146. // [params setValue:covertype forKey:@"covertype"];
  3147. // [params setValue:ctgid forKey:@"ctgId"];
  3148. // [params setValue:modelname forKey:@"modelName"];
  3149. // [params setValue:modeldescrip forKey:@"modelDescription"];
  3150. // [params setValue:alert forKey:@"alert"];
  3151. // [params setValue:qty forKey:@"sold_by_qty"];
  3152. // [params setValue:available forKey:@"available"];
  3153. // [params setValue:price forKey:@"price"];
  3154. // [params setValue:bestseller forKey:@"bestseller"];
  3155. //
  3156. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3157. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3158. //
  3159. // if(appDelegate.offline_mode)
  3160. // {
  3161. // return [OLDataProvider offline_itemsearch:params];
  3162. // }
  3163. // if(![self IsNetworkAvailable])
  3164. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3165. // NSData* json=[self get_json:URL_ITEM_SEARCH parameters:params];
  3166. // if(json==nil)
  3167. // return nil;
  3168. // NSError *error=nil;
  3169. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3170. // return jsobj;
  3171. //}
  3172. //+(NSDictionary*)Search: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword
  3173. //{
  3174. // if(![self IsNetworkAvailable])
  3175. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3176. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3177. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3178. // if(RASingleton.sharedInstance.user!=nil)
  3179. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  3180. // if(appDelegate.contact_id!=nil)
  3181. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3182. // if(RASingleton.sharedInstance.password!=nil)
  3183. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  3184. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3185. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3186. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3187. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3188. // [params setValue:filter forKey:@"filter"];
  3189. // [params setValue:keyword forKey:@"keyword"];
  3190. //
  3191. //
  3192. // NSData* json=[self get_json:URL_SEARCH parameters:params];
  3193. // if(json==nil)
  3194. // return nil;
  3195. // NSError *error=nil;
  3196. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3197. // return jsobj;
  3198. //}
  3199. +(NSDictionary*)request_model_qty: (NSString*) fashionId
  3200. {
  3201. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3202. __block AppDelegate *appDelegate = nil;
  3203. dispatch_sync(dispatch_get_main_queue(), ^{
  3204. //some UI methods ej
  3205. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3206. });
  3207. if(RASingleton.sharedInstance.user!=nil)
  3208. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  3209. if(appDelegate.contact_id!=nil)
  3210. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3211. if(RASingleton.sharedInstance.password!=nil)
  3212. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  3213. [params setValue:fashionId forKey:@"fashionId"];
  3214. [params setObject:ScreenCodeEditPortfolio forKey:kScreenName];
  3215. NSData* json = nil;
  3216. if(appDelegate.offline_mode)
  3217. {
  3218. json = [OLDataProvider offline_model_qty:params];
  3219. } else {
  3220. if(![self IsNetworkAvailable])
  3221. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3222. json=[self get_json:URL_REQUEST_MODEL_QTY parameters:params];
  3223. }
  3224. if(json==nil)
  3225. return nil;
  3226. NSError *error=nil;
  3227. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3228. return jsobj;
  3229. }
  3230. +(NSDictionary*)retrieve_password: (NSString*) user email:(NSString*) email
  3231. {
  3232. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3233. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3234. // if(RASingleton.sharedInstance.user!=nil)
  3235. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  3236. // if(appDelegate.contact_id!=nil)
  3237. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3238. // if(RASingleton.sharedInstance.password!=nil)
  3239. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  3240. [params setValue:user forKey:@"username"];
  3241. [params setValue:email forKey:@"email"];
  3242. [params setObject:ScreenCodeLoginView forKey:kScreenName];
  3243. if(![self IsNetworkAvailable])
  3244. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3245. NSData* json=[self get_json:URL_RETRIEVE_PASS parameters:params];
  3246. if(json==nil)
  3247. return nil;
  3248. NSError *error=nil;
  3249. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3250. return jsobj;
  3251. }
  3252. +(NSDictionary*)load_HomePage:(int) price_template customid:(int) customid
  3253. {
  3254. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3255. __block AppDelegate *appDelegate = nil;
  3256. dispatch_sync(dispatch_get_main_queue(), ^{
  3257. //some UI methods ej
  3258. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3259. });
  3260. if(RASingleton.sharedInstance.user!=nil)
  3261. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  3262. if(appDelegate.contact_id!=nil)
  3263. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3264. if(RASingleton.sharedInstance.password!=nil)
  3265. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  3266. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3267. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3268. [params setObject:ScreenCodeHomeView forKey:kScreenName];
  3269. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3270. if(appDelegate.offline_mode)
  3271. {
  3272. //params[@"offline_Command"]=url;
  3273. return [OLDataProvider offline_home];
  3274. }
  3275. if(![self IsNetworkAvailable])
  3276. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3277. NSData* json=[self get_json:URL_LOAD_HOME parameters:params];
  3278. if(json==nil)
  3279. return nil;
  3280. NSError *error=nil;
  3281. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3282. return jsobj;
  3283. }
  3284. //+(NSDictionary*)logout
  3285. //{
  3286. //
  3287. //
  3288. //
  3289. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3290. // __block AppDelegate *appDelegate = nil;
  3291. //
  3292. // dispatch_sync(dispatch_get_main_queue(), ^{
  3293. // //some UI methods ej
  3294. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3295. // });
  3296. // if(RASingleton.sharedInstance.user!=nil)
  3297. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  3298. //
  3299. //
  3300. // if(RASingleton.sharedInstance.password!=nil)
  3301. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  3302. //
  3303. //
  3304. // if(appDelegate.offline_mode)
  3305. // {
  3306. // return [OLDataProvider offline_logout:params];
  3307. // }
  3308. // if(![self IsNetworkAvailable])
  3309. // {
  3310. // DebugLog(@"NET ERR");
  3311. //
  3312. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3313. // // return nil;
  3314. // }
  3315. // NSData* json=[self get_json:URL_LOGOUT parameters:params];
  3316. // //if(json==nil)
  3317. //
  3318. //
  3319. // if(json==nil)
  3320. // return nil;
  3321. // NSError *error=nil;
  3322. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3323. // int result = [[jsobj valueForKey:@"result"] intValue];
  3324. //
  3325. // if (result==2)
  3326. // {
  3327. //
  3328. // appDelegate.cart_count = 0;//[[jsobj valueForKey:@"cart_count"] intValue];
  3329. // appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
  3330. // appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
  3331. //
  3332. // [appDelegate update_count_mark];
  3333. //
  3334. //
  3335. // appDelegate.can_show_price =false;
  3336. // appDelegate.can_see_price =false;
  3337. // appDelegate.can_create_portfolio =false;
  3338. // appDelegate.can_create_order =false;
  3339. //
  3340. //
  3341. // appDelegate.can_cancel_order =false;
  3342. // appDelegate.can_set_cart_price =false;
  3343. // appDelegate.can_delete_order =false;
  3344. // appDelegate.can_submit_order =false;
  3345. // appDelegate.can_set_tearsheet_price =false;
  3346. // appDelegate.can_update_contact_info = false;
  3347. //
  3348. // appDelegate.save_order_logout = false;
  3349. // appDelegate.submit_order_logout = false;
  3350. // appDelegate.alert_sold_in_quantities = false;
  3351. //
  3352. // RASingleton.sharedInstance.ipad_perm =nil ;
  3353. // appDelegate.user_type = USER_ROLE_UNKNOWN;
  3354. // appDelegate.OrderFilter= nil;
  3355. // [appDelegate SetSo:nil];
  3356. // [appDelegate set_main_button_panel];
  3357. //#ifdef RA_NOTIFICATION
  3358. // [ActiveViewController Notify:@"SearchViewController" Message:RA_NOTIFICATION_CLEAR_DATA];
  3359. //#endif
  3360. // }
  3361. // return jsobj;
  3362. //}
  3363. +(NSDictionary*)request_Cagegory
  3364. {
  3365. // DebugLog(@"@@@@@@@@@@@@@@@@@@@LOADING CATEGORY MENU");
  3366. __block AppDelegate *appDelegate = nil;
  3367. dispatch_sync(dispatch_get_main_queue(), ^{
  3368. //some UI methods ej
  3369. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3370. });
  3371. if(appDelegate.offline_mode)
  3372. {
  3373. //params[@"offline_Command"]=url;
  3374. return [OLDataProvider offline_category_menu];
  3375. }
  3376. if(![self IsNetworkAvailable])
  3377. {
  3378. DebugLog(@"NET ERR");
  3379. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3380. // return nil;
  3381. }
  3382. NSData* json=[self get_json:URL_REQUEST_CATMENU parameters:nil];
  3383. //if(json==nil)
  3384. if(json==nil)
  3385. return nil;
  3386. NSError *error=nil;
  3387. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3388. return jsobj;
  3389. }
  3390. +(int)Authorize : (NSString*) user password:(NSString*) password{
  3391. // if(![ApexMobileNetwork IsHostAvailable:URL_UPDATE_AUTH])
  3392. // return RESULT_NET_ERROR;
  3393. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  3394. long ver =[defaults integerForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  3395. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3396. __block AppDelegate *appDelegate = nil;
  3397. dispatch_sync(dispatch_get_main_queue(), ^{
  3398. //some UI methods ej
  3399. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3400. });
  3401. if(RASingleton.sharedInstance.duid !=nil)
  3402. [params setValue:RASingleton.sharedInstance.duid forKey:@"udid"];
  3403. [params setValue:@"handset_login" forKey:@"action"];
  3404. // [headers setValue:[NSString stringWithFormat:@"%d",dataLength] forKey:@"Content-Length"];
  3405. [params setValue:user forKey:@"user"];
  3406. [params setValue:password forKey:@"password"];
  3407. [params setValue:[NSString stringWithFormat:@"%ld",ver] forKey:@"auth_ver"];
  3408. #ifdef TEST
  3409. [params setValue:@"true" forKey:@"is_debug"];
  3410. #else
  3411. [params setValue:@"false" forKey:@"is_debug"];
  3412. #endif
  3413. [params setObject:ScreenCodeLoginView forKey:kScreenName];
  3414. [params setObject:@"Login" forKey:kAction];
  3415. NSData* json= nil;
  3416. if(appDelegate.offline_mode)
  3417. {
  3418. json= [OLDataProvider offline_login:params] ;
  3419. }
  3420. else
  3421. {
  3422. if(![self IsNetworkAvailable])
  3423. return RESULT_NET_NOTAVAILABLE;
  3424. json =[self get_json:URL_UPDATE_AUTH parameters:params];
  3425. }
  3426. if(json==nil)
  3427. return RESULT_NET_ERROR;
  3428. int ret = [self parse_authinfo:json user:user password:password];
  3429. DebugLog(@"parse_authinfo return %d ",ret);
  3430. return ret;
  3431. }
  3432. +(NSDictionary*)update_customer_img: (NSString*) contactid img_url:(NSString*) url
  3433. {
  3434. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3435. __block AppDelegate *appDelegate = nil;
  3436. dispatch_sync(dispatch_get_main_queue(), ^{
  3437. //some UI methods ej
  3438. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3439. });
  3440. if(RASingleton.sharedInstance.user!=nil)
  3441. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  3442. // if(appDelegate.contact_id!=nil)
  3443. if(RASingleton.sharedInstance.password!=nil)
  3444. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  3445. [params setValue:contactid forKey:@"contactId"];
  3446. [params setValue:url forKey:@"business_card"];
  3447. // [params setValue:[NSNumber numberWithInt:index ] forKey:@"index"];
  3448. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  3449. if(appDelegate.offline_mode)
  3450. {
  3451. return [OLDataProvider offline_notimpl];
  3452. }
  3453. if(![self IsNetworkAvailable])
  3454. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3455. NSData* json=[self get_json:URL_UPDATE_CUSTOMER_BCARD parameters:params];
  3456. if(json==nil)
  3457. return nil;
  3458. NSError *error=nil;
  3459. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3460. return jsobj;
  3461. }
  3462. +(NSDictionary*)request_PendingOrder:(NSString *)contactid
  3463. {
  3464. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3465. __block AppDelegate *appDelegate = nil;
  3466. dispatch_sync(dispatch_get_main_queue(), ^{
  3467. //some UI methods ej
  3468. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3469. });
  3470. if(RASingleton.sharedInstance.user!=nil)
  3471. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  3472. // if(appDelegate.contact_id!=nil)
  3473. if(RASingleton.sharedInstance.password!=nil)
  3474. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  3475. [params setValue:contactid forKey:@"contactId"];
  3476. if(appDelegate.offline_mode)
  3477. {
  3478. return [OLDataProvider offline_notimpl];
  3479. }
  3480. if(![self IsNetworkAvailable])
  3481. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3482. NSData* json=[self get_json:URL_CUSTOMER_PENDINGORDER parameters:params];
  3483. if(json==nil)
  3484. return nil;
  3485. NSError *error=nil;
  3486. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3487. return jsobj;
  3488. }
  3489. //+(NSDictionary*)request_CustomerInfo:(NSString* ) contactid
  3490. //{
  3491. //
  3492. //
  3493. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3494. // __block AppDelegate *appDelegate = nil;
  3495. //
  3496. // dispatch_sync(dispatch_get_main_queue(), ^{
  3497. // //some UI methods ej
  3498. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3499. // });
  3500. // if(RASingleton.sharedInstance.user!=nil)
  3501. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  3502. // // if(appDelegate.contact_id!=nil)
  3503. //
  3504. // if(RASingleton.sharedInstance.password!=nil)
  3505. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  3506. // [params setValue:contactid forKey:@"contactId"];
  3507. //
  3508. // [params setObject:ScreenCodeCustomerInfo forKey:kScreenName];
  3509. //
  3510. // if(appDelegate.offline_mode)
  3511. // return [OLDataProvider offline_contactinfo:params];
  3512. // if(![self IsNetworkAvailable])
  3513. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3514. //
  3515. // NSData* json=[self get_json:URL_CUSTOMER_INFO parameters:params];
  3516. // if(json==nil)
  3517. // return nil;
  3518. // NSError *error=nil;
  3519. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3520. // return jsobj;
  3521. //
  3522. //}
  3523. +(int)parse_authinfo : (NSData *) json user:(NSString*) user password:(NSString*) password
  3524. {
  3525. DebugLog(@"parse_authinfo");
  3526. NSError *error=nil;
  3527. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3528. if(jsobj)
  3529. {
  3530. __block AppDelegate *appDelegate = nil;
  3531. dispatch_sync(dispatch_get_main_queue(), ^{
  3532. //some UI methods ej
  3533. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3534. });
  3535. int result = [[jsobj valueForKey:@"result"] intValue];
  3536. if (result<0)
  3537. return result;
  3538. if(result!=AP_USER_AUTH&& result!=9)
  3539. {
  3540. DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
  3541. // [appDelegate Logout];
  3542. if(result==8)
  3543. {
  3544. return RESULT_LOGIN_DEVICE;
  3545. }
  3546. return RESULT_FALSE;
  3547. }
  3548. NSDictionary* objheader = [jsobj objectForKey:@"header"];
  3549. NSString* required_ver=[jsobj objectForKey:@"min_ver"] ;
  3550. user=[objheader objectForKey:@"username"] ;
  3551. DebugLog(@"required_ver=%@ ",required_ver);
  3552. // NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  3553. // NSString* versionNum =[infoDict valueForKey:@"CFBundleVersion"];
  3554. // versionNum = [NSString stringWithFormat:@"A%@",versionNum];
  3555. // int ibadge = [[objheader valueForKey:@"badge"] intValue];
  3556. // if([ibadge isEqual:[NSNull null]])
  3557. // strbadge=@"0";
  3558. // if(ibadge==nil)
  3559. // ibadge=@"0";
  3560. // if([strbadge isEqualToString:@"null"])
  3561. // strbadge=@"0";
  3562. // app.applicationIconBadgeNumber = ibadge;//[strbadge intValue];
  3563. // BOOL bigger = [RASingleton.sharedInstance.build compare:required_ver] ;
  3564. if([RASingleton.sharedInstance.build intValue]<[required_ver intValue])
  3565. return RESULT_VER_LOW;
  3566. // appDelegate.sessionid = [objheader valueForKey:@"sessionid"];
  3567. RASingleton.sharedInstance.user = user;
  3568. RASingleton.sharedInstance.password = password;
  3569. appDelegate.user_type = [[objheader valueForKey:@"user_type"] intValue];
  3570. appDelegate.user_icon =[objheader valueForKey:@"user_img"] ;
  3571. appDelegate.bLogin = true;
  3572. appDelegate.customer_type = [[objheader valueForKey:@"customer_login_type"] intValue];
  3573. if(appDelegate.user_type==USER_ROLE_CUSTOMER)
  3574. {
  3575. appDelegate.customerInfo = [[objheader objectForKeyedSubscript:@"customerInfo"] mutableCopy];
  3576. appDelegate.contact_id = [objheader valueForKey:@"contact_id"];
  3577. // appDelegate.order_code =[objheader valueForKey:@"orderCode"];
  3578. // appDelegate.order_status =[[objheader valueForKey:@"orderStatus"] intValue];
  3579. // [appDelegate SetSo:[objheader valueForKey:@"soId"]];
  3580. }
  3581. NSString* mode =[jsobj valueForKey:@"mode"] ;
  3582. [appDelegate SetMode:mode];
  3583. appDelegate.cart_count = [[objheader valueForKey:@"cart_count"] intValue];
  3584. appDelegate.wish_count =[[objheader valueForKey:@"wish_count"] intValue];
  3585. appDelegate.port_count =[[objheader valueForKey:@"portfolio_count"] intValue];
  3586. [appDelegate update_count_mark];
  3587. appDelegate.can_show_price =[[objheader valueForKey:@"can_show_price"] boolValue];
  3588. appDelegate.can_see_price =[[objheader valueForKey:@"can_see_price"] boolValue];
  3589. appDelegate.can_create_portfolio =[[objheader valueForKey:@"can_create_portfolio"] boolValue];
  3590. appDelegate.can_create_order =[[objheader valueForKey:@"can_create_order"] boolValue];
  3591. appDelegate.can_cancel_order =[[objheader valueForKey:@"can_cancel_order"] boolValue];
  3592. appDelegate.can_set_cart_price =[[objheader valueForKey:@"can_set_cart_price"] boolValue];
  3593. appDelegate.can_delete_order =[[objheader valueForKey:@"can_delete_order"] boolValue];
  3594. appDelegate.can_update_contact_info =[[objheader valueForKey:@"can_update_contact_info"] boolValue];
  3595. appDelegate.can_submit_order =[[objheader valueForKey:@"can_submit_order"] boolValue];
  3596. appDelegate.can_set_tearsheet_price =[[objheader valueForKey:@"can_set_tearsheet_price"] boolValue];
  3597. appDelegate.save_order_logout =[[objheader valueForKey:@"save_order_logout"] boolValue];
  3598. appDelegate.submit_order_logout =[[objheader valueForKey:@"submit_order_logout"] boolValue];
  3599. appDelegate.alert_sold_in_quantities = [[objheader valueForKey:@"alert_sold_in_quantities"] boolValue];
  3600. appDelegate.can_create_backorder = [[objheader valueForKey:@"can_create_backorder"] boolValue];
  3601. RASingleton.sharedInstance.ipad_perm =[objheader valueForKey:@"ipad_perm"] ;
  3602. NSString* strfilter = [objheader valueForKey:@"statusFilter"] ;
  3603. appDelegate.OrderFilter= [[RAConvertor string2dict:strfilter] mutableCopy];
  3604. [appDelegate set_main_button_panel];
  3605. if(appDelegate.user_type==USER_ROLE_CUSTOMER) {
  3606. // shop order status filter
  3607. NSString *shopOrderStatusFilterStr = [objheader valueForKey:@"shopOrderFilter"] ;
  3608. [RASingleton sharedInstance].shop_order_status_filter = [[RAConvertor string2dict:shopOrderStatusFilterStr] mutableCopy];
  3609. // Sales order status filter
  3610. NSString *salesOrderStatusFilterStr = [objheader valueForKey:@"purchaseOrderFilter"] ;
  3611. [RASingleton sharedInstance].sales_order_status_filter = [[RAConvertor string2dict:salesOrderStatusFilterStr] mutableCopy];
  3612. // specialInstruction
  3613. [RASingleton sharedInstance].specialInstruction = [objheader valueForKey:@"specialInstruction"];
  3614. //-价格类型
  3615. [RASingleton sharedInstance].npd_shop_price_type = [[objheader valueForKey:@"price_type"] integerValue];
  3616. // 权限
  3617. [RASingleton sharedInstance].permissions_price_setting = [[objheader valueForKey:@"can_set_price_formula"] boolValue];
  3618. [RASingleton sharedInstance].permissions_edit_order = [[objheader valueForKey:@"can_place_order"] boolValue];
  3619. [RASingleton sharedInstance].permissions_submit_order = [[objheader valueForKey:@"can_submit_order"] boolValue];
  3620. [RASingleton sharedInstance].permissions_merge_order = [[objheader valueForKey:@"can_merge_order"] boolValue];
  3621. [RASingleton sharedInstance].deliveryString = [objheader valueForKey:@"delivery_price"];
  3622. [[RASingleton sharedInstance] resetGlobalLock];
  3623. [RASingleton sharedInstance].customer_can_see_sales_Order = [[objheader valueForKey:@"can_see_salesorder"] boolValue];
  3624. [RASingleton sharedInstance].customerInfo = [objheader objectForKeyedSubscript:@"customerInfo"];
  3625. }
  3626. // DebugLog(@"sessionid=%@ ",appDelegate.sessionid);
  3627. // if ([[objheader valueForKey:@"update"] boolValue]==false)
  3628. // {
  3629. // // no update on the server;
  3630. // return RESULT_TRUE;
  3631. // }
  3632. // int Auth_InfoVer = [[objheader valueForKey:@"ver"] intValue];
  3633. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  3634. // [defaults removeObjectForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  3635. // [defaults setInteger:Auth_InfoVer forKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  3636. // [defaults synchronize];
  3637. //
  3638. // NSDictionary* objfuncs = [jsobj objectForKey:@"functions"];
  3639. // NSArray* keys= [objfuncs allKeys];
  3640. /*
  3641. db.setTransactionSuccessful();
  3642. db.endTransaction();
  3643. */
  3644. return RESULT_TRUE;
  3645. }
  3646. // NSDictionary *weatherInfo = [jsobj objectForKey:@"weatherinfo"];
  3647. // txtView.text = [NSString stringWithFormat:@"今天是 %@ %@ %@ 的天气状况是:%@ %@ ",[weatherInfo objectForKey:@"date_y"],[weatherInfo objectForKey:@"week"],[weatherInfo objectForKey:@"city"], [weatherInfo objectForKey:@"weather1"], [weatherInfo objectForKey:@"temp1"]];
  3648. // DebugLog(@"weatherInfo字典里面的内容为--》%@", weatherDic );
  3649. return RESULT_USERAUTH_ERROR;
  3650. }
  3651. //+(bool) IsNetworkAvailable
  3652. //{
  3653. //
  3654. // if (([Reachability reachabilityForInternetConnection].currentReachabilityStatus == NotReachable) &&
  3655. // ([Reachability reachabilityForLocalWiFi].currentReachabilityStatus == NotReachable))
  3656. // return false;
  3657. // return true;
  3658. //}
  3659. //+(NSString *)flattenHTML:(NSString *)html trimWhiteSpace:(BOOL)trim
  3660. //{
  3661. // NSScanner *theScanner = [NSScanner scannerWithString:html];
  3662. // NSString *text = nil;
  3663. //
  3664. // while ([theScanner isAtEnd] == NO) {
  3665. // // find start of tag
  3666. // [theScanner scanUpToString:@"<" intoString:NULL] ;
  3667. // // find end of tag
  3668. // [theScanner scanUpToString:@">" intoString:&text] ;
  3669. // // replace the found tag with a space
  3670. // //(you can filter multi-spaces out later if you wish)
  3671. // html = [html stringByReplacingOccurrencesOfString:
  3672. // [ NSString stringWithFormat:@"%@>", text]
  3673. // withString:@""];
  3674. // }
  3675. //
  3676. // return trim ? [html stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] : html;
  3677. //}
  3678. //
  3679. //+(NSString *)flattenURL:(NSString *)url trimWhiteSpace:(BOOL)trim
  3680. //{
  3681. // NSScanner *theScanner = [NSScanner scannerWithString:url];
  3682. // NSString *text = nil;
  3683. //
  3684. // while ([theScanner isAtEnd] == NO) {
  3685. // // find start of tag
  3686. // [theScanner scanUpToString:@"/" intoString:NULL] ;
  3687. // // find end of tag
  3688. // [theScanner scanUpToString:@"/" intoString:&text] ;
  3689. // // replace the found tag with a space
  3690. // //(you can filter multi-spaces out later if you wish)
  3691. // url = [url stringByReplacingOccurrencesOfString:
  3692. // [ NSString stringWithFormat:@"%@", text]
  3693. // withString:@""];
  3694. // }
  3695. //
  3696. // return trim ? [url stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] : url;
  3697. //}
  3698. + (NSDictionary *)set_npd_shop_price_type:(NSInteger)priceType {
  3699. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  3700. __block AppDelegate *appDelegate = nil;
  3701. dispatch_sync(dispatch_get_main_queue(), ^{
  3702. //some UI methods ej
  3703. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3704. });
  3705. if(RASingleton.sharedInstance.user!=nil)
  3706. [dic setValue:RASingleton.sharedInstance.user forKey:@"user"];
  3707. if(RASingleton.sharedInstance.password!=nil)
  3708. [dic setValue:RASingleton.sharedInstance.password forKey:@"password"];
  3709. [dic setValue:[NSString stringWithFormat:@"%ld",priceType] forKey:@"price_type"];
  3710. [dic setObject:ScreenCodePriceSetting forKey:kScreenName];
  3711. NSData* json=nil;
  3712. if(appDelegate.offline_mode)
  3713. {
  3714. return [OLDataProvider offline_notimpl];
  3715. }
  3716. else
  3717. {
  3718. if(![self IsNetworkAvailable])
  3719. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3720. json = [RANetwork get_json:URL_SET_PRICE_TYPE parameters:dic];
  3721. }
  3722. if(json!=nil)
  3723. {
  3724. NSError *error=nil;
  3725. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3726. return jsobj;
  3727. }
  3728. return nil;
  3729. }
  3730. + (NSDictionary *)get_npd_shop_givenPrice {
  3731. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  3732. __block AppDelegate *appDelegate = nil;
  3733. dispatch_sync(dispatch_get_main_queue(), ^{
  3734. //some UI methods ej
  3735. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3736. });
  3737. if(RASingleton.sharedInstance.user!=nil)
  3738. [dic setValue:RASingleton.sharedInstance.user forKey:@"user"];
  3739. if(RASingleton.sharedInstance.password!=nil)
  3740. [dic setValue:RASingleton.sharedInstance.password forKey:@"password"];
  3741. [dic setObject:ScreenCodeCategoryPrice forKey:kScreenName];
  3742. NSData* json=nil;
  3743. if(appDelegate.offline_mode)
  3744. {
  3745. return [OLDataProvider offline_notimpl];
  3746. }
  3747. else
  3748. {
  3749. if(![self IsNetworkAvailable])
  3750. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3751. json = [RANetwork get_json:URL_GET_CIVEN_PRICE parameters:dic];
  3752. }
  3753. if(json!=nil)
  3754. {
  3755. NSError *error=nil;
  3756. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3757. return jsobj;
  3758. }
  3759. return nil;
  3760. }
  3761. + (NSDictionary *)set_npd_shop_givenPrice:(NSMutableDictionary *)params {
  3762. __block AppDelegate *appDelegate = nil;
  3763. dispatch_sync(dispatch_get_main_queue(), ^{
  3764. //some UI methods ej
  3765. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3766. });
  3767. if(RASingleton.sharedInstance.user!=nil)
  3768. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  3769. if(RASingleton.sharedInstance.password!=nil)
  3770. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  3771. [params setObject:ScreenCodeSetCatetoryPrice forKey:kScreenName];
  3772. NSData* json=nil;
  3773. if(appDelegate.offline_mode)
  3774. {
  3775. return [OLDataProvider offline_notimpl];
  3776. }
  3777. else
  3778. {
  3779. if(![self IsNetworkAvailable])
  3780. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3781. json = [RANetwork get_json:URL_SET_GIVEN_PRICE parameters:params];
  3782. }
  3783. if(json!=nil)
  3784. {
  3785. NSError *error=nil;
  3786. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3787. return jsobj;
  3788. }
  3789. return nil;
  3790. }
  3791. + (NSDictionary *)merge_order:(NSMutableDictionary *)params {
  3792. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  3793. __block AppDelegate *appDelegate = nil;
  3794. dispatch_sync(dispatch_get_main_queue(), ^{
  3795. //some UI methods ej
  3796. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3797. });
  3798. if(RASingleton.sharedInstance.user!=nil)
  3799. [dic setValue:RASingleton.sharedInstance.user forKey:@"user"];
  3800. if(RASingleton.sharedInstance.password!=nil)
  3801. [dic setValue:RASingleton.sharedInstance.password forKey:@"password"];
  3802. [dic setValue:[params objectForKey:@"order_ids"] forKey:@"order_ids"];
  3803. [dic setValue:[params objectForKey:@"targetOrderId"] forKey:@"targetOrderId"];
  3804. [dic setValue:[params objectForKey:@"customerInfo"] forKey:@"customerInfo"];
  3805. [dic setObject:ScreenCodeOrderList forKey:kScreenName];
  3806. NSData* json=nil;
  3807. if(appDelegate.offline_mode)
  3808. {
  3809. return [OLDataProvider offline_notimpl];
  3810. }
  3811. else
  3812. {
  3813. if(![self IsNetworkAvailable])
  3814. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3815. json=[self get_json:URL_SET_MERGE_ORDER parameters:dic];
  3816. }
  3817. if(json!=nil)
  3818. {
  3819. NSError *error=nil;
  3820. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3821. return jsobj;
  3822. }
  3823. else
  3824. return nil;
  3825. }
  3826. //+ (NSDictionary *)lock_order:(NSString *)oderCode
  3827. //{
  3828. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3829. // __block AppDelegate *appDelegate = nil;
  3830. //
  3831. // dispatch_sync(dispatch_get_main_queue(), ^{
  3832. // //some UI methods ej
  3833. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3834. // });
  3835. // if(RASingleton.sharedInstance.user!=nil)
  3836. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  3837. //
  3838. // if(RASingleton.sharedInstance.password!=nil)
  3839. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  3840. //
  3841. // [params setValue:oderCode forKey:@"orderCode"];
  3842. //
  3843. // NSData* json=nil;
  3844. // if(appDelegate.offline_mode)
  3845. // {
  3846. // json=[OLDataProvider offline_editorder:params];
  3847. //
  3848. // }
  3849. // else
  3850. // {
  3851. // if(![self IsNetworkAvailable])
  3852. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3853. //
  3854. // json=[self get_json:URL_OPEN_ORDER parameters:params];
  3855. // }
  3856. // if(json!=nil)
  3857. // {
  3858. // NSError *error=nil;
  3859. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3860. //
  3861. // return jsobj;
  3862. // }
  3863. // else
  3864. // return nil;
  3865. //}
  3866. + (NSDictionary *)quoteOrder:(NSString *)so_id emailAddr:(NSString *)addr {
  3867. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  3868. __block AppDelegate *appDelegate = nil;
  3869. dispatch_sync(dispatch_get_main_queue(), ^{
  3870. //some UI methods ej
  3871. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3872. });
  3873. if(RASingleton.sharedInstance.user!=nil)
  3874. [dic setValue:RASingleton.sharedInstance.user forKey:@"user"];
  3875. if(RASingleton.sharedInstance.password!=nil)
  3876. [dic setValue:RASingleton.sharedInstance.password forKey:@"password"];
  3877. [dic setValue:so_id forKey:@"orderCode"];
  3878. [dic setValue:addr forKey:@"email"];
  3879. [dic setObject:ScreenCodeCart forKey:kScreenName];
  3880. if (appDelegate.customerInfo) {
  3881. NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  3882. if (customer_cid) {
  3883. [dic setValue:customer_cid forKey:@"contactId"];
  3884. }
  3885. }
  3886. NSData* json=nil;
  3887. if(appDelegate.offline_mode)
  3888. {
  3889. return [OLDataProvider offline_notimpl];
  3890. }
  3891. else
  3892. {
  3893. if(![self IsNetworkAvailable])
  3894. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3895. json = [RANetwork get_json:URL_EMAIL_CART parameters:dic];
  3896. }
  3897. if(json!=nil)
  3898. {
  3899. NSError *error=nil;
  3900. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3901. return jsobj;
  3902. }
  3903. return @{@"result" : @(RESULT_FALSE)};
  3904. }
  3905. + (NSDictionary *)notifyModel:(NSString *)modelID emailAddr:(NSString *)addr withScreen:(NSString *)screenName{
  3906. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  3907. __block AppDelegate *appDelegate = nil;
  3908. dispatch_sync(dispatch_get_main_queue(), ^{
  3909. //some UI methods ej
  3910. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3911. });
  3912. if(RASingleton.sharedInstance.user!=nil)
  3913. [dic setValue:RASingleton.sharedInstance.user forKey:@"user"];
  3914. if(RASingleton.sharedInstance.password!=nil)
  3915. [dic setValue:RASingleton.sharedInstance.password forKey:@"password"];
  3916. if (appDelegate.user_type == USER_ROLE_EMPLOYEE && appDelegate.customerInfo) {
  3917. NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  3918. if (customer_cid) {
  3919. [dic setValue:customer_cid forKey:@"contactId"];
  3920. }
  3921. }
  3922. [dic setObject:screenName forKey:kScreenName];
  3923. [dic setValue:modelID forKey:@"productId"];
  3924. if (addr) { // 弹框输入
  3925. [dic setValue:addr forKey:@"email"];
  3926. } else {
  3927. // employee选择了Contact,并且Contact有Email
  3928. // if (appDelegate.user_type == USER_ROLE_EMPLOYEE && appDelegate.customerInfo) {
  3929. // NSString *email = [appDelegate.customerInfo objectForKey:@"customer_email"];
  3930. // if (email) {
  3931. // [dic setValue:email forKey:@"email"];
  3932. // }
  3933. // }
  3934. }
  3935. NSData* json=nil;
  3936. if(appDelegate.offline_mode)
  3937. {
  3938. return [OLDataProvider offline_notimpl];
  3939. }
  3940. else
  3941. {
  3942. if(![self IsNetworkAvailable])
  3943. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3944. json = [RANetwork get_json:URL_NOTIFY_ME parameters:dic];
  3945. }
  3946. if(json!=nil)
  3947. {
  3948. NSError *error=nil;
  3949. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3950. return jsobj;
  3951. }
  3952. return @{@"result" : @(RESULT_FALSE)};
  3953. }
  3954. + (NSDictionary *)quoteWishlist2EmailAddr:(NSString *)addr {
  3955. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  3956. __block AppDelegate *appDelegate = nil;
  3957. dispatch_sync(dispatch_get_main_queue(), ^{
  3958. //some UI methods ej
  3959. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3960. });
  3961. if(RASingleton.sharedInstance.user!=nil)
  3962. [dic setValue:RASingleton.sharedInstance.user forKey:@"user"];
  3963. if(RASingleton.sharedInstance.password!=nil)
  3964. [dic setValue:RASingleton.sharedInstance.password forKey:@"password"];
  3965. [dic setValue:addr forKey:@"email"];
  3966. [dic setObject:ScreenCodeWishList forKey:kScreenName];
  3967. // if (appDelegate.customerInfo) {
  3968. // NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  3969. // if (customer_cid) {
  3970. // [dic setValue:customer_cid forKey:@"contactId"];
  3971. // }
  3972. // }
  3973. NSData* json=nil;
  3974. if(appDelegate.offline_mode)
  3975. {
  3976. return [OLDataProvider offline_notimpl];
  3977. }
  3978. else
  3979. {
  3980. if(![self IsNetworkAvailable])
  3981. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3982. json = [RANetwork get_json:URL_EMAIL_WISHLIST parameters:dic];
  3983. }
  3984. if(json!=nil)
  3985. {
  3986. NSError *error=nil;
  3987. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3988. return jsobj;
  3989. }
  3990. return @{@"result" : @(RESULT_FALSE)};
  3991. }
  3992. + (NSDictionary *)movetobackorder:(NSString *)cart_item_id {
  3993. if (cart_item_id == nil || cart_item_id.length < 1) {
  3994. return @{@"result" : @(RESULT_FALSE),@"err_msg" : @"invalided product"};
  3995. }
  3996. __block AppDelegate *appDelegate = nil;
  3997. dispatch_sync(dispatch_get_main_queue(), ^{
  3998. //some UI methods ej
  3999. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4000. });
  4001. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  4002. if(RASingleton.sharedInstance.user!=nil)
  4003. [dic setValue:RASingleton.sharedInstance.user forKey:@"user"];
  4004. if(RASingleton.sharedInstance.password!=nil)
  4005. [dic setValue:RASingleton.sharedInstance.password forKey:@"password"];
  4006. [dic setValue:cart_item_id forKey:@"orderitem_id"];
  4007. [dic setValue:appDelegate.order_code forKey:@"order_code"];
  4008. [dic setObject:ScreenCodeCart forKey:kScreenName];
  4009. if(![self IsNetworkAvailable])
  4010. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4011. NSData *json = [RANetwork get_json:URL_MOVE_TO_BACK_ORDER parameters:dic];
  4012. if(json!=nil)
  4013. {
  4014. NSError *error=nil;
  4015. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4016. return jsobj;
  4017. }
  4018. return @{@"result" : @(RESULT_FALSE)};
  4019. }
  4020. + (NSDictionary*)request_hangTag:(NSString *)group {
  4021. #ifdef BUILD_UWAVER
  4022. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4023. __block AppDelegate *appDelegate = nil;
  4024. dispatch_sync(dispatch_get_main_queue(), ^{
  4025. //some UI methods ej
  4026. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4027. });
  4028. if(RASingleton.sharedInstance.user!=nil)
  4029. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  4030. if(appDelegate.contact_id!=nil)
  4031. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4032. if(RASingleton.sharedInstance.password!=nil)
  4033. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  4034. if (group) {
  4035. [params setValue:group forKey:@"groupName"];
  4036. }
  4037. NSString * uuid= [[NSUUID UUID] UUIDString];
  4038. params[@"resultSerial"]=uuid;
  4039. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  4040. NSData* json = nil;
  4041. if(appDelegate.offline_mode)
  4042. {
  4043. return [OLDataProvider offline_notimpl];
  4044. } else {
  4045. if(![self IsNetworkAvailable])
  4046. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4047. json = [self get_json:URL_CREATE_HANG_TAG parameters:params];
  4048. }
  4049. if(json==nil)
  4050. return nil;
  4051. NSError *error=nil;
  4052. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4053. return jsobj;
  4054. #else
  4055. return nil;
  4056. #endif
  4057. }
  4058. #pragma mark 2020 new interface
  4059. // 新接口逐步替换以前的网络请求,2020
  4060. +(void)request_home:(int) price_template customid:(int) customid completionHandler:(resultHandler)result
  4061. {
  4062. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4063. AppDelegate *appDelegate = nil;
  4064. //some UI methods ej
  4065. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4066. if(RASingleton.sharedInstance.user!=nil)
  4067. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  4068. if(appDelegate.contact_id!=nil)
  4069. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4070. if(RASingleton.sharedInstance.password!=nil)
  4071. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  4072. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  4073. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  4074. [params setObject:ScreenCodeHomeView forKey:kScreenName];
  4075. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  4076. if(appDelegate.offline_mode)
  4077. {
  4078. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4079. NSMutableDictionary* json = [[OLDataProvider offline_home] mutableCopy];
  4080. dispatch_async(dispatch_get_main_queue(), ^{
  4081. result(json);
  4082. });
  4083. });
  4084. return;
  4085. }
  4086. [self request_interface:URL_LOAD_HOME parameters:params err_record_url:nil completionHandler:result retry:0];
  4087. return;
  4088. }
  4089. +(void)request_category:(resultHandler)result
  4090. {
  4091. // DebugLog(@"@@@@@@@@@@@@@@@@@@@LOADING CATEGORY MENU");
  4092. AppDelegate *appDelegate = nil;
  4093. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4094. if(appDelegate.offline_mode)
  4095. {
  4096. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4097. NSMutableDictionary* json = [[OLDataProvider offline_category_menu] mutableCopy];
  4098. dispatch_async(dispatch_get_main_queue(), ^{
  4099. result(json);
  4100. });
  4101. });
  4102. return;
  4103. }
  4104. [self request_interface:URL_REQUEST_CATMENU parameters:[NSMutableDictionary new] err_record_url:nil completionHandler:result retry:0];
  4105. //
  4106. // if(![self IsNetworkAvailable])
  4107. // {
  4108. // DebugLog(@"NET ERR");
  4109. //
  4110. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4111. // // return nil;
  4112. // }
  4113. //
  4114. // NSData* json=[self get_json:URL_REQUEST_CATMENU parameters:nil];
  4115. // //if(json==nil)
  4116. //
  4117. //
  4118. // if(json==nil)
  4119. // return nil;
  4120. // NSError *error=nil;
  4121. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4122. // return jsobj;
  4123. }
  4124. +(void)request_categorylist: (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 completionHandler:(resultHandler)result
  4125. {
  4126. AppDelegate *appDelegate = nil;
  4127. //some UI methods ej
  4128. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4129. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4130. if(RASingleton.sharedInstance.user!=nil)
  4131. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  4132. if(appDelegate.contact_id!=nil)
  4133. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4134. if(RASingleton.sharedInstance.password!=nil)
  4135. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  4136. if(appDelegate.order_code!=nil)
  4137. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  4138. [params setValue:alert forKey:@"alert"];
  4139. [params setValue:qty forKey:@"sold_by_qty"];
  4140. [params setValue:available forKey:@"available"];
  4141. [params setValue:price forKey:@"price"];
  4142. [params setValue:bestseller forKey:@"bestseller"];
  4143. [params setValue:modelname forKey:@"modelName"];
  4144. [params setValue:modeldescrip forKey:@"modelDescription"];
  4145. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  4146. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  4147. [params setValue:category forKey:@"category"];
  4148. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  4149. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  4150. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  4151. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  4152. [params setValue:filter forKey:@"filter"];
  4153. [params setValue:keyword forKey:@"keyword"];
  4154. [params setObject:ScreenCodeCategory forKey:kScreenName];
  4155. if (alert) {
  4156. [params setObject:@"Filter" forKey:kAction];
  4157. }
  4158. if ([RASingleton sharedInstance].homeItemClick) {
  4159. [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
  4160. [RASingleton sharedInstance].homeItemClick = NO;
  4161. NSDictionary *extra = @{@"CoverName" : [RASingleton sharedInstance].homeClickedItemName};
  4162. [RASingleton sharedInstance].homeClickedItemName = nil;
  4163. [params setObject:extra forKey:kExtra];
  4164. }
  4165. if(appDelegate.offline_mode)
  4166. {
  4167. // [OLDataProvider offline_category:params completionHandler:result];
  4168. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4169. NSMutableDictionary* json = [[OLDataProvider offline_category:params] mutableCopy];
  4170. dispatch_async(dispatch_get_main_queue(), ^{
  4171. result(json);
  4172. });
  4173. });
  4174. return;
  4175. }
  4176. [self request_interface:URL_CATEGORY parameters:params err_record_url:nil completionHandler:result retry:0];
  4177. return ;
  4178. //
  4179. // if(![self IsNetworkAvailable])
  4180. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4181. //
  4182. // NSData* json=[self get_json:URL_CATEGORY parameters:params];
  4183. // if(json==nil)
  4184. // return nil;
  4185. // NSError *error=nil;
  4186. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4187. // return jsobj;
  4188. //
  4189. }
  4190. +(void)request_modeldetail: (NSString* ) item_id model_name:(NSString*) model_name upc_code:(NSString*) upc_code category_id:(NSString*) category_id use_name :(bool) use_name use_upc :(bool) use_upc groupName:(NSString *)groupName completionHandler:(resultHandler)result
  4191. {
  4192. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4193. AppDelegate *appDelegate = nil;
  4194. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4195. if(RASingleton.sharedInstance.user!=nil)
  4196. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  4197. if(appDelegate.contact_id!=nil)
  4198. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4199. if(RASingleton.sharedInstance.password!=nil)
  4200. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  4201. if(appDelegate.order_code!=nil)
  4202. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  4203. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  4204. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  4205. if(use_name)
  4206. [params setValue:model_name forKey:@"product_name"];
  4207. else
  4208. if(use_upc){
  4209. params[@"search_upc"]=@true;
  4210. [params setValue:upc_code forKey:@"upc_code"];
  4211. }
  4212. else
  4213. [params setValue:item_id forKey:@"product_id"];
  4214. [params setValue:category_id forKey:@"category"];
  4215. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  4216. [params setObject:@"Open A Model" forKey:kAction];
  4217. if (model_name) {
  4218. NSDictionary *extra = @{@"ModelName" : model_name};
  4219. [params setObject:extra forKey:kExtra];
  4220. }
  4221. if (groupName.length > 0) {
  4222. [params setObject:groupName forKey:@"groupName"];
  4223. }
  4224. if(appDelegate.offline_mode)
  4225. {
  4226. [OLDataProvider offline_model:params completionHandler:result];
  4227. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4228. // NSMutableDictionary* json = [[OLDataProvider offline_model:params] mutableCopy];
  4229. // dispatch_async(dispatch_get_main_queue(), ^{
  4230. // result(json);
  4231. // });
  4232. // });
  4233. return;
  4234. }
  4235. [self request_interface:URL_ITEM_DETAIL parameters:params err_record_url:nil completionHandler:result retry:0];
  4236. //
  4237. // if(appDelegate.offline_mode)
  4238. // return [OLDataProvider offline_model:params];
  4239. //
  4240. // if(![self IsNetworkAvailable])
  4241. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4242. //
  4243. // NSData* json=[self get_json:URL_ITEM_DETAIL parameters:params];
  4244. // if(json==nil)
  4245. // return nil;
  4246. // NSError *error=nil;
  4247. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4248. // return jsobj;
  4249. }
  4250. +(void)request_search:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull completionHandler:(resultHandler)result
  4251. {
  4252. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4253. AppDelegate *appDelegate = nil;
  4254. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4255. if(RASingleton.sharedInstance.user!=nil)
  4256. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  4257. if(appDelegate.contact_id!=nil)
  4258. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4259. if(RASingleton.sharedInstance.password!=nil)
  4260. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  4261. if(appDelegate.order_code!=nil)
  4262. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  4263. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  4264. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  4265. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  4266. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  4267. // [params setValue:filter forKey:@"filter"];
  4268. [params setValue:keywords forKey:@"keyword"];
  4269. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  4270. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  4271. if(matchfull)
  4272. [params setValue:@"true" forKey:@"exactMatch"];
  4273. else
  4274. [params setValue:@"false" forKey:@"exactMatch"];
  4275. [params setObject:ScreenCodeSearch forKey:kScreenName];
  4276. if (keywords) {
  4277. [params setObject:@"Search" forKey:kAction];
  4278. }
  4279. if(appDelegate.offline_mode)
  4280. {
  4281. // [OLDataProvider offline_search:params completionHandler:result];
  4282. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4283. NSMutableDictionary* json = [[OLDataProvider offline_search:params] mutableCopy];
  4284. dispatch_async(dispatch_get_main_queue(), ^{
  4285. result(json);
  4286. });
  4287. });
  4288. return;
  4289. }
  4290. [self request_interface:URL_SEARCH parameters:params err_record_url:nil completionHandler:result retry:0];
  4291. // if(appDelegate.offline_mode)
  4292. // {
  4293. // return [OLDataProvider offline_search:params];
  4294. // }
  4295. // if(![self IsNetworkAvailable])
  4296. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4297. //
  4298. // NSData* json=[self get_json:URL_SEARCH parameters:params];
  4299. // if(json==nil)
  4300. // return nil;
  4301. // NSError *error=nil;
  4302. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4303. // return jsobj;
  4304. }
  4305. +(void)request_login: (NSString*) user password:(NSString*) password completionHandler:(resultHandler)result
  4306. {
  4307. // if(![ApexMobileNetwork IsHostAvailable:URL_UPDATE_AUTH])
  4308. // return RESULT_NET_ERROR;
  4309. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  4310. long ver =[defaults integerForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  4311. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4312. AppDelegate *appDelegate = nil;
  4313. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4314. if(RASingleton.sharedInstance.duid !=nil)
  4315. [params setValue:RASingleton.sharedInstance.duid forKey:@"udid"];
  4316. [params setValue:@"handset_login" forKey:@"action"];
  4317. // [headers setValue:[NSString stringWithFormat:@"%d",dataLength] forKey:@"Content-Length"];
  4318. [params setValue:user forKey:@"user"];
  4319. [params setValue:password forKey:@"password"];
  4320. [params setValue:[NSString stringWithFormat:@"%ld",ver] forKey:@"auth_ver"];
  4321. #ifdef TEST
  4322. [params setValue:@"true" forKey:@"is_debug"];
  4323. #else
  4324. [params setValue:@"false" forKey:@"is_debug"];
  4325. #endif
  4326. [params setObject:ScreenCodeLoginView forKey:kScreenName];
  4327. [params setObject:@"Login" forKey:kAction];
  4328. if(appDelegate.offline_mode)
  4329. {
  4330. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4331. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_login:params]] mutableCopy];
  4332. dispatch_async(dispatch_get_main_queue(), ^{
  4333. int ret = [self parse_logininfo:json user:user password:password] ;
  4334. NSMutableDictionary * retjson = [NSMutableDictionary new];
  4335. retjson[@"result"]= [NSNumber numberWithInt:ret];
  4336. result(retjson);
  4337. });
  4338. });
  4339. return;
  4340. }
  4341. NSString* url;
  4342. bool scan_guest = false;
  4343. #ifdef SCANNER_ORDER
  4344. params[@"site_name"]=[RADataProvider getSiteName];
  4345. params[@"_method"]=@"login";
  4346. url = [appDelegate.address stringByAppendingPathComponent:URL_UPDATE_AUTH];
  4347. if([user.uppercaseString isEqualToString:@"GUEST"]&&[password.uppercaseString isEqualToString:@"GUEST"])
  4348. scan_guest = true;
  4349. #else
  4350. url = URL_UPDATE_AUTH;
  4351. #endif
  4352. if(scan_guest)
  4353. {
  4354. [OLDataProvider realguestLogin];
  4355. // int ret = [self parse_logininfo:chresult user:user password:password] ;
  4356. NSMutableDictionary * retjson = [NSMutableDictionary new];
  4357. retjson[@"result"]= [NSNumber numberWithInt:RESULT_TRUE];
  4358. result(retjson);
  4359. }
  4360. else
  4361. {
  4362. [self request_interface:url parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *chresult) {
  4363. int ret = [self parse_logininfo:chresult user:user password:password] ;
  4364. NSMutableDictionary * retjson = [NSMutableDictionary new];
  4365. retjson[@"result"]= [NSNumber numberWithInt:ret];
  4366. result(retjson);
  4367. } retry:0];
  4368. }
  4369. //
  4370. // NSData* json= nil;
  4371. // if(appDelegate.offline_mode)
  4372. // {
  4373. // json= [OLDataProvider offline_login:params] ;
  4374. //
  4375. // }
  4376. // else
  4377. // {
  4378. // if(![self IsNetworkAvailable])
  4379. // return RESULT_NET_NOTAVAILABLE;
  4380. // json =[self get_json:URL_UPDATE_AUTH parameters:params];
  4381. //
  4382. // }
  4383. //
  4384. // if(json==nil)
  4385. // return RESULT_NET_ERROR;
  4386. //
  4387. // int ret = [self parse_authinfo:json user:user password:password];
  4388. // DebugLog(@"parse_authinfo return %d ",ret);
  4389. //
  4390. //
  4391. // return ret;
  4392. //
  4393. }
  4394. +(int)parse_logininfo : (NSMutableDictionary *) jsobj user:(NSString*) user password:(NSString*) password
  4395. {
  4396. // DebugLog(@"parse_authinfo");
  4397. // NSError *error=nil;
  4398. //
  4399. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4400. if(jsobj)
  4401. {
  4402. AppDelegate *appDelegate = nil;
  4403. //some UI methods ej
  4404. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4405. int result = [[jsobj valueForKey:@"result"] intValue];
  4406. if (result<0)
  4407. return result;
  4408. if(result!=AP_USER_AUTH&& result!=9)
  4409. {
  4410. DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
  4411. // [appDelegate Logout];
  4412. if(result==8)
  4413. {
  4414. return RESULT_LOGIN_DEVICE;
  4415. }
  4416. return RESULT_FALSE;
  4417. }
  4418. NSDictionary* objheader = [jsobj objectForKey:@"header"];
  4419. NSString* required_ver=[jsobj objectForKey:@"min_ver"] ;
  4420. user=[objheader objectForKey:@"username"] ;
  4421. DebugLog(@"required_ver=%@ ",required_ver);
  4422. // NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  4423. // NSString* versionNum =[infoDict valueForKey:@"CFBundleVersion"];
  4424. // versionNum = [NSString stringWithFormat:@"A%@",versionNum];
  4425. // int ibadge = [[objheader valueForKey:@"badge"] intValue];
  4426. // if([ibadge isEqual:[NSNull null]])
  4427. // strbadge=@"0";
  4428. // if(ibadge==nil)
  4429. // ibadge=@"0";
  4430. // if([strbadge isEqualToString:@"null"])
  4431. // strbadge=@"0";
  4432. // app.applicationIconBadgeNumber = ibadge;//[strbadge intValue];
  4433. // BOOL bigger = [RASingleton.sharedInstance.build compare:required_ver] ;
  4434. #ifndef SCANNER_ORDER
  4435. if([RASingleton.sharedInstance.build intValue]<[required_ver intValue])
  4436. return RESULT_VER_LOW;
  4437. #endif
  4438. // appDelegate.sessionid = [objheader valueForKey:@"sessionid"];
  4439. RASingleton.sharedInstance.user = user;
  4440. RASingleton.sharedInstance.password = password;
  4441. appDelegate.user_type = [[objheader valueForKey:@"user_type"] intValue];
  4442. appDelegate.user_icon =[objheader valueForKey:@"user_img"] ;
  4443. appDelegate.bLogin = true;
  4444. appDelegate.customer_type = [[objheader valueForKey:@"customer_login_type"] intValue];
  4445. #ifdef SCANNER_ORDER
  4446. appDelegate.available_price_group = objheader[@"price_group"];
  4447. [RADataProvider default_price_group];
  4448. #endif
  4449. if(appDelegate.user_type==USER_ROLE_CUSTOMER)
  4450. {
  4451. appDelegate.customerInfo = [[objheader objectForKeyedSubscript:@"customerInfo"] mutableCopy];
  4452. appDelegate.contact_id = [objheader valueForKey:@"contact_id"];
  4453. // appDelegate.order_code =[objheader valueForKey:@"orderCode"];
  4454. // appDelegate.order_status =[[objheader valueForKey:@"orderStatus"] intValue];
  4455. // [appDelegate SetSo:[objheader valueForKey:@"soId"]];
  4456. }
  4457. NSString* mode =[jsobj valueForKey:@"mode"] ;
  4458. [appDelegate SetMode:mode];
  4459. appDelegate.cart_count = [[objheader valueForKey:@"cart_count"] intValue];
  4460. appDelegate.wish_count =[[objheader valueForKey:@"wish_count"] intValue];
  4461. appDelegate.port_count =[[objheader valueForKey:@"portfolio_count"] intValue];
  4462. [appDelegate update_count_mark];
  4463. appDelegate.can_show_price =[[objheader valueForKey:@"can_show_price"] boolValue];
  4464. appDelegate.can_see_price =[[objheader valueForKey:@"can_see_price"] boolValue];
  4465. appDelegate.can_create_portfolio =[[objheader valueForKey:@"can_create_portfolio"] boolValue];
  4466. appDelegate.can_create_order =[[objheader valueForKey:@"can_create_order"] boolValue];
  4467. appDelegate.can_cancel_order =[[objheader valueForKey:@"can_cancel_order"] boolValue];
  4468. appDelegate.can_set_cart_price =[[objheader valueForKey:@"can_set_cart_price"] boolValue];
  4469. appDelegate.can_delete_order =[[objheader valueForKey:@"can_delete_order"] boolValue];
  4470. appDelegate.can_update_contact_info =[[objheader valueForKey:@"can_update_contact_info"] boolValue];
  4471. appDelegate.can_submit_order =[[objheader valueForKey:@"can_submit_order"] boolValue];
  4472. appDelegate.can_set_tearsheet_price =[[objheader valueForKey:@"can_set_tearsheet_price"] boolValue];
  4473. appDelegate.save_order_logout =[[objheader valueForKey:@"save_order_logout"] boolValue];
  4474. appDelegate.submit_order_logout =[[objheader valueForKey:@"submit_order_logout"] boolValue];
  4475. appDelegate.alert_sold_in_quantities = [[objheader valueForKey:@"alert_sold_in_quantities"] boolValue];
  4476. appDelegate.can_create_backorder = [[objheader valueForKey:@"can_create_backorder"] boolValue];
  4477. RASingleton.sharedInstance.ipad_perm =[objheader valueForKey:@"ipad_perm"] ;
  4478. NSString* strfilter = [objheader valueForKey:@"statusFilter"] ;
  4479. appDelegate.OrderFilter= [[RAConvertor string2dict:strfilter] mutableCopy];
  4480. [appDelegate set_main_button_panel];
  4481. if(appDelegate.user_type==USER_ROLE_CUSTOMER) {
  4482. // shop order status filter
  4483. NSString *shopOrderStatusFilterStr = [objheader valueForKey:@"shopOrderFilter"] ;
  4484. [RASingleton sharedInstance].shop_order_status_filter = [[RAConvertor string2dict:shopOrderStatusFilterStr] mutableCopy];
  4485. // Sales order status filter
  4486. NSString *salesOrderStatusFilterStr = [objheader valueForKey:@"purchaseOrderFilter"] ;
  4487. [RASingleton sharedInstance].sales_order_status_filter = [[RAConvertor string2dict:salesOrderStatusFilterStr] mutableCopy];
  4488. // specialInstruction
  4489. [RASingleton sharedInstance].specialInstruction = [objheader valueForKey:@"specialInstruction"];
  4490. //-价格类型
  4491. [RASingleton sharedInstance].npd_shop_price_type = [[objheader valueForKey:@"price_type"] integerValue];
  4492. // 权限
  4493. [RASingleton sharedInstance].permissions_price_setting = [[objheader valueForKey:@"can_set_price_formula"] boolValue];
  4494. [RASingleton sharedInstance].permissions_edit_order = [[objheader valueForKey:@"can_place_order"] boolValue];
  4495. [RASingleton sharedInstance].permissions_submit_order = [[objheader valueForKey:@"can_submit_order"] boolValue];
  4496. [RASingleton sharedInstance].permissions_merge_order = [[objheader valueForKey:@"can_merge_order"] boolValue];
  4497. [RASingleton sharedInstance].deliveryString = [objheader valueForKey:@"delivery_price"];
  4498. [[RASingleton sharedInstance] resetGlobalLock];
  4499. [RASingleton sharedInstance].customer_can_see_sales_Order = [[objheader valueForKey:@"can_see_salesorder"] boolValue];
  4500. [RASingleton sharedInstance].customerInfo = [objheader objectForKeyedSubscript:@"customerInfo"];
  4501. }
  4502. // DebugLog(@"sessionid=%@ ",appDelegate.sessionid);
  4503. // if ([[objheader valueForKey:@"update"] boolValue]==false)
  4504. // {
  4505. // // no update on the server;
  4506. // return RESULT_TRUE;
  4507. // }
  4508. // int Auth_InfoVer = [[objheader valueForKey:@"ver"] intValue];
  4509. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  4510. // [defaults removeObjectForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  4511. // [defaults setInteger:Auth_InfoVer forKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  4512. // [defaults synchronize];
  4513. //
  4514. // NSDictionary* objfuncs = [jsobj objectForKey:@"functions"];
  4515. // NSArray* keys= [objfuncs allKeys];
  4516. /*
  4517. db.setTransactionSuccessful();
  4518. db.endTransaction();
  4519. */
  4520. return RESULT_TRUE;
  4521. }
  4522. // NSDictionary *weatherInfo = [jsobj objectForKey:@"weatherinfo"];
  4523. // txtView.text = [NSString stringWithFormat:@"今天是 %@ %@ %@ 的天气状况是:%@ %@ ",[weatherInfo objectForKey:@"date_y"],[weatherInfo objectForKey:@"week"],[weatherInfo objectForKey:@"city"], [weatherInfo objectForKey:@"weather1"], [weatherInfo objectForKey:@"temp1"]];
  4524. // DebugLog(@"weatherInfo字典里面的内容为--》%@", weatherDic );
  4525. return RESULT_USERAUTH_ERROR;
  4526. }
  4527. +(void)request_contactlist:(int) offset limit:(int)limit keywords:(NSString*) keywords type:(NSString*) contact_type adv_search:(NSDictionary*)upparams completionHandler:(resultHandler)result
  4528. {
  4529. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4530. if(upparams!=nil)
  4531. params = [upparams mutableCopy];
  4532. AppDelegate *appDelegate = nil;
  4533. //some UI methods ej
  4534. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4535. if(RASingleton.sharedInstance.user!=nil)
  4536. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  4537. if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  4538. [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  4539. else
  4540. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4541. if(RASingleton.sharedInstance.password!=nil)
  4542. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  4543. [params setValue:[NSString stringWithFormat:@"%d",offset ] forKey:@"offset"];
  4544. [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  4545. [params setValue:contact_type forKey:@"contactType"];
  4546. [params setValue:keywords forKey:@"keyword"];
  4547. [params setObject:ScreenCodeAccount forKey:kScreenName];
  4548. if (keywords) {
  4549. [params setObject:@"Search" forKey:kAction];
  4550. }
  4551. if (upparams) {
  4552. [params setObject:@"Advance Search" forKey:kAction];
  4553. }
  4554. NSString* url=nil;
  4555. if([contact_type isEqualToString:@"Sales_Order_Ship_To"])
  4556. url=URL_SHIPTO_LIST;
  4557. else
  4558. url=URL_CONTACT_LIST;
  4559. if(appDelegate.offline_mode)
  4560. {
  4561. [OLDataProvider offline_contactlist:params completionHandler:result];
  4562. return;
  4563. }
  4564. [self request_interface:url parameters:params err_record_url:nil completionHandler:result retry:0];
  4565. //
  4566. // if(appDelegate.offline_mode)
  4567. // return [OLDataProvider offline_contactlist:params];
  4568. //
  4569. // if(![self IsNetworkAvailable])
  4570. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4571. //
  4572. // NSData* json=[self get_json:url parameters:params];
  4573. // if(json==nil)
  4574. // return nil;
  4575. // NSError *error=nil;
  4576. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4577. // return jsobj;
  4578. }
  4579. +(void)request_contactinfo:(NSString* ) contactid completionHandler:(resultHandler)result
  4580. {
  4581. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4582. AppDelegate *appDelegate = nil;
  4583. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4584. if(RASingleton.sharedInstance.user!=nil)
  4585. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  4586. // if(appDelegate.contact_id!=nil)
  4587. if(RASingleton.sharedInstance.password!=nil)
  4588. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  4589. [params setValue:contactid forKey:@"contactId"];
  4590. [params setObject:ScreenCodeCustomerInfo forKey:kScreenName];
  4591. if(appDelegate.offline_mode)
  4592. {
  4593. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4594. // [OLDataProvider offline_contactinfo:params completionHandler:result] ;
  4595. // });
  4596. params[@"mode"]=appDelegate.mode;
  4597. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4598. NSMutableDictionary* json = [[OLDataProvider offline_contactinfo:params] mutableCopy];
  4599. dispatch_async(dispatch_get_main_queue(), ^{
  4600. result(json);
  4601. });
  4602. });
  4603. return;
  4604. }
  4605. [self request_interface:URL_CUSTOMER_INFO parameters:params err_record_url:nil completionHandler:result retry:0];
  4606. // if(appDelegate.offline_mode)
  4607. // return [OLDataProvider offline_contactinfo:params];
  4608. // if(![self IsNetworkAvailable])
  4609. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4610. //
  4611. // NSData* json=[self get_json:URL_CUSTOMER_INFO parameters:params];
  4612. // if(json==nil)
  4613. // return nil;
  4614. // NSError *error=nil;
  4615. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4616. // return jsobj;
  4617. //
  4618. }
  4619. +(void)request_editor:(NSString*) request_url params:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  4620. {
  4621. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4622. AppDelegate *appDelegate = nil;
  4623. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4624. if(RASingleton.sharedInstance.user!=nil)
  4625. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  4626. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  4627. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  4628. // else
  4629. if(appDelegate.contact_id!=nil)
  4630. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4631. if(RASingleton.sharedInstance.password!=nil)
  4632. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  4633. if(appDelegate.order_code!=nil)
  4634. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  4635. bool can_create_backorder=appDelegate.can_create_backorder;
  4636. // [params setValue:sourceid forKey:@"sourceid"];
  4637. // [params setValue:editor forKey:@"editor"];
  4638. DebugLog(@"request editor url:%@",request_url);
  4639. if([request_url isEqualToString:URL_NEW_CUSTOMER])
  4640. {
  4641. [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
  4642. }
  4643. else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
  4644. {
  4645. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  4646. }
  4647. else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
  4648. {
  4649. [params setObject:ScreenCodeAdvanceSearch forKey:kScreenName];
  4650. }
  4651. else if([request_url isEqualToString:URL_CARTDELIVERY])
  4652. {
  4653. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  4654. }
  4655. else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
  4656. {
  4657. [params setObject:ScreenCodeNewAddress forKey:kScreenName];
  4658. }
  4659. else if ([request_url isEqualToString:URL_DM_PARAMS]){
  4660. [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  4661. }
  4662. if(appDelegate.offline_mode)
  4663. {
  4664. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4665. NSData* json = nil;
  4666. if([request_url isEqualToString:URL_NEW_CUSTOMER])
  4667. {
  4668. json= [OLDataProvider offline_createContact:params];
  4669. }
  4670. else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
  4671. {
  4672. json= [OLDataProvider offline_editContact:params];
  4673. }
  4674. else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
  4675. {
  4676. json= [OLDataProvider offline_contactAdvancedSearch:params];
  4677. }
  4678. else if([request_url isEqualToString:URL_CARTDELIVERY])
  4679. {
  4680. params[@"contact_id"]=params[@"contactId"];
  4681. params[@"can_create_backorder"]=@(can_create_backorder);
  4682. json= [OLDataProvider offline_placeorder:params];
  4683. }
  4684. else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
  4685. {
  4686. json= [OLDataProvider offline_addreditor:params];
  4687. }
  4688. else if ([request_url isEqualToString:URL_DM_PARAMS]){
  4689. json = [OLDataProvider offline_createTearSheet:params];
  4690. }
  4691. dispatch_async(dispatch_get_main_queue(), ^{
  4692. if(json==nil)
  4693. result( [[OLDataProvider offline_notimpl] mutableCopy]);
  4694. else
  4695. result([[RAConvertor data2dict:json] mutableCopy]);
  4696. });
  4697. });
  4698. return;
  4699. }
  4700. else
  4701. {
  4702. if([request_url isEqualToString:URL_CARTDELIVERY])
  4703. {
  4704. NSString * uuid= [[NSUUID UUID] UUIDString];
  4705. params[@"resultSerial"]=uuid;
  4706. __block bool bbreak = false;
  4707. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4708. for(int i=0;i<150;i++)
  4709. {
  4710. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  4711. // result_params[@"resultSerial"]=uuid;
  4712. //json=[self get_json:request_url parameters:params];
  4713. if(bbreak)
  4714. break;
  4715. dispatch_async(dispatch_get_main_queue(), ^{
  4716. DebugLog(@"request cart delivery %d",i);
  4717. [self request_interface:request_url parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  4718. if(resulti!=nil)
  4719. {
  4720. if([resulti[@"result"] intValue]==2 || [resulti[@"result"] intValue] == 8)
  4721. {
  4722. if(!bbreak) //此判断保证result只调用一次。
  4723. {
  4724. result(resulti);
  4725. DebugLog(@"result called at %d",i);
  4726. }
  4727. bbreak=true;
  4728. }
  4729. }
  4730. } retry:3];
  4731. });
  4732. // [self request_interface:request_url parameters:params err_record_url:nil completionHandler:result retry:0];
  4733. sleep(2);
  4734. }
  4735. });
  4736. }
  4737. else
  4738. [self request_interface:request_url parameters:params err_record_url:nil completionHandler:result retry:0];
  4739. }
  4740. // if(json!=nil)
  4741. // {
  4742. // NSError *error=nil;
  4743. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4744. // return jsobj;
  4745. // }
  4746. // else
  4747. // return nil;
  4748. }
  4749. +(void)request_wishlist:(int)sort completionHandler:(resultHandler)result
  4750. {
  4751. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4752. AppDelegate *appDelegate = nil;
  4753. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4754. if(RASingleton.sharedInstance.user!=nil)
  4755. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  4756. if(appDelegate.contact_id!=nil)
  4757. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4758. if(RASingleton.sharedInstance.password!=nil)
  4759. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  4760. [params setValue:[NSString stringWithFormat:@"%d",0 ] forKey:@"offset"];
  4761. [params setValue:[NSString stringWithFormat:@"%d",INT_MAX ] forKey:@"limit"];
  4762. [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  4763. [params setObject:ScreenCodeWishList forKey:kScreenName];
  4764. if(appDelegate.offline_mode)
  4765. {
  4766. [OLDataProvider offline_wishlist:params completionHandler:^(NSMutableDictionary *resulti) {
  4767. int result_code = [[resulti valueForKey:@"result"] intValue];
  4768. if (result_code==2)
  4769. {
  4770. appDelegate.wish_count =[[resulti valueForKey:@"count"] intValue];
  4771. [appDelegate update_count_mark];;
  4772. result(resulti);
  4773. }
  4774. }];
  4775. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4776. // NSMutableDictionary* json = [[OLDataProvider offline_wishlist:params] mutableCopy];
  4777. // dispatch_async(dispatch_get_main_queue(), ^{
  4778. // result(json);
  4779. // });
  4780. // });
  4781. return;
  4782. }
  4783. [self request_interface:URL_WATCHLIST parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  4784. int result_code = [[resulti valueForKey:@"result"] intValue];
  4785. if (result_code==2)
  4786. {
  4787. appDelegate.wish_count =[[resulti valueForKey:@"count"] intValue];
  4788. [appDelegate update_count_mark];;
  4789. result(resulti);
  4790. }
  4791. } retry:0];
  4792. // if(appDelegate.offline_mode)
  4793. // {
  4794. // return [OLDataProvider offline_wishlist:params];
  4795. // }
  4796. // if(![self IsNetworkAvailable])
  4797. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4798. //
  4799. // NSData* json=[self get_json:URL_WATCHLIST parameters:params];
  4800. // if(json==nil)
  4801. // return nil;
  4802. // NSError *error=nil;
  4803. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4804. // int result = [[jsobj valueForKey:@"result"] intValue];
  4805. //
  4806. // if (result==2)
  4807. // {
  4808. //
  4809. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  4810. // appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  4811. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  4812. //
  4813. // [appDelegate update_count_mark];
  4814. // }
  4815. // return jsobj;
  4816. }
  4817. +(void)request_portfoliolist:(int)sort completionHandler:(resultHandler)result
  4818. {
  4819. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4820. AppDelegate *appDelegate = nil;
  4821. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4822. if(RASingleton.sharedInstance.user!=nil)
  4823. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  4824. if(appDelegate.contact_id!=nil)
  4825. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4826. if(RASingleton.sharedInstance.password!=nil)
  4827. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  4828. [params setValue:[NSString stringWithFormat:@"%d",0 ] forKey:@"offset"];
  4829. [params setValue:[NSString stringWithFormat:@"%d",INT_MAX ] forKey:@"limit"];
  4830. [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  4831. [params setObject:ScreenCodePortfolio forKey:kScreenName];
  4832. if(appDelegate.offline_mode)
  4833. {
  4834. params[@"user"]=RASingleton.sharedInstance.user;
  4835. params[@"contact_id"]=appDelegate.contact_id;
  4836. params[@"can_see_price"]=@(appDelegate.can_see_price);
  4837. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4838. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_portfolioList:params]] mutableCopy];
  4839. dispatch_async(dispatch_get_main_queue(), ^{
  4840. if ([json[@"result"] intValue]==2)
  4841. {
  4842. appDelegate.port_count =[[json valueForKey:@"count"] intValue];
  4843. [appDelegate update_count_mark];
  4844. }
  4845. result(json);
  4846. });
  4847. });
  4848. return;
  4849. }
  4850. [self request_interface:URL_PORTFOLIO parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  4851. if ([resulti[@"result"] intValue]==2)
  4852. {
  4853. appDelegate.port_count =[[resulti valueForKey:@"count"] intValue];
  4854. [appDelegate update_count_mark];
  4855. }
  4856. result(resulti);
  4857. } retry:0];
  4858. // NSData* json = nil;
  4859. // if(appDelegate.offline_mode)
  4860. // {
  4861. // json = [OLDataProvider offline_portfolioList:params];
  4862. // } else {
  4863. // if(![self IsNetworkAvailable])
  4864. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4865. //
  4866. // json = [self get_json:URL_PORTFOLIO parameters:params];
  4867. // }
  4868. //
  4869. //
  4870. // if(json==nil)
  4871. // return nil;
  4872. // NSError *error=nil;
  4873. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4874. // int result = [[jsobj valueForKey:@"result"] intValue];
  4875. //
  4876. // if (result==2)
  4877. // {
  4878. //
  4879. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  4880. // //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  4881. // appDelegate.port_count =[[jsobj valueForKey:@"count"] intValue];
  4882. //
  4883. // [appDelegate update_count_mark];
  4884. // }
  4885. // return jsobj;
  4886. }
  4887. +(void)request_portfoliopdf:(int ) offset limit:(int)limit keywords:(NSString* ) keywords completionHandler:(resultHandler)result
  4888. {
  4889. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4890. AppDelegate *appDelegate = nil;
  4891. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4892. if(RASingleton.sharedInstance.user!=nil)
  4893. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  4894. if(appDelegate.contact_id!=nil)
  4895. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4896. if(RASingleton.sharedInstance.password!=nil)
  4897. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  4898. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  4899. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  4900. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  4901. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  4902. // [params setValue:filter forKey:@"filter"];
  4903. [params setValue:keywords forKey:@"keyWord"];
  4904. [params setValue:[NSString stringWithFormat:@"%d",limit] forKey:@"limit"];
  4905. [params setValue:[NSString stringWithFormat:@"%d",offset] forKey:@"offset"];
  4906. [params setObject:ScreenCodeViewPortfolios forKey:kScreenName];
  4907. if (keywords) {
  4908. [params setObject:@"Search" forKey:kAction];
  4909. }
  4910. if(appDelegate.offline_mode)
  4911. {
  4912. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4913. NSData* json = [[OLDataProvider offline_pdfList:params] mutableCopy];
  4914. dispatch_async(dispatch_get_main_queue(), ^{
  4915. result([[RAConvertor data2dict:json] mutableCopy]);
  4916. });
  4917. });
  4918. return;
  4919. }
  4920. [self request_interface:URL_DM_LIST parameters:params err_record_url:nil completionHandler:result retry:0];
  4921. return;
  4922. // NSData* json = nil;
  4923. // if(appDelegate.offline_mode)
  4924. // {
  4925. // json = [OLDataProvider offline_pdfList:params];
  4926. // } else {
  4927. // if(![self IsNetworkAvailable])
  4928. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4929. //
  4930. // json=[self get_json:URL_DM_LIST parameters:params];
  4931. // }
  4932. // if(json==nil)
  4933. // return nil;
  4934. // NSError *error=nil;
  4935. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4936. // return jsobj;
  4937. }
  4938. +(void)request_orderlist:(int ) offset limit :(int)limit keywords :(NSString* ) keywords status:(NSString*) status_code customer:(NSString*) customer is_merged:(BOOL) isMerged completionHandler:(resultHandler)result
  4939. {
  4940. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4941. AppDelegate *appDelegate = nil;
  4942. //some UI methods ej
  4943. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4944. if(RASingleton.sharedInstance.user!=nil)
  4945. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  4946. if(appDelegate.contact_id!=nil)
  4947. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4948. if(RASingleton.sharedInstance.password!=nil)
  4949. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  4950. [params setValue:[NSString stringWithFormat:@"%d",offset ] forKey:@"offset"];
  4951. [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  4952. [params setValue:keywords forKey:@"keyWord"];
  4953. [params setValue:customer forKey:@"customer_filter"];
  4954. [params setValue:[NSNumber numberWithBool:isMerged] forKey:@"isMerged"];
  4955. [params setValue:status_code forKey:@"orderStatus"];
  4956. [params setObject:ScreenCodeOrderList forKey:kScreenName];
  4957. if (keywords) {
  4958. [params setObject:@"Search" forKey:kAction];
  4959. }
  4960. if(appDelegate.offline_mode)
  4961. {
  4962. params[@"user"]=RASingleton.sharedInstance.user;
  4963. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4964. NSData* json = [[OLDataProvider offline_orderlist:params] mutableCopy];
  4965. dispatch_async(dispatch_get_main_queue(), ^{
  4966. result([[RAConvertor data2dict:json] mutableCopy]);
  4967. });
  4968. });
  4969. return;
  4970. }
  4971. [self request_interface:URL_ORDER_LIST parameters:params err_record_url:nil completionHandler:result retry:0];
  4972. // NSData* json=nil;
  4973. // if(appDelegate.offline_mode)
  4974. // {
  4975. // json= [OLDataProvider offline_orderlist:params];
  4976. // }
  4977. // else
  4978. // {
  4979. // if(![self IsNetworkAvailable])
  4980. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4981. //
  4982. // json=[self get_json:URL_ORDER_LIST parameters:params];
  4983. // }
  4984. // if(json==nil)
  4985. // return nil;
  4986. // NSError *error=nil;
  4987. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4988. // return jsobj;
  4989. }
  4990. +(void)request_logout:(resultHandler)result
  4991. {
  4992. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4993. AppDelegate *appDelegate = nil;
  4994. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4995. if(RASingleton.sharedInstance.user!=nil)
  4996. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  4997. if(RASingleton.sharedInstance.password!=nil)
  4998. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  4999. if(appDelegate.offline_mode)
  5000. {
  5001. [OLDataProvider offline_logout:params completionHandler:result];
  5002. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5003. // NSMutableDictionary* json = [[OLDataProvider offline_logout:params] mutableCopy];
  5004. // dispatch_async(dispatch_get_main_queue(), ^{
  5005. // result(json);
  5006. // });
  5007. // });
  5008. return;
  5009. }
  5010. [self request_interface:URL_LOGOUT parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5011. NSMutableDictionary* jsobj=resulti;
  5012. int result_code = [[jsobj valueForKey:@"result"] intValue];
  5013. if (result_code==2)
  5014. {
  5015. appDelegate.cart_count = 0;//[[jsobj :@"cart_count"] intValue];
  5016. appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
  5017. appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
  5018. [appDelegate update_count_mark];
  5019. appDelegate.can_show_price =false;
  5020. appDelegate.can_see_price =false;
  5021. appDelegate.can_create_portfolio =false;
  5022. appDelegate.can_create_order =false;
  5023. appDelegate.can_cancel_order =false;
  5024. appDelegate.can_set_cart_price =false;
  5025. appDelegate.can_delete_order =false;
  5026. appDelegate.can_submit_order =false;
  5027. appDelegate.can_set_tearsheet_price =false;
  5028. appDelegate.can_update_contact_info = false;
  5029. appDelegate.save_order_logout = false;
  5030. appDelegate.submit_order_logout = false;
  5031. appDelegate.alert_sold_in_quantities = false;
  5032. RASingleton.sharedInstance.ipad_perm =nil ;
  5033. appDelegate.user_type = USER_ROLE_UNKNOWN;
  5034. appDelegate.OrderFilter= nil;
  5035. [appDelegate SetSo:nil];
  5036. [appDelegate set_main_button_panel];
  5037. #ifdef RA_NOTIFICATION
  5038. [ActiveViewController Notify:@"SearchViewController" Message:RA_NOTIFICATION_CLEAR_DATA];
  5039. #endif
  5040. }
  5041. result(resulti);
  5042. } retry:0];
  5043. //
  5044. // if(appDelegate.offline_mode)
  5045. // {
  5046. // return [OLDataProvider offline_logout:params];
  5047. // }
  5048. // if(![self IsNetworkAvailable])
  5049. // {
  5050. // DebugLog(@"NET ERR");
  5051. //
  5052. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5053. // // return nil;
  5054. // }
  5055. // NSData* json=[self get_json:URL_LOGOUT parameters:params];
  5056. // //if(json==nil)
  5057. //
  5058. //
  5059. // if(json==nil)
  5060. // return nil;
  5061. // NSError *error=nil;
  5062. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5063. // int result = [[jsobj valueForKey:@"result"] intValue];
  5064. //
  5065. // if (result==2)
  5066. // {
  5067. //
  5068. // appDelegate.cart_count = 0;//[[jsobj valueForKey:@"cart_count"] intValue];
  5069. // appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
  5070. // appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
  5071. //
  5072. // [appDelegate update_count_mark];
  5073. //
  5074. //
  5075. // appDelegate.can_show_price =false;
  5076. // appDelegate.can_see_price =false;
  5077. // appDelegate.can_create_portfolio =false;
  5078. // appDelegate.can_create_order =false;
  5079. //
  5080. //
  5081. // appDelegate.can_cancel_order =false;
  5082. // appDelegate.can_set_cart_price =false;
  5083. // appDelegate.can_delete_order =false;
  5084. // appDelegate.can_submit_order =false;
  5085. // appDelegate.can_set_tearsheet_price =false;
  5086. // appDelegate.can_update_contact_info = false;
  5087. //
  5088. // appDelegate.save_order_logout = false;
  5089. // appDelegate.submit_order_logout = false;
  5090. // appDelegate.alert_sold_in_quantities = false;
  5091. //
  5092. // RASingleton.sharedInstance.ipad_perm =nil ;
  5093. // appDelegate.user_type = USER_ROLE_UNKNOWN;
  5094. // appDelegate.OrderFilter= nil;
  5095. // [appDelegate SetSo:nil];
  5096. // [appDelegate set_main_button_panel];
  5097. //#ifdef RA_NOTIFICATION
  5098. // [ActiveViewController Notify:@"SearchViewController" Message:RA_NOTIFICATION_CLEAR_DATA];
  5099. //#endif
  5100. // }
  5101. // return jsobj;
  5102. }
  5103. + (void)request_hangtag:(NSString *)group completionHandler:(resultHandler)result
  5104. {
  5105. #ifdef BUILD_UWAVER
  5106. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5107. AppDelegate *appDelegate = nil;
  5108. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5109. if(RASingleton.sharedInstance.user!=nil)
  5110. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  5111. if(appDelegate.contact_id!=nil)
  5112. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5113. if(RASingleton.sharedInstance.password!=nil)
  5114. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  5115. if (group) {
  5116. [params setValue:group forKey:@"groupName"];
  5117. }
  5118. NSString * uuid= [[NSUUID UUID] UUIDString];
  5119. params[@"resultSerial"]=uuid;
  5120. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  5121. if(appDelegate.offline_mode)
  5122. {
  5123. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5124. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5125. dispatch_async(dispatch_get_main_queue(), ^{
  5126. result(json);
  5127. });
  5128. });
  5129. return;
  5130. }
  5131. [self request_interface:URL_CREATE_HANG_TAG parameters:params err_record_url:nil completionHandler:result retry:0];
  5132. // NSData* json = nil;
  5133. // if(appDelegate.offline_mode)
  5134. // {
  5135. // json = [OLDataProvider offline_portfolioList:params];
  5136. // } else {
  5137. // if(![self IsNetworkAvailable])
  5138. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5139. //
  5140. // json = [self get_json:URL_CREATE_HANG_TAG parameters:params];
  5141. // }
  5142. //
  5143. //
  5144. // if(json==nil)
  5145. // return nil;
  5146. // NSError *error=nil;
  5147. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5148. //
  5149. // return jsobj;
  5150. #else
  5151. return result(nil);
  5152. #endif
  5153. }
  5154. + (void)request_movetobackorder:(NSString *)cart_item_id completionHandler:(resultHandler)result
  5155. {
  5156. if (cart_item_id == nil || cart_item_id.length < 1) {
  5157. result([@{@"result" : @(RESULT_FALSE),@"err_msg" : @"invalided product"} mutableCopy]);
  5158. }
  5159. AppDelegate *appDelegate = nil;
  5160. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5161. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5162. if(RASingleton.sharedInstance.user!=nil)
  5163. [dic setValue:RASingleton.sharedInstance.user forKey:@"user"];
  5164. if(RASingleton.sharedInstance.password!=nil)
  5165. [dic setValue:RASingleton.sharedInstance.password forKey:@"password"];
  5166. [dic setValue:cart_item_id forKey:@"orderitem_id"];
  5167. [dic setValue:appDelegate.order_code forKey:@"order_code"];
  5168. [dic setObject:ScreenCodeCart forKey:kScreenName];
  5169. if(appDelegate.offline_mode)
  5170. {
  5171. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5172. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5173. dispatch_async(dispatch_get_main_queue(), ^{
  5174. result(json);
  5175. });
  5176. });
  5177. return;
  5178. }
  5179. [self request_interface:URL_MOVE_TO_BACK_ORDER parameters:dic err_record_url:nil completionHandler:result retry:0];
  5180. // if(![self IsNetworkAvailable])
  5181. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5182. //
  5183. // NSData *json = [RANetwork get_json:URL_MOVE_TO_BACK_ORDER parameters:dic];
  5184. //
  5185. // if(json!=nil)
  5186. // {
  5187. // NSError *error=nil;
  5188. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5189. //
  5190. // return jsobj;
  5191. // }
  5192. //
  5193. // return @{@"result" : @(RESULT_FALSE)};
  5194. }
  5195. + (void)request_emailwishlist:(NSString *)addr completionHandler:(resultHandler)result
  5196. {
  5197. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5198. AppDelegate *appDelegate = nil;
  5199. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5200. if(RASingleton.sharedInstance.user!=nil)
  5201. [dic setValue:RASingleton.sharedInstance.user forKey:@"user"];
  5202. if(RASingleton.sharedInstance.password!=nil)
  5203. [dic setValue:RASingleton.sharedInstance.password forKey:@"password"];
  5204. [dic setValue:addr forKey:@"email"];
  5205. [dic setObject:ScreenCodeWishList forKey:kScreenName];
  5206. // if (appDelegate.customerInfo) {
  5207. // NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  5208. // if (customer_cid) {
  5209. // [dic setValue:customer_cid forKey:@"contactId"];
  5210. // }
  5211. // }
  5212. if(appDelegate.offline_mode)
  5213. {
  5214. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5215. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5216. dispatch_async(dispatch_get_main_queue(), ^{
  5217. result(json);
  5218. });
  5219. });
  5220. return;
  5221. }
  5222. [self request_interface:URL_EMAIL_WISHLIST parameters:dic err_record_url:nil completionHandler:result retry:0];
  5223. // NSData* json=nil;
  5224. // if(appDelegate.offline_mode)
  5225. // {
  5226. // return [OLDataProvider offline_notimpl];
  5227. // }
  5228. // else
  5229. // {
  5230. // if(![self IsNetworkAvailable])
  5231. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5232. //
  5233. // json = [RANetwork get_json:URL_EMAIL_WISHLIST parameters:dic];
  5234. // }
  5235. // if(json!=nil)
  5236. // {
  5237. // NSError *error=nil;
  5238. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5239. //
  5240. //
  5241. // return jsobj;
  5242. // }
  5243. //
  5244. // return @{@"result" : @(RESULT_FALSE)};
  5245. }
  5246. +(void)request_notifymodel:(NSString *)modelID emailAddr:(NSString *)addr withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  5247. {
  5248. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5249. AppDelegate *appDelegate = nil;
  5250. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5251. if(RASingleton.sharedInstance.user!=nil)
  5252. [dic setValue:RASingleton.sharedInstance.user forKey:@"user"];
  5253. if(RASingleton.sharedInstance.password!=nil)
  5254. [dic setValue:RASingleton.sharedInstance.password forKey:@"password"];
  5255. if (appDelegate.user_type == USER_ROLE_EMPLOYEE && appDelegate.customerInfo) {
  5256. NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  5257. if (customer_cid) {
  5258. [dic setValue:customer_cid forKey:@"contactId"];
  5259. }
  5260. }
  5261. [dic setObject:screenName forKey:kScreenName];
  5262. [dic setValue:modelID forKey:@"productId"];
  5263. if (addr) { // 弹框输入
  5264. [dic setValue:addr forKey:@"email"];
  5265. } else {
  5266. // employee选择了Contact,并且Contact有Email
  5267. // if (appDelegate.user_type == USER_ROLE_EMPLOYEE && appDelegate.customerInfo) {
  5268. // NSString *email = [appDelegate.customerInfo objectForKey:@"customer_email"];
  5269. // if (email) {
  5270. // [dic setValue:email forKey:@"email"];
  5271. // }
  5272. // }
  5273. }
  5274. if(appDelegate.offline_mode)
  5275. {
  5276. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5277. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5278. dispatch_async(dispatch_get_main_queue(), ^{
  5279. result(json);
  5280. });
  5281. });
  5282. return;
  5283. }
  5284. [self request_interface:URL_NOTIFY_ME parameters:dic err_record_url:nil completionHandler:result retry:0];
  5285. // NSData* json=nil;
  5286. // if(appDelegate.offline_mode)
  5287. // {
  5288. // return [OLDataProvider offline_notimpl];
  5289. // }
  5290. // else
  5291. // {
  5292. // if(![self IsNetworkAvailable])
  5293. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5294. //
  5295. // json = [RANetwork get_json:URL_NOTIFY_ME parameters:dic];
  5296. // }
  5297. // if(json!=nil)
  5298. // {
  5299. // NSError *error=nil;
  5300. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5301. //
  5302. //
  5303. // return jsobj;
  5304. // }
  5305. //
  5306. // return @{@"result" : @(RESULT_FALSE)};
  5307. }
  5308. + (void)request_qouteorder:(NSString *)so_id emailAddr:(NSString *)addr completionHandler:(resultHandler)result
  5309. {
  5310. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5311. AppDelegate *appDelegate = nil;
  5312. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5313. if(RASingleton.sharedInstance.user!=nil)
  5314. [dic setValue:RASingleton.sharedInstance.user forKey:@"user"];
  5315. if(RASingleton.sharedInstance.password!=nil)
  5316. [dic setValue:RASingleton.sharedInstance.password forKey:@"password"];
  5317. [dic setValue:so_id forKey:@"orderCode"];
  5318. [dic setValue:addr forKey:@"email"];
  5319. [dic setObject:ScreenCodeCart forKey:kScreenName];
  5320. if (appDelegate.customerInfo) {
  5321. NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  5322. if (customer_cid) {
  5323. [dic setValue:customer_cid forKey:@"contactId"];
  5324. }
  5325. }
  5326. if(appDelegate.offline_mode)
  5327. {
  5328. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5329. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5330. dispatch_async(dispatch_get_main_queue(), ^{
  5331. result(json);
  5332. });
  5333. });
  5334. return;
  5335. }
  5336. [self request_interface:URL_EMAIL_CART parameters:dic err_record_url:nil completionHandler:result retry:0];
  5337. // NSData* json=nil;
  5338. // if(appDelegate.offline_mode)
  5339. // {
  5340. // return [OLDataProvider offline_notimpl];
  5341. // }
  5342. // else
  5343. // {
  5344. // if(![self IsNetworkAvailable])
  5345. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5346. //
  5347. // json = [RANetwork get_json:URL_EMAIL_CART parameters:dic];
  5348. // }
  5349. // if(json!=nil)
  5350. // {
  5351. // NSError *error=nil;
  5352. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5353. //
  5354. //
  5355. // return jsobj;
  5356. // }
  5357. //
  5358. // return @{@"result" : @(RESULT_FALSE)};
  5359. }
  5360. + (void)request_mergeorder:(NSMutableDictionary *)params completionHandler:(resultHandler)result
  5361. {
  5362. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5363. AppDelegate *appDelegate = nil;
  5364. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5365. if(RASingleton.sharedInstance.user!=nil)
  5366. [dic setValue:RASingleton.sharedInstance.user forKey:@"user"];
  5367. if(RASingleton.sharedInstance.password!=nil)
  5368. [dic setValue:RASingleton.sharedInstance.password forKey:@"password"];
  5369. [dic setValue:[params objectForKey:@"order_ids"] forKey:@"order_ids"];
  5370. [dic setValue:[params objectForKey:@"targetOrderId"] forKey:@"targetOrderId"];
  5371. [dic setValue:[params objectForKey:@"customerInfo"] forKey:@"customerInfo"];
  5372. [dic setObject:ScreenCodeOrderList forKey:kScreenName];
  5373. if(appDelegate.offline_mode)
  5374. {
  5375. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5376. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5377. dispatch_async(dispatch_get_main_queue(), ^{
  5378. result(json);
  5379. });
  5380. });
  5381. return;
  5382. }
  5383. [self request_interface:URL_SET_MERGE_ORDER parameters:dic err_record_url:nil completionHandler:result retry:0];
  5384. // NSData* json=nil;
  5385. // if(appDelegate.offline_mode)
  5386. // {
  5387. // return [OLDataProvider offline_notimpl];
  5388. // }
  5389. // else
  5390. // {
  5391. // if(![self IsNetworkAvailable])
  5392. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5393. //
  5394. // json=[self get_json:URL_SET_MERGE_ORDER parameters:dic];
  5395. // }
  5396. // if(json!=nil)
  5397. // {
  5398. // NSError *error=nil;
  5399. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5400. //
  5401. //
  5402. // return jsobj;
  5403. // }
  5404. // else
  5405. // return nil;
  5406. }
  5407. +(void)request_pendingorder:(NSString *)contactid completionHandler:(resultHandler)result
  5408. {
  5409. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5410. AppDelegate *appDelegate = nil;
  5411. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5412. if(RASingleton.sharedInstance.user!=nil)
  5413. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  5414. // if(appDelegate.contact_id!=nil)
  5415. if(RASingleton.sharedInstance.password!=nil)
  5416. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  5417. [params setValue:contactid forKey:@"contactId"];
  5418. if(appDelegate.offline_mode)
  5419. {
  5420. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5421. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5422. dispatch_async(dispatch_get_main_queue(), ^{
  5423. result(json);
  5424. });
  5425. });
  5426. return;
  5427. }
  5428. [self request_interface:URL_CUSTOMER_PENDINGORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  5429. //
  5430. // if(appDelegate.offline_mode)
  5431. // {
  5432. // return [OLDataProvider offline_notimpl];
  5433. // }
  5434. // if(![self IsNetworkAvailable])
  5435. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5436. //
  5437. // NSData* json=[self get_json:URL_CUSTOMER_PENDINGORDER parameters:params];
  5438. // if(json==nil)
  5439. // return nil;
  5440. // NSError *error=nil;
  5441. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5442. // return jsobj;
  5443. //
  5444. }
  5445. +(void) request_removeportfolio:(NSString* ) item_ids completionHandler:(resultHandler)result
  5446. {
  5447. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5448. AppDelegate *appDelegate = nil;
  5449. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5450. if(RASingleton.sharedInstance.user!=nil)
  5451. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  5452. if(appDelegate.contact_id!=nil)
  5453. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5454. if(RASingleton.sharedInstance.password!=nil)
  5455. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  5456. [params setValue:item_ids forKey:@"portfolioId"];
  5457. // [params setValue:editor forKey:@"editor"];
  5458. [params setValue:ScreenCodePortfolio forKey:kScreenName];
  5459. if(appDelegate.offline_mode)
  5460. {
  5461. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5462. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_removePortfolio:params]] mutableCopy];
  5463. dispatch_async(dispatch_get_main_queue(), ^{
  5464. int result_code = [[resulti valueForKey:@"result"] intValue];
  5465. if (result_code==2)
  5466. {
  5467. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  5468. [appDelegate update_count_mark];
  5469. };
  5470. result(resulti);
  5471. });
  5472. });
  5473. return;
  5474. }
  5475. [self request_interface:URL_PORTFOLIO_REMOVE parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5476. int result_code = [[resulti valueForKey:@"result"] intValue];
  5477. if (result_code==2)
  5478. {
  5479. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  5480. [appDelegate update_count_mark];
  5481. };
  5482. result(resulti);
  5483. } retry:0];
  5484. // NSData* json = nil;
  5485. // if(appDelegate.offline_mode)
  5486. // {
  5487. // json = [OLDataProvider offline_removePortfolio:params];
  5488. // } else {
  5489. // if(![self IsNetworkAvailable])
  5490. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5491. // json=[self get_json:URL_PORTFOLIO_REMOVE parameters:params];
  5492. // }
  5493. // if(json!=nil)
  5494. // {
  5495. // NSError *error=nil;
  5496. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5497. //
  5498. //
  5499. // int result = [[jsobj valueForKey:@"result"] intValue];
  5500. //
  5501. // if (result==2)
  5502. // {
  5503. //
  5504. //
  5505. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  5506. //
  5507. // [appDelegate update_count_mark];
  5508. // }
  5509. // return jsobj;
  5510. // }
  5511. // else
  5512. // return nil;
  5513. }
  5514. +(void) request_removeportfoliopdf:(NSString* ) listid completionHandler:(resultHandler)result
  5515. {
  5516. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5517. AppDelegate *appDelegate = nil;
  5518. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5519. if(RASingleton.sharedInstance.user!=nil)
  5520. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  5521. if(appDelegate.contact_id!=nil)
  5522. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5523. if(RASingleton.sharedInstance.password!=nil)
  5524. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  5525. [params setValue:listid forKey:@"tearsheetsId"];
  5526. // [params setValue:editor forKey:@"editor"];
  5527. [params setValue:ScreenCodeViewPortfolios forKey:kScreenName];
  5528. // [params setValue:@"Delete Portfolio" forKey:kAction];
  5529. if(appDelegate.offline_mode)
  5530. {
  5531. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5532. NSData* json = [[OLDataProvider offline_removePDF:params] mutableCopy];
  5533. dispatch_async(dispatch_get_main_queue(), ^{
  5534. result([[RAConvertor data2dict:json] mutableCopy]);
  5535. });
  5536. });
  5537. return;
  5538. }
  5539. [self request_interface:URL_PORTFOLIOLIST_REMOVE parameters:params err_record_url:nil completionHandler:result retry:0];
  5540. }
  5541. +(void) request_remove_wishlist:(NSString* ) item_ids completionHandler:(resultHandler)result
  5542. {
  5543. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5544. __block AppDelegate *appDelegate = nil;
  5545. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5546. if(RASingleton.sharedInstance.user!=nil)
  5547. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  5548. if(appDelegate.contact_id!=nil)
  5549. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5550. if(RASingleton.sharedInstance.password!=nil)
  5551. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  5552. [params setValue:item_ids forKey:@"collectId"];
  5553. // [params setValue:editor forKey:@"editor"];
  5554. [params setValue:ScreenCodeWishList forKey:kScreenName];
  5555. if(appDelegate.offline_mode)
  5556. {
  5557. // [OLDataProvider offline_deletewishlist:params completionHandler:result];
  5558. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5559. NSMutableDictionary* resulti = [[OLDataProvider offline_deletewishlist:params] mutableCopy];
  5560. dispatch_async(dispatch_get_main_queue(), ^{
  5561. int result_code = [[resulti valueForKey:@"result"] intValue];
  5562. if (result_code==2)
  5563. {
  5564. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  5565. [appDelegate update_count_mark];
  5566. };
  5567. result(resulti);
  5568. });
  5569. });
  5570. return;
  5571. }
  5572. [self request_interface:URL_WATCHLIST_REMOVE parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5573. int result_code = [[resulti valueForKey:@"result"] intValue];
  5574. if (result_code==2)
  5575. {
  5576. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  5577. [appDelegate update_count_mark];
  5578. };
  5579. result(resulti);
  5580. } retry:0];
  5581. //
  5582. //
  5583. // if(appDelegate.offline_mode)
  5584. // {
  5585. // return [OLDataProvider offline_deletewishlist:params];
  5586. // }
  5587. // if(![self IsNetworkAvailable])
  5588. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5589. //
  5590. // NSData* json=[self get_json:URL_WATCHLIST_REMOVE parameters:params];
  5591. // if(json!=nil)
  5592. // {
  5593. // NSError *error=nil;
  5594. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5595. // int result = [[jsobj valueForKey:@"result"] intValue];
  5596. //
  5597. // if (result==2)
  5598. // {
  5599. //
  5600. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  5601. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  5602. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  5603. //
  5604. // [appDelegate update_count_mark];
  5605. // }
  5606. // return jsobj;
  5607. // }
  5608. // else
  5609. // return nil;
  5610. }
  5611. +(void) request_remove_cart:(NSString* ) item_ids completionHandler:(resultHandler)result
  5612. {
  5613. #ifdef SCANNER_ORDER
  5614. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  5615. {
  5616. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  5617. //
  5618. //
  5619. // [appDelegate update_count_mark];
  5620. NSArray* arr=[RAConvertor string2arr:item_ids separator:@","];
  5621. // NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:URL_SO_CART ofType:@"json" ]];
  5622. NSMutableDictionary* cartTemplate=[OLDataProvider loadScanTemplate:@"scan_cart.json"];
  5623. NSMutableDictionary* newsection =[cartTemplate[@"section_0"] mutableCopy];
  5624. int newcount = 0;
  5625. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  5626. int count = [section[@"count"] intValue];
  5627. for(int i=0;i<count;i++)
  5628. {
  5629. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  5630. long index = [arr indexOfObject:item[@"cart_item_id"]] ;
  5631. if(index ==NSNotFound)
  5632. {
  5633. newsection[[NSString stringWithFormat:@"item_%d",newcount]] = item;
  5634. newcount ++;
  5635. }
  5636. }
  5637. newsection[@"count"]=@(newcount);
  5638. RASingleton.sharedInstance.scan_cart[@"section_0"] = newsection;
  5639. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  5640. result(RASingleton.sharedInstance.scan_cart);
  5641. return;
  5642. }
  5643. #else
  5644. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5645. AppDelegate *appDelegate = nil;
  5646. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5647. if(RASingleton.sharedInstance.user!=nil)
  5648. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  5649. if(appDelegate.contact_id!=nil)
  5650. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5651. if(RASingleton.sharedInstance.password!=nil)
  5652. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  5653. if(appDelegate.order_code!=nil)
  5654. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  5655. [params setValue:item_ids forKey:@"cartItemId"];
  5656. // [params setValue:editor forKey:@"editor"];
  5657. [params setValue:ScreenCodeCart forKey:kScreenName];
  5658. // [params setValue:@"" forKey:kAction];
  5659. if(appDelegate.offline_mode)
  5660. {
  5661. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5662. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_cartremove:params]] mutableCopy];
  5663. dispatch_async(dispatch_get_main_queue(), ^{
  5664. int result_code = [[resulti valueForKey:@"result"] intValue];
  5665. if (result_code==2)
  5666. {
  5667. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  5668. [appDelegate update_count_mark];
  5669. };
  5670. result(resulti);
  5671. });
  5672. });
  5673. return;
  5674. }
  5675. [self request_interface:URL_CART_REMOVE parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5676. int result_code = [[resulti valueForKey:@"result"] intValue];
  5677. if (result_code==2)
  5678. {
  5679. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  5680. [appDelegate update_count_mark];
  5681. };
  5682. result(resulti);
  5683. } retry:0];
  5684. #endif
  5685. }
  5686. +(void)request_delete_account:(resultHandler)result
  5687. {
  5688. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5689. AppDelegate *appDelegate = nil;
  5690. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5691. if(RASingleton.sharedInstance.user!=nil)
  5692. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  5693. if(RASingleton.sharedInstance.password!=nil)
  5694. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  5695. if(appDelegate.offline_mode)
  5696. {
  5697. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5698. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5699. dispatch_async(dispatch_get_main_queue(), ^{
  5700. result(json);
  5701. });
  5702. });
  5703. return;
  5704. }
  5705. #ifdef SCANNER_ORDER
  5706. params[@"site_name"]=[RADataProvider getSiteName];
  5707. params[@"_method"]=@"cancelOfflineOrderUser";
  5708. NSString* url = [appDelegate.address stringByAppendingPathComponent:URL_DELETE_ACCOUNT];
  5709. [self request_interface:url parameters:params err_record_url:nil completionHandler:result retry:0];
  5710. #else
  5711. [self request_interface:URL_DELETE_ACCOUNT parameters:params err_record_url:nil completionHandler:result retry:0];
  5712. #endif
  5713. }
  5714. +(void) request_create_order:(resultHandler)result
  5715. {
  5716. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5717. AppDelegate *appDelegate = nil;
  5718. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5719. if(RASingleton.sharedInstance.user!=nil)
  5720. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  5721. if(appDelegate.contact_id!=nil)
  5722. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5723. if(RASingleton.sharedInstance.password!=nil)
  5724. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  5725. if(appDelegate.order_code!=nil)
  5726. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  5727. [params setObject:ScreenCodeOrderList forKey:kScreenName];
  5728. NSDictionary* customerinfo= appDelegate.customerInfo;
  5729. NSArray* keys=[customerinfo allKeys];
  5730. for(int i=0;i<keys.count;i++)
  5731. {
  5732. [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  5733. }
  5734. if(appDelegate.offline_mode)
  5735. {
  5736. [OLDataProvider offline_createorder:params completionHandler:^(NSMutableDictionary *resulti) {
  5737. int result_code = [[resulti valueForKey:@"result"] intValue];
  5738. if (result_code==2)
  5739. {
  5740. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  5741. [appDelegate update_count_mark];
  5742. };
  5743. [appDelegate SetSo:[resulti valueForKey:@"soId"]];
  5744. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  5745. [RASingleton sharedInstance].currentOrderIsMerged = NO;
  5746. }
  5747. result(resulti);
  5748. }];
  5749. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5750. // NSData* json = [[OLDataProvider offline_createorder:params] mutableCopy];
  5751. // dispatch_async(dispatch_get_main_queue(), ^{
  5752. // result([[RAConvertor data2dict:json] mutableCopy]);
  5753. // });
  5754. // });
  5755. return;
  5756. }
  5757. [self request_interface:URL_NEW_ORDER parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5758. int result_code = [[resulti valueForKey:@"result"] intValue];
  5759. if (result_code==2)
  5760. {
  5761. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  5762. [appDelegate update_count_mark];
  5763. };
  5764. [appDelegate SetSo:[resulti valueForKey:@"soId"]];
  5765. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  5766. [RASingleton sharedInstance].currentOrderIsMerged = NO;
  5767. }
  5768. result(resulti);
  5769. } retry:0];
  5770. //
  5771. // NSData* json = nil;
  5772. // if(appDelegate.offline_mode)
  5773. // {
  5774. // json= [OLDataProvider offline_createorder:params];
  5775. // }
  5776. // else
  5777. // {
  5778. // if(![self IsNetworkAvailable])
  5779. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5780. //
  5781. // json=[self get_json:URL_NEW_ORDER parameters:params];
  5782. // }
  5783. // if(json==nil)
  5784. // return nil;
  5785. // NSError *error=nil;
  5786. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5787. // int result = [[jsobj valueForKey:@"result"] intValue];
  5788. //
  5789. // if (result==2)
  5790. // {
  5791. //
  5792. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  5793. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  5794. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  5795. //
  5796. // [appDelegate update_count_mark];
  5797. // }
  5798. //
  5799. // [appDelegate SetSo:[jsobj valueForKey:@"soId"]];
  5800. //
  5801. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  5802. // [Singleton sharedInstance].currentOrderIsMerged = NO;
  5803. // }
  5804. //
  5805. // return jsobj;
  5806. }
  5807. +(void)request_open_order:(NSString*) order_code completionHandler:(resultHandler)result
  5808. {
  5809. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5810. AppDelegate *appDelegate = nil;
  5811. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5812. if(RASingleton.sharedInstance.user!=nil)
  5813. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  5814. // if(appDelegate.contact_id!=nil)
  5815. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5816. if(RASingleton.sharedInstance.password!=nil)
  5817. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  5818. [params setValue:order_code forKey:@"orderCode"];
  5819. // [params setValue:sourceid forKey:@"sourceid"];
  5820. // [params setValue:editor forKey:@"editor"];
  5821. [params setValue:ScreenCodeOrderInfo forKey:kScreenName];
  5822. if(appDelegate.offline_mode)
  5823. {
  5824. params[@"appDelegate.order_code"]=appDelegate.order_code;
  5825. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5826. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_editorder:params]] mutableCopy];
  5827. dispatch_async(dispatch_get_main_queue(), ^{
  5828. int result_code = [[resulti valueForKey:@"result"] intValue];
  5829. if (result_code==2)
  5830. {
  5831. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  5832. [appDelegate update_count_mark];
  5833. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  5834. [RASingleton sharedInstance].currentOrderIsMerged = [[resulti valueForKey:@"is_merged_order"] boolValue];
  5835. }
  5836. }
  5837. result(resulti);
  5838. });
  5839. });
  5840. return;
  5841. }
  5842. [self request_interface:URL_OPEN_ORDER parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5843. int result_code = [[resulti valueForKey:@"result"] intValue];
  5844. if (result_code==2)
  5845. {
  5846. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  5847. [appDelegate update_count_mark];
  5848. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  5849. [RASingleton sharedInstance].currentOrderIsMerged = [[resulti valueForKey:@"is_merged_order"] boolValue];
  5850. }
  5851. }
  5852. result(resulti);
  5853. } retry:0];
  5854. //
  5855. // NSData* json=nil;
  5856. // if(appDelegate.offline_mode)
  5857. // {
  5858. // json=[OLDataProvider offline_editorder:params];
  5859. //
  5860. // }
  5861. // else
  5862. // {
  5863. // if(![self IsNetworkAvailable])
  5864. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5865. //
  5866. // json=[self get_json:URL_OPEN_ORDER parameters:params];
  5867. // }
  5868. // if(json!=nil)
  5869. // {
  5870. // NSError *error=nil;
  5871. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5872. // int result = [[jsobj valueForKey:@"result"] intValue];
  5873. //
  5874. // if (result==2)
  5875. // {
  5876. //
  5877. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  5878. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  5879. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  5880. //
  5881. // [appDelegate update_count_mark];
  5882. //
  5883. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  5884. // [Singleton sharedInstance].currentOrderIsMerged = [[jsobj valueForKey:@"is_merged_order"] boolValue];
  5885. // }
  5886. //
  5887. // }
  5888. //
  5889. // return jsobj;
  5890. // }
  5891. // else
  5892. // return nil;
  5893. }
  5894. +(void)request_order_discount:(double)discount completionHandler:(resultHandler)result
  5895. {
  5896. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5897. AppDelegate *appDelegate = nil;
  5898. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5899. if(RASingleton.sharedInstance.user!=nil)
  5900. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  5901. // if(appDelegate.contact_id!=nil)
  5902. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5903. if(RASingleton.sharedInstance.password!=nil)
  5904. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  5905. if(appDelegate.order_code!=nil)
  5906. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  5907. [params setValue:@(discount) forKey:@"app_discount"];
  5908. if(appDelegate.offline_mode)
  5909. {
  5910. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5911. NSMutableDictionary* json = [[OLDataProvider offline_setorderdiscount:params] mutableCopy];
  5912. dispatch_async(dispatch_get_main_queue(), ^{
  5913. result(json);
  5914. });
  5915. });
  5916. return;
  5917. //
  5918. //
  5919. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5920. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5921. // dispatch_async(dispatch_get_main_queue(), ^{
  5922. // result(json);
  5923. // });
  5924. // });
  5925. //
  5926. // return;
  5927. }
  5928. [self request_interface:URL_ORDER_DISCOUNT parameters:params err_record_url:nil completionHandler:result retry:0];
  5929. }
  5930. +(void)request_cart:(int)sort completionHandler:(resultHandler)result
  5931. {
  5932. DebugLog(@"iSalesNetwork::request_Cart");
  5933. AppDelegate *appDelegate = nil;
  5934. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5935. #ifdef SCANNER_ORDER
  5936. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  5937. {
  5938. appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  5939. [appDelegate update_count_mark];
  5940. result(RASingleton.sharedInstance.scan_cart);
  5941. return;
  5942. }
  5943. #else
  5944. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5945. if(RASingleton.sharedInstance.user!=nil)
  5946. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  5947. // if(appDelegate.contact_id!=nil)
  5948. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5949. if(RASingleton.sharedInstance.password!=nil)
  5950. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  5951. if(appDelegate.order_code!=nil)
  5952. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  5953. [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  5954. [params setObject:ScreenCodeCart forKey:kScreenName];
  5955. if(appDelegate.offline_mode)
  5956. {
  5957. [OLDataProvider offline_requestcart:params completionHandler:^(NSMutableDictionary *resulti) {
  5958. if([resulti[@"result"] intValue]==2)
  5959. {
  5960. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  5961. [appDelegate update_count_mark];
  5962. result(resulti);
  5963. }
  5964. }];
  5965. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5966. // NSData* json = [[OLDataProvider offline_requestcart:params] mutableCopy];
  5967. // dispatch_async(dispatch_get_main_queue(), ^{
  5968. // result([[RAConvertor data2dict:json] mutableCopy]);
  5969. // });
  5970. // });
  5971. return;
  5972. }
  5973. NSString * uuid= [[NSUUID UUID] UUIDString];
  5974. params[@"resultSerial"]=uuid;
  5975. __block bool bbreak = false;
  5976. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5977. for(int i=0;i<150;i++)
  5978. {
  5979. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  5980. // result_params[@"resultSerial"]=uuid;
  5981. if(bbreak)
  5982. break;
  5983. dispatch_async(dispatch_get_main_queue(), ^{
  5984. [self request_interface:URL_CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5985. if([resulti[@"result"] intValue]==2)
  5986. {
  5987. if(!bbreak) //此判断保证result只调用一次。
  5988. {
  5989. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  5990. [appDelegate update_count_mark];
  5991. result(resulti);
  5992. }
  5993. bbreak=true;
  5994. }
  5995. } retry:3];
  5996. });
  5997. sleep(2);
  5998. // json=[self get_json:URL_CART parameters:params];
  5999. // if(json!=nil)
  6000. // {
  6001. //
  6002. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6003. // if([jsobj[@"result"] intValue]==2)
  6004. // {
  6005. // break;
  6006. // }
  6007. // }
  6008. }
  6009. });
  6010. //
  6011. //
  6012. //
  6013. // NSData* json=nil;
  6014. // if(appDelegate.offline_mode)
  6015. // {
  6016. // json= [OLDataProvider offline_requestcart:params];
  6017. // }
  6018. // else
  6019. // {
  6020. // if(![self IsNetworkAvailable])
  6021. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6022. //
  6023. // NSError *error=nil;
  6024. //
  6025. // NSString * uuid= [[NSUUID UUID] UUIDString];
  6026. // params[@"resultSerial"]=uuid;
  6027. //
  6028. // for(int i=0;i<150;i++)
  6029. // {
  6030. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6031. // // result_params[@"resultSerial"]=uuid;
  6032. // json=[self get_json:URL_CART parameters:params];
  6033. // if(json!=nil)
  6034. // {
  6035. //
  6036. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6037. // if([jsobj[@"result"] intValue]==2)
  6038. // {
  6039. // break;
  6040. // }
  6041. // }
  6042. // sleep(2);
  6043. // }
  6044. //
  6045. // }
  6046. // if(json==nil)
  6047. // return nil;
  6048. // NSError *error=nil;
  6049. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6050. // int result = [[jsobj valueForKey:@"result"] intValue];
  6051. //
  6052. // if (result==2)
  6053. // {
  6054. //
  6055. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6056. // //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  6057. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6058. //
  6059. // [appDelegate update_count_mark];
  6060. // }
  6061. // return jsobj;
  6062. #endif
  6063. }
  6064. +(void) request_move_wish2cart:(NSString* ) item_ids completionHandler:(resultHandler)result
  6065. {
  6066. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6067. AppDelegate *appDelegate = nil;
  6068. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6069. if(RASingleton.sharedInstance.user!=nil)
  6070. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  6071. if(appDelegate.contact_id!=nil)
  6072. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6073. if(RASingleton.sharedInstance.password!=nil)
  6074. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  6075. if(appDelegate.order_code!=nil)
  6076. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6077. [params setValue:item_ids forKey:@"collectId"];
  6078. // [params setValue:editor forKey:@"editor"];
  6079. [params setValue:ScreenCodeWishList forKey:kScreenName];
  6080. [params setValue:@"Move To Cart" forKey:kAction];
  6081. if(appDelegate.offline_mode)
  6082. {
  6083. // [OLDataProvider offline_movewish2cart:params completionHandler:result];
  6084. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  6085. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6086. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_movewish2cart:params]] mutableCopy];
  6087. dispatch_async(dispatch_get_main_queue(), ^{
  6088. int result_code = [[resulti valueForKey:@"result"] intValue];
  6089. if (result_code==2)
  6090. {
  6091. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6092. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6093. [appDelegate update_count_mark];
  6094. }
  6095. result(resulti);
  6096. });
  6097. });
  6098. return;
  6099. }
  6100. [self request_interface:URL_WISH2CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6101. int result_code = [[resulti valueForKey:@"result"] intValue];
  6102. if (result_code==2)
  6103. {
  6104. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6105. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6106. [appDelegate update_count_mark];
  6107. }
  6108. result(resulti);
  6109. } retry:0];
  6110. //
  6111. // NSData *json = nil;
  6112. // if(appDelegate.offline_mode)
  6113. // {
  6114. // json = [OLDataProvider offline_movewish2cart:params];
  6115. // } else {
  6116. // if(![self IsNetworkAvailable])
  6117. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6118. //
  6119. // json=[self get_json:URL_WISH2CART parameters:params];
  6120. // }
  6121. //
  6122. // if(json!=nil)
  6123. // {
  6124. // NSError *error=nil;
  6125. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6126. // int result = [[jsobj valueForKey:@"result"] intValue];
  6127. //
  6128. // if (result==2)
  6129. // {
  6130. //
  6131. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6132. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6133. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6134. //
  6135. // [appDelegate update_count_mark];
  6136. // }
  6137. // return jsobj;
  6138. // }
  6139. // else
  6140. // return nil;
  6141. }
  6142. +(void) request_move_cart2wish:(NSString* ) item_ids completionHandler:(resultHandler)result
  6143. {
  6144. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6145. AppDelegate *appDelegate = nil;
  6146. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6147. if(RASingleton.sharedInstance.user!=nil)
  6148. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  6149. if(appDelegate.contact_id!=nil)
  6150. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6151. if(RASingleton.sharedInstance.password!=nil)
  6152. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  6153. if(appDelegate.order_code!=nil)
  6154. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6155. [params setValue:item_ids forKey:@"cartItemId"];
  6156. // [params setValue:editor forKey:@"editor"];
  6157. [params setValue:ScreenCodeCart forKey:kScreenName];
  6158. // [params setValue:@"Cart Move To Wish List" forKey:kAction];
  6159. if(appDelegate.offline_mode)
  6160. {
  6161. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6162. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_movecart2wish:params]] mutableCopy];
  6163. dispatch_async(dispatch_get_main_queue(), ^{
  6164. int result_code = [[resulti valueForKey:@"result"] intValue];
  6165. if (result_code==2)
  6166. {
  6167. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6168. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6169. [appDelegate update_count_mark];
  6170. }
  6171. result(resulti);
  6172. });
  6173. });
  6174. return;
  6175. }
  6176. [self request_interface:URL_CART2WISH parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6177. int result_code = [[resulti valueForKey:@"result"] intValue];
  6178. if (result_code==2)
  6179. {
  6180. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6181. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6182. [appDelegate update_count_mark];
  6183. }
  6184. result(resulti);
  6185. } retry:0];
  6186. //
  6187. // NSData* json = nil;
  6188. // if(appDelegate.offline_mode)
  6189. // {
  6190. // json= [OLDataProvider offline_movecart2wish:params];
  6191. // }
  6192. // else
  6193. // {
  6194. // if(![self IsNetworkAvailable])
  6195. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6196. //
  6197. // json=[self get_json:URL_CART2WISH parameters:params];
  6198. // }
  6199. // if(json!=nil)
  6200. // {
  6201. // NSError *error=nil;
  6202. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6203. // int result = [[jsobj valueForKey:@"result"] intValue];
  6204. //
  6205. // if (result==2)
  6206. // {
  6207. //
  6208. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6209. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6210. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6211. //
  6212. // [appDelegate update_count_mark];
  6213. // }
  6214. // return jsobj;
  6215. // }
  6216. // else
  6217. // return nil;
  6218. }
  6219. +(void)request_orderdetail:(NSMutableDictionary *) params completionHandler:(resultHandler)result
  6220. {
  6221. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6222. if (params == nil) {
  6223. params = [[NSMutableDictionary alloc] init];
  6224. }
  6225. AppDelegate *appDelegate = nil;
  6226. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6227. if(RASingleton.sharedInstance.user!=nil)
  6228. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  6229. if(appDelegate.contact_id!=nil)
  6230. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6231. if(RASingleton.sharedInstance.password!=nil)
  6232. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  6233. // [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  6234. [params setObject:ScreenCodeOrderInfo forKey:kScreenName];
  6235. if(appDelegate.offline_mode)
  6236. {
  6237. params[@"mode"]=appDelegate.mode;
  6238. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6239. NSData* json = [[OLDataProvider offline_orderdetail:params] mutableCopy];
  6240. dispatch_async(dispatch_get_main_queue(), ^{
  6241. result([[RAConvertor data2dict:json] mutableCopy]);
  6242. });
  6243. });
  6244. return;
  6245. }
  6246. NSString * uuid= [[NSUUID UUID] UUIDString];
  6247. params[@"resultSerial"]=uuid;
  6248. __block bool bbreak = false;
  6249. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6250. for(int i=0;i<150;i++)
  6251. {
  6252. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6253. // result_params[@"resultSerial"]=uuid;
  6254. if(bbreak)
  6255. break;
  6256. dispatch_async(dispatch_get_main_queue(), ^{
  6257. [self request_interface:URL_ORDER_DETAIL parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6258. if([resulti[@"result"] intValue]==2||[resulti[@"result"] intValue]==8)
  6259. {
  6260. if(!bbreak)//此判断保证result只调用一次。
  6261. result(resulti);
  6262. bbreak=true;
  6263. }
  6264. } retry:3];
  6265. });
  6266. sleep(2);
  6267. }
  6268. });
  6269. //
  6270. // NSData* json=nil;
  6271. // if(appDelegate.offline_mode)
  6272. // {
  6273. // json= [OLDataProvider offline_orderdetail:params];
  6274. // }
  6275. // else
  6276. // {
  6277. // if(![self IsNetworkAvailable])
  6278. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6279. //
  6280. // NSError *error=nil;
  6281. //
  6282. // NSString * uuid= [[NSUUID UUID] UUIDString];
  6283. // params[@"resultSerial"]=uuid;
  6284. //
  6285. // for(int i=0;i<150;i++)
  6286. // {
  6287. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6288. // // result_params[@"resultSerial"]=uuid;
  6289. // json=[self get_json:URL_ORDER_DETAIL parameters:params];
  6290. // if(json!=nil)
  6291. // {
  6292. //
  6293. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6294. // int resultCode = [jsobj[@"result"] intValue];
  6295. // if(resultCode==2 || resultCode == 8)
  6296. // {
  6297. // break;
  6298. // }
  6299. // }
  6300. // sleep(2);
  6301. // }
  6302. //
  6303. //
  6304. // }
  6305. // if(json==nil)
  6306. // return nil;
  6307. // NSError *error=nil;
  6308. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6309. // return jsobj;
  6310. }
  6311. //
  6312. //+(void)request_commit_order:(NSString*) order_code completionHandler:(resultHandler)result
  6313. //{
  6314. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6315. // AppDelegate *appDelegate = nil;
  6316. //
  6317. //
  6318. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6319. //
  6320. // if(RASingleton.sharedInstance.user!=nil)
  6321. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  6322. // if(appDelegate.contact_id!=nil)
  6323. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6324. // if(RASingleton.sharedInstance.password!=nil)
  6325. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  6326. // // NSString* ssaved = @"false";
  6327. // // if(saved)
  6328. // // ssaved=@"true";
  6329. // [params setValue:@"true" forKey:@"saved"];
  6330. // [params setValue:order_code forKey:@"orderCode"];
  6331. // // [params setValue:sourceid forKey:@"sourceid"];
  6332. // // [params setValue:editor forKey:@"editor"];
  6333. //
  6334. // [params setValue:ScreenCodePlaceOrder forKey:kScreenName];
  6335. //
  6336. //
  6337. // if(appDelegate.offline_mode)
  6338. // {
  6339. //
  6340. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6341. // NSMutableDictionary* json = [[OLDataProvider offline_submitorder:params] mutableCopy];
  6342. // dispatch_async(dispatch_get_main_queue(), ^{
  6343. // result(json);
  6344. // });
  6345. // });
  6346. //
  6347. // return;
  6348. // }
  6349. //
  6350. //
  6351. // [self request_interface:URL_COMMIT_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  6352. //
  6353. //// NSData* json = nil;
  6354. ////
  6355. //// if(appDelegate.offline_mode)
  6356. //// {
  6357. //// json= [OLDataProvider offline_submitorder:params];
  6358. //// }
  6359. //// else
  6360. //// {
  6361. //// if(![self IsNetworkAvailable])
  6362. //// return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6363. ////
  6364. //// json=[self get_json:URL_COMMIT_ORDER parameters:params];
  6365. //// }
  6366. //// if(json!=nil)
  6367. //// {
  6368. //// NSError *error=nil;
  6369. //// NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6370. //// return jsobj;
  6371. //// }
  6372. //// else
  6373. //// return nil;
  6374. //
  6375. //}
  6376. +(void)request_copy_order:(NSString*) order_code completionHandler:(resultHandler)result
  6377. {
  6378. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6379. AppDelegate *appDelegate = nil;
  6380. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6381. if(RASingleton.sharedInstance.user!=nil)
  6382. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  6383. if(appDelegate.contact_id!=nil)
  6384. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6385. if(RASingleton.sharedInstance.password!=nil)
  6386. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  6387. // NSString* ssaved = @"false";
  6388. // if(saved)
  6389. // ssaved=@"true";
  6390. // [params setValue:@"true" forKey:@"saved"];
  6391. [params setValue:order_code forKey:@"code"];
  6392. // [params setValue:sourceid forKey:@"sourceid"];
  6393. // [params setValue:editor forKey:@"editor"];
  6394. [params setValue:ScreenCodeOrderInfo forKey:kScreenName];
  6395. if(appDelegate.offline_mode)
  6396. {
  6397. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6398. NSData* json = [[OLDataProvider offline_copyorder:params] mutableCopy];
  6399. dispatch_async(dispatch_get_main_queue(), ^{
  6400. result([[RAConvertor data2dict:json] mutableCopy]);
  6401. });
  6402. });
  6403. return;
  6404. }
  6405. [self request_interface:URL_COPY_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  6406. // NSData* json=nil;
  6407. // if(appDelegate.offline_mode)
  6408. // {
  6409. // json= [OLDataProvider offline_copyorder:params];
  6410. // }
  6411. // else
  6412. // {
  6413. // if(![self IsNetworkAvailable])
  6414. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6415. //
  6416. // json=[self get_json:URL_COPY_ORDER parameters:params];
  6417. // }
  6418. // if(json!=nil)
  6419. // {
  6420. // NSError *error=nil;
  6421. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6422. // return jsobj;
  6423. // }
  6424. // else
  6425. // return nil;
  6426. }
  6427. //
  6428. //+ (void)request_fastdownload:(NSMutableDictionary *)params url:(NSString *)url completionHandler:(resultHandler)result
  6429. //{
  6430. //
  6431. // //#ifdef test_server
  6432. // // url=URL_REQUEST_RECORDS;
  6433. // // params[@"prefix"]=URL_REQUEST_RECORDS;
  6434. // //#endif
  6435. //
  6436. // [self request_file_fast:url parameters:params completionHandler:result];
  6437. //
  6438. //}
  6439. +(void) request_addto_portfolio:(NSString* ) item_id withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  6440. {
  6441. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6442. AppDelegate *appDelegate = nil;
  6443. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6444. if(RASingleton.sharedInstance.user!=nil)
  6445. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  6446. if(appDelegate.contact_id!=nil)
  6447. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6448. if(RASingleton.sharedInstance.password!=nil)
  6449. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  6450. [params setValue:item_id forKey:@"product_id"];
  6451. [params setObject:screenName forKey:kScreenName];
  6452. if(appDelegate.offline_mode)
  6453. {
  6454. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6455. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_add2Portfolio:params]] mutableCopy];
  6456. dispatch_async(dispatch_get_main_queue(), ^{
  6457. int result_code = [[resulti valueForKey:@"result"] intValue];
  6458. if (result_code==2)
  6459. {
  6460. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  6461. [appDelegate update_count_mark];
  6462. }
  6463. result(resulti);
  6464. });
  6465. });
  6466. return;
  6467. }
  6468. [self request_interface:URL_ADD_TO_PORTFOLIO parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6469. int result_code = [[resulti valueForKey:@"result"] intValue];
  6470. if (result_code==2)
  6471. {
  6472. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  6473. [appDelegate update_count_mark];
  6474. }
  6475. result(resulti);
  6476. } retry:0];
  6477. //
  6478. // NSData* json = nil;
  6479. // if(appDelegate.offline_mode)
  6480. // {
  6481. // json = [OLDataProvider offline_add2Portfolio:params];
  6482. // } else {
  6483. // if(![self IsNetworkAvailable])
  6484. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6485. //
  6486. // json=[self get_json:URL_ADD_TO_PORTFOLIO parameters:params];
  6487. // }
  6488. //
  6489. // if(json==nil)
  6490. // return nil;
  6491. // NSError *error=nil;
  6492. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6493. // int result = [[jsobj valueForKey:@"result"] intValue];
  6494. //
  6495. // if (result==2)
  6496. // {
  6497. //
  6498. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6499. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6500. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6501. //
  6502. // [appDelegate update_count_mark];
  6503. // }
  6504. // return jsobj;
  6505. }
  6506. +(void)request_addall_search:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull orderCode:(NSString*) orderCode addTo:(NSString*) addTo completionHandler:(resultHandler)result
  6507. {
  6508. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6509. AppDelegate *appDelegate = nil;
  6510. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6511. if(RASingleton.sharedInstance.user!=nil)
  6512. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  6513. if(appDelegate.contact_id!=nil)
  6514. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6515. if(RASingleton.sharedInstance.password!=nil)
  6516. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  6517. if(appDelegate.order_code!=nil)
  6518. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6519. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  6520. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  6521. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  6522. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  6523. // [params setValue:filter forKey:@"filter"];
  6524. [params setValue:keywords forKey:@"keyword"];
  6525. [params setValue:addTo forKey:@"addTo"];
  6526. [params setValue:orderCode forKey:@"orderCode"];
  6527. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  6528. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  6529. if(matchfull)
  6530. [params setValue:@"true" forKey:@"exactMatch"];
  6531. else
  6532. [params setValue:@"false" forKey:@"exactMatch"];
  6533. [params setObject:ScreenCodeSearch forKey:kScreenName];
  6534. if ([addTo isEqualToString:@"cart"]) {
  6535. [params setObject:@"Add To Cart" forKey:kAction];
  6536. }
  6537. if(appDelegate.offline_mode)
  6538. {
  6539. if ([addTo isEqualToString:@"cart"])
  6540. {
  6541. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  6542. }
  6543. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6544. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_searchaddall:params]] mutableCopy];
  6545. dispatch_async(dispatch_get_main_queue(), ^{
  6546. int result_code =[json[@"result"] intValue];
  6547. if (result_code==2||result_code==8)
  6548. {
  6549. if(json[@"cart_count"])
  6550. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  6551. if(json[@"wish_count"])
  6552. appDelegate.wish_count =[[json valueForKey:@"wish_count"] intValue];
  6553. if(json[@"portfolio_count"])
  6554. appDelegate.port_count =[[json valueForKey:@"portfolio_count"] intValue];
  6555. //
  6556. //
  6557. [appDelegate update_count_mark];
  6558. }
  6559. result(json);
  6560. });
  6561. });
  6562. return;
  6563. }
  6564. NSString * uuid= [[NSUUID UUID] UUIDString];
  6565. params[@"resultSerial"]=uuid;
  6566. __block bool bbreak = false;
  6567. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6568. for(int i=0;i<150;i++)
  6569. {
  6570. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6571. // result_params[@"resultSerial"]=uuid;
  6572. if(bbreak)
  6573. break;
  6574. dispatch_async(dispatch_get_main_queue(), ^{
  6575. [self request_interface:URL_SEARCHADDALL parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6576. if([resulti[@"result"] intValue]==2)
  6577. {
  6578. if(!bbreak)//此判断保证result只调用一次。
  6579. result(resulti);
  6580. bbreak=true;
  6581. }
  6582. } retry:3];
  6583. });
  6584. sleep(2);
  6585. }
  6586. });
  6587. //
  6588. //
  6589. // NSData* json=nil;
  6590. // if(appDelegate.offline_mode)
  6591. // {
  6592. // json=[OLDataProvider offline_searchaddall:params];
  6593. // }
  6594. // else
  6595. // {
  6596. // if(![self IsNetworkAvailable])
  6597. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6598. //
  6599. // NSError *error=nil;
  6600. //
  6601. // NSString * uuid= [[NSUUID UUID] UUIDString];
  6602. // params[@"resultSerial"]=uuid;
  6603. //
  6604. // for(int i=0;i<150;i++)
  6605. // {
  6606. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6607. // // result_params[@"resultSerial"]=uuid;
  6608. // json=[self get_json:URL_SEARCHADDALL parameters:params];
  6609. // if(json!=nil)
  6610. // {
  6611. //
  6612. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6613. // if([jsobj[@"result"] intValue]==2)
  6614. // {
  6615. // break;
  6616. // }
  6617. // }
  6618. // sleep(2);
  6619. // }
  6620. // }
  6621. // if(json==nil)
  6622. // return nil;
  6623. // NSError *error=nil;
  6624. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6625. // return jsobj;
  6626. }
  6627. +(void) request_addto_cart_byupc:(NSString* ) upc_code withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  6628. {
  6629. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6630. AppDelegate *appDelegate = nil;
  6631. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6632. if(RASingleton.sharedInstance.user!=nil)
  6633. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  6634. if(appDelegate.contact_id!=nil)
  6635. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6636. if(RASingleton.sharedInstance.password!=nil)
  6637. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  6638. if(appDelegate.order_code!=nil)
  6639. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6640. [params setValue:upc_code forKey:@"upc_code"];
  6641. [params setValue:[NSString stringWithFormat:@"%d",-1] forKey:@"count"];
  6642. [params setObject:screenName forKey:kScreenName];
  6643. [params setObject:@"Add To Cart" forKey:kAction];
  6644. if (!upc_code) {
  6645. upc_code = @"";
  6646. }
  6647. [params setObject:@{@"UPCCode" : upc_code} forKey:kExtra];
  6648. params[@"search_upc"]=@true;
  6649. NSDictionary* customerinfo= appDelegate.customerInfo;
  6650. NSArray* keys=[customerinfo allKeys];
  6651. for(int i=0;i<keys.count;i++)
  6652. {
  6653. [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  6654. }
  6655. if(appDelegate.offline_mode)
  6656. {
  6657. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  6658. // [OLDataProvider offline_add2cartbyname:params completionHandler:result];
  6659. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6660. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_add2cartbyupc:params]] mutableCopy];
  6661. dispatch_async(dispatch_get_main_queue(), ^{
  6662. int result_code = [[json valueForKey:@"result"] intValue];
  6663. if (result_code==2||result_code==8)
  6664. {
  6665. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  6666. [appDelegate update_count_mark];
  6667. }
  6668. result(json);
  6669. });
  6670. });
  6671. return;
  6672. }
  6673. [self request_interface:URL_ADD_TO_CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6674. int result_code = [[resulti valueForKey:@"result"] intValue];
  6675. if (result_code==2||result_code==8)
  6676. {
  6677. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6678. [appDelegate update_count_mark];
  6679. }
  6680. result(resulti);
  6681. } retry:0];
  6682. }
  6683. +(void) request_addto_cart_byname:(NSString* ) model_name withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  6684. {
  6685. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6686. AppDelegate *appDelegate = nil;
  6687. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6688. if(RASingleton.sharedInstance.user!=nil)
  6689. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  6690. if(appDelegate.contact_id!=nil)
  6691. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6692. if(RASingleton.sharedInstance.password!=nil)
  6693. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  6694. if(appDelegate.order_code!=nil)
  6695. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6696. [params setValue:model_name forKey:@"product_name"];
  6697. [params setValue:[NSString stringWithFormat:@"%d",-1] forKey:@"count"];
  6698. [params setObject:screenName forKey:kScreenName];
  6699. [params setObject:@"Add To Cart" forKey:kAction];
  6700. if (!model_name) {
  6701. model_name = @"";
  6702. }
  6703. [params setObject:@{@"ModelName" : model_name} forKey:kExtra];
  6704. NSDictionary* customerinfo= appDelegate.customerInfo;
  6705. NSArray* keys=[customerinfo allKeys];
  6706. for(int i=0;i<keys.count;i++)
  6707. {
  6708. [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  6709. }
  6710. if(appDelegate.offline_mode)
  6711. {
  6712. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  6713. // [OLDataProvider offline_add2cartbyname:params completionHandler:result];
  6714. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6715. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_add2cartbyname:params]] mutableCopy];
  6716. dispatch_async(dispatch_get_main_queue(), ^{
  6717. int result_code = [[json valueForKey:@"result"] intValue];
  6718. if (result_code==2||result_code==8)
  6719. {
  6720. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  6721. [appDelegate update_count_mark];
  6722. }
  6723. result(json);
  6724. });
  6725. });
  6726. return;
  6727. }
  6728. [self request_interface:URL_ADD_TO_CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6729. int result_code = [[resulti valueForKey:@"result"] intValue];
  6730. if (result_code==2||result_code==8)
  6731. {
  6732. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6733. [appDelegate update_count_mark];
  6734. }
  6735. result(resulti);
  6736. } retry:0];
  6737. // NSData* json=nil;
  6738. // if(appDelegate.offline_mode)
  6739. // {
  6740. // json= [OLDataProvider offline_add2cartbyname:params];
  6741. // }
  6742. // else
  6743. // {
  6744. // if(![self IsNetworkAvailable])
  6745. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6746. //
  6747. // json=[self get_json:URL_ADD_TO_CART parameters:params];
  6748. // }
  6749. // if(json==nil)
  6750. // return nil;
  6751. // NSError *error=nil;
  6752. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6753. //
  6754. //
  6755. //
  6756. // int result = [[jsobj valueForKey:@"result"] intValue];
  6757. //
  6758. // if (result==2||result==8)
  6759. // {
  6760. //
  6761. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6762. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6763. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6764. //
  6765. // [appDelegate update_count_mark];
  6766. // }
  6767. //
  6768. // return jsobj;
  6769. }
  6770. +(void) request_addto_wishlist:(NSString* ) item_id withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  6771. {
  6772. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6773. AppDelegate *appDelegate = nil;
  6774. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6775. if(RASingleton.sharedInstance.user!=nil)
  6776. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  6777. if(appDelegate.contact_id!=nil)
  6778. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6779. if(RASingleton.sharedInstance.password!=nil)
  6780. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  6781. [params setValue:item_id forKey:@"product_id"];
  6782. [params setObject:screenName forKey:kScreenName];
  6783. if(appDelegate.offline_mode)
  6784. {
  6785. // [OLDataProvider offline_add2wishlist:params completionHandler:result];
  6786. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6787. NSMutableDictionary* resulti = [[OLDataProvider offline_add2wishlist:params] mutableCopy];
  6788. dispatch_async(dispatch_get_main_queue(), ^{
  6789. int result_code = [[resulti valueForKey:@"result"] intValue];
  6790. if (result_code==2||result_code==8)
  6791. {
  6792. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6793. [appDelegate update_count_mark];
  6794. }
  6795. result(resulti);
  6796. });
  6797. });
  6798. return;
  6799. }
  6800. [self request_interface:URL_ADD_TO_WATCHLIST parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6801. int result_code = [[resulti valueForKey:@"result"] intValue];
  6802. if (result_code==2||result_code==8)
  6803. {
  6804. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6805. [appDelegate update_count_mark];
  6806. }
  6807. result(resulti);
  6808. } retry:0];
  6809. // if(appDelegate.offline_mode)
  6810. // {
  6811. // return [OLDataProvider offline_add2wishlist:params];
  6812. // }
  6813. // if(![self IsNetworkAvailable])
  6814. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6815. //
  6816. // NSData* json=[self get_json:URL_ADD_TO_WATCHLIST parameters:params];
  6817. // if(json==nil)
  6818. // return nil;
  6819. // NSError *error=nil;
  6820. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6821. // int result = [[jsobj valueForKey:@"result"] intValue];
  6822. //
  6823. // if (result==2)
  6824. // {
  6825. //
  6826. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6827. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6828. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6829. //
  6830. // [appDelegate update_count_mark];
  6831. // }
  6832. // return jsobj;
  6833. }
  6834. +(void)request_addall_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 orderCode:(NSString*) orderCode addTo:(NSString*) addTo completionHandler:(resultHandler)result
  6835. {
  6836. // for debug
  6837. // return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
  6838. //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6839. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6840. AppDelegate *appDelegate = nil;
  6841. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6842. if(RASingleton.sharedInstance.user!=nil)
  6843. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  6844. if(appDelegate.contact_id!=nil)
  6845. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6846. if(RASingleton.sharedInstance.password!=nil)
  6847. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  6848. if(appDelegate.order_code!=nil)
  6849. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6850. [params setValue:addTo forKey:@"addTo"];
  6851. [params setValue:orderCode forKey:@"orderCode"];
  6852. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  6853. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  6854. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  6855. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  6856. // [params setValue:filter forKey:@"filter"];
  6857. [params setValue:covertype forKey:@"covertype"];
  6858. [params setValue:ctgid forKey:@"ctgId"];
  6859. [params setValue:modelname forKey:@"modelName"];
  6860. [params setValue:modeldescrip forKey:@"modelDescription"];
  6861. [params setValue:alert forKey:@"alert"];
  6862. [params setValue:qty forKey:@"sold_by_qty"];
  6863. [params setValue:available forKey:@"available"];
  6864. [params setValue:price forKey:@"price"];
  6865. [params setValue:bestseller forKey:@"bestseller"];
  6866. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  6867. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  6868. [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
  6869. if ([addTo isEqualToString:@"cart"]) {
  6870. [params setObject:@"Add To Cart" forKey:kAction];
  6871. }
  6872. if(appDelegate.offline_mode)
  6873. {
  6874. if ([addTo isEqualToString:@"cart"])
  6875. {
  6876. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  6877. }
  6878. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6879. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_itemsearchaddall:params]] mutableCopy];
  6880. dispatch_async(dispatch_get_main_queue(), ^{
  6881. int result_code =[json[@"result"] intValue];
  6882. if (result_code==2||result_code==8)
  6883. {
  6884. if(json[@"cart_count"])
  6885. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  6886. if(json[@"wish_count"])
  6887. appDelegate.wish_count =[[json valueForKey:@"wish_count"] intValue];
  6888. if(json[@"portfolio_count"])
  6889. appDelegate.port_count =[[json valueForKey:@"portfolio_count"] intValue];
  6890. //
  6891. //
  6892. [appDelegate update_count_mark];
  6893. }
  6894. result(json);
  6895. });
  6896. });
  6897. return;
  6898. }
  6899. NSString * uuid= [[NSUUID UUID] UUIDString];
  6900. params[@"resultSerial"]=uuid;
  6901. __block bool bbreak = false;
  6902. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6903. for(int i=0;i<150;i++)
  6904. {
  6905. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6906. // result_params[@"resultSerial"]=uuid;
  6907. if(bbreak)
  6908. break;
  6909. dispatch_async(dispatch_get_main_queue(), ^{
  6910. [self request_interface:URL_ITEMSEARCHADDALL parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6911. if([resulti[@"result"] intValue]==2)
  6912. {
  6913. if(!bbreak)//此判断保证result只调用一次。
  6914. result(resulti);
  6915. bbreak=true;
  6916. }
  6917. } retry:3];
  6918. });
  6919. sleep(2);
  6920. }
  6921. });
  6922. //
  6923. // NSData* json = nil;
  6924. //
  6925. // if(appDelegate.offline_mode)
  6926. // {
  6927. // json= [OLDataProvider offline_itemsearchaddall:params];
  6928. // }
  6929. // else
  6930. // {
  6931. // if(![self IsNetworkAvailable])
  6932. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6933. // NSError *error=nil;
  6934. //
  6935. // NSString * uuid= [[NSUUID UUID] UUIDString];
  6936. // params[@"resultSerial"]=uuid;
  6937. //
  6938. // for(int i=0;i<150;i++)
  6939. // {
  6940. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6941. // // result_params[@"resultSerial"]=uuid;
  6942. // json=[self get_json:URL_ITEMSEARCHADDALL parameters:params];
  6943. // if(json!=nil)
  6944. // {
  6945. //
  6946. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6947. // if([jsobj[@"result"] intValue]==2)
  6948. // {
  6949. // break;
  6950. // }
  6951. // }
  6952. // sleep(2);
  6953. // }
  6954. // }
  6955. // if(json==nil)
  6956. // return nil;
  6957. // NSError *error=nil;
  6958. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6959. // return jsobj;
  6960. }
  6961. +(void)request_addall_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 orderCode:(NSString*) orderCode addTo:(NSString*) addTo completionHandler:(resultHandler)result
  6962. {
  6963. AppDelegate *appDelegate = nil;
  6964. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6965. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6966. if(RASingleton.sharedInstance.user!=nil)
  6967. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  6968. if(appDelegate.contact_id!=nil)
  6969. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6970. if(RASingleton.sharedInstance.password!=nil)
  6971. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  6972. if(appDelegate.order_code!=nil)
  6973. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6974. [params setValue:addTo forKey:@"addTo"];
  6975. [params setValue:orderCode forKey:@"orderCode"];
  6976. [params setValue:alert forKey:@"alert"];
  6977. [params setValue:qty forKey:@"sold_by_qty"];
  6978. [params setValue:available forKey:@"available"];
  6979. [params setValue:price forKey:@"price"];
  6980. [params setValue:bestseller forKey:@"bestseller"];
  6981. [params setValue:modelname forKey:@"modelName"];
  6982. [params setValue:modeldescrip forKey:@"modelDescription"];
  6983. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  6984. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  6985. [params setValue:category forKey:@"category"];
  6986. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  6987. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  6988. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  6989. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  6990. [params setValue:filter forKey:@"filter"];
  6991. [params setValue:keyword forKey:@"keyword"];
  6992. [params setObject:ScreenCodeCategory forKey:kScreenName];
  6993. if ([addTo isEqualToString:@"cart"]) {
  6994. [params setObject:@"Add To Cart" forKey:kAction];
  6995. }
  6996. if(appDelegate.offline_mode)
  6997. {
  6998. if ([addTo isEqualToString:@"cart"])
  6999. {
  7000. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  7001. }
  7002. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7003. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_categoryaddall:params]] mutableCopy];
  7004. dispatch_async(dispatch_get_main_queue(), ^{
  7005. int result_code =[json[@"result"] intValue];
  7006. if (result_code==2||result_code==8)
  7007. {
  7008. if(json[@"cart_count"])
  7009. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  7010. if(json[@"wish_count"])
  7011. appDelegate.wish_count =[[json valueForKey:@"wish_count"] intValue];
  7012. if(json[@"portfolio_count"])
  7013. appDelegate.port_count =[[json valueForKey:@"portfolio_count"] intValue];
  7014. //
  7015. //
  7016. [appDelegate update_count_mark];
  7017. }
  7018. result(json);
  7019. });
  7020. });
  7021. return;
  7022. }
  7023. NSString * uuid= [[NSUUID UUID] UUIDString];
  7024. params[@"resultSerial"]=uuid;
  7025. __block bool bbreak = false;
  7026. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7027. for(int i=0;i<150;i++)
  7028. {
  7029. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7030. // result_params[@"resultSerial"]=uuid;
  7031. if(bbreak)
  7032. break;
  7033. dispatch_async(dispatch_get_main_queue(), ^{
  7034. [self request_interface:URL_CATEGORYADDALL parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7035. if([resulti[@"result"] intValue]==2|| [resulti[@"result"] intValue] == 8)
  7036. {
  7037. if(!bbreak)//此判断保证result只调用一次。
  7038. {
  7039. int result_code =[resulti[@"result"] intValue];
  7040. if (result_code==2||result_code==8)
  7041. {
  7042. if(resulti[@"cart_count"])
  7043. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  7044. if(resulti[@"wish_count"])
  7045. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  7046. if(resulti[@"portfolio_count"])
  7047. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  7048. //
  7049. //
  7050. [appDelegate update_count_mark];
  7051. }
  7052. result(resulti);
  7053. }
  7054. bbreak=true;
  7055. }
  7056. } retry:3];
  7057. });
  7058. sleep(2);
  7059. }
  7060. });
  7061. //
  7062. // NSData* json= nil;
  7063. //
  7064. // if(appDelegate.offline_mode)
  7065. // {
  7066. // json= [OLDataProvider offline_categoryaddall:params];
  7067. // }
  7068. // else
  7069. // {
  7070. // if(![self IsNetworkAvailable])
  7071. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7072. //
  7073. //
  7074. // NSError *error=nil;
  7075. //
  7076. // NSString * uuid= [[NSUUID UUID] UUIDString];
  7077. // params[@"resultSerial"]=uuid;
  7078. //
  7079. // for(int i=0;i<150;i++)
  7080. // {
  7081. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7082. //// result_params[@"resultSerial"]=uuid;
  7083. // json=[self get_json:URL_CATEGORYADDALL parameters:params];
  7084. // if(json!=nil)
  7085. // {
  7086. //
  7087. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7088. // int resultInt = [jsobj[@"result"] intValue];
  7089. // if(resultInt == 2 || resultInt == 8)
  7090. // {
  7091. // break;
  7092. // }
  7093. // }
  7094. // sleep(2);
  7095. // }
  7096. //
  7097. //
  7098. //
  7099. // }
  7100. // if(json==nil)
  7101. // return nil;
  7102. // NSError *error=nil;
  7103. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7104. // return jsobj;
  7105. }
  7106. +(void)request_save_order:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  7107. {
  7108. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7109. AppDelegate *appDelegate = nil;
  7110. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7111. if(RASingleton.sharedInstance.user!=nil)
  7112. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  7113. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  7114. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  7115. // else
  7116. if(appDelegate.contact_id!=nil)
  7117. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7118. if(RASingleton.sharedInstance.password!=nil)
  7119. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  7120. if(appDelegate.order_code!=nil)
  7121. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  7122. // NSDictionary* customerinfo=nil;
  7123. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  7124. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  7125. // else
  7126. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7127. //
  7128. // appDelegate.customerInfo;
  7129. // NSArray* keys=[customerinfo allKeys];
  7130. // for(int i=0;i<keys.count;i++)
  7131. // {
  7132. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  7133. // }
  7134. // [params setValue:sourceid forKey:@"sourceid"];
  7135. // [params setValue:editor forKey:@"editor"];
  7136. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  7137. if(appDelegate.offline_mode)
  7138. {
  7139. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7140. NSData* json = [[OLDataProvider offline_saveorder:params] mutableCopy];
  7141. dispatch_async(dispatch_get_main_queue(), ^{
  7142. result([[RAConvertor data2dict:json] mutableCopy]);
  7143. });
  7144. });
  7145. return;
  7146. }
  7147. [self request_interface:URL_SAVE_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  7148. //
  7149. // NSData* json=nil;
  7150. //
  7151. // if(appDelegate.offline_mode)
  7152. // {
  7153. // json= [OLDataProvider offline_saveorder:params];
  7154. // }
  7155. // else
  7156. // {
  7157. // if(![self IsNetworkAvailable])
  7158. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7159. //
  7160. // json=[self get_json:URL_SAVE_ORDER parameters:params];
  7161. // }
  7162. // if(json!=nil)
  7163. // {
  7164. // NSError *error=nil;
  7165. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7166. // NSString *so = [jsobj valueForKey:@"so#"];
  7167. // if (so) {
  7168. // [appDelegate SetSo:so];
  7169. // }
  7170. // return jsobj;
  7171. // }
  7172. // else
  7173. // return nil;
  7174. }
  7175. +(void) request_update_cartqty:(NSString*) cart_id value:(int) value completionHandler:(resultHandler)result
  7176. {
  7177. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  7178. #ifdef SCANNER_ORDER
  7179. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  7180. {
  7181. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  7182. //
  7183. //
  7184. // [appDelegate update_count_mark];
  7185. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  7186. int count = [section[@"count"] intValue];
  7187. for(int i=0;i<count;i++)
  7188. {
  7189. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  7190. if([item[@"cart_item_id"] isEqualToString:cart_id])
  7191. {
  7192. item[@"count"] =@(value);
  7193. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  7194. break;
  7195. }
  7196. }
  7197. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  7198. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  7199. result(RASingleton.sharedInstance.scan_cart);
  7200. [OLDataProvider updateScanOrder:appDelegate.order_code];
  7201. return;
  7202. }
  7203. #else
  7204. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7205. if(RASingleton.sharedInstance.user!=nil)
  7206. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  7207. if(appDelegate.contact_id!=nil)
  7208. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7209. if(RASingleton.sharedInstance.password!=nil)
  7210. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  7211. [params setValue:cart_id forKey:@"cartitem_id"];
  7212. [params setObject:ScreenCodeCart forKey:kScreenName];
  7213. [params setValue:[NSString stringWithFormat:@"%d",value] forKey:@"inputInt"];
  7214. if(appDelegate.offline_mode)
  7215. {
  7216. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  7217. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7218. NSData* json = [[OLDataProvider offline_cartsetqty:params] mutableCopy];
  7219. dispatch_async(dispatch_get_main_queue(), ^{
  7220. result([[RAConvertor data2dict:json] mutableCopy]);
  7221. });
  7222. });
  7223. return;
  7224. }
  7225. [self request_interface:URL_CART_INCRESEMENT parameters:params err_record_url:nil completionHandler:result retry:0];
  7226. //
  7227. // NSData* json=nil;
  7228. // if(appDelegate.offline_mode)
  7229. // {
  7230. // json= [OLDataProvider offline_cartsetqty:params];
  7231. // }
  7232. // else
  7233. // {
  7234. // if(![self IsNetworkAvailable])
  7235. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7236. //
  7237. // json=[self get_json:URL_CART_INCRESEMENT parameters:params];
  7238. // }
  7239. // if(json==nil)
  7240. // return nil;
  7241. // NSError *error=nil;
  7242. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7243. // return jsobj;
  7244. #endif
  7245. }
  7246. +(void) request_update_cartgeneralnote:(NSString*) order_code notes:(NSString*) notes completionHandler:(resultHandler)result
  7247. {
  7248. #ifdef SCANNER_ORDER
  7249. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  7250. {
  7251. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  7252. //
  7253. //
  7254. // [appDelegate update_count_mark];
  7255. RASingleton.sharedInstance.scan_cart[@"general_note"] = notes;
  7256. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  7257. result(RASingleton.sharedInstance.scan_cart);
  7258. return;
  7259. }
  7260. #else
  7261. AppDelegate *appDelegate = nil;
  7262. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7263. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7264. if(RASingleton.sharedInstance.user!=nil)
  7265. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  7266. if(appDelegate.contact_id!=nil)
  7267. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7268. if(RASingleton.sharedInstance.password!=nil)
  7269. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  7270. [params setValue:order_code forKey:@"orderCode"];
  7271. [params setObject:ScreenCodeCart forKey:kScreenName];
  7272. if(notes.length==0)
  7273. notes=@"";
  7274. [params setValue:notes forKey:@"comments"];
  7275. if(appDelegate.offline_mode)
  7276. {
  7277. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7278. NSData* json = [[OLDataProvider offline_updategnotes:params] mutableCopy];
  7279. dispatch_async(dispatch_get_main_queue(), ^{
  7280. result([[RAConvertor data2dict:json] mutableCopy]);
  7281. });
  7282. });
  7283. return;
  7284. }
  7285. [self request_interface:URL_CART_GENERAL_NOTES parameters:params err_record_url:nil completionHandler:result retry:0];
  7286. //
  7287. // NSData* json=nil;
  7288. // if(appDelegate.offline_mode)
  7289. // {
  7290. // json= [OLDataProvider offline_updategnotes:params];
  7291. // }
  7292. // else
  7293. // {
  7294. // if(![self IsNetworkAvailable])
  7295. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7296. //
  7297. // json=[self get_json:URL_CART_GENERAL_NOTES parameters:params];
  7298. // }
  7299. // if(json==nil)
  7300. // return nil;
  7301. // NSError *error=nil;
  7302. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7303. // return jsobj;
  7304. #endif
  7305. }
  7306. +(void) request_update_cartitemnote:(NSString*) cart_id notes:(NSString*) notes completionHandler:(resultHandler)result
  7307. {
  7308. AppDelegate *appDelegate = nil;
  7309. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7310. #ifdef SCANNER_ORDER
  7311. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  7312. {
  7313. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  7314. //
  7315. //
  7316. // [appDelegate update_count_mark];
  7317. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  7318. int count = [section[@"count"] intValue];
  7319. for(int i=0;i<count;i++)
  7320. {
  7321. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  7322. if([item[@"cart_item_id"] isEqualToString:cart_id])
  7323. {
  7324. item[@"note"] =notes;
  7325. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  7326. break;
  7327. }
  7328. }
  7329. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  7330. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  7331. result(RASingleton.sharedInstance.scan_cart);
  7332. return;
  7333. }
  7334. #else
  7335. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7336. if(RASingleton.sharedInstance.user!=nil)
  7337. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  7338. if(appDelegate.contact_id!=nil)
  7339. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7340. if(RASingleton.sharedInstance.password!=nil)
  7341. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  7342. [params setValue:cart_id forKey:@"cartitem_id"];
  7343. [params setObject:ScreenCodeCart forKey:kScreenName];
  7344. if(notes.length==0)
  7345. notes=@"";
  7346. [params setValue:notes forKey:@"notes"];
  7347. if(appDelegate.offline_mode)
  7348. {
  7349. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7350. NSData* json = [[OLDataProvider offline_cartsetlnotes:params] mutableCopy];
  7351. dispatch_async(dispatch_get_main_queue(), ^{
  7352. result([[RAConvertor data2dict:json] mutableCopy]);
  7353. });
  7354. });
  7355. return;
  7356. }
  7357. [self request_interface:URL_CART_ITEM_NOTES parameters:params err_record_url:nil completionHandler:result retry:0];
  7358. //
  7359. // NSData* json=nil;
  7360. // if(appDelegate.offline_mode)
  7361. // {
  7362. // json= [OLDataProvider offline_cartsetlnotes:params];
  7363. // }
  7364. // else
  7365. // {
  7366. // if(![self IsNetworkAvailable])
  7367. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7368. //
  7369. // json=[self get_json:URL_CART_ITEM_NOTES parameters:params];
  7370. // }
  7371. // if(json==nil)
  7372. // return nil;
  7373. // NSError *error=nil;
  7374. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7375. // return jsobj;
  7376. #endif
  7377. }
  7378. + (void)request_update_npd_shop_price_type:(NSInteger)priceType completionHandler:(resultHandler)result
  7379. {
  7380. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  7381. AppDelegate *appDelegate = nil;
  7382. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7383. if(RASingleton.sharedInstance.user!=nil)
  7384. [dic setValue:RASingleton.sharedInstance.user forKey:@"user"];
  7385. if(RASingleton.sharedInstance.password!=nil)
  7386. [dic setValue:RASingleton.sharedInstance.password forKey:@"password"];
  7387. [dic setValue:[NSString stringWithFormat:@"%ld",priceType] forKey:@"price_type"];
  7388. [dic setObject:ScreenCodePriceSetting forKey:kScreenName];
  7389. if(appDelegate.offline_mode)
  7390. {
  7391. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7392. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  7393. dispatch_async(dispatch_get_main_queue(), ^{
  7394. result(json);
  7395. });
  7396. });
  7397. return;
  7398. }
  7399. [self request_interface:URL_SET_PRICE_TYPE parameters:dic err_record_url:nil completionHandler:result retry:0];
  7400. //
  7401. // NSData* json=nil;
  7402. // if(appDelegate.offline_mode)
  7403. // {
  7404. // return [OLDataProvider offline_notimpl];
  7405. // }
  7406. // else
  7407. // {
  7408. // if(![self IsNetworkAvailable])
  7409. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7410. //
  7411. // json = [RANetwork get_json:URL_SET_PRICE_TYPE parameters:dic];
  7412. // }
  7413. // if(json!=nil)
  7414. // {
  7415. // NSError *error=nil;
  7416. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7417. //
  7418. //
  7419. // return jsobj;
  7420. // }
  7421. //
  7422. //
  7423. // return nil;
  7424. }
  7425. + (void)request_npd_shop_givenprice:(resultHandler)result
  7426. {
  7427. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  7428. AppDelegate *appDelegate = nil;
  7429. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7430. if(RASingleton.sharedInstance.user!=nil)
  7431. [dic setValue:RASingleton.sharedInstance.user forKey:@"user"];
  7432. if(RASingleton.sharedInstance.password!=nil)
  7433. [dic setValue:RASingleton.sharedInstance.password forKey:@"password"];
  7434. [dic setObject:ScreenCodeCategoryPrice forKey:kScreenName];
  7435. if(appDelegate.offline_mode)
  7436. {
  7437. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7438. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  7439. dispatch_async(dispatch_get_main_queue(), ^{
  7440. result(json);
  7441. });
  7442. });
  7443. return;
  7444. }
  7445. [self request_interface:URL_GET_CIVEN_PRICE parameters:dic err_record_url:nil completionHandler:result retry:0];
  7446. //
  7447. // NSData* json=nil;
  7448. // if(appDelegate.offline_mode)
  7449. // {
  7450. // return [OLDataProvider offline_notimpl];
  7451. // }
  7452. // else
  7453. // {
  7454. // if(![self IsNetworkAvailable])
  7455. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7456. //
  7457. // json = [RANetwork get_json:URL_GET_CIVEN_PRICE parameters:dic];
  7458. // }
  7459. // if(json!=nil)
  7460. // {
  7461. // NSError *error=nil;
  7462. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7463. //
  7464. //
  7465. // return jsobj;
  7466. // }
  7467. //
  7468. //
  7469. // return nil;
  7470. }
  7471. + (void)request_update_npd_shop_givenprice:(NSMutableDictionary *)params completionHandler:(resultHandler)result
  7472. {
  7473. AppDelegate *appDelegate = nil;
  7474. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7475. if(RASingleton.sharedInstance.user!=nil)
  7476. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  7477. if(RASingleton.sharedInstance.password!=nil)
  7478. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  7479. [params setObject:ScreenCodeSetCatetoryPrice forKey:kScreenName];
  7480. if(appDelegate.offline_mode)
  7481. {
  7482. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7483. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  7484. dispatch_async(dispatch_get_main_queue(), ^{
  7485. result(json);
  7486. });
  7487. });
  7488. return;
  7489. }
  7490. [self request_interface:URL_SET_GIVEN_PRICE parameters:params err_record_url:nil completionHandler:result retry:0];
  7491. //
  7492. // NSData* json=nil;
  7493. // if(appDelegate.offline_mode)
  7494. // {
  7495. // return [OLDataProvider offline_notimpl];
  7496. // }
  7497. // else
  7498. // {
  7499. // if(![self IsNetworkAvailable])
  7500. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7501. //
  7502. // json = [RANetwork get_json:URL_SET_GIVEN_PRICE parameters:params];
  7503. // }
  7504. // if(json!=nil)
  7505. // {
  7506. // NSError *error=nil;
  7507. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7508. //
  7509. //
  7510. // return jsobj;
  7511. // }
  7512. //
  7513. //
  7514. // return nil;
  7515. }
  7516. +(void) request_create_portfolio:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  7517. {
  7518. AppDelegate *appDelegate = nil;
  7519. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7520. if(appDelegate.offline_mode)
  7521. {
  7522. params[@"contact_id"]=params[@"contactId"];
  7523. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7524. NSData* json = [[OLDataProvider offline_direct_save_TearSheet:params] mutableCopy];
  7525. dispatch_async(dispatch_get_main_queue(), ^{
  7526. result([[RAConvertor data2dict:json] mutableCopy]);
  7527. });
  7528. });
  7529. return;
  7530. }
  7531. //
  7532. // if(appDelegate.offline_mode)
  7533. // {
  7534. //
  7535. //
  7536. // NSData*json = [OLDataProvider offline_direct_save_TearSheet:params];
  7537. // if(json==nil)
  7538. // return nil;
  7539. // NSError *error=nil;
  7540. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7541. //
  7542. // return jsobj[@"pdf_path"];
  7543. // }
  7544. // else
  7545. // {
  7546. // return nil;
  7547. // }
  7548. }
  7549. +(void)request_save_portfoliodirectly:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  7550. {
  7551. NSMutableDictionary* off_params = [params mutableCopy];
  7552. AppDelegate *appDelegate = nil;
  7553. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7554. if(RASingleton.sharedInstance.user!=nil)
  7555. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  7556. if(appDelegate.contact_id!=nil)
  7557. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7558. if(RASingleton.sharedInstance.password!=nil)
  7559. params[@"off_params"]=[RAConvertor dict2string:off_params];
  7560. [off_params removeObjectForKey:@"password"]; // 确保离线参数不会写入创建用户的密码;
  7561. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  7562. [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  7563. if(appDelegate.offline_mode)
  7564. {
  7565. params[@"contact_id"]=appDelegate.contact_id;
  7566. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7567. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_direct_save_TearSheet:params]] mutableCopy];
  7568. dispatch_async(dispatch_get_main_queue(), ^{
  7569. result(json);
  7570. });
  7571. });
  7572. return;
  7573. }
  7574. NSString * uuid= [[NSUUID UUID] UUIDString];
  7575. params[@"resultSerial"]=uuid;
  7576. __block bool bbreak = false;
  7577. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7578. for(int i=0;i<150;i++)
  7579. {
  7580. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7581. // result_params[@"resultSerial"]=uuid;
  7582. if(bbreak)
  7583. break;
  7584. dispatch_async(dispatch_get_main_queue(), ^{
  7585. [self request_interface:URL_REQUEST_DM parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7586. if([resulti[@"result"] intValue]==2)
  7587. {
  7588. if(!bbreak)//此判断保证result只调用一次。
  7589. result(resulti);
  7590. bbreak=true;
  7591. }
  7592. } retry:3];
  7593. });
  7594. sleep(2);
  7595. }
  7596. });
  7597. //
  7598. //
  7599. // NSData* json= nil;
  7600. //
  7601. // if(appDelegate.offline_mode)
  7602. // {
  7603. // json = [OLDataProvider offline_direct_save_TearSheet:params];
  7604. // }
  7605. // else
  7606. // {
  7607. // if(![self IsNetworkAvailable])
  7608. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7609. //
  7610. // json=[self get_json:URL_REQUEST_DM parameters:params];
  7611. //
  7612. // NSError *error=nil;
  7613. //
  7614. // NSString * uuid= [[NSUUID UUID] UUIDString];
  7615. // params[@"resultSerial"]=uuid;
  7616. //
  7617. // for(int i=0;i<150;i++)
  7618. // {
  7619. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7620. // // result_params[@"resultSerial"]=uuid;
  7621. // json=[self get_json:URL_REQUEST_DM parameters:params];
  7622. // if(json!=nil)
  7623. // {
  7624. //
  7625. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7626. // if([jsobj[@"result"] intValue]==2)
  7627. // {
  7628. // break;
  7629. // }
  7630. // }
  7631. // sleep(5);
  7632. // }
  7633. //
  7634. // }
  7635. // if(json==nil)
  7636. // return nil;
  7637. // NSError *error=nil;
  7638. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7639. // return jsobj;
  7640. }
  7641. +(void)request_save_portfolio:(NSMutableDictionary *)params completionHandler:(resultHandler)result
  7642. {
  7643. AppDelegate *appDelegate = nil;
  7644. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7645. if(RASingleton.sharedInstance.user!=nil)
  7646. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  7647. if(appDelegate.contact_id!=nil)
  7648. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7649. NSMutableDictionary* off_params = [params mutableCopy];;
  7650. [off_params removeObjectForKey:@"password"]; // 确保离线参数不会写入创建用户的密码;
  7651. params[@"off_params"]=[RAConvertor dict2string:off_params];
  7652. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7653. if(RASingleton.sharedInstance.password!=nil)
  7654. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  7655. [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  7656. if(appDelegate.offline_mode)
  7657. {
  7658. params[@"contact_id"]=appDelegate.contact_id;
  7659. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7660. NSData* json = [[OLDataProvider offline_save_TearSheet:params] mutableCopy];
  7661. dispatch_async(dispatch_get_main_queue(), ^{
  7662. result([[RAConvertor data2dict:json] mutableCopy]);
  7663. });
  7664. });
  7665. return;
  7666. }
  7667. [self request_interface:URL_SAVE_DM parameters:params err_record_url:nil completionHandler:result retry:0];
  7668. //
  7669. // NSData* json = nil;
  7670. // if(appDelegate.offline_mode)
  7671. // {
  7672. // json = [OLDataProvider offline_save_TearSheet:params];
  7673. // } else {
  7674. // if(![self IsNetworkAvailable])
  7675. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7676. //
  7677. // json=[self get_json:URL_SAVE_DM parameters:params];
  7678. // }
  7679. // if(json==nil)
  7680. // return nil;
  7681. // NSError *error=nil;
  7682. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7683. // return jsobj;
  7684. }
  7685. +(void)request_portfoliopreview:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  7686. {
  7687. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7688. AppDelegate *appDelegate = nil;
  7689. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7690. if(RASingleton.sharedInstance.user!=nil)
  7691. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  7692. if(appDelegate.contact_id!=nil)
  7693. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7694. if(RASingleton.sharedInstance.password!=nil)
  7695. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  7696. [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  7697. // [params setValue:request_url forKey:@"pdfUrl"];
  7698. if(appDelegate.offline_mode)
  7699. {
  7700. params[@"contact_id"]=params[@"contactId"];
  7701. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7702. NSData* json = [[OLDataProvider offline_request_tearsheet:params] mutableCopy];
  7703. dispatch_async(dispatch_get_main_queue(), ^{
  7704. result([[RAConvertor data2dict:json] mutableCopy]);
  7705. });
  7706. });
  7707. return;
  7708. }
  7709. NSString * uuid= [[NSUUID UUID] UUIDString];
  7710. params[@"resultSerial"]=uuid;
  7711. __block bool bbreak = false;
  7712. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7713. for(int i=0;i<150;i++)
  7714. {
  7715. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7716. // result_params[@"resultSerial"]=uuid;
  7717. if(bbreak)
  7718. break;
  7719. dispatch_async(dispatch_get_main_queue(), ^{
  7720. [self request_interface:URL_REQUEST_DM parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7721. if([resulti[@"result"] intValue]==2)
  7722. {
  7723. if(!bbreak)//此判断保证result只调用一次。
  7724. result(resulti);
  7725. bbreak=true;
  7726. }
  7727. } retry:3];
  7728. });
  7729. sleep(5);
  7730. }
  7731. });
  7732. //
  7733. // NSData* json= nil;
  7734. // if(appDelegate.offline_mode)
  7735. // {
  7736. // json= [OLDataProvider offline_request_tearsheet:params];
  7737. // }
  7738. // else
  7739. // {
  7740. // if(![self IsNetworkAvailable])
  7741. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7742. //
  7743. // NSError *error=nil;
  7744. //
  7745. // NSString * uuid= [[NSUUID UUID] UUIDString];
  7746. // params[@"resultSerial"]=uuid;
  7747. //
  7748. // for(int i=0;i<150;i++)
  7749. // {
  7750. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7751. // // result_params[@"resultSerial"]=uuid;
  7752. // json=[self get_json:URL_REQUEST_DM parameters:params];
  7753. // if(json!=nil)
  7754. // {
  7755. //
  7756. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7757. // if([jsobj[@"result"] intValue]==2)
  7758. // {
  7759. // break;
  7760. // }
  7761. // }
  7762. // sleep(5);
  7763. // }
  7764. // }
  7765. // if(json==nil)
  7766. // return nil;
  7767. // NSError *error=nil;
  7768. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7769. // return jsobj;
  7770. }
  7771. +(void)request_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 completionHandler:(resultHandler)result
  7772. {
  7773. // for debug
  7774. // return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
  7775. //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7776. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7777. AppDelegate *appDelegate = nil;
  7778. //some UI methods ej
  7779. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7780. if(RASingleton.sharedInstance.user!=nil)
  7781. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  7782. if(appDelegate.contact_id!=nil)
  7783. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7784. if(RASingleton.sharedInstance.password!=nil)
  7785. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  7786. if(appDelegate.order_code!=nil)
  7787. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  7788. [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
  7789. if (alert && qty && available && price && bestseller) {
  7790. [params setObject:@"Filter" forKey:kAction];
  7791. }
  7792. if ([RASingleton sharedInstance].homeItemClick) {
  7793. [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
  7794. [RASingleton sharedInstance].homeItemClick = NO;
  7795. NSDictionary *extra = @{@"CoverName" : [RASingleton sharedInstance].homeClickedItemName};
  7796. [RASingleton sharedInstance].homeClickedItemName = nil;
  7797. [params setObject:extra forKey:kExtra];
  7798. }
  7799. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  7800. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  7801. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  7802. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  7803. // [params setValue:filter forKey:@"filter"];
  7804. [params setValue:covertype forKey:@"covertype"];
  7805. [params setValue:ctgid forKey:@"ctgId"];
  7806. [params setValue:modelname forKey:@"modelName"];
  7807. [params setValue:modeldescrip forKey:@"modelDescription"];
  7808. [params setValue:alert forKey:@"alert"];
  7809. [params setValue:qty forKey:@"sold_by_qty"];
  7810. [params setValue:available forKey:@"available"];
  7811. [params setValue:price forKey:@"price"];
  7812. [params setValue:bestseller forKey:@"bestseller"];
  7813. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  7814. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  7815. if(appDelegate.offline_mode)
  7816. {
  7817. // [OLDataProvider offline_itemsearch:params completionHandler:result];
  7818. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7819. NSMutableDictionary* json = [[OLDataProvider offline_itemsearch:params] mutableCopy];
  7820. dispatch_async(dispatch_get_main_queue(), ^{
  7821. result(json);
  7822. });
  7823. });
  7824. return;
  7825. }
  7826. [self request_interface:URL_ITEM_SEARCH parameters:params err_record_url:nil completionHandler:result retry:0];
  7827. // if(appDelegate.offline_mode)
  7828. // {
  7829. // return [OLDataProvider offline_itemsearch:params];
  7830. // }
  7831. // if(![self IsNetworkAvailable])
  7832. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7833. // NSData* json=[self get_json:URL_ITEM_SEARCH parameters:params];
  7834. // if(json==nil)
  7835. // return nil;
  7836. // NSError *error=nil;
  7837. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7838. // return jsobj;
  7839. }
  7840. +(void)request_modelqty: (NSString*) fashionId completionHandler:(resultHandler)result
  7841. {
  7842. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7843. AppDelegate *appDelegate = nil;
  7844. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7845. if(RASingleton.sharedInstance.user!=nil)
  7846. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  7847. if(appDelegate.contact_id!=nil)
  7848. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7849. if(RASingleton.sharedInstance.password!=nil)
  7850. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  7851. [params setValue:fashionId forKey:@"fashionId"];
  7852. [params setObject:ScreenCodeEditPortfolio forKey:kScreenName];
  7853. if(appDelegate.offline_mode)
  7854. {
  7855. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7856. NSData* json = [[OLDataProvider offline_model_qty:params] mutableCopy];
  7857. dispatch_async(dispatch_get_main_queue(), ^{
  7858. result([[RAConvertor data2dict:json] mutableCopy]);
  7859. });
  7860. });
  7861. return;
  7862. }
  7863. [self request_interface:URL_REQUEST_MODEL_QTY parameters:params err_record_url:nil completionHandler:result retry:0];
  7864. // NSData* json = nil;
  7865. // if(appDelegate.offline_mode)
  7866. // {
  7867. // json = [OLDataProvider offline_model_qty:params];
  7868. // } else {
  7869. // if(![self IsNetworkAvailable])
  7870. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7871. //
  7872. // json=[self get_json:URL_REQUEST_MODEL_QTY parameters:params];
  7873. // }
  7874. // if(json==nil)
  7875. // return nil;
  7876. // NSError *error=nil;
  7877. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7878. // return jsobj;
  7879. }
  7880. +(void) request_update_portfolio_price:(NSString*) watchlist_id price:(float) price discount:(float) discount QTY:(int)qty qty_p:(float) qty_p notes:(NSString*)notes completionHandler:(resultHandler)result
  7881. {
  7882. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7883. AppDelegate *appDelegate = nil;
  7884. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7885. if(RASingleton.sharedInstance.user!=nil)
  7886. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  7887. if(appDelegate.contact_id!=nil)
  7888. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7889. if(RASingleton.sharedInstance.password!=nil)
  7890. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  7891. [params setValue:watchlist_id forKey:@"item_id"];
  7892. // if(notes.length>0)
  7893. // [params setValue:notes forKey:@"notes"];
  7894. if(notes)
  7895. [params setValue:notes forKey:@"notes"];
  7896. if(price != -MAXFLOAT)
  7897. [params setValue:[NSString stringWithFormat:@"%f",price] forKey:@"price"];
  7898. if (discount != -MAXFLOAT)
  7899. [params setValue:[NSString stringWithFormat:@"%f",discount] forKey:@"discount"];
  7900. if(qty_p != -MAXFLOAT)
  7901. [params setValue:[NSString stringWithFormat:@"%f",qty_p] forKey:@"available_percent"];
  7902. if(qty != -INT32_MAX)
  7903. [params setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"available_qty"];
  7904. [params setObject:ScreenCodePortfolio forKey:kScreenName];
  7905. // NSData* json = nil;
  7906. if(appDelegate.offline_mode)
  7907. {
  7908. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7909. NSData* json = [[OLDataProvider offline_editPortfolio:params] mutableCopy];
  7910. dispatch_async(dispatch_get_main_queue(), ^{
  7911. result([[RAConvertor data2dict:json] mutableCopy]);
  7912. });
  7913. });
  7914. return;
  7915. }
  7916. [self request_interface:URL_PORTFOLIO_SET_PRICE parameters:params err_record_url:nil completionHandler:result retry:0];
  7917. //
  7918. // if(appDelegate.offline_mode)
  7919. // {
  7920. // json = [OLDataProvider offline_editPortfolio:params];
  7921. // } else {
  7922. // if(![self IsNetworkAvailable])
  7923. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7924. //
  7925. // json = [self get_json:URL_PORTFOLIO_SET_PRICE parameters:params];
  7926. // }
  7927. // if(json==nil)
  7928. // return nil;
  7929. // NSError *error=nil;
  7930. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7931. // return jsobj;
  7932. }
  7933. +(void)request_add_customer:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  7934. {
  7935. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7936. AppDelegate *appDelegate = nil;
  7937. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7938. if(RASingleton.sharedInstance.user!=nil)
  7939. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  7940. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  7941. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  7942. // else
  7943. if(appDelegate.contact_id!=nil)
  7944. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7945. if(RASingleton.sharedInstance.password!=nil)
  7946. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  7947. // NSDictionary* customerinfo=nil;
  7948. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  7949. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  7950. // else
  7951. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7952. //
  7953. // appDelegate.customerInfo;
  7954. // NSArray* keys=[customerinfo allKeys];
  7955. // for(int i=0;i<keys.count;i++)
  7956. // {
  7957. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  7958. // }
  7959. // [params setValue:sourceid forKey:@"sourceid"];
  7960. // [params setValue:editor forKey:@"editor"];
  7961. [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
  7962. if(appDelegate.offline_mode)
  7963. {
  7964. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7965. NSData* json = [[OLDataProvider offline_saveNewContact:params] mutableCopy];
  7966. dispatch_async(dispatch_get_main_queue(), ^{
  7967. result([[RAConvertor data2dict:json] mutableCopy]);
  7968. });
  7969. });
  7970. return;
  7971. }
  7972. [self request_interface:URL_CUSTOMER_SAVE parameters:params err_record_url:nil completionHandler:result retry:0];
  7973. //
  7974. // NSData* json=nil;
  7975. // if(appDelegate.offline_mode)
  7976. // {
  7977. // json= [OLDataProvider offline_saveNewContact:params];
  7978. // }
  7979. // else
  7980. // {
  7981. // if(![self IsNetworkAvailable])
  7982. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7983. //
  7984. // json=[self get_json:URL_CUSTOMER_SAVE parameters:params];
  7985. // }
  7986. //
  7987. // if(json!=nil)
  7988. // {
  7989. // NSError *error=nil;
  7990. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7991. // return jsobj;
  7992. // }
  7993. // else
  7994. // return nil;
  7995. }
  7996. +(void)request_update_customer:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  7997. {
  7998. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7999. AppDelegate *appDelegate = nil;
  8000. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8001. if(RASingleton.sharedInstance.user!=nil)
  8002. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  8003. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  8004. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  8005. // else
  8006. if(appDelegate.contact_id!=nil)
  8007. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8008. if(RASingleton.sharedInstance.password!=nil)
  8009. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  8010. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  8011. if(appDelegate.offline_mode)
  8012. {
  8013. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8014. NSData* json = [[OLDataProvider offline_saveContact:params] mutableCopy];
  8015. dispatch_async(dispatch_get_main_queue(), ^{
  8016. result([[RAConvertor data2dict:json] mutableCopy]);
  8017. });
  8018. });
  8019. return;
  8020. }
  8021. [self request_interface:URL_CUSTOMER_UPDATE parameters:params err_record_url:nil completionHandler:result retry:0];
  8022. //
  8023. // NSData* json=nil;
  8024. // if(appDelegate.offline_mode)
  8025. // {
  8026. // json= [OLDataProvider offline_saveContact:params];
  8027. // }
  8028. // else
  8029. // {
  8030. // if(![self IsNetworkAvailable])
  8031. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8032. //
  8033. // json=[self get_json:URL_CUSTOMER_UPDATE parameters:params];
  8034. // }
  8035. //
  8036. // if(json!=nil)
  8037. // {
  8038. // NSError *error=nil;
  8039. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8040. // return jsobj;
  8041. // }
  8042. // else
  8043. // return nil;
  8044. }
  8045. +(void)request_delete_order:(NSString*) order_id completionHandler:(resultHandler)result
  8046. {
  8047. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8048. AppDelegate *appDelegate = nil;
  8049. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8050. if(RASingleton.sharedInstance.user!=nil)
  8051. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  8052. // if(appDelegate.contact_id!=nil)
  8053. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8054. if(RASingleton.sharedInstance.password!=nil)
  8055. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  8056. [params setValue:order_id forKey:@"orderId"];
  8057. // [params setValue:sourceid forKey:@"sourceid"];
  8058. // [params setValue:editor forKey:@"editor"];
  8059. [params setValue:ScreenCodeOrderList forKey:kScreenName];
  8060. if(appDelegate.offline_mode)
  8061. {
  8062. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8063. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8064. dispatch_async(dispatch_get_main_queue(), ^{
  8065. result(json);
  8066. });
  8067. });
  8068. return;
  8069. }
  8070. [self request_interface:URL_DELETE_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  8071. //
  8072. // if(appDelegate.offline_mode)
  8073. // {
  8074. // return [OLDataProvider offline_notimpl];
  8075. // }
  8076. // if(![self IsNetworkAvailable])
  8077. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8078. //
  8079. // NSData* json=[self get_json:URL_DELETE_ORDER parameters:params];
  8080. // if(json!=nil)
  8081. // {
  8082. // NSError *error=nil;
  8083. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8084. //
  8085. //
  8086. // return jsobj;
  8087. // }
  8088. // else
  8089. // return nil;
  8090. }
  8091. +(void)request_cancel_order:(NSString*) order_id order_code:(NSString*) order_code completionHandler:(resultHandler)result
  8092. {
  8093. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8094. AppDelegate *appDelegate = nil;
  8095. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8096. if(RASingleton.sharedInstance.user!=nil)
  8097. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  8098. // if(appDelegate.contact_id!=nil)
  8099. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8100. if(RASingleton.sharedInstance.password!=nil)
  8101. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  8102. [params setValue:order_id forKey:@"orderId"];
  8103. [params setValue:order_code forKey:@"orderCode"];
  8104. // [params setValue:sourceid forKey:@"sourceid"];
  8105. // [params setValue:editor forKey:@"editor"];
  8106. [params setValue:ScreenCodeOrderList forKey:kScreenName];
  8107. if(appDelegate.offline_mode)
  8108. {
  8109. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8110. NSData* json = [[OLDataProvider offline_cancelorder:params] mutableCopy];
  8111. dispatch_async(dispatch_get_main_queue(), ^{
  8112. result([[RAConvertor data2dict:json] mutableCopy]);
  8113. });
  8114. });
  8115. return;
  8116. }
  8117. [self request_interface:URL_CANCEL_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  8118. //
  8119. // NSData* json=nil;
  8120. // if(appDelegate.offline_mode)
  8121. // {
  8122. // json=[OLDataProvider offline_cancelorder:params];
  8123. // }
  8124. // else
  8125. // {
  8126. // if(![self IsNetworkAvailable])
  8127. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8128. // json=[self get_json:URL_CANCEL_ORDER parameters:params];
  8129. // }
  8130. // if(json!=nil)
  8131. // {
  8132. // NSError *error=nil;
  8133. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8134. //
  8135. //
  8136. // return jsobj;
  8137. // }
  8138. // else
  8139. // return nil;
  8140. }
  8141. +(void)request_release_order:(NSString*) order_code withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  8142. {
  8143. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8144. AppDelegate *appDelegate = nil;
  8145. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8146. if(RASingleton.sharedInstance.user!=nil)
  8147. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  8148. // if(appDelegate.contact_id!=nil)
  8149. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8150. if(RASingleton.sharedInstance.password!=nil)
  8151. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  8152. [params setValue:order_code forKey:@"orderCode"];
  8153. // [params setValue:sourceid forKey:@"sourceid"];
  8154. // [params setValue:editor forKey:@"editor"];
  8155. if (screenName) {
  8156. [params setValue:screenName forKey:kScreenName];
  8157. }
  8158. if(appDelegate.offline_mode)
  8159. {
  8160. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8161. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_resetorder:params]] mutableCopy];
  8162. dispatch_async(dispatch_get_main_queue(), ^{
  8163. if([[resulti valueForKey:@"result"]intValue]==2)
  8164. { [appDelegate SetSo:nil];
  8165. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  8166. //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  8167. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8168. [appDelegate update_count_mark];
  8169. dispatch_async(dispatch_get_main_queue(), ^{
  8170. result(resulti);
  8171. });
  8172. }
  8173. });
  8174. });
  8175. return;
  8176. }
  8177. [self request_interface:URL_RELEASE_ORDER parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  8178. if([[resulti valueForKey:@"result"]intValue]==2)
  8179. { [appDelegate SetSo:nil];
  8180. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  8181. //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  8182. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8183. [appDelegate update_count_mark];
  8184. dispatch_async(dispatch_get_main_queue(), ^{
  8185. result(resulti);
  8186. });
  8187. }
  8188. } retry:0];
  8189. //
  8190. // NSData* json=nil;
  8191. // if(appDelegate.offline_mode)
  8192. // {
  8193. // json= [OLDataProvider offline_resetorder:params];
  8194. // }
  8195. // else
  8196. // {
  8197. // if(![self IsNetworkAvailable])
  8198. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8199. //
  8200. // json=[self get_json:URL_RELEASE_ORDER parameters:params];
  8201. // }
  8202. // if(json!=nil)
  8203. // {
  8204. // NSError *error=nil;
  8205. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8206. // if([[jsobj valueForKey:@"result"]intValue]==2)
  8207. // { [appDelegate SetSo:nil];
  8208. //
  8209. //
  8210. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  8211. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  8212. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8213. //
  8214. // [appDelegate update_count_mark];
  8215. // }
  8216. // return jsobj;
  8217. // }
  8218. // else
  8219. // return nil;
  8220. }
  8221. +(void)request_update_order_signature:(NSString*) order_code path:(NSString*)path completionHandler:(resultHandler)result
  8222. {
  8223. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8224. AppDelegate *appDelegate = nil;
  8225. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8226. if(RASingleton.sharedInstance.user!=nil)
  8227. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  8228. if(appDelegate.contact_id!=nil)
  8229. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8230. if(RASingleton.sharedInstance.password!=nil)
  8231. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  8232. // NSString* ssaved = @"false";
  8233. // if(saved)
  8234. // ssaved=@"true";
  8235. // [params setValue:@"true" forKey:@"saved"];
  8236. [params setValue:order_code forKey:@"orderCode"];
  8237. [params setValue:path forKey:@"picpath"];
  8238. // [params setValue:sourceid forKey:@"sourceid"];
  8239. // [params setValue:editor forKey:@"editor"];
  8240. [params setValue:ScreenCodeUserSign forKey:kScreenName];
  8241. if(appDelegate.offline_mode)
  8242. {
  8243. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8244. NSData* json = [[OLDataProvider offline_signorder:params] mutableCopy];
  8245. dispatch_async(dispatch_get_main_queue(), ^{
  8246. result([[RAConvertor data2dict:json] mutableCopy]);
  8247. });
  8248. });
  8249. return;
  8250. }
  8251. [self request_interface:URL_SIGN_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  8252. //
  8253. // NSData* json=nil;
  8254. // if(appDelegate.offline_mode)
  8255. // {
  8256. // json= [OLDataProvider offline_signorder:params];
  8257. // }
  8258. // else
  8259. // {
  8260. // if(![self IsNetworkAvailable])
  8261. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8262. //
  8263. // json=[self get_json:URL_SIGN_ORDER parameters:params];
  8264. // }
  8265. // if(json!=nil)
  8266. // {
  8267. // NSError *error=nil;
  8268. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8269. // return jsobj;
  8270. // }
  8271. // else
  8272. // return nil;
  8273. }
  8274. #ifdef SCANNER_ORDER
  8275. +(void) request_scan_bulkdiscount:(float) discount notes:(NSString*) notes completionHandler:(resultHandler)result
  8276. {
  8277. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  8278. //
  8279. //
  8280. // [appDelegate update_count_mark];
  8281. if(RASingleton.sharedInstance.price_type==0)
  8282. {
  8283. result(RASingleton.sharedInstance.scan_cart);
  8284. return;
  8285. }
  8286. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  8287. int count = [section[@"count"] intValue];
  8288. for(int i=0;i<count;i++)
  8289. {
  8290. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  8291. if ([item[@"special_price"] boolValue]||[item[@"net_price"] boolValue])
  8292. continue;
  8293. int item_count = [item[@"count"] intValue];
  8294. float price=[item[@"unit_price"] floatValue] ;
  8295. item[@"discount"] =@(discount);
  8296. // item[@"subtotal_price"] =@(price*item_count);
  8297. item[@"subtotal_price"]= [NSString stringWithFormat:@"%f",price*item_count*(1-discount/100.0)];
  8298. if(discount>0)
  8299. item[@"note"] =[NSString stringWithFormat:@"Note: discount %d%% off.",(int)discount];
  8300. else
  8301. item[@"note"] =@"";
  8302. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  8303. }
  8304. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  8305. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  8306. result(RASingleton.sharedInstance.scan_cart);
  8307. AppDelegate *appDelegate = nil;
  8308. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8309. [OLDataProvider updateScanOrder:appDelegate.order_code];
  8310. return;
  8311. }
  8312. #endif
  8313. +(void) request_update_cart_modelprice:(NSString*) cart_id price:(float) price discount:(float) discount notes:(NSString*) notes completionHandler:(resultHandler)result
  8314. {
  8315. AppDelegate *appDelegate = nil;
  8316. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8317. #ifdef SCANNER_ORDER
  8318. // return;
  8319. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  8320. {
  8321. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  8322. //
  8323. //
  8324. // [appDelegate update_count_mark];
  8325. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  8326. int count = [section[@"count"] intValue];
  8327. for(int i=0;i<count;i++)
  8328. {
  8329. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  8330. if([item[@"cart_item_id"] isEqualToString:cart_id])
  8331. {
  8332. int item_count = [item[@"count"] intValue];
  8333. item[@"unit_price"] =@(price);
  8334. item[@"discount"] =@(discount);
  8335. // item[@"subtotal_price"] =@(price*item_count);
  8336. item[@"subtotal_price"]= [NSString stringWithFormat:@"%f",price*item_count*(1-discount/100.0)];
  8337. if(discount>0)
  8338. item[@"note"] =[NSString stringWithFormat:@"Note: discount %d%% off.",(int)discount];
  8339. else
  8340. item[@"note"] =@"";
  8341. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  8342. break;
  8343. }
  8344. }
  8345. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  8346. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  8347. result(RASingleton.sharedInstance.scan_cart);
  8348. [OLDataProvider updateScanOrder:appDelegate.order_code];
  8349. return;
  8350. }
  8351. #else
  8352. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8353. if(RASingleton.sharedInstance.user!=nil)
  8354. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  8355. if(appDelegate.contact_id!=nil)
  8356. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8357. if(RASingleton.sharedInstance.password!=nil)
  8358. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  8359. [params setValue:cart_id forKey:@"cartitem_id"];
  8360. [params setValue:notes forKey:@"item_note"];
  8361. [params setValue:[NSString stringWithFormat:@"%f",price] forKey:@"price"];
  8362. [params setValue:[NSString stringWithFormat:@"%f",discount] forKey:@"discount"];
  8363. [params setObject:ScreenCodeCart forKey:kScreenName];
  8364. if(appDelegate.offline_mode)
  8365. {
  8366. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8367. NSData* json = [[OLDataProvider offline_cartsetprice:params] mutableCopy];
  8368. dispatch_async(dispatch_get_main_queue(), ^{
  8369. result([[RAConvertor data2dict:json] mutableCopy]);
  8370. });
  8371. });
  8372. return;
  8373. }
  8374. [self request_interface:URL_CART_SET_PRICE parameters:params err_record_url:nil completionHandler:result retry:0];
  8375. //
  8376. // NSData* json= nil;
  8377. // if(appDelegate.offline_mode)
  8378. // {
  8379. // json=[OLDataProvider offline_cartsetprice:params];
  8380. // }
  8381. // else
  8382. // {
  8383. // if(![self IsNetworkAvailable])
  8384. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8385. //
  8386. // json=[self get_json:URL_CART_SET_PRICE parameters:params];
  8387. // }
  8388. // if(json==nil)
  8389. // return nil;
  8390. // NSError *error=nil;
  8391. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8392. // return jsobj;
  8393. #endif
  8394. }
  8395. +(void) request_addto_cart:(NSString* ) item_id count:(int) count name:(NSString *)name completionHandler:(resultHandler)result
  8396. {
  8397. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8398. AppDelegate *appDelegate = nil;
  8399. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8400. if(RASingleton.sharedInstance.user!=nil)
  8401. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  8402. if(appDelegate.contact_id!=nil)
  8403. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8404. if(RASingleton.sharedInstance.password!=nil)
  8405. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  8406. if(appDelegate.order_code!=nil)
  8407. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  8408. [params setValue:item_id forKey:@"product_id"];
  8409. [params setValue:[NSString stringWithFormat:@"%d",count] forKey:@"count"];
  8410. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  8411. [params setObject:@"Add To Cart" forKey:kAction];
  8412. if (name) {
  8413. NSDictionary *extra = @{@"ModelName" : name,@"Count" : @(count)};
  8414. [params setObject:extra forKey:kExtra];
  8415. }
  8416. NSDictionary* customerinfo= appDelegate.customerInfo;
  8417. NSArray* keys=[customerinfo allKeys];
  8418. for(int i=0;i<keys.count;i++)
  8419. {
  8420. [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  8421. }
  8422. if(appDelegate.offline_mode)
  8423. {
  8424. // [OLDataProvider offline_add2cart:params completionHandler:^(NSMutableDictionary *resulti) {
  8425. // NSMutableDictionary* json = resulti;
  8426. // if ([json[@"result"] intValue]==2)
  8427. // {
  8428. // appDelegate.port_count =[[json valueForKey:@"count"] intValue];
  8429. //
  8430. // [appDelegate update_count_mark];
  8431. // }
  8432. // result(json);
  8433. // }];
  8434. params[@"can_create_backorder"]= @(appDelegate.can_create_backorder);
  8435. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8436. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_add2cart:params]] mutableCopy];
  8437. dispatch_async(dispatch_get_main_queue(), ^{
  8438. if ([json[@"result"] intValue]==2)
  8439. {
  8440. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  8441. [appDelegate update_count_mark];
  8442. }
  8443. result(json);
  8444. });
  8445. });
  8446. return;
  8447. }
  8448. [self request_interface:URL_ADD_TO_CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  8449. if ([resulti[@"result"] intValue]==2)
  8450. {
  8451. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  8452. [appDelegate update_count_mark];
  8453. }
  8454. result(resulti);
  8455. } retry:0];
  8456. //
  8457. // NSData* json=nil;
  8458. // if(appDelegate.offline_mode)
  8459. // {
  8460. // json=[OLDataProvider offline_add2cart:params];
  8461. // }
  8462. // else
  8463. // {
  8464. // if(![self IsNetworkAvailable])
  8465. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8466. //
  8467. // json=[self get_json:URL_ADD_TO_CART parameters:params];
  8468. // }
  8469. // if(json==nil)
  8470. // return nil;
  8471. // NSError *error=nil;
  8472. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8473. //
  8474. //
  8475. //
  8476. // int result = [[jsobj valueForKey:@"result"] intValue];
  8477. //
  8478. // if (result==2)
  8479. // {
  8480. //
  8481. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  8482. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  8483. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8484. //
  8485. // [appDelegate update_count_mark];
  8486. // }
  8487. //
  8488. // return jsobj;
  8489. }
  8490. //+(void) request_update_cart_modelfree:(NSString*) cart_id isfree:(bool) isfree completionHandler:(resultHandler)result
  8491. //{
  8492. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8493. // AppDelegate *appDelegate = nil;
  8494. //
  8495. //
  8496. //
  8497. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8498. //
  8499. // if(RASingleton.sharedInstance.user!=nil)
  8500. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  8501. // if(appDelegate.contact_id!=nil)
  8502. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8503. // if(RASingleton.sharedInstance.password!=nil)
  8504. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  8505. //
  8506. // [params setValue:cart_id forKey:@"cartitem_id"];
  8507. //
  8508. // [params setObject:ScreenCodeCart forKey:kScreenName];
  8509. //
  8510. // NSString* free=nil;
  8511. //
  8512. // if(isfree)
  8513. // free=@"true";
  8514. // else
  8515. // free=@"false";
  8516. //
  8517. // [params setValue:free forKey:@"free_giveaway"];
  8518. //
  8519. //
  8520. // if(appDelegate.offline_mode)
  8521. // {
  8522. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8523. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8524. // dispatch_async(dispatch_get_main_queue(), ^{
  8525. // result(json);
  8526. // });
  8527. // });
  8528. //
  8529. // return;
  8530. //
  8531. // }
  8532. // [self request_interface:URL_CART_SET_PRICE parameters:params err_record_url:nil completionHandler:result retry:0];
  8533. //
  8534. ////
  8535. ////
  8536. //// if(appDelegate.offline_mode)
  8537. //// {
  8538. //// return [OLDataProvider offline_notimpl];
  8539. //// }
  8540. //// if(![self IsNetworkAvailable])
  8541. //// return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8542. ////
  8543. //// NSData* json=[self get_json:URL_CART_SET_PRICE parameters:params];
  8544. //// if(json==nil)
  8545. //// return nil;
  8546. //// NSError *error=nil;
  8547. //// NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8548. //// return jsobj;
  8549. //}
  8550. +(void)request_retrieve_password: (NSString*) user email:(NSString*) email completionHandler:(resultHandler)result
  8551. {
  8552. AppDelegate *appDelegate = nil;
  8553. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8554. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8555. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  8556. // if(RASingleton.sharedInstance.user!=nil)
  8557. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  8558. // if(appDelegate.contact_id!=nil)
  8559. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8560. // if(RASingleton.sharedInstance.password!=nil)
  8561. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  8562. [params setValue:user forKey:@"username"];
  8563. [params setValue:email forKey:@"email"];
  8564. [params setObject:ScreenCodeLoginView forKey:kScreenName];
  8565. if(appDelegate.offline_mode)
  8566. {
  8567. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8568. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8569. dispatch_async(dispatch_get_main_queue(), ^{
  8570. result(json);
  8571. });
  8572. });
  8573. return;
  8574. }
  8575. #ifdef SCANNER_ORDER
  8576. params[@"site_name"]=[RADataProvider getSiteName];
  8577. params[@"_method"]=@"forgotPasswordOfflineOrderUser";
  8578. params[@"user"]=user;
  8579. NSString* url = [appDelegate.address stringByAppendingPathComponent:URL_RETRIEVE_PASS];
  8580. [self request_interface:url parameters:params err_record_url:nil completionHandler:result retry:0];
  8581. #else
  8582. [self request_interface:URL_RETRIEVE_PASS parameters:params err_record_url:nil completionHandler:result retry:0];
  8583. #endif
  8584. //
  8585. //
  8586. // if(![self IsNetworkAvailable])
  8587. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8588. //
  8589. // NSData* json=[self get_json:URL_RETRIEVE_PASS parameters:params];
  8590. // if(json==nil)
  8591. // return nil;
  8592. // NSError *error=nil;
  8593. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8594. // return jsobj;
  8595. }
  8596. +(void)request_update_ordercustomer:(NSString*) order_code customerinfo:(NSMutableDictionary*)info completionHandler:(resultHandler)result
  8597. {
  8598. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8599. AppDelegate *appDelegate = nil;
  8600. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8601. if(RASingleton.sharedInstance.user!=nil)
  8602. [info setValue:RASingleton.sharedInstance.user forKey:@"user"];
  8603. // if(appDelegate.contact_id!=nil)
  8604. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8605. if(RASingleton.sharedInstance.password!=nil)
  8606. [info setValue:RASingleton.sharedInstance.password forKey:@"password"];
  8607. [info setObject:ScreenCodeEditCustomer forKey:kScreenName];
  8608. [info setValue:order_code forKey:@"orderCode"];
  8609. // [params setValue:sourceid forKey:@"sourceid"];
  8610. // [params setValue:editor forKey:@"editor"];
  8611. if(appDelegate.offline_mode)
  8612. {
  8613. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8614. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8615. dispatch_async(dispatch_get_main_queue(), ^{
  8616. result(json);
  8617. });
  8618. });
  8619. return;
  8620. }
  8621. [self request_interface:URL_UPDATE_ORDERCUSTOMER parameters:info err_record_url:nil completionHandler:result retry:0];
  8622. // if(appDelegate.offline_mode)
  8623. // {
  8624. // return [OLDataProvider offline_notimpl];
  8625. // }
  8626. // if(![self IsNetworkAvailable])
  8627. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8628. //
  8629. // NSData* json=[self get_json:URL_UPDATE_ORDERCUSTOMER parameters:info];
  8630. // if(json!=nil)
  8631. // {
  8632. // NSError *error=nil;
  8633. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8634. // return jsobj;
  8635. // }
  8636. // else
  8637. // return nil;
  8638. }
  8639. +(void)request_update_customer_img: (NSString*) contactid img_url:(NSString*) url completionHandler:(resultHandler)result
  8640. {
  8641. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8642. AppDelegate *appDelegate = nil;
  8643. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8644. if(RASingleton.sharedInstance.user!=nil)
  8645. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  8646. // if(appDelegate.contact_id!=nil)
  8647. if(RASingleton.sharedInstance.password!=nil)
  8648. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  8649. [params setValue:contactid forKey:@"contactId"];
  8650. [params setValue:url forKey:@"business_card"];
  8651. // [params setValue:[NSNumber numberWithInt:index ] forKey:@"index"];
  8652. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  8653. if(appDelegate.offline_mode)
  8654. {
  8655. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8656. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8657. dispatch_async(dispatch_get_main_queue(), ^{
  8658. result(json);
  8659. });
  8660. });
  8661. return;
  8662. }
  8663. [self request_interface:URL_UPDATE_CUSTOMER_BCARD parameters:params err_record_url:nil completionHandler:result retry:0];
  8664. // if(appDelegate.offline_mode)
  8665. // {
  8666. // return [OLDataProvider offline_notimpl];
  8667. // }
  8668. // if(![self IsNetworkAvailable])
  8669. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8670. //
  8671. // NSData* json=[self get_json:URL_UPDATE_CUSTOMER_BCARD parameters:params];
  8672. // if(json==nil)
  8673. // return nil;
  8674. // NSError *error=nil;
  8675. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8676. // return jsobj;
  8677. }
  8678. +(void)request_commoneditor_partialrefresh: (NSMutableDictionary*)params url:(NSString*)url completionHandler:(resultHandler)result
  8679. {
  8680. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8681. AppDelegate *appDelegate = nil;
  8682. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8683. if(RASingleton.sharedInstance.user!=nil)
  8684. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  8685. if(appDelegate.contact_id!=nil)
  8686. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8687. if(RASingleton.sharedInstance.password!=nil)
  8688. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  8689. // if(appDelegate.order_code!=nil)
  8690. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  8691. // NSDictionary* customerinfo= appDelegate.customerInfo;
  8692. //
  8693. // NSArray* keys=[customerinfo allKeys];
  8694. // for(int i=0;i<keys.count;i++)
  8695. // {
  8696. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  8697. // }
  8698. //
  8699. // [params setValue:sourceid forKey:@"sourceid"];
  8700. // [params setValue:editor forKey:@"editor"];
  8701. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  8702. if(appDelegate.offline_mode)
  8703. {
  8704. params[@"offline_Command"]=url;
  8705. [OLDataProvider offline_commoneditor_partialrefresh:params completionHandler:result];
  8706. //
  8707. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8708. // NSMutableDictionary* json = [[OLDataProvider offline_commoneditor_partialrefresh:params] mutableCopy];
  8709. // dispatch_async(dispatch_get_main_queue(), ^{
  8710. // result(json);
  8711. // });
  8712. // });
  8713. return;
  8714. }
  8715. [self request_interface:url parameters:params err_record_url:nil completionHandler:result retry:0];
  8716. //
  8717. // if(appDelegate.offline_mode)
  8718. // {
  8719. // params[@"offline_Command"]=url;
  8720. // return [OLDataProvider offline_commoneditor_partialrefresh:params];
  8721. // }
  8722. //
  8723. // if(![self IsNetworkAvailable])
  8724. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8725. //
  8726. // NSData* json=[self get_json:url parameters:params];
  8727. // if(json!=nil)
  8728. // {
  8729. // NSError *error=nil;
  8730. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8731. // if([[jsobj valueForKey:@"result"]intValue]==2)
  8732. // [appDelegate SetSo:nil];
  8733. //
  8734. //
  8735. // return jsobj;
  8736. // }
  8737. // else
  8738. // return nil;
  8739. }
  8740. +(void)request_add_address:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  8741. {
  8742. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8743. AppDelegate *appDelegate = nil;
  8744. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8745. if(RASingleton.sharedInstance.user!=nil)
  8746. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  8747. if(appDelegate.contact_id!=nil)
  8748. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8749. if(RASingleton.sharedInstance.password!=nil)
  8750. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  8751. // [params setValue:sourceid forKey:@"sourceid"];
  8752. // [params setValue:editor forKey:@"editor"];
  8753. [params setValue:ScreenCodeNewAddress forKey:kScreenName];
  8754. if(appDelegate.offline_mode)
  8755. {
  8756. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8757. NSData* json = [[OLDataProvider offline_saveaddr:params] mutableCopy];
  8758. dispatch_async(dispatch_get_main_queue(), ^{
  8759. result([[RAConvertor data2dict:json] mutableCopy]);
  8760. });
  8761. });
  8762. return;
  8763. }
  8764. [self request_interface:URL_ADDRESS_SAVE parameters:params err_record_url:nil completionHandler:result retry:0];
  8765. //
  8766. // NSData* json=nil;
  8767. //
  8768. // if(appDelegate.offline_mode)
  8769. // {
  8770. // json= [OLDataProvider offline_saveaddr:params];
  8771. // }
  8772. // else
  8773. // {
  8774. // if(![self IsNetworkAvailable])
  8775. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8776. //
  8777. // json =[self get_json:URL_ADDRESS_SAVE parameters:params];
  8778. // }
  8779. // if(json!=nil)
  8780. // {
  8781. // NSError *error=nil;
  8782. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8783. // return jsobj;
  8784. // }
  8785. // else
  8786. // return nil;
  8787. }
  8788. +(void)request_commit_order:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  8789. {
  8790. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8791. AppDelegate *appDelegate = nil;
  8792. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8793. if(RASingleton.sharedInstance.user!=nil)
  8794. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  8795. if(appDelegate.contact_id!=nil)
  8796. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8797. if(RASingleton.sharedInstance.password!=nil)
  8798. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  8799. if(appDelegate.order_code!=nil)
  8800. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  8801. // NSDictionary* customerinfo= appDelegate.customerInfo;
  8802. //
  8803. // NSArray* keys=[customerinfo allKeys];
  8804. // for(int i=0;i<keys.count;i++)
  8805. // {
  8806. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  8807. // }
  8808. //
  8809. // [params setValue:sourceid forKey:@"sourceid"];
  8810. // [params setValue:editor forKey:@"editor"];
  8811. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  8812. if(appDelegate.offline_mode)
  8813. {
  8814. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8815. NSData* json = [[OLDataProvider offline_submitorder:params] mutableCopy];
  8816. dispatch_async(dispatch_get_main_queue(), ^{
  8817. result([[RAConvertor data2dict:json] mutableCopy]);
  8818. });
  8819. });
  8820. return;
  8821. }
  8822. [self request_interface:URL_COMMIT_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  8823. //
  8824. // NSData* json=nil;
  8825. // if(appDelegate.offline_mode)
  8826. // {
  8827. // json=[OLDataProvider offline_submitorder:params];
  8828. // }
  8829. // else
  8830. // {
  8831. // if(![self IsNetworkAvailable])
  8832. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8833. //
  8834. // json=[self get_json:URL_COMMIT_ORDER parameters:params];
  8835. // }
  8836. // if(json!=nil)
  8837. // {
  8838. // NSError *error=nil;
  8839. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8840. // if([[jsobj valueForKey:@"result"]intValue]==2)
  8841. // [appDelegate SetSo:nil];
  8842. //
  8843. //
  8844. // return jsobj;
  8845. // }
  8846. // else
  8847. // return nil;
  8848. }
  8849. +(void) request_new_offline_ticket:(NSString* )ver useInternalAddress:(bool)buseinternaladdress vid:(NSString*)vid completionHandler:(resultHandler)result
  8850. {
  8851. // if(![self IsNetworkAvailable])
  8852. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8853. //
  8854. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8855. AppDelegate *appDelegate = nil;
  8856. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8857. if(RASingleton.sharedInstance.user!=nil)
  8858. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  8859. // if(appDelegate.contact_id!=nil)
  8860. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8861. if(RASingleton.sharedInstance.password!=nil)
  8862. [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  8863. [params setValue:ver forKey:@"ver"];
  8864. [params setValue:vid forKey:@"vid"];
  8865. if(buseinternaladdress)
  8866. [params setValue:@"true" forKey:@"internal_address"];
  8867. else
  8868. [params setValue:@"false" forKey:@"internal_address"];
  8869. [params setObject:ScreenCodeOfflineSync forKey:kScreenName];
  8870. // 无论当前是离线还是在线状态,都可以进行同步;
  8871. // if(appDelegate.offline_mode)
  8872. // {
  8873. //
  8874. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8875. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8876. // dispatch_async(dispatch_get_main_queue(), ^{
  8877. // result(json);
  8878. // });
  8879. // });
  8880. //
  8881. // return;
  8882. //
  8883. // }
  8884. [self request_interface:URL_CHECK_OFFLINE parameters:params err_record_url:nil completionHandler:result retry:0];
  8885. //
  8886. // NSData* json=[self get_json:URL_CHECK_OFFLINE parameters:params];
  8887. // if(json==nil)
  8888. // return nil;
  8889. // NSError *error=nil;
  8890. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8891. // // int result = [[jsobj valueForKey:@"result"] intValue];
  8892. // //
  8893. // // if (result==2)
  8894. // // {
  8895. // //
  8896. // //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  8897. // //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  8898. // //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8899. // ////
  8900. // //// [appDelegate update_count_mark];
  8901. // // }
  8902. // return jsobj;
  8903. }
  8904. +(void) request_complete_offline_ticket:(NSString* )vid completionHandler:(resultHandler)result
  8905. {
  8906. // AppDelegate *appDelegate = nil;
  8907. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8908. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8909. [params setObject:ScreenCodeOfflineSetting forKey:kScreenName];
  8910. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  8911. // if(RASingleton.sharedInstance.user!=nil)
  8912. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  8913. // // if(appDelegate.contact_id!=nil)
  8914. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8915. // if(RASingleton.sharedInstance.password!=nil)
  8916. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  8917. [params setValue:vid forKey:@"downSerial"];
  8918. // 无论当前是离线还是在线状态,都可以进行同步;
  8919. // if(appDelegate.offline_mode)
  8920. // {
  8921. //
  8922. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8923. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8924. // dispatch_async(dispatch_get_main_queue(), ^{
  8925. // result(json);
  8926. // });
  8927. // });
  8928. //
  8929. // return;
  8930. //
  8931. // }
  8932. [self request_interface:URL_FINISH_DOWNLOAD_OFFLINE parameters:params err_record_url:nil completionHandler:result retry:0];
  8933. // NSData* json=[self get_json:URL_FINISH_DOWNLOAD_OFFLINE parameters:params];
  8934. // if(json==nil)
  8935. // return nil;
  8936. // NSError *error=nil;
  8937. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8938. // // int result = [[jsobj valueForKey:@"result"] intValue];
  8939. // //
  8940. // // if (result==2)
  8941. // // {
  8942. // //
  8943. // //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  8944. // //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  8945. // //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8946. // ////
  8947. // //// [appDelegate update_count_mark];
  8948. // // }
  8949. // return jsobj;
  8950. }
  8951. +(void) request_download_offline:(NSString* )vid completionHandler:(resultHandler)result
  8952. {
  8953. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8954. [params setObject:ScreenCodeOfflineSync forKey:kScreenName];
  8955. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  8956. // if(RASingleton.sharedInstance.user!=nil)
  8957. // [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  8958. // // if(appDelegate.contact_id!=nil)
  8959. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8960. // if(RASingleton.sharedInstance.password!=nil)
  8961. // [params setValue:RASingleton.sharedInstance.password forKey:@"password"];
  8962. [params setValue:vid forKey:@"downSerial"];
  8963. // AppDelegate *appDelegate = nil;
  8964. //
  8965. //
  8966. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8967. // if(appDelegate.offline_mode)
  8968. // {
  8969. //
  8970. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8971. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8972. // dispatch_async(dispatch_get_main_queue(), ^{
  8973. // result(json);
  8974. // });
  8975. // });
  8976. //
  8977. // return;
  8978. //
  8979. // }
  8980. __block bool bbreak = false;
  8981. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8982. __block NSMutableDictionary* download_json=nil;
  8983. int count=0;
  8984. // __block bool preparing = true;
  8985. while ([[download_json valueForKey:@"result"] intValue]!=2&&count<REQUEST_DOWNLOAD_RETRY_TIMES) //超过60分钟还没准被好数据就视为服务器出错。
  8986. {
  8987. if(bbreak)
  8988. break;
  8989. dispatch_async(dispatch_get_main_queue(), ^{
  8990. [self request_interface:URL_DOWNLOAD_OFFLINE parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  8991. if([resulti[@"result"] intValue]==RESULT_TRUE)
  8992. {
  8993. if(!bbreak) //此判断保证result只调用一次。
  8994. {
  8995. // appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  8996. // [appDelegate update_count_mark];
  8997. resulti[@"request_count"]=[NSNumber numberWithInt:count];
  8998. result(resulti);
  8999. }
  9000. bbreak=true;
  9001. }
  9002. else if([resulti[@"result"] intValue]==RESULT_ERROR)
  9003. {
  9004. result(resulti);
  9005. bbreak=true;
  9006. }
  9007. } retry:3];
  9008. });
  9009. sleep(RETRY_DELAY);
  9010. count++;
  9011. // download_json=[[RANetwork download_Offline:downSerial] mutableCopy];
  9012. //
  9013. // [RANetwork request_download_offline:downSerial completionHandler:^(NSMutableDictionary *result) {
  9014. // download_json=result;
  9015. // }];
  9016. //
  9017. }
  9018. // for(int i=0;i<150;i++)
  9019. // {
  9020. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  9021. // // result_params[@"resultSerial"]=uuid;
  9022. //
  9023. //
  9024. //
  9025. // sleep(2);
  9026. //
  9027. // // json=[self get_json:URL_CART parameters:params];
  9028. // // if(json!=nil)
  9029. // // {
  9030. // //
  9031. // // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9032. // // if([jsobj[@"result"] intValue]==2)
  9033. // // {
  9034. // // break;
  9035. // // }
  9036. // // }
  9037. //
  9038. // }
  9039. });
  9040. //
  9041. // NSData* json=[self get_json:URL_DOWNLOAD_OFFLINE parameters:params];
  9042. // if(json==nil)
  9043. // return nil;
  9044. // NSError *error=nil;
  9045. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9046. // // int result = [[jsobj valueForKey:@"result"] intValue];
  9047. // //
  9048. // // if (result==2)
  9049. // // {
  9050. // //
  9051. // //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  9052. // //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  9053. // //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  9054. // ////
  9055. // //// [appDelegate update_count_mark];
  9056. // // }
  9057. // return jsobj;
  9058. }
  9059. + (void)request_fastupload:(NSMutableDictionary *)params filename:(NSString*)filename data:(NSData*) data url:(NSString *)url completionHandler:(resultHandler)result
  9060. {
  9061. //#ifdef test_server
  9062. // url=URL_REQUEST_RECORDS;
  9063. // params[@"prefix"]=URL_REQUEST_RECORDS;
  9064. //#endif
  9065. // [self request_file_fast:url parameters:params completionHandler:result];
  9066. #ifdef SCANNER_ORDER
  9067. params[@"site_name"]=[RADataProvider getSiteName];
  9068. #endif
  9069. [self request_upload_fast:data FileName:filename server:url parameters:params completionHandler:result];
  9070. }
  9071. +(void)request_err_log:(NSString*) up_params result:(NSString*)result_str module:(NSString*) module code:(int) code completionHandler:(resultHandler)result
  9072. {
  9073. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9074. AppDelegate *appDelegate = nil;
  9075. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9076. if(RASingleton.sharedInstance.user!=nil)
  9077. [params setValue:RASingleton.sharedInstance.user forKey:@"user"];
  9078. [params setValue:up_params forKey:@"upparam"];
  9079. [params setValue:[NSNumber numberWithInt:code ] forKey:@"code"];
  9080. [params setValue:result_str forKey:@"result"];
  9081. [params setValue:module forKey:@"interfac"];
  9082. [params setValue:[RAUtils base64en:[RAConvertor dict2string: [RAUtils device_info]]] forKey:@"device"];
  9083. // [params setValue:module forKey:@"module"];
  9084. // [[UIDevice currentDevice] name];
  9085. // if(appDelegate.offline_mode)
  9086. // {
  9087. // return [OLDataProvider offline_notimpl];
  9088. // }
  9089. if(appDelegate.offline_mode)
  9090. {
  9091. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9092. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  9093. dispatch_async(dispatch_get_main_queue(), ^{
  9094. result(json);
  9095. });
  9096. });
  9097. return;
  9098. }
  9099. [self request_interface:URL_ERR_LOG parameters:params err_record_url:nil completionHandler:result retry:0];
  9100. //
  9101. // if(![self IsNetworkAvailable])
  9102. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  9103. //
  9104. // NSData* json=[self get_json:URL_ERR_LOG parameters:params];
  9105. // if(json==nil)
  9106. // return nil;
  9107. // NSError *error=nil;
  9108. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9109. // return jsobj;
  9110. }
  9111. @end