| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743 |
- //
- // OLDataProvider.m
- // iSales-NPD
- //
- // Created by Ray on 2/2/16.
- // Copyright © 2016 United Software Applications, Inc. All rights reserved.
- //
- #import "OLDataProvider.h"
- #import "iSalesDB.h"
- #import "RAUtils.h"
- #import "AESCrypt.h"
- #import "AppDelegate.h"
- #import "ZipArchive.h"
- #import "UIProgressView+AFNetworking.h"
- #import "AFHTTPSessionManager.h"
- @interface OLDataProvider ()
- @end
- @implementation OLDataProvider
- +(NSArray*) enumOfflineOrder
- {
-
- NSMutableArray* ret = [[NSMutableArray alloc] init];
- sqlite3 *db = [iSalesDB get_db];
-
- NSString *sqlQuery =@"select so_id from offline_order where order_id is null";
- sqlite3_stmt * statement;
-
- int dbresult=sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil);
- if ( dbresult== SQLITE_OK)
- {
-
-
- while (sqlite3_step(statement) == SQLITE_ROW)
- {
-
-
- char *so_id = (char*)sqlite3_column_text(statement, 0);
- NSString* nsso_id=nil;
- if(so_id!=nil)
- {
- nsso_id= [[NSString alloc]initWithUTF8String:so_id];
-
- }
-
- [ret addObject:nsso_id];
-
- }
-
-
-
- sqlite3_finalize(statement);
- }
-
-
-
- [iSalesDB close_db:db];
-
-
- return ret;
- }
- +(void) uploadFile:(NSString*) file
- {
- NSData* data = [NSData dataWithContentsOfFile: file];
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
-
- AFHTTPRequestSerializer* serializer=[AFHTTPRequestSerializer serializer] ;
-
-
-
- NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
-
- if(appDelegate.user!=nil)
- [params setValue:appDelegate.user forKey:@"user"];
- // if(appDelegate.contact_id!=nil)
- // [params setValue:appDelegate.contact_id forKey:@"contactId"];
- if(appDelegate.password!=nil)
- [params setValue:appDelegate.password forKey:@"password"];
-
-
- NSMutableURLRequest *request = [serializer multipartFormRequestWithMethod:@"POST" URLString:URL_UPLOAD_OFFLINE parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
- [formData appendPartWithFileData:data name:@"upfile" fileName:[file lastPathComponent] mimeType:@"application/zip"];
- } error:nil];
-
-
- AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
-
- NSProgress *progress = nil;
-
- NSURLSessionUploadTask *uploadTask = [manager uploadTaskWithStreamedRequest:request progress:&progress completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
-
-
-
- if (error) {
-
- NSString* err_msg = [error localizedDescription];
- NSLog(@"%@",err_msg);// [self.view updateWithMessage:[NSString stringWithFormat:@"Error : %@!", error.debugDescription]];
-
-
- NSMutableString *str = [[NSMutableString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
-
- NSLog(@"data string: %@",str);
- [RAUtils message_alert:@"Can not connect to server please try again." title:@"Upload Image" controller:self] ;
-
- } else {
- NSLog(@"response ");
-
-
-
- NSData *data = [NSJSONSerialization dataWithJSONObject:(NSDictionary*)responseObject options:kNilOptions error:nil];
-
- // 再将NSData转为字符串
- NSString *jsonStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
-
- // NSMutableString *str = [[NSMutableString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
-
- NSLog(@"data string: %@",jsonStr);
-
- NSDictionary* json = responseObject;
-
-
- if([[json valueForKey:@"result"] intValue]==2)
- {
- // NSString* img_url_down = json[@"img_url_aname"];
- // NSString* img_url_up = json[@"img_url"];
-
- }
- else
- {
- [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Upload file" controller:nil] ;
- }
-
-
- }
- // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
- }];
-
-
-
-
- // [self.uploadProgress setProgressWithUploadProgressOfTask:uploadTask animated:true];
- //
-
-
-
-
-
-
- [uploadTask resume];
-
- }
- +(NSDictionary *) prepareUpload:(NSArray*) arr_order
- {
- NSString* serial= [[NSUUID UUID] UUIDString];
-
-
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
- NSString *cachefolder = [paths objectAtIndex:0];
-
- NSString *upfolder = [cachefolder stringByAppendingPathComponent:@"upload_data"];
- upfolder = [upfolder stringByAppendingPathComponent:serial];
-
- NSFileManager* fileManager = [NSFileManager defaultManager];
- BOOL bdir=YES;
- if(! [fileManager fileExistsAtPath:upfolder isDirectory:&bdir])
- {
-
- NSError *error = nil;
- bool bsuccess=[fileManager createDirectoryAtPath:upfolder withIntermediateDirectories:YES attributes:nil error:&error];
-
- if(!bsuccess)
- DebugLog(@"Create UPLOAD folder failed");
-
- }
-
- NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
- ret[@"contact"]=[self prepareContact:serial];
- ret[@"wishlist"]=[self prepareWishlist:serial];
- ret[@"order"]=[self prepareOrder:serial soid:arr_order];
-
- NSString* str= [RAUtils dict2string:ret];
-
-
-
-
- NSString * jsonpath= [upfolder stringByAppendingPathComponent:@"json.json"];
-
- NSString * zippath= [upfolder stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.zip",serial]];
-
-
- NSError *error=nil;
-
- [str writeToFile:jsonpath atomically:true encoding:NSUTF8StringEncoding error:&error];
-
- NSArray* arr_files=[RAUtils allFilesAtPath:upfolder];
-
- ZipArchive* zip = [[ZipArchive alloc] init];
-
-
- BOOL result = [zip CreateZipFile2:zippath Password:@"usai2010"];
-
- for(int i=0;i<arr_files.count;i++)
- {
- NSString* file=arr_files[i];
-
- result = [zip addFileToZip:file newname:[file lastPathComponent]];
- }
- if( ![zip CloseZipFile2] )
- {
- zippath = @"";
- }
-
-
- ret[@"file"]=zippath;
-
- return ret;
- }
- + (bool) copy_upImg:(NSString* ) serial file:(NSString*) filename
- {
- if(filename.length==0)
- return false;
- // NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
- bool ret=false;
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
- NSString *cachefolder = [paths objectAtIndex:0];
-
- // NSString* from_subpath= [fromPath stringByReplacingOccurrencesOfString:cachefolder withString:@""];
- NSString *offline_createimg = [cachefolder stringByAppendingPathComponent:@"offline_createimg"];
- NSString *upfolder = [cachefolder stringByAppendingPathComponent:@"upload_data"];
- upfolder = [upfolder stringByAppendingPathComponent:serial];
- NSString * fromPath= [offline_createimg stringByAppendingPathComponent:filename];
- NSString * toPath= [upfolder stringByAppendingPathComponent:filename];
-
- NSFileManager* fileManager = [NSFileManager defaultManager];
- BOOL bdir=NO;
- if(! [fileManager fileExistsAtPath:toPath isDirectory:&bdir])
- {
-
- NSError *error = nil;
- if(![fileManager copyItemAtPath:fromPath toPath:toPath error:&error])
- {
- ret=false;
- }
- else
- {
- ret=true;
- }
- }
- return ret;
- }
- +(NSMutableDictionary*) prepareWishlist:(NSString* ) serial
- {
-
- NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
- sqlite3 *db = [iSalesDB get_db];
-
- NSString *sqlQuery =@"select _id,product_id,item_id,qty,create_time from wishlist";
- sqlite3_stmt * statement;
-
-
- [ret setValue:[NSNumber numberWithInt:AP_USER_NOT_AUTH ] forKey:@"result"];
-
- int count=0;
- int dbresult=sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil);
- if ( dbresult== SQLITE_OK)
- {
-
-
- while (sqlite3_step(statement) == SQLITE_ROW)
- {
-
-
- NSMutableDictionary* itemjson = [[NSMutableDictionary alloc] init];
-
-
-
-
- int _id = sqlite3_column_int(statement, 0);
- int product_id = sqlite3_column_int(statement, 1);
- int item_id = sqlite3_column_int(statement, 2);
- int qty = sqlite3_column_int(statement, 3);
-
- char *create_time = (char*)sqlite3_column_text(statement, 4);
- NSString* nscreate_time=nil;
- if(create_time!=nil)
- {
- nscreate_time= [[NSString alloc]initWithUTF8String:create_time];
-
- }
-
- itemjson[@"_id"]=[NSNumber numberWithInt:_id];
- itemjson[@"product_id"]=[NSNumber numberWithInt:product_id];
- itemjson[@"item_id"]=[NSNumber numberWithInt:item_id];
- itemjson[@"qty"]=[NSNumber numberWithInt:qty];
- itemjson[@"create_time"]=nscreate_time;
-
-
- ret[[NSString stringWithFormat:@"item_%d",count]]=itemjson;
- count++;
- }
-
-
- ret[@"result"]=[NSNumber numberWithInt:RESULT_TRUE ];
- sqlite3_finalize(statement);
- }
-
- ret[@"count"]=[NSNumber numberWithInt:count ];
-
- [iSalesDB close_db:db];
-
-
- return ret;
- }
- +(NSMutableDictionary*) preparecart:(NSString* ) orderCode db:(sqlite3*)db
- {
- NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
-
-
-
-
-
-
- NSString *sqlQuery = [ NSString stringWithFormat:@"select c.product_id,c.price,c.discount,c.item_count,c.line_note,m.name,m.description,c.item_id,m.stockUom,c._id from (select _id,product_id,decrypt(str_price) as price,discount,item_count,line_note,item_id from offline_cart where so_no='%@') c left join product m on c.product_id=m.product_id",orderCode ];
-
-
- // NSString *sqlQuery = [ NSString stringWithFormat:@"select c.product_id,decrypt(c.str_price),c.discount,c.item_count,c.line_note,m.name,m.description,c.item_id,m.stockUom,c._id from offline_cart c left join product m on c.product_id=m.product_id where c.so_no='%@'",orderCode ];
-
-
- // NSString *sqlQuery = @"select * from (select decrypt(str_price) from offline_cart) c";
-
- DebugLog(@"offline_login sql:%@",sqlQuery);
- sqlite3_stmt * statement;
-
-
- [ret setValue:[NSNumber numberWithInt:AP_USER_NOT_AUTH ] forKey:@"result"];
-
- int count=0;
- int dbresult=sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil);
- if ( dbresult== SQLITE_OK)
- {
-
-
- while (sqlite3_step(statement) == SQLITE_ROW)
- {
-
-
- NSMutableDictionary* itemjson = [[NSMutableDictionary alloc] init];
-
-
-
-
- int product_id = sqlite3_column_int(statement, 0);
-
- char *str_price = (char*)sqlite3_column_text(statement, 1);
-
- int item_id = sqlite3_column_int(statement, 7);
-
- NSString* Price=nil;
- if(str_price==nil)
- {
- // NSNumber* price= [self get_model_default_price:appDelegate.contact_id product_id:product_id db:db];
- NSNumber* price = [self get_model_default_price:appDelegate.contact_id product_id:nil item_id:@(item_id) db:db];
- if(price==nil)
- Price=@"No Price.";
- else
- Price=[NSString stringWithFormat:@"%.2f",price.floatValue];
- }
- else
- {
-
- Price=[NSString stringWithFormat:@"%.2f",[[[NSString alloc]initWithUTF8String:str_price] floatValue]];
- }
-
-
- double discount = sqlite3_column_double(statement, 2);
- int item_count = sqlite3_column_int(statement, 3);
-
- char *line_note = (char*)sqlite3_column_text(statement, 4);
- NSString *nsline_note=nil;
- if(line_note!=nil)
- nsline_note= [[NSString alloc]initWithUTF8String:line_note];
-
-
- char *name = (char*)sqlite3_column_text(statement, 5);
- NSString *nsname=nil;
- if(name!=nil)
- nsname= [[NSString alloc]initWithUTF8String:name];
-
- char *description = (char*)sqlite3_column_text(statement, 6);
- NSString *nsdescription=nil;
- if(description!=nil)
- nsdescription= [[NSString alloc]initWithUTF8String:description];
-
-
-
- // int stockUom = sqlite3_column_int(statement, 8);
- // int _id = sqlite3_column_int(statement, 9);
- //
- //
- // NSDictionary* bsubtotaljson=[self model_subtotal:item_id count:item_count db:db compute_part:true];
- // double cuft=[bsubtotaljson[@"cuft"] doubleValue];
- // double weight=[bsubtotaljson[@"weight"] doubleValue];
- // int carton=[bsubtotaljson[@"carton"] intValue];
-
- // itemjson[@"img_url"]= [self model_category_img:[NSString stringWithFormat:@"%@",[NSNumber numberWithInt:item_id]] model_name:nil db:db];
- // itemjson[@"img_url"] = [self item_image:[NSString stringWithFormat:@"%@",[NSNumber numberWithInt:item_id]] db:db];
- itemjson[@"model"]=nsname;
- // itemjson[@"cuft"]=[NSNumber numberWithDouble:cuft];
- // itemjson[@"weight"]=[NSNumber numberWithDouble:weight];
- // itemjson[@"carton"]=[NSNumber numberWithInt:carton];
- // itemjson[@"cart_item_id"]=[NSNumber numberWithInt:_id].stringValue;
- // itemjson[@"check"]=@"true";
- itemjson[@"item_id"]=[NSNumber numberWithInt:item_id];
-
- itemjson[@"product_id"]=[NSNumber numberWithInt:product_id].stringValue;
- itemjson[@"count"]=[NSNumber numberWithInt:item_count];
- itemjson[@"unit_price"]=Price;
- itemjson[@"discount"]=[NSNumber numberWithInt:discount];
- // itemjson[@"description"]=[NSString stringWithFormat:@"%@\n%@",nsname,nsdescription ];
- // itemjson[@"stockUom"]=[NSNumber numberWithInt:stockUom];
- itemjson[@"note"]=nsline_note;
- itemjson[@"combine"]=[self model_bundle:item_id db:db compute_part:false];
-
- ret[[NSString stringWithFormat:@"item_%d",count]]=itemjson;
- count++;
- }
-
-
- ret[@"result"]=[NSNumber numberWithInt:RESULT_TRUE ];
- sqlite3_finalize(statement);
- }
-
-
-
-
-
-
- int cart_count=[iSalesDB get_recordcount:db table:@"offline_cart" where:[NSString stringWithFormat:@"so_no='%@'",orderCode]];
-
- ret[@"count"]=[NSNumber numberWithInt:cart_count ];
-
-
- return ret;
- }
- +(NSMutableDictionary*) prepareOrder:(NSString* ) serial soid:(NSArray*) arr_soid
- {
- NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
- sqlite3 *db = [iSalesDB get_db];
- for(int i=0;i<arr_soid.count;i++)
- {
-
- NSMutableDictionary* itemjson = [[NSMutableDictionary alloc] init];
-
- NSString *sqlQuery =[NSString stringWithFormat:@"select _id,sync_data,sign_picpath,so_id from offline_order where so_id='%@'",arr_soid[i]];
- sqlite3_stmt * statement;
-
-
- [ret setValue:[NSNumber numberWithInt:AP_USER_NOT_AUTH ] forKey:@"result"];
-
- //int count=0;
- int dbresult=sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil);
- if ( dbresult== SQLITE_OK)
- {
- if (sqlite3_step(statement) == SQLITE_ROW)
- {
- int _id = sqlite3_column_int(statement, 0);
-
- char *sync_data = (char*)sqlite3_column_text(statement, 1);
- NSString* nssync_data=nil;
- if(sync_data!=nil)
- {
- nssync_data= [[NSString alloc]initWithUTF8String:sync_data];
-
- }
- char *img_1 = (char*)sqlite3_column_text(statement, 2);
- NSString* nsimg_1=nil;
- if(img_1!=nil)
- {
- nsimg_1= [[NSString alloc]initWithUTF8String:img_1];
- [self copy_upImg:serial file:nsimg_1];
- }
- char *so_no = (char*)sqlite3_column_text(statement, 3);
- NSString* nsso_no=nil;
- if(so_no!=nil)
- {
- nsso_no= [[NSString alloc]initWithUTF8String:so_no];
-
- }
-
-
- itemjson[@"_id"]=[NSNumber numberWithInt:_id];
- itemjson[@"json_data"]= nssync_data;
-
- itemjson[@"order_items"]=[self preparecart:nsso_no db:db];
- }
-
-
- ret[@"result"]=[NSNumber numberWithInt:RESULT_TRUE ];
-
- }
-
- sqlite3_finalize(statement);
- ret[[NSString stringWithFormat:@"item_%d",i]]=itemjson;
-
-
- }
- ret[@"count"]=[NSNumber numberWithInt:arr_soid.count ];
- [iSalesDB close_db:db];
-
-
- return ret;
- }
- +(NSMutableDictionary*) prepareContact:(NSString* ) serial
- {
-
- NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
- sqlite3 *db = [iSalesDB get_db];
- // UIApplication * app = [UIApplication sharedApplication];
- // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
-
-
-
-
-
-
- NSString *sqlQuery =@"select _id,img_0,img_1,img_2,sync_data from offline_contact where is_active=1 and not sync_data is null";
-
-
-
- sqlite3_stmt * statement;
-
-
- [ret setValue:[NSNumber numberWithInt:AP_USER_NOT_AUTH ] forKey:@"result"];
-
- int count=0;
- int dbresult=sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil);
- if ( dbresult== SQLITE_OK)
- {
-
-
- while (sqlite3_step(statement) == SQLITE_ROW)
- {
-
-
- NSMutableDictionary* itemjson = [[NSMutableDictionary alloc] init];
-
-
-
-
- int _id = sqlite3_column_int(statement, 0);
-
- char *img_0 = (char*)sqlite3_column_text(statement, 1);
- NSString* nsimg_0=nil;
- if(img_0!=nil)
- {
- nsimg_0= [[NSString alloc]initWithUTF8String:img_0];
- [self copy_upImg:serial file:nsimg_0];
- }
-
- char *img_1 = (char*)sqlite3_column_text(statement, 2);
- NSString* nsimg_1=nil;
- if(img_1!=nil)
- {
- nsimg_1= [[NSString alloc]initWithUTF8String:img_1];
- [self copy_upImg:serial file:nsimg_1];
- }
-
- char *img_2 = (char*)sqlite3_column_text(statement, 3);
- NSString* nsimg_2=nil;
- if(img_2!=nil)
- {
- nsimg_2= [[NSString alloc]initWithUTF8String:img_2];
- [self copy_upImg:serial file:nsimg_2];
- }
-
-
- char *sync_data = (char*)sqlite3_column_text(statement, 4);
- NSString* nssync_data=nil;
- if(sync_data!=nil)
- nssync_data= [[NSString alloc]initWithUTF8String:sync_data];
-
-
-
- // itemjson[@"img_url"]= [self model_category_img:[NSString stringWithFormat:@"%@",[NSNumber numberWithInt:item_id]] model_name:nil db:db];
-
- itemjson[@"_id"]=[NSNumber numberWithInt:_id];
- itemjson[@"json_data"]= nssync_data;
-
- ret[[NSString stringWithFormat:@"item_%d",count]]=itemjson;
- count++;
- }
-
-
- ret[@"result"]=[NSNumber numberWithInt:RESULT_TRUE ];
- sqlite3_finalize(statement);
- }
-
-
-
-
-
-
-
- ret[@"count"]=[NSNumber numberWithInt:count ];
-
- [iSalesDB close_db:db];
-
-
- return ret;
- }
- +(bool) check_offlinedata
- {
- UIApplication * app = [UIApplication sharedApplication];
- // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- sqlite3 *db = [iSalesDB get_db];
- NSString * where=@"1=1";
- // if(appDelegate.user!=nil)
- // where=[NSString stringWithFormat:@"lower(username)='%@'",appDelegate.user.lowercaseString];
- int count = [iSalesDB get_recordcount:db table:@"offline_login" where:where];
- [iSalesDB close_db:db];
- if(count==0)
- {
- return false;
- }
- return true;
- //
- //[iSalesDB close_db:db];
-
- }
- +(NSDictionary*) offline_deletewishlist :(NSMutableDictionary *) params
- {
-
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
-
- NSMutableDictionary* ret=[[NSMutableDictionary alloc]init];
- sqlite3 *db = [iSalesDB get_db];
- NSString* collectId=params[@"collectId"];
-
-
-
-
- NSString* sqlQuery = [NSString stringWithFormat:@"delete from wishlist where _id in (%@);",collectId];
- [iSalesDB execSql:sqlQuery db:db];
- int count=[iSalesDB get_recordcount:db table:@"wishlist" where:@"1=1"];
- [iSalesDB close_db:db];
-
- appDelegate.wish_count =count;
-
- [appDelegate update_count_mark];
- ret[@"result"]= [NSNumber numberWithInt:2];
- return ret;
- }
- +(NSDictionary*) offline_add2wishlist :(NSMutableDictionary *) params
- {
-
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
-
- NSMutableDictionary* ret=[[NSMutableDictionary alloc]init];
- sqlite3 *db = [iSalesDB get_db];
- NSString* product_id=params[@"product_id"];
-
-
- NSArray* arr=[RAUtils string2arr:product_id separator:@","];
-
-
- for(int i=0;i<arr.count;i++)
- {
- NSString* where=[NSString stringWithFormat:@"product_id=%@",arr[i]];
- int count=[iSalesDB get_recordcount:db table:@"wishlist" where:where];
- if(count==0)
- {
- NSString* sqlQuery = [NSString stringWithFormat:@"insert into wishlist(product_id) values('%@');",arr[i]];
- [iSalesDB execSql:sqlQuery db:db];
- }
- }
- int count=[iSalesDB get_recordcount:db table:@"wishlist" where:@"1=1"];
- [iSalesDB close_db:db];
-
- appDelegate.wish_count =count;
-
- [appDelegate update_count_mark];
- ret[@"result"]= [NSNumber numberWithInt:2];
- return ret;
- //
- //return ret;
- }
- +(NSDictionary*) offline_wishlist :(NSMutableDictionary *) params
- {
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
-
-
-
- NSString* user = appDelegate.user;
-
- sqlite3 *db = [iSalesDB get_db];
-
- NSString* sqlQuery = @"select w.product_id,m.name||'\n'||m.description,w._id from wishlist as w left join product as m on w.product_id=m.product_id order by w.create_time;";
- sqlite3_stmt * statement;
-
-
- NSMutableDictionary* ret=[[NSMutableDictionary alloc]init];
- int count=0;
-
- if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
- {
-
-
- while (sqlite3_step(statement) == SQLITE_ROW)
- {
-
-
-
- NSMutableDictionary* item=[[NSMutableDictionary alloc]init];
-
- int product_id = sqlite3_column_double(statement, 0);
-
-
-
-
-
- char *description = (char*)sqlite3_column_text(statement, 1);
- if(description==nil)
- description= "";
- NSString *nsdescription= [[NSString alloc]initWithUTF8String:description];
-
- int item_id = sqlite3_column_double(statement, 2);
-
-
- NSString *nsurl=[self model_category_img:[NSString stringWithFormat:@"%@",[NSNumber numberWithInt:product_id]] model_name:nil db:db];
-
- // char *url = (char*)sqlite3_column_text(statement, 3);
- // if(url==nil)
- // url="";
- // NSString *nsurl = [[NSString alloc]initWithUTF8String:url];
-
-
-
- item[@"product_id"]= [NSString stringWithFormat:@"%d",product_id];
- item[@"item_id"]= [NSString stringWithFormat:@"%d",item_id];
- item[@"description"]= nsdescription;
- item[@"img"]= nsurl;
-
-
-
- ret[[NSString stringWithFormat:@"item_%d",count]]= item;
- count++;
-
- }
-
- ret[@"count"]= [NSNumber numberWithInt:count];
- ret[@"total_count"]= [NSNumber numberWithInt:count];
- // ret[@"wish_count"]= [NSNumber numberWithInt:count];
- ret[@"result"]= [NSNumber numberWithInt:2];
-
-
- appDelegate.wish_count =count;
-
- [appDelegate update_count_mark];
- sqlite3_finalize(statement);
-
-
-
-
- }
-
- [iSalesDB close_db:db];
-
- return ret;
- }
- +(NSDictionary*) offline_notimpl
- {
-
- NSMutableDictionary* ret=[[NSMutableDictionary alloc]init];
- ret[@"result"]=@"8";
- ret[@"err_msg"]=@"offline mode does not support this function.";
- return ret;
- }
- +(NSDictionary*) offline_home
- {
-
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
- NSString *cachefolder = [paths objectAtIndex:0];
- NSString *img_cache = [cachefolder stringByAppendingPathComponent:@"offline_data/home.json"];
-
-
- NSData* json =nil;
- json=[NSData dataWithContentsOfFile:img_cache];
- NSError *error=nil;
- NSMutableDictionary* menu = [[NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
-
- return menu;
- }
- +(NSDictionary*) offline_category_menu
- {
-
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
- NSString *cachefolder = [paths objectAtIndex:0];
- NSString *img_cache = [cachefolder stringByAppendingPathComponent:@"offline_data/category_menu.json"];
-
-
- NSData* json =nil;
- json=[NSData dataWithContentsOfFile:img_cache];
- NSError *error=nil;
- NSMutableDictionary* menu = [[NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
-
- return menu;
- }
- +(NSDictionary*) offline_commoneditor_partialrefresh :(NSMutableDictionary *) params
- {
- NSString* offline_command=params[@"offline_Command"];
- NSDictionary* ret=nil;
- if([offline_command isEqualToString:@"model_NIYMAL"])
- {
- NSString* category = params[@"category"];
- ret = [self refresh_model_NIYMAL:category];
- }
- return ret;
- }
- +(NSDictionary*) refresh_model_NIYMAL :(NSString *) category
- {
-
- NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
-
-
- [ret setValue:@"2" forKey:@"result"];
- [ret setValue:@"Regular Mode" forKey:@"mode"];
- sqlite3* db= [iSalesDB get_db];
- NSMutableDictionary* detail1_section = [[self model_NIYMAL:category db:db] mutableCopy];
-
- [iSalesDB close_db:db];
-
- [ret setObject:detail1_section forKey:@"detail_1"];
- return ret;
- }
- +(NSMutableDictionary*) get_model_all_price:(NSString*) contact_id item_id:(int) item_id db:(sqlite3*)db
- {
-
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
-
- // NSArray* arr1 = [self get_user_all_price_type];
- NSArray* arr2 = [self get_contact_default_price_type:contact_id db:db];
-
- // NSSet *set1 = [NSSet setWithArray:arr1];
- // NSMutableSet *set2 = [[NSSet setWithArray:arr2] mutableCopy];
-
- // if(appDelegate.contact_id==nil)
- // set2=[set1 mutableCopy];
- // else
- // [set2 intersectsSet:set1];
-
-
- // NSArray *retarr = [set2 allObjects];
-
- NSString* whereprice=[RAUtils arr2string:arr2 separator:@"," trim:true brackets:@"'"];
-
-
- // sqlite3 *db = [iSalesDB get_db];
-
- NSString* sqlQuery = nil;
- if(appDelegate.contact_id==nil)
- sqlQuery=[NSString stringWithFormat:@"select a.name,b.price from price as a left join model_price as b on a.name=b.price_name and b.item_id=%d order by a.order_by;",item_id];
- else
- sqlQuery=[NSString stringWithFormat:@"select a.name,b.price from price as a left join model_price as b on a.name=b.price_name and b.item_id=%d and b.price_name in(%@) order by a.order_by;",item_id,whereprice];
- sqlite3_stmt * statement;
-
-
- NSMutableDictionary* ret=[[NSMutableDictionary alloc]init];
- int count=0;
-
- if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
- {
-
-
- while (sqlite3_step(statement) == SQLITE_ROW)
- {
-
-
-
- NSMutableDictionary* item=[[NSMutableDictionary alloc]init];
-
- char *name = (char*)sqlite3_column_text(statement, 0);
- if(name==nil)
- name="";
- NSString *nsname = [[NSString alloc]initWithUTF8String:name];
-
- // double price = sqlite3_column_double(statement, 1);
-
- // char *isnull = (char*)sqlite3_column_text(statement, 1);
- // if(isnull==nil)
- // item[nsname]= @"No Price";
- // else
- // item[nsname]= [NSString stringWithFormat:@"%.2f",price];
-
-
- char *price = (char*)sqlite3_column_text(statement, 1);
- if(price!=nil)
- {
- NSString* nsprice = [[NSString alloc]initWithUTF8String:price];
- nsprice=[AESCrypt fastdecrypt:nsprice];
- if(nsprice.length>0)
- {
- double dp= [nsprice doubleValue];
- item[nsname]= [NSString stringWithFormat:@"%.2f",dp];
- }
- }
- else
- {
- item[nsname]= @"No Price";
- }
-
-
- // item[nsname]= nsprice;
-
- ret[[NSString stringWithFormat:@"item_%d",count]]= item;
- count++;
-
- }
-
- ret[@"count"]= [NSNumber numberWithInt:count];
-
-
-
- sqlite3_finalize(statement);
-
-
-
-
- }
-
- // [iSalesDB close_db:db];
-
- return ret;
- }
- //+(NSNumber*) get_model_default_price:(NSString*) contact_id product_id:(int) product_id db:(sqlite3*)db
- //{
- // NSArray* arr1 = [self get_user_all_price_type:db];
- // NSArray* arr2 = [self get_contact_default_price_type:contact_id db:db];
- //
- // // NSSet *set1 = [NSSet setWithArray:arr1];
- // // NSMutableSet *set2 = [[NSSet setWithArray:arr2] mutableCopy];
- // // [set2 intersectsSet:set1];
- // //
- // //
- // // NSArray *retarr = [set2 allObjects];
- //
- // NSString* whereprice=nil;
- // if(contact_id==nil)
- // whereprice=[RAUtils arr2string:arr1 separator:@"," trim:true brackets:@"'"];
- // else
- // whereprice=[RAUtils arr2string:arr2 separator:@"," trim:true brackets:@"'"];
- //
- //
- // // sqlite3 *db = [iSalesDB get_db];
- //
- // NSString* sqlQuery = [NSString stringWithFormat:@"select price from model_price where product_id='%d' and price_name in(%@);",product_id,whereprice];
- // sqlite3_stmt * statement;
- //
- //
- // NSNumber* ret = nil;
- // double dprice=DBL_MAX;
- // if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
- // {
- //
- //
- // while (sqlite3_step(statement) == SQLITE_ROW)
- // {
- //
- // // double val = sqlite3_column_double(statement, 0);
- // char *price = (char*)sqlite3_column_text(statement, 0);
- // if(price!=nil)
- // {
- // NSString* nsprice = [[NSString alloc]initWithUTF8String:price];
- // nsprice=[AESCrypt fastdecrypt:nsprice];
- // if(nsprice.length>0)
- // {
- // double dp= [nsprice doubleValue];
- // if(dp<dprice)
- // dprice=dp;
- // }
- // }
- // }
- //
- //
- //
- //
- // sqlite3_finalize(statement);
- //
- //
- //
- //
- // }
- //
- // // [iSalesDB close_db:db];
- //
- // if(dprice==DBL_MAX)
- // ret= nil;
- // else
- // ret= [NSNumber numberWithDouble:dprice];
- // return ret;
- //}
- +(NSNumber*) get_model_default_price:(NSString*) contact_id product_id:(id) product_id item_id:(id)item_id db:(sqlite3*)db
- {
- NSArray* arr1 = [self get_user_all_price_type:db];
- NSArray* arr2 = [self get_contact_default_price_type:contact_id db:db];
-
-
- NSString* whereprice=nil;
- if(contact_id==nil)
- whereprice=[RAUtils arr2string:arr1 separator:@"," trim:true brackets:@"'"];
- else
- whereprice=[RAUtils arr2string:arr2 separator:@"," trim:true brackets:@"'"];
-
-
- // sqlite3 *db = [iSalesDB get_db];
- NSString *productIdCondition = @"1 = 1";
- if (product_id) {
- productIdCondition = [NSString stringWithFormat:@"product_id = %@",product_id];
- }
- NSString *itemIdCondition = @"";
- if (item_id) {
- itemIdCondition = [NSString stringWithFormat:@"and item_id = %@",item_id];
- }
-
-
- NSString* sqlQuery = [NSString stringWithFormat:@"select price from model_price where %@ %@ and price_name in(%@);",productIdCondition,itemIdCondition,whereprice];
- sqlite3_stmt * statement;
-
-
- NSNumber* ret = nil;
- double dprice=DBL_MAX;
- if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
- {
-
-
- while (sqlite3_step(statement) == SQLITE_ROW)
- {
-
- // double val = sqlite3_column_double(statement, 0);
- char *price = (char*)sqlite3_column_text(statement, 0);
- if(price!=nil)
- {
- NSString* nsprice = [[NSString alloc]initWithUTF8String:price];
- nsprice=[AESCrypt fastdecrypt:nsprice];
- if(nsprice.length>0)
- {
- double dp= [nsprice doubleValue];
- if(dp<dprice)
- dprice=dp;
- }
- }
- }
-
-
-
-
- sqlite3_finalize(statement);
-
-
-
-
- }
-
- // [iSalesDB close_db:db];
-
- if(dprice==DBL_MAX)
- ret= nil;
- else
- ret= [NSNumber numberWithDouble:dprice];
- return ret;
- }
- +(NSArray*) get_user_all_price_type:(sqlite3*)db
- {
-
- NSArray* ret=nil;
-
- // sqlite3 *db = [iSalesDB get_db];
- // no customer assigned , use login user contact_id
-
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- NSString* sqlQuery = [NSString stringWithFormat:@"select price from offline_login where username='%@';",appDelegate.user];
- sqlite3_stmt * statement;
-
-
-
-
- // int count=0;
- if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
- {
-
-
- if (sqlite3_step(statement) == SQLITE_ROW)
- {
-
- char *val = (char*)sqlite3_column_text(statement, 0);
- if(val==nil)
- val="";
- NSString* price = [[NSString alloc]initWithUTF8String:val];
-
- ret=[RAUtils string2arr:price separator:OFFLINE_ARRAY_SEPARATOR];
-
- }
-
-
-
-
- sqlite3_finalize(statement);
-
-
-
-
- }
-
- // [iSalesDB close_db:db];
-
- return ret;
-
-
-
- }
- +(NSArray*) get_contact_default_price_type:(NSString*) contact_id db:(sqlite3*)db
- {
-
- // sqlite3 *db = [iSalesDB get_db];
- if(contact_id==nil)
- {
- // no customer assigned , use login user contact_id
-
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- NSString* sqlQuery = [NSString stringWithFormat:@"select contact_id from offline_login where username='%@';",appDelegate.user];
- sqlite3_stmt * statement;
-
-
-
-
- // int count=0;
- if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
- {
-
-
- if (sqlite3_step(statement) == SQLITE_ROW)
- {
-
- char *val = (char*)sqlite3_column_text(statement, 0);
- if(val==nil)
- val="";
- contact_id = [[NSString alloc]initWithUTF8String:val];
-
-
-
- }
-
-
-
-
- sqlite3_finalize(statement);
-
-
-
-
- }
-
- if(contact_id.length<=0)
- {
- // [iSalesDB close_db:db];
- return nil;
- }
-
- }
-
- NSString* sqlQuery = [NSString stringWithFormat:@"select price_type from offline_contact where contact_id='%@';",contact_id];
- sqlite3_stmt * statement;
-
-
-
- NSArray* ret=nil;
- // int count=0;
- if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
- {
-
-
- if (sqlite3_step(statement) == SQLITE_ROW)
- {
-
- char *price_type = (char*)sqlite3_column_text(statement, 0);
- if(price_type==nil)
- price_type="";
- NSString *nsprice_type = [[NSString alloc]initWithUTF8String:price_type];
- if(nsprice_type.length>0)
- ret=[RAUtils string2arr:nsprice_type separator:OFFLINE_ARRAY_SEPARATOR];
- else
- ret=nil;
-
-
- }
-
-
-
-
- sqlite3_finalize(statement);
- }
-
- // [iSalesDB close_db:db];
-
- return ret;
-
-
- }
- +(NSString*) model_category_img :(NSString *) product_id model_name:(NSString *) model_name db:(sqlite3*)db
- {
-
-
- NSString* ret= nil;
-
-
- // sqlite3 *db = [iSalesDB get_db];
-
-
- NSString *sqlQuery = nil;
- //select url,type from model_image where product_id=%d and type=1 order by default_img desc , _id asc limit 1;",product_id
-
- if(product_id==nil && model_name)
- sqlQuery = [NSString stringWithFormat:@"select i.url from product m LEFT join model_image i on m.product_id = i.product_id where m.name=%@ order by i.default_img desc, i._id asc limit 1;",model_name];// select i.url from model m LEFT join model_image i on m.product_id = i.product_id where m.name=%@ order by i.default_img desc, i._id asc limit 1;
- else if (product_id)
- sqlQuery = [NSString stringWithFormat:@"select i.url from product m LEFT join model_image i on m.product_id = i.product_id where m.product_id=%@ order by i.default_img desc, i._id asc limit 1;",product_id];// select i.url from model m
-
- sqlite3_stmt * statement;
-
- // int count=0;
- if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
- {
-
-
- if (sqlite3_step(statement) == SQLITE_ROW)
- {
-
-
- char *imgurl = (char*)sqlite3_column_text(statement, 0);
- if(imgurl==nil)
- imgurl="";
- NSString *nsimgurl = [[NSString alloc]initWithUTF8String:imgurl];
-
-
- ret=nsimgurl;
-
-
- }
-
- sqlite3_finalize(statement);
- }
- else
- {
- [ret setValue:@"8" forKey:@"result"];
- }
-
-
-
- // [iSalesDB close_db:db];
- DebugLog(@"data string: %@",ret );
-
-
- return ret;
- }
- +(NSString*) model_default_category :(NSString *) product_id model_name:(NSString *) model_name
- {
-
-
- NSString* ret= nil;
-
-
- sqlite3 *db = [iSalesDB get_db];
-
-
- NSString *sqlQuery = nil;
-
- if(product_id==nil)
- sqlQuery = [NSString stringWithFormat:@"select default_category from product where name='%@';",model_name];// select default_category from model where name='%@';
- else
- sqlQuery = [NSString stringWithFormat:@"select default_category from product where product_id=%@;",product_id]; // select default_category from model where product_id=%@;
-
- sqlite3_stmt * statement;
-
- // int count=0;
- if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
- {
-
-
- if (sqlite3_step(statement) == SQLITE_ROW)
- {
-
-
- char *default_category = (char*)sqlite3_column_text(statement, 0);
- if(default_category==nil)
- default_category="";
- NSString *nsdefault_category = [[NSString alloc]initWithUTF8String:default_category];
- nsdefault_category=[nsdefault_category stringByReplacingOccurrencesOfString:@"%#" withString:@""];
- nsdefault_category=[nsdefault_category stringByReplacingOccurrencesOfString:@"#%" withString:@""];
-
- ret=nsdefault_category;
-
-
- }
-
- sqlite3_finalize(statement);
- }
- else
- {
- [ret setValue:@"8" forKey:@"result"];
- }
-
-
-
- [iSalesDB close_db:db];
- DebugLog(@"data string: %@",ret );
-
-
- return ret;
- }
- +(NSDictionary*) offline_model :(NSMutableDictionary *) params
- {
-
-
-
-
-
-
- NSString* model_name = [params valueForKey:@"product_name"];
-
- NSString* product_id = [params valueForKey:@"product_id"];
-
- NSString* category = [params valueForKey:@"category"];
-
-
- if(category==nil)
- category = [self model_default_category:product_id model_name:model_name];
-
- NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
-
-
-
-
-
-
- sqlite3 *db = [iSalesDB get_db];
-
- int count = [iSalesDB get_recordcount:db table:@"product" where:[NSString stringWithFormat:@"category like'#%%%@%%#'",category]];
-
-
- NSString *sqlQuery = nil;
-
- if(product_id==nil)
- sqlQuery = [NSString stringWithFormat:@"select name,description,product_id,color,legcolor,availability,incoming_stock,demension,seat_height,material,box_dim,volume,weight,model_set,load_ability,default_category,fabric_content,assembling,made_in,special_remarks,stockUom,product_group,selector_field,property_field,packaging from product where name='%@';",model_name]; // select name,description,product_id,color,legcolor,availability,incoming_stock,demension,seat_height,material,box_dim,volume,weight,model_set,load_ability,default_category,fabric_content,assembling,made_in,special_remarks,stockUom,product_group,selector_field,property_field,packaging from model where name='%@';
- else
- sqlQuery = [NSString stringWithFormat:@"select name,description,product_id,color,legcolor,availability,incoming_stock,demension,seat_height,material,box_dim,volume,weight,model_set,load_ability,default_category,fabric_content,assembling,made_in,special_remarks,stockUom,product_group,selector_field,property_field,packaging,item_id from product where product_id=%@;",product_id]; // select name,description,product_id,color,legcolor,availability,incoming_stock,demension,seat_height,material,box_dim,volume,weight,model_set,load_ability,default_category,fabric_content,assembling,made_in,special_remarks,stockUom,product_group,selector_field,property_field,packaging from model where product_id=%@;
-
- sqlite3_stmt * statement;
- [ret setValue:@"2" forKey:@"result"];
- [ret setValue:@"3" forKey:@"detail_section_count"];
-
- // int count=0;
- if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
- {
-
-
- if (sqlite3_step(statement) == SQLITE_ROW)
- {
- // NSMutableDictionary* item = [[NSMutableDictionary alloc] init];
-
-
- char *name = (char*)sqlite3_column_text(statement, 0);
- if(name==nil)
- name="";
- NSString *nsname = [[NSString alloc]initWithUTF8String:name];
-
- char *description = (char*)sqlite3_column_text(statement, 1);
- if(description==nil)
- description="";
- NSString *nsdescription = [[NSString alloc]initWithUTF8String:description];
-
-
- int product_id = sqlite3_column_int(statement, 2);
-
-
- char *color = (char*)sqlite3_column_text(statement, 3);
- if(color==nil)
- color="";
- // NSString *nscolor = [[NSString alloc]initWithUTF8String:color];
- //
- // char *legcolor = (char*)sqlite3_column_text(statement, 4);
- // if(legcolor==nil)
- // legcolor="";
- // NSString *nslegcolor = [[NSString alloc]initWithUTF8String:legcolor];
- //
- //
- int availability = sqlite3_column_int(statement, 5);
- //
- // int incoming_stock = sqlite3_column_int(statement, 6);
-
-
- char *demension = (char*)sqlite3_column_text(statement, 7);
- if(demension==nil)
- demension="";
- NSString *nsdemension = [[NSString alloc]initWithUTF8String:demension];
-
-
-
- // ,,,,,,,,,
-
-
- char *seat_height = (char*)sqlite3_column_text(statement, 8);
- if(seat_height==nil)
- seat_height="";
- NSString *nsseat_height = [[NSString alloc]initWithUTF8String:seat_height];
-
-
- char *material = (char*)sqlite3_column_text(statement, 9);
- if(material==nil)
- material="";
- NSString *nsmaterial = [[NSString alloc]initWithUTF8String:material];
-
- char *box_dim = (char*)sqlite3_column_text(statement, 10);
- if(box_dim==nil)
- box_dim="";
- NSString *nsbox_dim = [[NSString alloc]initWithUTF8String:box_dim];
-
- char *volume = (char*)sqlite3_column_text(statement, 11);
- if(volume==nil)
- volume="";
- NSString *nsvolume = [[NSString alloc]initWithUTF8String:volume];
-
- double weight = sqlite3_column_double(statement, 12);
-
- char *model_set = (char*)sqlite3_column_text(statement, 13);
- if(model_set==nil)
- model_set="";
- NSString *nsmodel_set = [[NSString alloc]initWithUTF8String:model_set];
-
- char *load_ability = (char*)sqlite3_column_text(statement, 14);
- if(load_ability==nil)
- load_ability="";
- NSString *nsload_ability = [[NSString alloc]initWithUTF8String:load_ability];
-
- char *default_category = (char*)sqlite3_column_text(statement, 15);
- if(default_category==nil)
- default_category="";
- NSString *nsdefault_category = [[NSString alloc]initWithUTF8String:default_category];
-
-
- char *fabric_content = (char*)sqlite3_column_text(statement, 16);
- if(fabric_content==nil)
- fabric_content="";
- NSString *nsfabric_content = [[NSString alloc]initWithUTF8String:fabric_content];
-
- char *assembling = (char*)sqlite3_column_text(statement, 17);
- if(assembling==nil)
- assembling="";
- NSString *nsassembling = [[NSString alloc]initWithUTF8String:assembling];
-
- char *made_in = (char*)sqlite3_column_text(statement, 18);
- if(made_in==nil)
- made_in="";
- NSString *nsmade_in = [[NSString alloc]initWithUTF8String:made_in];
-
-
- char *special_remarks = (char*)sqlite3_column_text(statement, 19);
- if(special_remarks==nil)
- special_remarks="";
- NSString *nsspecial_remarks = [[NSString alloc]initWithUTF8String:special_remarks];
-
-
- int stockUcom = sqlite3_column_double(statement, 20);
-
- char *product_group = (char*)sqlite3_column_text(statement, 21);
- if(product_group==nil)
- product_group="";
- NSString *nsproduct_group = [[NSString alloc]initWithUTF8String:product_group];
-
- // char *fashion_selector = (char*)sqlite3_column_text(statement, 22);
- // if(fashion_selector==nil)
- // fashion_selector="";
- // NSString *nsfashion_selector = [[NSString alloc]initWithUTF8String:fashion_selector];
-
- char *selector_field = (char*)sqlite3_column_text(statement, 22);
- if(selector_field==nil)
- selector_field="";
- NSString *nsselector_field = [[NSString alloc]initWithUTF8String:selector_field];
-
- char *property_field = (char*)sqlite3_column_text(statement, 23);
- if(property_field==nil)
- property_field="";
- NSString *nsproperty_field = [[NSString alloc]initWithUTF8String:property_field];
-
-
-
- char *packaging = (char*)sqlite3_column_text(statement, 24);
- if(packaging==nil)
- packaging="";
- NSString *nspackaging = [[NSString alloc]initWithUTF8String:packaging];
-
- [ret setValue:[NSString stringWithFormat:@"%d",product_id] forKey:@"product_id"];
-
- NSMutableDictionary* img_section = [[NSMutableDictionary alloc] init];
-
- NSString* model_s_img = [self model_category_img:[NSString stringWithFormat:@"%d",product_id] model_name:model_name db:db];
-
- [img_section setValue:model_s_img forKey:@"model_s_img"];
- [img_section setObject:[self model_img:product_id db:db] forKey:@"images"];
- [img_section setObject:[self model_property:product_id field:nsproperty_field db:db] forKey:@"property"];
- [img_section setObject:[self model_selector:nsproduct_group field:nsselector_field db:db] forKey:@"selector"];
-
-
-
-
-
- NSString* Availability=nil;
- if(availability>0)
- Availability=[NSString stringWithFormat:@"%d",availability];
- else
- Availability = @"In Production";
-
- [img_section setValue:Availability forKey:@"Availability"];
- [img_section setValue:[NSString stringWithFormat:@"%d",stockUcom] forKey:@"stockUom"];
-
- AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
-
- int item_id = sqlite3_column_int(statement, 25);
-
- NSString* Price=nil;
- if(appDelegate.bLogin==false)
- Price=@"Must Sign in.";
- else
- {
- // NSNumber* price= [self get_model_default_price:appDelegate.contact_id product_id:product_id db:db];
- NSNumber* price = [self get_model_default_price:appDelegate.contact_id product_id:nil item_id:@(item_id) db:db];
- if(price==nil)
- Price=@"No Price.";
- else
- Price=[NSString stringWithFormat:@"%.2f",price.floatValue];
- }
-
- [img_section setValue:Price forKey:@"price"];
- [img_section setValue:nsname forKey:@"model_name"];
- [img_section setValue:nsdescription forKey:@"model_descrition"];
-
- [ret setObject:img_section forKey:@"img_section"];
-
- NSMutableDictionary* detail0_section = [[NSMutableDictionary alloc] init];
- int detail0_item_count=0;
-
- [detail0_section setObject:[self model_kvItem:@"Dimension" value:nsdemension] forKey:[NSString stringWithFormat:@"item_%d",detail0_item_count++]];
- [detail0_section setObject:[self model_kvItem:@"Seat Height" value:nsseat_height] forKey:[NSString stringWithFormat:@"item_%d",detail0_item_count++]];
- [detail0_section setObject:[self model_kvItem:@"Material" value:nsmaterial] forKey:[NSString stringWithFormat:@"item_%d",detail0_item_count++]];
- [detail0_section setObject:[self model_kvItem:@"Box dimension" value:nsbox_dim] forKey:[NSString stringWithFormat:@"item_%d",detail0_item_count++]];
- [detail0_section setObject:[self model_kvItem:@"Volume" value:nsvolume] forKey:[NSString stringWithFormat:@"item_%d",detail0_item_count++]];
- [detail0_section setObject:[self model_kvItem:@"Weight" value:[NSString stringWithFormat:@"%0.2f",weight]] forKey:[NSString stringWithFormat:@"item_%d",detail0_item_count++]];
- [detail0_section setObject:[self model_kvItem:@"Set" value:nsmodel_set] forKey:[NSString stringWithFormat:@"item_%d",detail0_item_count++]];
- [detail0_section setObject:[self model_kvItem:@"Load ability" value:nsload_ability] forKey:[NSString stringWithFormat:@"item_%d",detail0_item_count++]];
- [detail0_section setObject:[self model_kvItem:@"Fabric Content" value:nsfabric_content] forKey:[NSString stringWithFormat:@"item_%d",detail0_item_count++]];
- [detail0_section setObject:[self model_kvItem:@"Assembling" value:nsassembling] forKey:[NSString stringWithFormat:@"item_%d",detail0_item_count++]];
- [detail0_section setObject:[self model_kvItem:@"Made in" value:nsmade_in] forKey:[NSString stringWithFormat:@"item_%d",detail0_item_count++]];
- [detail0_section setObject:[self model_kvItem:@"Special Remarks" value:nsspecial_remarks] forKey:[NSString stringWithFormat:@"item_%d",detail0_item_count++]];
- [detail0_section setObject:[self model_kvItem:@"Packaging" value:nspackaging] forKey:[NSString stringWithFormat:@"item_%d",detail0_item_count++]];
-
-
- // NSDictionary* pricejson=[self get_model_all_price:appDelegate.contact_id product_id:product_id db:db];
- NSDictionary* pricejson = [self get_model_all_price:appDelegate.contact_id item_id:item_id db:db];
- for(int l=0;l<[pricejson[@"count"] intValue];l++)
- {
- NSDictionary* price_item = pricejson[[NSString stringWithFormat:@"item_%d",l]];
- [detail0_section setObject:[self model_kvItem:price_item.allKeys[0] value:price_item.allValues[0]] forKey:[NSString stringWithFormat:@"item_%d",detail0_item_count++]];
- }
-
-
-
-
- [detail0_section setValue:[NSString stringWithFormat:@"%d",detail0_item_count] forKey:@"count"];
- [detail0_section setValue:@"kv" forKey:@"type"];
- [detail0_section setValue:@"Product Information" forKey:@"title"];
-
- [ret setObject:detail0_section forKey:@"detail_0"];
-
-
- NSMutableDictionary* detail1_section = [[self model_NIYMAL:category db:db] mutableCopy];
- // [detail1_section setValue:@"detail" forKey:@"target"];
- // [detail1_section setValue:@"popup" forKey:@"action"];
- // [detail1_section setValue:@"content" forKey:@"type"];
- // [detail1_section setValue:@"New Items You May Also Like" forKey:@"title"];
- // [detail1_section setValue:@"model_NIYMAL" forKey:@"data_interface"];
- // [detail1_section setValue:@"true" forKey:@"single_row"];
- // [detail1_section setValue:@"true" forKey:@"partial_refresh"];
- [ret setObject:detail1_section forKey:@"detail_1"];
-
-
-
-
- NSMutableDictionary* detail2_section = [[NSMutableDictionary alloc]init];
- [detail2_section setValue:@"detail" forKey:@"target"];
- [detail2_section setValue:@"popup" forKey:@"action"];
- [detail2_section setValue:@"content" forKey:@"type"];
- [detail2_section setValue:@"Recently Viewed" forKey:@"title"];
- [detail2_section setValue:@"true" forKey:@"single_row"];
- [detail2_section setValue:@"local" forKey:@"data"];
- [ret setObject:detail2_section forKey:@"detail_2"];
- }
-
-
-
-
- sqlite3_finalize(statement);
- }
- else
- {
- [ret setValue:@"8" forKey:@"result"];
- }
- NSLog(@"count:%d",count);
-
-
- [iSalesDB close_db:db];
- DebugLog(@"data string: %@",[RAUtils dict2string:ret] );
-
- return ret;
- }
- +(NSDictionary*) offline_search:(NSMutableDictionary *) params
- {
-
-
-
-
-
-
- NSString* orderCode = [params valueForKey:@"orderCode"];
-
- NSString* keyword = [params valueForKey:@"keyword"];
- keyword=keyword.lowercaseString;
-
- bool exactMatch = [[params valueForKey:@"exactMatch"] boolValue];
-
-
- int limit = [[params valueForKey:@"limit"] intValue];
- int offset = [[params valueForKey:@"offset"] intValue];
-
- NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
-
-
-
-
-
-
- sqlite3 *db = [iSalesDB get_db];
-
- int count = [iSalesDB get_recordcount:db table:@"product" where:[NSString stringWithFormat:@"(lower(name) like'%%%@%%' or lower(description) like'%%%@%%') and is_active = 1",keyword,keyword]];
-
-
- NSString *sqlQuery = nil;
- if(exactMatch )
- sqlQuery=[NSString stringWithFormat:@"select m.name,m.description,m.product_id,w._id,m.closeout from product m left join wishlist w on m.product_id=w.product_id where lower(name) like'%@%%' and m.is_active = 1 order by m.name limit %d offset %d ;",keyword,limit, offset]; // select m.name,m.description,m.product_id,w._id,m.closeout from model m left join wishlist w on m.product_id=w.product_id where lower(name) like'%@%%' order by m.name limit %d offset %d ;
- else
- sqlQuery=[NSString stringWithFormat:@"select m.name,m.description,m.product_id,w._id,m.closeout from product m left join wishlist w on m.product_id=w.product_id where (lower(name) like'%%%@%%' or lower(description) like'%%%@%%') and m.is_active = 1 order by m.name limit %d offset %d ;",keyword,keyword,limit, offset];// select m.name,m.description,m.product_id,w._id,m.closeout from model m left join wishlist w on m.product_id=w.product_id where lower(name) like'%%%@%%' or
-
- DebugLog(@"offline_search sql:%@",sqlQuery);
- sqlite3_stmt * statement;
- [ret setValue:@"2" forKey:@"result"];
- [ret setValue:[NSString stringWithFormat:@"%d",count] forKey:@"item_total_count"];
- NSMutableDictionary* items = [[NSMutableDictionary alloc] init];
- // int count=0;
- if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
- {
-
- int i=0;
- while (sqlite3_step(statement) == SQLITE_ROW)
- {
- NSMutableDictionary* item = [[NSMutableDictionary alloc] init];
-
- // char *name = (char*)sqlite3_column_text(statement, 1);
- // NSString *nsNameStr = [[NSString alloc]initWithUTF8String:name];
-
- char *name = (char*)sqlite3_column_text(statement, 0);
- NSString *nsname = [[NSString alloc]initWithUTF8String:name];
-
- char *description = (char*)sqlite3_column_text(statement, 1);
- NSString *nsdescription = [[NSString alloc]initWithUTF8String:description];
-
-
-
- int product_id = sqlite3_column_int(statement, 2);
-
-
- // char *url = (char*)sqlite3_column_text(statement, 3);
- // if(url==nil)
- // url="";
- // NSString *nsurl = [[NSString alloc]initWithUTF8String:url];
-
- int wid = sqlite3_column_int(statement, 3);
- int closeout = sqlite3_column_int(statement, 4);
-
- NSMutableDictionary* imgjson=[self category_img:product_id db:db];
-
- if(wid==0)
- [item setValue:@"false" forKey:@"wish_exists"];
- else
- [item setValue:@"true" forKey:@"wish_exists"];
-
- if(closeout==0)
- [item setValue:@"false" forKey:@"is_closeout"];
- else
- [item setValue:@"true" forKey:@"is_closeout"];
-
- [item addEntriesFromDictionary:imgjson];
-
-
- // [item setValue:nsurl forKey:@"img"];
- [item setValue:nsname forKey:@"fash_name"];
- [item setValue:nsdescription forKey:@"description"];
- [item setValue:[NSString stringWithFormat:@"%d",product_id] forKey:@"product_id"];
- [items setObject:item forKey:[NSString stringWithFormat:@"item_%d",i]];
- i++;
-
- }
- [items setValue:[NSString stringWithFormat:@"%d",i] forKey:@"count"];
- [ret setObject:items forKey:@"items"];
- sqlite3_finalize(statement);
- }
- NSLog(@"count:%d",count);
-
-
- [iSalesDB close_db:db];
-
-
-
-
- DebugLog(@"data string: %@",[RAUtils dict2string:ret] );
-
- return ret;
- }
- +(NSDictionary*) offline_logout :(NSMutableDictionary *) params
- {
-
-
- //
- // NSString* user = [params valueForKey:@"user"];
- //
- // NSString* password = [params valueForKey:@"password"];
-
-
-
- NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
-
- ret[@"result"]=[NSNumber numberWithInt:2 ];
-
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
-
- appDelegate.cart_count = 0;//[[jsobj valueForKey:@"cart_count"] intValue];
- appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
- appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
-
- [appDelegate update_count_mark];
-
-
- appDelegate.can_show_price =false;
- appDelegate.can_see_price =false;
- appDelegate.can_create_portfolio =false;
- appDelegate.can_create_order =false;
-
-
- appDelegate.can_cancel_order =false;
- appDelegate.can_set_cart_price =false;
- appDelegate.can_delete_order =false;
- appDelegate.can_submit_order =false;
- appDelegate.can_set_tearsheet_price =false;
- appDelegate.can_update_contact_info = false;
-
- appDelegate.save_order_logout = false;
- appDelegate.submit_order_logout = false;
- appDelegate.alert_sold_in_quantities = false;
-
- appDelegate.ipad_perm =nil ;
- appDelegate.user_type = USER_ROLE_UNKNOWN;
- appDelegate.OrderFilter= nil;
- [appDelegate SetSo:nil];
- [appDelegate set_main_button_panel];
-
-
- // sqlite3 *db = [iSalesDB get_db];
- //
- //
- //
- //
- //
- // NSString *sqlQuery = [NSString stringWithFormat:@"select can_show_price,can_see_price,contact_id,user_type,can_cancel_order,can_set_cart_price,can_create_portfolio,can_delete_order,can_submit_order,can_set_tearsheet_price,can_create_order,mode,username from offline_login where lower(username)='%@' and password='%@'",user.lowercaseString ,[AESCrypt encrypt:password password:@"usai"]];
- //
- //
- //
- //
- // DebugLog(@"offline_login sql:%@",sqlQuery);
- // sqlite3_stmt * statement;
- //
- //
- // [ret setValue:[NSNumber numberWithInt:AP_USER_NOT_AUTH ] forKey:@"result"];
- //
- //
- // if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
- // {
- //
- //
- // if (sqlite3_step(statement) == SQLITE_ROW)
- // {
- //
- // [ret setValue:[NSNumber numberWithInt:AP_USER_AUTH ] forKey:@"result"];
- // NSMutableDictionary* header = [[NSMutableDictionary alloc] init];
- //
- //
- //
- // int can_show_price = sqlite3_column_int(statement, 0);
- // int can_see_price = sqlite3_column_int(statement, 1);
- //
- // char *contact_id = (char*)sqlite3_column_text(statement, 2);
- // if(contact_id==nil)
- // contact_id="";
- // NSString *nscontact_id= [[NSString alloc]initWithUTF8String:contact_id];
- //
- // int user_type = sqlite3_column_int(statement, 3);
- //
- // int can_cancel_order = sqlite3_column_int(statement, 4);
- // int can_set_cart_price = sqlite3_column_int(statement, 5);
- // int can_create_portfolio = sqlite3_column_int(statement, 6);
- // int can_delete_order = sqlite3_column_int(statement, 7);
- // int can_submit_order = sqlite3_column_int(statement, 8);
- // int can_set_tearsheet_price = sqlite3_column_int(statement, 9);
- // int can_create_order = sqlite3_column_int(statement, 10);
- //
- //
- // char *mode = (char*)sqlite3_column_text(statement, 11);
- // if(mode==nil)
- // mode="";
- // NSString *nsmode= [[NSString alloc]initWithUTF8String:mode];
- //
- //
- // char *username = (char*)sqlite3_column_text(statement, 12);
- // if(username==nil)
- // username="";
- // NSString *nsusername= [[NSString alloc]initWithUTF8String:username];
- //
- //
- // [header setValue:[NSNumber numberWithBool:can_show_price] forKey:@"can_show_price"];
- // [header setValue:[NSNumber numberWithBool:can_see_price] forKey:@"can_see_price"];
- // [header setValue:nscontact_id forKey:@"contact_id"];
- // [header setValue:[NSNumber numberWithBool:user_type] forKey:@"user_type"];
- // [header setValue:[NSNumber numberWithBool:can_cancel_order] forKey:@"can_cancel_order"];
- // [header setValue:[NSNumber numberWithBool:can_set_cart_price] forKey:@"can_set_cart_price"];
- // [header setValue:[NSNumber numberWithBool:can_create_portfolio] forKey:@"can_create_portfolio"];
- // [header setValue:[NSNumber numberWithBool:can_delete_order] forKey:@"can_delete_order"];
- // [header setValue:[NSNumber numberWithBool:can_submit_order] forKey:@"can_submit_order"];
- // [header setValue:[NSNumber numberWithBool:can_set_tearsheet_price] forKey:@"can_set_tearsheet_price"];
- // [header setValue:[NSNumber numberWithBool:can_create_order] forKey:@"can_create_order"];
- //
- // [header setValue:nsusername forKey:@"username"];
- //
- //
- // [ret setObject:header forKey:@"header"];
- // [ret setValue:nsmode forKey:@"mode"];
- //
- //
- // }
- //
- //
- //
- // sqlite3_finalize(statement);
- // }
- //
- //
- //
- // [iSalesDB close_db:db];
- //
- //
- //
- //
- // DebugLog(@"data string: %@",[RAUtils dict2string:ret] );
-
- return ret;
- }
- +(NSData*) offline_createorder :(NSMutableDictionary *) params
- {
- NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
-
- NSString* customer_cid = [self translateSingleQuote:params[@"customer_cid"]];
- // NSString* customer_address1 = [self translateSingleQuote:params[@"customer_address1"]];
- // NSString* customer_address2 = [self translateSingleQuote:params[@"customer_address2"]];
- // NSString* customer_address3 = [self translateSingleQuote:params[@"customer_address3"]];
- // NSString* customer_address4 = [self translateSingleQuote:params[@"customer_address4"]];
- // NSString* customer_city = [self translateSingleQuote:params[@"customer_city"]];
- NSString* customer_contact = [self translateSingleQuote:params[@"customer_contact"]];
- // NSString* customer_contact_ext = [self translateSingleQuote:params[@"customer_contact_ext"]];
- // NSString* customer_contact_notes = [self translateSingleQuote:params[@"customer_contact_notes"]];
- // NSString* customer_country = [self translateSingleQuote:params[@"customer_country"]];
- NSString* customer_email = [self translateSingleQuote:params[@"customer_email"]];
- NSString* customer_fax = [self translateSingleQuote:params[@"customer_fax"]];
- NSString* customer_first_name = [self translateSingleQuote:params[@"customer_first_name"]];
- NSString* customer_last_name = [self translateSingleQuote:params[@"customer_last_name"]];
- // NSString* customer_name = [self translateSingleQuote:params[@"customer_name"]];
- NSString* customer_phone = [self translateSingleQuote:params[@"customer_phone"]];
- // NSString* customer_price_type = [self translateSingleQuote:params[@"customer_price_type"]];
- NSString* customer_sales_rep = [self translateSingleQuote:params[@"customer_sales_rep"]];
- // NSString* customer_state = [self translateSingleQuote:params[@"customer_state"]];
- // NSString* customer_zipcode = [self translateSingleQuote:params[@"customer_zipcode"]];
- NSString* create_by = [self translateSingleQuote:params[@"user"]];
-
- NSMutableArray* arr_name= [[NSMutableArray alloc] init];
-
- [arr_name addObject:customer_first_name];
- [arr_name addObject:customer_last_name];
-
- NSString *contact_name=[RAUtils arr2string:arr_name separator:@" " trim:true];
-
-
- NSString* sql_neworder=[NSString stringWithFormat:@"insert into offline_order(so_id,status,customer_cid,customer_contact,customer_email,customer_fax,customer_phone,sales_rep,create_by,customer_contact) values('OFFLINE'||hex(randomblob(16)),0,'%@','%@','%@','%@','%@','%@','%@','%@')",customer_cid,customer_contact,customer_email,customer_fax,customer_phone,customer_sales_rep,create_by ,contact_name];
-
- sqlite3 *db = [iSalesDB get_db];
-
- int result =[iSalesDB execSql:sql_neworder db:db];
- [ret setValue:[NSNumber numberWithInt:result] forKey:@"result"];
-
-
-
- //insert into offline_order(so_id,status,contact_id,sales_rep,create_by,customer_contact) select 'OFFLINE'||hex(randomblob(16)),-1,contact_id,sales_rep,company_name from offline_contact where contact_id='99FURO0002'
- //soId
- int _id=[iSalesDB get_insertid:@"offline_order" db:db];
-
-
-
-
-
- NSString *sqlQuery = [NSString stringWithFormat:@"select so_id from offline_order where _id=%d ",_id];
- sqlite3_stmt * statement;
-
- if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
- {
- if (sqlite3_step(statement) == SQLITE_ROW)
- {
- // char *name = (char*)sqlite3_column_text(statement, 1);
- // NSString *nsNameStr = [[NSString alloc]initWithUTF8String:name];
-
- //ret = sqlite3_column_int(statement, 0);
-
- char *soId = (char*)sqlite3_column_text(statement, 0);
- if(soId==nil)
- soId="";
- NSString *nssoId = [[NSString alloc]initWithUTF8String:soId];
- [ret setValue:nssoId forKey:@"soId"];
- [ret setValue:nssoId forKey:@"orderCode"];
-
- }
- sqlite3_finalize(statement);
- }
-
- [ret setValue:[NSNumber numberWithInt:0] forKey:@"orderStatus"];
- [ret setValue:@"Regular Mode" forKey:@"mode"];
-
-
- [iSalesDB close_db:db];
-
- return [RAUtils dict2data:ret];
-
- }
- +(NSData*) offline_editorder :(NSMutableDictionary *) params
- {
-
-
- NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
-
-
- NSString* orderCode = [params valueForKey:@"orderCode"];
-
-
-
- sqlite3 *db = [iSalesDB get_db];
-
- int cart_count=[iSalesDB get_recordcount:db table:@"offline_cart" where:[NSString stringWithFormat:@"so_no='%@'",orderCode]];
-
- int wish_count=[iSalesDB get_recordcount:db table:@"offline_wishlist" where:@"1=1"];
- ret[@"wish_count"]=[NSNumber numberWithInt:wish_count ];
- ret[@"cart_count"]=[NSNumber numberWithInt:cart_count ];
- ret[@"result"]=[NSNumber numberWithInt:RESULT_TRUE ];
-
- [iSalesDB close_db:db];
-
- return [RAUtils dict2data:ret];
-
-
- }
- +(NSData*) offline_add2cart :(NSMutableDictionary *) params;
- {
- NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
- sqlite3 *db = [iSalesDB get_db];
-
- int count =0;
- if(params[@"count"]!=nil)
- {
- count = [params[@"count"] intValue];
- }
-
-
- NSString* product_id=params[@"product_id"];
- NSString* orderCode=params[@"orderCode"];
-
-
- NSArray* arr_id=[RAUtils string2arr:product_id separator:@","];
-
- for(int i=0;i<arr_id.count;i++)
- {
-
- int _id=[iSalesDB get_recordid:db table:@"offline_cart" where:[NSString stringWithFormat:@"so_no='%@' and product_id=%@",orderCode,arr_id[i]]];
- int item_qty= count;
- if(item_qty==0)
- item_qty=[self model_stockUom:[arr_id[i] intValue] db:db];
-
- NSString* sql=nil;
-
-
- if(_id<0)
- {
- // NSString* bundle_serialno= [self model_bundle:[arr_id[i] intValue] db:db];
- int item_id=[self product_itemid:[arr_id[i] intValue] db:db];
-
- sql=[NSString stringWithFormat:@"insert into offline_cart(product_id,so_no,item_count,item_id,create_time) values(%@,'%@',%d,%d,datetime('now', 'localtime'))",arr_id[i],orderCode,item_qty,item_id];
-
- }
- else
- {
- sql=[NSString stringWithFormat:@"update offline_cart set item_count=item_count+%d,create_time = datetime('now', 'localtime') where _id=%d",item_qty,_id];
-
- }
- [iSalesDB execSql:sql db:db];
-
- }
-
-
-
-
- int cart_count=[iSalesDB get_recordcount:db table:@"offline_cart" where:[NSString stringWithFormat:@"so_no='%@'",orderCode]];
-
- int wish_count=[iSalesDB get_recordcount:db table:@"offline_wishlist" where:@"1=1"];
- ret[@"wish_count"]=[NSNumber numberWithInt:wish_count ];
- ret[@"cart_count"]=[NSNumber numberWithInt:cart_count ];
- ret[@"result"]=[NSNumber numberWithInt:RESULT_TRUE ];
-
- [iSalesDB close_db:db];
-
- return [RAUtils dict2data:ret];
- }
- +(NSDictionary*) model_bundle:(int) item_id db:(sqlite3*)db compute_part:(bool)compute
- {
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
-
- NSMutableDictionary* ret = [[NSMutableDictionary alloc]init];
-
-
- NSString *sqlQuery = [NSString stringWithFormat:@"select b.item_id,b.qty,c.name,c.description,b.unit_price,b.use_unitprice from (select item_id,qty,decrypt(unit_price) as unit_price,use_unitprice from bundle where product_item_id=%d) b left join catalog c on b.item_id=c.item_id;",item_id];
- sqlite3_stmt * statement;
-
- int count=0;
- if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
- {
-
- while (sqlite3_step(statement) == SQLITE_ROW)
- {
-
- NSMutableDictionary* itemjson = [[NSMutableDictionary alloc]init];
- int bitem_id = sqlite3_column_int(statement, 0);
- int bitem_qty = sqlite3_column_int(statement, 1);
-
- char *name = (char*)sqlite3_column_text(statement, 2);
- if(name==nil)
- name="";
- NSString* nsname=[[NSString alloc]initWithUTF8String:name];
-
- char *description = (char*)sqlite3_column_text(statement, 3);
- if(description==nil)
- description="";
- NSString* nsdescription=[[NSString alloc]initWithUTF8String:description];
-
- double unit_price = sqlite3_column_double(statement, 4);
- int use_unitprice = sqlite3_column_int(statement, 5);
- if(use_unitprice!=1)
- {
- unit_price=[self get_model_default_price:appDelegate.contact_id product_id:nil item_id:@(item_id) db:db].doubleValue;
- }
-
- itemjson[@"model"]=nsname;
- itemjson[@"description"]=nsdescription;
- itemjson[@"unit_price"]=[NSString stringWithFormat:@"%.2f",unit_price];
- itemjson[@"modulus"]=[NSNumber numberWithInt:bitem_qty];
- itemjson[@"item_id"]=[NSNumber numberWithInt:bitem_id].stringValue;
-
- if(compute)
- {
- itemjson[@"combine"]=[self model_bundle:bitem_id db:db compute_part:compute];
- }
- ret[[NSString stringWithFormat:@"item_%d",count]]=itemjson;
- count++;
-
- }
- sqlite3_finalize(statement);
- }
- ret[@"count"]=@(count);
- if(count==0)
- return nil;
- else
- return ret;
- }
- +(NSDictionary*) model_subtotal:(int) item_id count:(int)count db:(sqlite3*)db compute_part:(bool)compute
- {
- //compute: add part to subtotal;
- NSMutableDictionary* ret = [[NSMutableDictionary alloc]init];
-
- double cuft=0;
- double weight=0;
- int carton=0;
-
-
- NSString *sqlQuery = [NSString stringWithFormat:@"select ulength ,uwidth ,uheight ,uweight ,mlength ,mwidth ,mheight ,mweigth ,ilength ,iwidth ,iheight , iweight ,pcs ,mpack ,ipack,ucbf,icbf,mcbf from catalog where item_id=%d;",item_id];
- sqlite3_stmt * statement;
-
-
- if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
- {
-
- if (sqlite3_step(statement) == SQLITE_ROW)
- {
- double ulength = sqlite3_column_double(statement, 0);
- double uwidth = sqlite3_column_double(statement, 1);
- double uheight = sqlite3_column_double(statement, 2);
- double uweight = sqlite3_column_double(statement, 3);
- double mlength = sqlite3_column_double(statement, 4);
- double mwidth = sqlite3_column_double(statement, 5);
- double mheight = sqlite3_column_double(statement, 6);
- double mweight = sqlite3_column_double(statement, 7);
- double ilength = sqlite3_column_double(statement, 8);
- double iwidth = sqlite3_column_double(statement, 9);
- double iheight = sqlite3_column_double(statement, 10);
- double iweight = sqlite3_column_double(statement, 11);
- int pcs = sqlite3_column_int(statement,12);
- int mpack = sqlite3_column_int(statement, 13);
- int ipack = sqlite3_column_int(statement, 14);
- double ucbf = sqlite3_column_double(statement, 15);
- double icbf = sqlite3_column_double(statement, 16);
- double mcbf = sqlite3_column_double(statement, 17);
-
- if(ipack==0)
- {
- carton= count/mpack ;
- weight = mweight*carton;
- cuft= carton*(mlength*mwidth*mheight);
- int remain=count%mpack;
- if(remain==0)
- {
- //do nothing;
- }
- else
- {
- carton++;
- weight += uweight*remain;
- cuft += (ulength*uwidth*uheight)*remain;
- }
-
- }
- else
- {
- carton = count/(mpack*ipack);
- weight = mweight*carton;
- cuft= carton*(mlength*mwidth*mheight);
- int remain=count%(mpack*ipack);
- if(remain==0)
- {
- // do nothing;
- }
- else
- {
- carton++;
- int icarton =remain/ipack;
- int iremain=remain%ipack;
-
- weight += iweight*icarton;
- cuft += (ilength*iwidth*iheight)*icarton;
- if(iremain==0)
- {
- //do nothing;
- }
- else
- {
-
- weight += uweight*iremain;
- cuft += (ulength*uwidth*uheight)*iremain;
- }
-
-
- }
-
- }
- #ifdef BUILD_NPD
- cuft=ucbf*count;
- weight= uweight*count;
- #endif
-
- }
-
-
- sqlite3_finalize(statement);
- }
-
-
-
- if(compute)
- {
- NSArray * arr_count=nil;
- NSArray * arr_bundle=[self model_bundle:item_id db:db count:&arr_count];
- for(int i=0;i<arr_bundle.count;i++)
- {
- [arr_bundle[i] intValue];
- NSDictionary* bundlejson=[self model_subtotal:[arr_bundle[i] intValue] count:[arr_count[i] intValue]*count db:db compute_part:compute];
- cuft+=[bundlejson[@"cuft"] doubleValue];
- weight+=[bundlejson[@"weight"] doubleValue];
- carton+=[bundlejson[@"carton"] intValue];
- }
- }
- ret[@"cuft"]= [NSNumber numberWithDouble:cuft];
- ret[@"weight"]= [NSNumber numberWithDouble:weight];
- ret[@"carton"]= [NSNumber numberWithInteger:carton];
-
- return ret;
- }
- +(NSData*) offline_requestcart :(NSMutableDictionary *) params
- {
- NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
- sqlite3 *db = [iSalesDB get_db];
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
-
- NSString* orderCode=params[@"orderCode"];
-
-
-
-
-
- NSString *sqlQuery = [ NSString stringWithFormat:@"select c.product_id,c.price,c.discount,c.item_count,c.line_note,m.name,m.description,c.item_id,m.stockUom,c._id from (select _id,product_id,decrypt(str_price) as price,discount,item_count,line_note,item_id from offline_cart where so_no='%@') c left join product m on c.product_id=m.product_id",orderCode ];
-
- // NSString *sqlQuery = [ NSString stringWithFormat:@"select c.product_id,decrypt(c.str_price),c.discount,c.item_count,c.line_note,m.name,m.description,c.item_id,m.stockUom,c._id from offline_cart c left join product m on c.product_id=m.product_id where c.so_no='%@'",orderCode ];
-
-
- // NSString *sqlQuery = @"select * from (select decrypt(str_price) from offline_cart) c";
-
- DebugLog(@"offline_login sql:%@",sqlQuery);
- sqlite3_stmt * statement;
-
-
- [ret setValue:[NSNumber numberWithInt:AP_USER_NOT_AUTH ] forKey:@"result"];
-
- int count=0;
- int dbresult=sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil);
- if ( dbresult== SQLITE_OK)
- {
-
-
- while (sqlite3_step(statement) == SQLITE_ROW)
- {
-
-
- NSMutableDictionary* itemjson = [[NSMutableDictionary alloc] init];
-
-
-
-
- int product_id = sqlite3_column_int(statement, 0);
-
- char *str_price = (char*)sqlite3_column_text(statement, 1);
-
- int item_id = sqlite3_column_int(statement, 7);
-
- NSString* Price=nil;
- if(str_price==nil)
- {
- // NSNumber* price= [self get_model_default_price:appDelegate.contact_id product_id:product_id db:db];
- NSNumber* price = [self get_model_default_price:appDelegate.contact_id product_id:nil item_id:@(item_id) db:db];
- if(price==nil)
- Price=@"No Price.";
- else
- Price=[NSString stringWithFormat:@"%.2f",price.floatValue];
- }
- else
- {
-
- Price=[NSString stringWithFormat:@"%.2f",[[[NSString alloc]initWithUTF8String:str_price] floatValue]];
- }
-
-
- double discount = sqlite3_column_double(statement, 2);
- int item_count = sqlite3_column_int(statement, 3);
-
- char *line_note = (char*)sqlite3_column_text(statement, 4);
- NSString *nsline_note=nil;
- if(line_note!=nil)
- nsline_note= [[NSString alloc]initWithUTF8String:line_note];
-
-
- char *name = (char*)sqlite3_column_text(statement, 5);
- NSString *nsname=nil;
- if(name!=nil)
- nsname= [[NSString alloc]initWithUTF8String:name];
-
- char *description = (char*)sqlite3_column_text(statement, 6);
- NSString *nsdescription=nil;
- if(description!=nil)
- nsdescription= [[NSString alloc]initWithUTF8String:description];
-
-
- int stockUom = sqlite3_column_int(statement, 8);
- int _id = sqlite3_column_int(statement, 9);
-
- NSDictionary* bsubtotaljson=[self model_subtotal:item_id count:item_count db:db compute_part:true];
- double cuft=[bsubtotaljson[@"cuft"] doubleValue];
- double weight=[bsubtotaljson[@"weight"] doubleValue];
- int carton=[bsubtotaljson[@"carton"] intValue];
-
- // itemjson[@"img_url"]= [self model_category_img:[NSString stringWithFormat:@"%@",[NSNumber numberWithInt:item_id]] model_name:nil db:db];
- itemjson[@"img_url"] = [self item_image:[NSString stringWithFormat:@"%@",[NSNumber numberWithInt:item_id]] db:db];
- itemjson[@"model"]=nsname;
- itemjson[@"cuft"]=[NSNumber numberWithDouble:cuft];
- itemjson[@"weight"]=[NSNumber numberWithDouble:weight];
- itemjson[@"carton"]=[NSNumber numberWithInt:carton];
- itemjson[@"cart_item_id"]=[NSNumber numberWithInt:_id].stringValue;
- itemjson[@"check"]=@"true";
- itemjson[@"product_id"]=[NSNumber numberWithInt:product_id].stringValue;
- itemjson[@"count"]=[NSNumber numberWithInt:item_count];
- itemjson[@"unit_price"]=Price;
- itemjson[@"discount"]=[NSNumber numberWithInt:discount];
- itemjson[@"description"]=[NSString stringWithFormat:@"%@\n%@",nsname,nsdescription ];
- itemjson[@"stockUom"]=[NSNumber numberWithInt:stockUom];
- itemjson[@"note"]=nsline_note;
- itemjson[@"combine"]=[self model_bundle:item_id db:db compute_part:false];
-
- ret[[NSString stringWithFormat:@"item_%d",count]]=itemjson;
- count++;
- }
-
-
- ret[@"result"]=[NSNumber numberWithInt:RESULT_TRUE ];
- sqlite3_finalize(statement);
- }
-
-
-
-
-
-
- int cart_count=[iSalesDB get_recordcount:db table:@"offline_cart" where:[NSString stringWithFormat:@"so_no='%@'",orderCode]];
-
- int wish_count=[iSalesDB get_recordcount:db table:@"offline_wishlist" where:@"1=1"];
- ret[@"wish_count"]=[NSNumber numberWithInt:wish_count ];
- ret[@"cart_count"]=[NSNumber numberWithInt:cart_count ];
- ret[@"count"]=[NSNumber numberWithInt:cart_count ];
- ret[@"mode"]=@"Regular Mode";
-
- [iSalesDB close_db:db];
-
- NSString *general_note = [iSalesDB jk_queryText:[NSString stringWithFormat:@"select general_notes from offline_order where so_id = '%@';",orderCode]];
-
- DebugLog(@"general notes :%@",general_note);
-
- ret[@"general_note"]= general_note;
-
- return [RAUtils dict2data:ret];
- }
- +(NSData*) offline_login :(NSMutableDictionary *) params
- {
-
-
-
- NSString* user = [params valueForKey:@"user"];
-
- NSString* password = [params valueForKey:@"password"];
-
-
-
- NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
-
-
-
-
-
-
- sqlite3 *db = [iSalesDB get_db];
-
-
-
-
-
- NSString *sqlQuery = [NSString stringWithFormat:@"select can_show_price,can_see_price,contact_id,user_type,can_cancel_order,can_set_cart_price,can_create_portfolio,can_delete_order,can_submit_order,can_set_tearsheet_price,can_create_order,mode,username,can_update_contact_info from offline_login where lower(username)='%@' and password='%@'",user.lowercaseString ,[AESCrypt encrypt:password password:@"usai"]];
-
-
-
-
- DebugLog(@"offline_login sql:%@",sqlQuery);
- sqlite3_stmt * statement;
-
-
- [ret setValue:[NSNumber numberWithInt:AP_USER_NOT_AUTH ] forKey:@"result"];
-
-
- if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
- {
-
-
- if (sqlite3_step(statement) == SQLITE_ROW)
- {
-
- [ret setValue:[NSNumber numberWithInt:AP_USER_AUTH ] forKey:@"result"];
- NSMutableDictionary* header = [[NSMutableDictionary alloc] init];
-
-
-
-
- int can_show_price = sqlite3_column_int(statement, 0);
- int can_see_price = sqlite3_column_int(statement, 1);
-
- char *contact_id = (char*)sqlite3_column_text(statement, 2);
- if(contact_id==nil)
- contact_id="";
- NSString *nscontact_id= [[NSString alloc]initWithUTF8String:contact_id];
-
- int user_type = sqlite3_column_int(statement, 3);
-
- int can_cancel_order = sqlite3_column_int(statement, 4);
- int can_set_cart_price = sqlite3_column_int(statement, 5);
- int can_create_portfolio = sqlite3_column_int(statement, 6);
- int can_delete_order = sqlite3_column_int(statement, 7);
- int can_submit_order = sqlite3_column_int(statement, 8);
- int can_set_tearsheet_price = sqlite3_column_int(statement, 9);
- int can_create_order = sqlite3_column_int(statement, 10);
-
-
- char *mode = (char*)sqlite3_column_text(statement, 11);
- if(mode==nil)
- mode="";
- NSString *nsmode= [[NSString alloc]initWithUTF8String:mode];
-
-
- char *username = (char*)sqlite3_column_text(statement, 12);
- if(username==nil)
- username="";
- NSString *nsusername= [[NSString alloc]initWithUTF8String:username];
-
- int can_update_contact_info = sqlite3_column_int(statement, 13);
-
-
- [header setValue:[NSNumber numberWithBool:can_show_price] forKey:@"can_show_price"];
- [header setValue:[NSNumber numberWithBool:can_see_price] forKey:@"can_see_price"];
- [header setValue:nscontact_id forKey:@"contact_id"];
- [header setValue:[NSNumber numberWithBool:user_type] forKey:@"user_type"];
- [header setValue:[NSNumber numberWithBool:can_cancel_order] forKey:@"can_cancel_order"];
- [header setValue:[NSNumber numberWithBool:can_set_cart_price] forKey:@"can_set_cart_price"];
- [header setValue:[NSNumber numberWithBool:can_create_portfolio] forKey:@"can_create_portfolio"];
- [header setValue:[NSNumber numberWithBool:can_delete_order] forKey:@"can_delete_order"];
- [header setValue:[NSNumber numberWithBool:can_submit_order] forKey:@"can_submit_order"];
- [header setValue:[NSNumber numberWithBool:can_set_tearsheet_price] forKey:@"can_set_tearsheet_price"];
- [header setValue:[NSNumber numberWithBool:can_create_order] forKey:@"can_create_order"];
-
- [header setValue:[NSNumber numberWithBool:can_update_contact_info] forKey:@"can_update_contact_info"];
-
- [header setValue:nsusername forKey:@"username"];
-
- NSError* error=nil;
-
- NSString* statusFilter =[NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"offline_status_filter_cadedate" ofType:@"json"] encoding:NSUTF8StringEncoding error:&error];
- [header setValue:statusFilter forKey:@"statusFilter"];
-
-
-
-
-
- [ret setObject:header forKey:@"header"];
- [ret setValue:nsmode forKey:@"mode"];
-
-
-
- }
-
-
-
- sqlite3_finalize(statement);
- }
-
-
-
- [iSalesDB close_db:db];
-
-
-
-
- DebugLog(@"data string: %@",[RAUtils dict2string:ret] );
-
- return [RAUtils dict2data:ret];
- }
- +(NSDictionary*) offline_contactinfo :(NSMutableDictionary *) params
- {
- NSString* contactId = [params valueForKey:@"contactId"];
-
-
- NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
-
-
-
-
-
-
- sqlite3 *db = [iSalesDB get_db];
-
-
-
-
-
- NSString *sqlQuery = nil;
-
-
- {
- sqlQuery=[NSString stringWithFormat:@"select editable,company_name,country,addr,zipcode,state,city,contact_name,phone,contact_id,addr_1,addr_2,addr_3,addr_4,first_name,last_name,fax,email,img_0,img_1,img_2,price_type,notes,sales_rep from offline_contact where contact_id='%@'",contactId];
-
- }
-
-
- DebugLog(@"offline_contactlist sql:%@",sqlQuery);
- sqlite3_stmt * statement;
-
-
- [ret setValue:@"2" forKey:@"result"];
-
-
- if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
- {
-
- //int i = 0;
- if (sqlite3_step(statement) == SQLITE_ROW)
- {
-
- [ret setValue:[NSNumber numberWithInt:AP_USER_AUTH ] forKey:@"result"];
-
- NSMutableDictionary* item = [[NSMutableDictionary alloc] init];
-
-
- // int editable = sqlite3_column_int(statement, 0);
-
-
- char *company_name = (char*)sqlite3_column_text(statement, 1);
- NSString *nscompany_name =nil;
- if(company_name==nil)
- nscompany_name=@"";
- else
- nscompany_name=[[NSString alloc]initWithUTF8String:company_name] ;
-
-
- char *country = (char*)sqlite3_column_text(statement, 2);
- if(country==nil)
- country="";
- NSString *nscountry= [[NSString alloc]initWithUTF8String:country];
-
-
- // char *addr = (char*)sqlite3_column_text(statement, 3);
- // if(addr==nil)
- // addr="";
- // NSString *nsaddr= [[NSString alloc]initWithUTF8String:addr];
-
-
- char *zipcode = (char*)sqlite3_column_text(statement, 4);
- if(zipcode==nil)
- zipcode="";
- NSString *nszipcode= [[NSString alloc]initWithUTF8String:zipcode];
-
-
- char *state = (char*)sqlite3_column_text(statement, 5);
- if(state==nil)
- state="";
- NSString *nsstate= [[NSString alloc]initWithUTF8String:state];
-
- char *city = (char*)sqlite3_column_text(statement, 6);
- if(city==nil)
- city="";
- NSString *nscity= [[NSString alloc]initWithUTF8String:city];
-
- // char *contact_name = (char*)sqlite3_column_text(statement, 7);
- // NSString *nscontact_name = nil;
- // if(contact_name==nil)
- // nscontact_name=@"";
- // else
- // nscontact_name= [[NSString alloc]initWithUTF8String:contact_name];
-
- char *phone = (char*)sqlite3_column_text(statement, 8);
- NSString *nsphone = nil;
- if(phone==nil)
- nsphone=@"";
- else
- nsphone= [[NSString alloc]initWithUTF8String:phone];
-
-
- char *contact_id = (char*)sqlite3_column_text(statement, 9);
- if(contact_id==nil)
- contact_id="";
- NSString *nscontact_id= [[NSString alloc]initWithUTF8String:contact_id];
-
- char *addr_1 = (char*)sqlite3_column_text(statement, 10);
- if(addr_1==nil)
- addr_1="";
- NSString *nsaddr_1= [[NSString alloc]initWithUTF8String:addr_1];
-
- char *addr_2 = (char*)sqlite3_column_text(statement, 11);
- if(addr_2==nil)
- addr_2="";
- NSString *nsaddr_2= [[NSString alloc]initWithUTF8String:addr_2];
-
-
- char *addr_3 = (char*)sqlite3_column_text(statement, 12);
- if(addr_3==nil)
- addr_3="";
- NSString *nsaddr_3= [[NSString alloc]initWithUTF8String:addr_3];
-
-
- char *addr_4 = (char*)sqlite3_column_text(statement, 13);
- if(addr_4==nil)
- addr_4="";
- NSString *nsaddr_4= [[NSString alloc]initWithUTF8String:addr_4];
-
-
- char *first_name = (char*)sqlite3_column_text(statement, 14);
- if(first_name==nil)
- first_name="";
- NSString *nsfirst_name= [[NSString alloc]initWithUTF8String:first_name];
-
-
- char *last_name = (char*)sqlite3_column_text(statement, 15);
- if(last_name==nil)
- last_name="";
- NSString *nslast_name= [[NSString alloc]initWithUTF8String:last_name];
-
- char *fax = (char*)sqlite3_column_text(statement, 16);
- NSString *nsfax = nil;
- if(fax==nil)
- nsfax=@"";
- else
- nsfax= [[NSString alloc]initWithUTF8String:fax];
-
- char *email = (char*)sqlite3_column_text(statement, 17);
- NSString *nsemail = nil;
- if(email==nil)
- nsemail=@"";
- else
- nsemail= [[NSString alloc]initWithUTF8String:email];
-
- char *img_0 = (char*)sqlite3_column_text(statement, 18);
- NSString *nsimg_0 = nil;
- if(img_0==nil)
- nsimg_0=@"";
- else
- nsimg_0= [[NSString alloc]initWithUTF8String:img_0];
-
- [self copy_bcardImg:nsimg_0];
-
- char *img_1 = (char*)sqlite3_column_text(statement, 19);
- NSString *nsimg_1 = nil;
- if(img_1==nil)
- nsimg_1=@"";
- else
- nsimg_1= [[NSString alloc]initWithUTF8String:img_1];
- [self copy_bcardImg:nsimg_1];
-
-
- char *img_2 = (char*)sqlite3_column_text(statement, 20);
- NSString *nsimg_2 = nil;
- if(img_2==nil)
- nsimg_2=@"";
- else
- nsimg_2= [[NSString alloc]initWithUTF8String:img_2];
- [self copy_bcardImg:nsimg_2];
-
- char *price_type = (char*)sqlite3_column_text(statement, 21);
- NSString *nsprice_type = nil;
- if(price_type==nil)
- nsprice_type=@"";
- else
- nsprice_type= [[NSString alloc]initWithUTF8String:price_type];
-
-
- char *notes = (char*)sqlite3_column_text(statement, 22);
- NSString *nsnotes = nil;
- if(notes==nil)
- nsnotes=@"";
- else
- nsnotes= [[NSString alloc]initWithUTF8String:notes];
-
-
- char *salesrep = (char*)sqlite3_column_text(statement, 23);
- NSString *nssalesrep = nil;
- if(salesrep==nil)
- nssalesrep=@"";
- else
- nssalesrep= [[NSString alloc]initWithUTF8String:salesrep];
-
-
- {
- // decrypt
-
- nscompany_name=[AESCrypt fastdecrypt:nscompany_name];
-
- // nscompany_name=[NSString stringWithFormat:@"<b>%@</b>",nscompany_name];
-
- nsphone=[AESCrypt fastdecrypt:nsphone];
- // nsphone=[NSString stringWithFormat:@"TEL:%@",nsphone];
-
- nsaddr_1=[AESCrypt fastdecrypt:nsaddr_1];
- // nsaddr_1=[NSString stringWithFormat:@"TEL:%@",nsphone];
-
- }
-
- NSMutableArray* arr_name= [[NSMutableArray alloc] init];
-
- [arr_name addObject:nsfirst_name];
- [arr_name addObject:nslast_name];
-
- NSString *nscontact_name=[RAUtils arr2string:arr_name separator:@" " trim:true];
-
-
- NSMutableArray* arr_ext= [[NSMutableArray alloc] init];
-
- [arr_ext addObject:nsaddr_1];
- [arr_ext addObject:nsaddr_2];
- [arr_ext addObject:nsaddr_3];
- [arr_ext addObject:nsaddr_4];
- [arr_ext addObject:@"\r\n"];
-
- [arr_ext addObject:nscity];
- [arr_ext addObject:nsstate];
- [arr_ext addObject:nszipcode];
- [arr_ext addObject:nscountry];
-
- NSString *nsext=[RAUtils arr2string:arr_ext separator:@", " trim:true];
-
-
- nsext=[nsext stringByReplacingOccurrencesOfString:@", \r\n," withString:@"\r\n"];
-
-
- [item setValue:nsimg_2 forKey:@"business_card_2"];
- [item setValue:nsimg_0 forKey:@"business_card_0"];
- [item setValue:nscountry forKey:@"customer_country"];
- [item setValue:nsphone forKey:@"customer_phone"];
- [item setValue:nsimg_1 forKey:@"business_card_1"];
- [item setValue:nscompany_name forKey:@"customer_name"];
- [item setValue:nsprice_type forKey:@"customer_price_type"];
- [item setValue:nsfirst_name forKey:@"customer_first_name"];
- [item setValue:nsext forKey:@"customer_contact_ext"];
- [item setValue:nszipcode forKey:@"customer_zipcode"];
- [item setValue:nsaddr_1 forKey:@"customer_address1"];
- [item setValue:nsaddr_2 forKey:@"customer_address2"];
- [item setValue:nsaddr_3 forKey:@"customer_address3"];
- [item setValue:nsaddr_4 forKey:@"customer_address4"];
- [item setValue:nsnotes forKey:@"customer_contact_notes"];
- [item setValue:nslast_name forKey:@"customer_last_name"];
- [item setValue:nscity forKey:@"customer_city"];
- [item setValue:nsstate forKey:@"customer_state"];
- [item setValue:nssalesrep forKey:@"customer_sales_rep"];
- [item setValue:contactId forKey:@"customer_cid"];
- [item setValue:nscontact_name forKey:@"customer_contact"];
- [item setValue:nsfax forKey:@"customer_fax"];
- [item setValue:nsemail forKey:@"customer_email"];
-
-
-
- [ret setObject:item forKey:@"customerInfo"];
- // i++;
-
-
-
- }
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- [ret setValue:appDelegate.mode forKey:@"mode"];
- [ret setValue:[NSNumber numberWithInt:1 ] forKey:@"count"];
-
-
-
- sqlite3_finalize(statement);
- }
-
-
-
- [iSalesDB close_db:db];
-
-
-
-
- DebugLog(@"data string: %@",[RAUtils dict2string:ret] );
-
- return ret;
- }
- + (bool) copy_bcardImg:(NSString*) filename
- {
- if(filename.length==0)
- return false;
- // NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
- bool ret=false;
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
- NSString *cachefolder = [paths objectAtIndex:0];
-
- // NSString* from_subpath= [fromPath stringByReplacingOccurrencesOfString:cachefolder withString:@""];
- NSString *offline_createimg = [cachefolder stringByAppendingPathComponent:@"offline_createimg"];
- NSString *img_cache = [cachefolder stringByAppendingPathComponent:@"img_cache"];
-
- NSString * fromPath= [offline_createimg stringByAppendingPathComponent:filename];
- NSString * toPath= [img_cache stringByAppendingPathComponent:filename];
-
- // NSString *savedImagePath=[offline_createimg stringByAppendingPathComponent:filename];
- //
- // NSString *cacheImagePath=[img_cache stringByAppendingPathComponent:filename];
-
- NSFileManager* fileManager = [NSFileManager defaultManager];
- BOOL bdir=NO;
- if(! [fileManager fileExistsAtPath:toPath isDirectory:&bdir])
- {
-
- NSError *error = nil;
- if(![fileManager copyItemAtPath:fromPath toPath:toPath error:&error])
- {
- ret=false;
- }
- else
- {
- ret=true;
- }
-
- // NSError *error = nil;
- // bool bsuccess=[fileManager createDirectoryAtPath:offline_createimg withIntermediateDirectories:YES attributes:nil error:&error];
- //
- // if(!bsuccess)
- // {
- // DebugLog(@"Create offline_createimg folder failed");
- // [ret setValue:[NSNumber numberWithInt:RESULT_ERROR] forKey:@"result"];
- // return [RAUtils dict2data:ret];
- // }
-
- // if(bsuccess)
- // {
- // sqlite3 *db = [self get_db];
- //
- // [self execSql:[NSString stringWithFormat:@"insert into img_cache(name) values('%@')",name] db:db];
- // [iSalesDB close_db:db];
- // }
- }
- return ret;
-
-
- //
- // bool bsuccess=[image writeToFile:savedImagePath atomically:YES];
- // if(bsuccess)
- // {
- // NSError *error = nil;
- // if(![fileManager copyItemAtPath:savedImagePath toPath:cacheImagePath error:&error])
- // {
- // [ret setValue:[NSNumber numberWithInt:RESULT_ERROR] forKey:@"result"];
- // }
- // else
- // {
- // [ret setValue:[NSNumber numberWithInt:RESULT_TRUE] forKey:@"result"];
- //
- // ret[@"img_url_aname"]=filename;
- // ret[@"img_url"]=savedImagePath;
- // }
- // }
- }
- +(NSData *) offline_saveBusinesscard:(NSData *) image
- {
- NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
- NSString *cachefolder = [paths objectAtIndex:0];
- NSString *offline_createimg = [cachefolder stringByAppendingPathComponent:@"offline_createimg"];
- NSString *img_cache = [cachefolder stringByAppendingPathComponent:@"img_cache"];
-
-
- NSFileManager* fileManager = [NSFileManager defaultManager];
- BOOL bdir=YES;
- if(! [fileManager fileExistsAtPath:offline_createimg isDirectory:&bdir])
- {
-
- NSError *error = nil;
- bool bsuccess=[fileManager createDirectoryAtPath:offline_createimg withIntermediateDirectories:YES attributes:nil error:&error];
-
- if(!bsuccess)
- {
- DebugLog(@"Create offline_createimg folder failed");
- [ret setValue:[NSNumber numberWithInt:RESULT_ERROR] forKey:@"result"];
- return [RAUtils dict2data:ret];
- }
-
- // if(bsuccess)
- // {
- // sqlite3 *db = [self get_db];
- //
- // [self execSql:[NSString stringWithFormat:@"insert into img_cache(name) values('%@')",name] db:db];
- // [iSalesDB close_db:db];
- // }
- }
-
-
- // NSData *imagedata=UIImagePNGRepresentation(self.imgview.image);
-
- //JEPG格式
-
- //NSData *imagedata=UIImageJEPGRepresentation(m_imgFore,1.0);
-
- NSString* filename =[NSString stringWithFormat:@"%@.png",[[NSUUID UUID] UUIDString]];
- NSString *savedImagePath=[offline_createimg stringByAppendingPathComponent:filename];
-
- NSString *cacheImagePath=[img_cache stringByAppendingPathComponent:filename];
-
- bool bsuccess=[image writeToFile:savedImagePath atomically:YES];
- if(bsuccess)
- {
- NSError *error = nil;
- if(![fileManager copyItemAtPath:savedImagePath toPath:cacheImagePath error:&error])
- {
- [ret setValue:[NSNumber numberWithInt:RESULT_ERROR] forKey:@"result"];
- }
- else
- {
- [ret setValue:[NSNumber numberWithInt:RESULT_TRUE] forKey:@"result"];
-
- ret[@"img_url_aname"]=filename;
- ret[@"img_url"]=filename;
- }
- }
- else
- {
- [ret setValue:[NSNumber numberWithInt:RESULT_ERROR] forKey:@"result"];
- }
-
-
- return [RAUtils dict2data:ret];
- }
- +(NSDictionary*) model_NIYMAL:(NSString*) category db:(sqlite3 *)db
- {
- // MODEL DETAIL NEW ITEM YOU MAY ALSO LIKE
-
-
- category = [category substringToIndex:3];
- NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
-
- NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
-
- params[@"category"]= category;
-
- ret[@"params"]= params;
- [ret setValue:@"detail" forKey:@"target"];
- [ret setValue:@"popup" forKey:@"action"];
- [ret setValue:@"content" forKey:@"type"];
- [ret setValue:@"New Items You May Also Like" forKey:@"title"];
- [ret setValue:@"model_NIYMAL" forKey:@"data_interface"];
- [ret setValue:@"true" forKey:@"single_row"];
- [ret setValue:@"true" forKey:@"partial_refresh"];
-
- // sqlite3 *db = [iSalesDB get_db];
-
- // int count = [iSalesDB get_recordcount:db table:@"model" where:[NSString stringWithFormat:@"category like'#%%%@%%#'",category]];
-
-
- NSString *sqlQuery = [NSString stringWithFormat:@"select m.name,m.product_id,i.url,random() as aa from product m LEFT join model_image i on m.product_id = i.product_id where m.category like'%%#%@#%%' and m.category like'%%#005#%%' and i.default_img = %d order by aa limit 10 ;",category,OFFLINE_IMG_TYPE_CATEGORY]; // select m.name,m.product_id,i.url,random() as aa from model m LEFT join model_image i on m.product_id = i.product_id where m.category like'%%#%@#%%' and m.category like'%%#005#%%' and i.default_img = %d order by aa limit 10 ;
- sqlite3_stmt * statement;
- int count = 0;
- [ret setValue:[NSString stringWithFormat:@"%d",count] forKey:@"count"];
-
- // int count=0;
- if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
- {
-
- int i=0;
- while (sqlite3_step(statement) == SQLITE_ROW)
- {
- NSMutableDictionary* item = [[NSMutableDictionary alloc] init];
-
- // char *name = (char*)sqlite3_column_text(statement, 1);
- // NSString *nsNameStr = [[NSString alloc]initWithUTF8String:name];
-
- char *name = (char*)sqlite3_column_text(statement, 0);
- NSString *nsname = [[NSString alloc]initWithUTF8String:name];
-
-
-
-
- int product_id = sqlite3_column_int(statement, 1);
-
-
- char *url = (char*)sqlite3_column_text(statement, 2);
- if(url==nil)
- url="";
- NSString *nsurl = [[NSString alloc]initWithUTF8String:url];
-
- [item setValue:nsurl forKey:@"picture_path"];
- [item setValue:nsname forKey:@"fash_name"];
- [item setValue:[NSString stringWithFormat:@"%d",product_id] forKey:@"product_id"];
- [item setValue:category forKey:@"category"];
- [ret setObject:item forKey:[NSString stringWithFormat:@"item_%d",i]];
- i++;
-
- }
- [ret setValue:[NSString stringWithFormat:@"%d",i] forKey:@"count"];
-
-
- sqlite3_finalize(statement);
- }
- NSLog(@"count:%d",count);
-
-
- // [iSalesDB close_db:db];
-
-
- return ret;
-
-
- }
- +(NSDictionary*) model_kvItem:(NSString*) key value:(NSString*)value
- {
- NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
-
- [ret setValue:key forKey:@"key"];
- [ret setValue:value forKey:@"val"];
- return ret;
- }
- +(NSDictionary*) model_property :(int)product_id field:(NSString*) field db:(sqlite3 *)db
- {
- NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
-
- [ret setValue:@"0" forKey:@"img_count"];
-
- // sqlite3 *db = [iSalesDB get_db];
-
-
-
-
- NSString *sqlQuery = [NSString stringWithFormat:@"select %@,property_display from product where product_id=%d ;",field,product_id]; // select %@,property_display from model where product_id=%d ;
- sqlite3_stmt * statement;
-
-
- if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
- {
-
- int i=0;
- if (sqlite3_step(statement) == SQLITE_ROW)
- {
- NSMutableDictionary* item = [[NSMutableDictionary alloc] init];
-
- // char *name = (char*)sqlite3_column_text(statement, 1);
- // NSString *nsNameStr = [[NSString alloc]initWithUTF8String:name];
-
- char *value = (char*)sqlite3_column_text(statement, 0);
- if(value==nil)
- value="";
- NSString *nsvalue = [[NSString alloc]initWithUTF8String:value];
-
- char *key = (char*)sqlite3_column_text(statement, 1);
- if(key==nil)
- key="";
- NSString *nskey = [[NSString alloc]initWithUTF8String:key];
-
- [item setValue:nsvalue forKey:@"val"];
- [item setValue:nskey forKey:@"key"];
-
-
- [ret setObject:item forKey:[NSString stringWithFormat:@"item_%d",i]];
- [ret setValue:@"1" forKey:@"count"];
- i++;
-
- }
-
-
-
- sqlite3_finalize(statement);
- }
-
-
-
- // [iSalesDB close_db:db];
-
- return ret;
- }
- +(NSDictionary*) model_selector :(NSString*)product_group field:(NSString*) field db:(sqlite3*)db
- {
- NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
-
- [ret setValue:@"0" forKey:@"count"];
-
- // sqlite3 *db = [iSalesDB get_db];
-
-
-
- NSString *sqlQuery = [NSString stringWithFormat:@"select %@,selector_display,product_id,category from product where product_group='%@' order by name;",field,product_group]; // select %@,selector_display,product_id,category from model where product_group='%@' order by name;
- sqlite3_stmt * statement;
-
-
- if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
- {
-
- int i=0;
- while (sqlite3_step(statement) == SQLITE_ROW)
- {
- NSMutableDictionary* item = [[NSMutableDictionary alloc] init];
-
- // char *name = (char*)sqlite3_column_text(statement, 1);
- // NSString *nsNameStr = [[NSString alloc]initWithUTF8String:name];
-
- char *value = (char*)sqlite3_column_text(statement, 0);
- if(value==nil)
- value="";
- NSString *nsvalue = [[NSString alloc]initWithUTF8String:value];
-
- char *selector_display = (char*)sqlite3_column_text(statement, 1);
- if(selector_display==nil)
- selector_display="";
- NSString *nsselector_display = [[NSString alloc]initWithUTF8String:selector_display];
-
-
- int product_id = sqlite3_column_int(statement, 2);
-
-
-
-
- char *category = (char*)sqlite3_column_text(statement, 3);
- if(category==nil)
- category="";
- NSString *nscategory = [[NSString alloc]initWithUTF8String:category];
-
- NSString* url = [self model_category_img:[NSNumber numberWithInt:product_id].stringValue model_name:nil db:db];//[self category_img:product_id];
-
- [item setValue:nsvalue forKey:@"title"];
- [item setValue:url forKey:@"pic_url"];
-
- NSMutableDictionary* params=[[NSMutableDictionary alloc] init];
- [params setValue:@"2" forKey:@"count"];
- NSMutableDictionary* param0=[[NSMutableDictionary alloc] init];
- [param0 setValue:[NSNumber numberWithInt:product_id ] forKey:@"val"];
- [param0 setValue:@"product_id" forKey:@"name"];
-
-
- NSMutableDictionary* param1=[[NSMutableDictionary alloc] init];
- [param1 setValue:nscategory forKey:@"val"];
- [param1 setValue:@"category" forKey:@"name"];
-
- [params setObject:param0 forKey:@"param_0"];
- [params setObject:param1 forKey:@"param_1"];
-
-
- [item setObject:params forKey:@"params"];
-
-
-
- [ret setValue:nsselector_display forKey:@"name"];
-
- [ret setObject:item forKey:[NSString stringWithFormat:@"item_%d",i]];
- i++;
-
- }
- [ret setValue:[NSString stringWithFormat:@"%d",i] forKey:@"count"];
- [ret setValue:@"switch" forKey:@"action"];
-
- sqlite3_finalize(statement);
- }
-
-
-
- // [iSalesDB close_db:db];
-
- return ret;
- }
- +(NSMutableDictionary*) category_img :(int)product_id db:(sqlite3 *)db
- {
- // model 在 category search 显示的图片。
- NSMutableDictionary* ret =[[NSMutableDictionary alloc]init];
-
-
-
- // sqlite3 *db = [iSalesDB get_db];
-
-
- NSString *sqlQuery = [NSString stringWithFormat:@"select url,type from model_image where product_id=%d and type<2 order by default_img desc , _id asc limit 2;",product_id];
- sqlite3_stmt * statement;
-
-
- if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
- {
-
-
- while (sqlite3_step(statement) == SQLITE_ROW)
- {
- char *url = (char*)sqlite3_column_text(statement, 0);
- if(url==nil)
- url="";
- int type = sqlite3_column_int(statement, 1);
- if(type==0)
- [ret setValue:[[NSString alloc]initWithUTF8String:url] forKey:@"img"];
- else
- [ret setValue:[[NSString alloc]initWithUTF8String:url] forKey:@"img_big"];
-
- }
-
-
-
- sqlite3_finalize(statement);
- }
-
-
-
- // [iSalesDB close_db:db];
-
- return ret;
- }
- +(int) product_itemid:(int)product_id db:(sqlite3*)db
- {
- int item_id=-1;
- NSString *sqlQuery = [NSString stringWithFormat:@"select item_id from product where product_id=%d;",product_id];
- sqlite3_stmt * statement;
-
-
- if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
- {
-
- if (sqlite3_step(statement) == SQLITE_ROW)
- {
- item_id = sqlite3_column_int(statement, 0);
- }
-
-
- sqlite3_finalize(statement);
- }
-
- return item_id;
- }
- +(NSArray*) model_bundle:(int)item_id db:(sqlite3*)db count:(NSArray**)count //DEPRECATED(1_5)
- {
- // NSString* ret = @"";
- NSMutableArray* arr_bundle = [[NSMutableArray alloc]init];
- NSMutableArray* arr_count = [[NSMutableArray alloc]init];
-
- NSString *sqlQuery = [NSString stringWithFormat:@"select item_id,qty from bundle where product_item_id=%d;",item_id];
- sqlite3_stmt * statement;
-
-
- if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
- {
-
- while (sqlite3_step(statement) == SQLITE_ROW)
- {
- int bitem_id = sqlite3_column_int(statement, 0);
- int bitem_qty = sqlite3_column_int(statement, 1);
-
-
- [arr_bundle addObject:[NSNumber numberWithInt:bitem_id] ];
- [arr_count addObject:[NSNumber numberWithInt:bitem_qty] ];
- }
-
- // ret=[RAUtils arr2string:arr_bundle separator:@";" trim:true];
-
- sqlite3_finalize(statement);
- }
- // if(ret==nil)
- // ret=@"";
- *count=arr_count;
- return arr_bundle;
- }
- +(int) model_stockUom :(int)product_id db:(sqlite3*)db
- {
- // get default sold qty, return -1 if model not found;
- int ret = -1;
- NSString *sqlQuery = [NSString stringWithFormat:@"select stockUom from product where product_id=%d;",product_id];// select stockUom from model where product_id=%d;
- sqlite3_stmt * statement;
-
-
- if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
- {
-
- if (sqlite3_step(statement) == SQLITE_ROW)
- {
- ret = sqlite3_column_int(statement, 0);
- }
-
-
- sqlite3_finalize(statement);
- }
-
- return ret;
-
-
- }
- +(NSDictionary*) model_img :(int)product_id db:(sqlite3*)db
- {
- NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
-
- [ret setValue:@"0" forKey:@"img_count"];
-
- // sqlite3 *db = [iSalesDB get_db];
-
-
-
- NSString *sqlQuery = [NSString stringWithFormat:@"select url from model_image where product_id=%d and type=1;",product_id];
- sqlite3_stmt * statement;
-
-
- if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
- {
-
- int i=0;
- while (sqlite3_step(statement) == SQLITE_ROW)
- {
- NSMutableDictionary* item = [[NSMutableDictionary alloc] init];
-
- // char *name = (char*)sqlite3_column_text(statement, 1);
- // NSString *nsNameStr = [[NSString alloc]initWithUTF8String:name];
-
- char *url = (char*)sqlite3_column_text(statement, 0);
- if(url==nil)
- url="";
- NSString *nsurl = [[NSString alloc]initWithUTF8String:url];
-
-
-
- [item setValue:nsurl forKey:@"s"];
- [item setValue:nsurl forKey:@"l"];
-
-
- [ret setObject:item forKey:[NSString stringWithFormat:@"img_%d",i]];
- i++;
-
- }
- [ret setValue:[NSString stringWithFormat:@"%d",i] forKey:@"img_count"];
-
-
- sqlite3_finalize(statement);
- }
-
-
-
- // [iSalesDB close_db:db];
-
- return ret;
- }
- #pragma mark - Jack
- #warning 做SQL操作时转义!!
- + (NSDictionary *)offline_getAllCountryDefault:(NSString *)countryCode {
- // "val_227" : {
- // "check" : 1,
- // "value" : "US United States",
- // "value_id" : "228"
- // },
-
- if (!countryCode) {
- countryCode = @"US";
- }
-
- NSMutableDictionary *ret = [[iSalesDB jk_query:@"select _id,name,code,countrycode_id from offline_country;" completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container,long *count) {
- char *name = (char *) sqlite3_column_text(stmt, 1); // 全称
- char *code = (char *) sqlite3_column_text(stmt, 2); // 缩写
- int code_id = sqlite3_column_int(stmt, 3); // id
-
- NSMutableDictionary *countryDic = [NSMutableDictionary dictionaryWithCapacity:2];
- [countryDic setValue:[NSString stringWithFormat:@"%s",name] forKey:@"value"];
- [countryDic setValue:[NSString stringWithFormat:@"%d",code_id] forKey:@"value_id"];
- [countryDic setValue:[NSNumber numberWithInt:0] forKey:@"check"];
-
- if ([countryCode isEqualToString:[NSString stringWithUTF8String:code]]) {
- [countryDic setValue:[NSNumber numberWithInt:1] forKey:@"check"];
- }
-
- long n = *count;
- *count = n + 1;
- NSString *key = [NSString stringWithFormat:@"val_%ld",n];
- [container setValue:countryDic forKey:key];
- }] mutableCopy];
-
- [ret setValue:[NSNumber numberWithInt:ret.allKeys.count] forKey:@"count"];
- return ret;
- }
- + (NSDictionary *)offline_getStateByCountryCode:(NSString *)countryCode checkedState:(NSString *)state_code{
- countryCode = [self translateSingleQuote:countryCode];
- NSString *sqlQuery = [NSString stringWithFormat:@"select _id,name,code,country_code from offline_state where country_code = '%@';",countryCode];
-
- NSMutableDictionary *ret = [[iSalesDB jk_query:sqlQuery completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- char *name = (char *) sqlite3_column_text(stmt, 1); // value
- char *code = (char *) sqlite3_column_text(stmt, 2); // value_id
-
- if (name == NULL) {
- name = "";
- }
- if (code == NULL) {
- code = "";
- }
-
-
- NSMutableDictionary *stateDic = [NSMutableDictionary dictionaryWithCapacity:2];
- [stateDic setValue:[NSString stringWithUTF8String:name] forKey:@"value"];
- [stateDic setValue:[NSString stringWithUTF8String:code] forKey:@"value_id"];
- [stateDic setValue:[NSNumber numberWithInt:0] forKey:@"check"];
-
- if (state_code && [[NSString stringWithUTF8String:code] isEqualToString:state_code]) {
- [stateDic setValue:[NSNumber numberWithInt:1] forKey:@"check"];
- }
-
- NSString *key = [NSString stringWithFormat:@"val_%ld",(*count)++];
- [container setValue:stateDic forKey:key];
-
- } failure:^(NSMutableDictionary *container,NSString *err_msg){
-
- DebugLog(@"query all state error: %@",err_msg);
-
- // NSMutableDictionary *stateDic = [NSMutableDictionary dictionaryWithCapacity:2];
- // [stateDic setValue:@"Other" forKey:@"value"];
- // [stateDic setValue:@"" forKey:@"value_id"];
- // [stateDic setValue:[NSNumber numberWithInt:0] forKey:@"check"];
- //
- // if (state_code && [@"" isEqualToString:state_code]) {
- // [stateDic setValue:[NSNumber numberWithInt:1] forKey:@"check"];
- // }
- //
- // NSString *key = [NSString stringWithFormat:@"val_0"];
- // [container setValue:stateDic forKey:key];
-
- }] mutableCopy];
-
- // failure 可以不用了,一样的
- if (ret.allKeys.count == 0) {
- NSMutableDictionary *stateDic = [NSMutableDictionary dictionaryWithCapacity:2];
- [stateDic setValue:@"Other" forKey:@"value"];
- [stateDic setValue:@"" forKey:@"value_id"];
- [stateDic setValue:[NSNumber numberWithInt:0] forKey:@"check"];
-
- if (state_code && [@"" isEqualToString:state_code]) {
- [stateDic setValue:[NSNumber numberWithInt:1] forKey:@"check"];
- }
-
- NSString *key = [NSString stringWithFormat:@"val_0"];
- [ret setValue:stateDic forKey:key];
- }
-
- [ret setValue:[NSNumber numberWithInt:ret.allKeys.count] forKey:@"count"];
-
- return ret;
- }
- + (NSDictionary *)offline_getStateByCountryCodeId:(NSString *)codeId checkedState:(NSString *)stateCode {
-
- codeId = [self translateSingleQuote:codeId];
- NSString *sql = [NSString stringWithFormat:@"select name,code from offline_state where country_code = (select code as country_code FROM offline_country where countrycode_id = %@);",codeId];
-
- NSMutableDictionary *ret = [[iSalesDB jk_query:sql completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
- char *name = (char *) sqlite3_column_text(stmt, 0); // value
- char *code = (char *) sqlite3_column_text(stmt, 1); // value_id
-
- if (name == NULL) {
- name = "";
- }
- if (code == NULL) {
- code = "";
- }
-
-
- NSMutableDictionary *stateDic = [NSMutableDictionary dictionaryWithCapacity:2];
- [stateDic setValue:[NSString stringWithUTF8String:name] forKey:@"value"];
- [stateDic setValue:[NSString stringWithUTF8String:code] forKey:@"value_id"];
- [stateDic setValue:[NSNumber numberWithInt:0] forKey:@"check"];
-
- if (stateCode && [[NSString stringWithUTF8String:code] isEqualToString:stateCode]) {
- [stateDic setValue:[NSNumber numberWithInt:1] forKey:@"check"];
- }
-
- NSString *key = [NSString stringWithFormat:@"val_%ld",(*count)++];
- [container setValue:stateDic forKey:key];
- }] mutableCopy];
-
- [ret setValue:[NSNumber numberWithInt:ret.allKeys.count] forKey:@"count"];
-
- return ret;
- }
- + (NSDictionary *)offline_getPrice {
-
- NSString *sql = [NSString stringWithFormat:@"select _id,name,type,order_by from price;"];
-
- NSMutableDictionary *ret = [[iSalesDB jk_query:sql completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- char *name = (char *) sqlite3_column_text(stmt, 1);
- int type = sqlite3_column_int(stmt, 2);
- int orderBy = sqlite3_column_int(stmt, 3);
-
- if (name == NULL) {
- name = "";
- }
-
-
- NSMutableDictionary *priceDic = [NSMutableDictionary dictionary];
- [priceDic setValue:[NSString stringWithUTF8String:name] forKey:@"value"];
- [priceDic setValue:[NSNumber numberWithInt:type] forKey:@"value_id"];
- NSString *key = [NSString stringWithFormat:@"val_%d",orderBy];
- [priceDic setValue:[NSNumber numberWithInt:0] forKey:@"check"];
-
- if (orderBy == 0) {
- [priceDic setValue:[NSNumber numberWithInt:1] forKey:@"check"];
- }
-
- [container setValue:priceDic forKey:key];
-
- }] mutableCopy];
-
- [ret setValue:[NSNumber numberWithInt:ret.allKeys.count] forKey:@"count"];
-
- return ret;
- }
- + (NSDictionary *)offline_getSalesRep {
-
- // 首先从offline_login表中取出sales_code
- AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
- NSString *user = app.user;
- user = [self translateSingleQuote:user];
- NSString *loginSql = [NSString stringWithFormat:@"select sales_code from offline_login where username = '%@'",user];
- __block NSString *user_code = @"";
- [iSalesDB jk_query:loginSql completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
- char *code = (char *)sqlite3_column_text(stmt, 0);
- if (code == NULL) {
- code = "";
- }
-
- user_code = [NSString stringWithUTF8String:code];
-
- }];
-
- // 再取所有salesRep
- NSString *sql = [NSString stringWithFormat:@"select _id,name,code,salesrep_id from offline_salesrep;"];
- NSMutableDictionary *ret = [[iSalesDB jk_query:sql completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- // 1 name 2 code 3 salesrep_id
- char *name = (char *)sqlite3_column_text(stmt, 1);
- char *code = (char *)sqlite3_column_text(stmt, 2);
- int salesrep_id = sqlite3_column_int(stmt, 3);
-
- if (name == NULL) {
- name = "";
- }
- if (code == NULL) {
- code = "";
- }
-
-
- NSMutableDictionary *repDic = [NSMutableDictionary dictionary];
- [repDic setValue:[NSString stringWithFormat:@"%s - %s",code,name] forKey:@"value"];
- [repDic setValue:[NSNumber numberWithInt:salesrep_id] forKey:@"value_id"];
- // 比较code 相等则check
- if ([[NSString stringWithUTF8String:code] isEqualToString:user_code]) {
- [repDic setValue:[NSNumber numberWithInt:1] forKey:@"check"];
- }
-
- [container setValue:repDic forKey:[NSString stringWithFormat:@"val_%ld",(*count)++]];
-
- }] mutableCopy];
-
- [ret setValue:[NSNumber numberWithInt:ret.allKeys.count] forKey:@"count"];
-
- return ret;
- }
- + (NSDictionary *)offline_dealZipCode:(NSString *)zipcode {
-
- zipcode = [self translateSingleQuote:zipcode];
- NSString *sql = [NSString stringWithFormat:@"select country,state,city,country_code,state_code from offline_zipcode where zipcode = '%@';",zipcode];
-
- NSMutableDictionary *ret = [[iSalesDB jk_query:sql completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- char *country = (char *)sqlite3_column_text(stmt, 0);
- char *state = (char *)sqlite3_column_text(stmt, 1);
- char *city = (char *)sqlite3_column_text(stmt, 2);
- char *country_code = (char *)sqlite3_column_text(stmt, 3);
- char *state_code = (char *)sqlite3_column_text(stmt, 4);
-
- if (country == NULL) {
- country = "";
- }
- if (state == NULL) {
- state = "";
- }
- if (city == NULL) {
- city = "";
- }
- if (country_code == NULL) {
- country_code = "";
- }
- if (state_code == NULL) {
- state_code = "";
- }
-
-
-
- [container setValue:[NSString stringWithUTF8String:country] forKey:@"country"];
- [container setValue:[NSString stringWithUTF8String:state] forKey:@"state"];
- [container setValue:[NSString stringWithUTF8String:city] forKey:@"city"];
- [container setValue:[NSString stringWithUTF8String:country_code] forKey:@"country_code"];
- [container setValue:[NSString stringWithUTF8String:state_code] forKey:@"state_code"];
-
- }] mutableCopy];
-
- return ret;
- }
- + (void)setValue:(id)value forItemKey:(NSString *)itemKey valueKey:(NSString *)valueKey inDictionary:(NSMutableDictionary *)dic{
-
- NSMutableDictionary *item = [[dic objectForKey:itemKey] mutableCopy];
- [item setValue:value forKey:valueKey];
-
- [dic setValue:item forKey:itemKey];
- }
- + (NSString *)countryCodeByid:(NSString *)code_id {
-
- NSString *ret = nil;
- code_id = [self translateSingleQuote:code_id];
- sqlite3 *db = [iSalesDB get_db];
- NSString *sqlQuery = [NSString stringWithFormat:@"select code from offline_country where countrycode_id = %@",code_id];
- sqlite3_stmt * statement;
-
- if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK) {
- while (sqlite3_step(statement) == SQLITE_ROW) {
- char *code = (char *)sqlite3_column_text(statement, 0);
- if (code == NULL) {
- code = "";
- }
- ret = [NSString stringWithUTF8String:code];
- }
-
- sqlite3_finalize(statement);
- }
- [iSalesDB close_db:db];
-
- return ret;
-
- }
- + (NSString *)countryCodeIdByCode:(NSString *)code {
- NSString *ret = nil;
- code = [self translateSingleQuote:code];
- sqlite3 *db = [iSalesDB get_db];
- NSString *sqlQuery = [NSString stringWithFormat:@"select countrycode_id from offline_country where code = '%@';",code];
- sqlite3_stmt * statement;
-
- if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK) {
- while (sqlite3_step(statement) == SQLITE_ROW) {
- char *_id = (char *)sqlite3_column_text(statement, 0);
- if (_id == NULL) {
- _id = "";
- }
- ret = [NSString stringWithFormat:@"%s",_id];
- }
-
- sqlite3_finalize(statement);
- }
- [iSalesDB close_db:db];
-
- return ret;
- }
- + (NSString *)countryNameByCountryCodeId:(NSString *)codeId {
-
- NSString *name = nil;
- codeId = [self translateSingleQuote:codeId];
- sqlite3 *db = [iSalesDB get_db];
- NSString *sqlQuery = [NSString stringWithFormat:@"select name from offline_country where countrycode_id = %@",codeId];
- sqlite3_stmt * statement;
-
- if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK) {
- while (sqlite3_step(statement) == SQLITE_ROW) {
- char *value = (char *)sqlite3_column_text(statement, 0);
- if (value == NULL) {
- value = "";
- }
- name = [NSString stringWithUTF8String:value];
- }
-
- sqlite3_finalize(statement);
- }
- [iSalesDB close_db:db];
-
- return name;
- }
- + (NSString *)priceNameByPriceId:(NSString *)priceId {
-
- NSString *ret = nil;
- sqlite3 *db = [iSalesDB get_db];
- NSString *sqlQuery = [NSString stringWithFormat:@"select name from price where type = %@;",priceId];
- sqlite3_stmt * statement;
-
- if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK) {
- while (sqlite3_step(statement) == SQLITE_ROW) {
- char *name = (char *)sqlite3_column_text(statement, 0);
- if (name == NULL) {
- name = "";
- }
- ret = [NSString stringWithUTF8String:name];
- }
-
- sqlite3_finalize(statement);
- }
- [iSalesDB close_db:db];
-
- return ret;
- }
- + (NSString *)salesRepCodeById:(NSString *)_id {
-
- NSString *ret = nil;
- _id = [self translateSingleQuote:_id];
- sqlite3 *db = [iSalesDB get_db];
- NSString *sqlQuery = [NSString stringWithFormat:@"select code from offline_salesrep where salesrep_id = %@",_id];
- sqlite3_stmt * statement;
-
- if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK) {
- while (sqlite3_step(statement) == SQLITE_ROW) {
- char *rep = (char *)sqlite3_column_text(statement, 0);
- if (rep == NULL) {
- rep = "";
- }
- ret = [NSString stringWithUTF8String:rep];
- }
-
- sqlite3_finalize(statement);
- }
- [iSalesDB close_db:db];
-
-
- return ret;
- }
- + (NSString *)textAtColumn:(int)col statement:(sqlite3_stmt *)stmt{
- char *tx = (char *)sqlite3_column_text(stmt, col);
- if (tx == NULL) {
- tx = "";
- }
-
- NSString *text = [NSString stringWithFormat:@"%s",tx];
-
- if (!text) {
- text = @"";
- }
-
- // 将字符全部为' '的字符串干掉
- int spaceCount = 0;
- for (int i = 0; i < text.length; i++) {
- if ([text characterAtIndex:i] == ' ') {
- spaceCount++;
- }
- }
- if (spaceCount == text.length) {
- text = @"";
- }
-
- return text;
- }
- + (NSMutableDictionary *)dictionaryFileName:(NSString *)name {
- NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:nil];
- NSData *data = [NSData dataWithContentsOfFile:path];
- NSMutableDictionary *ret = [[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil] mutableCopy];
-
- return ret;
- }
- + (NSString *)textFileName:(NSString *)name {
- NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:nil];
- NSString *text = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
- if (!text) {
- text = @"";
- }
-
- return text;
- }
- + (NSMutableDictionary *)mutableDictionary:(NSString *)key inDictionary:(NSDictionary *)dic {
- return [[dic objectForKey:key] mutableCopy];
- }
- + (id)translateSingleQuote:(NSString *)string {
- if ([string isKindOfClass:[NSString class]])
- return [string stringByReplacingOccurrencesOfString:@"'" withString:@"''"];
- return string;
- }
- + (NSString *)valueInParams:(NSDictionary *)params key:(NSString *)key {
- return [params valueForKey:key] ? [params valueForKey:key] : @"";
- }
- + (NSString *)item_image:(NSString *)item_id db:(sqlite3 *)db {
-
- NSString* ret= nil;
-
- NSString *sqlQuery = nil;
- sqlQuery = [NSString stringWithFormat:@"select i.url from product m LEFT join model_image i on m.product_id = i.product_id where m.item_id=%@ order by i.default_img desc, i._id asc limit 1;",item_id];// select i.url from model m
-
- sqlite3_stmt * statement;
-
- // int count=0;
- if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
- {
-
-
- if (sqlite3_step(statement) == SQLITE_ROW)
- {
-
-
- char *imgurl = (char*)sqlite3_column_text(statement, 0);
- if(imgurl==nil)
- imgurl="";
- NSString *nsimgurl = [[NSString alloc]initWithUTF8String:imgurl];
-
-
- ret=nsimgurl;
-
-
- }
-
- sqlite3_finalize(statement);
- }
- else
- {
- [ret setValue:@"8" forKey:@"result"];
- }
-
-
-
- // [iSalesDB close_db:db];
- DebugLog(@"data string: %@",ret );
-
-
- return ret;
- }
- #pragma mark contact list
- +(NSDictionary*) offline_contactlist :(NSMutableDictionary *) params
- {
-
- // contactType = "Sales_Order_Customer";
- // limit = 25;
- // offset = 0;
- // password = 123456;
- // "price_name" = 16;
- // user = EvanK;
-
- sqlite3 *db = [iSalesDB get_db];
-
- NSString* contactType = [params valueForKey:@"contactType"]; // contactType = "Sales_Order_Customer";
- if (contactType) {
- contactType = [NSString stringWithFormat:@"%@ = 1",contactType];
- } else {
- contactType = @"1 = 1";
- }
-
- NSString* keyword = [params valueForKey:@"keyword"]; // search 时才有
- DebugLog(@"offline contact list keyword: %@",keyword);
-
- // advanced search
-
- NSString* contact_name = [params valueForKey:@"contact_name"]; // "contact_name"
- if (contact_name) {
- contact_name = [contact_name stringByReplacingOccurrencesOfString:@"'" withString:@"''"];
- contact_name = [NSString stringWithFormat:@"and lower(contact_name) like '%%%@%%'",contact_name.lowercaseString];
- } else {
- contact_name = @"";
- }
- NSString* customer_phone = [params valueForKey:@"customer_phone"]; // "customer_phone"
- if (customer_phone) {
- customer_phone = [customer_phone stringByReplacingOccurrencesOfString:@"'" withString:@"''"];
- customer_phone = [NSString stringWithFormat:@"and lower(decrypt(phone)) like '%%%@%%'",customer_phone.lowercaseString];
- } else {
- customer_phone = @"";
- }
- NSString* customer_fax = [params valueForKey:@"customer_fax"]; // "customer_fax"
- if (customer_fax) {
- customer_fax = [customer_fax stringByReplacingOccurrencesOfString:@"'" withString:@"''"];
- customer_fax = [NSString stringWithFormat:@"and lower(fax) like '%%%@%%'",customer_fax.lowercaseString];
- } else {
- customer_fax = @"";
- }
-
- NSString* customer_zipcode = [params valueForKey:@"customer_zipcode"]; // "customer_zipcode"
- if (customer_zipcode) {
- customer_zipcode = [customer_zipcode stringByReplacingOccurrencesOfString:@"'" withString:@"''"];
- customer_zipcode = [NSString stringWithFormat:@"and lower(zipcode) like '%%%@%%'",customer_zipcode.lowercaseString];
- } else {
- customer_zipcode = @"";
- }
- NSString* customer_sales_rep = [params valueForKey:@"customer_sales_rep"]; // "customer_sales_rep"
- if (customer_sales_rep) {
- customer_zipcode = [customer_zipcode stringByReplacingOccurrencesOfString:@"'" withString:@"''"];
- customer_sales_rep = [NSString stringWithFormat:@"and lower(sales_rep) like '%%%@%%'",customer_sales_rep.lowercaseString];
- } else {
- customer_sales_rep = @"";
- }
- NSString* customer_state = [params valueForKey:@"customer_state"]; // "customer_state"
- if (customer_state) {
- customer_state = [customer_state stringByReplacingOccurrencesOfString:@"'" withString:@"''"];
- customer_state = [NSString stringWithFormat:@"and lower(state) like '%%%@%%'",customer_state.lowercaseString];
- } else {
- customer_state = @"";
- }
- NSString* customer_name = [params valueForKey:@"customer_name"]; // "customer_name" 也就是company name
- if (customer_name) {
- customer_name = [customer_name stringByReplacingOccurrencesOfString:@"'" withString:@"''"];
- customer_name = [NSString stringWithFormat:@"and lower(decrypt(company_name)) like '%%%@%%'",customer_name.lowercaseString];
- } else {
- customer_name = @"";
- }
- NSString* customer_country = [params valueForKey:@"customer_country"]; // "customer_country"
- if (customer_country) {
- customer_country = [customer_country stringByReplacingOccurrencesOfString:@"'" withString:@"''"];
- customer_country = [NSString stringWithFormat:@"and lower(country) like '%%%@%%'",customer_country.lowercaseString];
- } else {
- customer_country = @"";
- }
- NSString* customer_cid = [params valueForKey:@"customer_cid"]; // "customer_cid"
- if (customer_cid) {
- customer_cid = [customer_cid stringByReplacingOccurrencesOfString:@"'" withString:@"''"];
- customer_cid = [NSString stringWithFormat:@"and lower(contact_id) like '%%%@%%'",customer_cid.lowercaseString];
- } else {
- customer_cid = @"";
- }
- NSString* customer_city = [params valueForKey:@"customer_city"]; // "customer_city"
- if (customer_city) {
- customer_city = [customer_city stringByReplacingOccurrencesOfString:@"'" withString:@"''"];
- customer_city = [NSString stringWithFormat:@"and lower(city) like '%%%@%%'",customer_city.lowercaseString];
- } else {
- customer_city = @"";
- }
- NSString* customer_address = [params valueForKey:@"customer_address"]; // "customer_address"
- if (customer_address) {
- customer_address = [customer_address stringByReplacingOccurrencesOfString:@"'" withString:@"''"];
- customer_address = [NSString stringWithFormat:@"and lower(decrypt(addr)) like '%%%@%%'",customer_address.lowercaseString];
- } else {
- customer_address = @"";
- }
- NSString* customer_email = [params valueForKey:@"customer_email"]; // "customer_email"
- if (customer_email) {
- customer_email = [customer_email stringByReplacingOccurrencesOfString:@"'" withString:@"''"];
- customer_email = [NSString stringWithFormat:@"and lower(email) like '%%%@%%'",customer_email.lowercaseString];
- } else {
- customer_email = @"";
- }
-
- NSString *price_name = [params valueForKey:@"price_name"];
- if (price_name) {
- if ([price_name containsString:@","]) {
-
- // 首先从 price表中查处name
- NSArray *pArray = [price_name componentsSeparatedByString:@","];
-
- NSMutableString *mutablePStr = [NSMutableString stringWithFormat:@"SELECT name FROM price where type = %@ ",pArray[0]];
-
- for (int i = 1;i < pArray.count;i++) {
- NSString *p = pArray[i];
- [mutablePStr appendFormat:@" or type = %@ ",p];
- }
- [mutablePStr appendString:@";"];
-
- __block NSMutableArray *price_name_array = [NSMutableArray array];
- [iSalesDB jk_query:mutablePStr db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
- char *name = (char *)sqlite3_column_text(stmt, 0);
- if (!name)
- name = "";
- [price_name_array addObject:[self translateSingleQuote:[NSString stringWithUTF8String:name]]];
-
- }];
-
- // 再根据name 拼sql
- NSMutableString *mutable_price_name = [NSMutableString string];
- [mutable_price_name appendFormat:@" and( price_type like '%%%@%%' ",price_name_array[0]];
- for (int i = 1; i < price_name_array.count; i++) {
- [mutable_price_name appendFormat:@" or price_type like '%%%@%%' ",price_name_array[i]];
- }
- [mutable_price_name appendString:@")"];
-
- price_name = mutable_price_name;
-
- } else {
- price_name = [price_name stringByReplacingOccurrencesOfString:@" " withString:@""];
- if ([price_name isEqualToString:@""]) {
- price_name = @"";
- } else {
-
- __block NSString *price;
- price_name = [self translateSingleQuote:price_name];
- [iSalesDB jk_query:[NSString stringWithFormat:@"SELECT name FROM price where type = %@ ;",price_name] db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
- char *p = (char *)sqlite3_column_text(stmt, 0);
- if (p == NULL) {
- p = "";
- }
- price = [NSString stringWithUTF8String:p];
- }];
-
- if ([price isEqualToString:@""]) {
- price_name = @"";
- } else {
- price = [self translateSingleQuote:price];
- price_name = [NSString stringWithFormat:@"and price_type like '%%%@%%'",price];
- }
-
- }
-
- }
-
- } else {
- price_name = @"";
- }
-
-
-
- int limit = [[params valueForKey:@"limit"] intValue];
- int offset = [[params valueForKey:@"offset"] intValue];
-
-
- NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
-
- NSString *where = [NSString stringWithFormat:@" %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ and is_active=1 ",contactType,contact_name,customer_phone,customer_fax,customer_zipcode,customer_sales_rep,customer_state,customer_name,customer_country,customer_cid,customer_city,customer_address,customer_email,price_name];
-
-
- NSString *sql = [NSString stringWithFormat:@"select editable,company_name,country,addr,zipcode,state,city,contact_name,phone,contact_id,addr_1,addr_2,addr_3,addr_4,first_name,last_name,fax,email from offline_contact where %@ order by decrypt(company_name) limit %d offset %d",where,limit,offset];
-
-
-
-
- // int result= [iSalesDB AddExFunction:db];
-
- int count =0;
-
-
-
- NSString *sqlQuery = nil;
-
- if(keyword.length==0)
- {
- // sqlQuery=[NSString stringWithFormat:@"select editable,company_name,country,addr,zipcode,state,city,contact_name,phone,contact_id,addr_1,addr_2,addr_3,addr_4,first_name,last_name,fax,email from offline_contact where %@=1 order by decrypt(company_name) limit %d offset %d",contactType , limit, offset];
- // count=[iSalesDB get_recordcount:db table:@"offline_contact" where:[NSString stringWithFormat:@"%@='1",contactType]];
-
- sqlQuery = sql;
-
- count = [iSalesDB get_recordcount:db table:@"offline_contact" where:where];
- }
- else
- {
- // NSString* encrypt_keyword= [AESCrypt fastencrypt:keyword];
-
- keyword = keyword.lowercaseString;
- keyword = [keyword stringByReplacingOccurrencesOfString:@"'" withString:@"''"];
-
- sqlQuery=[NSString stringWithFormat:@"select editable,company_name,country,addr,zipcode,state,city,contact_name,phone,contact_id,addr_1,addr_2,addr_3,addr_4,first_name,last_name,fax,email from offline_contact where %@ and (lower(contact_id ) like'%%%@%%' or lower(decrypt(company_name)) like '%%%@%%' or lower(decrypt(phone)) like '%%%@%%' or lower(decrypt(addr)) like '%%%@%%') and is_active=1 order by decrypt(company_name) limit %d offset %d",contactType , keyword,keyword,keyword,keyword,limit, offset];
-
- count=[iSalesDB get_recordcount:db table:@"offline_contact" where:[NSString stringWithFormat:@"%@=1 and (lower(contact_id ) like'%@' or lower(company_name) like'%@') and is_active=1",contactType,keyword,keyword]];
- }
-
-
-
- DebugLog(@"offline_contactlist sql:%@",sqlQuery);
- sqlite3_stmt * statement;
-
-
- [ret setValue:@"2" forKey:@"result"];
- [ret setValue:[NSNumber numberWithInt:count ] forKey:@"total"];
-
-
- if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
- {
-
- int i = 0;
- while (sqlite3_step(statement) == SQLITE_ROW)
- {
-
- [ret setValue:[NSNumber numberWithInt:AP_USER_AUTH ] forKey:@"result"];
-
- NSMutableDictionary* item = [[NSMutableDictionary alloc] init];
-
-
- int editable = sqlite3_column_int(statement, 0);
-
-
- char *company_name = (char*)sqlite3_column_text(statement, 1);
- NSString *nscompany_name =nil;
- if(company_name==nil)
- nscompany_name=@"";
- else
- nscompany_name= [[NSString alloc]initWithUTF8String:company_name] ;
-
-
- char *country = (char*)sqlite3_column_text(statement, 2);
- if(country==nil)
- country="";
- NSString *nscountry= [[NSString alloc]initWithUTF8String:country];
-
-
- // char *addr = (char*)sqlite3_column_text(statement, 3);
- // if(addr==nil)
- // addr="";
- // NSString *nsaddr= [[NSString alloc]initWithUTF8String:addr];
-
-
- char *zipcode = (char*)sqlite3_column_text(statement, 4);
- if(zipcode==nil)
- zipcode="";
- NSString *nszipcode= [[NSString alloc]initWithUTF8String:zipcode];
-
-
- char *state = (char*)sqlite3_column_text(statement, 5);
- if(state==nil)
- state="";
- NSString *nsstate= [[NSString alloc]initWithUTF8String:state];
-
- char *city = (char*)sqlite3_column_text(statement, 6);
- if(city==nil)
- city="";
- NSString *nscity= [[NSString alloc]initWithUTF8String:city];
-
- // char *contact_name = (char*)sqlite3_column_text(statement, 7);
- // NSString *nscontact_name = nil;
- // if(contact_name==nil)
- // nscontact_name=@"";
- // else
- // nscontact_name= [[NSString alloc]initWithUTF8String:contact_name];
-
- char *phone = (char*)sqlite3_column_text(statement, 8);
- NSString *nsphone = nil;
- if(phone==nil)
- nsphone=@"";
- else
- nsphone= [[NSString alloc]initWithUTF8String:phone];
-
-
- char *contact_id = (char*)sqlite3_column_text(statement, 9);
- if(contact_id==nil)
- contact_id="";
- NSString *nscontact_id= [[NSString alloc]initWithUTF8String:contact_id];
-
- char *addr_1 = (char*)sqlite3_column_text(statement, 10);
- if(addr_1==nil)
- addr_1="";
- NSString *nsaddr_1= [[NSString alloc]initWithUTF8String:addr_1];
-
- char *addr_2 = (char*)sqlite3_column_text(statement, 11);
- if(addr_2==nil)
- addr_2="";
- NSString *nsaddr_2= [[NSString alloc]initWithUTF8String:addr_2];
-
-
- char *addr_3 = (char*)sqlite3_column_text(statement, 12);
- if(addr_3==nil)
- addr_3="";
- NSString *nsaddr_3= [[NSString alloc]initWithUTF8String:addr_3];
-
-
- char *addr_4 = (char*)sqlite3_column_text(statement, 13);
- if(addr_4==nil)
- addr_4="";
- NSString *nsaddr_4= [[NSString alloc]initWithUTF8String:addr_4];
-
-
- char *first_name = (char*)sqlite3_column_text(statement, 14);
- if(first_name==nil)
- first_name="";
- NSString *nsfirst_name= [[NSString alloc]initWithUTF8String:first_name];
-
-
- char *last_name = (char*)sqlite3_column_text(statement, 15);
- if(last_name==nil)
- last_name="";
- NSString *nslast_name= [[NSString alloc]initWithUTF8String:last_name];
-
- char *fax = (char*)sqlite3_column_text(statement, 16);
- NSString *nsfax = nil;
- if(fax==nil)
- nsfax=@"";
- else
- {
- nsfax= [[NSString alloc]initWithUTF8String:fax];
- if(nsfax.length>0)
- nsfax= [NSString stringWithFormat:@"FAX:%@",nsfax];
- }
-
- char *email = (char*)sqlite3_column_text(statement, 17);
- NSString *nsemail = nil;
- if(email==nil)
- nsemail=@"";
- else
- {
- nsemail= [[NSString alloc]initWithUTF8String:email];
- if(nsemail.length>0)
- nsemail= [NSString stringWithFormat:@"EMAIL:%@",nsemail];
-
- // nsemail= [NSString stringWithFormat:@"EMAIL:%@",[[NSString alloc]initWithUTF8String:email]];
- }
-
-
-
-
- NSMutableArray* arr_name= [[NSMutableArray alloc] init];
-
- [arr_name addObject:nsfirst_name];
- [arr_name addObject:nslast_name];
-
- NSString *nscontact_name=[RAUtils arr2string:arr_name separator:@" " trim:true];
-
- NSMutableArray* arr_addr = [[NSMutableArray alloc] init];
-
- {
- // decrypt
-
- nscompany_name=[AESCrypt fastdecrypt:nscompany_name];
-
- nscompany_name=[NSString stringWithFormat:@"<b>%@</b>",nscompany_name];
-
- nsphone=[AESCrypt fastdecrypt:nsphone];
- nsphone=[NSString stringWithFormat:@"TEL:%@",nsphone];
-
- nsaddr_1=[AESCrypt fastdecrypt:nsaddr_1];
- // nsaddr_1=[NSString stringWithFormat:@"TEL:%@",nsphone];
-
- }
-
-
- [arr_addr addObject:nscompany_name];
- [arr_addr addObject:nscontact_name];
- [arr_addr addObject:@"<br>"];
-
- [arr_addr addObject:nsaddr_1];
- [arr_addr addObject:nsaddr_2];
- [arr_addr addObject:nsaddr_3];
- [arr_addr addObject:nsaddr_4];
- //[arr_addr addObject:nsaddr];
- [arr_addr addObject:nszipcode];
- [arr_addr addObject:nscity];
- [arr_addr addObject:nsstate];
- [arr_addr addObject:nscountry];
- [arr_addr addObject:@"<br>"];
- [arr_addr addObject:nsphone];
- [arr_addr addObject:nsfax];
- [arr_addr addObject:nsemail];
-
- NSString * name = [RAUtils arr2string:arr_addr separator:@", " trim:true];
-
- name=[name stringByReplacingOccurrencesOfString:@", <br>," withString:@"<br>"];
-
-
- [item setValue:name forKey:@"name"];
- [item setValue:nscontact_id forKey:@"contact_id"];
- [item setValue:editable==1?@"true":@"false" forKey:@"can_update"];
- [ret setObject:item forKey:[NSString stringWithFormat:@"item_%d",i]];
- i++;
-
-
-
- }
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- [ret setValue:appDelegate.mode forKey:@"mode"];
- [ret setValue:[NSNumber numberWithInt:i ] forKey:@"count"];
-
-
-
- sqlite3_finalize(statement);
- }
-
-
-
- [iSalesDB close_db:db];
-
-
-
-
- DebugLog(@"data string: %@",[RAUtils dict2string:ret] );
-
- return ret;
- }
- #pragma mark contact Advanced search
- +(NSData *) offline_contactAdvancedSearch:(NSMutableDictionary *) params
- {
- NSMutableDictionary *contactAdvanceDic = [self dictionaryFileName:@"contactAdvanceSearch.json"];
- return [RAUtils dict2data:contactAdvanceDic];
- }
- #pragma mark create new contact
- + (NSData *)offline_createContact:(NSMutableDictionary *)params {
-
-
- NSString *path = [[NSBundle mainBundle] pathForResource:@"createContact.json" ofType:nil];
- NSData *data = [NSData dataWithContentsOfFile:path];
- NSMutableDictionary *ret = [[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil] mutableCopy];
-
- NSMutableDictionary *section_0 = [[ret objectForKey:@"section_0"] mutableCopy];
-
-
- NSString *countryCode = nil;
- NSString *countryCode_id = nil;
- NSString *stateCode = nil;
- NSString *city = nil;
- NSString *zipCode = nil;
-
- if ([params.allKeys containsObject:@"refresh_trigger"]) {
-
- if([params[@"refresh_trigger"] isEqualToString:@"country"]) { // choose country
-
- NSString *code_id = params[@"country"];
- countryCode_id = code_id;
- countryCode = [self countryCodeByid:code_id];
-
- } else if ([params[@"refresh_trigger"] isEqualToString:@"zipcode"]) { // zipcode
-
- NSString *zip_code = params[@"zipcode"];
-
-
- // 剔除全部为空格
- int spaceCount = 0;
- for (int i = 0; i < zip_code.length; i++) {
- if ([zip_code characterAtIndex:i] == ' ') {
- spaceCount++;
- }
- }
- if (spaceCount == zip_code.length) {
- zip_code = @"";
- }
- zipCode = zip_code;
-
- if (zipCode.length > 0) {
- countryCode_id = params[@"country"];
-
- NSDictionary *dic = [self offline_dealZipCode:zip_code];
-
- countryCode = [dic valueForKey:@"country_code"];
- if (!countryCode) {
- countryCode = @"US";
- }
-
- stateCode = [dic valueForKey:@"state_code"];
-
-
- city = [dic valueForKey:@"city"];
-
- // zip code
- NSMutableDictionary *zipDic = [[section_0 valueForKey:@"item_10"] mutableCopy];
- [zipDic setValue:zipCode forKey:@"value"];
- [section_0 setValue:zipDic forKey:@"item_10"];
- }
- }
-
- } else {
- // default: US United States
- countryCode = @"US";
- countryCode_id = @"228";
- }
-
- // country
- NSDictionary *allCountry = [self offline_getAllCountryDefault:countryCode];
- [self setValue:allCountry forItemKey:@"item_5" valueKey:@"cadedate" inDictionary:section_0];
-
- // state
- NSDictionary *allState = [self offline_getStateByCountryCode:countryCode checkedState:stateCode];
- // NSDictionary *allState = [self offline_getStateByCountryCodeId:countryCode_id checkedState:stateCode];
- [self setValue:allState forItemKey:@"item_11" valueKey:@"cadedate" inDictionary:section_0];
-
- // city
- if (city) {
- NSMutableDictionary *cityDic = [[section_0 valueForKey:@"item_12"] mutableCopy];
- [cityDic setValue:city forKey:@"value"];
-
- [section_0 setValue:cityDic forKey:@"item_12"];
- }
-
- // price type
- NSDictionary *priceDic = [self offline_getPrice];
- [self setValue:priceDic forItemKey:@"item_2" valueKey:@"cadedate" inDictionary:section_0];
-
- // Sales Rep
- NSDictionary *repDic = [self offline_getSalesRep];
- [self setValue:repDic forItemKey:@"item_17" valueKey:@"cadedate" inDictionary:section_0];
-
- [ret setValue:section_0 forKey:@"section_0"];
-
- return [RAUtils dict2data:ret];
- }
- #pragma mark save
- + (NSData *)offline_saveContact:(NSDictionary *)params update:(BOOL)update isCustomer:(BOOL)isCustomer{
-
- NSString *addr = nil;
- NSString *contact_name = nil;
-
- NSString *companyName = [params objectForKey:@"company"];
- if (companyName) {
- companyName = [AESCrypt fastencrypt:companyName];
- } else {
- companyName = @"";
- }
- DebugLog(@"company");
- companyName = [self translateSingleQuote:companyName];
-
- NSString *addr1 = [params objectForKey:@"address"];
-
-
- NSString *addr2 = [params objectForKey:@"address2"];
-
-
- NSString *addr3 = [params objectForKey:@"address_3"];
-
-
- NSString *addr4 = [params objectForKey:@"address_4"];
-
- if (!addr2) {
- addr2 = @"";
- }
- if (!addr3) {
- addr3 = @"";
- }
- if (!addr4) {
- addr4 = @"";
- }
- if (!addr1) {
- addr1 = @"";
- }
- DebugLog(@"addr");
- addr = [RAUtils arr2string:@[addr1,addr2,addr3,addr4] separator:@" " trim:true];
- addr = [AESCrypt fastencrypt:addr];
- addr = [self translateSingleQuote:addr];
-
- if (addr1 && ![addr1 isEqualToString:@""]) {
- addr1 = [AESCrypt fastencrypt:addr1];
- }
- addr1 = [self translateSingleQuote:addr1];
- addr2 = [self translateSingleQuote:addr2];
- addr3 = [self translateSingleQuote:addr3];
- addr4 = [self translateSingleQuote:addr4];
-
-
- NSString *country = [params objectForKey:@"country"];
- if (country) {
- country = [self countryNameByCountryCodeId:country];
- } else {
- country = @"";
- }
- DebugLog(@"country");
- country = [self translateSingleQuote:country];
-
- NSString *state = [params objectForKey:@"state"];
- if (!state) {
- state = @"";
- }
- DebugLog(@"state");
- state = [self translateSingleQuote:state];
-
- NSString *city = [params objectForKey:@"city"];
- if (!city) {
- city = @"";
- }
- city = [self translateSingleQuote:city];
-
- NSString *zipcode = [params objectForKey:@"zipcode"];
- if (!zipcode) {
- zipcode = @"";
- }
- DebugLog(@"zip");
- zipcode = [self translateSingleQuote:zipcode];
-
- NSString *fistName = [params objectForKey:@"firstname"];
- if (!fistName) {
- fistName = @"";
- }
-
-
- NSString *lastName = [params objectForKey:@"lastname"];
- if (!lastName) {
- lastName = @"";
- }
-
- contact_name = [RAUtils arr2string:@[fistName,lastName] separator:@" " trim:true];
- DebugLog(@"contact_name");
- contact_name = [self translateSingleQuote:contact_name];
-
- fistName = [self translateSingleQuote:fistName];
-
-
- lastName = [self translateSingleQuote:lastName];
-
- NSString *phone = [params objectForKey:@"phone"];
- if (phone) {
- phone = [AESCrypt fastencrypt:phone];
- } else {
- phone = @"";
- }
- DebugLog(@"PHONE");
- phone = [self translateSingleQuote:phone];
-
- NSString *fax = [params objectForKey:@"fax"];
- if (!fax) {
- fax = @"";
- }
- DebugLog(@"FAX");
- fax = [self translateSingleQuote:fax];
-
- NSString *email = [params objectForKey:@"email"];
- if (!email) {
- email = @"";
- }
- DebugLog(@"EMAIL:%@",email);
- email = [self translateSingleQuote:email];
-
- NSString *notes = [params objectForKey:@"contact_notes"];
- if (!notes) {
- notes = @"";
- }
- DebugLog(@"NOTE:%@",notes);
- notes = [self translateSingleQuote:notes];
-
- NSString *price = [params objectForKey:@"price_name"];
- if (price) {
- price = [self priceNameByPriceId:price];
- } else {
- price = @"";
- }
- DebugLog(@"PRICE");
- price = [self translateSingleQuote:price];
-
- NSString *salesRep = [params objectForKey:@"sales_rep"];
- if (salesRep) {
- salesRep = [self salesRepCodeById:salesRep];
- } else {
- salesRep = @"";
- }
- salesRep = [self translateSingleQuote:salesRep];
-
- NSString *img = [params objectForKey:@"business_card"];
- NSArray *array = [img componentsSeparatedByString:@","];
- NSString *img_0 = array[0];
- if (!img_0) {
- img_0 = @"";
- }
- img_0 = [self translateSingleQuote:img_0];
-
- NSString *img_1 = array[1];
- if (!img_1) {
- img_1 = @"";
- }
- img_1 = [self translateSingleQuote:img_1];
-
- NSString *img_2 = array[2];
- if (!img_2) {
- img_2 = @"";
- }
- img_2 = [self translateSingleQuote:img_2];
-
- NSString *contact_id = [NSUUID UUID].UUIDString;
-
- // 判断更新时是否为customer
- if (update) {
- contact_id = [params objectForKey:@"contact_id"];
- if (!contact_id) {
- contact_id = @"";
- }
- NSString *checkCustomerSql = [NSString stringWithFormat:@"select Sales_Order_Customer from offline_contact where contact_id = '%@';",contact_id];
-
- __block int customer = 0;
- [iSalesDB jk_query:checkCustomerSql completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
- customer = sqlite3_column_int(stmt, 0);
- }];
- isCustomer = customer ? YES : NO;
- }
-
- NSMutableDictionary *sync_dic = [params mutableCopy];
- if (isCustomer) {
- [sync_dic setValue:@"Sales_Order_Customer" forKey:@"contactType"];
- } else {
- [sync_dic setValue:@"Sales_Order_Ship_To" forKey:@"contactType"];
- }
-
- NSString *sync_data = nil;
-
- NSString *sql = nil;
- if (update){
- contact_id = [params objectForKey:@"contact_id"];
- if (!contact_id) {
- contact_id = @"";
- }
-
-
- [sync_dic setValue:contact_id forKey:@"contact_id"];
- // sync_data = [AESCrypt fastencrypt:[RAUtils dict2string:sync_dic]];
- sync_data = [RAUtils dict2string:sync_dic];
- sync_data = [self translateSingleQuote:sync_data];
-
- sql = [NSString stringWithFormat:@"update offline_contact set company_name = '%@',addr_1 = '%@',addr_2 = '%@',addr_3 = '%@',addr_4 = '%@',country = '%@',state = '%@',city = '%@',zipcode = '%@',first_name = '%@',last_name = '%@',phone = '%@',fax = '%@',email = '%@',notes = '%@',price_type = '%@',sales_rep = '%@',img_0 = '%@',img_1 = '%@',img_2 = '%@',sync_data = '%@',contact_name = '%@',addr = '%@' where contact_id = '%@';",companyName,addr1,addr2,addr3,addr4,country,state,city,zipcode,fistName,lastName,phone,fax,email,notes,price,salesRep,img_0,img_1,img_2,sync_data,contact_name,addr,contact_id];
- } else {
-
- contact_id = [self translateSingleQuote:contact_id];
-
- [sync_dic setValue:contact_id forKey:@"contact_id"];
- // sync_data = [AESCrypt fastencrypt:[RAUtils dict2string:sync_dic]];
- sync_data = [RAUtils dict2string:sync_dic];
- sync_data = [self translateSingleQuote:sync_data];
-
- sql = [NSString stringWithFormat:@"insert into offline_contact (is_active,company_name,addr_1,addr_2,addr_3,addr_4,country,state,city,zipcode,first_name,last_name,phone,fax,email,notes,price_type,sales_rep,img_0,img_1,img_2,editable,contact_id,Sales_Order_Customer,Sales_Order_Freight_Bill_To,Sales_Order_Ship_From,Sales_Order_Merchandise_Bill_To,Contact_Return_To,Sales_Order_Ship_To,sync_data,contact_name,addr) values (1,'%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@',1,'%@',%d,%d,0,%d,0,1,'%@','%@','%@')",companyName,addr1,addr2,addr3,addr4,country,state,city,zipcode,fistName,lastName,phone,fax,email,notes,price,salesRep,img_0,img_1,img_2,contact_id,isCustomer ? 1 : 0,isCustomer ? 1 : 0,isCustomer ? 1 : 0,sync_data,contact_name,addr];
- }
-
- int result = [iSalesDB execSql:sql];
-
- // NSString *retStr = [NSString stringWithFormat:@"{\"result\":%d,\"min_ver\":\"160409\",\"mode\":\"Regular Mode\"}",result];
- NSString *retStr = [NSString stringWithFormat:@"{\"result\":%d,\"mode\":\"Regular Mode\"}",result];
-
- return [retStr dataUsingEncoding:NSUTF8StringEncoding];
- }
- #pragma mark save new contact
- +(NSData *) offline_saveNewContact:(NSMutableDictionary *) params
- {
- return [self offline_saveContact:params update:NO isCustomer:YES];
- }
- #pragma mark edit contact
- +(NSData *) offline_editContact:(NSMutableDictionary *) params
- {
- // {
- // "contact_id" = "CE0D2445-3C1F-40EC-B94C-A39A6900FBDA";
- // password = 123456;
- // user = EvanK;
- // }
-
- NSString *path = [[NSBundle mainBundle] pathForResource:@"editContact.json" ofType:nil];
- NSData *data = [NSData dataWithContentsOfFile:path];
- NSMutableDictionary *ret = [[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil] mutableCopy];
-
- NSMutableDictionary *section_0 = [[ret objectForKey:@"section_0"] mutableCopy];
-
- NSString *countryCode = nil;
- NSString *countryCode_id = nil;
- NSString *stateCode = nil;
-
- /*------contact infor------*/
- __block NSString *country = nil;
- __block NSString *company_name = nil;
- __block NSString *contact_id = params[@"contact_id"];
-
- __block NSString *addr_1,*addr_2,*addr_3,*addr_4;
- __block NSString *zipcode = nil;
- __block NSString *state = nil; // state_code
- __block NSString *city = nil; //
- __block NSString *firt_name,*last_name;
- __block NSString *phone,*fax,*email;
- __block NSString *notes,*price_type,*sales_rep;
- __block NSString *img_0,*img_1,*img_2;
-
- contact_id = [self translateSingleQuote:contact_id];
- NSString *sql = [NSString stringWithFormat:@"select country,company_name,addr_1,addr_2,addr_3,addr_4,zipcode,state,city,first_name,last_name,phone,fax,email,notes,price_type,sales_rep,img_0,img_1,img_2 from offline_contact where contact_id = '%@';",contact_id];
-
- [iSalesDB jk_query:sql completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- country = [self textAtColumn:0 statement:stmt]; // country name
- company_name = [self textAtColumn:1 statement:stmt];
- addr_1 = [self textAtColumn:2 statement:stmt];
- addr_2 = [self textAtColumn:3 statement:stmt];
- addr_3 = [self textAtColumn:4 statement:stmt];
- addr_4 = [self textAtColumn:5 statement:stmt];
- zipcode = [self textAtColumn:6 statement:stmt];
- state = [self textAtColumn:7 statement:stmt]; // state code
- city = [self textAtColumn:8 statement:stmt];
- firt_name = [self textAtColumn:9 statement:stmt];
- last_name = [self textAtColumn:10 statement:stmt];
- phone = [self textAtColumn:11 statement:stmt];
- fax = [self textAtColumn:12 statement:stmt];
- email = [self textAtColumn:13 statement:stmt];
- notes = [self textAtColumn:14 statement:stmt];
- price_type = [self textAtColumn:15 statement:stmt]; // name
- sales_rep = [self textAtColumn:16 statement:stmt]; // code
- img_0 = [self textAtColumn:17 statement:stmt];
- img_1 = [self textAtColumn:18 statement:stmt];
- img_2 = [self textAtColumn:19 statement:stmt];
-
- }];
-
- // decrypt
- if (company_name) {
- company_name = [AESCrypt fastdecrypt:company_name];
- }
- if (addr_1) {
- addr_1 = [AESCrypt fastdecrypt:addr_1];
- }
- if (phone) {
- phone = [AESCrypt fastdecrypt:phone];
- }
-
- NSString *countrySql = [NSString stringWithFormat:@"select code from offline_country where name = '%@';",[self translateSingleQuote:country]];
- countryCode = [iSalesDB jk_queryText:countrySql];
-
- stateCode = state;
-
- if ([params.allKeys containsObject:@"refresh_trigger"]) {
-
- if ([params[@"refresh_trigger"] isEqualToString:@"country"]) {
-
- NSString *code_id = params[@"country"];
- countryCode_id = code_id;
- countryCode = [self countryCodeByid:code_id];
-
- } else if ([params[@"refresh_trigger"] isEqualToString:@"zipcode"]) {
-
- NSString *zip_code = params[@"zipcode"];
- // 剔除全部为空格
- int spaceCount = 0;
- for (int i = 0; i < zip_code.length; i++) {
- if ([zip_code characterAtIndex:i] == ' ') {
- spaceCount++;
- }
- }
- if (spaceCount == zip_code.length) {
- zip_code = @"";
- }
-
- if (zipcode.length > 0) {
- zipcode = zip_code;
-
- countryCode_id = params[@"country"];
-
- NSDictionary *dic = [self offline_dealZipCode:zip_code];
-
- countryCode = [dic valueForKey:@"country_code"];
-
- stateCode = [dic valueForKey:@"state_code"];
-
- city = [dic valueForKey:@"city"];
-
- // zip code
- NSMutableDictionary *zipDic = [[section_0 valueForKey:@"item_8"] mutableCopy];
- [zipDic setValue:zipcode forKey:@"value"];
- [section_0 setValue:zipDic forKey:@"item_8"];
- }
-
- }
-
- }
-
- // 0 Country
- // 1 Company Name
- // 2 Contact ID
- // 3 Picture
- // 4 Address 1
- // 5 Address 2
- // 6 Address 3
- // 7 Address 4
- // 8 Zip Code
- // 9 State/Province
- // 10 City
- // 11 Contact First Name
- // 12 Contact Last Name
- // 13 Phone
- // 14 Fax
- // 15 Email
- // 16 Contact Notes
- // 17 Price Type
- // 18 Sales Rep
-
- // country
- NSDictionary *allCountry = [self offline_getAllCountryDefault:countryCode];
- [self setValue:allCountry forItemKey:@"item_0" valueKey:@"cadedate" inDictionary:section_0];
-
- // company
- [self setValue:company_name forItemKey:@"item_1" valueKey:@"value" inDictionary:section_0];
-
- // contact_id
- [self setValue:contact_id forItemKey:@"item_2" valueKey:@"value" inDictionary:section_0];
-
- // picture
- NSString *img_avalue = [NSString stringWithFormat:@"%@,%@,%@",img_0,img_1,img_2];
- [self setValue:img_avalue forItemKey:@"item_3" valueKey:@"avalue" inDictionary:section_0];
- [self setValue:img_0 forItemKey:@"item_3" valueKey:@"img_url_aname_0" inDictionary:section_0];
- [self setValue:img_1 forItemKey:@"item_3" valueKey:@"img_url_aname_1" inDictionary:section_0];
- [self setValue:img_2 forItemKey:@"item_3" valueKey:@"img_url_aname_2" inDictionary:section_0];
- [self setValue:img_0 forItemKey:@"item_3" valueKey:@"img_url_0" inDictionary:section_0];
- [self setValue:img_1 forItemKey:@"item_3" valueKey:@"img_url_1" inDictionary:section_0];
- [self setValue:img_2 forItemKey:@"item_3" valueKey:@"img_url_2" inDictionary:section_0];
-
- // addr 1 2 3 4
- [self setValue:addr_1 forItemKey:@"item_4" valueKey:@"value" inDictionary:section_0];
- [self setValue:addr_2 forItemKey:@"item_5" valueKey:@"value" inDictionary:section_0];
- [self setValue:addr_3 forItemKey:@"item_6" valueKey:@"value" inDictionary:section_0];
- [self setValue:addr_4 forItemKey:@"item_7" valueKey:@"value" inDictionary:section_0];
-
- // zip code
- [self setValue:zipcode forItemKey:@"item_8" valueKey:@"value" inDictionary:section_0];
-
- // state
- NSDictionary *allState = [self offline_getStateByCountryCode:countryCode checkedState:stateCode];
- [self setValue:allState forItemKey:@"item_9" valueKey:@"cadedate" inDictionary:section_0];
-
- // city
- [self setValue:city forItemKey:@"item_10" valueKey:@"value" inDictionary:section_0];
-
- // first last
- [self setValue:firt_name forItemKey:@"item_11" valueKey:@"value" inDictionary:section_0];
- [self setValue:last_name forItemKey:@"item_12" valueKey:@"value" inDictionary:section_0];
-
- // phone fax email
- [self setValue:phone forItemKey:@"item_13" valueKey:@"value" inDictionary:section_0];
- [self setValue:fax forItemKey:@"item_14" valueKey:@"value" inDictionary:section_0];
- [self setValue:email forItemKey:@"item_15" valueKey:@"value" inDictionary:section_0];
-
- // notes
- [self setValue:notes forItemKey:@"item_16" valueKey:@"value" inDictionary:section_0];
-
- // price
- NSMutableDictionary *priceDic = [[self offline_getPrice] mutableCopy];
- for (NSString *key in priceDic.allKeys) {
-
- if ([key containsString:@"val_"]) {
- NSMutableDictionary *dic = [priceDic[key] mutableCopy];
- if ([dic[@"value"] isEqualToString:price_type]) {
- [dic setValue:[NSNumber numberWithInteger:1] forKey:@"check"];
- [priceDic setValue:dic forKey:key];
- }
- }
-
- }
- [self setValue:priceDic forItemKey:@"item_17" valueKey:@"cadedate" inDictionary:section_0];
-
- // Sales Rep
- NSMutableDictionary *repDic = [[self offline_getSalesRep] mutableCopy];
- for (NSString *key in repDic.allKeys) {
- if ([key containsString:@"val_"]) {
- NSMutableDictionary *dic = [repDic[key] mutableCopy];
- NSString *value = dic[@"value"];
- NSString *code = [[[value componentsSeparatedByString:@"-"] firstObject] stringByReplacingOccurrencesOfString:@" " withString:@""];
- if (code && [code isEqualToString:sales_rep]) {
- [dic setValue:[NSNumber numberWithInteger:1] forKey:@"check"];
- [repDic setValue:dic forKey:key];
- }
- }
- }
- [self setValue:repDic forItemKey:@"item_18" valueKey:@"cadedate" inDictionary:section_0];
-
- [ret setValue:section_0 forKey:@"section_0"];
-
- return [RAUtils dict2data:ret];
- }
- #pragma mark save contact
- +(NSData *) offline_saveContact:(NSMutableDictionary *) params
- {
- return [self offline_saveContact:params update:YES isCustomer:YES];
- }
- #pragma mark category
- + (void)check:(NSString *)ck valueKey:(NSString *)valueKey inDictionary:(NSMutableDictionary *)dic{
- if (ck) {
- NSMutableDictionary *res = [self mutableDictionary:valueKey inDictionary:dic];
- for (NSString *key in res.allKeys) {
- if (![key isEqualToString:@"count"]) {
- NSMutableDictionary *val = [self mutableDictionary:key inDictionary:res];
- [val setValue:[NSNumber numberWithInteger:0] forKey:@"check"];
- if ([val[@"value"] isEqualToString:ck]) {
- [val setValue:[NSNumber numberWithInteger:1] forKey:@"check"];
- }
- [res setValue:val forKey:key];
- }
- }
- [dic setValue:res forKey:valueKey];
- }
- }
- +(NSDictionary*) offline_category :(NSMutableDictionary *) params
- {
- // NSString* orderCode = [params valueForKey:@"orderCode"];
-
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
-
- NSString* category = [params valueForKey:@"category"];
- if (!category || [category isEqualToString:@""]) {
- category = @"%";
- }
- category = [self translateSingleQuote:category];
-
- int limit = [[params valueForKey:@"limit"] intValue];
- int offset = [[params valueForKey:@"offset"] intValue];
-
- // NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
-
-
- NSMutableDictionary *ret = [self dictionaryFileName:@"category.json"];
- NSMutableDictionary *filter = [[ret objectForKey:@"filter"] mutableCopy];
-
-
- sqlite3 *db = [iSalesDB get_db];
- // [iSalesDB AddExFunction:db];
-
- int count;
- NSString *where = [NSString stringWithFormat:@"category like'%%#%@#%%' and is_active = 1",category];
-
- NSString *sqlQuery = [NSString stringWithFormat:@"select m.name,m.description,m.product_id,w._id,m.closeout from product m left join wishlist w on m.product_id=w.product_id where m.category like'%%#%@#%%' and m.is_active = 1 order by m.name limit %d offset %d ;",category,limit, offset];
-
- // {
- // alert = SP;
- // available = "Available Now";
- // bestseller = No;
- // category = 001;
- // "custom_id" = 0;
- // limit = 20;
- // offset = 0;
- // password = 123456;
- // price = "Display All";
- // "price_template" = 0;
- // "sold_by_qty" = "Display All";
- // "sort_by" = 0;
- // user = EvanK;
- // }
- double price_min = 0;
- double price_max = 0;
- if ([params.allKeys containsObject:@"alert"]) {
- // alert
- [self check:params[@"alert"] valueKey:@"alert" inDictionary:filter];
- NSString *alert = params[@"alert"];
- if ([alert isEqualToString:@"Display All"]) {
- alert = [NSString stringWithFormat:@""];
- } else {
- alert = [self translateSingleQuote:alert];
- alert = [NSString stringWithFormat:@"and alert = '%@'",alert];
- }
-
- // available
- [self check:params[@"available"] valueKey:@"availability" inDictionary:filter];
- NSString *available = params[@"available"];
- NSString *available_condition;
- if ([available isEqualToString:@"Display All"]) {
- available_condition = @"";
- } else if ([available isEqualToString:@"Available Now"]) {
- available_condition = @"and availability > 0";
- } else {
- available_condition = @"and availability == 0";
- }
-
- // best seller
- [self check:params[@"bestseller"] valueKey:@"best_seller" inDictionary:filter];
- NSString *best_seller = @"";
- NSString *order_best_seller = @"m.name asc";
- if ([params[@"bestseller"] isEqualToString:@"Yes"]) {
- best_seller = @"and best_seller > 0";
- order_best_seller = @"m.best_seller desc,m.name asc";
- }
-
- // price
- [self check:params[@"price"] valueKey:@"price" inDictionary:filter];
- NSString *price = params[@"price"];
- price_min = 0;
- price_max = MAXFLOAT;
- if (appDelegate.user) {
- NSArray *priceTypeArray = [self get_contact_default_price_type:nil db:db];
- NSMutableString *priceName = [NSMutableString string];
- for (int i = 0; i < priceTypeArray.count; i++) {
- NSString *pricetype = priceTypeArray[i];
- pricetype = [self translateSingleQuote:pricetype];
- if (i == 0) {
- [priceName appendFormat:@"'%@'",pricetype];
- } else {
- [priceName appendFormat:@",'%@'",pricetype];
- }
- }
-
- if ([price isEqualToString:@"Display All"]) {
- price = [NSString stringWithFormat:@""];
- } else if([price containsString:@"+"]){
- price = [price stringByReplacingOccurrencesOfString:@"+" withString:@""];
- price_min = [price doubleValue];
- price = [NSString stringWithFormat:@"and item_id in (select DISTINCT item_id from model_price where price_name in (%@) and cast(decrypt(price) as double) >= %.2lf and cast(decrypt(price) as double) <= %.2lf)",priceName,price_min,price_max];
- } else {
- NSArray *priceArray = [price componentsSeparatedByString:@"-"];
- price_min = [[priceArray objectAtIndex:0] doubleValue];
- price_max = [[priceArray objectAtIndex:1] doubleValue];
- price = [NSString stringWithFormat:@"and item_id in (select DISTINCT item_id from model_price where price_name in (%@) and cast(decrypt(price) as double) >= %.2lf and cast(decrypt(price) as double) <= %.2lf)",priceName,price_min,price_max];
- }
- } else {
- price = @"";
- }
-
- // sold_by_qty : Sold in quantities of %@
- [self check:params[@"sold_by_qty"] valueKey:@"qty" inDictionary:filter];
- NSString *qty = params[@"sold_by_qty"];
- if ([qty isEqualToString:@"Display All"]) {
- qty = @"";
- } else {
- qty = [self translateSingleQuote:qty];
- qty = [NSString stringWithFormat:@"and model_set = 'Sold in quantities of %@'",qty];
- }
-
- // cate
- category = [self translateSingleQuote:category];
- NSString *cateWhere = [NSString stringWithFormat:@"category like'%%#%@#%%'",category];
-
- // where bestseller > 0 order by bestseller desc
- // sql query: alert availability(int) best_seller(int) price qty
- sqlQuery = [NSString stringWithFormat:@"select m.name,m.description,m.product_id,w._id,m.closeout from (select name,description,product_id,closeout,best_seller from product where %@ %@ %@ %@ %@ %@ and is_active = 1) m left join wishlist w on m.product_id=w.product_id order by %@ limit %d offset %d;",cateWhere,best_seller,alert,available_condition,qty,price,order_best_seller,limit,offset];
-
- where =[NSString stringWithFormat:@"%@ %@ %@ %@ %@ %@ and is_active = 1",cateWhere,best_seller,alert,available_condition,qty,price];
-
- }
-
- count = [iSalesDB get_recordcount:db table:@"product" where:where];
-
- if (!appDelegate.user) {
- [filter setValue:@{@"count" : @(0)} forKey:@"price"];
- }
-
- [ret setValue:filter forKey:@"filter"];
-
- DebugLog(@"offline_category sql:%@",sqlQuery);
-
- sqlite3_stmt * statement;
- [ret setValue:@"2" forKey:@"result"];
- [ret setValue:[NSString stringWithFormat:@"%d",count] forKey:@"item_total_count"];
-
- NSMutableDictionary* items = [[NSMutableDictionary alloc] init];
- // int count=0;
- if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
- {
-
- int i=0;
- while (sqlite3_step(statement) == SQLITE_ROW)
- {
- NSMutableDictionary* item = [[NSMutableDictionary alloc] init];
-
- char *name = (char*)sqlite3_column_text(statement, 0);
- if(name==nil)
- name="";
- NSString *nsname = [[NSString alloc]initWithUTF8String:name];
-
- char *description = (char*)sqlite3_column_text(statement, 1);
- if(description==nil)
- description="";
- NSString *nsdescription = [[NSString alloc]initWithUTF8String:description];
-
-
-
- int product_id = sqlite3_column_int(statement, 2);
-
- int wid = sqlite3_column_int(statement, 3);
- int closeout = sqlite3_column_int(statement, 4);
-
- NSMutableDictionary* imgjson=[self category_img:product_id db:db];
-
- if(wid==0)
- [item setValue:@"false" forKey:@"wish_exists"];
- else
- [item setValue:@"true" forKey:@"wish_exists"];
-
- if(closeout==0)
- [item setValue:@"false" forKey:@"is_closeout"];
- else
- [item setValue:@"true" forKey:@"is_closeout"];
-
- [item addEntriesFromDictionary:imgjson];
-
-
- // [item setValue:nsurl forKey:@"img"];
- [item setValue:nsname forKey:@"name"];
- [item setValue:nsdescription forKey:@"description"];
- [item setValue:[NSString stringWithFormat:@"%d",product_id] forKey:@"product_id"];
- [items setObject:item forKey:[NSString stringWithFormat:@"item_%d",i]];
- i++;
-
- }
-
- [items setValue:[NSString stringWithFormat:@"%d",i] forKey:@"count"];
- [ret setObject:items forKey:@"items"];
- sqlite3_finalize(statement);
- } else {
- DebugLog(@"nothing...");
- }
- DebugLog(@"count:%d",count);
-
-
- [iSalesDB close_db:db];
-
- DebugLog(@"data string: %@",[RAUtils dict2string:ret] );
-
- return ret;
- }
- # pragma mark item search
- +(NSDictionary*) offline_itemsearch:(NSMutableDictionary *) params
- {
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
-
- BOOL filterSearch = ![params.allKeys containsObject:@"covertype"];
-
- NSMutableDictionary *ret = [self dictionaryFileName:@"category.json"];
- NSMutableDictionary *filter = [[ret objectForKey:@"filter"] mutableCopy];
-
- // category
- NSDictionary *category_menu = [self offline_category_menu];
- [filter setValue:category_menu forKey:@"category"];
-
- NSString* where= nil;
- NSString* orderby= @"m.name";
- if (!filterSearch) {
- int covertype = [[params valueForKey:@"covertype"] intValue];
-
- switch (covertype) {
- case 0:
- {
- where=@"m.category like'%%#005#%%'";
- break;
- }
- case 1:
- {
- where=@"m.alert like '%QS%'";
- break;
- }
- case 2:
- {
- where=@"m.availability>0";
- break;
- }
- case 3:
- {
- where=@"m.best_seller>0";
- orderby=@"m.best_seller desc,m.name asc";
- break;
- }
- default:
- where=@"1=1";
- break;
- }
-
- }
-
-
- int limit = [[params valueForKey:@"limit"] intValue];
- int offset = [[params valueForKey:@"offset"] intValue];
-
-
-
- sqlite3 *db = [iSalesDB get_db];
- // [iSalesDB AddExFunction:db];
-
- int count;
-
- NSString *sqlQuery = nil;
- where = [where stringByAppendingString:@" and m.is_active = 1"];
- sqlQuery=[NSString stringWithFormat:@"select m.name,m.description,m.product_id,w._id,m.closeout from product m left join wishlist w on m.product_id=w.product_id where %@ order by %@ limit %d offset %d ;",where,orderby,limit, offset];
-
- double price_min = 0;
- double price_max = 0;
- if (filterSearch) {
- // alert
- [self check:params[@"alert"] valueKey:@"alert" inDictionary:filter];
- NSString *alert = params[@"alert"];
- if ([alert isEqualToString:@"Display All"]) {
- alert = [NSString stringWithFormat:@""];
- } else {
- alert = [self translateSingleQuote:alert];
- alert = [NSString stringWithFormat:@"and alert = '%@'",alert];
- }
-
- // available
- [self check:params[@"available"] valueKey:@"availability" inDictionary:filter];
- NSString *available = params[@"available"];
- NSString *available_condition;
- if ([available isEqualToString:@"Display All"]) {
- available_condition = @"";
- } else if ([available isEqualToString:@"Available Now"]) {
- available_condition = @"and availability > 0";
- } else {
- available_condition = @"and availability == 0";
- }
-
- // best seller
- [self check:params[@"bestseller"] valueKey:@"best_seller" inDictionary:filter];
- NSString *best_seller = @"";
- NSString *order_best_seller = @"m.name asc";
-
- if ([params[@"bestseller"] isEqualToString:@"Yes"]) {
- best_seller = @"and best_seller > 0";
- order_best_seller = @"m.best_seller desc,m.name asc";
- }
-
- // price
- [self check:params[@"price"] valueKey:@"price" inDictionary:filter];
- NSString *price = params[@"price"];
- price_min = 0;
- price_max = MAXFLOAT;
- if (appDelegate.user) {
- NSArray *priceTypeArray = [self get_contact_default_price_type:nil db:db];
- NSMutableString *priceName = [NSMutableString string];
- for (int i = 0; i < priceTypeArray.count; i++) {
- NSString *pricetype = priceTypeArray[i];
- pricetype = [self translateSingleQuote:pricetype];
- if (i == 0) {
- [priceName appendFormat:@"'%@'",pricetype];
- } else {
- [priceName appendFormat:@",'%@'",pricetype];
- }
- }
-
- if ([price isEqualToString:@"Display All"]) {
- price = [NSString stringWithFormat:@""];
- } else if([price containsString:@"+"]){
- price = [price stringByReplacingOccurrencesOfString:@"+" withString:@""];
- price_min = [price doubleValue];
- price = [NSString stringWithFormat:@"and item_id in (select DISTINCT item_id from model_price where price_name in (%@) and cast(decrypt(price) as double) >= %.2lf and cast(decrypt(price) as double) <= %.2lf)",priceName,price_min,price_max];
- } else {
- NSArray *priceArray = [price componentsSeparatedByString:@"-"];
- price_min = [[priceArray objectAtIndex:0] doubleValue];
- price_max = [[priceArray objectAtIndex:1] doubleValue];
- price = [NSString stringWithFormat:@"and item_id in (select DISTINCT item_id from model_price where price_name in (%@) and cast(decrypt(price) as double) >= %.2lf and cast(decrypt(price) as double) <= %.2lf)",priceName,price_min,price_max];
- }
- } else {
- price = @"";
- }
-
- // sold_by_qty : Sold in quantities of %@
- [self check:params[@"sold_by_qty"] valueKey:@"qty" inDictionary:filter];
- NSString *qty = params[@"sold_by_qty"];
- if ([qty isEqualToString:@"Display All"]) {
- qty = @"";
- } else {
- qty = [self translateSingleQuote:qty];
- qty = [NSString stringWithFormat:@"and model_set = 'Sold in quantities of %@'",qty];
- }
-
- // category
- NSString *category_id = params[@"ctgId"];
- NSMutableArray *cate_id_array = nil;
- NSMutableString *cateWhere = [NSMutableString string];
-
- if ([category_id isEqualToString:@""] || !category_id) {
- [cateWhere appendString:@"1 = 1"];
- } else {
-
- if ([category_id containsString:@","]) {
- cate_id_array = [[category_id componentsSeparatedByString:@","] mutableCopy];
- } else {
- cate_id_array = [@[category_id] mutableCopy];
- }
- /*-----------*/
- NSMutableDictionary *cateDic = [[filter objectForKey:@"category"] mutableCopy];
-
-
- for (int i = 0; i < cate_id_array.count; i++) {
-
- for (NSString *key0 in cateDic.allKeys) {
-
- if ([key0 containsString:@"category_"]) {
-
- NSMutableDictionary *category0 = [[cateDic objectForKey:key0] mutableCopy];
- for (NSString *key1 in category0.allKeys) {
-
- if ([key1 containsString:@"category_"]) {
-
- NSMutableDictionary *category1 = [[category0 objectForKey:key1] mutableCopy];
- [category1 setValue:[NSNumber numberWithInteger:0] forKey:@"check"];
- if ([[category1 objectForKey:@"cid"] isEqualToString:cate_id_array[i]]) {
-
- cate_id_array[i] = [category1 objectForKey:@"id"];
- if (i == 0) {
- [cateWhere appendFormat:@"category like'%%#%@#%%'",cate_id_array[i]];
- } else {
- [cateWhere appendFormat:@"or category like'%%#%@#%%'",cate_id_array[i]];
- }
- [category1 setValue:[NSNumber numberWithInteger:1] forKey:@"check"];
- [category0 setValue:category1 forKey:key1];
- [cateDic setValue:category0 forKey:key0];
-
- }
-
- }
-
- }
-
- }
-
- }
-
- }
- [filter setValue:cateDic forKey:@"category"];
- }
-
- // where bestseller > 0 order by bestseller desc
- // sql query: alert availability(int) best_seller(int) price qty
- sqlQuery = [NSString stringWithFormat:@"select m.name,m.description,m.product_id,w._id,m.closeout from (select name,description,product_id,closeout,best_seller from product where %@ %@ %@ %@ %@ %@ and is_active = 1) m left join wishlist w on m.product_id=w.product_id order by %@ limit %d offset %d;",cateWhere,best_seller,alert,available_condition,qty,price,order_best_seller,limit,offset];
-
- // count
- where =[NSString stringWithFormat:@"%@ %@ %@ %@ %@ %@ and m.is_active = 1",cateWhere,best_seller,alert,available_condition,qty,price];
-
- }
- where = [where stringByReplacingOccurrencesOfString:@"m." withString:@""];
-
- count = [iSalesDB get_recordcount:db table:@"product" where:where];
-
-
-
-
- if (!appDelegate.user) {
- [filter setValue:@{@"count" : @(0)} forKey:@"price"];
- }
-
- [ret setValue:filter forKey:@"filter"];
-
-
-
- DebugLog(@"offline_itemsearch sql:%@",sqlQuery);
-
- sqlite3_stmt * statement;
- [ret setValue:@"2" forKey:@"result"];
- [ret setValue:[NSString stringWithFormat:@"%d",count] forKey:@"item_total_count"];
-
- NSMutableDictionary* items = [[NSMutableDictionary alloc] init];
- // int count=0;
- if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
- {
-
- int i=0;
- while (sqlite3_step(statement) == SQLITE_ROW)
- {
- NSMutableDictionary* item = [[NSMutableDictionary alloc] init];
-
-
- char *name = (char*)sqlite3_column_text(statement, 0);
- NSString *nsname = [[NSString alloc]initWithUTF8String:name];
-
- char *description = (char*)sqlite3_column_text(statement, 1);
- NSString *nsdescription = [[NSString alloc]initWithUTF8String:description];
-
-
-
- int product_id = sqlite3_column_int(statement, 2);
-
-
- int wid = sqlite3_column_int(statement, 3);
- int closeout = sqlite3_column_int(statement, 4);
-
- NSMutableDictionary* imgjson=[self category_img:product_id db:db];
-
- if(wid==0)
- [item setValue:@"false" forKey:@"wish_exists"];
- else
- [item setValue:@"true" forKey:@"wish_exists"];
-
- if(closeout==0)
- [item setValue:@"false" forKey:@"is_closeout"];
- else
- [item setValue:@"true" forKey:@"is_closeout"];
-
- [item addEntriesFromDictionary:imgjson];
-
-
- // [item setValue:nsurl forKey:@"img"];
- [item setValue:nsname forKey:@"fash_name"];
- [item setValue:nsdescription forKey:@"description"];
- [item setValue:[NSString stringWithFormat:@"%d",product_id] forKey:@"product_id"];
- [items setObject:item forKey:[NSString stringWithFormat:@"item_%d",i]];
- i++;
- }
- [items setValue:[NSString stringWithFormat:@"%d",i] forKey:@"count"];
- [ret setObject:items forKey:@"items"];
- sqlite3_finalize(statement);
- }
-
- [iSalesDB close_db:db];
-
- DebugLog(@"data string: %@",[RAUtils dict2string:ret] );
-
- return ret;
- }
- #pragma mark order detail
- + (NSString *)replaceHtml:(NSString *)html String:(NSString *)str0 withString:(NSString *)str1 {
- if (str1.length == 0) {
- str1 = @" ";
- }
- NSString *str = [html stringByReplacingOccurrencesOfString:str0 withString:str1];
- return str;
- }
- +(NSString*) timeFormat:(NSString*)datetime from:(NSString*) from to:(NSString*) to
- {
- NSDateFormatter *fromformatter = [[NSDateFormatter alloc] init];
- [fromformatter setDateFormat:from];
- NSDate *date = [fromformatter dateFromString:datetime];
-
- NSDateFormatter * toformatter = [[NSDateFormatter alloc] init ];
- [toformatter setDateFormat:to];
- NSString * ret = [toformatter stringFromDate:date];
-
- return ret;
-
- }
- + (NSString *)changeDateTime:(NSString *)dateTime Formate:(NSString *)formate withFormate:(NSString *)newFormate {
-
- // 把毫秒去掉
- if ([dateTime containsString:@"."]) {
- dateTime = [[dateTime componentsSeparatedByString:@"."] firstObject];
- }
-
- NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
- formatter.dateFormat = formate;
-
- // [formatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];;
-
- NSDate *date = [formatter dateFromString:dateTime];
-
- formatter.dateFormat = newFormate;
- return [formatter stringFromDate:date];
-
- }
- + (NSString *)changeDateTimeFormate:(NSString *)dateTime {
- return [self changeDateTime:dateTime Formate:@"yyyy-MM-dd HH:mm:ss" withFormate:@"MM/dd/yyyy HH:mm:ss"];
- // return [self timeFormat:dateTime from:@"YYYY-MM-DD HH:mm:ss" to:@"MM/DD/YYYY HH:mm:ss"];
- }
- +(NSData*) offline_orderdetail :(NSMutableDictionary *) params
- {
-
- DebugLog(@"offline oderdetail params: %@",params);
-
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
-
- int orderId = [params[@"orderId"] intValue];
- NSMutableDictionary* ret = [self dictionaryFileName:@"orderDetail.json"];
-
- // decrypt card number and card security code
- // NSString* sql=[NSString stringWithFormat:@"select o._id,o.so_id,o.poNumber,o.create_time,o.status,o.TotalCuft,o.TotalWeight,o.TotalCarton,decrypt(c.company_name),o.customer_contact,decrypt(c.addr_1),c.addr_2,c.addr_3,c.addr_4,o.logist,o.shipping,o.lift_gate_value,o.general_notes,o.internal_notes,o.paymentType,o.lift_gate,o.receive_name,o.receive_contact,o.receive_ext,o.sender_name,o.sender_contact,o.sender_ext,o.shipping_billto_name,o.shipping_billto_contact,o.shipping_billto_ext,o.billing_name,o.billing_contact,o.billing_ext,o.returnto_name,o.returnto_contact,o.returnto_ext,o.handling_fee_value,o.paymentsAndCredits,o.total_price,o.customer_cid,o.credit_card_first_name,o.credit_card_last_name,o.credit_card_address1,o.credit_card_address2,o.credit_card_zipcode,o.credit_card_type,decrypt(o.credit_card_number),decrypt(o.credit_card_security_code),o.credit_card_expiration,o.credit_card_city,o.credit_card_state,o.shipNull,o.erpOrderStatus from (select _id,so_id,poNumber,create_time,status,TotalCuft,TotalWeight,TotalCarton,customer_cid,customer_contact,logist,shipping,lift_gate_value,general_notes,internal_notes,paymentType,lift_gate,receive_name,receive_contact,receive_ext,sender_name,sender_contact,sender_ext,shipping_billto_name,shipping_billto_contact,shipping_billto_ext,billing_name,billing_contact,billing_ext,returnto_name,returnto_contact,returnto_ext,handling_fee_value,paymentsAndCredits,total_price,customer_cid,credit_card_first_name,credit_card_last_name,credit_card_address1,credit_card_address2,credit_card_zipcode,credit_card_type,credit_card_number,credit_card_security_code,credit_card_expiration,credit_card_city,credit_card_state,ifnull(shipping,'ship_null') as shipNull,erpOrderStatus from offline_order where _id=%d) o left join offline_contact c on o.customer_cid=c.contact_id",orderId ];
-
- NSString *sql = [NSString stringWithFormat:@"select o._id,o.so_id,o.poNumber,o.create_time,o.status,decrypt(c.company_name),o.customer_contact,decrypt(c.addr_1),c.addr_2,c.addr_3,c.addr_4,o.logist,o.shipping,o.lift_gate_value,o.general_notes,o.internal_notes,o.paymentType,o.lift_gate,o.receive_name,o.receive_contact,o.receive_ext,o.sender_name,o.sender_contact,o.sender_ext,o.shipping_billto_name,o.shipping_billto_contact,o.shipping_billto_ext,o.billing_name,o.billing_contact,o.billing_ext,o.returnto_name,o.returnto_contact,o.returnto_ext,o.handling_fee_value,o.paymentsAndCredits,o.total_price,o.customer_cid,o.credit_card_first_name,o.credit_card_last_name,o.credit_card_address1,o.credit_card_address2,o.credit_card_zipcode,o.credit_card_type,decrypt(o.credit_card_number),decrypt(o.credit_card_security_code),decrypt(o.credit_card_expiration_month),o.credit_card_city,o.credit_card_state,o.shipNull,o.erpOrderStatus,decrypt(o.credit_card_expiration_year),o.sign_picpath,o.customer_contact,o.customer_email,o.customer_phone,o.customer_fax from (select _id,so_id,poNumber,create_time,status,customer_cid,customer_contact,logist,shipping,lift_gate_value,general_notes,internal_notes,paymentType,lift_gate,receive_name,receive_contact,receive_ext,sender_name,sender_contact,sender_ext,shipping_billto_name,shipping_billto_contact,shipping_billto_ext,billing_name,billing_contact,billing_ext,returnto_name,returnto_contact,returnto_ext,handling_fee_value,paymentsAndCredits,total_price,customer_cid,credit_card_first_name,credit_card_last_name,credit_card_address1,credit_card_address2,credit_card_zipcode,credit_card_type,credit_card_number,credit_card_security_code,credit_card_expiration_month,credit_card_city,credit_card_state,ifnull(shipping,'ship_null') as shipNull,erpOrderStatus,credit_card_expiration_year,sign_picpath,customer_contact,customer_email,customer_phone,customer_fax from offline_order where _id=%d) o left join offline_contact c on o.customer_cid=c.contact_id",orderId];
-
- sqlite3 *db = [iSalesDB get_db];
- sqlite3_stmt * statement;
-
-
-
- NSString *customerID = nil; // 在查询结果中还需要调用offline_contactinfo,需要使用,其中要打开db 就会lock,故而将其置于外面,在close db后在调用
- NSString *nssoid = nil;
- NSString* orderinfo = nil;
- NSString *moreInfo = nil;
- double handlingFee = 0;
- double payments_and_credist = 0;
- double totalPrice = 0;
- double shippingFee = 0;
- double lift_gate = 0;
- NSString *customer_contact = nil;
- NSString *customer_email = nil;
- NSString *customer_fax = nil;
- NSString *customer_phone = nil;
- if (sqlite3_prepare_v2(db, [sql UTF8String], -1, &statement, nil) == SQLITE_OK)
- {
-
-
- if (sqlite3_step(statement) == SQLITE_ROW)
- {
-
- int order_id = sqlite3_column_int(statement, 0);
-
- NSString *sign_url = [self textAtColumn:51 statement:statement];
- ret[@"sign_url"] = sign_url;
-
- customer_contact = [self textAtColumn:52 statement:statement];
- customer_email = [self textAtColumn:53 statement:statement];
- customer_phone = [self textAtColumn:54 statement:statement];
- customer_fax = [self textAtColumn:55 statement:statement];
-
- char *soid = (char*)sqlite3_column_text(statement, 1);
- if(soid==nil)
- soid= "";
- nssoid= [[NSString alloc]initWithUTF8String:soid];
- // so#
- ret[@"so#"] = nssoid;
-
- char *poNumber = (char*)sqlite3_column_text(statement, 2);
- if(poNumber==nil)
- poNumber= "";
- NSString *nspoNumber= [[NSString alloc]initWithUTF8String:poNumber];
-
-
-
- char *create_time = (char*)sqlite3_column_text(statement, 3);
- if(create_time==nil)
- create_time= "";
- NSString *nscreate_time= [[NSString alloc]initWithUTF8String:create_time];
- nscreate_time = [[self changeDateTimeFormate:nscreate_time] stringByAppendingString:@" PST"];// 与在线统一
-
- int status = sqlite3_column_int(statement, 4);
- int erpStatus = sqlite3_column_int(statement, 49);
- NSString* nsstatus = [self orderStatus:status erpStatus:erpStatus];
-
- // status
- if (status > 1 && status != 3) {
- status = erpStatus;
- } else if (status == 3) {
- status = 15;
- }
- ret[@"orderStatus"] = [NSNumber numberWithInteger:status];
- ret[@"order_status"] = nsstatus;
-
-
- char *company_name = (char*)sqlite3_column_text(statement, 5);
- if(company_name==nil)
- company_name= "";
- NSString *nscompany_name= [[NSString alloc]initWithUTF8String:company_name];
- // company name
- ret[@"company_name"] = nscompany_name;
-
- char *customer_contact = (char*)sqlite3_column_text(statement, 6);
- if(customer_contact==nil)
- customer_contact= "";
- NSString *nscustomer_contact= [[NSString alloc]initWithUTF8String:customer_contact];
-
-
- char *addr_1 = (char*)sqlite3_column_text(statement, 7);
- if(addr_1==nil)
- addr_1="";
- NSString *nsaddr_1= [[NSString alloc]initWithUTF8String:addr_1];
-
- char *addr_2 = (char*)sqlite3_column_text(statement, 8);
- if(addr_2==nil)
- addr_2="";
- NSString *nsaddr_2= [[NSString alloc]initWithUTF8String:addr_2];
-
-
- char *addr_3 = (char*)sqlite3_column_text(statement, 9);
- if(addr_3==nil)
- addr_3="";
- NSString *nsaddr_3= [[NSString alloc]initWithUTF8String:addr_3];
-
-
- char *addr_4 = (char*)sqlite3_column_text(statement, 10);
- if(addr_4==nil)
- addr_4="";
- NSString *nsaddr_4= [[NSString alloc]initWithUTF8String:addr_4];
-
- NSMutableArray* arr_addr = [[NSMutableArray alloc] init];
- [arr_addr addObject:nsaddr_1];
- [arr_addr addObject:nsaddr_2];
- [arr_addr addObject:nsaddr_3];
- [arr_addr addObject:nsaddr_4];
- NSString * customer_address = [RAUtils arr2string:arr_addr separator:@"<br>" trim:true];
-
-
- char *logist = (char*)sqlite3_column_text(statement, 11);
- if(logist==nil)
- logist= "";
- NSString *nslogist=[[NSString alloc]initWithUTF8String:logist];
-
- NSString *shipping = [NSString stringWithFormat:@"$%.2f",sqlite3_column_double(statement, 12)];
- if ([[self textAtColumn:48 statement:statement] isEqualToString:@"ship_null"]) {
- shipping = @"Shipping To Be Quoted";
- } else {
- shippingFee = sqlite3_column_double(statement, 12);
- }
-
- // Shipping
- ret[@"Shipping"] = shipping;
-
- int have_lift_gate = sqlite3_column_int(statement, 17);
- lift_gate = sqlite3_column_double(statement, 13);
- // Liftgate Fee(No loading dock)
- if (!have_lift_gate) {
- lift_gate = 0;
- }
- ret[@"Liftgate Fee(No loading dock)"] = [NSString stringWithFormat:@"$%.2f",lift_gate];
-
- char *general_notes = (char*)sqlite3_column_text(statement, 14);
- if(general_notes==nil)
- general_notes= "";
- NSString *nsgeneral_notes=[[NSString alloc]initWithUTF8String:general_notes];
-
- char *internal_notes = (char*)sqlite3_column_text(statement, 15);
- if(internal_notes==nil)
- internal_notes= "";
- NSString *nsinternal_notes=[[NSString alloc]initWithUTF8String:internal_notes];
-
- char *payment_type = (char*)sqlite3_column_text(statement, 16);
- if(payment_type==nil)
- payment_type= "";
- NSString *nspayment_type=[[NSString alloc]initWithUTF8String:payment_type];
-
-
-
- // order info
- orderinfo = [self textFileName:@"order_info.html"];
-
-
- orderinfo = [self replaceHtml:orderinfo String:@"SO_or_nbsp" withString:nssoid];
- orderinfo = [self replaceHtml:orderinfo String:@"PO_or_nbsp" withString:nspoNumber];
- orderinfo = [self replaceHtml:orderinfo String:@"OrderDate_or_nbsp" withString:nscreate_time];
- orderinfo = [self replaceHtml:orderinfo String:@"OrderStatus_or_nbsp" withString:nsstatus];
-
- orderinfo = [self replaceHtml:orderinfo String:@"CustomerInfo_or_nbsp" withString:nscompany_name];
- orderinfo = [self replaceHtml:orderinfo String:@"CustomerName_or_nbsp" withString:nscustomer_contact];
- orderinfo = [self replaceHtml:orderinfo String:@"CustomerAddress_or_nbsp" withString:customer_address];
- orderinfo = [self replaceHtml:orderinfo String:@"ShippingMethod_or_nbsp" withString:nslogist];
- orderinfo = [self replaceHtml:orderinfo String:@"Shipping_or_nbsp" withString:shipping];
- orderinfo = [self replaceHtml:orderinfo String:@"LiftgateFee_or_nbsp" withString:[NSString stringWithFormat:@"%.2f",lift_gate]];
- orderinfo = [self replaceHtml:orderinfo String:@"GeneralNotes_or_nbsp" withString:nsgeneral_notes];
- orderinfo = [self replaceHtml:orderinfo String:@"InternalNotes_or_nbsp" withString:nsinternal_notes];
-
- NSString *payment = nil;
- if([nspayment_type isEqualToString:@"Credit Card"])
- {
- payment = [self textFileName:@"creditcardpayment.html"];
-
- NSString *card_first_name = [self textAtColumn:37 statement:statement];
- NSString *card_last_name = [self textAtColumn:38 statement:statement];
- NSString *card_addr1 = [self textAtColumn:39 statement:statement];
- NSString *card_addr2 = [self textAtColumn:40 statement:statement];
- NSString *card_zipcode = [self textAtColumn:41 statement:statement];
- NSString *card_type = [self textAtColumn:42 statement:statement];
- if (card_type.length > 0) { // 显示星号
- card_type = @"****";
- }
- NSString *card_number = [self textAtColumn:43 statement:statement]; // 只显示最后四位
- if (card_number.length > 0 && card_number.length > 4) {
- for (int i = 0; i < card_number.length - 4; i++) {
- card_number = [card_number stringByReplacingCharactersInRange:NSMakeRange(i, 1) withString:@"*"];
- }
- } else {
- card_number = @"";
- }
- NSString *card_security_code = [self textAtColumn:44 statement:statement];
- NSString *card_expiration_month = [self textAtColumn:45 statement:statement];
- NSString *card_expiration_year = [self textAtColumn:50 statement:statement];
- NSString *card_expiration = [NSString stringWithFormat:@"%@/%@",card_expiration_month,card_expiration_year];
- if (card_expiration_month.length && card_expiration_year.length) { // 显示星号
- card_expiration = @"****";
- }
-
-
- NSString *card_city = [self textAtColumn:46 statement:statement];
- NSString *card_state = [self textAtColumn:47 statement:statement];
-
- payment = [self replaceHtml:payment String:@"CardNumber_or_nbsp" withString:card_number];
- payment = [self replaceHtml:payment String:@"CardType_or_nbsp" withString:card_type];
- payment = [self replaceHtml:payment String:@"CardExpireDate_or_nbsp" withString:card_expiration];
- payment = [self replaceHtml:payment String:@"BillingFirstName_or_nbsp" withString:card_first_name];
- payment = [self replaceHtml:payment String:@"BillingLastName_or_nbsp" withString:card_last_name];
- payment = [self replaceHtml:payment String:@"BillingAddr1_or_nbsp" withString:card_addr1];
- payment = [self replaceHtml:payment String:@"BillingAddr2_or_nbsp" withString:card_addr2];
- payment = [self replaceHtml:payment String:@"BillingCity_or_nbsp" withString:card_city];
- payment = [self replaceHtml:payment String:@"BillingState_or_nbsp" withString:card_state];
- payment = [self replaceHtml:payment String:@"BillingZipCode_or_nbsp" withString:card_zipcode];
-
-
- }
- else
- {
- payment=[self textFileName:@"normalpayment.html"];
- payment = [self replaceHtml:payment String:@"PAYMENTTYPE_PLACEHOLDER" withString:nspayment_type];
- }
- orderinfo=[self replaceHtml:orderinfo String:@"Payment_info_or_nbsp" withString:payment];
-
- ret[@"result"]= [NSNumber numberWithInt:2];
-
- // more info
- moreInfo = [self textFileName:@"more_info.html"];
-
- /*****ship to******/
- // ShipToCompany_or_ 
- NSString *shipToCompany = [self textAtColumn:18 statement:statement];
- moreInfo = [self replaceHtml:moreInfo String:@"ShipToCompany_or_" withString:shipToCompany];
- NSString *shipToName = [self textAtColumn:19 statement:statement];
- moreInfo = [self replaceHtml:moreInfo String:@"ShipToName_or_" withString:shipToName];
- NSString *shipToAddr = [self textAtColumn:20 statement:statement];
- moreInfo = [self replaceHtml:moreInfo String:@"ShipToAddress_or_" withString:shipToAddr];
-
- /*****ship from******/
- // ShipFromCompany_or_ 
- NSString *shipFromCompany = [self textAtColumn:21 statement:statement];
- moreInfo = [self replaceHtml:moreInfo String:@"ShipFromCompany_or_" withString:shipFromCompany];
- NSString *shipFromName = [self textAtColumn:22 statement:statement];
- moreInfo = [self replaceHtml:moreInfo String:@"ShipFromName_or_" withString:shipFromName];
- NSString *shipFromAddr = [self textAtColumn:23 statement:statement];
- moreInfo = [self replaceHtml:moreInfo String:@"ShipFromAddress_or_" withString:shipFromAddr];
-
- /*****freight to******/
- // FreightBillToCompany_or_ 
- NSString *freightBillToCompany = [self textAtColumn:24 statement:statement];
- moreInfo = [self replaceHtml:moreInfo String:@"FreightBillToCompany_or_" withString:freightBillToCompany];
- NSString *freightBillToName = [self textAtColumn:25 statement:statement];
- moreInfo = [self replaceHtml:moreInfo String:@"FreightBillToName_or_" withString:freightBillToName];
- NSString *freightBillToAddr = [self textAtColumn:26 statement:statement];
- moreInfo = [self replaceHtml:moreInfo String:@"FreightBillToAddress_or_" withString:freightBillToAddr];
-
- /*****merchandise to******/
- // MerchandiseBillToCompany_or_ 
- NSString *merchandiseBillToCompany = [self textAtColumn:27 statement:statement];
- moreInfo = [self replaceHtml:moreInfo String:@"MerchandiseBillToCompany_or_" withString:merchandiseBillToCompany];
- NSString *merchandiseBillToName = [self textAtColumn:28 statement:statement];
- moreInfo = [self replaceHtml:moreInfo String:@"MerchandiseBillToName_or_" withString:merchandiseBillToName];
- NSString *merchandiseBillToAddr = [self textAtColumn:29 statement:statement];
- moreInfo = [self replaceHtml:moreInfo String:@"MerchandiseBillToAddress_or_" withString:merchandiseBillToAddr];
-
- /*****return to******/
- // ReturnToCompany_or_ 
- NSString *returnToCompany = [self textAtColumn:30 statement:statement];
- moreInfo = [self replaceHtml:moreInfo String:@"ReturnToCompany_or_" withString:returnToCompany];
- NSString *returnToName = [self textAtColumn:31 statement:statement];
- moreInfo = [self replaceHtml:moreInfo String:@"ReturnToName_or_" withString:returnToName];
- NSString *returnToAddr = [self textAtColumn:32 statement:statement];
- moreInfo = [self replaceHtml:moreInfo String:@"ReturnToAddress_or_" withString:returnToAddr];
- //
-
- DebugLog(@"more info : %@",moreInfo);
-
- // handling fee
- handlingFee = sqlite3_column_double(statement, 33);
- ret[@"Handling Fee"] = [NSString stringWithFormat:@"$%.2f",handlingFee];
-
- // customer info
- customerID = [self textAtColumn:36 statement:statement];
-
- // mode
- ret[@"mode"] = appDelegate.mode;
-
- // model_count
- ret[@"model_count"] = @(0);
-
- }
-
-
-
-
-
- sqlite3_finalize(statement);
-
-
-
-
- }
-
- [iSalesDB close_db:db];
-
- NSMutableDictionary *contactInfo = [[[self offline_contactinfo:[@{@"contactId":customerID} mutableCopy]] objectForKey:@"customerInfo"] mutableCopy];
-
- // "customer_email" = "Shui Hu";
- // "customer_fax" = "";
- // "customer_first_name" = F;
- // "customer_last_name" = L;
- // "customer_name" = ",da He Xiang Dong Liu A";
- // "customer_phone" = "Hey Xuan Feng";
- contactInfo[@"customer_phone"] = customer_phone;
- contactInfo[@"customer_fax"] = customer_fax;
- contactInfo[@"customer_email"] = customer_email;
- NSString *first_name = @"";
- NSString *last_name = @"";
- if ([customer_contact isEqualToString:@""]) {
-
- } else if ([customer_contact containsString:@" "]) {
- NSInteger first_space_index = [customer_contact rangeOfString:@" "].location;
- first_name = [customer_contact substringToIndex:first_space_index];
- last_name = [customer_contact substringFromIndex:first_space_index + 1];
- }
-
- contactInfo[@"customer_first_name"] = first_name;
- contactInfo[@"customer_last_name"] = last_name;
-
- ret[@"customerInfo"] = contactInfo;
-
- // models
- if (nssoid) {
-
- __block double TotalCuft = 0;
- __block double TotalWeight = 0;
- __block int TotalCarton = 0;
- __block double allItemPrice = 0;
-
- NSString *modelSql = [NSString stringWithFormat:@"select c.product_id,c.price,c.discount,c.item_count,c.line_note,m.name,m.description,c.item_id,m.stockUom,c._id from (select _id,product_id,decrypt(str_price) as price,discount,item_count,line_note,item_id from offline_cart where so_no='%@') c left join product m on c.product_id=m.product_id",nssoid];
- sqlite3 *db1 = [iSalesDB get_db];
- [iSalesDB jk_query:modelSql db:db1 close:YES completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- NSMutableDictionary* itemjson = [[NSMutableDictionary alloc] init];
-
-
-
-
- int product_id = sqlite3_column_int(stmt, 0);
-
- char *str_price = (char*)sqlite3_column_text(stmt, 1);
-
- int item_id = sqlite3_column_int(stmt, 7);
-
- NSString* Price=nil;
- if(str_price==nil)
- {
- NSNumber* price = [self get_model_default_price:appDelegate.contact_id product_id:nil item_id:@(item_id) db:db1];
- if(price==nil)
- Price=@"No Price.";
- else
- Price=[NSString stringWithFormat:@"%.2f",price.floatValue];
- }
- else
- {
-
- Price=[NSString stringWithFormat:@"%.2f",[[[NSString alloc]initWithUTF8String:str_price] floatValue]];
- }
-
-
- double discount = sqlite3_column_double(stmt, 2);
- int item_count = sqlite3_column_int(stmt, 3);
-
- char *line_note = (char*)sqlite3_column_text(stmt, 4);
- NSString *nsline_note=nil;
- if(line_note!=nil)
- nsline_note= [[NSString alloc]initWithUTF8String:line_note];
-
-
- // char *name = (char*)sqlite3_column_text(stmt, 5);
- // NSString *nsname = nil;
- // if(name!=nil)
- // nsname= [[NSString alloc]initWithUTF8String:name];
- NSString *nsname = [self textAtColumn:5 statement:stmt];
-
- // char *description = (char*)sqlite3_column_text(stmt, 6);
- // NSString *nsdescription=nil;
- // if(description!=nil)
- // nsdescription= [[NSString alloc]initWithUTF8String:description];
- NSString *nsdescription = [self textAtColumn:6 statement:stmt];
-
- // int stockUom = sqlite3_column_int(stmt, 8);
- // int _id = sqlite3_column_int(stmt, 9);
-
-
- NSDictionary* bsubtotaljson=[self model_subtotal:item_id count:item_count db:db1 compute_part:true];
- double cuft=[bsubtotaljson[@"cuft"] doubleValue];
- double weight=[bsubtotaljson[@"weight"] doubleValue];
- int carton=[bsubtotaljson[@"carton"] intValue];
-
- TotalCuft += cuft;
- TotalWeight += weight;
- TotalCarton += carton;
-
- itemjson[@"combine"]=[self model_bundle:item_id db:db1 compute_part:false];
-
- // itemjson[@"img"]= [self model_category_img:[NSString stringWithFormat:@"%@",[NSNumber numberWithInt:item_id]] model_name:nil db:db1];
- itemjson[@"img"] = [self item_image:[NSString stringWithFormat:@"%@",[NSNumber numberWithInt:item_id]] db:db1];
-
- itemjson[@"Item Number"]=[NSString stringWithFormat:@"%@\n%@",nsname,nsdescription ];
- itemjson[@"note"]=nsline_note;
- itemjson[@"origin_price"] = Price;
- // Price = [NSString stringWithFormat:@"%f",[Price doubleValue] * (1.0 - discount / 100.0)];
- itemjson[@"The unit price"] = [NSString stringWithFormat:@"%f",[Price doubleValue] * (1.0 - discount / 100.0)];
-
- itemjson[@"order_item_status"] = @""; // 暂时不处理
- itemjson[@"product_id"] = [NSString stringWithFormat:@"%d",product_id];
- itemjson[@"QTY"] = [NSString stringWithFormat:@"%d",item_count];
- itemjson[@"discount"] = [NSNumber numberWithDouble:discount];
-
-
- double subTotal = item_count * [Price doubleValue] * (1.0 - discount / 100.0);
- if(itemjson[@"combine"] != nil)
- {
- // int citem=0;
-
- int bcount=[[itemjson[@"combine"] valueForKey:@"count"] intValue];
- for(int bc=0;bc<bcount;bc++)
- {
- NSDictionary * bitem = [itemjson[@"combine"] objectForKey:[NSString stringWithFormat:@"item_%d",bc]];
- int modulus= [[bitem valueForKey:@"modulus"] intValue];
- double uprice= [[bitem valueForKey:@"unit_price"]doubleValue];
- subTotal += uprice * modulus * item_count;
- }
- }
-
- itemjson[@"Subtotal"] = [NSString stringWithFormat:@"%.2f",subTotal];
- NSLog(@"item unite price: %@ \n discount: %f item count: %d subTotal: %f",Price,discount,item_count,subTotal);
-
-
- ret[[NSString stringWithFormat:@"item_%ld",(*count)++]]=itemjson;
- ret[@"model_count"] = [NSNumber numberWithInteger:*count];
-
- allItemPrice += subTotal;
-
- }];
-
- orderinfo = [self replaceHtml:orderinfo String:@"TotalCuft_or_nbsp" withString:[NSString stringWithFormat:@"%.2f ft³",TotalCuft]];
- orderinfo = [self replaceHtml:orderinfo String:@"TotalWeight_or_nbsp" withString:[NSString stringWithFormat:@"%.2f lbs",TotalWeight]];
- orderinfo = [self replaceHtml:orderinfo String:@"TotalCarton_or_nbsp" withString:[NSString stringWithFormat:@"%d",TotalCarton]];
-
- // payments/Credits
- // payments_and_credist = sqlite3_column_double(statement, 34);
- payments_and_credist = allItemPrice;
- ret[@"Payments/Credits"] = [NSString stringWithFormat:@"$%.2f",payments_and_credist];
-
- // // total
- // totalPrice = sqlite3_column_double(statement, 35);
- // ret[@"Total"] = [NSString stringWithFormat:@"$%.2f",totalPrice];
-
-
- } else {
- orderinfo = [self replaceHtml:orderinfo String:@"TotalCuft_or_nbsp" withString:@""];
- orderinfo = [self replaceHtml:orderinfo String:@"TotalWeight_or_nbsp" withString:@""];
- orderinfo = [self replaceHtml:orderinfo String:@"TotalCarton_or_nbsp" withString:@""];
-
- // payments/Credits
- payments_and_credist = 0;
- ret[@"Payments/Credits"] = [NSString stringWithFormat:@"$%.2f",payments_and_credist];
- }
- // total
- totalPrice = payments_and_credist + lift_gate + handlingFee + shippingFee;
- ret[@"Total"] = [NSString stringWithFormat:@"$%.2f",totalPrice];
-
- ret[@"order_info"]= orderinfo;
- ret[@"more_order_info"] = moreInfo;
-
-
- return [RAUtils dict2data:ret];
-
- }
- #pragma mark order list
- + (NSString *)orderStatus:(int)status erpStatus:(int)erpStatus{
- NSString *nsstatus = @"";
- switch (status) {
- case 0:
- {
- nsstatus=@"Temp Order";
- break;
- }
- case 1:
- {
- nsstatus=@"Saved Order";
- break;
- }
- case 2: {
- nsstatus = [self orderStatus:erpStatus erpStatus:-1];
- break;
- }
- case 3:
- case 15:
- {
- nsstatus=@"Cancelled";
- break;
- }
- case 10:
- {
- nsstatus=@"Quote Submitted";
- break;
- }
- case 11:
- {
- nsstatus=@"Sales Order Submitted";
- break;
- }
- case 12:
- {
- nsstatus=@"Processing";
- break;
- }
- case 13:
- {
- nsstatus=@"Shipped";
- break;
- }
- case 14:
- {
- nsstatus=@"Closed";
- break;
- }
-
-
-
- default:
- break;
- }
-
- return nsstatus;
-
- }
- + (double) orderTotalPrice:(NSString *)so_id db:(sqlite3 *)db1 close:(BOOL)close{
-
- double total = 0;
-
- __block double payments_and_credist = 0;
- __block double allItemPrice = 0;
-
- // sqlite3 *db1 = [iSalesDB get_db];
-
- if (so_id) {
- NSString *modelSql = [NSString stringWithFormat:@"select c.product_id,c.price,c.discount,c.item_count,c.line_note,m.name,m.description,c.item_id,m.stockUom,c._id from (select _id,product_id,decrypt(str_price) as price,discount,item_count,line_note,item_id from offline_cart where so_no='%@') c left join product m on c.product_id=m.product_id",so_id];
-
-
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
-
- [iSalesDB jk_query:modelSql db:db1 close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- NSMutableDictionary* itemjson = [[NSMutableDictionary alloc] init];
-
- int product_id = sqlite3_column_int(stmt, 0);
-
- char *str_price = (char*)sqlite3_column_text(stmt, 1);
-
- int item_id = sqlite3_column_int(stmt, 7);
-
- NSString* Price=nil;
- if(str_price==nil)
- {
- NSNumber* price = [self get_model_default_price:appDelegate.contact_id product_id:nil item_id:@(item_id) db:db1];
- if(price==nil)
- Price=@"No Price.";
- else
- Price=[NSString stringWithFormat:@"%.2f",price.floatValue];
- }
- else
- {
-
- Price=[NSString stringWithFormat:@"%.2f",[[[NSString alloc]initWithUTF8String:str_price] floatValue]];
- }
-
-
- int discount = sqlite3_column_int(stmt, 2);
- int item_count = sqlite3_column_int(stmt, 3);
-
-
- itemjson[@"combine"]=[self model_bundle:item_id db:db1 compute_part:false];
-
- itemjson[@"The unit price"]=Price;
-
- itemjson[@"product_id"] = [NSString stringWithFormat:@"%d",product_id];
- itemjson[@"QTY"] = [NSString stringWithFormat:@"%d",item_count];
-
- double subTotal = item_count * [Price doubleValue] * (1.0 - discount / 100.0);
- if(itemjson[@"combine"] != nil)
- {
- // int citem=0;
-
- int bcount=[[itemjson[@"combine"] valueForKey:@"count"] intValue];
- for(int bc=0;bc<bcount;bc++)
- {
- NSDictionary * bitem = [itemjson[@"combine"] objectForKey:[NSString stringWithFormat:@"item_%d",bc]];
- int modulus= [[bitem valueForKey:@"modulus"] intValue];
- double uprice= [[bitem valueForKey:@"unit_price"]doubleValue];
- subTotal += uprice * modulus * item_count;
- }
- }
-
-
- itemjson[@"Subtotal"] = [NSString stringWithFormat:@"%.2f",subTotal];
-
-
- allItemPrice += subTotal;
-
- }];
-
-
- payments_and_credist = allItemPrice;
- } else {
-
-
- // payments/Credits
- payments_and_credist = 0;
-
-
- }
-
- // lift_gate handlingFee shippingFee
- __block double lift_gate = 0;
- __block double handlingFee = 0;
- __block double shippingFee = 0;
- NSString *orderSql = [NSString stringWithFormat:@"select lift_gate,lift_gate_value,handling_fee_value,shipping from offline_order where so_id = '%@';",so_id];
-
- [iSalesDB jk_query:orderSql db:db1 close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- int have_lift_gate = sqlite3_column_int(stmt, 0);
- if (have_lift_gate) {
- lift_gate = sqlite3_column_double(stmt, 1);
- }
-
- handlingFee = sqlite3_column_double(stmt, 2);
- shippingFee = sqlite3_column_double(stmt, 3);
-
- }];
-
- // total
- total = payments_and_credist + lift_gate + handlingFee + shippingFee;
- if (close) {
- [iSalesDB close_db:db1];
- }
- return total;
- }
- +(NSData*) offline_orderlist :(NSMutableDictionary *) params
- {
- NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
-
-
- int limit = [[params valueForKey:@"limit"] intValue];
- int offset = [[params valueForKey:@"offset"] intValue];
- NSString* keyword = [params valueForKey:@"keyWord"];
- keyword = [self translateSingleQuote:keyword]; // 转义单引号
- NSString *orderStatus = [params valueForKey:@"orderStatus"];
-
-
- NSString* where=@"1 = 1";
- if(keyword.length>0)
- where=[where stringByAppendingString:[NSString stringWithFormat:@" and (lower(o.so_id) like '%%%@%%' or lower(o.sales_rep) like '%%%@%%' or lower(decrypt(c.company_name)) like '%%%@%%' or lower(o.create_by) like '%%%@%%')",keyword.lowercaseString,keyword.lowercaseString,keyword.lowercaseString,keyword.lowercaseString]];
-
- if (orderStatus.length > 0) {
- NSArray *order_status_array = [orderStatus componentsSeparatedByString:@","];
- if (order_status_array.count == 1) {
- int status_value = [[order_status_array firstObject] integerValue];
- if (status_value <= 1 || status_value == 3) {
- where = [where stringByAppendingString:[NSString stringWithFormat:@" and o.status = %d",status_value]];
- } else {
- where = [where stringByAppendingString:[NSString stringWithFormat:@" and o.erpOrderStatus = %d",status_value]];
- }
-
- } else if (order_status_array.count > 1) {
-
- for (int i = 0; i < order_status_array.count;i++) {
- NSString *status = order_status_array[i];
- NSString *condition = @" or";
- if (i == 0) {
- condition = @" and (";
- }
- // where = [where stringByAppendingString:[NSString stringWithFormat:@"%@ o.status = %@",condition,status]];
-
- int status_value = [status integerValue];
- if (status_value <= 1 || status_value == 3) {
- where = [where stringByAppendingString:[NSString stringWithFormat:@"%@ o.status = %d",condition,status_value]];
- } else {
- where = [where stringByAppendingString:[NSString stringWithFormat:@" %@ o.erpOrderStatus = %d",condition,status_value]];
- }
-
-
- }
-
- where = [where stringByAppendingString:@" )"];
- }
- }
-
- NSString* sqlQuery=[NSString stringWithFormat:@"SELECT o._id,o.so_id,o.status,o.sales_rep,o.create_by,decrypt(c.company_name),o.create_time,o.total_price,o.customer_contact,o.erpOrderStatus from offline_order o left join offline_contact c on o.customer_cid=c.contact_id where %@ order by o.create_time desc limit %d offset %d" ,where, limit, offset];
-
- DebugLog(@"order list sql: %@",sqlQuery);
-
- sqlite3 *db = [iSalesDB get_db];
- sqlite3_stmt * statement;
-
-
- if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
- {
-
- int count=0;
- while (sqlite3_step(statement) == SQLITE_ROW)
- {
-
-
-
- NSMutableDictionary* item=[[NSMutableDictionary alloc]init];
-
- int order_id = sqlite3_column_double(statement, 0);
-
- char *soid = (char*)sqlite3_column_text(statement, 1);
- if(soid==nil)
- soid= "";
- NSString *nssoid= [[NSString alloc]initWithUTF8String:soid];
-
-
- int status = sqlite3_column_double(statement, 2);
- int erpStatus = sqlite3_column_double(statement, 9);
-
- char *sales_rep = (char*)sqlite3_column_text(statement, 3);
- if(sales_rep==nil)
- sales_rep= "";
- NSString *nssales_rep= [[NSString alloc]initWithUTF8String:sales_rep];
-
- char *create_by = (char*)sqlite3_column_text(statement, 4);
- if(create_by==nil)
- create_by= "";
- NSString *nscreate_by= [[NSString alloc]initWithUTF8String:create_by];
-
- char *company_name = (char*)sqlite3_column_text(statement, 5);
- if(company_name==nil)
- company_name= "";
- NSString *nscompany_name= [[NSString alloc]initWithUTF8String:company_name];
-
- char *create_time = (char*)sqlite3_column_text(statement, 6);
- if(create_time==nil)
- create_time= "";
- NSString *nscreate_time= [[NSString alloc]initWithUTF8String:create_time];
- DebugLog(@"time: %@",nscreate_time);
- nscreate_time = [self changeDateTimeFormate:nscreate_time]; // 与在线统一
- // double total_price = sqlite3_column_double(statement, 7);
- double total_price = [self orderTotalPrice:[NSString stringWithUTF8String:soid] db:db close:NO];
-
- NSString *customer_contact = [self textAtColumn:8 statement:statement];
-
- NSString* nsstatus = [self orderStatus:status erpStatus:erpStatus];
-
- // ": "JH",
- // "": "$8307.00",
- // "": "MOB1608050001",
- // "": "ArpithaT",
- // "": "1st Stage Property Transformations",
- // "": "JANICE SUTTON",
- // "": 2255,
- // "": "08/02/2016 09:49:18",
- // "": 1,
- // "": "Saved Order"
- // "": "1470384050483",
- // "model_count": "6 / 28"
-
- item[@"sales_rep"]= nssales_rep;
- item[@"price"]= [NSString stringWithFormat:@"$%.2f",total_price];
- item[@"so#"]= nssoid;
- item[@"create_by"]= nscreate_by;
- item[@"customer_name"]= nscompany_name;
- item[@"customer_contact"] = customer_contact;
- item[@"order_id"]= [NSString stringWithFormat:@"%d",order_id];
- item[@"purchase_time"]= nscreate_time;
- item[@"orderStatus"]= [NSString stringWithFormat:@"%d",status];
- item[@"order_status"]= nsstatus;
- item[@"order_code"]= nssoid;//[NSString stringWithFormat:@"%d",order_id];
- // item[@"model_count"]
-
-
- ret[[NSString stringWithFormat:@"item_%d",count]]= item;
- count++;
-
- }
-
- ret[@"count"]= [NSNumber numberWithInt:count];
- //ret[@"total_count"]= [NSNumber numberWithInt:count];
- // ret[@"wish_count"]= [NSNumber numberWithInt:count];
- ret[@"result"]= [NSNumber numberWithInt:2];
- ret[@"can_see_price"] = [NSNumber numberWithBool:YES];
- ret[@"time_zone"] = @"PST";
-
-
- sqlite3_finalize(statement);
-
- }
-
- int total_count = [iSalesDB get_recordcount:db table:@"offline_order o left join offline_contact c on o.customer_cid=c.contact_id" where:where];
-
- ret[@"total_count"] = [NSNumber numberWithInteger:total_count];
-
- [iSalesDB close_db:db];
-
- return [RAUtils dict2data:ret];
- }
- #pragma mark update gnotes
- +(NSData*) offline_updategnotes :(NSMutableDictionary *) params
- {
- DebugLog(@"params: %@",params);
- // comments = Meyoyoyoyoyoyoy;
- // orderCode = MOB1608110001;
- // password = 123456;
- // user = EvanK;
-
- NSString *sql = [NSString stringWithFormat:@"update offline_order set general_notes = '%@' where so_id = '%@';",[self valueInParams:params key:@"comments"],[self valueInParams:params key:@"orderCode"]];
- int ret = [iSalesDB execSql:sql];
-
- NSMutableDictionary *dic = [NSMutableDictionary dictionary];
- [dic setValue:[NSNumber numberWithInteger:ret] forKey:@"result"];
- [dic setValue:@"Regular Mode" forKey:@"mode"];
- // [dic setValue:@"160409" forKey:@"min_ver"];
-
- return [RAUtils dict2data:dic];
- }
- #pragma mark move to wishlist
- +(NSData*) offline_movecart2wish :(NSMutableDictionary *) params
- {
-
- NSString *_id = [self valueInParams:params key:@"cartItemId"];
-
- NSString *orderCode = [self valueInParams:params key:@"orderCode"];
- NSString *sql = [NSString stringWithFormat:@"select product_id,item_count,item_id from offline_cart where so_no = '%@' and _id = %@;",orderCode,_id];
- sqlite3 *db = [iSalesDB get_db];
-
- __block NSString *product_id = nil;
- __block int item_count = 0;
- __block NSString *item_id = nil;
- [iSalesDB jk_query:sql db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
- product_id = [self textAtColumn:0 statement:stmt];
- item_count = sqlite3_column_int(stmt, 1);
- item_id = [self textAtColumn:2 statement:stmt];
- }];
-
- //
- // NSString *contactIdSql = [NSString stringWithFormat:@"select customer_cid from offline_order where so_id = '%@';",orderCode];
- // __block NSString *contact_id = nil;
- // [iSalesDB jk_query:contactIdSql db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
- // contact_id = [self textAtColumn:0 statement:stmt];
- // }];
-
- NSString *insertIntoWishlistSql = [NSString stringWithFormat:@"insert into wishlist (product_id,item_id,qty) values (%@,%@,%d);",product_id,item_id,item_count];
- int ret = [iSalesDB execSql:insertIntoWishlistSql db:db];
-
- int wish_count = [iSalesDB get_recordcount:db table:@"wishlist" where:nil];
- NSMutableDictionary *dic = [NSMutableDictionary dictionary];
- [dic setValue:[NSNumber numberWithInteger:ret] forKey:@"result"];
- [dic setValue:@"Regular Mode" forKey:@"mode"];
- // [dic setValue:@"160409" forKey:@"min_ver"];
- [dic setValue:[NSNumber numberWithInteger:wish_count] forKey:@"wish_count"];
-
- // 删除
- NSString *deleteSql = [NSString stringWithFormat:@"delete from offline_cart where _id = %@;",_id];
- [iSalesDB execSql:deleteSql db:db];
-
- [iSalesDB close_db:db];
-
- return [RAUtils dict2data:dic];
- }
- #pragma mark cart delete
- +(NSData*) offline_cartremove :(NSMutableDictionary *) params
- {
- // cartItemId = 548;
- // orderCode = MOB1608110001;
-
- NSString *_id = [self valueInParams:params key:@"cartItemId"];
- NSString *orderCode = [self valueInParams:params key:@"orderCode"];
-
- NSString *sql = [NSString stringWithFormat:@"delete from offline_cart where _id = %@ and so_no = '%@';",_id,orderCode];
- int ret = [iSalesDB execSql:sql];
-
-
- NSMutableDictionary *dic = [NSMutableDictionary dictionary];
- [dic setValue:[NSNumber numberWithInteger:ret] forKey:@"result"];
- [dic setValue:@"Regular Mode" forKey:@"mode"];
- // [dic setValue:@"160409" forKey:@"min_ver"];
-
- return [RAUtils dict2data:dic];
- }
- #pragma mark set price
- +(NSData*) offline_cartsetprice :(NSMutableDictionary *) params
- {
- DebugLog(@"cart set price params: %@",params);
- // "cartitem_id" = 1;
- // discount = "0.000000";
- // "item_note" = "";
- // price = "269.000000";
-
- NSString *_id = [self valueInParams:params key:@"cartitem_id"];
- NSString *notes = [self valueInParams:params key:@"item_note"];
- NSString *discount = [self valueInParams:params key:@"discount"];
- NSString *price = [self valueInParams:params key:@"price"];
- price = [self translateSingleQuote:[AESCrypt fastencrypt:price]];
-
- NSString *sql = [NSString stringWithFormat:@"update offline_cart set str_price = '%@',discount = %f where _id = %@",price,discount.doubleValue,_id];
-
- int ret = [iSalesDB execSql:sql];
-
- NSMutableDictionary *dic = [NSMutableDictionary dictionary];
- [dic setValue:[NSNumber numberWithInteger:ret] forKey:@"result"];
- [dic setValue:@"Regular Mode" forKey:@"mode"];
- // [dic setValue:@"160409" forKey:@"min_ver"];
-
- return [RAUtils dict2data:dic];
-
- }
- #pragma mark set line notes
- +(NSData*) offline_cartsetlnotes :(NSMutableDictionary *) params
- {
- NSString *_id = [self valueInParams:params key:@"cartitem_id"];
- NSString *notes = [self valueInParams:params key:@"notes"];
- notes = [self translateSingleQuote:notes];
-
- NSString *sql = [NSString stringWithFormat:@"update offline_cart set line_note = '%@' where _id = %@",notes,_id];
-
- int ret = [iSalesDB execSql:sql];
-
- NSMutableDictionary *dic = [NSMutableDictionary dictionary];
- [dic setValue:[NSNumber numberWithInteger:ret] forKey:@"result"];
- [dic setValue:@"Regular Mode" forKey:@"mode"];
- // [dic setValue:@"160409" forKey:@"min_ver"];
-
- return [RAUtils dict2data:dic];
- }
- #pragma mark set qty
- +(NSData*) offline_cartsetqty :(NSMutableDictionary *) params
- {
- NSString *_id = [self valueInParams:params key:@"cartitem_id"];
- int item_count = [params[@"inputInt"] integerValue];
-
- NSString *sql = [NSString stringWithFormat:@"update offline_cart set item_count = %d where _id = %@;",item_count,_id];
-
- int ret = [iSalesDB execSql:sql];
-
- __block int item_id = 0;
-
- [iSalesDB jk_query:[NSString stringWithFormat:@"select item_id from offline_cart where _id = %@;",_id] completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
- item_id = sqlite3_column_int(stmt, 0);
- }];
-
- sqlite3 *db = [iSalesDB get_db];
-
- NSDictionary* bsubtotaljson=[self model_subtotal:item_id count:item_count db:db compute_part:true];
- [iSalesDB close_db:db];
-
- NSMutableDictionary *dic = [NSMutableDictionary dictionary];
- [dic setValue:[NSNumber numberWithInteger:ret] forKey:@"result"];
- [dic setValue:@"Regular Mode" forKey:@"mode"];
- // [dic setValue:@"160409" forKey:@"min_ver"];
- [dic setValue:bsubtotaljson[@"cuft"] forKey:@"cuft"];
- [dic setValue:bsubtotaljson[@"weight"] forKey:@"weight"];
- [dic setValue:bsubtotaljson[@"carton"] forKey:@"carton"];
-
- return [RAUtils dict2data:dic];
- }
- #pragma mark place order
- + (NSDictionary *)infoName:(NSString *)name aname:(NSString *)aname control:(NSString *)control keyboard:(NSString *)keyboard value:(id)value {
-
- NSMutableDictionary *dic = [NSMutableDictionary dictionary];
- if (aname) {
- [dic setValue:aname forKey:@"aname"];
- }
- if (control) {
- [dic setValue:control forKey:@"control"];
- }
- if (keyboard) {
- [dic setValue:keyboard forKey:@"keyboard"];
- }
- if (name) {
- [dic setValue:name forKey:@"name"];
- }
- if (value) {
- [dic setValue:value forKey:@"value"];
- }
-
- return dic;
- }
- + (NSDictionary *)customerDic:(NSDictionary *) params db:(sqlite3 *)db {
-
- NSString *orderCode = [self valueInParams:params key:@"orderCode"];
- orderCode = [self translateSingleQuote:orderCode];
-
- __block NSMutableDictionary *customer_dic = [NSMutableDictionary dictionary];
-
- NSString *customerSql = [NSString stringWithFormat:@"select c.contact_id,c.img_0,c.img_1,c.img_2,decrypt(c.company_name),decrypt(c.addr_1),c.addr_2,c.addr_3,c.addr_4,c.first_name,c.last_name,c.email,decrypt(c.phone),c.fax,c.zipcode,c.city,c.state,c.country from offline_contact as c join offline_order as o on c.contact_id = o.customer_cid where o.so_id = '%@';",orderCode];
- [iSalesDB jk_query:customerSql db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- NSString *contact_id = [self textAtColumn:0 statement:stmt];
- NSString *img0 = [self textAtColumn:1 statement:stmt];
- NSString *img1 = [self textAtColumn:2 statement:stmt];
- NSString *img2 = [self textAtColumn:3 statement:stmt];
- NSString *company_name = [self textAtColumn:4 statement:stmt];
- NSString *addr1 = [self textAtColumn:5 statement:stmt];
- NSString *addr2 = [self textAtColumn:6 statement:stmt];
- NSString *addr3 = [self textAtColumn:7 statement:stmt];
- NSString *addr4 = [self textAtColumn:8 statement:stmt];
- NSString *first_name = [self textAtColumn:9 statement:stmt];
- NSString *last_name = [self textAtColumn:10 statement:stmt];
- NSString *email = [self textAtColumn:11 statement:stmt];
- NSString *phone = [self textAtColumn:12 statement:stmt];
- NSString *fax = [self textAtColumn:13 statement:stmt];
- NSString *zipcode = [self textAtColumn:14 statement:stmt];
- NSString *city = [self textAtColumn:15 statement:stmt];
- NSString *state = [self textAtColumn:16 statement:stmt];
- NSString *country = [self textAtColumn:17 statement:stmt];
-
- NSString *name = [first_name stringByAppendingFormat:@" %@",last_name];
-
- // contact id
- NSMutableDictionary *contact_id_dic = [NSMutableDictionary dictionary];
- [contact_id_dic setValue:@"Contact ID" forKey:@"aname"];
- [contact_id_dic setValue:@"text" forKey:@"control"];
- [contact_id_dic setValue:@"text" forKey:@"keyboard"];
- [contact_id_dic setValue:@"customer_cid" forKey:@"name"];
- [contact_id_dic setValue:@"true" forKey:@"required"];
- [contact_id_dic setValue:contact_id forKey:@"value"];
-
- [customer_dic setValue:contact_id_dic forKey:@"item_0"];
-
- // business card
- NSMutableDictionary *business_card_dic = [NSMutableDictionary dictionary];
- [business_card_dic setValue:@"Business Card" forKey:@"aname"];
- [business_card_dic setValue:@"img" forKey:@"control"];
- [business_card_dic setValue:@"1" forKey:@"disable"];
- [business_card_dic setValue:img0 forKey:@"img_url_0"];
- [business_card_dic setValue:img1 forKey:@"img_url_1"];
- [business_card_dic setValue:img2 forKey:@"img_url_2"];
- [business_card_dic setValue:img0 forKey:@"img_url_aname_0"];
- [business_card_dic setValue:img1 forKey:@"img_url_aname_1"];
- [business_card_dic setValue:img2 forKey:@"img_url_aname_2"];
- [business_card_dic setValue:@"business_card" forKey:@"name"];
-
- [customer_dic setValue:business_card_dic forKey:@"item_1"];
-
- // fax
- NSDictionary *fax_dic = [self infoName:@"customer_fax" aname:@"Fax" control:@"edit" keyboard:@"text" value:fax];
-
- [customer_dic setValue:fax_dic forKey:@"item_10"];
-
- // zipcode
- NSDictionary *zipcode_dic = [self infoName:@"customer_zipcode" aname:@"Zipcode" control:@"text" keyboard:nil value:zipcode];
-
- [customer_dic setValue:zipcode_dic forKey:@"item_11"];
-
- // city
- NSDictionary *city_dic = [self infoName:@"customer_city" aname:@"City" control:@"text" keyboard:nil value:city];
-
- [customer_dic setValue:city_dic forKey:@"item_12"];
-
- // state
- NSDictionary *state_dic = [self infoName:@"customer_state" aname:@"State" control:@"text" keyboard:nil value:state];
-
- [customer_dic setValue:state_dic forKey:@"item_13"];
-
- // country
- NSDictionary *country_dic = [self infoName:@"customer_country" aname:@"Country" control:@"text" keyboard:nil value:country];
-
- [customer_dic setValue:country_dic forKey:@"item_14"];
-
- // company name
- NSDictionary *company_dic = [self infoName:@"customer_name" aname:@"Company Name" control:@"text" keyboard:nil value:company_name];
-
- [customer_dic setValue:company_dic forKey:@"item_2"];
-
- // addr_1
- NSDictionary *addr1_dic = [self infoName:@"customer_address1" aname:@"Address_1" control:@"text" keyboard:nil value:addr1];
-
- [customer_dic setValue:addr1_dic forKey:@"item_3"];
-
- // addr_2
- NSDictionary *addr2_dic = [self infoName:@"customer_address2" aname:@"Address_2" control:@"text" keyboard:nil value:addr2];
-
- [customer_dic setValue:addr2_dic forKey:@"item_4"];
-
- // addr_3
- NSDictionary *addr3_dic = [self infoName:@"customer_address3" aname:@"Address_3" control:@"text" keyboard:nil value:addr3];
-
- [customer_dic setValue:addr3_dic forKey:@"item_5"];
-
- // addr_4
- NSDictionary *addr4_dic = [self infoName:@"customer_address4" aname:@"Address_4" control:@"text" keyboard:nil value:addr4];
-
- [customer_dic setValue:addr4_dic forKey:@"item_6"];
-
- // Contact
- NSDictionary *contact_dic = [self infoName:@"customer_contact" aname:@"Contact" control:@"edit" keyboard:@"text" value:name];
-
- [customer_dic setValue:contact_dic forKey:@"item_7"];
-
- // email
- NSDictionary *email_dic = [self infoName:@"customer_email" aname:@"Email" control:@"edit" keyboard:@"text" value:email];
-
- [customer_dic setValue:email_dic forKey:@"item_8"];
-
- // phone
- NSDictionary *phone_dic = [self infoName:@"customer_phone" aname:@"Phone" control:@"edit" keyboard:@"text" value:phone];
-
- [customer_dic setValue:phone_dic forKey:@"item_9"];
-
- // title
- [customer_dic setValue:@"Customer" forKey:@"title"];
-
- // count
- [customer_dic setValue:[NSNumber numberWithInteger:15] forKey:@"count"];
-
- }];
- return customer_dic;
- }
- + (NSDictionary *)shipToDic:(NSDictionary *)params db:(sqlite3 *)db {
-
- __block NSMutableDictionary *dic = [NSMutableDictionary dictionary];
-
- NSString *orderCode = [self valueInParams:params key:@"orderCode"];
- orderCode = [self translateSingleQuote:orderCode];
-
-
-
- NSString *sql = [NSString stringWithFormat:@"select receive_cid,receive_name,receive_ext,receive_contact,receive_email,receive_fax,receive_phone from offline_order where so_id = '%@';",orderCode];
-
-
- [iSalesDB jk_query:sql db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- NSString *cid = [self textAtColumn:0 statement:stmt];
- NSString *name = [self textAtColumn:1 statement:stmt];
- NSString *ext = [self textAtColumn:2 statement:stmt];
- NSString *contact = [self textAtColumn:3 statement:stmt];
- NSString *email = [self textAtColumn:4 statement:stmt];
- NSString *fax = [self textAtColumn:5 statement:stmt];
- NSString *phone = [self textAtColumn:6 statement:stmt];
-
- // count
- [dic setValue:[NSNumber numberWithInteger:8] forKey:@"count"];
-
- // title
- [dic setValue:@"Ship To" forKey:@"title"];
-
- // choose
- NSMutableDictionary *choose_dic = [NSMutableDictionary dictionary];
- [choose_dic setValue:@"choose" forKey:@"aname"];
- [choose_dic setValue:@"multi_action" forKey:@"control"];
- [choose_dic setValue:[NSNumber numberWithInteger:3] forKey:@"count"];
- NSDictionary *same_as_customer_dic = @{@"aname" : @"Same as customer",
- @"key_map" : @{@"receive_cid" : @"customer_cid",
- @"receive_contact" : @"customer_contact",
- @"receive_email" : @"customer_email",
- @"receive_ext" : @"customer_contact_ext",
- @"receive_fax" : @"customer_fax",
- @"receive_name" : @"customer_name",
- @"receive_phone" : @"customer_phone"},
- @"refresh" : [NSNumber numberWithInteger:1],
- @"type" : @"pull"};
- [choose_dic setValue:same_as_customer_dic forKey:@"item_0"];
- NSDictionary *create_new_ship_to_dic = @{@"aname" : @"Create new ship to",
- @"name" : @"Add new address",
- @"refresh" : [NSNumber numberWithInteger:1],
- @"value" : @"new_addr"
- };
- [choose_dic setValue:create_new_ship_to_dic forKey:@"item_1"];
- NSDictionary *select_ship_to_dic = @{@"aname" : @"Select ship to",
- @"key_map" : @{@"receive_cid" : @"customer_cid",
- @"receive_contact" : @"customer_contact",
- @"receive_email" : @"customer_email",
- @"receive_ext" : @"customer_contact_ext",
- @"receive_fax" : @"customer_fax",
- @"receive_name" : @"customer_name",
- @"receive_phone" : @"customer_phone"},
- @"name" : @"select_ship_to",
- @"refresh" : [NSNumber numberWithInteger:1],
- @"value" : @"Sales_Order_Ship_To"};
- [choose_dic setValue:select_ship_to_dic forKey:@"item_2"];
-
- [dic setValue:choose_dic forKey:@"item_0"];
-
- // contact id
- NSDictionary *contact_id_dic = [[self infoName:@"receive_cid" aname:@"Contact ID" control:@"edit" keyboard:@"text" value:cid] mutableCopy];
- [contact_id_dic setValue:@"1" forKey:@"disable"];
- [contact_id_dic setValue:@"true" forKey:@"required"];
- [dic setValue:contact_id_dic forKey:@"item_1"];
-
- // company name
- NSDictionary *company_name_dic = [self infoName:@"receive_name" aname:@"Company Name" control:@"edit" keyboard:@"text" value:name];
-
- [dic setValue:company_name_dic forKey:@"item_2"];
-
- // address
- NSDictionary *ext_dic = [self infoName:@"receive_ext" aname:@"Address" control:@"text_view" keyboard:@"text" value:ext];
-
- [dic setValue:ext_dic forKey:@"item_3"];
-
- // contact
- NSDictionary *contact_dic = [self infoName:@"receive_contact" aname:@"Contact" control:@"edit" keyboard:@"text" value:contact];
-
- [dic setValue:contact_dic forKey:@"item_4"];
- // phone
- NSDictionary *phone_dic = [self infoName:@"receive_phone" aname:@"Phone" control:@"edit" keyboard:@"text" value:phone];
-
- [dic setValue:phone_dic forKey:@"item_5"];
-
- // fax
- NSDictionary *fax_dic = [self infoName:@"receive_fax" aname:@"Fax" control:@"edit" keyboard:@"text" value:fax];
- [dic setValue:fax_dic forKey:@"item_6"];
- // email
- NSDictionary *email_dic = [self infoName:@"receive_email" aname:@"Email" control:@"edit" keyboard:@"text" value:email];
-
- [dic setValue:email_dic forKey:@"item_7"];
-
- }];
-
- return dic;
- }
- + (NSDictionary *)shipFromDic:(NSDictionary *)params db:(sqlite3 *)db {
- __block NSMutableDictionary *dic = [NSMutableDictionary dictionary];
-
- NSString *orderCode = [self valueInParams:params key:@"orderCode"];
- orderCode = [self translateSingleQuote:orderCode];
-
-
- NSString *sql = [NSString stringWithFormat:@"select sender_cid,sender_name,sender_ext,sender_contact,sender_email,sender_fax,sender_phone from offline_order where so_id = '%@';",orderCode];
-
-
- [iSalesDB jk_query:sql db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- NSString *cid = [self textAtColumn:0 statement:stmt];
- NSString *name = [self textAtColumn:1 statement:stmt];
- NSString *ext = [self textAtColumn:2 statement:stmt];
- NSString *contact = [self textAtColumn:3 statement:stmt];
- NSString *email = [self textAtColumn:4 statement:stmt];
- NSString *fax = [self textAtColumn:5 statement:stmt];
- NSString *phone = [self textAtColumn:6 statement:stmt];
-
- // count
- [dic setValue:[NSNumber numberWithInteger:8] forKey:@"count"];
-
- // title
- [dic setValue:@"Ship From" forKey:@"title"];
-
- // hide
- [dic setValue:[NSNumber numberWithInteger:1] forKey:@"hide"];
-
- // choose
- NSMutableDictionary *choose_dic = [NSMutableDictionary dictionary];
- [choose_dic setValue:@"choose" forKey:@"aname"];
- [choose_dic setValue:@"multi_action" forKey:@"control"];
- [choose_dic setValue:[NSNumber numberWithInteger:1] forKey:@"count"];
- NSDictionary *select_ship_from_dic = @{@"aname" : @"Select ship from",
- @"key_map" : @{@"sender_cid" : @"customer_cid",
- @"sender_contact" : @"customer_contact",
- @"sender_email" : @"customer_email",
- @"sender_ext" : @"customer_contact_ext",
- @"sender_fax" : @"customer_fax",
- @"sender_name" : @"customer_name",
- @"sender_phone" : @"customer_phone"},
- @"name" : @"select_cid",
- @"refresh" : [NSNumber numberWithInteger:0],
- @"value" : @"Sales_Order_Ship_From"};
- [choose_dic setValue:select_ship_from_dic forKey:@"item_0"];
-
- [dic setValue:choose_dic forKey:@"item_0"];
-
- // contact id
- NSDictionary *contact_id_dic = [[self infoName:@"sender_cid" aname:@"Contact ID" control:@"edit" keyboard:@"text" value:cid] mutableCopy];
- [contact_id_dic setValue:@"1" forKey:@"disable"];
- [contact_id_dic setValue:@"true" forKey:@"required"];
-
- [dic setValue:contact_id_dic forKey:@"item_1"];
-
- // company name
- NSDictionary *company_name_dic = [self infoName:@"sender_name" aname:@"Company Name" control:@"edit" keyboard:@"text" value:name];
-
- [dic setValue:company_name_dic forKey:@"item_2"];
-
- // address
- NSDictionary *ext_dic = [self infoName:@"sender_ext" aname:@"Address" control:@"text_view" keyboard:@"text" value:ext];
-
- [dic setValue:ext_dic forKey:@"item_3"];
-
- // contact
- NSDictionary *contact_dic = [self infoName:@"sender_contact" aname:@"Contact" control:@"edit" keyboard:@"text" value:contact];
-
- [dic setValue:contact_dic forKey:@"item_4"];
-
- // phone
- NSDictionary *phone_dic = [self infoName:@"sender_phone" aname:@"Phone" control:@"edit" keyboard:@"text" value:phone];
-
- [dic setValue:phone_dic forKey:@"item_5"];
-
- // fax
- NSDictionary *fax_dic = [self infoName:@"sender_fax" aname:@"Fax" control:@"edit" keyboard:@"text" value:fax];
- [dic setValue:fax_dic forKey:@"item_6"];
-
- // email
- NSDictionary *email_dic = [self infoName:@"sender_email" aname:@"Email" control:@"edit" keyboard:@"text" value:email];
-
- [dic setValue:email_dic forKey:@"item_7"];
-
- }];
-
- return dic;
- }
- + (NSDictionary *)freightBillToDic:(NSDictionary *) params db:(sqlite3 *)db {
- __block NSMutableDictionary *dic = [NSMutableDictionary dictionary];
-
- NSString *orderCode = [self valueInParams:params key:@"orderCode"];
- orderCode = [self translateSingleQuote:orderCode];
-
-
- NSString *sql = [NSString stringWithFormat:@"select shipping_billto_cid,shipping_billto_name,shipping_billto_ext,shipping_billto_contact,shipping_billto_email,shipping_billto_fax,shipping_billto_phone from offline_order where so_id = '%@';",orderCode];
-
-
- [iSalesDB jk_query:sql db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- NSString *cid = [self textAtColumn:0 statement:stmt];
- NSString *name = [self textAtColumn:1 statement:stmt];
- NSString *ext = [self textAtColumn:2 statement:stmt];
- NSString *contact = [self textAtColumn:3 statement:stmt];
- NSString *email = [self textAtColumn:4 statement:stmt];
- NSString *fax = [self textAtColumn:5 statement:stmt];
- NSString *phone = [self textAtColumn:6 statement:stmt];
-
- // count
- [dic setValue:[NSNumber numberWithInteger:8] forKey:@"count"];
-
- // title
- [dic setValue:@"Freight Bill To" forKey:@"title"];
-
- // hide
- [dic setValue:[NSNumber numberWithInteger:1] forKey:@"hide"];
-
- // choose
- NSMutableDictionary *choose_dic = [NSMutableDictionary dictionary];
- [choose_dic setValue:@"choose" forKey:@"aname"];
- [choose_dic setValue:@"multi_action" forKey:@"control"];
- [choose_dic setValue:[NSNumber numberWithInteger:4] forKey:@"count"];
- NSDictionary *same_as_ship_to_dic = @{@"aname" : @"Same as ship to",
- @"key_map" : @{@"shipping_billto_cid" : @"receive_cid",
- @"shipping_billto_contact" : @"receive_contact",
- @"shipping_billto_email" : @"receive_email",
- @"shipping_billto_ext" : @"receive_ext",
- @"shipping_billto_fax" : @"receive_fax",
- @"shipping_billto_name" : @"receive_name",
- @"shipping_billto_phone" : @"receive_phone"},
- @"type" : @"pull"};
- [choose_dic setValue:same_as_ship_to_dic forKey:@"item_0"];
-
- NSDictionary *same_as_customer_dic = @{@"aname" : @"Same as customer",
- @"type" : @"pull",
- @"key_map" : @{@"shipping_billto_cid" : @"customer_cid",
- @"shipping_billto_contact" : @"customer_contact",
- @"shipping_billto_email" : @"customer_email",
- @"shipping_billto_ext" : @"customer_contact_ext",
- @"shipping_billto_fax" : @"customer_fax",
- @"shipping_billto_name" : @"customer_name",
- @"shipping_billto_phone" : @"customer_phone"}
- };
- [choose_dic setValue:same_as_customer_dic forKey:@"item_1"];
-
- NSDictionary *same_as_ship_from_dic = @{@"aname" : @"Same as ship from",
- @"key_map" : @{@"shipping_billto_cid" : @"sender_cid",
- @"shipping_billto_contact" : @"sender_contact",
- @"shipping_billto_email" : @"sender_email",
- @"shipping_billto_ext" : @"sender_ext",
- @"shipping_billto_fax" : @"sender_fax",
- @"shipping_billto_name" : @"sender_name",
- @"shipping_billto_phone" : @"sender_phone"},
- @"type" : @"pull"
- };
- [choose_dic setValue:same_as_ship_from_dic forKey:@"item_2"];
-
- NSDictionary *select_freight_bill_to_dic = @{
- @"aname" : @"Select freight bill to",
- @"name" : @"select_cid",
- @"refresh" : [NSNumber numberWithInteger:0],
- @"value" : @"Sales_Order_Freight_Bill_To",
- @"key_map" : @{
- @"shipping_billto_cid" : @"customer_cid",
- @"shipping_billto_contact" : @"customer_contact",
- @"shipping_billto_email" : @"customer_email",
- @"shipping_billto_ext" : @"customer_contact_ext",
- @"shipping_billto_fax" : @"customer_fax",
- @"shipping_billto_name" : @"customer_name",
- @"shipping_billto_phone" : @"customer_phone"
- }
- };
- [choose_dic setValue:select_freight_bill_to_dic forKey:@"item_3"];
-
- [dic setValue:choose_dic forKey:@"item_0"];
-
- // contact id
- NSDictionary *contact_id_dic = [[self infoName:@"shipping_billto_cid" aname:@"Contact ID" control:@"edit" keyboard:@"text" value:cid] mutableCopy];
- [contact_id_dic setValue:@"1" forKey:@"disable"];
- [contact_id_dic setValue:@"true" forKey:@"required"];
-
- [dic setValue:contact_id_dic forKey:@"item_1"];
-
- // company name
- NSDictionary *company_name_dic = [self infoName:@"shipping_billto_name" aname:@"Company Name" control:@"edit" keyboard:@"text" value:name];
-
- [dic setValue:company_name_dic forKey:@"item_2"];
-
- // address
- NSDictionary *ext_dic = [self infoName:@"shipping_billto_ext" aname:@"Address" control:@"text_view" keyboard:@"text" value:ext];
-
- [dic setValue:ext_dic forKey:@"item_3"];
-
- // contact
- NSDictionary *contact_dic = [self infoName:@"shipping_billto_contact" aname:@"Contact" control:@"edit" keyboard:@"text" value:contact];
-
- [dic setValue:contact_dic forKey:@"item_4"];
-
- // phone
- NSDictionary *phone_dic = [self infoName:@"shipping_billto_phone" aname:@"Phone" control:@"edit" keyboard:@"text" value:phone];
-
- [dic setValue:phone_dic forKey:@"item_5"];
-
- // fax
- NSDictionary *fax_dic = [self infoName:@"shipping_billto_fax" aname:@"Fax" control:@"edit" keyboard:@"text" value:fax];
- [dic setValue:fax_dic forKey:@"item_6"];
-
- // email
- NSDictionary *email_dic = [self infoName:@"shipping_billto_email" aname:@"Email" control:@"edit" keyboard:@"text" value:email];
-
- [dic setValue:email_dic forKey:@"item_7"];
-
- }];
-
- return dic;
- }
- + (NSDictionary *)merchandiseBillToDic:(NSDictionary *)params db:(sqlite3 *)db {
- __block NSMutableDictionary *dic = [NSMutableDictionary dictionary];
-
- NSString *orderCode = [self valueInParams:params key:@"orderCode"];
- orderCode = [self translateSingleQuote:orderCode];
-
-
- NSString *sql = [NSString stringWithFormat:@"select billing_cid,billing_name,billing_ext,billing_contact,billing_email,billing_fax,billing_phone from offline_order where so_id = '%@';",orderCode];
-
-
- [iSalesDB jk_query:sql db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- NSString *cid = [self textAtColumn:0 statement:stmt];
- NSString *name = [self textAtColumn:1 statement:stmt];
- NSString *ext = [self textAtColumn:2 statement:stmt];
- NSString *contact = [self textAtColumn:3 statement:stmt];
- NSString *email = [self textAtColumn:4 statement:stmt];
- NSString *fax = [self textAtColumn:5 statement:stmt];
- NSString *phone = [self textAtColumn:6 statement:stmt];
-
- // count
- [dic setValue:[NSNumber numberWithInteger:8] forKey:@"count"];
-
- // title
- [dic setValue:@"Merchandise Bill To" forKey:@"title"];
-
- // hide
- [dic setValue:[NSNumber numberWithInteger:1] forKey:@"hide"];
-
- // choose
- NSMutableDictionary *choose_dic = [NSMutableDictionary dictionary];
- [choose_dic setValue:@"choose" forKey:@"aname"];
- [choose_dic setValue:@"multi_action" forKey:@"control"];
- [choose_dic setValue:[NSNumber numberWithInteger:3] forKey:@"count"];
- NSDictionary *same_as_ship_to_dic = @{@"aname" : @"Same as ship to",
- @"key_map" : @{@"billing_cid" : @"receive_cid",
- @"billing_contact" : @"receive_contact",
- @"billing_email" : @"receive_email",
- @"billing_ext" : @"receive_ext",
- @"billing_fax" : @"receive_fax",
- @"billing_name" : @"receive_name",
- @"billing_phone" : @"receive_phone"},
- @"type" : @"pull"};
- [choose_dic setValue:same_as_ship_to_dic forKey:@"item_0"];
-
- NSDictionary *same_as_customer_dic = @{@"aname" : @"Same as customer",
- @"type" : @"pull",
- @"key_map" : @{@"billing_cid" : @"customer_cid",
- @"billing_contact" : @"customer_contact",
- @"billing_email" : @"customer_email",
- @"billing_ext" : @"customer_contact_ext",
- @"billing_fax" : @"customer_fax",
- @"billing_name" : @"customer_name",
- @"billing_phone" : @"customer_phone"}
- };
- [choose_dic setValue:same_as_customer_dic forKey:@"item_1"];
-
-
- NSDictionary *select_bill_to_dic = @{
- @"aname" : @"Select bill to",
- @"name" : @"select_cid",
- @"refresh" : [NSNumber numberWithInteger:0],
- @"value" : @"Sales_Order_Merchandise_Bill_To",
- @"key_map" : @{
- @"billing_cid" : @"customer_cid",
- @"billing_contact" : @"customer_contact",
- @"billing_email" : @"customer_email",
- @"billing_ext" : @"customer_contact_ext",
- @"billing_fax" : @"customer_fax",
- @"billing_name" : @"customer_name",
- @"billing_phone" : @"customer_phone"
- }
- };
- [choose_dic setValue:select_bill_to_dic forKey:@"item_2"];
-
- [dic setValue:choose_dic forKey:@"item_0"];
-
- // contact id
- NSDictionary *contact_id_dic = [[self infoName:@"billing_cid" aname:@"Contact ID" control:@"edit" keyboard:@"text" value:cid] mutableCopy];
- [contact_id_dic setValue:@"1" forKey:@"disable"];
- [contact_id_dic setValue:@"true" forKey:@"required"];
-
- [dic setValue:contact_id_dic forKey:@"item_1"];
-
- // company name
- NSDictionary *company_name_dic = [self infoName:@"billing_name" aname:@"Company Name" control:@"edit" keyboard:@"text" value:name];
-
- [dic setValue:company_name_dic forKey:@"item_2"];
-
- // address
- NSDictionary *ext_dic = [self infoName:@"billing_ext" aname:@"Address" control:@"text_view" keyboard:@"text" value:ext];
-
- [dic setValue:ext_dic forKey:@"item_3"];
-
- // contact
- NSDictionary *contact_dic = [self infoName:@"billing_contact" aname:@"Contact" control:@"edit" keyboard:@"text" value:contact];
-
- [dic setValue:contact_dic forKey:@"item_4"];
-
- // phone
- NSDictionary *phone_dic = [self infoName:@"billing_phone" aname:@"Phone" control:@"edit" keyboard:@"text" value:phone];
-
- [dic setValue:phone_dic forKey:@"item_5"];
-
- // fax
- NSDictionary *fax_dic = [self infoName:@"billing_fax" aname:@"Fax" control:@"edit" keyboard:@"text" value:fax];
- [dic setValue:fax_dic forKey:@"item_6"];
-
- // email
- NSDictionary *email_dic = [self infoName:@"billing_email" aname:@"Email" control:@"edit" keyboard:@"text" value:email];
-
- [dic setValue:email_dic forKey:@"item_7"];
-
- }];
-
- return dic;
- }
- + (NSDictionary *)returnToDic:(NSDictionary *)params db:(sqlite3 *)db {
- __block NSMutableDictionary *dic = [NSMutableDictionary dictionary];
-
- NSString *orderCode = [self valueInParams:params key:@"orderCode"];
- orderCode = [self translateSingleQuote:orderCode];
-
-
- NSString *sql = [NSString stringWithFormat:@"select returnto_cid,returnto_name,returnto_ext,returnto_contact,returnto_email,returnto_fax,returnto_phone from offline_order where so_id = '%@';",orderCode];
-
-
- [iSalesDB jk_query:sql db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- NSString *cid = [self textAtColumn:0 statement:stmt];
- NSString *name = [self textAtColumn:1 statement:stmt];
- NSString *ext = [self textAtColumn:2 statement:stmt];
- NSString *contact = [self textAtColumn:3 statement:stmt];
- NSString *email = [self textAtColumn:4 statement:stmt];
- NSString *fax = [self textAtColumn:5 statement:stmt];
- NSString *phone = [self textAtColumn:6 statement:stmt];
-
- // count
- [dic setValue:[NSNumber numberWithInteger:8] forKey:@"count"];
-
- // title
- [dic setValue:@"Return To" forKey:@"title"];
-
- // hide
- [dic setValue:[NSNumber numberWithInteger:1] forKey:@"hide"];
-
- // choose
- NSMutableDictionary *choose_dic = [NSMutableDictionary dictionary];
- [choose_dic setValue:@"choose" forKey:@"aname"];
- [choose_dic setValue:@"multi_action" forKey:@"control"];
- [choose_dic setValue:[NSNumber numberWithInteger:2] forKey:@"count"];
- NSDictionary *same_as_ship_from_dic = @{@"aname" : @"Same as ship from",
- @"key_map" : @{@"returnto_cid" : @"sender_cid",
- @"returnto_contact" : @"sender_contact",
- @"returnto_email" : @"sender_email",
- @"returnto_ext" : @"sender_ext",
- @"returnto_fax" : @"sender_fax",
- @"returnto_name" : @"sender_name",
- @"returnto_phone" : @"sender_phone"},
- @"type" : @"pull"};
- [choose_dic setValue:same_as_ship_from_dic forKey:@"item_0"];
-
-
- NSDictionary *select_return_to_dic = @{
- @"aname" : @"Select return to",
- @"name" : @"select_cid",
- @"refresh" : [NSNumber numberWithInteger:0],
- @"value" : @"Contact_Return_To",
- @"key_map" : @{
- @"returnto_cid" : @"customer_cid",
- @"returnto_contact" : @"customer_contact",
- @"returnto_email" : @"customer_email",
- @"returnto_ext" : @"customer_contact_ext",
- @"returnto_fax" : @"customer_fax",
- @"returnto_name" : @"customer_name",
- @"returnto_phone" : @"customer_phone"
- }
- };
- [choose_dic setValue:select_return_to_dic forKey:@"item_1"];
-
- [dic setValue:choose_dic forKey:@"item_0"];
-
- // contact id
- NSDictionary *contact_id_dic = [[self infoName:@"returnto_cid" aname:@"Contact ID" control:@"edit" keyboard:@"text" value:cid] mutableCopy];
- [contact_id_dic setValue:@"1" forKey:@"disable"];
- [contact_id_dic setValue:@"true" forKey:@"required"];
-
- [dic setValue:contact_id_dic forKey:@"item_1"];
-
- // company name
- NSDictionary *company_name_dic = [self infoName:@"returnto_name" aname:@"Company Name" control:@"edit" keyboard:@"text" value:name];
-
- [dic setValue:company_name_dic forKey:@"item_2"];
-
- // address
- NSDictionary *ext_dic = [self infoName:@"returnto_ext" aname:@"Address" control:@"text_view" keyboard:@"text" value:ext];
-
- [dic setValue:ext_dic forKey:@"item_3"];
-
- // contact
- NSDictionary *contact_dic = [self infoName:@"returnto_contact" aname:@"Contact" control:@"edit" keyboard:@"text" value:contact];
-
- [dic setValue:contact_dic forKey:@"item_4"];
-
- // phone
- NSDictionary *phone_dic = [self infoName:@"returnto_phone" aname:@"Phone" control:@"edit" keyboard:@"text" value:phone];
-
- [dic setValue:phone_dic forKey:@"item_5"];
-
- // fax
- NSDictionary *fax_dic = [self infoName:@"returnto_fax" aname:@"Fax" control:@"edit" keyboard:@"text" value:fax];
- [dic setValue:fax_dic forKey:@"item_6"];
-
- // email
- NSDictionary *email_dic = [self infoName:@"returnto_email" aname:@"Email" control:@"edit" keyboard:@"text" value:email];
-
- [dic setValue:email_dic forKey:@"item_7"];
-
- }];
-
- return dic;
- }
- + (NSDictionary *)modelInfoDic:(NSDictionary *)params db:(sqlite3 *)db {
-
- NSString *orderCode = [self valueInParams:params key:@"orderCode"];
- orderCode = [self translateSingleQuote:orderCode];
-
- __block NSMutableDictionary *dic = [NSMutableDictionary dictionary];
- __block double TotalCuft = 0;
- __block double TotalWeight = 0;
- __block int TotalCarton = 0;
- __block double payments = 0;
-
- NSString *sql = [NSString stringWithFormat:@"select c.item_id,c.item_count,m.stockUom,c.price,c.discount,m.name,m.description,c.line_note from (select _id,product_id,decrypt(str_price) as price,discount,item_count,line_note,item_id from offline_cart where so_no='%@') c left join product m on c.product_id=m.product_id;",orderCode];
-
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
-
- [iSalesDB jk_query:sql db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- NSMutableDictionary *model_dic = [NSMutableDictionary dictionary];
-
- // item id
- int item_id = sqlite3_column_int(stmt, 0);
-
- // count
- int item_count = sqlite3_column_int(stmt, 1);
-
- // stockUom
- int stockUom = sqlite3_column_int(stmt, 2);
-
- // unit price
- NSString *str_price = [self textAtColumn:3 statement:stmt];
- NSString* Price=nil;
- if([str_price isEqualToString:@""])
- {
- NSNumber* price = [self get_model_default_price:appDelegate.contact_id product_id:nil item_id:@(item_id) db:db];
- if(price==nil)
- Price=@"No Price.";
- else
- Price=[NSString stringWithFormat:@"%.2f",price.floatValue];
- }
- else
- {
- Price=[NSString stringWithFormat:@"%.2f",[str_price floatValue]];
- }
-
- // discount
- double discount = sqlite3_column_double(stmt, 4);
-
- // name
- NSString *name = [self textAtColumn:5 statement:stmt];
-
- // description
- NSString *description = [self textAtColumn:6 statement:stmt];
- description = [NSString stringWithFormat:@"%@\n%@",name,description ];
- // line note
- NSString *line_note = [self textAtColumn:7 statement:stmt];
-
- // img
- NSString *img = [self item_image:[NSString stringWithFormat:@"%@",[NSNumber numberWithInt:item_id]] db:db];
-
-
- NSDictionary *combine = [self model_bundle:item_id db:db compute_part:false];
-
- double subTotal = item_count * [Price doubleValue] * (1.0 - discount / 100.0);
- if(combine != nil)
- {
- // int citem=0;
-
- int bcount=[[combine valueForKey:@"count"] intValue];
- for(int bc=0;bc<bcount;bc++)
- {
- NSDictionary * bitem = [combine objectForKey:[NSString stringWithFormat:@"item_%d",bc]];
- int modulus= [[bitem valueForKey:@"modulus"] intValue];
- double uprice= [[bitem valueForKey:@"unit_price"]doubleValue];
- subTotal += uprice * modulus * item_count;
- }
- }
- [model_dic setValue:[NSString stringWithFormat:@"%d",item_id] forKey:@"cart_item_id"];
- [model_dic setValue:@"model" forKey:@"control"];
- [model_dic setValue:[NSString stringWithFormat:@"%d",item_count] forKey:@"count"];
- [model_dic setValue:description forKey:@"description"];
- [model_dic setValue:line_note forKey:@"note"];
- [model_dic setValue:img forKey:@"img_url"];
- [model_dic setValue:[NSNumber numberWithInteger:stockUom] forKey:@"stockUom"];
- [model_dic setValue:[NSString stringWithFormat:@"%.2f",subTotal] forKey:@"total_price"];
- [model_dic setValue:Price forKey:@"unit_price"];
- [model_dic setValue:[NSString stringWithFormat:@"%.2f",discount] forKey:@"discount"];
- if (combine) {
- [model_dic setValue:combine forKey:@"combine"];
- }
-
- // well,what under the row is the info for total
- NSDictionary* bsubtotaljson=[self model_subtotal:item_id count:item_count db:db compute_part:true];
- double cuft=[bsubtotaljson[@"cuft"] doubleValue];
- double weight=[bsubtotaljson[@"weight"] doubleValue];
- int carton=[bsubtotaljson[@"carton"] intValue];
-
- TotalCuft += cuft;
- TotalWeight += weight;
- TotalCarton += carton;
-
- payments += subTotal;
-
- //---------------------------
- [dic setValue:model_dic forKey:[NSString stringWithFormat:@"item_%ld",(*count)++]];
- [dic setValue:[NSNumber numberWithInteger:(*count)] forKey:@"count"];
- }];
-
- [dic setValue:@"Model Information" forKey:@"title"];
-
- [dic setValue:@{@"payments" : [NSNumber numberWithDouble:payments],@"totalCuft" : [NSNumber numberWithDouble:TotalCuft],@"totalWeight" : [NSNumber numberWithDouble:TotalWeight],@"totalCarton" : [NSNumber numberWithInteger:TotalCarton]} forKey:@"toOrderTotal"];
-
- return dic;
- }
- + (NSDictionary *)remarksContentDic:(NSDictionary *)params db:(sqlite3 *)db {
- NSMutableDictionary *dic = [NSMutableDictionary dictionary];
-
- [dic setValue:@"Remarks Content" forKey:@"title"];
- [dic setValue:[NSNumber numberWithInteger:4] forKey:@"count"];
-
- NSString *orderCode = [self valueInParams:params key:@"orderCode"];
- orderCode = [self translateSingleQuote:orderCode];
-
- NSString *sql = [NSString stringWithFormat:@"select poNumber,must_call,internal_notes,general_notes from offline_order where so_id = '%@';",orderCode];
-
- [iSalesDB jk_query:sql db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- NSString *poNumber = [self textAtColumn:0 statement:stmt];
- int mustCall = sqlite3_column_int(stmt, 1);
- NSString *internalNotes = [self textAtColumn:2 statement:stmt];
- NSString *generalNotes = [self textAtColumn:3 statement:stmt];
-
- NSDictionary *po_dic = @{
- @"aname" : @"PO#",
- @"control" : @"edit",
- @"keyboard" : @"text",
- @"name" : @"poNumber",
- @"value" : poNumber
- };
- NSDictionary *must_call_dic = @{
- @"aname" : @"MUST CALL BEFORE DELIVERY",
- @"control" : @"switch",
- @"name" : @"must_call",
- @"value" : mustCall ? @"true" : @"false"
- };
-
- NSDictionary *general_notes_dic = @{
- @"aname" : @"General notes",
- @"control" : @"text_view",
- @"keyboard" : @"text",
- @"name" : @"comments",
- @"value" : generalNotes
- };
-
- NSDictionary *internal_notes_dic = @{
- @"aname" : @"Internal notes",
- @"control" : @"text_view",
- @"keyboard" : @"text",
- @"name" : @"internal_notes",
- @"value" : internalNotes
- };
-
- [dic setValue:po_dic forKey:@"item_0"];
- [dic setValue:must_call_dic forKey:@"item_1"];
- [dic setValue:general_notes_dic forKey:@"item_2"];
- [dic setValue:internal_notes_dic forKey:@"item_3"];
- }];
-
-
- return dic;
- }
- + (NSDictionary *)orderTotalDic:(NSDictionary *)params otherTotal:(NSDictionary *)total db:(sqlite3 *)db {
- // params
- NSString *orderCode = [self valueInParams:params key:@"orderCode"];
- orderCode = [self translateSingleQuote:orderCode];
- NSMutableDictionary *dic = [NSMutableDictionary dictionary];
-
- NSString *sql = [NSString stringWithFormat:@"select lift_gate,lift_gate_value,shipping,handling_fee_value from offline_order where so_id = '%@';",orderCode];
-
- __block double lift_gate_value = 0;
- __block double handling_fee = 0;
- __block double shipping = 0;
-
- [iSalesDB jk_query:sql db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- int lift_gate = sqlite3_column_int(stmt, 0);
- lift_gate_value = sqlite3_column_double(stmt, 1);
- shipping = sqlite3_column_double(stmt, 2);
- handling_fee = sqlite3_column_double(stmt, 3);
-
- if (!lift_gate) {
- lift_gate_value = 0;
- }
-
- }];
-
- double totalCuft = [[total valueForKey:@"totalCuft"] doubleValue];
- double totalWeight = [[total valueForKey:@"totalWeight"] doubleValue];
- int totalCarton = [[total valueForKey:@"totalCarton"] doubleValue];
- double payments = [[total valueForKey:@"payments"] doubleValue];
- // double totalPrice = payments + lift_gate_value + shipping + handling_fee;
- double totalPrice = payments;
-
- [dic setValue:@"Order Total" forKey:@"title"];
-
- NSDictionary *payments_dic = @{
- @"align" : @"right",
- @"aname" : @"Payments/Credits",
- @"control" : @"text",
- @"name" : @"paymentsAndCredits",
- @"type" : @"price",
- @"value" : [NSString stringWithFormat:@"%.2f",payments]
- };
- [dic setValue:payments_dic forKey:@"item_0"];
-
- NSDictionary *handling_fee_dic = @{
- @"align" : @"right",
- @"aname" : @"Handling Fee",
- @"control" : @"text",
- @"name" : @"handling_fee_value",
- @"required" : @"true",
- @"type" : @"price",
- @"value" : @"Shipping To Be Quoted"/*[NSString stringWithFormat:@"%.2f",handling_fee]*/
- };
-
-
- NSDictionary *shipping_dic = @{
- @"align" : @"right",
- @"aname" : @"Shipping*",
- @"control" : @"text",
- @"name" : @"shipping",
- @"required" : @"true",
- @"type" : @"price",
- @"value" : @"Shipping To Be Quoted"/*[NSString stringWithFormat:@"%.2f",shipping]*/
- };
-
-
- NSDictionary *lift_gate_dic = @{
- @"align" : @"right",
- @"aname" : @"Liftgate Fee(No Loading Dock)",
- @"control" : @"text",
- @"name" : @"lift_gate_value",
- @"required" : @"true",
- @"type" : @"price",
- @"value" : @"Shipping To Be Quoted"/*[NSString stringWithFormat:@"%.2f",lift_gate_value]*/
- };
-
- int item_count = 1;
-
- NSString *params_lift_gate = [self valueInParams:params key:@"lift_gate"];
- if (params_lift_gate && [params_lift_gate isEqualToString:@"false"]) {
-
- [dic setValue:shipping_dic forKey:[NSString stringWithFormat:@"item_%d",item_count++]];
- [dic setValue:lift_gate_dic forKey:[NSString stringWithFormat:@"item_%d",item_count++]];
-
- } else if (params_lift_gate && [params_lift_gate isEqualToString:@"true"]) {
-
- [dic setValue:shipping_dic forKey:[NSString stringWithFormat:@"item_%d",item_count++]];
-
- } else {
-
- }
-
- [dic setValue:handling_fee_dic forKey:[NSString stringWithFormat:@"item_%d",item_count++]];
-
-
-
- NSDictionary *total_price_dic = @{
- @"align" : @"right",
- @"aname" : @"Total",
- @"control" : @"text",
- @"name" : @"totalPrice",
- @"type" : @"price",
- @"value" : [NSString stringWithFormat:@"%.2f",totalPrice]
- };
- [dic setValue:total_price_dic forKey:[NSString stringWithFormat:@"item_%d",item_count++]];
-
- NSDictionary *total_cuft_dic = @{
- @"align" : @"right",
- @"aname" : @"Total Cuft",
- @"control" : @"text",
- @"name" : @"",
- @"value" : [NSString stringWithFormat:@"%.2f",totalCuft]
- };
- [dic setValue:total_cuft_dic forKey:[NSString stringWithFormat:@"item_%d",item_count++]];
-
- NSDictionary *total_weight_dic = @{
- @"align" : @"right",
- @"aname" : @"Total Weight",
- @"control" : @"text",
- @"name" : @"",
- @"value" : [NSString stringWithFormat:@"%.2f",totalWeight]
- };
- [dic setValue:total_weight_dic forKey:[NSString stringWithFormat:@"item_%d",item_count++]];
-
- NSDictionary *total_carton_dic = @{
- @"align" : @"right",
- @"aname" : @"Total Carton",
- @"control" : @"text",
- @"name" : @"",
- @"value" : [NSString stringWithFormat:@"%d",totalCarton]
- };
- [dic setValue:total_carton_dic forKey:[NSString stringWithFormat:@"item_%d",item_count++]];
-
- [dic setValue:[NSNumber numberWithInteger:item_count] forKey:@"count"];
-
- return dic;
- }
- + (NSDictionary *)signatureDic:(NSDictionary *)params db:(sqlite3 *)db {
-
- NSString *orderCode = [self valueInParams:params key:@"orderCode"];
- orderCode = [self translateSingleQuote:orderCode];
-
- NSMutableDictionary *dic = [NSMutableDictionary dictionary];
-
- [dic setValue:@"Signature" forKey:@"title"];
-
- __block NSString *pic_path = @"";
-
- NSString *sql = [NSString stringWithFormat:@"select sign_picpath from offline_order where so_id = '%@';",orderCode];
-
- [iSalesDB jk_query:sql db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- pic_path = [self textAtColumn:0 statement:stmt];
-
- }];
-
- NSDictionary *pic_dic = @{
- @"aname" : @"Signature",
- @"avalue" :pic_path,
- @"control" : @"signature",
- @"name" : @"sign_picpath",
- @"value" : pic_path
- };
- [dic setValue:pic_dic forKey:@"item_0"];
- [dic setValue:[NSNumber numberWithInteger:1] forKey:@"count"];
-
- return dic;
- }
- + (NSDictionary *)shippingMethodDic:(NSMutableDictionary *)params db:(sqlite3 *)db {
- NSMutableDictionary *dic = [NSMutableDictionary dictionary];
-
- NSString *orderCode = [self valueInParams:params key:@"orderCode"];
- orderCode = [self translateSingleQuote:orderCode];
-
- NSString *sql = [NSString stringWithFormat:@"select logist,lift_gate,logistic_note from offline_order where so_id = '%@';",orderCode];
-
-
- __block NSString *logist = @"";
- __block NSString *lift_gate = @"";
- __block int lift_gate_integer = 0;
- __block NSString *logistic_note = @"";
- [iSalesDB jk_query:sql db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- logist = [self textAtColumn:0 statement:stmt];
-
- lift_gate_integer = sqlite3_column_int(stmt, 1);
-
- logistic_note = [self textAtColumn:2 statement:stmt];
-
- }];
-
-
- [dic setValue:[NSNumber numberWithInteger:1] forKey:@"count"];
- [dic setValue:@"Shipping Method" forKey:@"title"];
-
- // val_0
- int PERSONAL_PICK_UP_check = 0;
- int USE_MY_CARRIER_check = 0;
- NSString *logistic_note_text = @"";
- int will_call_check = 0;
- if (logist && [logist isEqualToString:@"WILL CALL"]) {
-
- will_call_check = 1;
-
- if ([logistic_note containsString:@"PERSONAL PICK UP"]) {
-
- PERSONAL_PICK_UP_check = 1;
-
- } else if ([logistic_note containsString:@"USE MY CARRIER"]) {
-
- USE_MY_CARRIER_check = 1;
- NSArray *logistic_note_array = [logistic_note componentsSeparatedByString:@"\n\t"];
- logistic_note = [logistic_note_array firstObject];
- if (logistic_note_array.count > 1) {
- logistic_note_text = [logistic_note_array lastObject];
- }
-
- }
-
- }
-
-
- NSMutableDictionary *val_0 = [NSMutableDictionary dictionary];
- [val_0 setValue:[NSNumber numberWithInteger:will_call_check] forKey:@"check"];
- [val_0 setValue:@"WILL CALL(requires 24 hours advance notice)" forKey:@"value"];
- [val_0 setValue:@"WILL CALL" forKey:@"value_id"];
-
- NSMutableDictionary *val0_subItem = [NSMutableDictionary dictionary];
- [val0_subItem setValue:[NSNumber numberWithInteger:1] forKey:@"count"];
- NSDictionary *val0_subItem_item0 = @{
- @"aname" : @"Option",
- @"cadedate" : @{
- @"count" : [NSNumber numberWithInteger:2],
- @"val_0" : @{
- @"check" : [NSNumber numberWithInteger:PERSONAL_PICK_UP_check],
- @"refresh" : [NSNumber numberWithInteger:0],
- @"value" : @"PERSONAL PICK UP",
- @"value_id" : @"PERSONAL PICK UP"
- },
- @"val_1" : @{
- @"check" : [NSNumber numberWithInteger:USE_MY_CARRIER_check],
- @"refresh" : [NSNumber numberWithInteger:0],
- @"sub_item" : @{
- @"count" : [NSNumber numberWithInteger:1],
- @"item_0" : @{
- @"aname" : @"BOL",
- @"control" : @"edit",
- @"keyboard" : @"text",
- @"name" : @"logist_note_text",
- @"refresh" : [NSNumber numberWithInteger:0],
- @"required" : @"false",
- @"value" : logistic_note_text
- }
- },
- @"value" : @"USE MY CARRIER",
- @"value_id" : @"USE MY CARRIER"
- }
- },
- @"control" : @"enum",
- @"name" : @"logistic_note",
- @"required" : @"true",
- @"single_select" : @"true"
- };
- [val0_subItem setValue:val0_subItem_item0 forKey:@"item_0"];
-
- [val_0 setValue:val0_subItem forKey:@"sub_item"];
-
- // val_1
- lift_gate = [self valueInParams:params key:@"lift_gate"];
- if([lift_gate isEqualToString:@""]) {
-
- if (lift_gate_integer == 1) {
- lift_gate = @"true";
- } else {
- lift_gate = @"false";
- }
-
- }
-
- int common_carrier_check = 0;
- if (logist && [logist isEqualToString:@"COMMON CARRIER"]) {
-
- common_carrier_check = 1;
- [params setValue:lift_gate forKey:@"lift_gate"];
- }
-
- NSDictionary *val_1 = @{
- @"check" : [NSNumber numberWithInteger:common_carrier_check],
- @"sub_item" : @{
- @"count" : [NSNumber numberWithInteger:1],
- @"item_0" : @{
- @"aname" : @"Do you have Loading Dock Available ? Slide to green for YES",
- @"control" : @"switch",
- @"name" : @"lift_gate",
- @"refresh" : [NSNumber numberWithInteger:1],
- @"required" : @"true",
- @"value" : lift_gate
- }
- },
- @"value" : @"COMMON CARRIER",
- @"value_id" : @"COMMON CARRIER"
- };
-
- // cadedate
- NSDictionary *cadedate = @{
- @"count" : [NSNumber numberWithInteger:2],
- @"val_0" : val_0,
- @"val_1" : val_1
- };
-
-
- // item_0
- NSDictionary *item_0 = @{
- @"aname" : @"Shipping",
- @"cadedate" : cadedate,
- @"control" : @"enum",
- @"name" : @"logist",
- @"refresh" : [NSNumber numberWithInteger:1],
- @"single_select" : @"true",
- };
-
- [dic setValue:item_0 forKey:@"item_0"];
-
-
-
- return dic;
- }
- + (NSDictionary *)submitAsDic:(NSDictionary *)params db:(sqlite3 *)db {
-
- NSString *orderCode = [self valueInParams:params key:@"orderCode"];
- orderCode = [self translateSingleQuote:orderCode];
-
- NSString *sql = [NSString stringWithFormat:@"select submit_as from offline_order where so_id = '%@';",orderCode];
- __block int submit_as_integer = 0;
- [iSalesDB jk_query:sql db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
- submit_as_integer = sqlite3_column_int(stmt, 0);
- }];
-
- int check11 = 0;
- int check10 = 0;
- if (submit_as_integer == 11) {
- check11 = 1;
- }
-
- if (submit_as_integer == 10) {
- check10 = 1;
- }
-
- // section_0
- NSDictionary *dic = @{
- @"count" : @(1),
- @"item_0" : @{
- @"aname" : @"Submit Order As",
- @"cadedate" : @{
- @"count" : @(2),
- @"val_0" : @{
- @"check" : [NSNumber numberWithInteger:check11],
- @"value" : @"Sales Order",
- @"value_id" : @(11)
- },
- @"val_1" : @{
- @"check" : [NSNumber numberWithInteger:check10],
- @"value" : @"Quote",
- @"value_id" : @(10)
- }
- },
- @"control" : @"enum",
- @"name" : @"erpOrderStatus",
- @"required" : @"true",
- @"single_select" : @"true"
- },
- @"title" : @"Order Type"
- };
-
-
- return dic;
-
- }
- + (NSDictionary *)offline_getStateByCountryCode:(NSString *)countryCode checkedState:(NSString *)state_code db:(sqlite3 *)db {
- countryCode = [self translateSingleQuote:countryCode];
- NSString *sqlQuery = [NSString stringWithFormat:@"select _id,name,code,country_code from offline_state where country_code = '%@';",countryCode];
-
- NSMutableDictionary *ret = [[iSalesDB jk_query:sqlQuery db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- char *name = (char *) sqlite3_column_text(stmt, 1); // value
- char *code = (char *) sqlite3_column_text(stmt, 2); // value_id
-
- if (name == NULL) {
- name = "";
- }
- if (code == NULL) {
- code = "";
- }
-
-
- NSMutableDictionary *stateDic = [NSMutableDictionary dictionaryWithCapacity:2];
- [stateDic setValue:[NSString stringWithUTF8String:name] forKey:@"value"];
- [stateDic setValue:[NSString stringWithUTF8String:code] forKey:@"value_id"];
- [stateDic setValue:[NSNumber numberWithInt:0] forKey:@"check"];
-
- if (state_code && [[NSString stringWithUTF8String:code] isEqualToString:state_code]) {
- [stateDic setValue:[NSNumber numberWithInt:1] forKey:@"check"];
- }
-
- NSString *key = [NSString stringWithFormat:@"val_%ld",(*count)++];
- [container setValue:stateDic forKey:key];
-
-
- }] mutableCopy];
-
- // failure 可以不用了,一样的
- if (ret.allKeys.count == 0) {
- NSMutableDictionary *stateDic = [NSMutableDictionary dictionaryWithCapacity:2];
- [stateDic setValue:@"Other" forKey:@"value"];
- [stateDic setValue:@"" forKey:@"value_id"];
- [stateDic setValue:[NSNumber numberWithInt:0] forKey:@"check"];
-
- if (state_code && [@"" isEqualToString:state_code]) {
- [stateDic setValue:[NSNumber numberWithInt:1] forKey:@"check"];
- }
-
- NSString *key = [NSString stringWithFormat:@"val_0"];
- [ret setValue:stateDic forKey:key];
- }
-
- [ret setValue:[NSNumber numberWithInt:ret.allKeys.count] forKey:@"count"];
-
- return ret;
- }
- + (NSDictionary *)paymentInfoDic:(NSDictionary *)params db:(sqlite3 *)db {
-
-
- NSString *orderCode = [self valueInParams:params key:@"orderCode"];
- orderCode = [self translateSingleQuote:orderCode];
-
- NSString *sql = [NSString stringWithFormat:@"select paymentType,credit_card_first_name,credit_card_last_name,credit_card_address1,credit_card_address2,credit_card_zipcode,credit_card_type,decrypt(credit_card_number),decrypt(credit_card_security_code),decrypt(credit_card_expiration_month),decrypt(credit_card_expiration_year),credit_card_city,credit_card_state from offline_order where so_id = '%@';",orderCode];
-
- __block NSString *payType = @"";
- __block NSString *firstName = @"";
- __block NSString *lastName = @"";
- __block NSString *addr1 = @"";
- __block NSString *addr2 = @"";
- __block NSString *zipcode = @"";
- __block NSString *cardType = @"";
- __block NSString *cardNumber = @"";
- __block NSString *securityCode = @"";
- __block NSString *month = @"";
- __block NSString *year = @"";
- __block NSString *city = @"";
- __block NSString *state = @"";
- [iSalesDB jk_query:sql db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- payType = [self textAtColumn:0 statement:stmt];
- firstName = [self textAtColumn:1 statement:stmt];
- lastName = [self textAtColumn:2 statement:stmt];
- addr1 = [self textAtColumn:3 statement:stmt];
- addr2 = [self textAtColumn:4 statement:stmt];
- zipcode = [self textAtColumn:5 statement:stmt];
- cardType = [self textAtColumn:6 statement:stmt];
- cardNumber = [self textAtColumn:7 statement:stmt];
- securityCode = [self textAtColumn:8 statement:stmt];
- month = [self textAtColumn:9 statement:stmt];
- year = [self textAtColumn:10 statement:stmt];
- city = [self textAtColumn:11 statement:stmt];
- state = [self textAtColumn:12 statement:stmt];
- }];
-
- // if ([year isEqualToString:@""]) {
- // NSDate *date = [NSDate date];
- // NSCalendar *calendar = [NSCalendar currentCalendar];
- // int year_integer = [calendar component:NSCalendarUnitYear fromDate:date];
- // year = [NSString stringWithFormat:@"%d",year_integer];
- // }
- // if ([month isEqualToString:@""]) {
- // month = @"01";
- // }
-
- // "section_2"
- NSDictionary *dic = @{
- @"count" : @(1),
- @"item_0" : @{
- @"aname" : @"Payment",
- @"cadedate" : @{
- @"count" : @(6),
- @"val_0" : @{
- @"check" : [payType isEqualToString:@"Check"] ? @(1) : @(0),
- @"value" : @"Check",
- @"value_id" : @"Check"
- },
- @"val_1" : @{
- @"check" : [payType isEqualToString:@"Cash"] ? @(1) : @(0),
- @"value" : @"Cash",
- @"value_id" : @"Cash"
- },
- @"val_2" : @{
- @"check" : [payType isEqualToString:@"NET 30"] ? @(1) : @(0),
- @"value" : @"NET 30",
- @"value_id" : @"NET 30"
- },
- @"val_3" : @{
- @"check" : [payType isEqualToString:@"Wire Transfer"] ? @(1) : @(0),
- @"value" : @"Wire Transfer",
- @"value_id" : @"Wire Transfer"
- },
- @"val_4" : @{
- @"check" : [payType isEqualToString:@"Credit Card"] ? @(1) : @(0),
- @"sub_item" : @{
- @"count" : @(3),
- @"item_0" : @{
- @"aname" : @"choose",
- @"control" : @"multi_action",
- @"count" : @(1),
- @"item_0" : @{
- @"aname" : @"Same as customer",
- @"key_map" : @{
- @"credit_card_address1" : @"customer_address1",
- @"credit_card_address2" : @"customer_address2",
- @"credit_card_city" : @"customer_city",
- @"credit_card_first_name" : @"customer_first_name",
- @"credit_card_last_name" : @"customer_last_name",
- @"credit_card_state" : @"customer_state",
- @"credit_card_zipcode" : @"customer_zipcode"
- },
- @"type" : @"pull"
- }
- },
- @"item_1" : @{
- @"aname" : @"",
- @"color" : @"red",
- @"control" : @"text",
- @"name" : @"",
- @"value" : @"USA Credit cards only"
- },
- @"item_2" : @{
- @"aname" : @"Fill",
- @"cadedate" : @{
- @"count" : @(2),
- @"val_0" : @{
- @"check" : @(1),
- @"sub_item" : @{
- @"count" : @(11),
- @"item_0" : @{
- @"aname" : @"Type",
- @"cadedate" : @{
- @"count" : @(2),
- @"val_0" : @{
- @"check" : [cardType isEqualToString:@"VISA"] ? @(1) : @(0),
- @"value" : @"VISA",
- @"value_id" : @(0)
- },
- @"val_1" : @{
- @"check" : [cardType isEqualToString:@"MASTER CARD"] ? @(1) : @(0),
- @"value" : @"MASTER CARD",
- @"value_id" : @(1)
- }
- },
- @"control" : @"enum",
- @"name" : @"credit_card_type",
- @"required" : @"true",
- @"single_select" : @"true"
- },
- @"item_1" : @{
- @"aname" : @"Number",
- @"control" : @"edit",
- @"keyboard" : @"int",
- @"length" : @"16",
- @"name" : @"credit_card_number",
- @"required" : @"true",
- @"value" : cardNumber
- },
- @"item_10" : @{
- @"aname" : @"State",
- @"cadedate" : [self offline_getStateByCountryCode:@"US" checkedState:state db:db],
- @"control" : @"enum",
- @"enum" : @"true",
- @"name" : @"credit_card_state",
- @"required" : @"true",
- @"single_select" : @"true"
- },
- @"item_2" : @{
- @"aname" : @"Expiration Date",
- @"control" : @"monthpicker",
- @"name" : @"credit_card_expiration",
- @"required" : @"true",
- @"type" : @"date",
- @"value" : [month isEqualToString:@""] || [year isEqualToString:@""] ? @"" : [NSString stringWithFormat:@"%@/%@",month,year]
- },
- @"item_3" : @{
- @"aname" : @"Security Code",
- @"control" : @"edit",
- @"keyboard" : @"int",
- @"length" : @"3",
- @"name" : @"credit_card_security_code",
- @"required" : @"true",
- @"value" : securityCode
- },
- @"item_4" : @{
- @"aname" : @"First Name",
- @"control" : @"edit",
- @"keyboard" : @"text",
- @"name" : @"credit_card_first_name",
- @"required" : @"true",
- @"value" : firstName
- },
- @"item_5" : @{
- @"aname" : @"Last Name",
- @"control" : @"edit",
- @"keyboard" : @"text",
- @"name" : @"credit_card_last_name",
- @"required" : @"true",
- @"value" : lastName
- },
- @"item_6" : @{
- @"aname" : @"Address 1",
- @"control" : @"edit",
- @"keyboard" : @"text",
- @"name" : @"credit_card_address1",
- @"required" : @"true",
- @"value" : addr1
- },
- @"item_7" : @{
- @"aname" : @"Address 2",
- @"control" : @"edit",
- @"keyboard" : @"text",
- @"name" : @"credit_card_address2",
- @"value" : addr2
- },
- @"item_8" : @{
- @"aname" : @"zip code",
- @"control" : @"edit",
- @"keyboard" : @"text",
- @"name" : @"credit_card_zipcode",
- @"required" : @"true",
- @"value" : zipcode
- },
- @"item_9" : @{
- @"aname" : @"City",
- @"control" : @"edit",
- @"keyboard" : @"text",
- @"name" : @"credit_card_city",
- @"required" : @"true",
- @"value" : city
- }
- },
- @"value" : @"Fill Now",
- @"value_id" : @""
- },
- @"val_1" : @{
- @"check" : @(0),
- @"value" : @"Fill Later",
- @"value_id" : @""
- }
- },
- @"control" : @"enum",
- @"name" : @"",
- @"single_select" : @"true"
- }
- },
- @"value" : @"Credit Card",
- @"value_id" : @"Credit Card"
- },
- @"val_5" : @{
- @"check" : [payType isEqualToString:@"FOLLOW EXISTING"] ? @(1) : @(0),
- @"value" : @"FOLLOW EXISTING",
- @"value_id" : @"FOLLOW EXISTING"
- }
- },
- @"control" : @"enum",
- @"name" : @"paymentType",
- @"single_select" : @"true"
- },
- @"title" : @"Payment Information"
- };
-
-
- return dic;
- }
- +(NSData*) offline_placeorder :(NSMutableDictionary *) params
- {
-
- sqlite3 *db = [iSalesDB get_db];
-
- // params
- NSString *orderCode = [self valueInParams:params key:@"orderCode"];
- orderCode = [self translateSingleQuote:orderCode];
-
- // 0 Order Type 1 Shipping Method 2 Payment Information
- __block NSMutableDictionary *ret = [self dictionaryFileName:@"placeOrderTemplate.json"];
-
- // 0 Order Type
- NSDictionary *order_type_dic = [self submitAsDic:params db:db];
- [ret setValue:order_type_dic forKey:@"section_0"];
-
- // 1 Shipping Method
- NSMutableDictionary *shipping_method_dic = [[self shippingMethodDic:params db:db] mutableCopy];
- // [params setValue:[shipping_method_dic objectForKey:@"lift_gate"] forKey:@"lift_gate"];
- // [shipping_method_dic removeObjectForKey:@"lift_gate"];
- [ret setValue:shipping_method_dic forKey:@"section_1"];
-
-
- // 2 Payment Information
- NSDictionary *payment_info_dic = [self paymentInfoDic:params db:db];
- [ret setValue:payment_info_dic forKey:@"section_2"];
-
- // 3 Customer
- NSDictionary *customer_dic = [self customerDic:params db:db];
- [ret setValue:customer_dic forKey:@"section_3"];
- // 4 Ship To
- NSDictionary *ship_to_dic = [self shipToDic:params db:db];
- [ret setValue:ship_to_dic forKey:@"section_4"];
-
- // 5 Ship From
- NSDictionary *ship_from_dic = [self shipFromDic:params db:db];
- [ret setValue:ship_from_dic forKey:@"section_5"];
-
- // 6 Freight Bill To
- NSDictionary *freight_bill_to = [self freightBillToDic:params db:db];
- [ret setValue:freight_bill_to forKey:@"section_6"];
-
- // 7 Merchandise Bill To
- NSDictionary *merchandise_bill_to_dic = [self merchandiseBillToDic:params db:db];
- [ret setValue:merchandise_bill_to_dic forKey:@"section_7"];
-
- // 8 Return To
- NSDictionary *return_to_dic = [self returnToDic:params db:db];
- [ret setValue:return_to_dic forKey:@"section_8"];
-
- // 9 Model Information
- NSMutableDictionary *model_info_dic = [[self modelInfoDic:params db:db] mutableCopy];
-
- NSDictionary *toOrderTotal = [model_info_dic valueForKey:@"toOrderTotal"];
- [model_info_dic removeObjectForKey:@"toOrderTotal"];
-
- [ret setValue:model_info_dic forKey:@"section_9"];
-
- // 10 Remarks Content
- NSDictionary *remarks_content_dic = [self remarksContentDic:params db:db];
-
- [ret setValue:remarks_content_dic forKey:@"section_10"];
-
- // 11 Order Total
- NSDictionary *order_total_dic = [self orderTotalDic:params otherTotal:toOrderTotal db:db];
-
- [ret setValue:order_total_dic forKey:@"section_11"];
-
- // 12 Signature
- NSDictionary *sign_dic = [self signatureDic:params db:db];
-
- [ret setValue:sign_dic forKey:@"section_12"];
-
- [iSalesDB close_db:db];
-
- return [RAUtils dict2data:ret];
- // return nil;
- }
- #pragma mark addr editor
- + (NSMutableDictionary *)anameDealWithStarAtItem:(NSDictionary *)item add:(BOOL)add {
- NSMutableDictionary *new_item = [item mutableCopy];
-
- [new_item setValue:add ? @"true" : @"false" forKey:@"required"];
-
- return new_item;
- }
- +(NSData*) offline_addreditor :(NSMutableDictionary *) params
- {
- // "is_subaction" = true;
- // orderCode = MOB1608240002;
- // password = 123456;
- // "subaction_tag" = 1;
- // user = EvanK;
-
- // {
- // "is_subaction" = true;
- // orderCode = MOB1608240002;
- // password = 123456;
- // "refresh_trigger" = zipcode;
- // "subaction_tag" = 1;
- // user = EvanK;
- // }
-
- NSMutableDictionary * ret = [self dictionaryFileName:@"createContact.json"];
- [ret removeObjectForKey:@"up_params"];
- [ret setObject:@"New Address" forKey:@"title"];
-
- NSDictionary * section_0 = [ret objectForKey:@"section_0"];
- NSMutableDictionary *new_section_0 = [NSMutableDictionary dictionary];
-
- [new_section_0 setObject:[NSNumber numberWithInteger:14] forKey:@"count"];
-
- NSMutableDictionary *country_dic = [section_0[@"item_5"] mutableCopy];
- [country_dic removeObjectForKey:@"refresh"];
- [country_dic removeObjectForKey:@"restore"];
- [new_section_0 setObject:country_dic forKey:@"item_0"]; // Country
-
-
- [new_section_0 setObject:section_0[@"item_0"] forKey:@"item_1"]; // company name*
- [new_section_0 setObject:[self anameDealWithStarAtItem:section_0[@"item_6"] add:YES] forKey:@"item_2"]; // Address 1*
- [new_section_0 setObject:section_0[@"item_7"] forKey:@"item_3"]; // Address 2
- [new_section_0 setObject:section_0[@"item_8"] forKey:@"item_4"]; // Address 3
- [new_section_0 setObject:section_0[@"item_9"] forKey:@"item_5"]; // Address 4
-
- NSMutableDictionary *zip_code_dic = [self anameDealWithStarAtItem:section_0[@"item_10"] add:YES];
- [zip_code_dic removeObjectForKey:@"refresh"];
- [new_section_0 setObject:zip_code_dic forKey:@"item_6"]; // Zip Code*
-
- [new_section_0 setObject:[self anameDealWithStarAtItem:section_0[@"item_11"] add:YES] forKey:@"item_7"]; // State/Province*
- [new_section_0 setObject:[self anameDealWithStarAtItem:section_0[@"item_12"] add:YES] forKey:@"item_8"]; // City*
- [new_section_0 setObject:section_0[@"item_13"] forKey:@"item_9"]; // Contact First Name
- [new_section_0 setObject:section_0[@"item_14"] forKey:@"item_10"]; // Contact Last Name
- [new_section_0 setObject:section_0[@"item_4"] forKey:@"item_11"]; // Phone*
- [new_section_0 setObject:section_0[@"item_15"] forKey:@"item_12"]; // Fax
- [new_section_0 setObject:[self anameDealWithStarAtItem:section_0[@"item_3"] add:NO] forKey:@"item_13"]; // Email
- [new_section_0 setObject:section_0[@"title"] forKey:@"title"];
-
-
- // country
- NSString *countryCode = @"US";
- NSDictionary *allCountry = [self offline_getAllCountryDefault:countryCode];
- [self setValue:allCountry forItemKey:@"item_0" valueKey:@"cadedate" inDictionary:new_section_0];
-
-
- // state
- NSMutableDictionary *allState = [[self offline_getStateByCountryCode:countryCode checkedState:nil] mutableCopy];
-
- NSDictionary *tmpDic = @{
- @"value" : @"Other",
- @"value_id" : @"",
- @"check" : [NSNumber numberWithInteger:0]
- };
-
- for (int i = 0; i < allState.allKeys.count; i++) {
- NSString *key = [NSString stringWithFormat:@"val_%d",i];
-
- NSDictionary *tmp = allState[key];
- [allState setValue:tmpDic forKey:key];
- tmpDic = tmp;
- }
- [allState setValue:[NSNumber numberWithInteger:allState.allKeys.count - 1] forKey:@"count"];
-
- [self setValue:allState forItemKey:@"item_7" valueKey:@"cadedate" inDictionary:new_section_0];
-
- [ret setValue:new_section_0 forKey:@"section_0"];
-
- return [RAUtils dict2data:ret];
- }
- #pragma mark save addr
- +(NSData*) offline_saveaddr :(NSMutableDictionary *) params
- {
-
- // NSString *companyName = [self valueInParams:params key:@"company"];
- // NSString *addr1 = [self valueInParams:params key:@"address"];
- // NSString *addr2 = [self valueInParams:params key:@"address2"];
- // NSString *addr3 = [self valueInParams:params key:@"address_3"];
- // NSString *addr4 = [self valueInParams:params key:@"address_4"];
- // NSString *countryId = [self valueInParams:params key:@"country"];
- // NSString *stateCode = [self valueInParams:params key:@"state"];
- // NSString *city = [self valueInParams:params key:@"city"];
- // NSString *zipCode = [self valueInParams:params key:@"zipcode"];
- // NSString *firstName = [self valueInParams:params key:@"firstname"];
- // NSString *lastName = [self valueInParams:params key:@"lastname"];
- // NSString *phone = [self valueInParams:params key:@"phone"];
- // NSString *fax = [self valueInParams:params key:@"fax"];
- // NSString *email = [self valueInParams:params key:@"email"];
-
-
- return [self offline_saveContact:params update:NO isCustomer:NO];
- }
- #pragma mark cancel order
- +(NSData*) offline_cancelorder :(NSMutableDictionary *) params
- {
- NSString *orderCode = [self valueInParams:params key:@"orderCode"];
-
- NSString *sql = [NSString stringWithFormat:@"update offline_order set status = 2,erpOrderStatus = 15 where so_id = '%@';",orderCode];
-
- int ret = [iSalesDB execSql:sql];
-
- NSMutableDictionary *dic = [NSMutableDictionary dictionary];
- [dic setValue:[NSNumber numberWithInteger:ret] forKey:@"result"];
- [dic setValue:@"Regular Mode" forKey:@"mode"];
- // [dic setValue:@"160409" forKey:@"min_ver"];
-
- return [RAUtils dict2data:dic];
-
- }
- #pragma mark sign order
- +(NSData*) offline_signorder :(NSMutableDictionary *) params
- {
- //参考 offline_saveBusinesscard
- NSLog(@"sign order params: %@",params);
- // orderCode = MOB1608240002;
- // picpath = "16360511-BA55-4D66-9112-EF9DEA4A14F0.png";
-
- NSString *orderCode = [self valueInParams:params key:@"orderCode"];
- orderCode = [self translateSingleQuote:orderCode];
- NSString *picPath = [self valueInParams:params key:@"picpath"];
- picPath = [self translateSingleQuote:picPath];
-
- NSString *sql = [NSString stringWithFormat:@"update offline_order set sign_picpath = '%@' where so_id = '%@';",picPath,orderCode];
-
-
- int ret = [iSalesDB execSql:sql];
-
- NSMutableDictionary *dic = [NSMutableDictionary dictionary];
- [dic setValue:[NSNumber numberWithInteger:ret] forKey:@"result"];
- [dic setValue:@"Regular Mode" forKey:@"mode"];
- // [dic setValue:@"160409" forKey:@"min_ver"];
-
- return [RAUtils dict2data:dic];
- }
- #pragma mark save order
- + (NSString *)valueInParams:(NSDictionary *)params key:(NSString *)key translateSingleQuote:(BOOL)translate {
- NSString *ret = [self valueInParams:params key:key];
- if (translate) {
- ret = [self translateSingleQuote:ret];
- }
-
- return ret;
- }
- +(NSData*) offline_saveorder :(NSMutableDictionary *) param
- {
- // "logistic_note" = "PERSONAL PICK UP";
- // logist_note_text
- // "logistic_note" = "USE MY CARRIER";
- NSString *so_id = [self valueInParams:param key:@"orderCode" translateSingleQuote:YES];
- NSString *general_notes = [self valueInParams:param key:@"comments" translateSingleQuote:YES];
- general_notes = [NSString stringWithFormat:@"general_notes = '%@',",general_notes] ;
-
- NSString *internal_notes = [self valueInParams:param key:@"internal_notes" translateSingleQuote:YES];
- internal_notes = [NSString stringWithFormat:@"internal_notes = '%@',",internal_notes];
-
- NSString *poNumber = [self valueInParams:param key:@"poNumber" translateSingleQuote:YES];
- poNumber = [NSString stringWithFormat:@"poNumber = '%@',",poNumber];
-
- NSString *must_call = [self valueInParams:param key:@"must_call"]; // false
- int must_call_integer = [must_call isEqualToString:@"true"] ? 1 : 0;
- must_call = [NSString stringWithFormat:@"must_call = %d,",must_call_integer];
-
- NSString *sign_picpath = [self valueInParams:param key:@"sign_picpath" translateSingleQuote:YES];
- sign_picpath = [NSString stringWithFormat:@"sign_picpath = '%@',",sign_picpath];
-
- NSString *total_price = [self valueInParams:param key:@"totalPrice"];
- if (![total_price isEqualToString:@""]) {
- total_price = [NSString stringWithFormat:@"total_price = %@,",total_price];
- } else {
- total_price = @"";
- }
-
- NSString *paymentsAndCredits = [self valueInParams:param key:@"paymentsAndCredits"];
- if ([paymentsAndCredits isEqualToString:@""]) {
- paymentsAndCredits = @"";
- } else {
- paymentsAndCredits = [NSString stringWithFormat:@"paymentsAndCredits = %@,",paymentsAndCredits];
- }
-
- NSString *handling_fee_value = [self valueInParams:param key:@"handling_fee_value"];
- if ([handling_fee_value isEqualToString:@""]) {
- handling_fee_value = @"";
- } else if ([handling_fee_value isEqualToString:@"Shipping To Be Quoted"]) {
- handling_fee_value = @"";
- } else {
- handling_fee_value = [NSString stringWithFormat:@"handling_fee_value = %@,",handling_fee_value];
- }
- NSString *handling_fee_placeholder = handling_fee_value;
-
- NSString *lift_gate = [self valueInParams:param key:@"lift_gate"]; // false
- int lift_gate_integer = [lift_gate isEqualToString:@"true"] ? 1 : 0;
- lift_gate = [NSString stringWithFormat:@"lift_gate = %d,",lift_gate_integer];
-
- NSString *lift_gate_value = [self valueInParams:param key:@"lift_gate_value"]; // Shipping To Be Quoted
- NSString *lift_gate_placeholder = @"";
- if ([lift_gate_value isEqualToString:@""]) {
-
- lift_gate_placeholder = @"";
-
- } else if ([lift_gate_value isEqualToString:@"Shipping To Be Quoted"]) {
-
- lift_gate_placeholder = @"";
-
- } else {
- lift_gate_placeholder = [NSString stringWithFormat:@"lift_gate_value = %@,",lift_gate_value];
- }
-
- NSString *logist = [self valueInParams:param key:@"logist" translateSingleQuote:YES];
- logist = [NSString stringWithFormat:@"logist = '%@',",logist];
-
- NSString *logistic_note_text = [self valueInParams:param key:@"logist_note_text" translateSingleQuote:YES];
- NSString *logistic_note = [self valueInParams:param key:@"logistic_note" translateSingleQuote:YES];
- logistic_note = [logistic_note isEqualToString:@"USE MY CARRIER"] ? [NSString stringWithFormat:@"logistic_note = '%@\n\t%@',",logistic_note,logistic_note_text] : [NSString stringWithFormat:@"logistic_note = '%@',",logistic_note];
-
- // NSString *erpOrderStatus = [self valueInParams:param key:@"erpOrderStatus"];
- NSNumber *erpOrderStatus_number = [param objectForKey:@"erpOrderStatus"];
- NSString *erpOrderStatus = !erpOrderStatus_number ? @"" : [NSString stringWithFormat:@"submit_as = %@,",erpOrderStatus_number];
-
- NSString *paymentType = [self valueInParams:param key:@"paymentType" translateSingleQuote:YES];
- paymentType = [NSString stringWithFormat:@"paymentType = '%@',",paymentType];
-
- NSString *credit_card_address1 = [self valueInParams:param key:@"credit_card_address1" translateSingleQuote:YES];
- credit_card_address1 = [NSString stringWithFormat:@"credit_card_address1 = '%@',",credit_card_address1];
-
- NSString *credit_card_address2 = [self valueInParams:param key:@"credit_card_address2" translateSingleQuote:YES];
- credit_card_address2 = [NSString stringWithFormat:@"credit_card_address2 = '%@',",credit_card_address2];
-
- NSString *credit_card_city = [self valueInParams:param key:@"credit_card_city" translateSingleQuote:YES];
- credit_card_city = [NSString stringWithFormat:@"credit_card_city = '%@',",credit_card_city];
-
- NSString *credit_card_expiration = [self valueInParams:param key:@"credit_card_expiration" translateSingleQuote:YES];
-
- NSString *credit_card_first_name = [self valueInParams:param key:@"credit_card_first_name" translateSingleQuote:YES];
- credit_card_first_name = [NSString stringWithFormat:@"credit_card_first_name = '%@',",credit_card_first_name];
-
- NSString *credit_card_last_name = [self valueInParams:param key:@"credit_card_last_name" translateSingleQuote:YES];
- credit_card_last_name = [NSString stringWithFormat:@"credit_card_last_name = '%@',",credit_card_last_name];
-
- NSString *credit_card_number = [self valueInParams:param key:@"credit_card_number" translateSingleQuote:YES];
- BOOL number_nil = [credit_card_number isEqualToString:@""];
- if (!number_nil) {
- credit_card_number = [AESCrypt fastencrypt:credit_card_number];
- }
- credit_card_number = [NSString stringWithFormat:@"credit_card_number = '%@',",credit_card_number];
-
- NSString *credit_card_security_code = [self valueInParams:param key:@"credit_card_security_code" translateSingleQuote:YES];
- BOOL security_code_nil = [credit_card_security_code isEqualToString:@""];
- if (!security_code_nil) {
- credit_card_security_code = [AESCrypt fastencrypt:credit_card_security_code];
- }
- credit_card_security_code = [NSString stringWithFormat:@"credit_card_security_code = '%@',",credit_card_security_code];
-
- NSString *credit_card_state = [self valueInParams:param key:@"credit_card_state" translateSingleQuote:YES];
- credit_card_state = [NSString stringWithFormat:@"credit_card_state = '%@',",credit_card_state];
-
- NSNumber *card_type_number = [param objectForKey:@"credit_card_type"];
- NSString *credit_card_type = [NSString stringWithFormat:@"credit_card_type = '%@',",[card_type_number integerValue] == 0 ? @"VISA" : @"MASTER CARD"];
-
-
- NSString *credit_card_zipcode = [self valueInParams:param key:@"credit_card_zipcode" translateSingleQuote:YES];
- credit_card_zipcode = [NSString stringWithFormat:@"credit_card_zipcode = '%@',",credit_card_zipcode];
-
- NSString *credit_card_expiration_year = [[credit_card_expiration componentsSeparatedByString:@"/"] lastObject];
- credit_card_expiration_year = [AESCrypt fastencrypt:credit_card_expiration_year];
- credit_card_expiration_year = [NSString stringWithFormat:@"credit_card_expiration_year = '%@',",credit_card_expiration_year];
-
- NSString *credit_card_expiration_month = [[credit_card_expiration componentsSeparatedByString:@"/"] firstObject];
- credit_card_expiration_month = [AESCrypt fastencrypt:credit_card_expiration_month];
- credit_card_expiration_month = [NSString stringWithFormat:@"credit_card_expiration_month = '%@',",credit_card_expiration_month];
-
-
- NSString *customer_cid = [self valueInParams:param key:@"customer_cid" translateSingleQuote:YES];
- NSString *contact_id = customer_cid;
- customer_cid = [NSString stringWithFormat:@"customer_cid = '%@',",customer_cid];
-
- NSString *customer_contact = [self valueInParams:param key:@"customer_contact" translateSingleQuote:YES];
- NSString *contact_contact = [NSString stringWithFormat:@"contact_name = '%@',",customer_contact];
- customer_contact = [NSString stringWithFormat:@"customer_contact = '%@',",customer_contact];
-
- NSString *customer_email = [self valueInParams:param key:@"customer_email" translateSingleQuote:YES];
- NSString *contact_email = [NSString stringWithFormat:@"email = '%@',",customer_email];
- customer_email = [NSString stringWithFormat:@"customer_email = '%@',",customer_email];
-
- NSString *customer_phone = [self valueInParams:param key:@"customer_phone" translateSingleQuote:YES];
- NSString *contact_phone = [NSString stringWithFormat:@"phone = '%@',",[AESCrypt fastencrypt:customer_phone]];
- customer_phone = [NSString stringWithFormat:@"customer_phone = '%@',",customer_phone];
-
-
- NSString *customer_fax = [self valueInParams:param key:@"customer_fax" translateSingleQuote:YES];
- NSString *contact_fax = [NSString stringWithFormat:@"fax = '%@',",customer_fax];
- customer_fax = [NSString stringWithFormat:@"customer_fax = '%@',",customer_fax];
-
-
- //
- NSString *customer_name = [self valueInParams:param key:@"customer_name" translateSingleQuote:YES];
- customer_name = [NSString stringWithFormat:@"company_name = '%@',",[AESCrypt fastencrypt:customer_name]];
-
- NSString *customer_address1 = [self valueInParams:param key:@"customer_address1" translateSingleQuote:YES];
- customer_address1 = [NSString stringWithFormat:@"addr_1 = '%@',",[AESCrypt fastencrypt:customer_address1]];
-
- NSString *customer_address2 = [self valueInParams:param key:@"customer_address2" translateSingleQuote:YES];
- customer_address2 = [NSString stringWithFormat:@"addr_2 = '%@',",customer_address2];
-
- NSString *customer_address3 = [self valueInParams:param key:@"customer_address3" translateSingleQuote:YES];
- customer_address3 = [NSString stringWithFormat:@"addr_3 = '%@',",customer_address3];
-
- NSString *customer_address4 = [self valueInParams:param key:@"customer_address4" translateSingleQuote:YES];
- customer_address4 = [NSString stringWithFormat:@"addr_4 = '%@',",customer_address4];
-
- NSString *customer_country = [self valueInParams:param key:@"customer_country" translateSingleQuote:YES];
- customer_country = [NSString stringWithFormat:@"country = '%@',",customer_country];
-
- NSString *customer_state = [self valueInParams:param key:@"customer_state" translateSingleQuote:YES];
- customer_state = [NSString stringWithFormat:@"state = '%@',",customer_state];
-
- NSString *customer_city = [self valueInParams:param key:@"customer_city" translateSingleQuote:YES];
- customer_city = [NSString stringWithFormat:@"city = '%@',",customer_city];
-
- NSString *customer_zipcode = [self valueInParams:param key:@"customer_zipcode" translateSingleQuote:YES];
- customer_zipcode = [NSString stringWithFormat:@"zipcode = '%@'",customer_zipcode];
-
- NSString *contactSql = [NSString stringWithFormat:@"update offline_contact set %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ where contact_id = '%@'",contact_contact,contact_email,contact_phone,contact_fax,customer_name,customer_address1,customer_address2,customer_address3,customer_address4,customer_country,customer_state,customer_city,customer_zipcode,contact_id];
-
-
- NSString *receive_cid = [self valueInParams:param key:@"receive_cid" translateSingleQuote:YES];
- receive_cid = [NSString stringWithFormat:@"receive_cid = '%@',",receive_cid];
-
- NSString *receive_name = [self valueInParams:param key:@"receive_name" translateSingleQuote:YES];
- receive_name = [NSString stringWithFormat:@"receive_name = '%@',",receive_name];
-
- NSString *receive_ext = [self valueInParams:param key:@"receive_ext" translateSingleQuote:YES];
- receive_ext = [NSString stringWithFormat:@"receive_ext = '%@',",receive_ext];
-
- NSString *receive_contact = [self valueInParams:param key:@"receive_contact" translateSingleQuote:YES];
- receive_contact = [NSString stringWithFormat:@"receive_contact = '%@',",receive_contact];
-
- NSString *receive_phone = [self valueInParams:param key:@"receive_phone" translateSingleQuote:YES];
- receive_phone = [NSString stringWithFormat:@"receive_phone = '%@',",receive_phone];
-
- NSString *receive_email = [self valueInParams:param key:@"receive_email" translateSingleQuote:YES];
- receive_email = [NSString stringWithFormat:@"receive_email = '%@',",receive_email];
-
- NSString *receive_fax = [self valueInParams:param key:@"receive_fax" translateSingleQuote:YES];
- receive_fax = [NSString stringWithFormat:@"receive_fax = '%@',",receive_fax];
-
-
- NSString *sender_cid = [self valueInParams:param key:@"sender_cid" translateSingleQuote:YES];
- sender_cid = [NSString stringWithFormat:@"sender_cid = '%@',",sender_cid];
-
- NSString *sender_name = [self valueInParams:param key:@"sender_name" translateSingleQuote:YES];
- sender_name = [NSString stringWithFormat:@"sender_name = '%@',",sender_name];
-
- NSString *sender_ext = [self valueInParams:param key:@"sender_ext" translateSingleQuote:YES];
- sender_ext = [NSString stringWithFormat:@"sender_ext = '%@',",sender_ext];
-
- NSString *sender_contact = [self valueInParams:param key:@"sender_contact" translateSingleQuote:YES];
- sender_contact = [NSString stringWithFormat:@"sender_contact = '%@',",sender_contact];
-
- NSString *sender_phone = [self valueInParams:param key:@"sender_phone" translateSingleQuote:YES];
- sender_phone = [NSString stringWithFormat:@"sender_phone = '%@',",sender_phone];
-
- NSString *sender_fax = [self valueInParams:param key:@"sender_fax" translateSingleQuote:YES];
- sender_fax = [NSString stringWithFormat:@"sender_fax = '%@',",sender_fax];
-
- NSString *sender_email = [self valueInParams:param key:@"sender_email" translateSingleQuote:YES];
- sender_email = [NSString stringWithFormat:@"sender_email = '%@',",sender_email];
-
-
-
-
- NSString *shipping_billto_cid = [self valueInParams:param key:@"shipping_billto_cid" translateSingleQuote:YES];
- shipping_billto_cid = [NSString stringWithFormat:@"shipping_billto_cid = '%@',",shipping_billto_cid];
-
- NSString *shipping_billto_name = [self valueInParams:param key:@"shipping_billto_name" translateSingleQuote:YES];
- shipping_billto_name = [NSString stringWithFormat:@"shipping_billto_name = '%@',",shipping_billto_name];
-
- NSString *shipping_billto_ext = [self valueInParams:param key:@"shipping_billto_ext" translateSingleQuote:YES];
- shipping_billto_ext = [NSString stringWithFormat:@"shipping_billto_ext = '%@',",shipping_billto_ext];
-
- NSString *shipping_billto_contact = [self valueInParams:param key:@"shipping_billto_contact" translateSingleQuote:YES];
- shipping_billto_contact = [NSString stringWithFormat:@"shipping_billto_contact = '%@',",shipping_billto_contact];
-
- NSString *shipping_billto_phone = [self valueInParams:param key:@"shipping_billto_phone" translateSingleQuote:YES];
- shipping_billto_phone = [NSString stringWithFormat:@"shipping_billto_phone = '%@',",shipping_billto_phone];
-
- NSString *shipping_billto_fax = [self valueInParams:param key:@"shipping_billto_fax" translateSingleQuote:YES];
- shipping_billto_fax = [NSString stringWithFormat:@"shipping_billto_fax = '%@',",shipping_billto_fax];
-
- NSString *shipping_billto_email = [self valueInParams:param key:@"shipping_billto_email" translateSingleQuote:YES];
- shipping_billto_email = [NSString stringWithFormat:@"shipping_billto_email = '%@',",shipping_billto_email];
-
-
- NSString *billing_cid = [self valueInParams:param key:@"billing_cid" translateSingleQuote:YES];
- billing_cid = [NSString stringWithFormat:@"billing_cid = '%@',",billing_cid];
-
- NSString *billing_name = [self valueInParams:param key:@"billing_name" translateSingleQuote:YES];
- billing_name = [NSString stringWithFormat:@"billing_name = '%@',",billing_name];
-
- NSString *billing_ext = [self valueInParams:param key:@"billing_ext" translateSingleQuote:YES];
- billing_ext = [NSString stringWithFormat:@"billing_ext = '%@',",billing_ext];
-
- NSString *billing_contact = [self valueInParams:param key:@"billing_contact" translateSingleQuote:YES];
- billing_contact = [NSString stringWithFormat:@"billing_contact = '%@',",billing_contact];
-
- NSString *billing_phone = [self valueInParams:param key:@"billing_phone" translateSingleQuote:YES];
- billing_phone = [NSString stringWithFormat:@"billing_phone = '%@',",billing_phone];
-
- NSString *billing_fax = [self valueInParams:param key:@"billing_fax" translateSingleQuote:YES];
- billing_fax = [NSString stringWithFormat:@"billing_fax = '%@',",billing_fax];
-
- NSString *billing_email = [self valueInParams:param key:@"billing_email" translateSingleQuote:YES];
- billing_email = [NSString stringWithFormat:@"billing_email = '%@',",billing_email];
-
-
- NSString *returnto_cid = [self valueInParams:param key:@"returnto_cid" translateSingleQuote:YES];
- returnto_cid = [NSString stringWithFormat:@"returnto_cid = '%@',",returnto_cid];
-
- NSString *returnto_name = [self valueInParams:param key:@"returnto_name" translateSingleQuote:YES];
- returnto_name = [NSString stringWithFormat:@"returnto_name = '%@',",returnto_name];
-
- NSString *returnto_ext = [self valueInParams:param key:@"returnto_ext" translateSingleQuote:YES];
- returnto_ext = [NSString stringWithFormat:@"returnto_ext = '%@',",returnto_ext];
-
- NSString *returnto_contact = [self valueInParams:param key:@"returnto_contact" translateSingleQuote:YES];
- returnto_contact = [NSString stringWithFormat:@"returnto_contact = '%@',",returnto_contact];
-
- NSString *returnto_phone = [self valueInParams:param key:@"returnto_phone" translateSingleQuote:YES];
- returnto_phone = [NSString stringWithFormat:@"returnto_phone = '%@',",returnto_phone];
-
- NSString *returnto_fax = [self valueInParams:param key:@"returnto_fax" translateSingleQuote:YES];
- returnto_fax = [NSString stringWithFormat:@"returnto_fax = '%@',",returnto_fax];
-
- NSString *returnto_email = [self valueInParams:param key:@"returnto_email" translateSingleQuote:YES];
- returnto_email = [NSString stringWithFormat:@"returnto_email = '%@',",returnto_email];
-
- NSString *order_status = @"status = 1,";
-
- // NSString *sync_data = [AESCrypt fastencrypt:[RAUtils dict2string:param]];
- NSString *sync_data = [self translateSingleQuote:[RAUtils dict2string:param]];
-
- NSString *orderSql = [NSString stringWithFormat:@"update offline_order set %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ so_id = '%@',sync_data = '%@' where so_id = '%@';",order_status,general_notes,internal_notes,poNumber,must_call,sign_picpath,total_price,paymentsAndCredits,handling_fee_placeholder,lift_gate,lift_gate_placeholder,logist,logistic_note,erpOrderStatus,paymentType,credit_card_address1,credit_card_address2,credit_card_city,credit_card_first_name,credit_card_last_name,credit_card_number,credit_card_security_code,credit_card_state,credit_card_type,credit_card_zipcode,credit_card_expiration_year,credit_card_expiration_month,customer_cid,customer_contact,customer_email,customer_phone,customer_fax,receive_cid,receive_name,receive_ext,receive_contact,receive_phone,receive_email,receive_fax,sender_cid,sender_name,sender_ext,sender_contact,sender_phone,sender_fax,sender_email,shipping_billto_cid,shipping_billto_name,shipping_billto_ext,shipping_billto_contact,shipping_billto_phone,shipping_billto_fax,shipping_billto_email,billing_cid,billing_name,billing_ext,billing_contact,billing_phone,billing_fax,billing_email,returnto_cid,returnto_name,returnto_ext,returnto_contact,returnto_phone,returnto_fax,returnto_email,so_id,sync_data,so_id];
-
- DebugLog(@"save order contactSql: %@",contactSql);
- DebugLog(@"save order orderSql: %@",orderSql);
-
- // int contact_ret = [iSalesDB execSql:contactSql];
-
- int order_ret = [iSalesDB execSql:orderSql];
-
- int ret = order_ret;
-
-
- NSMutableDictionary *dic = [NSMutableDictionary dictionary];
- [dic setValue:[NSNumber numberWithInteger:ret] forKey:@"result"];
- [dic setValue:@"Regular Mode" forKey:@"mode"];
- // [dic setValue:@"160409" forKey:@"min_ver"];
-
- return [RAUtils dict2data:dic];
- }
- #pragma mark add to cart by name
- +(NSData*) offline_add2cartbyname :(NSMutableDictionary *) params
- {
- // {
- // count = 1;
- // customerInfo = {
- // "business_card_0" = "";
- // "business_card_1" = "";
- // "business_card_2" = "";
- // "customer_address1" = "1815 PEARL ST";
- // "customer_address2" = "";
- // "customer_address3" = "";
- // "customer_address4" = "";
- // "customer_cid" = 3RDVIN0001;
- // "customer_city" = BOULDER;
- // "customer_contact" = "CONNIE DRUNNER";
- // "customer_contact_ext" = "1815 PEARL ST
- // \n BOULDER, CO, 80302, US United States";
- // "customer_contact_notes" = "Remark: Please review your order carefully and make sure EVERYTHING is correct, including the SHIP TO address. Please sign to authorize NPD to ship. Thank you for your business.";
- // "customer_country" = "US United States";
- // "customer_email" = "3RDANDVINEDESIGN@GMAIL.COM";
- // "customer_fax" = "303.442.0672";
- // "customer_first_name" = CONNIE;
- // "customer_last_name" = DRUNNER;
- // "customer_name" = "3rd & Vine Desgin";
- // "customer_phone" = "303.442.0669";
- // "customer_price_type" = "West Dealer Price;Special Customer Price;West Wholesale Price;East Wholesale Price;";
- // "customer_sales_rep" = "";
- // "customer_state" = CO;
- // "customer_zipcode" = 80302;
- // };
- // mode = RM;
- // orderCode = MOB1608240002;
- // password = 123456;
- // "product_name" = "108239B-23,108239B-01";
- // result = 2;
- // user = EvanK;
- // }
- NSString *orderCode = [params objectForKey:@"orderCode"];
- NSString *product_name = [params objectForKey:@"product_name"];
- product_name = [self translateSingleQuote:product_name];
- NSArray *product_name_array = [product_name componentsSeparatedByString:@","];
-
- sqlite3 *db = [iSalesDB get_db];
-
- __block NSMutableString *product_id_string = [NSMutableString string];
- for (int i = 0; i < product_name_array.count; i++) {
- NSString *name = [product_name_array objectAtIndex:i];
-
- NSString *sql = [NSString stringWithFormat:@"select product_id from product where name = '%@';",name];
-
- [iSalesDB jk_query:sql db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- int product_id = sqlite3_column_int(stmt, 0);
- if (i == product_name_array.count - 1) {
- [product_id_string appendFormat:@"%d",product_id];
- } else {
- [product_id_string appendFormat:@"%d,",product_id];
- }
-
- }];
- }
-
- NSDictionary *newParams = @{
- @"product_id" : product_id_string,
- @"orderCode" : orderCode
- };
-
- [iSalesDB close_db:db];
-
-
-
- return [self offline_add2cart:[newParams mutableCopy]];
- }
- @end
|