| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131 |
- //
- // 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 "AppDelegate.h"
- #import "pdfCreator.h"
- #import "RASingleton.h"
- #import "QRCodeGenerator.h"
- #import "config.h"
- #import "ImageUtils.h"
- #import "RAConvertor.h"
- #import "ActiveViewController.h"
- #import "RANetwork.h"
- #import "RADataProvider.h"
- @interface OLDataProvider ()
- @end
- @implementation OLDataProvider
- +(NSString*) get_portfolio_price:(NSString*) contact_id item_id:(int) item_id price:(int)price_id db:(sqlite3*)db
- {
-
- NSString * sqlQuery = [NSString stringWithFormat:@"select decrypt(price) from model_price where item_id=%d and price_name in (select name from price where type=%d) ",item_id,price_id];
-
-
-
- NSString* ret=@"No Price.";
- 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 *price = (char*)sqlite3_column_text(statement, 0);
- if(price==nil)
- price="";
- NSString *nsprice = [[NSString alloc]initWithUTF8String:price];
- double dp= [nsprice doubleValue];
-
- ret=[NSString stringWithFormat:@"%.2f",dp];
-
-
- }
-
- sqlite3_finalize(statement);
- }
-
-
-
-
-
-
-
-
- return ret;
-
-
- // // [iSalesDB close_db:db];
- //
- // return nil;
- //// if(dprice==DBL_MAX)
- //// ret= nil;
- //// else
- //// ret= [NSNumber numberWithDouble:dprice];
- //// return ret;
- }
- + (NSString *)portfolio_img:(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
- sqlQuery = [NSString stringWithFormat:@"select i.url from model_image as i where item_id = %@ and i.type<=1 order by i.default_img desc, i.type desc limit 1;",item_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 *imgurl = (char*)sqlite3_column_text(statement, 0);
- if(imgurl==nil)
- imgurl="";
- NSString *nsimgurl = [[NSString alloc]initWithUTF8String:imgurl];
-
-
- ret=nsimgurl;
-
-
- }
-
- sqlite3_finalize(statement);
- }
- else
- {
- ret=@"";
- }
-
-
-
- // [iSalesDB close_db:db];
- // DebugLog(@"data string: %@",ret );
-
-
- return ret;
-
- }
- +(NSMutableDictionary*) prepare_portfolio_data:(NSMutableDictionary*) params
- {
-
- // assert(params[@"contact_id"]!=nil);
- assert(params[@"user"]!=nil);
-
- NSMutableDictionary* values=params[@"replaceValue"]; // 离线下发的参数
- //生成portfolio pdf需要的数据
- NSMutableDictionary* data = [[NSMutableDictionary alloc]init];
-
- data[@"npd_url"]=COMPANY_WEB;
-
- NSDateFormatter * formatter = [[NSDateFormatter alloc]init];
- [formatter setDateFormat:@"MMMM yyyy"];
- NSString* date = [formatter stringFromDate:[NSDate date]];
- data[@"create_month"]=date;
- data[@"company_name"]=COMPANY_FULL_NAME;
- data[@"catalog_name"]=params[@"catalog_name"];
- data[@"PAGE_INDEX"]=@"Page $.{CURRENT_PAGE}.$ of $.{TOTAL_PAGE}.$";
- data[@"TOTAL_PAGE"]=0;
- data[@"CURRENT_PAGE"]=0;
- NSMutableDictionary* grid = [[NSMutableDictionary alloc]init];
-
- BOOL show_group_by = [[params objectForKey:@"show_group_by"] boolValue];
- bool show_stockout=[params[@"show_stockout"] boolValue];
- NSString *sql = nil;
- // v1.90 more color
-
- NSString *group_by = @"";
-
- if(values==nil)
- {
- if (show_group_by) {
- group_by = @"group by b.product_group ";
- }
- sql=[NSString stringWithFormat:@"select a.product_id,a.name,a.description,a.price,a.sheet_discount,a.qty,a.is_percentage,a.item_id,a.fashion_id,a.line_note,a.percent,a._id,b.availability,b.color,b.legcolor,b.demension,b.seat_height,b.material,b.box_dim,b.volume,b.weight,stockuom,b.load_ability,b.fabric_content,b.assembling,b.made_in,b.more_color from (select _id, product_id,name,description,ifnull(sheet_price,'null') as price,sheet_discount,ifnull(available_qty,'null') as qty,percentage as is_percentage,item_id,fashion_id,line_note,percent from offline_portfolio where product_id in(%@)) a left join (select * from product where product_id in(%@)) b on a.product_id=b.product_id %@ order by a.name",params[@"product_ids"],params[@"product_ids"],group_by];
- }
- else
- {
- if (show_group_by) {
- group_by = @"group by product_group ";
- }
- sql=[NSString stringWithFormat:@"select product_id,name,description,null,null,null,null,item_id,null,null,null,-1,availability,color,legcolor,demension,seat_height,material,box_dim,volume,weight,stockuom,load_ability,fabric_content,assembling,made_in,more_color from product where product_id in(%@) %@ order by name",params[@"product_ids"],group_by];
- }
-
- __block NSMutableDictionary *dic = [NSMutableDictionary dictionary];
-
- // AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
-
- sqlite3 *db = [iSalesDB get_db];
- // NSDictionary *resultDic =
- [iSalesDB jk_query:sql db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- // [dic setValue:[NSNumber numberWithInteger:RESULT_TRUE] forKey:@"result"];
-
- int product_id = sqlite3_column_int(stmt, 0);
-
-
-
-
- // NSString *product_id_string = [NSString stringWithFormat:@"%d",product_id];
- NSString *name = [self textAtColumn:1 statement:stmt];
- NSString *description = [self textAtColumn:2 statement:stmt];
- double price = sqlite3_column_double(stmt, 3);
- NSString *s_price = [self textAtColumn:3 statement:stmt];
- double discount = sqlite3_column_double(stmt,4);
- int qty = sqlite3_column_int(stmt, 5);
- NSString *s_qty = [self textAtColumn:5 statement:stmt];
- int is_percentage = sqlite3_column_int(stmt, 6);
- NSString *s_is_percentage = [self textAtColumn:6 statement:stmt];
- int item_id = sqlite3_column_int(stmt, 7);
- // int fashion_id = sqlite3_column_int(stmt, 8);
- NSString *line_note = [self textAtColumn:9 statement:stmt];
- NSString *s_percent = [self textAtColumn:10 statement:stmt];
- double percent = sqlite3_column_double(stmt, 10);
- // int portfolio_id = sqlite3_column_int(stmt, 11);
- NSString *s_availability = [self textAtColumn:12 statement:stmt];
- int availability = sqlite3_column_int(stmt, 12);
- NSString *color = [self textAtColumn:13 statement:stmt];
-
- NSString *legcolor = [self textAtColumn:14 statement:stmt];
- NSString *demension = [self textAtColumn:15 statement:stmt];
- NSString *seat_height = [self textAtColumn:16 statement:stmt];
- NSString *material = [self textAtColumn:17 statement:stmt];
- NSString *box_dim = [self textAtColumn:18 statement:stmt];
- NSString *s_volume = [self textAtColumn:19 statement:stmt];
- double volume = sqlite3_column_double(stmt, 19);
- NSString *s_weight = [self textAtColumn:20 statement:stmt];
- double weight = sqlite3_column_double(stmt, 20);
- NSString *s_model_set = [self textAtColumn:21 statement:stmt];
- int model_set = sqlite3_column_int(stmt, 21);
-
- NSString *s_load_ability = [self textAtColumn:22 statement:stmt];
- double load_ability = sqlite3_column_double(stmt, 22);
- NSString *fabric_content = [self textAtColumn:23 statement:stmt];
- NSString *assembling = [self textAtColumn:24 statement:stmt];
- NSString *made_in = [self textAtColumn:25 statement:stmt];
- NSInteger more_color_int = sqlite3_column_int(stmt, 26);
-
-
- NSString* gprice = [self get_portfolio_price :params[@"contact_id"] item_id:item_id price:[params[@"regular_price"] intValue] db:db];
-
-
- float bprice=0;
- NSDictionary* bundle=[self model_bundle:item_id db:db compute_part:false contactID:params[@"contact_id"] user:params[@"user"]];
- for(int b=0;b< [bundle[@"count"] intValue];b++)
- {
- NSDictionary* bi=bundle[[NSString stringWithFormat:@"item_%d",b]];
- bprice+= [bi[@"modulus"] intValue] * [bi[@"unit_price"] floatValue];
-
- }
- if(gprice!=nil)
- gprice = [NSString stringWithFormat:@"%.2f",[gprice floatValue]+bprice];
-
-
-
-
-
-
-
- if(s_percent.length==0||is_percentage==0)
- {
- percent=100.0;
- if([s_qty isEqualToString:@"null"])
- qty=availability;
-
- }
- else
- {
- qty=availability;
- }
-
- qty=qty*percent/100+0.5;
-
-
- for(int i=0;i<[values[@"count"] intValue];i++)
- {
- NSMutableDictionary * valueitem=values[[NSString stringWithFormat:@"item_%d",i]];;
-
- if([valueitem[@"product_id"] intValue]==product_id)
- {
- line_note=valueitem[@"line_note"];
- qty=[valueitem[@"available_qty"] intValue];
- if([[valueitem allKeys] containsObject:@"available_qty"])
- s_qty=[NSString stringWithFormat:@"%d",qty];
- else
- s_qty=@"null";
- if(valueitem[@"regular_price"]!=nil)
- gprice=[NSString stringWithFormat:@"%.2f",[valueitem[@"regular_price"] floatValue]];
- s_price=valueitem[@"special_price"];
- price=[valueitem[@"special_price"] floatValue];
- discount=0;
- // v1.90
- more_color_int = [[valueitem objectForKey:@"more_color"] integerValue];
- }
- }
-
- if(is_percentage==0&&qty==0&&!show_stockout)
- {
- return;
- }
- if((is_percentage!=0||s_is_percentage.length!=0)&&qty==0&&!show_stockout)
- {
- return;
- }
-
- NSString* set_price=@"";
- if([params[@"entered_price"] boolValue])
- {
- if (s_price==nil ) {
- // set_price=[NSString stringWithFormat:@"Special: $ %@",gprice];
- }
- else
- {
- if(price*(1-discount/100.0)!=gprice.floatValue)
- set_price=[NSString stringWithFormat:@"Special: $ %.2f",price*(1-discount/100.0)];
- }
- }
-
- NSString* get_price=@"";
- {
-
- // NSNumber* price = [self get_model_default_price:appDelegate.contact_id product_id:nil item_id:@(item_id) db:db];
-
-
- // DebugLog(@"price time interval");
- // [self printTimeIntervalBetween:price_date and:[NSDate date]];
- if(gprice==nil)
- get_price=@"Price:No Price.";
- else
- get_price=[NSString stringWithFormat:@"Price: $ %@",gprice];
- }
- // NSString *qty_null = [self textAtColumn:5 statement:stmt];
- // if ([qty_null isEqualToString:@"null"]) {
- // qty=availability;
- // }
- //
- // NSString *qty_percent_null = [self textAtColumn:6 statement:stmt];
- // if ([qty_percent_null isEqualToString:@"null"]) {
- // percentage=1;
- // }
-
- NSString * str_availability=[NSString stringWithFormat:@"<b>Availability:</b> %d",(int)qty];
- NSString * str_color=[NSString stringWithFormat:@"<b>Color:</b> %@",color];
- NSString * str_model_set=[NSString stringWithFormat:@"<b>Set:</b> Sold in QTY of %d",model_set];
- NSString * str_legcolor=[NSString stringWithFormat:@"<b>Leg Color:</b> %@",legcolor];
- NSString * str_demension=[NSString stringWithFormat:@"<b>Dimension:</b> %@",demension];
- NSString * str_seat_height=[NSString stringWithFormat:@"<b>Seat Height:</b> %@",seat_height];
- NSString * str_meterial=[NSString stringWithFormat:@"<b>Meterial:</b> %@",material];
- NSString * str_box_dim=[NSString stringWithFormat:@"<b>Box Dimension:</b> %@",box_dim];
- NSString * str_volume=[NSString stringWithFormat:@"<b>Volume:</b> %.2f",volume];
- NSString * str_weight=[NSString stringWithFormat:@"<b>Weight:</b> %.2f",weight];
- NSString * str_load_ability=[NSString stringWithFormat:@"<b>Load Ability:</b> %.2f",load_ability];
- NSString * str_fabric_content=[NSString stringWithFormat:@"<b>Fabric Content:</b> %@",fabric_content];
- NSString * str_assembling=[NSString stringWithFormat:@"<b>Assembling:</b> %@",assembling];
- NSString * str_made_in=[NSString stringWithFormat:@"<b>Made In:</b> %@",made_in];
- NSString * str_line_note=[NSString stringWithFormat:@"<b>Line Note:</b> %@",line_note];
-
- if([params[@"availability"] boolValue]==false)
- str_availability=@"";
- else
- {
- if ([s_qty isEqualToString:@"null"] && [s_availability isEqualToString:@"0"])
- str_availability=@"<b>Availability:</b> In Production";
- }
-
- if([params[@"color"] boolValue]==false || color.length==0 )
- str_color=@"";
- if([params[@"set"] boolValue]==false || s_model_set.length==0 )
- str_model_set=@"";
- if([params[@"leg_color"] boolValue]==false || legcolor.length==0 )
- str_legcolor=@"";
- if([params[@"dimension"] boolValue]==false || demension.length==0 )
- str_demension=@"";
- if([params[@"seat_height"] boolValue]==false || seat_height.length==0 )
- str_seat_height=@"";
- if([params[@"material"] boolValue]==false || material.length==0 )
- str_meterial=@"";
- if([params[@"box_dimension"] boolValue]==false || box_dim.length==0 )
- str_box_dim=@"";
- if([params[@"volume"] boolValue]==false || s_volume.length==0 )
- str_volume=@"";
- if([params[@"weight"] boolValue]==false || s_weight.length==0 )
- str_weight=@"";
- if([params[@"load_ability"] boolValue]==false || s_load_ability.length==0 )
- str_load_ability=@"";
- if([params[@"fabric_content"] boolValue]==false || fabric_content.length==0 )
- str_fabric_content=@"";
- if([params[@"assembling"] boolValue]==false || assembling.length==0 )
- str_assembling=@"";
- if([params[@"made"] boolValue]==false || made_in.length==0 )
- str_made_in=@"";
- if([params[@"show_line_note"] boolValue]==false || line_note.length==0 )
- str_line_note=@"";
-
- NSMutableArray* arr_detail=[[NSMutableArray alloc]init];
-
- [arr_detail addObject:str_availability];
- [arr_detail addObject:str_color];
- [arr_detail addObject:str_model_set];
- [arr_detail addObject:str_legcolor];
- [arr_detail addObject:str_demension];
- [arr_detail addObject:str_seat_height];
- [arr_detail addObject:str_meterial];
- [arr_detail addObject:str_box_dim];
- [arr_detail addObject:str_volume];
- [arr_detail addObject:str_weight];
- [arr_detail addObject:str_load_ability];
- [arr_detail addObject:str_fabric_content];
- [arr_detail addObject:str_assembling];
- [arr_detail addObject:str_made_in];
- [arr_detail addObject:str_line_note];
-
-
- // NSString* detail =[NSString stringWithFormat:@"<font size=0.2>%@</font>",[RAUtils arr2string:arr_detail separator:@" " trim:true]];
- NSString* detail =[RAConvertor arr2string:arr_detail separator:@" " trim:true];
-
-
- //model image;
- NSString* img_path = [self portfolio_img:[NSString stringWithFormat:@"%@",[NSNumber numberWithInt:item_id]] db:db];
-
-
- // qr image
- NSString* qrpath=nil;
- if([params[@"show_barcode"] boolValue])
- {
- NSString* temp = NSTemporaryDirectory();
- NSString* filename =[NSString stringWithFormat:@"%@.png", [[NSUUID UUID] UUIDString]];
- qrpath=[temp stringByAppendingPathComponent:filename];
- UIImage* qrimg=[QRCodeGenerator qrImageForString:name imageSize:240];
- [UIImagePNGRepresentation(qrimg)writeToFile: qrpath atomically:YES];
- }
-
- NSString *more_color_path = [[NSBundle mainBundle] pathForResource:@"more_color_64" ofType:@"png"];
-
-
-
- NSMutableDictionary *item = [[NSMutableDictionary alloc] init];
- item[@"img"]=img_path;
- item[@"img_qr"]=qrpath;
- item[@"special_price"]=set_price;
- item[@"price"]=get_price;
- item[@"name"]=name;
- item[@"description"]=description;
- item[@"detail"]=detail;
- item[@"img"]=img_path;
- if (show_group_by && more_color_int != 0) {
- item[@"more_color"] = more_color_path;
- }
-
- // @{
- // //@"linenotes": line_note,
- //// @"product_id": product_id_string,
- //// @"available_qty": @(qty),
- //// @"available_percent" : @(percent),
- //// @"description": [NSString stringWithFormat:@"%@\n%@",name,description],
- //// @"item_id": [NSString stringWithFormat:@"%d",item_id],
- //// @"fashion_id": [NSString stringWithFormat:@"%d",product_id],
- // @"": ,
- // @"": ,
- // @"": ,
- // @"": ,
- // @"": ,
- // @"": ,
- // @"":
- // }.mutableCopy;
- // if (percentage) {
- // [item removeObjectForKey:@"available_qty"];
- // } else {
- // [item removeObjectForKey:@"available_percent"];
- // }
- //
- // NSString *qty_null = [self textAtColumn:5 statement:stmt];
- // if ([qty_null isEqualToString:@"null"]) {
- // [item removeObjectForKey:@"available_qty"];
- // }
-
-
- [dic setObject:item forKey:[NSString stringWithFormat:@"item_%ld",*count]];
- [dic setValue:[NSNumber numberWithLong:++(*count)] forKey:@"count"];
-
- }];
-
-
- [iSalesDB close_db:db];
-
-
-
- // [dic setValue:[NSNumber numberWithBool:appDelegate.can_see_price] forKey:@"can_see_price"];
- // [dic setValue:@"" forKey:@"email_content"];
- // [dic setValue:[dic objectForKey:@"count"] forKey:@"total_count"];
- // [dic setValue:@"Regular Mode" forKey:@"mode"];
- //
-
-
- // NSMutableDictionary* cell = [[NSMutableDictionary alloc]init];
- // cell[@"count"]=[NSNumber numberWithInt:10];
- grid[@"cell0"]=dic;
- data[@"grid0"]=grid;
- return data;
- }
- +(NSMutableDictionary*) get_pdftemplate:(NSString*) template
- {
- NSString *default_path = [[NSBundle mainBundle] pathForResource:template ofType:nil];
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
- NSString *cache_folder=[paths objectAtIndex:0];
-
- NSString *template_path = [cache_folder stringByAppendingPathComponent:[NSString stringWithFormat:@"offline_data/%@",template]];
- BOOL bdir=NO;
- NSFileManager* fileManager = [NSFileManager defaultManager];
- if(PDF_DEBUG)
- {
- NSData *data = [NSData dataWithContentsOfFile:default_path];
- NSMutableDictionary *ret = [[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil] mutableCopy];
- return ret;
- }
- if(! [fileManager fileExistsAtPath:template_path isDirectory:&bdir] )
- {
-
- NSError * error=nil;
- if(![fileManager copyItemAtPath:default_path toPath:template_path error:&error])
- {
- return nil;
- }
- }
-
-
- NSData *data = [NSData dataWithContentsOfFile:template_path];
- NSMutableDictionary *ret = [[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil] mutableCopy];
- return ret;
- }
- +(NSMutableDictionary*) query_login:(NSString*) user db:(sqlite3*) db
- {
-
-
-
-
-
-
- NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
-
-
-
-
-
-
-
- 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,first_name from offline_login where lower(username)='%@' ",user.lowercaseString ];
-
-
-
-
- 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);
-
-
- char *first_name = (char*)sqlite3_column_text(statement, 14);
- if(first_name==nil)
- first_name="";
- NSString *nsfirst_name= [[NSString alloc]initWithUTF8String:first_name];
-
- // [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"];
- //
- //
- //
- // int wish_count = [iSalesDB get_recordcount:db table:@"wishlist" where:@"is_delete is NULL or is_delete != 1"];
- // [header setObject:[NSString stringWithFormat:@"%d",wish_count] forKey:@"wish_count"];
- //
- // // int portfolio_count = [iSalesDB get_recordcount:db table:@"portfoliolist" where:@"1=1"];
- // // [header setObject:[NSString stringWithFormat:@"%d",wish_count] forKey:@"portfolio_count"];
- // int portfolio_count = [iSalesDB get_recordcount:db table:@"offline_portfolio" where:@"is_delete is NULL or is_delete != 1"];
- // [header setObject:[NSString stringWithFormat:@"%d",portfolio_count] forKey:@"portfolio_count"];
- //
- // [ret setObject:header forKey:@"header"];
- [ret setValue:nsfirst_name forKey:@"first_name"];
-
-
-
- }
-
-
-
- sqlite3_finalize(statement);
- }
-
-
-
-
-
- DebugLog(@"data string: %@",[RAConvertor dict2string:ret] );
-
- return ret;
- }
- +(NSMutableDictionary*) prepare_salesorder_data:(NSString*) order_code user:(NSString*) user type:(int) type
- {
-
- assert(user!=nil);
- // AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
-
-
- NSMutableDictionary* data = [[NSMutableDictionary alloc]init];
- data[@"npd_url"]=COMPANY_WEB;
- NSDateFormatter * formatter = [[NSDateFormatter alloc]init];
- [formatter setDateFormat:@"MM/dd/yyyy HH:mm:ss"];
- NSString* date = [formatter stringFromDate:[NSDate date]];
- data[@"print_date"]=date;
- data[@"company_name"]=COMPANY_FULL_NAME;
- data[@"PAGE_INDEX"]=@"Page $.{CURRENT_PAGE}.$ of $.{TOTAL_PAGE}.$";
- data[@"TOTAL_PAGE"]=0;
- data[@"CURRENT_PAGE"]=0;
-
- // [formatter setDateFormat:@"MM/dd/yyyy"];
- // date = [formatter stringFromDate:[NSDate date]];
- // data[@"creat_date"]=date;
- NSString* temp = NSTemporaryDirectory();
- NSString* filename =[NSString stringWithFormat:@"%@.png", [[NSUUID UUID] UUIDString]];
- NSString* qrpath=[temp stringByAppendingPathComponent:filename];
- UIImage* qrimg=[ImageUtils generateBarCode:order_code width:480 height:44];//[QRCodeGenerator qrImageForString:order_code imageSize:240];
- // bool bwrite=
- [UIImagePNGRepresentation(qrimg)writeToFile: qrpath atomically:YES];
- data[@"img_barcode"]=qrpath;
- data[@"so_id"]=order_code;
- data[@"company"]=COMPANY_FULL_NAME;
-
-
-
- // 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,o.editable,o.lift_null,o.handling_null,o.ship_via 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,order_id is null as editable,lift_gate_value is null as lift_null,handling_fee_value is null as handling_null,ship_via from offline_order where so_id=%@) o left join offline_contact c on o.customer_cid=c.contact_id",order_code];
- NSString *sql = [NSString stringWithFormat:@"select erpOrderStatus,sender_name,sender_ext,sender_phone,sender_fax,sender_email,warehouse_name,billing_name,billing_ext,billing_phone,billing_fax,billing_email,receive_name,receive_ext,receive_phone,receive_fax,receive_email,poNumber,sales_rep,carrier,vendor_no,terms,sales_terms,port_destination,etd,sign_picpath,status,create_time,shipping,lift_gate_value,handling_fee_value,billing_contact,receive_contact,general_notes,customer_cid from offline_order where so_id='%@'",order_code];
- sqlite3 *db = [iSalesDB get_db];
-
- data[@"print_by"]= [self query_login:user db:db][@"first_name"];
- sqlite3_stmt * statement;
-
-
- NSMutableDictionary* datasource = [[NSMutableDictionary alloc]init];
-
- NSMutableDictionary* row0 = [[NSMutableDictionary alloc]init];
- row0[@"count"]=[NSNumber numberWithInt:1];
-
- datasource[@"row0"]=row0;
- NSString* print_status=@"";
- NSString* order_type=@"Offline Quote";
- if (sqlite3_prepare_v2(db, [sql UTF8String], -1, &statement, nil) == SQLITE_OK)
- {
-
-
- if (sqlite3_step(statement) == SQLITE_ROW)
- {
-
- int erpOrderStatus = sqlite3_column_int(statement, 0);
- int status = sqlite3_column_int(statement, 26);
-
- if(status==2)
- {
- switch (erpOrderStatus) {
- case 10:
- // order_type=@"Quoted Order";
- print_status=@"Quote";
- break;
- case 11:
- print_status=@"Booked";
- break;
- case 12:
- print_status=@"Picked";
- break;
- case 13:
- print_status=@"Shipped";
- break;
- case 14:
- print_status=@"Closed";
- break;
- case 15:
- print_status=@"Canceled";
- break;
- case 16:
- print_status=@"All";
- break;
- case 18:
- print_status=@"Processing";
- break;
-
- default:
- break;
- }
-
-
- }
- else{
-
-
- switch (status) {
- case 0:
- {
- print_status=@"Quote";
- break;
- }
- case 1:
- {
- print_status=@"Saved";
- break;
- }
- case 3:
- {
- //canceled
- print_status=@"Canceled";
- break;
- }
-
- default:
- break;
- }
- }
- NSString* sender_name = [self textAtColumn:1 statement:statement];
- NSString* sender_ext = [self textAtColumn:2 statement:statement];
- NSString* sender_phone = [self textAtColumn:3 statement:statement];
- NSString* sender_fax = [self textAtColumn:4 statement:statement];
- NSString* sender_email = [self textAtColumn:5 statement:statement];
-
- NSString* warehouse_name = [self textAtColumn:6 statement:statement];
-
- NSString* billing_name = [self textAtColumn:7 statement:statement];
- NSString* billing_ext = [self textAtColumn:8 statement:statement];
- NSString* billing_phone = [self textAtColumn:9 statement:statement];
- if(billing_phone.length>0)
- billing_phone= [@"TEL: " stringByAppendingString:billing_phone];
- NSString* billing_fax = [self textAtColumn:10 statement:statement];
- if(billing_fax.length>0)
- billing_fax= [@"FAX: " stringByAppendingString:billing_fax];
- NSMutableArray* billto_arr0 = [[NSMutableArray alloc]init];
- [billto_arr0 addObject:billing_phone];
- [billto_arr0 addObject:billing_fax];
- NSString* billing_pf=[RAConvertor arr2string:billto_arr0 separator:@" " trim:true];
- NSString* billing_email = [self textAtColumn:11 statement:statement];
- if(billing_email.length>0)
- billing_email= [@"EMAIL: " stringByAppendingString:billing_email];
- NSString* billing_contact = [self textAtColumn:31 statement:statement];
- if(billing_contact.length>0)
- billing_contact= [@"ATTN: " stringByAppendingString:billing_contact];
-
- NSString* receive_name = [self textAtColumn:12 statement:statement];
- NSString* receive_ext = [self textAtColumn:13 statement:statement];
- NSString* receive_phone = [self textAtColumn:14 statement:statement];
- if(receive_phone.length>0)
- receive_phone= [@"TEL: " stringByAppendingString:receive_phone];
- NSString* receive_fax = [self textAtColumn:15 statement:statement];
- if(receive_fax.length>0)
- receive_fax= [@"FAX: " stringByAppendingString:receive_fax];
- NSMutableArray* receive_arr0 = [[NSMutableArray alloc]init];
- [receive_arr0 addObject:receive_phone];
- [receive_arr0 addObject:receive_fax];
- NSString* receive_email = [self textAtColumn:16 statement:statement];
- NSString* receive_pf=[RAConvertor arr2string:billto_arr0 separator:@" " trim:true];
-
- if(receive_email.length>0)
- receive_email= [@"EMAIL: " stringByAppendingString:receive_email];
- NSString* receive_contact = [self textAtColumn:32 statement:statement];
- if(receive_contact.length>0)
- receive_contact= [@"ATTN: " stringByAppendingString:receive_contact];
-
- NSString* poNumber = [self textAtColumn:17 statement:statement];
- NSString* sales_rep = [self textAtColumn:18 statement:statement];
- NSString* carrier = [self textAtColumn:19 statement:statement];
- NSString* vendor_no = [self textAtColumn:20 statement:statement];
- NSString* terms = [self textAtColumn:21 statement:statement];
- NSString* sales_terms = [self textAtColumn:22 statement:statement];
- NSString* port_destination = [self textAtColumn:23 statement:statement];
- NSString* etd = [self textAtColumn:24 statement:statement];
- NSString* sign_picpath = [self textAtColumn:25 statement:statement];
- if(sign_picpath.length==0)
- sign_picpath=nil;
- NSString* create_date = [self textAtColumn:27 statement:statement];
- create_date=[self changeDateTime:create_date Formate:@"yyyy-MM-dd HH:mm:ss" withFormate:@"MM/dd/yyyy"];
-
- NSString* general_notes=[self textAtColumn:33 statement:statement];
- NSString *customerID = [self textAtColumn:34 statement:statement];
- if (customerID.length == 0) {
- customerID = nil;
- }
-
- // itemjson[@"ln#"]=[NSString stringWithFormat:@"%d.%d",count+1,1];
- // fee_row0[@"item_0"]=@{@"name":@"Payments/Credits:" ,@"value": [NSString stringWithFormat:@"%.2f",credits]};
-
- if(general_notes.length>0)
- {
- NSMutableDictionary* row2 = [[NSMutableDictionary alloc]init];
- row2[@"item_0"]=@{@"g_notes":general_notes };
- row2[@"count"]=[NSNumber numberWithInt:1];
- datasource[@"row2"]=row2;
- }
-
-
-
-
- NSMutableArray* billto_arr = [[NSMutableArray alloc]init];
- [billto_arr addObject:billing_ext];
- [billto_arr addObject:billing_pf];
- [billto_arr addObject:billing_contact];
- [billto_arr addObject:billing_email];
- NSString* billto=[RAConvertor arr2string:billto_arr separator:@"\r\n" trim:true];
-
-
- NSMutableArray* receive_arr = [[NSMutableArray alloc]init];
- [receive_arr addObject:receive_ext];
- [receive_arr addObject:receive_pf];
- [receive_arr addObject:receive_contact];
- [receive_arr addObject:receive_email];
- NSString* receive=[RAConvertor arr2string:receive_arr separator:@"\r\n" trim:true];
-
- float shipping = sqlite3_column_double(statement, 28);
- float lift_gate_value = sqlite3_column_double(statement, 29);
- float handling_fee_value = sqlite3_column_double(statement, 30);
-
-
- data[@"company"]=sender_name;
- data[@"shipfrom_addr"]=sender_ext;
- data[@"shipfrom_phone"]=sender_phone;
- data[@"shipfrom_fax"]=sender_fax;
- data[@"shipfrom_email"]=sender_email;
-
- data[@"warehouse_name"]=warehouse_name;
-
- data[@"bill_to_name"]=billing_name;
- data[@"bill_to_ext"]=billto;
-
- data[@"ship_to_name"]=receive_name;
- data[@"ship_to_ext"]=receive;
-
- data[@"po_no"]=poNumber;
- data[@"rep"]=sales_rep;
- data[@"e_schdule"]=etd;
- data[@"sales_terms"]=sales_terms;
- data[@"port_destination"]=port_destination;
- data[@"terms"]=terms;
- data[@"truck_carrier"]=carrier;
- data[@"vendor_no"]=vendor_no;
- data[@"customer_sign"]=sign_picpath;
- data[@"print_status"]=print_status;
- data[@"create_date"]=create_date;
-
-
- NSString *sql_cart=[ 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,modify_time from offline_cart where so_no='%@') c left join product m on c.product_id=m.product_id ",order_code];;
- sqlite3_stmt * statement_cart;
-
-
- // NSDate *date1 = [NSDate date];
-
- int count=0;
- // int cart_count=0;
- float credits=0;
- int dbresult=sqlite3_prepare_v2(db, [sql_cart UTF8String], -1, &statement_cart, nil);
- if ( dbresult== SQLITE_OK)
- {
- NSMutableDictionary* row1 = [[NSMutableDictionary alloc]init];
- int row1count=0;
-
- while (sqlite3_step(statement_cart) == SQLITE_ROW)
- {
- // NSDate *row_date = [NSDate date];
-
-
- NSMutableDictionary* itemjson = [[NSMutableDictionary alloc] init];
-
-
-
-
- // int product_id = sqlite3_column_int(statement_cart, 0);
-
- char *str_price = (char*)sqlite3_column_text(statement_cart, 1);
-
- int item_id = sqlite3_column_int(statement_cart, 7);
- double discount = sqlite3_column_double(statement_cart, 2);
- NSString* Price=nil;
- if(str_price==nil)
- {
- // NSNumber* price= [self get_model_default_price:appDelegate.contact_id product_id:product_id db:db];
- // NSDate *price_date = [NSDate date];
- NSNumber* price = [self get_model_default_price:customerID user:user product_id:nil item_id:@(item_id) db:db];
- // DebugLog(@"price time interval");
- // [self printTimeIntervalBetween:price_date and:[NSDate date]];
-
- if(price==nil)
- Price=@"No Price.";
- else
- Price=[NSString stringWithFormat:@"%.2f",price.floatValue];
- }
- else
- {
-
- Price=[NSString stringWithFormat:@"%.2f",[[[NSString alloc]initWithUTF8String:str_price] floatValue]];
- }
- float dunitprice=0;
- int item_count = sqlite3_column_int(statement_cart, 3);
-
- NSString* Amount=@"";
- if(![Price isEqualToString:@"No Price."])
- {
- dunitprice=[Price floatValue];
- dunitprice=dunitprice* (1-discount/100.0);
- Price=[NSString stringWithFormat:@"%.2f",dunitprice];
- credits+=dunitprice*item_count;
- Amount=[NSString stringWithFormat:@"%.2f",dunitprice*item_count];
- }
- else
- {
- Price=@"";
- }
-
-
-
-
- // char *line_note = (char*)sqlite3_column_text(statement_cart, 4);
- // NSString *nsline_note=nil;
- // if(line_note!=nil)
- // nsline_note= [[NSString alloc]initWithUTF8String:line_note];
-
-
- char *name = (char*)sqlite3_column_text(statement_cart, 5);
- NSString *nsname=nil;
- if(name!=nil)
- nsname= [[NSString alloc]initWithUTF8String:name];
-
- char *description = (char*)sqlite3_column_text(statement_cart, 6);
- NSString *nsdescription=nil;
- if(description!=nil)
- nsdescription= [[NSString alloc]initWithUTF8String:description];
-
-
-
- // int stockUom = sqlite3_column_int(statement_cart, 8);
- // int _id = sqlite3_column_int(statement_cart, 9);
-
- // NSDate *subtotal_date = [NSDate date];
- // NSDictionary* bsubtotaljson=[self model_subtotal:item_id count:item_count db:db compute_part:true];
- // DebugLog(@"subtotal_date time interval");
- // [self printTimeIntervalBetween:subtotal_date and:[NSDate date]];
-
- // double cuft=[bsubtotaljson[@"cuft"] doubleValue];
- // double weight=[bsubtotaljson[@"weight"] doubleValue];
- // int carton=[bsubtotaljson[@"carton"] intValue];
- // cart_count+=[bsubtotaljson[@"items"] allKeys].count;
-
- // itemjson[@"img_url"]= [self model_category_img:[NSString stringWithFormat:@"%@",[NSNumber numberWithInt:item_id]] model_name:nil db:db];
- // NSDate *img_date = [NSDate date];
- itemjson[@"img_url"] = [self item_image:[NSString stringWithFormat:@"%@",[NSNumber numberWithInt:item_id]] db:db];
- // DebugLog(@"img_date time interval");
- // [self printTimeIntervalBetween:img_date and:[NSDate date]];
-
- 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"]=[NSString stringWithFormat:@"%d",item_count];
- itemjson[@"unit_price"]=Price;
- itemjson[@"amount"]=Amount;
- // itemjson[@"discount"]=[NSNumber numberWithInt:discount];
- itemjson[@"description"]=[NSString stringWithFormat:@"%@",nsdescription ];
- // itemjson[@"stockUom"]=[NSNumber numberWithInt:stockUom];
- // itemjson[@"note"]=nsline_note;
-
- // NSDate *date2 = [NSDate date];
- // itemjson[@"combine"]=[self model_bundle:item_id db:db compute_part:false];
- // DebugLog(@"model_bundle time interval");
- // [self printTimeIntervalBetween:date2 and:[NSDate date]];
-
- itemjson[@"ln#"]=[NSString stringWithFormat:@"%d.%d",count+1,1];
- row1[[NSString stringWithFormat:@"item_%d", row1count] ]=itemjson;
- row1count++;
- NSDictionary* combine =[self model_bundle:item_id db:db compute_part:false contactID:customerID user:user];
- for(int c=0;c<[combine[@"count"] intValue];c++)
- {
- NSMutableDictionary* combine_item=[combine[[NSString stringWithFormat:@"item_%d",c]] mutableCopy];
- combine_item[@"count"]=[NSString stringWithFormat:@"%d",[combine_item[@"modulus"] intValue]*item_count];
- // combine_item[@"count"]=[NSNumber numberWithInt:[combine_item[@"modulus"] intValue]*item_count];
-
- double combine_amount=[combine_item[@"modulus"] intValue]*item_count* [combine_item[@"unit_price"] floatValue];
- credits+=combine_amount;
- combine_item[@"amount"]=[NSString stringWithFormat:@"%.2f",combine_amount];
- combine_item[@"ln#"]=[NSString stringWithFormat:@"%d.%d",count+1,c+2];
- row1[[NSString stringWithFormat:@"item_%d", row1count] ]=combine_item;
- row1count++;
- }
- count++;
-
- // DebugLog(@"row time interval");
- // [self printTimeIntervalBetween:row_date and:[NSDate date]];
- }
-
- row1[@"count"]=[NSNumber numberWithInt:row1count];
-
- datasource[@"row1"]=row1;
- data[@"table_model"]=datasource;
- sqlite3_finalize(statement_cart);
- }
-
-
- NSMutableDictionary* fee = [[NSMutableDictionary alloc]init];
-
- NSMutableDictionary* fee_row0 = [[NSMutableDictionary alloc]init];
-
- // itemjson[@"ln#"]=[NSString stringWithFormat:@"%d.%d",count+1,1];
- // fee_row0[@"item_0"]=@{@"name":@"Payments/Credits:" ,@"value": [NSString stringWithFormat:@"%.2f",credits]};
-
- // if(credits>0)
- fee_row0[@"item_0"]=@{@"name":@"Payments/Credits:" ,@"value": [NSString stringWithFormat:@"%.2f",credits]};
- // else
- // fee_row0[@"item_0"]=@{@"name":@"Payments/Credits:" ,@"value": @""};
-
- if(shipping>0)
- fee_row0[@"item_1"]=@{@"name":@"Shipping:" ,@"value": [NSString stringWithFormat:@"%.2f",shipping]};
- else
- fee_row0[@"item_1"]=@{@"name":@"Shipping:" ,@"value": @""};
-
- if(lift_gate_value>0)
- fee_row0[@"item_2"]=@{@"name":@"Lift Gate Fee:" ,@"value": [NSString stringWithFormat:@"%.2f",lift_gate_value]};
- else
- fee_row0[@"item_2"]=@{@"name":@"Lift Gate Fee:" ,@"value": @""};
-
- if(handling_fee_value>0)
- fee_row0[@"item_3"]=@{@"name":@"Handling Fee:" ,@"value": [NSString stringWithFormat:@"%.2f",handling_fee_value]};
- else
- fee_row0[@"item_3"]=@{@"name":@"Handling Fee:" ,@"value": @""};
-
- float total = credits+shipping+lift_gate_value+handling_fee_value;
-
- if(total>0)
- fee_row0[@"item_4"]=@{@"name":@"Total:" ,@"value": [NSString stringWithFormat:@"%.2f",total]};
- else
- fee_row0[@"item_4"]=@{@"name":@"Total:" ,@"value": @""};
-
- fee_row0[@"count"]=[NSNumber numberWithInt:5];
- fee[@"row0"]=fee_row0;
- data[@"table_fee"]=fee;
- // 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];
- //
- //
- // int offline_edit=sqlite3_column_int(statement, 56);
- //
- // ret[@"offline_edit"]= [NSNumber numberWithInt:offline_edit];
- //
- // 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];
- // if (status == -11 || status == 10 || status == 11) {
- // nslogist = [self textAtColumn:59 statement:statement];
- // };
- //
- // 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];
- // if (sqlite3_column_int(statement, 57)) {
- // ret[@"Liftgate Fee(No loading dock)"] = @"Shipping To Be Quoted";
- // }
- //
- // 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"];
- //
- //
- // // 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];
- //
- //
- // // 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];
- //
- //
- // // 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];
- //
- //
- // // 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];
- //
- //
- // // 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];
- // if (sqlite3_column_int(statement, 58)) {
- // ret[@"Handling Fee"] = @"Shipping To Be Quoted";
- // }
- // //
- //
- // // 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];
-
-
- data[@"order_type"]=order_type;
- /*
- 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];
- // DebugLog(@"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 [RAConvertor dict2data:ret];
- */
- DebugLog(@"debug sales order data:%@", [RAConvertor dict2string:data]);
- return data;
- }
- +(NSData*) offline_request_salesorder :(NSMutableDictionary *) params
- {
- assert(params[@"user"]!=nil);
- NSString* template_file=nil;
- switch([params[@"thumb"] intValue])
- {
- case 0:
- template_file= @"so.json";
- break;
- case 1:
- template_file= @"so_thumb.json";
- break;
- default:
- template_file= @"so.json";
- }
-
- NSMutableDictionary* data = [self prepare_salesorder_data:params[@"order_code"] user:params[@"user"] type:[params[@"thumb"] intValue]];
- NSMutableDictionary* template = [self get_pdftemplate:template_file];
- if(data[@"table_model"][@"row2"]==nil)
- template[@"pages"][@"page_0"][@"contents"][@"item_0"][@"rows"][@"count"]=[NSNumber numberWithInt:1];
- NSString* file=[pdfCreator CreatePdf: template dataSource:data];
- DebugLog(@"%@",file);
- // return nil;
- NSMutableDictionary *dic = [NSMutableDictionary dictionary];
- [dic setObject:@"Regular Mode" forKey:@"mode"];
- if (file) {
- [dic setObject:[NSNumber numberWithInteger:RESULT_TRUE] forKey:@"result"];
- [dic setObject:file forKey:@"pdf_path"];
- dic[@"isLocalFile"]=@"true";
- return [RAConvertor dict2data:dic];
- }
- [dic setObject:[NSNumber numberWithInteger:RESULT_FALSE] forKey:@"result"];
- dic[@"isLocalFile"]=@"true";
- return [RAConvertor dict2data:dic];
- }
- +(NSData*) offline_request_tearsheet :(NSMutableDictionary *) params
- {
-
- // assert(params[@"contact_id"]!=nil);
- // assert(params[@"user"]!=nil);
-
-
-
- if(params[@"user"]==nil)
- {
- AppDelegate *appDelegate = nil;
-
-
- //some UI methods ej
- appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
-
-
-
- if(appDelegate.user!=nil)
- [params setValue:appDelegate.user forKey:@"user"];
- }
-
-
- NSString* template_file=nil;
- switch([params[@"pdf_style"] intValue])
- {
- case 0:
- template_file= @"portfolio_2x3.json";
- break;
- case 1:
- template_file= @"portfolio_3x2.json";
- break;
- default:
- template_file= @"portfolio_3x2.json";
- }
-
- NSMutableDictionary* data = [self prepare_portfolio_data:params];
- NSMutableDictionary* template = [self get_pdftemplate:template_file];
-
- NSString* file=[pdfCreator CreatePdf: template dataSource:data];
- DebugLog(@"%@",file);
-
- NSMutableDictionary *dic = [NSMutableDictionary dictionary];
- [dic setObject:@"Regular Mode" forKey:@"mode"];
- if (file) {
- [dic setObject:[NSNumber numberWithInteger:RESULT_TRUE] forKey:@"result"];
- [dic setObject:file forKey:@"pdf_path"];
- dic[@"isLocalFile"]=@"true";
- return [RAConvertor dict2data:dic];
- }
- [dic setObject:[NSNumber numberWithInteger:RESULT_FALSE] forKey:@"result"];
- dic[@"isLocalFile"]=@"true";
- return [RAConvertor dict2data:dic];
- }
- +(NSString*) get_offline_soid:(sqlite3*)db
- {
- NSString* soid=nil;
-
-
- NSDateFormatter* formatter = [[NSDateFormatter alloc]init];
- [formatter setDateFormat:@"yyMMdd"];
- NSString* date = [formatter stringFromDate:[NSDate date]];
- for(int i=1;i<999;i++)
- {
-
- soid=[NSString stringWithFormat:@"OFF%@%4d",date,i];
- soid= [soid stringByReplacingOccurrencesOfString:@" " withString:@"0"];
- int count=[iSalesDB get_recordcount:db table:@"offline_order" where:[NSString stringWithFormat:@"so_id='%@'",soid]];
- if(count==0)
- return soid;
-
-
- }
- return nil;
- }
- +(NSArray*) enumOfflineOrder
- {
-
- NSMutableArray* ret = [[NSMutableArray alloc] init];
- sqlite3 *db = [iSalesDB get_db];
-
- NSString *sqlQuery =@"select so_id from offline_order where status=-11;";
- 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) saveScanSubmitList:(NSMutableDictionary*) submitlist
- {
-
- if(submitlist==nil)
- return;
-
- NSString *userdir = [OLDataProvider getUserPath];
- NSString *submitlistPath = [userdir stringByAppendingPathComponent:@"submitlist.json"];
-
- [RAUtils dicttofile:submitlistPath dict:submitlist];
- }
- +(void) saveScanOrderList:(NSMutableDictionary*) orderlist
- {
-
- if(orderlist==nil)
- return;
-
- NSString *userdir = [OLDataProvider getUserPath];
- NSString *orderlistPath = [userdir stringByAppendingPathComponent:@"orderlist.json"];
-
- [RAUtils dicttofile:orderlistPath dict:orderlist];
- }
- +(NSMutableDictionary*) getScanSubmitList
- {
- NSString *userdir = [OLDataProvider getUserPath];
- NSString *submitlistPath = [userdir stringByAppendingPathComponent:@"submitlist.json"];
- NSMutableDictionary* submitlist = nil;
- if (![[NSFileManager defaultManager] fileExistsAtPath:submitlistPath]) {
-
- submitlist = [NSMutableDictionary new];
-
-
- }
- else
- {
- submitlist=[[RAUtils dictfromfile:submitlistPath] mutableCopy];
-
-
- }
- return submitlist;
- }
- //+(NSMutableDictionary*) getScanOrderList:(NSString*)userdir{
- //// NSString *userdir = [self getUserPath:user];
- // NSMutableDictionary* orderlist = nil;
- // NSString *orderlistPath = [userdir stringByAppendingPathComponent:@"orderlist.json"];
- //
- // if (![[NSFileManager defaultManager] fileExistsAtPath:orderlistPath]) {
- //
- //
- // orderlist = [NSMutableDictionary new];
- //
- // // [orderlist addObject:appDelegate.order_code];
- // // [RAUtils dicttofile:orderlistPath dict:orderlist];
- //
- // }
- // else
- // {
- // orderlist=[[RAUtils dictfromfile:orderlistPath] mutableCopy];
- //
- // // [orderlist insertObject:appDelegate.order_code atIndex:0];
- //
- // // [RAUtils dicttofile:orderlistPath dict:orderlist];
- // }
- // return orderlist;
- //}
- +(NSMutableDictionary*) getScanOrderList{
- NSString *userdir = [OLDataProvider getUserPath];
- NSMutableDictionary* orderlist = nil;
- NSString *orderlistPath = [userdir stringByAppendingPathComponent:@"orderlist.json"];
-
- if (![[NSFileManager defaultManager] fileExistsAtPath:orderlistPath]) {
-
-
- orderlist = [NSMutableDictionary new];
-
- // [orderlist addObject:appDelegate.order_code];
- // [RAUtils dicttofile:orderlistPath dict:orderlist];
-
- }
- else
- {
- orderlist=[[RAUtils dictfromfile:orderlistPath] mutableCopy];
-
- // [orderlist insertObject:appDelegate.order_code atIndex:0];
-
- // [RAUtils dicttofile:orderlistPath dict:orderlist];
- }
- return orderlist;
- }
- +(void) save2submitScanOrder:(NSString*) soid company:(NSString*) company
- {
-
- // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- // NSString *documents = [paths objectAtIndex:0];
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-
-
- // NSString *userdir = [OLDataProvider getUserPath];
- NSMutableDictionary* orderlist = [self getScanOrderList];
- // NSString *orderlistPath = [userdir stringByAppendingPathComponent:@"orderlist.json"];
-
- int count = [orderlist[@"count"] intValue];
- if(count==0)
- {
- // order list 为空,不用维护
- #ifdef RA_NOTIFICATION
- [ActiveViewController Notify:@"CartViewController,ScanOrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
- #else
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
- #endif
- return;
- }
-
- // if (![[NSFileManager defaultManager] fileExistsAtPath:orderlistPath]) {
- //
- // // order list 为空,不用维护
- //
- //
- // // [orderlist addObject:appDelegate.order_code];
- // // [RAUtils dicttofile:orderlistPath dict:orderlist];
- //
- // }
- // else
- // {
- // orderlist=[[RAUtils dictfromfile:orderlistPath] mutableCopy];
- //
- // // [orderlist insertObject:appDelegate.order_code atIndex:0];
- //
- // // [RAUtils dicttofile:orderlistPath dict:orderlist];
- // }
-
-
- //==================== order list 删除
-
-
- NSMutableDictionary* newlist = [NSMutableDictionary new];
- NSMutableDictionary* submititem =nil;
-
- int newcount = 0;
- for(int i=0;i<count;i++)
- {
- NSMutableDictionary* item = orderlist[[NSString stringWithFormat:@"item_%d",i]];
- if([item[@"order_code"] isEqualToString: appDelegate.order_code ])
- {
- submititem = item;
- continue;
- }
- else
- {
- newlist[[NSString stringWithFormat:@"item_%d",newcount]] = item;
- newcount++;
- }
- }
-
- if(submititem==nil)
- {
- //order list 里没有和当前打开的order code一致的order
- //这种情况往往是因为重复点提交按钮,order已关闭。
- return;
- }
- newlist[@"count"] = @(newcount);
-
- [self saveScanOrderList:newlist];
- // [RAUtils dicttofile:orderlistPath dict:newlist];
-
-
-
- //////////////////---=============================== submitlist 添加
- // NSString *submitlistPath = [userdir stringByAppendingPathComponent:@"submitlist.json"];
-
- NSMutableDictionary* submitlist = [OLDataProvider getScanSubmitList];
- // if (![[NSFileManager defaultManager] fileExistsAtPath:submitlistPath]) {
- //
- // submitlist = [NSMutableDictionary new];
- //
- //
- // }
- // else
- // {
- // submitlist=[[RAUtils dictfromfile:submitlistPath] mutableCopy];
- //
- //
- // }
- int submitcount =[submitlist[@"count"] intValue];
- submititem[@"order_status"] = soid;//@"Submitted Order";
- submititem[@"customer_name"] = company;//@"Submitted Order";
-
- submitlist[[NSString stringWithFormat:@"item_%d",submitcount]]=submititem;
- submitlist[@"count"] = @(submitcount+1);
- // [RAUtils dicttofile:submitlistPath dict:submitlist];
- [self saveScanSubmitList:submitlist];
-
- #ifdef RA_NOTIFICATION
- [ActiveViewController Notify:@"CartViewController,ScanOrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
- #else
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
- #endif
-
- }
- +(void) save2submitScanOrder1
- {
-
- // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- // NSString *documents = [paths objectAtIndex:0];
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-
-
- // NSString *userdir = [OLDataProvider getUserPath];
- NSMutableDictionary* orderlist = [self getScanOrderList];
- // NSString *orderlistPath = [userdir stringByAppendingPathComponent:@"orderlist.json"];
-
- int count = [orderlist[@"count"] intValue];
- if(count==0)
- {
- // order list 为空,不用维护
- #ifdef RA_NOTIFICATION
- [ActiveViewController Notify:@"CartViewController,ScanOrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
- #else
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
- #endif
- return;
- return;
- }
-
-
- NSMutableDictionary* newlist = [NSMutableDictionary new];
-
-
- int newcount = 0;
- for(int i=0;i<count;i++)
- {
- NSMutableDictionary* item = orderlist[[NSString stringWithFormat:@"item_%d",i]];
- if([item[@"order_code"] isEqualToString: appDelegate.order_code ])
- continue;
- else
- {
- newlist[[NSString stringWithFormat:@"item_%d",newcount]] = item;
- newcount++;
- }
- }
- newlist[@"count"] = @(newcount);
- [self saveScanOrderList:newlist];
- // [RAUtils dicttofile:orderlistPath dict:newlist];
- #ifdef RA_NOTIFICATION
- [ActiveViewController Notify:@"CartViewController,ScanOrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
- #else
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
- #endif
-
- }
- //+(void) createScanTempFolder
- //{
- // return;
- //// NSString* scanFilePath = [self getScanTempPath];
- //// BOOL bdir=YES;
- //// NSFileManager* fileManager = [NSFileManager defaultManager];
- //// if(! [fileManager fileExistsAtPath:scanFilePath isDirectory:&bdir])
- //// {
- ////
- //// NSError *error = nil;
- //// bool bsuccess=[fileManager createDirectoryAtPath:scanFilePath withIntermediateDirectories:YES attributes:nil error:&error];
- ////
- //// if(!bsuccess)
- //// DebugLog(@"Create cache folder failed");
- ////
- //// // if(bsuccess)
- //// // {
- //// // sqlite3 *db = [self get_db];
- //// //
- //// // [self execSql:[NSString stringWithFormat:@"insert into img_cache(name) values('%@')",name] db:db];
- //// // [iSalesDB close_db:db];
- //// // }
- //// }
- //}
- +(NSString*) getScanOrderPathByCode:(NSString*) order_code
- {
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSString *documents = [paths objectAtIndex:0];
-
- NSDictionary *addressDic = [[NSUserDefaults standardUserDefaults] valueForKey:@"ScanAddress"];
-
- NSString* servername = addressDic[@"name"];
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- NSString* user = appDelegate.user;
- NSString* orderpath = [documents stringByAppendingPathComponent:servername];
- orderpath = [orderpath stringByAppendingPathComponent:user];
- orderpath = [orderpath stringByAppendingPathComponent:order_code];
- BOOL bdir=YES;
- NSFileManager* fileManager = [NSFileManager defaultManager];
- if(! [fileManager fileExistsAtPath:orderpath isDirectory:&bdir])
- {
-
- NSError *error = nil;
- bool bsuccess=[fileManager createDirectoryAtPath:orderpath withIntermediateDirectories:YES attributes:nil error:&error];
-
- if(!bsuccess)
- DebugLog(@"Create cache folder failed");
-
- // 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 orderpath;
- }
- +(NSString*) getScanOrderPath
- {
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSString *documents = [paths objectAtIndex:0];
-
- NSDictionary *addressDic = [[NSUserDefaults standardUserDefaults] valueForKey:@"ScanAddress"];
-
- NSString* servername = addressDic[@"name"];
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- NSString* user = appDelegate.user;
- NSString* orderpath = [documents stringByAppendingPathComponent:servername];
- orderpath = [orderpath stringByAppendingPathComponent:user];
- orderpath = [orderpath stringByAppendingPathComponent:appDelegate.order_code];
- BOOL bdir=YES;
- NSFileManager* fileManager = [NSFileManager defaultManager];
- if(! [fileManager fileExistsAtPath:orderpath isDirectory:&bdir])
- {
-
- NSError *error = nil;
- bool bsuccess=[fileManager createDirectoryAtPath:orderpath withIntermediateDirectories:YES attributes:nil error:&error];
-
- if(!bsuccess)
- DebugLog(@"Create cache folder failed");
-
- // 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 orderpath;
- }
- //+(NSString*) getScanTempPath
- //{
- // return nil;
- ////
- //// if(RASingleton.sharedInstance.scan_temp_code == nil)
- //// RASingleton.sharedInstance.scan_temp_code = [self createScanTempCode];
- //// return [NSTemporaryDirectory() stringByAppendingPathComponent:RASingleton.sharedInstance.scan_temp_code];
- //}
- //+(void) moveScanTemp2Order
- //{
- // return;
- //// NSString *orderdir = [OLDataProvider getScanOrderPath];
- ////
- //// NSError *error = nil;
- //// NSString* tempdir = [OLDataProvider getScanTempPath];
- ////
- //// // NSArray* arr_files=[RAUtils allFilesAtPath:tempdir];
- //// // for(int i=0;i<arr_files.count;i++)
- //// // {
- //// // NSString* file=arr_files[i];
- //// //
- //// //
- //// // }
- //// [ [NSFileManager defaultManager] moveItemAtPath:[tempdir stringByAppendingPathComponent:@"cart.json"] toPath:[orderdir stringByAppendingPathComponent:@"cart.json"] error:&error];
- ////
- //
- //}
- //+(NSString*) getUserPath: (NSString*) user
- //{
- // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- // NSString *documents = [paths objectAtIndex:0];
- //
- // NSDictionary *addressDic = [[NSUserDefaults standardUserDefaults] valueForKey:@"ScanAddress"];
- //
- // NSString* servername = addressDic[@"name"];
- //// AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- //// NSString* user = appDelegate.user;
- // NSString* userpath = [documents stringByAppendingPathComponent:servername];
- // userpath = [userpath stringByAppendingPathComponent:user];
- // return userpath;
- //}
- +(NSString*) getServerPath
- {
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSString *documents = [paths objectAtIndex:0];
-
- NSDictionary *addressDic = [[NSUserDefaults standardUserDefaults] valueForKey:@"ScanAddress"];
-
- NSString* servername = addressDic[@"name"];
- // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- // NSString* user = appDelegate.user;
- // NSString* user = RASingleton.sharedInstance.user;
- NSString* serverpath = [documents stringByAppendingPathComponent:servername];
- // userpath = [userpath stringByAppendingPathComponent:user];
-
-
- NSFileManager* fileManager = [NSFileManager defaultManager];
- BOOL bdir=YES;
- if(! [fileManager fileExistsAtPath:serverpath isDirectory:&bdir])
- {
-
- NSError *error = nil;
- bool bsuccess=[fileManager createDirectoryAtPath:serverpath withIntermediateDirectories:YES attributes:nil error:&error];
- }
-
-
- return serverpath;
- }
- +(NSString*) getUserPath
- {
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSString *documents = [paths objectAtIndex:0];
-
- NSDictionary *addressDic = [[NSUserDefaults standardUserDefaults] valueForKey:@"ScanAddress"];
-
- NSString* servername = addressDic[@"name"];
- // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- // NSString* user = appDelegate.user;
- NSString* user = RASingleton.sharedInstance.user;
- NSString* userpath = [documents stringByAppendingPathComponent:servername];
- userpath = [userpath stringByAppendingPathComponent:user];
-
-
-
- NSFileManager* fileManager = [NSFileManager defaultManager];
- BOOL bdir=YES;
- if(! [fileManager fileExistsAtPath:userpath isDirectory:&bdir])
- {
-
- NSError *error = nil;
- bool bsuccess=[fileManager createDirectoryAtPath:userpath withIntermediateDirectories:YES attributes:nil error:&error];
- }
- return userpath;
- }
- +(bool) isSavedScanOrder:(NSString*) order_code
- {
- if(order_code == nil)
- return false;
- NSMutableDictionary * orderlist=[self getScanOrderList];
- int count = [orderlist[@"count"] intValue];
-
-
-
-
- for(int i=0;i<count;i++)
- {
- NSMutableDictionary* item = orderlist[[NSString stringWithFormat:@"item_%d",i]];
- if([item[@"order_code"] isEqualToString: order_code ])
- {
- return true;
- }
- }
- return false;
- }
- +(NSString*) getScanPath
- {
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-
-
- if(appDelegate.order_code==nil)
- {
- appDelegate.order_code=[[NSUUID new] UUIDString];
-
- }
- return [self getScanOrderPath];
- // else
- // {
- // [self createScanTempFolder];
- // return [self getScanTempPath];
- // }
- }
- +(void) scanCloseOrder
- {
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-
- {
- // 当前订单先关闭
- // [OLDataProvider deleteScanOrder:appDelegate.order_code];
- appDelegate.order_code = nil;
- // RASingleton.sharedInstance.scan_temp_code = nil;
- if(appDelegate.customer_type!=USER_ROLE_CUSTOMER ) //customer 角色不清空customer info
- { appDelegate.customerInfo = nil;
- appDelegate.contact_id = nil;
- }
- RASingleton.sharedInstance.scan_cart = nil;
- RASingleton.sharedInstance.price_type = 1;
- // [appDelegate updateScanButton:false];
-
- [appDelegate update_count_mark];
- [appDelegate closeOrder];
-
- }
- }
- +(NSString*) createScanTempCode
- {
- return [[NSUUID new] UUIDString];
- }
- +(NSString*) scanTemplatePath:(NSString*)file
- {
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSString *documents = [paths objectAtIndex:0];
- NSString* unZipTo=[documents stringByAppendingPathComponent:@"download"];
- NSString* templatefile = [unZipTo stringByAppendingPathComponent:file];
- return templatefile;
- }
- +(void) realguestLogin
- {
- NSMutableDictionary* guestjson=[self loadScanTemplate:@"guest.json"];
- [RANetwork parse_logininfo:guestjson user:@"GUEST" password:@"GUEST"];
- [ActiveViewController Notify:@"CartViewController,ScanOrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
-
- }
- +(NSMutableDictionary*) loadScanTemplate:(NSString*)file
- {
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSString *documents = [paths objectAtIndex:0];
- NSString* unZipTo=[documents stringByAppendingPathComponent:@"download"];
- NSString* templatefile = [unZipTo stringByAppendingPathComponent:file];
- NSDictionary* dict=[RAUtils dictfromfile:templatefile];
- return [dict mutableCopy];
- }
- +(void) deleteSubmittedOrder:(NSString*) order_code
- {
-
- NSString *userdir = [OLDataProvider getUserPath];
-
- if(order_code.length==0)
- return;
- // orderdirNSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- // NSString *documents = [paths objectAtIndex:0];
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-
-
- // if([appDelegate.order_code isEqualToString:order_code])
- // {
- // //要删除的订单是当前打开的订单;
- // appDelegate.order_code = nil;
- // appDelegate.customerInfo = nil;
- // RASingleton.sharedInstance.scan_cart = nil;
- // appDelegate.contact_id = nil;
- // // [appDelegate updateScanButton:false];
- //
- // [appDelegate update_count_mark];
- // }
- //删除订单目录
- [[NSFileManager defaultManager] removeItemAtPath:[userdir stringByAppendingPathComponent:order_code] error:nil];
- //维护订单列表
- NSMutableDictionary* submitlist = [self getScanSubmitList];
-
- int count = [submitlist[@"count"] intValue];
- if(count==0)
- {
- // order list 为空,不用维护
-
-
- #ifdef RA_NOTIFICATION
- [ActiveViewController Notify:@"CartViewController,ScanOrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
-
- #else
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
- #endif
- return;
- }
- // NSString *orderlistPath = [userdir stringByAppendingPathComponent:@"submitlist.json"];
-
- //
- // if (![[NSFileManager defaultManager] fileExistsAtPath:orderlistPath]) {
- //
- //
- //
- // // [orderlist addObject:appDelegate.order_code];
- // // [RAUtils dicttofile:orderlistPath dict:orderlist];
- //
- // }
- // else
- // {
- // orderlist=[[RAUtils dictfromfile:orderlistPath] mutableCopy];
- //
- // // [orderlist insertObject:appDelegate.order_code atIndex:0];
- //
- // // [RAUtils dicttofile:orderlistPath dict:orderlist];
- // }
-
-
-
- NSMutableDictionary* newlist = [NSMutableDictionary new];
-
-
- int newcount = 0;
- for(int i=0;i<count;i++)
- {
- NSMutableDictionary* item = submitlist[[NSString stringWithFormat:@"item_%d",i]];
- if([item[@"order_code"] isEqualToString: order_code ])
- continue;
- else
- {
- newlist[[NSString stringWithFormat:@"item_%d",newcount]] = item;
- newcount++;
- }
- }
- newlist[@"count"] = @(newcount);
- // [RAUtils dicttofile:orderlistPath dict:newlist];
- [self saveScanSubmitList:newlist];
-
- #ifdef RA_NOTIFICATION
- [ActiveViewController Notify:@"CartViewController,ScanOrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
- #else
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
- #endif
- }
- +(void) updateScanOrder:(NSString*) order_code
- {
-
- #ifdef SCANNER_ORDER
- NSString *userdir = [OLDataProvider getUserPath];
-
- if(order_code.length==0)
- return;
- // orderdirNSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- // NSString *documents = [paths objectAtIndex:0];
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-
-
-
- NSMutableDictionary* orderlist = [self getScanOrderList];
- int count = [orderlist[@"count"] intValue];
- if(count==0)
- {
- // order list 为空,不用维护
-
-
- [ActiveViewController Notify:@"ScanOrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
-
- return;
- }
-
- // NSString *orderlistPath = [userdir stringByAppendingPathComponent:@"orderlist.json"];
-
-
- // if (![[NSFileManager defaultManager] fileExistsAtPath:orderlistPath]) {
- //
- //
- //
- // // [orderlist addObject:appDelegate.order_code];
- // // [RAUtils dicttofile:orderlistPath dict:orderlist];
- //
- // }
- // else
- // {
- // orderlist=[[RAUtils dictfromfile:orderlistPath] mutableCopy];
- //
- // // [orderlist insertObject:appDelegate.order_code atIndex:0];
- //
- // // [RAUtils dicttofile:orderlistPath dict:orderlist];
- // }
- //
- //
- // int count = [orderlist[@"count"] intValue];
-
- // NSMutableDictionary* newlist = [NSMutableDictionary new];
-
- // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-
- NSDictionary* price_group = [RADataProvider get_price_group:appDelegate.price_group];
- float p =0;
- float s =0;
- for(int j=0;j<[RASingleton.sharedInstance.scan_cart[@"section_0"][@"count"] intValue];j++)
- {
- NSDictionary* cartitem =RASingleton.sharedInstance.scan_cart[@"section_0"][[NSString stringWithFormat:@"item_%d",j]];
- p+=[cartitem[@"unit_price"] doubleValue]*[cartitem[@"count"]intValue] * (1-[cartitem[@"discount"]doubleValue]/100.0);
- int mcount = [cartitem[@"count"] intValue];
- double msurcharge =0;
- // remove net price
- // if(RASingleton.sharedInstance.price_type==1)
- // {
- // if([cartitem[@"special_price"] boolValue])
- // {
- // msurcharge=([cartitem[price_group[@"price_3"][@"name"]] doubleValue]-[cartitem[price_group[@"price_2"][@"name"]] doubleValue])*mcount*(1-[cartitem[@"discount"]doubleValue]/100.0);
- // }
- // else
- // {
- // msurcharge=([cartitem[price_group[@"price_3"][@"name"]] doubleValue]-[cartitem[price_group[@"price_1"][@"name"]] doubleValue])*mcount*(1-[cartitem[@"discount"]doubleValue]/100.0);
- // }
- // }
- s+=msurcharge;
- }
-
- NSMutableDictionary* section =RASingleton.sharedInstance.scan_cart[@"section_0"];
- int order_qty=0;
- for(int c=0;c<[section[@"count"] intValue];c++)
- {
- NSDictionary* item = section[[NSString stringWithFormat:@"item_%d",c]];
- order_qty+=[item[@"count"] intValue];
-
- }
- // orderitem[@"model_count"] =[ NSString stringWithFormat:@"%@",order_qty];
- // int newcount = 0;
- for(int i=0;i<count;i++)
- {
- NSMutableDictionary* item = orderlist[[NSString stringWithFormat:@"item_%d",i]];
- if([item[@"order_code"] isEqualToString: order_code ])
- {
- item[@"price"] = [RAConvertor currencyNumber:p+s];//[NSString stringWithFormat:@"%.2f",p+s];
- item[@"model_count"] =[ NSString stringWithFormat:@"%d",order_qty];//RASingleton.sharedInstance.scan_cart[@"section_0"][@"count"] ];
- orderlist[[NSString stringWithFormat:@"item_%d",i]] = item;
- }
-
- }
- // newlist[@"count"] = @(newcount);
-
- [self saveScanOrderList:orderlist];
- // [RAUtils dicttofile:orderlistPath dict:orderlist];
- [ActiveViewController Notify:@"ScanOrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
- #endif
- }
- +(void) deleteScanOrder:(NSString*) order_code
- {
-
- NSString *userdir = [OLDataProvider getUserPath];
-
- if(order_code.length==0)
- return;
- // orderdirNSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- // NSString *documents = [paths objectAtIndex:0];
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-
-
- if([appDelegate.order_code isEqualToString:order_code])
- {
- //要删除的订单是当前打开的订单;
- // appDelegate.order_code = nil;
- // appDelegate.customerInfo = nil;
- // RASingleton.sharedInstance.scan_cart = nil;
- // appDelegate.contact_id = nil;
- [self scanCloseOrder];
- // [appDelegate updateScanButton:false];
-
- [appDelegate update_count_mark];
- }
- //删除订单目录
- [[NSFileManager defaultManager] removeItemAtPath:[userdir stringByAppendingPathComponent:order_code] error:nil];
- //维护订单列表
- NSMutableDictionary* orderlist = [self getScanOrderList];
-
- int count = [orderlist[@"count"] intValue];
-
- if(count==0)
- {
- // order list 为空,不用维护
-
-
- #ifdef RA_NOTIFICATION
- [ActiveViewController Notify:@"CartViewController,ScanOrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
-
- #else
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
- #endif
- return;
- }
- // NSString *orderlistPath = [userdir stringByAppendingPathComponent:@"orderlist.json"];
-
-
- // if (![[NSFileManager defaultManager] fileExistsAtPath:orderlistPath]) {
- //
- //
- //
- // // [orderlist addObject:appDelegate.order_code];
- // // [RAUtils dicttofile:orderlistPath dict:orderlist];
- //
- // }
- // else
- // {
- // orderlist=[[RAUtils dictfromfile:orderlistPath] mutableCopy];
- //
- // // [orderlist insertObject:appDelegate.order_code atIndex:0];
- //
- // // [RAUtils dicttofile:orderlistPath dict:orderlist];
- // }
-
-
-
- NSMutableDictionary* newlist = [NSMutableDictionary new];
-
-
- int newcount = 0;
- for(int i=0;i<count;i++)
- {
- NSMutableDictionary* item = orderlist[[NSString stringWithFormat:@"item_%d",i]];
- if([item[@"order_code"] isEqualToString: order_code ])
- continue;
- else
- {
- newlist[[NSString stringWithFormat:@"item_%d",newcount]] = item;
- newcount++;
- }
- }
- newlist[@"count"] = @(newcount);
- [self saveScanOrderList:newlist];
- // [RAUtils dicttofile:orderlistPath dict:newlist];
- #ifdef RA_NOTIFICATION
- [ActiveViewController Notify:@"CartViewController,ScanOrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
- #else
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
- #endif
- }
- #ifdef SCANNER_ORDER
- +(void) scanRefreshCart
- {
-
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- NSMutableDictionary* cart =[[RAUtils copyDict: RASingleton.sharedInstance.scan_cart] mutableCopy];
- NSMutableDictionary * section = cart[@"section_0"];
- NSMutableDictionary* newsection = [NSMutableDictionary new];
- int count = [section[@"count"] intValue];
- int newcount = 0;
- for(int i=0;i<count;i++)
- {
-
- NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
- NSString* model = item[@"model"];
- NSDictionary* modeljson=appDelegate.scan_model[model];
-
- if(modeljson==nil)
- continue;
-
- NSMutableDictionary* cartitem = [[self scanmodel2cartitem:[modeljson mutableCopy]] mutableCopy];
- cartitem[@"note"]=item[@"note"];
- cartitem[@"discount"]=item[@"discount"];
- // [item removeObjectForKey:@"discount"];
- // [item removeObjectForKey:@"note"];
- newsection[[NSString stringWithFormat:@"item_%d",newcount]]=cartitem;
- newcount++;
- }
- newsection[@"count"]=@(newcount);
- newsection[@"available"] = @(1);
- newsection[@"title"] = @"Available List";
- RASingleton.sharedInstance.scan_cart[@"section_0"]=newsection;
- }
- +(NSDictionary*) scanmodel2cartitem:(NSMutableDictionary*) _modelJson
- {
- // _modelJson = modelJson;
-
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-
- // self.labelPrice0.text = appDelegate.price0_name;
- // self.labelPrice1.text = appDelegate.price1_name;
- // self.labelPrice2.text = appDelegate.price2_name;
- // self.labelPrice3.text = appDelegate.price3_name;
- NSDictionary* price_group = [RADataProvider get_price_group:appDelegate.price_group];
- // self.labelPrice0.text = price_group[@"price_0"][@"display"];//appDelegate.price0_name;
- // self.labelPrice1.text = price_group[@"price_1"][@"display"];//appDelegate.price1_name;
- // self.labelPrice2.text = price_group[@"price_2"][@"display"];//appDelegate.price2_name;
- // self.labelPrice3.text = price_group[@"price_3"][@"display"];//appDelegate.price3_name;
- NSLog( [RAConvertor dict2string:_modelJson]);
-
- NSString * port=_modelJson[@"port"];
- if(port.length==0)
- port = @"N/A";
-
- NSString * origin=_modelJson[@"origin"];
- if(origin.length==0)
- origin = @"N/A";
- NSString * dimension=_modelJson[@"dimension"];
- if(dimension.length==0)
- dimension = @"N/A";
-
- // _labelModel.text=_modelJson[@"model"];
- // _labelDescription.text=_modelJson[@"description"];
- // _labelDimension.text=dimension;
- // _labelCuft.text=_modelJson[@"unit_cuft"];
- // _labelOrigin.text=origin;
- // _labelPort.text=port;
- NSString* price0=_modelJson[price_group[@"price_0"][@"name"]]; //DDP
- NSString* price1=_modelJson[price_group[@"price_1"][@"name"]]; //WHSE
- NSString* price2=_modelJson[price_group[@"price_2"][@"name"]]; //SHOW
- NSString* price3=_modelJson[price_group[@"price_3"][@"name"]]; //NET
-
-
-
- if(![price0 isEqualToString: @"N/A"])
- price0 = [NSString stringWithFormat:@"%.2f",[_modelJson[price_group[@"price_0"][@"name"]] doubleValue]];
- if(![price1 isEqualToString: @"N/A"])
- price1 = [NSString stringWithFormat:@"%.2f",[_modelJson[price_group[@"price_1"][@"name"]] doubleValue]];
- if(![price2 isEqualToString: @"N/A"])
- {
- price2 = [NSString stringWithFormat:@"%.2f",[_modelJson[price_group[@"price_2"][@"name"]] doubleValue]];
- // if(RASingleton.sharedInstance.price_type==1)
- _modelJson [@"special_price"] = @true;
- }
- if(![price3 isEqualToString: @"N/A"])
- price3 = [NSString stringWithFormat:@"%.2f",[_modelJson[price_group[@"price_3"][@"name"]] doubleValue]];
- // if(![_modelJson [@"special_price"] boolValue]&& ![price1 isEqualToString: @"N/A"] && [price1 isEqual:price3])
- if((![price1 isEqualToString: @"N/A"] && [price1 isEqual:price3])||(![price2 isEqualToString: @"N/A"] && [price2 isEqual:price3]))
- {
- // if(RASingleton.sharedInstance.price_type==1)
- _modelJson [@"net_price"] = @true;
-
- // remove net price
- _modelJson [@"net_price"] = @false;
- }
-
-
- //
- // if(![price1 isEqualToString:@"N/A"])
- // {
- // price2 = [NSString stringWithFormat:@"%.2f",[_modelJson[@"price1"] doubleValue] *1.25];
- // _modelJson[@"price2"]= price2;
- // }
- // else
- // {
- // price2=@"N/A";
- // }
- //
-
-
- // if([price0 isEqualToString:@"N/A"])
- // _labelPriceCTNR.text= @"";//price0;
- // else
- // _labelPriceCTNR.text=[RAConvertor currencyNumber:[price0 floatValue]];
-
- //
- // if([price3 isEqualToString:@"N/A"])
- // _labelPriceNCA.text= price3;
- // else
- // _labelPriceNCA.text=[RAConvertor currencyNumber:[price3 floatValue]];
- // _labelPrice25p.text=price2;
-
- //
- // if([_modelJson [@"special_price"] boolValue])
- // {
- // if([_modelJson[price_group[@"price_2"][@"name"]] isEqualToString:@"N/A"])
- // _labelPriceSpecial.text=@"";//_modelJson[@"price2"];
- // else
- // _labelPriceSpecial.text=[RAConvertor currencyNumber:[_modelJson[price_group[@"price_2"][@"name"]] floatValue]];
- // }
- // else
- // {
- // _labelPriceSpecial.text=@"";//@"N/A";
- // }
- //
-
- // if([_modelJson [@"net_price"] boolValue])
- // {
- //// if([_modelJson[@"price1"] isEqualToString:@"N/A"])
- //// {
- //// _labelPriceNet.text=_modelJson[@"price1"];
- ////// _labelPriceNCA.text=@"N/A";
- //// }
- //// else
- //// {
- //// _labelPriceNet.text=[RAConvertor currencyNumber:[_modelJson[@"price1"] floatValue]];
- ////// _labelPriceNCA.text=@"N/A";
- //// }
- //
- // if([_modelJson[price_group[@"price_3"][@"name"]] isEqualToString:@"N/A"])
- // {
- // _labelPriceNet.text=@"";//_modelJson[@"price3"];
- //// _labelPriceNCA.text=@"N/A";
- // }
- // else
- // {
- // _labelPriceNet.text=[RAConvertor currencyNumber:[_modelJson[price_group[@"price_3"][@"name"]] floatValue]];
- //// _labelPriceNCA.text=@"N/A";
- // }
- //
- // }
- // else
- // {
- // _labelPriceNet.text=@"";//@"N/A";
- // }
- //
- // {
- // if([_modelJson[price_group[@"price_1"][@"name"]] isEqualToString:@"N/A"])
- // {
- // _labelPriceNCA.text=@"";//_modelJson[@"price1"];
- //// _labelPriceNCA.text=@"N/A";
- // }
- // else
- // {
- // _labelPriceNCA.text=[RAConvertor currencyNumber:[_modelJson[price_group[@"price_1"][@"name"]] floatValue]];
- //// _labelPriceNet.text=@"N/A";
- // }
- // }
-
-
- NSString * available=_modelJson[@"available"];
- if(available.length==0)
- available = @"N/A";
-
- // _labelAvailable.text=available;
- NSString * unit_cuft=_modelJson[@"unit_cuft"];
- if(unit_cuft.length==0)
- unit_cuft = @"N/A";
- else
- {
-
- unit_cuft = [NSString stringWithFormat:@"%.2f", [_modelJson[@"unit_cuft"] doubleValue]];
- }
-
- NSString * cell_price;
- if(RASingleton.sharedInstance.price_type==1)
- {
- // if(_modelJson [@"net_price"])
- cell_price=_modelJson[price_group[@"price_3"][@"name"]];
- // else if(_modelJson [@"special_price"])
- // {
- // unit_price= _modelJson[@"price2"];
- // }
- // else
- // {
- // unit_price= _modelJson[@"price1"];
- // }
- }
- else
- {
- cell_price=_modelJson[price_group[@"price_0"][@"name"]];
- }
-
-
-
-
-
- NSString * mpack=_modelJson[@"stockUom"];
- if([mpack isEqualToString:@"N/A"])
- mpack=@"1";
- _modelJson[@"count"]=_modelJson[@"stockUom"];
- _modelJson[@"cuft"] = @([mpack intValue]* [unit_cuft doubleValue]);
- _modelJson[@"subtotal_price"] = @([mpack intValue]* [cell_price doubleValue]);
-
- NSMutableDictionary* jitem = nil;
- jitem = [_modelJson mutableCopy];
- int stockUom =[jitem[@"stockUom"] intValue];
- if(stockUom==0)
- stockUom=1;
- bool newitem = true;
- //AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- //NSDictionary* price_group = [RADataProvider get_price_group:appDelegate.price_group];
- // for(int i=0;i<count;i++)
- // {
- //
- // NSMutableDictionary* litem = [section[[NSString stringWithFormat:@"item_%i",i]] mutableCopy];
- //
- // if([litem[@"product_id"] isEqualToString:jitem[@"product_id"]])
- // {
- //
- //// int oldcount = [litem[@"stockUom"] intValue];
- // newitem = false;
- //
- // litem[@"count"]=@([litem[@"count"] intValue] +[jitem[@"count"] intValue]);
- // litem[@"cuft"]=@([litem[@"count"] intValue] * [litem[@"unit_cuft"] doubleValue]);
- //
- // section[[NSString stringWithFormat:@"item_%i",i]] = litem;
- // break;
- //
- //
- // }
- //
- //
- //
- // }
- // if(true)
- // {
- jitem[@"count"]=@(stockUom);
- jitem[@"check"]=@(true);
- jitem[@"cart_item_id"]=[NSUUID UUID].UUIDString;
-
- NSString * unit_price;
- if(RASingleton.sharedInstance.price_type==0)
- unit_price=_modelJson[price_group[@"price_0"][@"name"]];
- else if(_modelJson [@"special_price"])
- {
- unit_price= _modelJson[price_group[@"price_2"][@"name"]];
- }
- else if(_modelJson [@"net_price"])
- unit_price=_modelJson[price_group[@"price_3"][@"name"]];
- else
- {
- unit_price= _modelJson[price_group[@"price_1"][@"name"]];
- }
- if([unit_price isEqualToString:@"N/A"])
- unit_price = @"0";
- else
- {
-
- unit_price = [NSString stringWithFormat:@"%.2f", [unit_price doubleValue]];
- }
-
-
- jitem[@"unit_price"] = unit_price;
- jitem[@"erp_unit_price"] = unit_price;
-
-
- // section[[NSString stringWithFormat:@"item_%i",count]] = jitem;
- // section[@"count"]= @(count+1);
- // count++;
-
- // }
-
-
-
-
- return jitem;
- }
- +(void) saveScanCart:(NSMutableDictionary*) cart
- {
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- if(appDelegate.order_code.length<=0)
- return;
- if(cart==nil)
- return;
- // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- // NSString *documents = [paths objectAtIndex:0];
- // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-
- if(RASingleton.sharedInstance.price_type==0)
- {
- NSMutableDictionary * section = cart[@"section_0"];
- int count = [section[@"count"] intValue];
- for(int i=0;i<count;i++)
- {
- NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
- [item removeObjectForKey:@"discount"];
- [item removeObjectForKey:@"note"];
- section[[NSString stringWithFormat:@"item_%d",i]]=item;
- }
- cart[@"section_0"]=section;
- }
-
- NSString *orderdir = [self getScanPath];
-
- NSString *cartpath = [orderdir stringByAppendingPathComponent:@"cart.json"];
-
- cart[@"price_group"] = appDelegate.price_group;
-
- [RAUtils dicttofile:cartpath dict:cart];
- }
- #endif
- +(NSDictionary *) prepareUpload:(NSArray*) arr_order params:(NSMutableDictionary*)add_params
- {
- assert(add_params[@"user"]!=nil);
- // assert(add_params[@"contact_id"]!=nil);
- // assert(add_params[@"password"]!=nil);
-
- 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 params:add_params];
- ret[@"portfolio"] = [self preparePortfolio:serial params:add_params];
- ret[@"view_portfolio"] = [self preparePDF:serial];
-
- NSString* str= [RAConvertor 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];
-
- NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
-
- NSString* ver = [defaults stringForKey:@"OfflineVer"] ;
-
-
- NSString* where=@" 1=1";
-
- if (ver!=nil) {
-
- where=@"is_dirty=1";
- }
- sqlite3 *db = [iSalesDB get_db];
-
- NSString *sqlQuery =[NSString stringWithFormat:@"select _id,product_id,item_id,qty,create_time,modify_time,is_delete from wishlist where %@",where];
- 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];
-
- }
-
- char *modify_time = (char*)sqlite3_column_text(statement, 5);
- NSString* nsmodify_time=nil;
- if(modify_time!=nil)
- {
- nsmodify_time= [[NSString alloc]initWithUTF8String:modify_time];
-
- }
-
- int is_delete = sqlite3_column_int(statement, 6);
- 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;
- itemjson[@"modify_time"]=nsmodify_time;
- itemjson[@"is_delete"]=[NSNumber numberWithInt:is_delete];
-
-
- 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 params:(NSMutableDictionary*)add_params db:(sqlite3*)db
- {
- NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
- // UIApplication * app = [UIApplication sharedApplication];
- // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
-
-
- assert(add_params[@"user"]!=nil);
- // assert(add_params[@"password"]!=nil);
-
-
-
- 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,o.customer_cid from (select _id,product_id,decrypt(str_price) as price,discount,item_count,line_note,item_id,so_no from offline_cart where so_no='%@') c left join product m on c.product_id=m.product_id left join offline_order as o on c.so_no = o.so_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];
-
- char *customer_cid = (char *)sqlite3_column_text(statement, 10);
- NSString *customerID = [NSString stringWithUTF8String:customer_cid];
-
-
- 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:customerID user:add_params[@"user"] 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 contactID:customerID user:add_params[@"user"]];
-
- 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 params:(NSMutableDictionary*)add_params
- {
-
- assert(add_params[@"user"]!=nil);
-
- NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
- sqlite3 *db = [iSalesDB get_db];
-
- NSString *sqlQuery =@"select _id,sync_data,sign_picpath,so_id,discount from offline_order where order_id is null";
- // for(int i=0;i<arr_soid.count;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)
- {
- int count=0;
- while (sqlite3_step(statement) == SQLITE_ROW)
- {
- NSMutableDictionary* itemjson = [[NSMutableDictionary alloc] init];
- 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];
- // NSMutableDictionary* sync_dic = [RAConvertor string2dict:sync_data];
- // sync_dic[@"truck_carrier"] = sync_dic[@"carrier"]
- }
- 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];
-
- }
- if([arr_soid indexOfObject:nsso_no]!= NSNotFound)
- itemjson[@"order_type"]=@"submit order";
- else
- itemjson[@"order_type"]=@"archive order";
-
-
-
- double discount =sqlite3_column_double(statement, 4);
- itemjson[@"discount"]=@(discount);
- itemjson[@"_id"]=[NSNumber numberWithInt:_id];
- itemjson[@"json_data"]= nssync_data;
-
- itemjson[@"order_items"]=[self preparecart:nsso_no params:add_params db:db];
- ret[[NSString stringWithFormat:@"item_%d",count]]=itemjson;
- count++;
- }
-
- ret[@"count"]=[NSNumber numberWithInt:count ];
- ret[@"result"]=[NSNumber numberWithInt:RESULT_TRUE ];
-
- }
-
- sqlite3_finalize(statement);
-
-
-
-
-
- [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];
- NSString* sqlQuery = [NSString stringWithFormat:@"update wishlist set is_delete = 1 where _id in (%@);",collectId];
- [iSalesDB execSql:sqlQuery db:db];
- int count=[iSalesDB get_recordcount:db table:@"wishlist" where:@"is_delete is NULL or is_delete != 1"];
- [iSalesDB close_db:db];
-
- // appDelegate.wish_count =count;
- //
- // [appDelegate update_count_mark];
- ret[@"result"]= [NSNumber numberWithInt:2];
- ret[@"wish_count"]=@(count);
-
- 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;
- //}
- + (void) printTimeIntervalBetween:(NSDate *)date1 and:(NSDate *)date2 {
-
- NSTimeInterval interval = [date2 timeIntervalSinceDate:date1];
-
- DebugLog(@"time interval: %lf",interval);
- }
- //+(NSDictionary*) offline_wishlist :(NSMutableDictionary *) params
- //{
- // UIApplication * app = [UIApplication sharedApplication];
- // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- //
- // int sort = [[params objectForKey:@"sort"] intValue];
- // NSString *sort_str = @"";
- // switch (sort) {
- // case 0:{
- // sort_str = @"order by w.modify_time desc";
- // }
- // break;
- // case 1:{
- // sort_str = @"order by w.modify_time asc";
- // }
- // break;
- // case 2:{
- // sort_str = @"order by m.name asc";
- // }
- // break;
- // case 3:{
- // sort_str = @"order by m.name desc";
- // }
- // break;
- // case 4:{
- // sort_str = @"order by m.description asc";
- // }
- // break;
- //
- // default:
- // break;
- //
- // }
- //
- //
- //// NSString* user = appDelegate.user;
- //
- // sqlite3 *db = [iSalesDB get_db];
- //
- // // order by w.create_time
- // NSString* sqlQuery = [NSString stringWithFormat:@"select w.product_id,m.name||'\n'||m.description,w._id,w.qty from wishlist as w left join product as m on w.product_id=m.product_id where w.is_delete is NULL or w.is_delete != 1 %@ ",sort_str];
- //
- //// NSString* sqlQuery = [NSString stringWithFormat:@"select m.product_id,(m.name||'\n'||m.description) as des,w._id from product as m,wishlist as w where m.product_id = w.product_id %@",sort_str];
- //
- //
- // sqlite3_stmt * statement;
- //
- // NSDate *date1 = [NSDate date];
- //// NSDate *date2 = nil;
- //
- // 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);
- //
- // NSDate *date_image = [NSDate date];
- //
- // NSString *nsurl=[self model_category_img:[NSString stringWithFormat:@"%@",[NSNumber numberWithInt:product_id]] model_name:nil db:db];
- //
- // printf("image : ");
- // [self printTimeIntervalBetween:date_image and:[NSDate date]];
- //
- // // char *url = (char*)sqlite3_column_text(statement, 3);
- // // if(url==nil)
- // // url="";
- // // NSString *nsurl = [[NSString alloc]initWithUTF8String:url];
- //
- // int qty = sqlite3_column_int(statement, 3);
- //
- //
- // item[@"cart_count"] = [NSNumber numberWithInt:qty];
- // 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++;
- //
- // }
- // printf("total time:");
- // [self printTimeIntervalBetween:date1 and:[NSDate date]];
- //
- // 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];
- if(json==nil)
- return nil;
- 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];
-
- if(json==nil)
- return nil;
- 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 user:(NSString*)user islogin:(bool)blogin db:(sqlite3*)db
- {
-
- //assert(user!=nil);
-
- // 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 user:user 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=[RAConvertor arr2string:arr2 separator:@"," trim:true brackets:@"'"];
-
-
- // sqlite3 *db = [iSalesDB get_db];
-
- NSString* sqlQuery = nil;
- if(contact_id==nil)
- {
- if(!blogin)
- return nil;
- sqlQuery=[NSString stringWithFormat:@"select a.name,b.price,b.type 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,b.type 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";
- }
-
- // int type= sqlite3_column_int(statement, 2);
- //item[@"type"]=@"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 user:(NSString*)user product_id:(id) product_id item_id:(id)item_id db:(sqlite3*)db
- {
- assert(user!=nil);
-
- NSArray* arr1 = [self get_user_all_price_type:db user:user];
- NSArray* arr2 = [self get_contact_default_price_type:contact_id user:user db:db];
-
-
- NSString* whereprice=nil;
- if(contact_id==nil)
- whereprice=[RAConvertor arr2string:arr1 separator:@"," trim:true brackets:@"'"];
- else
- whereprice=[RAConvertor 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 user:(NSString*) user
- {
- assert(user!=nil);
-
- 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='%@';",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=[RAConvertor string2arr:price separator:OFFLINE_ARRAY_SEPARATOR];
-
- }
-
-
-
-
- sqlite3_finalize(statement);
-
-
-
-
- }
-
- // [iSalesDB close_db:db];
-
- return ret;
-
-
-
- }
- +(NSArray*) get_contact_default_price_type:(NSString*) contact_id user:(NSString*)user 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='%@';",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=[RAConvertor 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
- // 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;
- // 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
-
-
- if(product_id==nil && model_name)
- sqlQuery = [NSString stringWithFormat:@"select i.url from model_image i where product_id in (select product_id from product where 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 model_image i where i.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 upc_code:(NSString *) upc_code
- {
-
-
- NSString* ret= nil;
-
-
- sqlite3 *db = [iSalesDB get_db];
-
-
- NSString *sqlQuery = nil;
-
- if(product_id==nil)
- if(upc_code==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 upc_code = '%@' or upc_code like '%@;%%' or upc_code like '%%;%@;%%' or upc_code like '%%;%@';",upc_code,upc_code,upc_code,upc_code];// 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;
- }
- + (NSString *) categoryIdOfProduct:(NSString *)product_id name:(NSString *)product_name {
-
- NSString *sql = nil;
- if (product_id != nil) {
- sql = [NSString stringWithFormat:@"select category from product where product_id = '%@';",product_id];
- } else {
- sql = [NSString stringWithFormat:@"select category from product where name = '%@';",product_name];
- }
- NSString *result_set = [iSalesDB jk_queryText:sql];
- result_set = [result_set stringByReplacingOccurrencesOfString:@"%" withString:@""];
- result_set = [result_set stringByReplacingOccurrencesOfString:@"#" withString:@""];
- return result_set;
- }
- //+(NSDictionary*) offline_model :(NSMutableDictionary *) params
- //{
- //
- //
- // assert(params[@"user"]!=nil);
- //
- //
- //
- // NSString* model_name = [params valueForKey:@"product_name"];
- //
- // NSString* product_id = [params valueForKey:@"product_id"];
- //
- // NSString* category = [params valueForKey:@"category"];
- //
- // NSString *default_category_id = [self model_default_category:product_id model_name:model_name];
- // if(category==nil) {
- // category = default_category_id;
- // } else {
- //
- // NSArray *arr_0 = [category componentsSeparatedByString:@","];
- // // 参数重有多个category id
- // if (arr_0.count > 1) {
- // NSArray *arr_1 = [[self categoryIdOfProduct:product_id name:model_name] componentsSeparatedByString:@","];
- //
- // // 取交集
- // NSMutableSet *set_0 = [NSMutableSet setWithArray:arr_0];
- // NSMutableSet *set_1 = [NSMutableSet setWithArray:arr_1];
- // [set_0 intersectSet:set_1];
- //
- // if (set_0.count == 1) {
- // category = (NSString *)[set_0 anyObject];
- // } else {
- // if ([set_0 containsObject:default_category_id]) {
- // category = default_category_id;
- // } else {
- // category = (NSString *)[set_0 anyObject];
- // }
- // }
- // }
- // }
- //
- // 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,ETA,item_id,seat_dimension,product_content_writing 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,ETA,item_id,seat_dimension,product_content_writing 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];
- // [img_section setValue:[NSString stringWithFormat:@"%d",incoming_stock] forKey:@"incoming_stock"];
- // 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 = @"Out of Stock";
- //
- // [img_section setValue:Availability forKey:@"Availability"];
- // [img_section setValue:[NSString stringWithFormat:@"%d",stockUcom] forKey:@"stockUom"];
- //
- // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
- //
- //
- // char *eta = (char*)sqlite3_column_text(statement, 25);
- // if(eta==nil)
- // eta="";
- // NSString *nseta = [[NSString alloc]initWithUTF8String:eta];
- // if ([nseta isEqualToString:@"null"]) {
- // nseta = @"";
- // }
- // if (availability <= 0) {
- // [img_section setValue:nseta forKey:@"ETA"];
- // }
- //
- //
- // int item_id = sqlite3_column_int(statement, 26);
- // NSString *seat_dimension = [self textAtColumn:27 statement:statement];
- // NSString *content_writing = [self textAtColumn:28 statement:statement];
- //
- // 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 setObject:content_writing forKey:@"product_content_writing"];
- // [img_section setValue:Price forKey:@"price"];
- // [img_section setValue:nsname forKey:@"model_name"];
- // [img_section setValue:nsdescription forKey:@"model_descrition"];
- //
- // if (appDelegate.order_code) { // 离线order code即so#
- //
- // NSString *cartQtySql = [NSString stringWithFormat:@"select c.item_count from offline_cart as c left join offline_order as o on c.so_no = o.so_id where o.so_id = '%@' and c.item_id = %d;",appDelegate.order_code,item_id];
- // __block int cartQTY = 0;
- // [iSalesDB jk_query:cartQtySql db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
- //
- // cartQTY = sqlite3_column_int(stmt, 0);
- //
- // }];
- //
- // if (cartQTY > 0) {
- // [img_section setObject:[NSNumber numberWithInt:cartQTY] forKey:@"Model QTY in cart"];
- // }
- // }
- //
- // [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:@"Seat Dimension" value:seat_dimension] 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_priceKvItem: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"];
- // }
- //// DebugLog(@"count:%d",count);
- //
- //
- // [iSalesDB close_db:db];
- // DebugLog(@"data string: %@",[RAConvertor dict2string:ret] );
- //
- // return ret;
- //}
- + (NSDictionary *) search:(NSMutableDictionary *)params limited:(BOOL)limited {
- // NSString* orderCode = [params valueForKey:@"orderCode"];
-
- NSString* keyword = [params valueForKey:@"keyword"];
- keyword=keyword.lowercaseString;
-
- bool exactMatch = [[params valueForKey:@"exactMatch"] boolValue]; // search by factory code
-
-
- int limit = [[params valueForKey:@"limit"] intValue];
- int offset = [[params valueForKey:@"offset"] intValue];
-
- NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
-
-
- NSString *limit_str = @"";
- if (limited) {
- limit_str = [NSString stringWithFormat:@"limit %d offset %d ",limit,offset];
- }
-
-
- 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]];
-
-
- // UIApplication * app = [UIApplication sharedApplication];
- // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
-
- NSString *sqlQuery = nil;
- if(exactMatch )
- sqlQuery=[NSString stringWithFormat:@"select m.name,m.description,m.product_id,w._id,m.closeout,c._id,w.is_delete,m.more_color from product m left join wishlist w on m.product_id=w.product_id left join (select _id,product_id from offline_cart where so_no='%@') c on c.product_id=m.product_id where lower(name) like'%@%%' and m.is_active = 1 order by m.name %@;",params[@"orderCode"], keyword,limit_str]; // 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,c._id,w.is_delete,m.more_color from product m left join wishlist w on m.product_id=w.product_id left join (select _id,product_id from offline_cart where so_no='%@') c on c.product_id=m.product_id where (lower(name) like'%%%@%%' or lower(description) like'%%%@%%' or lower(made_in) like '%%%@%%' or lower(material) like '%%%@%%' or lower(packaging) like '%%%@%%') and m.is_active = 1 order by m.name %@ ;",params[@"orderCode"], keyword,keyword,keyword,keyword,keyword,limit_str];// 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);
- int cid = sqlite3_column_int(statement, 5);
- int wisdelete = sqlite3_column_int(statement, 6);
- int more_color = sqlite3_column_int(statement, 7);
-
- NSMutableDictionary* imgjson=[self category_img:product_id db:db];
-
- if(wid !=0 && wisdelete != 1)
- [item setValue:@"true" forKey:@"wish_exists"];
- else
- [item setValue:@"false" forKey:@"wish_exists"];
-
- if(closeout==0)
- [item setValue:@"false" forKey:@"is_closeout"];
- else
- [item setValue:@"true" forKey:@"is_closeout"];
-
- if(cid==0)
- [item setValue:@"false" forKey:@"cart_exists"];
- else
- [item setValue:@"true" forKey:@"cart_exists"];
-
- if (more_color == 0) {
- [item setObject:@(false) forKey:@"more_color"];
- } else if (more_color == 1) {
- [item setObject:@(true) forKey:@"more_color"];
- }
-
- [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);
- }
- DebugLog(@"count:%d",count);
-
-
- [iSalesDB close_db:db];
-
-
-
-
- DebugLog(@"data string: %@",[RAConvertor dict2string:ret] );
-
- return ret;
- }
- +(NSDictionary*) offline_search:(NSMutableDictionary *) params
- {
- return [self search:params limited:YES];
- }
- //+(NSDictionary*) offline_logout :(NSMutableDictionary *) params
- //{
- // UIApplication * app = [UIApplication sharedApplication];
- // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- //
- //// [iSalesDB disable_trigger]
- // [iSalesDB disable_trigger];
- // [iSalesDB execSql:@"delete from offline_cart where so_no in (select so_id from offline_order where status = 0);"];
- // [iSalesDB execSql:@"delete from offline_order where status=0;"];
- //
- // [iSalesDB enable_trigger];
- //// [iSalesDB enable_trigger]
- // //
- // // NSString* user = [params valueForKey:@"user"];
- // //
- // // NSString* password = [params valueForKey:@"password"];
- //
- //
- //
- // NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
- //
- // ret[@"result"]=[NSNumber numberWithInt:2 ];
- //
- //
- //
- // 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
- //{
- //
- // UIApplication * app = [UIApplication sharedApplication];
- // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- //
- // [iSalesDB disable_trigger];
- // [iSalesDB execSql:@"delete from offline_cart where so_no in (select so_id from offline_order where status = 0);"];
- // [iSalesDB execSql:@"delete from offline_order where status=0;"];
- // [iSalesDB enable_trigger];
- //
- // NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
- // NSString *customer_name = [self translateSingleQuote:params[@"customer_name"]];
- // 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=[RAConvertor arr2string:arr_name separator:@" " trim:true];
- //
- // // default ship from
- // NSString *ship_from_default_sql = @"select contact_id,decrypt(company_name),decrypt(addr_1),first_name || ' ' || last_name,email,fax,decrypt(phone) from offline_contact where contact_id = 'NPD';";
- //
- // __block NSString *cid = @"";
- // __block NSString *name = @"";
- // __block NSString *ext = @"";
- // __block NSString *contact = @"";
- // __block NSString *email = @"";
- // __block NSString *fax = @"";
- // __block NSString *phone = @"";
- //
- // sqlite3 *db = [iSalesDB get_db];
- //
- // [iSalesDB jk_query:ship_from_default_sql db:db close:NO completion:^(sqlite3_stmt *statment, NSMutableDictionary *container, long *count) {
- //
- // cid = [self textAtColumn:0 statement:statment];
- // name = [self textAtColumn:1 statement:statment];
- // ext = [self textAtColumn:2 statement:statment];
- // contact = [self textAtColumn:3 statement:statment];
- // email = [self textAtColumn:4 statement:statment];
- // fax = [self textAtColumn:5 statement:statment];
- // phone = [self textAtColumn:6 statement:statment];
- //
- // }];
- //
- // NSString* so_id = [self get_offline_soid:db];
- // if(so_id==nil)
- // so_id=[NSString stringWithFormat:@"OFFLINE%@",[NSUUID UUID].UUIDString ];
- //
- // 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,must_call,sender_cid,sender_name,sender_ext,sender_contact,sender_phone,sender_fax,sender_email,billing_cid,billing_name,billing_ext,billing_contact,billing_phone,billing_fax,billing_email,sales_terms) values('%@',0,'%@','%@','%@','%@','%@','%@','%@','%@',1,'%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','FOB')",so_id,customer_cid,customer_contact,customer_email,customer_fax,customer_phone,customer_sales_rep,create_by ,contact_name,cid,name,ext,contact,phone,fax,email,customer_cid,customer_name,customer_contact_ext,customer_contact,customer_phone,customer_fax,customer_email];
- //
- //
- //
- // 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 [RAConvertor dict2data:ret];
- //
- //}
- +(NSData*) offline_editorder :(NSMutableDictionary *) params
- {
-
- //assert(params[@"order_code"]);
-
-
- // assert(params[@"order_code"]);
- NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
-
-
- NSString* orderCode = [params valueForKey:@"orderCode"];
-
- NSString* app_order_code= params[@"appDelegate.order_code"];
- // UIApplication * app = [UIApplication sharedApplication];
- // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- if(![app_order_code isEqualToString:orderCode]&& app_order_code!=0)
- {
- [iSalesDB disable_trigger];
- [iSalesDB execSql:@"delete from offline_cart where so_no in (select so_id from offline_order where status = 0);"];
- [iSalesDB execSql:@"delete from offline_order where status=0;"];
- [iSalesDB enable_trigger];
- }
-
-
- sqlite3 *db = [iSalesDB get_db];
-
- int cart_count=[self query_ordercartcount:orderCode db:db];
-
- int wish_count=[iSalesDB get_recordcount:db table:@"wishlist" where:@"is_delete is NULL or is_delete != 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 [RAConvertor dict2data:ret];
-
-
- }
- +(NSData*) offline_add2cart :(NSMutableDictionary *) params;
- {
-
- assert(params[@"can_create_backorder"]!=nil);
- NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
- sqlite3 *db = [iSalesDB get_db];
- [iSalesDB execSql:@"BEGIN TRANSACTION" db:db];
- int count =0;
- if(params[@"count"]!=nil)
- {
- count = [params[@"count"] intValue];
- }
-
- // AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- NSString* product_id=params[@"product_id"];
- NSString* orderCode=params[@"orderCode"];
- NSString *qty = params[@"qty"];
-
- NSArray* arr_id=[RAConvertor string2arr:product_id separator:@","];
- NSArray *qty_arr = [RAConvertor string2arr:qty separator:@","];
-
- __block int number_of_outOfStock = 0;
-
- for(int i=0;i<arr_id.count;i++)
- {
-
- NSInteger item_qty= count;
- if (qty) {
- item_qty = [qty_arr[i] integerValue];
- }
- if(item_qty==0)
- item_qty=[self model_stockUom:[arr_id[i] intValue] db:db];
-
- // 检查新加Model数量是否大于库存
- if (![params[@"can_create_backorder"] boolValue]) {
- __block BOOL needContinue = NO;
- [iSalesDB jk_query:[NSString stringWithFormat:@"select availability from product where product_id = %@;",arr_id[i]] db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- int availability = sqlite3_column_int(stmt, 0);
- // 库存小于购买量为缺货
- if (availability < item_qty || availability <= 0) {
- number_of_outOfStock++;
- needContinue = YES;
- }
-
- }];
-
- if (needContinue) {
- continue;
- }
- }
-
- int _id=[iSalesDB get_recordid:db table:@"offline_cart" where:[NSString stringWithFormat:@"so_no='%@' and product_id=%@",orderCode,arr_id[i]]];
-
-
- NSString* sql=nil;
-
- sqlite3_stmt *stmt = nil;
- BOOL shouldStep = NO;
-
- if(_id<0)
- {
-
- 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(?,?,?,?,datetime('now', 'localtime'))"];
-
- sqlite3_prepare_v2(db, [sql UTF8String], -1, &stmt, nil);
- sqlite3_bind_text(stmt,1,[arr_id[i] UTF8String],(int)[arr_id[i] length],NULL);
- sqlite3_bind_text(stmt,2,[orderCode UTF8String],(int)[orderCode length],NULL);
- sqlite3_bind_text(stmt,3,[[NSString stringWithFormat:@"%ld",item_qty] UTF8String],(int)[[NSString stringWithFormat:@"%ld",item_qty] length],NULL);
- sqlite3_bind_text(stmt,4,[[NSString stringWithFormat:@"%d",item_id] UTF8String],(int)[[NSString stringWithFormat:@"%d",item_id] length],NULL);
- shouldStep = YES;
- }
- else
- {
- if (qty) { // wish list move to cart
- sql=[NSString stringWithFormat:@"update offline_cart set item_count=1,modify_time = datetime('now', 'localtime') where _id=?"];
-
- sqlite3_prepare_v2(db, [sql UTF8String], -1, &stmt, nil);
- sqlite3_bind_int(stmt, 1, _id);
- shouldStep = YES;
- } else {
-
- sql = [NSString stringWithFormat:@"select c.item_count + %ld,p.availability from product as p left join offline_cart as c on c.item_id = p.item_id where c._id = %d;",item_qty,_id];
- __block BOOL update = YES;
- if (![params[@"can_create_backorder"] boolValue]) {
- [iSalesDB jk_query:sql db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- int newQTY = sqlite3_column_int(stmt, 0);
- int availability = sqlite3_column_int(stmt, 1);
-
- if (newQTY > availability) { // 库存不够
- update = NO;
- number_of_outOfStock++;
- }
-
- }];
- }
-
- if (update) {
-
- sql=[NSString stringWithFormat:@"update offline_cart set item_count=item_count+?,create_time = datetime('now', 'localtime') where _id=?"];
-
- sqlite3_prepare_v2(db, [sql UTF8String], -1, &stmt, nil);
- sqlite3_bind_text(stmt,1,[[NSString stringWithFormat:@"%ld",item_qty] UTF8String],(int)[[NSString stringWithFormat:@"%ld",item_qty] length],NULL);
- sqlite3_bind_text(stmt,2,[[NSString stringWithFormat:@"%d",_id] UTF8String],(int)[[NSString stringWithFormat:@"%d",_id] length],NULL);
- shouldStep = YES;
- }
- }
-
-
-
- }
-
-
- if (shouldStep) {
-
- if (sqlite3_step(stmt) == SQLITE_ERROR) {
- [iSalesDB execSql:@"ROLLBACK" db:db];
- ret[@"result"]=[NSNumber numberWithInt:RESULT_ERROR ];
-
- [iSalesDB close_db:db];
- DebugLog(@"add to cart error");
- return [RAConvertor dict2data:ret];
- }
- }
-
- }
-
-
-
-
- int cart_count=[iSalesDB get_recordcount:db table:@"offline_cart" where:[NSString stringWithFormat:@"so_no='%@'",orderCode]];
-
- int wish_count=[iSalesDB get_recordcount:db table:@"wishlist" where:@"is_delete is NULL or is_delete != 1"];
- ret[@"wish_count"]=[NSNumber numberWithInt:wish_count ];
- ret[@"cart_count"]=[NSNumber numberWithInt:cart_count ];
- ret[@"result"]=[NSNumber numberWithInt:RESULT_TRUE ];
- if (![params[@"can_create_backorder"] boolValue]) {
- if (number_of_outOfStock > 0) {
- ret[@"result"]=[NSNumber numberWithInt:8];
- ret[@"err_msg"] = @"Out of Stock.\nNo more quantity available.\nPlease try again after sync.";
- /*[NSString stringWithFormat:@"%d item is out of stock",number_of_outOfStock]*/
- }
- }
-
- [iSalesDB execSql:@"END TRANSACTION" db:db];
- [iSalesDB close_db:db];
-
- return [RAConvertor dict2data:ret];
- }
- +(NSDictionary*) model_bundle:(int) item_id db:(sqlite3*)db compute_part:(bool)compute contactID:(NSString *)contactID user:(NSString*)user
- {
- // 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:contactID user:user product_id:nil item_id:@(bitem_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 contactID:contactID user:user];
- }
- 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 * dict_item = [[NSMutableDictionary alloc]init];
-
- dict_item[@(item_id)]=@"1";
- NSMutableDictionary* ret = [[NSMutableDictionary alloc]init];
-
- double cuft=0;
- double weight=0;
- int carton=0;
- int impack=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);
- impack = mpack;
- 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;
- }
-
-
- }
-
- }
- #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)|| defined (BUILD_CONTRAST)
- cuft=ucbf*count;
- weight= uweight*count;
- #endif
-
- #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
- 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++)
- {
- dict_item[arr_bundle[i]]=@"1";
-
- 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];
-
- [dict_item addEntriesFromDictionary:bundlejson[@"items"]];
-
- }
- }
- ret[@"cuft"]= [NSNumber numberWithDouble:cuft];
- ret[@"mpack"]= [NSNumber numberWithInteger:impack];
- ret[@"weight"]= [NSNumber numberWithDouble:weight];
- ret[@"carton"]= [NSNumber numberWithInteger:carton];
- ret[@"items"]=dict_item;
- return ret;
- }
- +(int) query_ordercartcount:(NSString*) orderCode db:(sqlite3*)db
- {
-
-
-
-
- NSString *sqlQuery = [ NSString stringWithFormat:@"select item_id from offline_cart where so_no='%@'",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;
-
-
-
-
- int cart_count=0;
- int dbresult=sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil);
- if ( dbresult== SQLITE_OK)
- {
-
-
- while (sqlite3_step(statement) == SQLITE_ROW)
- {
-
- int item_id = sqlite3_column_int(statement, 0);
-
-
- NSDictionary* bsubtotaljson=[self model_subtotal:item_id count:1 db:db compute_part:true];
-
- cart_count+=[bsubtotaljson[@"items"] allKeys].count;
-
- }
-
-
-
- sqlite3_finalize(statement);
- }
-
-
- return cart_count;
-
- }
- //+(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"];
- //
- // int sort = [[params objectForKey:@"sort"] intValue];
- // NSString *sort_str = @"";
- // switch (sort) {
- // case 0:{
- // sort_str = @"order by c.modify_time desc";
- // }
- // break;
- // case 1:{
- // sort_str = @"order by c.modify_time asc";
- // }
- // break;
- // case 2:{
- // sort_str = @"order by m.name asc";
- // }
- // break;
- // case 3:{
- // sort_str = @"order by m.name desc";
- // }
- // break;
- // case 4:{
- // sort_str = @"order by m.description asc";
- // }
- // break;
- //
- // default:
- // break;
- //
- // }
- //
- //
- //
- // 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,m.availability from (select _id,product_id,decrypt(str_price) as price,discount,item_count,line_note,item_id,modify_time from offline_cart where so_no='%@') c left join product m on c.product_id=m.product_id %@",orderCode,sort_str ];
- //
- //
- //// 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"];
- //
- // NSDate *date1 = [NSDate date];
- //
- // int count=0;
- // int cart_count=0;
- // int dbresult=sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil);
- // if ( dbresult== SQLITE_OK)
- // {
- //
- //
- // while (sqlite3_step(statement) == SQLITE_ROW)
- // {
- //// NSDate *row_date = [NSDate date];
- //
- //
- // 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];
- //// NSDate *price_date = [NSDate date];
- // NSNumber* price = [self get_model_default_price:appDelegate.contact_id product_id:nil item_id:@(item_id) db:db];
- //// DebugLog(@"price time interval");
- //// [self printTimeIntervalBetween:price_date and:[NSDate date]];
- //
- // 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);
- // int availability = sqlite3_column_int(statement, 10);
- //
- //// NSDate *subtotal_date = [NSDate date];
- // NSDictionary* bsubtotaljson=[self model_subtotal:item_id count:item_count db:db compute_part:true];
- //// DebugLog(@"subtotal_date time interval");
- //// [self printTimeIntervalBetween:subtotal_date and:[NSDate date]];
- //
- // double cuft=[bsubtotaljson[@"cuft"] doubleValue];
- // double weight=[bsubtotaljson[@"weight"] doubleValue];
- // int carton=[bsubtotaljson[@"carton"] intValue];
- // cart_count+=[bsubtotaljson[@"items"] allKeys].count;
- //
- //// itemjson[@"img_url"]= [self model_category_img:[NSString stringWithFormat:@"%@",[NSNumber numberWithInt:item_id]] model_name:nil db:db];
- //// NSDate *img_date = [NSDate date];
- // itemjson[@"img_url"] = [self item_image:[NSString stringWithFormat:@"%@",[NSNumber numberWithInt:item_id]] db:db];
- //// DebugLog(@"img_date time interval");
- //// [self printTimeIntervalBetween:img_date and:[NSDate date]];
- //
- // 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;
- // if (!appDelegate.can_create_backorder) {
- // itemjson[@"is_out_of_stock"] = [NSNumber numberWithBool:availability >= item_count ? NO : YES];
- // }
- //// NSDate *date2 = [NSDate date];
- // itemjson[@"combine"]=[self model_bundle:item_id db:db compute_part:false contactID:appDelegate.contact_id];
- //// DebugLog(@"model_bundle time interval");
- //// [self printTimeIntervalBetween:date2 and:[NSDate date]];
- //
- // ret[[NSString stringWithFormat:@"item_%d",count]]=itemjson;
- // count++;
- //
- //// DebugLog(@"row time interval");
- //// [self printTimeIntervalBetween:row_date and:[NSDate date]];
- // }
- //
- //
- // ret[@"result"]=[NSNumber numberWithInt:RESULT_TRUE ];
- // sqlite3_finalize(statement);
- // }
- //
- //
- // DebugLog(@"request cart total time interval");
- // [self printTimeIntervalBetween:date1 and:[NSDate date]];
- //
- //
- // //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: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 [RAConvertor 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 setObject:@(YES) forKey:@"can_create_backorder"];
-
- [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"];
-
-
-
- int wish_count = [iSalesDB get_recordcount:db table:@"wishlist" where:@"is_delete is NULL or is_delete != 1"];
- [header setObject:[NSString stringWithFormat:@"%d",wish_count] forKey:@"wish_count"];
-
- // int portfolio_count = [iSalesDB get_recordcount:db table:@"portfoliolist" where:@"1=1"];
- // [header setObject:[NSString stringWithFormat:@"%d",wish_count] forKey:@"portfolio_count"];
- int portfolio_count = [iSalesDB get_recordcount:db table:@"offline_portfolio" where:@"is_delete is NULL or is_delete != 1"];
- [header setObject:[NSString stringWithFormat:@"%d",portfolio_count] forKey:@"portfolio_count"];
-
- [ret setObject:header forKey:@"header"];
- [ret setValue:nsmode forKey:@"mode"];
-
-
-
- }
-
-
-
- sqlite3_finalize(statement);
- }
-
-
-
- [iSalesDB close_db:db];
-
-
- DebugLog(@"data string: %@",[RAConvertor dict2string:ret] );
-
- return [RAConvertor dict2data:ret];
- }
- +(NSDictionary*) offline_contactinfo :(NSMutableDictionary *) params
- {
-
- assert(params[@"mode"]!=nil);
-
- NSString* contactId = [params valueForKey:@"contactId"];
-
-
- NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
-
-
-
- NSMutableDictionary* item = [[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,type,carrier from offline_contact where contact_id='%@'",contactId];
-
- }
-
-
- DebugLog(@"offline_contactlist sql:%@",sqlQuery);
- sqlite3_stmt * statement;
-
-
- [ret setValue:@"2" forKey:@"result"];
-
-
- int carrier = -1;
-
- 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"];
-
-
-
-
- // 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];
-
- NSString *contact_type = [self textAtColumn:24 statement:statement];
-
- carrier = sqlite3_column_int(statement, 25);
-
-
-
-
- {
- // 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=[RAConvertor 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=[RAConvertor 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"];
- [item setValue:contact_type forKey:@"customer_contact_type"];
-
- // i++;
-
-
-
- }
-
-
-
-
- // UIApplication * app = [UIApplication sharedApplication];
- // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- [ret setValue:params[@"mode"] forKey:@"mode"];
- [ret setValue:[NSNumber numberWithInt:1 ] forKey:@"count"];
-
-
-
- sqlite3_finalize(statement);
- }
-
-
-
- [iSalesDB close_db:db];
-
- NSString* scarrier = [self offline_getCarrier:carrier];
-
-
- item[@"customer_truck_carrier"] = scarrier;
-
- [ret setObject:item forKey:@"customerInfo"];
-
-
- DebugLog(@"data string: %@",[RAConvertor 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 [RAConvertor 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 [RAConvertor 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];
- // }
- }
-
-
- if(! [fileManager fileExistsAtPath:img_cache isDirectory:&bdir])
- {
-
- NSError *error = nil;
- bool bsuccess=[fileManager createDirectoryAtPath:img_cache withIntermediateDirectories:YES attributes:nil error:&error];
-
- if(!bsuccess)
- {
- DebugLog(@"Create img_cache folder failed");
- [ret setValue:[NSNumber numberWithInt:RESULT_ERROR] forKey:@"result"];
- return [RAConvertor 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:@"%@.jpg",[[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 [RAConvertor 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 =nil;
-
- #ifdef BUILD_NPD
- 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 ;
- #else
- 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 i.default_img = %d order by aa limit 10 ;",category,OFFLINE_IMG_TYPE_CATEGORY];
-
- #endif
- 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);
- }
- DebugLog(@"count:%d",count);
-
-
- // [iSalesDB close_db:db];
-
-
- return ret;
-
-
- }
- +(NSDictionary*) model_priceKvItem:(NSString*) key value:(NSString*)value
- {
- NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
-
- [ret setValue:key forKey:@"key"];
- [ret setValue:value forKey:@"val"];
- [ret setValue:@"price" forKey:@"type"];
- 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;
- }
- + (NSDictionary *) offline_add2wishlist:(NSMutableDictionary *)params {
- // UIApplication * app = [UIApplication sharedApplication];
- // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
-
- NSMutableDictionary* ret=[[NSMutableDictionary alloc]init];
- sqlite3 *db = [iSalesDB get_db];
-
- [iSalesDB execSql:@"BEGIN TRANSACTION" db:db];
-
- NSString* product_id=params[@"product_id"];
- NSString *item_count_str = params[@"item_count"];
-
-
- NSArray* arr=[RAConvertor string2arr:product_id separator:@","];
-
- NSArray *item_count_arr = item_count_str ? [RAConvertor string2arr:item_count_str separator:@","] : nil;
-
-
- NSString* sqlQuery = [NSString stringWithFormat:@"insert into wishlist(product_id,qty) values(?,?);"];
- // NSString *sql = @"";
- 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];
-
- __block int cart_count = 0;
- if (!item_count_str) {
- NSString *product_sold_qty_sql = [NSString stringWithFormat:@"select model_set from product where product_id = %@",arr[i]];
- [iSalesDB jk_query:product_sold_qty_sql db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- NSString *model_set = [self textAtColumn:0 statement:stmt];
- NSArray *model_set_components = [model_set componentsSeparatedByString:@" "];
- cart_count = [[model_set_components lastObject] intValue];
-
- }];
- }
-
- if(count==0)
- {
-
- sqlQuery = [NSString stringWithFormat:@"insert into wishlist(product_id,qty) values(?,?);"];
-
- sqlite3_stmt *stmt;
- sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &stmt, nil);
- sqlite3_bind_text(stmt,1,[arr[i] UTF8String],(int)[arr[i] length],NULL);
- if (item_count_arr) {
- sqlite3_bind_int(stmt,2,[item_count_arr[i] intValue]);
- } else {
- sqlite3_bind_int(stmt,2,cart_count);
- }
-
- if (sqlite3_step(stmt) == SQLITE_ERROR) {
- [iSalesDB execSql:@"ROLLBACK" db:db];
- ret[@"result"]=[NSNumber numberWithInt:RESULT_ERROR ];
-
- [iSalesDB close_db:db];
- DebugLog(@"add to wishlist error");
- return ret;
- }
- } else {
- int qty = 0;
- if (item_count_arr) {
- qty = [item_count_arr[i] intValue];
- } else {
- qty = cart_count;
- }
- sqlQuery = [NSString stringWithFormat:@"update wishlist set qty = 1 where product_id = %@ and (is_delete is null or is_delete != 1);update wishlist set qty = %d,is_delete = 0 where product_id = %@ and is_delete = 1;",arr[i],qty,arr[i]];
-
- if ([iSalesDB execSql:sqlQuery db:db] == RESULT_FALSE) {
- [iSalesDB execSql:@"ROLLBACK" db:db];
- ret[@"result"]=[NSNumber numberWithInt:RESULT_ERROR];
-
- [iSalesDB close_db:db];
- DebugLog(@"add to wishlist error");
- return ret;
-
- }
- }
-
- }
- // [iSalesDB execSql:sql db:db];
- int count=[iSalesDB get_recordcount:db table:@"wishlist" where:@"is_delete is NULL or is_delete != 1"];
- [iSalesDB execSql:@"END TRANSACTION" db:db];
-
- // int wish_count = [iSalesDB get_recordcount:db table:@"wishlist" where:@"1=1"];
- [ret setValue:[NSNumber numberWithInteger:count] forKey:@"wish_count"];
- [iSalesDB close_db:db];
-
-
- ret[@"wish_count"]=@(count);
- ret[@"result"]= [NSNumber numberWithInt:2];
-
-
- return ret;
-
- }
- + (NSData *) addAll:(NSMutableDictionary *) params from:(int)from {
-
- // 0 category
- // 1 search
- // 2 itemsearch
-
- NSData *ret = nil;
-
- NSDictionary *items = nil;
-
- switch (from) {
- case 0:{
- items = [[self categoryList:params limited:NO] objectForKey:@"items"];
- }
- break;
- case 1:{
- items = [[self search:params limited:NO] objectForKey:@"items"];
- }
- break;
- case 2:{
- items = [[self itemsearch:params limited:NO] objectForKey:@"items"];
- }
- break;
- default:
- break;
- }
- if (!items) {
- return ret;
- }
-
- int count = [[items objectForKey:@"count"] intValue];
- NSMutableString *product_id_str = [@"" mutableCopy];
- for (int i = 0; i < count; i++) {
- NSString *key = [NSString stringWithFormat:@"item_%d",i];
- NSDictionary *item = [items objectForKey:key];
- NSString *product_id = [item objectForKey:@"product_id"];
- if (i == 0) {
- [product_id_str appendString:product_id];
- } else {
- [product_id_str appendString:[NSString stringWithFormat:@",%@",product_id]];
- }
- }
-
- NSString *add_to = [self valueInParams:params key:@"addTo"];
- if ([add_to isEqualToString:@"cart"]) {
-
- NSString *order_code = [params objectForKey:@"orderCode"];
- if (order_code.length) {
- NSDictionary *newParams = @{
- @"product_id" : product_id_str,
- @"orderCode" : order_code,
- @"can_create_backorder":params[@"can_create_backorder"]
- };
- ret = [self offline_add2cart:newParams.mutableCopy];
-
- NSMutableDictionary *retDic = [[NSJSONSerialization JSONObjectWithData:ret options:NSJSONReadingMutableContainers error:nil] mutableCopy];
- [retDic setValue:[NSNumber numberWithInteger:count] forKey:@"count"];
-
- ret = [RAConvertor dict2data:retDic];
- }
-
-
- } else if([add_to isEqualToString:@"wishlist"]) {
-
- NSDictionary *newParams = @{
- @"product_id" : product_id_str
- };
-
- NSMutableDictionary *retDic = [self offline_add2wishlist:newParams.mutableCopy].mutableCopy;
- [retDic setValue:[NSNumber numberWithInteger:count] forKey:@"count"];
-
- ret = [RAConvertor dict2data:retDic];
-
-
- } else if([add_to isEqualToString:@"portfolio"]) {
-
-
- NSDictionary *newParams = @{
- @"product_id" : product_id_str
- };
- NSData *data = [self offline_add2Portfolio:newParams.mutableCopy];
- NSMutableDictionary *retDic = [[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil] mutableCopy];
-
- [retDic setValue:[NSNumber numberWithInteger:count] forKey:@"count"];
-
- ret = [RAConvertor dict2data:retDic];
- }
-
- return ret;
-
- }
- +(NSData*) offline_categoryaddall :(NSMutableDictionary *) params
- {
- return [self addAll:params from:0];
- }
- +(NSData*) offline_searchaddall :(NSMutableDictionary *) params
- {
- return [self addAll:params from:1];
- }
- +(NSData*) offline_itemsearchaddall :(NSMutableDictionary *) params
- {
- return [self addAll:params from:2];
- }
- #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 numberWithLong:ret.allKeys.count] forKey:@"count"];
- return ret;
- }
- + (NSDictionary *)offline_OrderCarrier:(NSString *)order_code db:(sqlite3 *)db {
- // "val_227" : {
- // "check" : 1,
- // "value" : "US United States",
- // "value_id" : "228"
- // },
-
- __block NSString* OrderCarrier =@"";
-
- // sqlite3 *db = [iSalesDB get_db];
-
- // sqlite3_stmt * statement;
-
-
- [iSalesDB jk_query:[NSString stringWithFormat:@"select carrier from offline_order where so_id='%@';",order_code] db:db close:NO completion:^(sqlite3_stmt *statment, NSMutableDictionary *container, long *count) {
-
- OrderCarrier = [self textAtColumn:0 statement:statment];
- // sqlite3_finalize(statement);
-
- }];
- // [iSalesDB close_db:db];
-
- __block int c=0;
-
- NSMutableDictionary *ret = [[iSalesDB jk_query:@"select _id,name,code_id from carrier order by name;" db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- char *name = (char *) sqlite3_column_text(stmt, 1); // 全称
- int code_id = sqlite3_column_int(stmt, 2); // id
-
- NSMutableDictionary *carrierDic = [NSMutableDictionary dictionaryWithCapacity:2];
- [carrierDic setValue:[NSString stringWithFormat:@"%s",name] forKey:@"value"];
- [carrierDic setValue:[NSString stringWithFormat:@"%d",code_id] forKey:@"value_id"];
- [carrierDic setValue:[NSNumber numberWithInt:0] forKey:@"check"];
-
- if ([OrderCarrier isEqualToString:[NSString stringWithUTF8String:name]]) {
- [carrierDic setValue:[NSNumber numberWithInt:1] forKey:@"check"];
- }
- c++;
- long n = *count;
- *count = n + 1;
- NSString *key = [NSString stringWithFormat:@"val_%ld",n];
- [container setValue:carrierDic forKey:key];
-
- }] mutableCopy];
-
-
-
- [ret setValue:[NSNumber numberWithLong:c] forKey:@"count"];
-
-
-
-
-
- return ret;
- }
- + (NSDictionary *)offline_getAllCarrier:(NSString *)carrierName {
- // "val_227" : {
- // "check" : 1,
- // "value" : "US United States",
- // "value_id" : "228"
- // },
-
-
- NSMutableDictionary *ret = [[iSalesDB jk_query:@"select _id,name,code_id from carrier order by name;" completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container,long *count) {
- char *name = (char *) sqlite3_column_text(stmt, 1); // 全称
- int code_id = sqlite3_column_int(stmt, 2); // id
-
- NSMutableDictionary *carrierDic = [NSMutableDictionary dictionaryWithCapacity:2];
- [carrierDic setValue:[NSString stringWithFormat:@"%s",name] forKey:@"value"];
- [carrierDic setValue:[NSString stringWithFormat:@"%d",code_id] forKey:@"value_id"];
- [carrierDic setValue:[NSNumber numberWithInt:0] forKey:@"check"];
-
- if ([carrierName isEqualToString:[NSString stringWithUTF8String:name]]) {
- [carrierDic setValue:[NSNumber numberWithInt:1] forKey:@"check"];
- }
-
- long n = *count;
- *count = n + 1;
- NSString *key = [NSString stringWithFormat:@"val_%ld",n];
- [container setValue:carrierDic forKey:key];
- }] mutableCopy];
-
- [ret setValue:[NSNumber numberWithLong:ret.allKeys.count] forKey:@"count"];
- return ret;
- }
- //+ (NSString *)offline_getContactCarrier:(int)contact_id {
- // // "val_227" : {
- // // "check" : 1,
- // // "value" : "US United States",
- // // "value_id" : "228"
- // // },
- //
- // NSString *Sql = [NSString stringWithFormat: @"select carrier from offline_contact where contact_id = %d;",contact_id];
- // NSString * code = [iSalesDB jk_queryText:Sql];
- //
- // return [self offline_getCarrier:code];
- //
- //}
- + (NSString *)offline_getCarrier:(int)code {
- // "val_227" : {
- // "check" : 1,
- // "value" : "US United States",
- // "value_id" : "228"
- // },
-
- NSString *Sql = [NSString stringWithFormat: @"select name from carrier where code_id = %d;",code];
- NSString * ret = [iSalesDB jk_queryText:Sql];
-
- return ret;
- }
- + (int )offline_getCarrierCode:(NSString*)name {
- // "val_227" : {
- // "check" : 1,
- // "value" : "US United States",
- // "value_id" : "228"
- // },
-
- NSString *Sql = [NSString stringWithFormat: @"select code from carrier where name = '%@';",name];
- NSString * ret = [iSalesDB jk_queryText:Sql];
-
- return [ret intValue];
- }
- + (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];
- [ret removeObjectForKey:@"result"];
- // 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 numberWithLong: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 removeObjectForKey:@"result"];
- [ret setValue:[NSNumber numberWithLong:ret.allKeys.count] forKey:@"count"];
-
- return ret;
- }
- + (NSDictionary *)offline_getPrice {
-
- NSString *sql = [NSString stringWithFormat:@"select _id,name,type,order_by from price where is_show = 1;"];
-
- 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_%ld",(*count)++];
- [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 numberWithLong:ret.allKeys.count] forKey:@"count"];
-
- return ret;
- }
- + (NSDictionary *)offline_getContactTypeChecked:(NSString *)type {
- NSString *sql = @"select _id,type_name from contact_type where is_show = 1";
- __block NSMutableDictionary *ret = [NSMutableDictionary dictionary];
- [ret setValue:[NSNumber numberWithInt:0] forKey:@"count"];
-
- [iSalesDB jk_query:sql completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- // int _id = sqlite3_column_int(stmt, 0);
- NSString *name = [self textAtColumn:1 statement:stmt];
-
- NSDictionary *typeDic = @{
- @"value_id" : name,
- @"value" : name,
- @"check" : type && [type isEqualToString:name] ? @(1) : !type && *count == 0 ? @(1) : @(0)
- };
-
- [ret setValue:typeDic forKey:[NSString stringWithFormat:@"val_%ld",*count]];
- [ret setValue:[NSNumber numberWithLong:++(*count)] forKey:@"count"];
-
- } failure:^(NSMutableDictionary *container, NSString *err_msg) {
-
- }];
-
- return ret;
- }
- + (NSDictionary *)offline_getSalesRep:(NSString*) user{
-
- // 首先从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 numberWithLong: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];
- NSString *text = [NSString stringWithCString:tx encoding:NSUTF8StringEncoding];
-
- 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
- sqlQuery = [NSString stringWithFormat:@"select i.url from model_image as i where item_id = %@ order by i.default_img desc, i._id asc limit 1;",item_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 *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 Advanced search
- +(NSData *) offline_contactAdvancedSearch:(NSMutableDictionary *) params
- {
- NSMutableDictionary *contactAdvanceDic = [self dictionaryFileName:@"contactAdvanceSearch.json"];
- return [RAConvertor dict2data:contactAdvanceDic];
- }
- #pragma mark create new contact
- + (NSData *)offline_createContact:(NSMutableDictionary *)params {
-
- assert(params[@"user"]!=nil);
-
- 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;
- NSString *carrierCode = 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";
- NSString *code_id = params[@"country"];
- countryCode = [self countryCodeByid:code_id];
- }
-
- stateCode = [dic valueForKey:@"state_code"];
- if (!stateCode.length) {
- stateCode = params[@"state"];
- }
-
- city = [dic valueForKey:@"city"];
- if (!city.length) {
- city = params[@"city"];
- }
-
- // zip code
- NSMutableDictionary *zipDic = [[section_0 valueForKey:@"item_11"] mutableCopy];
- [zipDic setValue:zipCode forKey:@"value"];
- [section_0 setValue:zipDic forKey:@"item_11"];
- } else {
-
- NSString *code_id = params[@"country"];
- countryCode = [self countryCodeByid:code_id];
- stateCode = params[@"state"];
- city = params[@"city"];
- }
- }
-
- } else {
- // default: US United States
- countryCode = @"US";
- countryCode_id = @"228";
- }
-
- // country
- NSDictionary *allCountry = [self offline_getAllCountryDefault:countryCode];
- [self setValue:allCountry forItemKey:@"item_6" 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_12" valueKey:@"cadedate" inDictionary:section_0];
-
- // city
- if (city) {
- NSMutableDictionary *cityDic = [[section_0 valueForKey:@"item_13"] mutableCopy];
- [cityDic setValue:city forKey:@"value"];
-
- [section_0 setValue:cityDic forKey:@"item_13"];
- }
-
- // price type
- NSDictionary *priceDic = [self offline_getPrice];
- [self setValue:priceDic forItemKey:@"item_2" valueKey:@"cadedate" inDictionary:section_0];
-
- // contact type
- NSDictionary *contactTypeDic = [self offline_getContactTypeChecked:nil];
- [self setValue:contactTypeDic forItemKey:@"item_3" valueKey:@"cadedate" inDictionary:section_0];
-
- // Sales Rep
- NSDictionary *repDic = [self offline_getSalesRep:params[@"user"]];
- [self setValue:repDic forItemKey:@"item_18" valueKey:@"cadedate" inDictionary:section_0];
-
- #ifdef BUILD_CONTRAST
- //carrier
- NSDictionary *carrierDic = [self offline_getAllCarrier:params[@"carrier"]];
- [self setValue:carrierDic forItemKey:@"item_19" valueKey:@"cadedate" inDictionary:section_0];
- #endif
-
- [ret setValue:section_0 forKey:@"section_0"];
-
- return [RAConvertor dict2data:ret];
- }
- #pragma mark save
- + (NSData *)offline_saveContact:(NSDictionary *)params update:(BOOL)update isCustomer:(BOOL)isCustomer{
-
- NSString *addr = nil;
- NSString *contact_name = nil;
- // int carrier = [params[@"carrier"] intValue];
- 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 = [RAConvertor 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 = @"";
- }
-
- int carrier = [params[@"carrier"] intValue];
-
-
-
-
- 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 = [RAConvertor 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;
-
- NSString *contact_type = [params objectForKey:@"type_name"];
- if (!contact_type) {
- contact_type = @"";
- }
- contact_type = [self translateSingleQuote:contact_type];
-
- // 判断更新时是否为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"];
- }
-
-
- sync_dic[@"truck_carrier"] = [self offline_getCarrier: [sync_dic[@"carrier"] intValue]];
- 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 = [RAConvertor 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 = '%@',type = '%@' ,carrier = %d 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_type,carrier,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 = [RAConvertor 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,type,carrier) values (1,'%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@',1,'%@',%d,%d,0,%d,0,1,'%@','%@','%@','%@',%d)",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,contact_type,carrier];
- }
-
- 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
- {
-
- assert(params[@"user"]!=nil);
- // {
- // "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;
- __block int carrierCode = -1;
-
- /*------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;
- __block NSString *contact_type;
-
- 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,type,carrier 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];
- contact_type = [self textAtColumn:20 statement:stmt];
- carrierCode = sqlite3_column_int(stmt, 21);
- }];
-
- // 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"];
- if (!countryCode) {
- NSString *code_id = params[@"country"];
- countryCode = [self countryCodeByid:code_id];
- }
-
- stateCode = [dic valueForKey:@"state_code"];
- if (!stateCode.length) {
- stateCode = params[@"state"];
- }
-
- city = [dic valueForKey:@"city"];
- if (!city.length) {
- city = params[@"city"];
- }
-
- // zip code
- NSMutableDictionary *zipDic = [[section_0 valueForKey:@"item_8"] mutableCopy];
- [zipDic setValue:zipcode forKey:@"value"];
- [section_0 setValue:zipDic forKey:@"item_8"];
- } else {
-
- NSString *code_id = params[@"country"];
- countryCode = [self countryCodeByid:code_id];
- stateCode = params[@"state"];
- city = params[@"city"];
- }
-
- }
-
- }
-
- // 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 Contact Type
- // 19 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];
-
- // Contact Rep
- NSDictionary *contactTypeDic = [self offline_getContactTypeChecked:contact_type];
- [self setValue:contactTypeDic forItemKey:@"item_18" valueKey:@"cadedate" inDictionary:section_0];
-
- // Sales Rep
- NSMutableDictionary *repDic = [[self offline_getSalesRep:params[@"user"]] 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_19" valueKey:@"cadedate" inDictionary:section_0];
-
- #ifdef BUILD_CONTRAST
- //carrier
-
- NSString* scarrier = [self offline_getCarrier:carrierCode];
- NSDictionary *carrierDic = [self offline_getAllCarrier:scarrier];
- [self setValue:carrierDic forItemKey:@"item_20" valueKey:@"cadedate" inDictionary:section_0];
- #endif
-
-
- [ret setValue:section_0 forKey:@"section_0"];
-
- return [RAConvertor 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 *)categoryList:(NSMutableDictionary *)params limited:(BOOL)limited {
- // 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];
- NSString *limit_str = @"";
- if (limited) {
- limit_str = [NSString stringWithFormat:@"limit %d offset %d ",limit,offset];
- }
-
-
- 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,c._id,w.is_delete,m.category,m.more_color from product m left join wishlist w on m.product_id=w.product_id left join (select _id,product_id from offline_cart where so_no='%@') c on c.product_id=m.product_id where m.category like'%%#%@#%%' and m.is_active = 1 order by m.name %@ ;",params[@"orderCode"], category,limit_str];
-
-
- 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 (params[@"user"] && price != nil) {
- NSArray *priceTypeArray = [self get_contact_default_price_type:nil user:params[@"user"] 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];
- }
-
-
- // model name;
- NSString* modelname =params[@"modelName"];
- if(modelname.length==0)
- {
- modelname=@"";
- }
- else
- {
-
- modelname = modelname.lowercaseString;
- modelname=[NSString stringWithFormat:@"and lower(name) like'%%%@%%'",modelname];
- }
-
-
- //modelDescription
- NSString* modelDescription =params[@"modelDescription"];
- if(modelDescription.length==0)
- {
- modelDescription=@"";
- }
- else
- {
-
- modelDescription = modelDescription.lowercaseString;
- modelDescription=[NSString stringWithFormat:@"and lower(description) like'%%%@%%'",modelDescription];
- }
- // cate
- // category = [self translateSingleQuote:category];
- // NSString *cateWhere = [NSString stringWithFormat:@"category like'%%#%@#%%'",category];
-
- // cate mutiple selection
- NSString *category_id = params[@"category"];
- 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];
- }
-
- [cateWhere appendString:@"("];
- for (int i = 0; i < cate_id_array.count; i++) {
-
- if (i == 0) {
- [cateWhere appendFormat:@"category like'%%#%@#%%'",cate_id_array[i]];
- } else {
- [cateWhere appendFormat:@" or category like'%%#%@#%%'",cate_id_array[i]];
- }
-
- }
- [cateWhere appendString:@")"];
-
- }
-
- // 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,c._id,w.is_delete,m.category,m.more_color from (select name,description,product_id,closeout,best_seller,category,more_color from product where %@ %@ %@ %@ %@ %@ %@ %@ and is_active = 1) m left join wishlist w on m.product_id=w.product_id left join (select _id,product_id from offline_cart where so_no='%@') c on c.product_id=m.product_id order by %@ %@;",cateWhere,best_seller,alert,available_condition,qty,modelname,modelDescription,price,params[@"orderCode"],order_best_seller,limit_str];
-
-
- where =[NSString stringWithFormat:@"%@ %@ %@ %@ %@ %@ and is_active = 1",cateWhere,best_seller,alert,available_condition,qty,price];
-
- }
- DebugLog(@"offline category where: %@",where);
- count = [iSalesDB get_recordcount:db table:@"product" where:where];
-
- if (!params[@"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);
- int cid = sqlite3_column_int(statement, 5);
- int wisdelete = sqlite3_column_int(statement, 6);
- NSString *categoryStr = [self textAtColumn:7 statement:statement];
- int more_color = sqlite3_column_int(statement, 8);
-
- // Defaul Category ID
- __block NSString *categoryID = nil;
- NSString *defaultCateSQL = [NSString stringWithFormat:@"select default_category from product where product_id=%d;",product_id];
- [iSalesDB jk_query:defaultCateSQL db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- char *default_category = (char*)sqlite3_column_text(stmt, 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:@""];
-
- categoryID = nsdefault_category;
-
- }];
-
- if (!categoryID.length) {
- NSString *cateIDs = params[@"category"];
- NSArray *requestCategoryArr = [cateIDs componentsSeparatedByString:@","];
- NSArray *itemCategoryArr = [categoryStr componentsSeparatedByString:@","];
- for (NSString *cateID in requestCategoryArr) {
-
- BOOL needBreak = NO;
- for (NSString *itemCateIDBox in itemCategoryArr) {
-
- if (itemCateIDBox.length > 4) {
- NSString *itemCategoryID = [itemCateIDBox substringFromIndex:2];
- itemCategoryID = [itemCategoryID substringToIndex:itemCategoryID.length - 2];
-
- if ([itemCategoryID isEqualToString:cateID]) {
- needBreak = YES;
- categoryID = itemCategoryID;
- break;
- }
- }
-
- }
- if (needBreak) {
- break;
- }
-
- }
- }
-
- NSMutableDictionary* imgjson=[self category_img:product_id db:db];
-
- if(wid !=0 && wisdelete != 1)
- [item setValue:@"true" forKey:@"wish_exists"];
- else
- [item setValue:@"false" forKey:@"wish_exists"];
-
- if(closeout==0)
- [item setValue:@"false" forKey:@"is_closeout"];
- else
- [item setValue:@"true" forKey:@"is_closeout"];
-
-
- if(cid==0)
- [item setValue:@"false" forKey:@"cart_exists"];
- else
- [item setValue:@"true" forKey:@"cart_exists"];
-
- if (more_color == 0) {
- [item setObject:@(false) forKey:@"more_color"];
- } else if (more_color == 1) {
- [item setObject:@(true) forKey:@"more_color"];
- }
-
- [item addEntriesFromDictionary:imgjson];
-
-
- // [item setValue:nsurl forKey:@"img"];
- [item setValue:nsname forKey:@"name"];
- [item setValue:nsdescription forKey:@"description"];
- if (categoryID) {
- [item setValue:categoryID forKey:@"item_category_id"];
- }
- [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: %@",[RAConvertor dict2string:ret] );
-
- return ret;
-
- }
- +(NSDictionary*) offline_category :(NSMutableDictionary *) params
- {
- return [self categoryList:params limited:YES];
- }
- # pragma mark item search
- + (NSDictionary *) itemsearch:(NSMutableDictionary *)params limited:(BOOL)limited {
- // AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
-
- // assert(params[@"order_code"]);
- // params[@"user"]
- 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];
-
- NSString *limit_str = @"";
- if (limited) {
- limit_str = [NSString stringWithFormat:@"limit %d offset %d",limit,offset];
- }
-
-
- 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,c._id,w.is_delete,m.more_color from product m left join wishlist w on m.product_id=w.product_id left join (select _id,product_id from offline_cart where so_no='%@') c on c.product_id=m.product_id where %@ order by %@ %@;",params[@"orderCode"], where,orderby,limit_str];
-
-
- 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 (params[@"user"]) {
- NSArray *priceTypeArray = [self get_contact_default_price_type:nil user:params[@"user"] 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];
- }
- // model name;
- NSString* modelname =params[@"modelName"];
- if(modelname.length==0)
- {
- modelname=@"";
- }
- else
- {
-
- modelname = modelname.lowercaseString;
- modelname=[NSString stringWithFormat:@"and lower(name) like'%%%@%%'",modelname];
- }
-
-
- //modelDescription
- NSString* modelDescription =params[@"modelDescription"];
- if(modelDescription.length==0)
- {
- modelDescription=@"";
- }
- else
- {
-
- modelDescription = modelDescription.lowercaseString;
- modelDescription=[NSString stringWithFormat:@"and lower(description) like'%%%@%%'",modelDescription];
- }
-
- //lower(description) like'%%%@%%'
- // 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];// 老子
-
- [cateWhere appendString:@"("];
- 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];
-
- }
-
- } else if ([key1 isEqualToString:@"cid"]) { // 2017-03-10 修复Item Search父节点下没有子节点的情况下选中父节点查询没有结果
-
- if ([[category0 objectForKey:@"cid"] isEqualToString:cate_id_array[i]]) {
-
- cate_id_array[i] = [category0 objectForKey:@"id"];
- if (i == 0) {
- [cateWhere appendFormat:@"category like'%%#%@#%%'",cate_id_array[i]];
- } else {
- [cateWhere appendFormat:@" or category like'%%#%@#%%'",cate_id_array[i]];
- }
- [category0 setValue:[NSNumber numberWithInteger:1] forKey:@"check"];
- [cateDic setValue:category0 forKey:key0];
-
- }
-
- }
-
- }
-
- }
-
- }
-
- }
- [cateWhere appendString:@")"];
-
- [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,c._id,w.is_delete,m.more_color from (select name,description,product_id,closeout,best_seller,more_color from product where %@ %@ %@ %@ %@ %@ %@ %@ and is_active = 1) m left join wishlist w on m.product_id=w.product_id left join (select _id,product_id from offline_cart where so_no='%@') c on c.product_id=m.product_id order by %@ %@;", cateWhere,best_seller,alert,available_condition,qty,modelname,modelDescription,price,params[@"orderCode"],order_best_seller,limit_str];
-
-
- // count
- where =[NSString stringWithFormat:@"%@ %@ %@ %@ %@ %@ %@ %@ and m.is_active = 1",cateWhere,best_seller,alert,available_condition,qty,modelname,modelDescription,price];
-
- }
- where = [where stringByReplacingOccurrencesOfString:@"m." withString:@""];
-
- count = [iSalesDB get_recordcount:db table:@"product" where:where];
-
-
-
-
- if (!params[@"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);
- int cid = sqlite3_column_int(statement, 5);
- int wisdelete = sqlite3_column_int(statement, 6);
- int more_color = sqlite3_column_int(statement, 7);
- NSMutableDictionary* imgjson=[self category_img:product_id db:db];
-
- if(wid !=0 && wisdelete != 1)
- [item setValue:@"true" forKey:@"wish_exists"];
- else
- [item setValue:@"false" forKey:@"wish_exists"];
-
- if(closeout==0)
- [item setValue:@"false" forKey:@"is_closeout"];
- else
- [item setValue:@"true" forKey:@"is_closeout"];
-
- if(cid==0)
- [item setValue:@"false" forKey:@"cart_exists"];
- else
- [item setValue:@"true" forKey:@"cart_exists"];
-
- if (more_color == 0) {
- [item setObject:@(false) forKey:@"more_color"];
- } else if (more_color == 1) {
- [item setObject:@(true) forKey:@"more_color"];
- }
-
- [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: %@",[RAConvertor dict2string:ret] );
-
- return ret;
-
- }
- +(NSDictionary*) offline_itemsearch:(NSMutableDictionary *) params
- {
- return [self itemsearch:params limited:YES];
- }
- #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;
- NSString *result = [formatter stringFromDate:date];
- return result ? result : @"";
-
- }
- + (NSString *)rchangeDateFormate:(NSString *)dateTime {
- return [self changeDateTime:dateTime Formate:@"MM/dd/yyyy" withFormate:@"yyyy-MM-dd"];
- // return [self timeFormat:dateTime from:@"YYYY-MM-DD HH:mm:ss" to:@"MM/DD/YYYY HH:mm:ss"];
- }
- + (NSString *)changeDateFormate:(NSString *)dateTime {
- return [self changeDateTime:dateTime Formate:@"yyyy-MM-dd" withFormate:@"MM/dd/yyyy"];
- // return [self timeFormat:dateTime from:@"YYYY-MM-DD HH:mm:ss" to:@"MM/DD/YYYY HH:mm:ss"];
- }
- + (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
- {
-
- assert(params[@"mode"]!=nil);
- assert(params[@"user"]!=nil);
-
- 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,o.editable,o.lift_null,o.handling_null,o.ship_via,c.city,c.state,c.zipcode,c.country,o.must_call,discount 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,order_id is null as editable,lift_gate_value is null as lift_null,handling_fee_value is null as handling_null,ship_via,must_call,discount 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 = @""; // 在查询结果中还需要调用offline_contactinfo,需要使用,其中要打开db 就会lock,故而将其置于外面,在close db后在调用
- NSString *nssoid = @"";
- NSString* orderinfo = @"";
- NSString *moreInfo = @"";
- double handlingFee = 0;
- double payments_and_credist = 0;
- double totalPrice = 0;
- double shippingFee = 0;
- double lift_gate = 0;
- NSString *customer_contact = @"";
- NSString *customer_email = @"";
- NSString *customer_fax = @"";
- NSString *customer_phone = @"";
- NSString *customer_city = @"";
- NSString *customer_state = @"";
- NSString *customer_zipcode = @"";
- NSString *customer_country = @"";
- BOOL must_call = NO;
- double discount = 0;
-
- __block NSMutableDictionary *section_0 = [NSMutableDictionary dictionary];
- __block NSMutableDictionary *section_1 = [NSMutableDictionary dictionary];
- __block NSMutableDictionary *section_2 = [NSMutableDictionary dictionary];
- __block NSMutableDictionary *section_3 = [NSMutableDictionary dictionary];
- __block NSMutableDictionary *section_4 = [NSMutableDictionary dictionary];
- __block NSMutableDictionary *price_data = [NSMutableDictionary dictionary];
-
- 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;
- section_1 = @{
- @"data":sign_url,
- @"title":@"Signature",
- @"type":@"sign_url"
- }.mutableCopy;
- [ret setObject:section_1 forKey:@"section_1"];
-
- 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];
-
- customer_city = [self textAtColumn:60 statement:statement];
- customer_state = [self textAtColumn:61 statement:statement];
- customer_zipcode = [self textAtColumn:62 statement:statement];
- customer_country = [self textAtColumn:63 statement:statement];
- must_call = [[self textAtColumn:64 statement:statement] boolValue];
-
- discount =sqlite3_column_double(statement, 65);
-
- int offline_edit=sqlite3_column_int(statement, 56);
-
- ret[@"offline_edit"]= [NSNumber numberWithInt:offline_edit];
-
- 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];
- [arr_addr addObject:[NSString stringWithFormat:@"%@,",customer_city]];
- [arr_addr addObject:customer_state];
- [arr_addr addObject:customer_zipcode];
- [arr_addr addObject:customer_country];
-
- // NSString * customer_address = [RAConvertor arr2string:arr_addr separator:@" " trim:true];
- NSString *customer_address = [NSString stringWithFormat:@"%@<br/>%@, %@ %@ %@",nsaddr_1,customer_city,customer_state,customer_zipcode,customer_country];
-
-
- char *logist = (char*)sqlite3_column_text(statement, 11);
- if(logist==nil)
- logist= "";
- NSString *nslogist=[[NSString alloc]initWithUTF8String:logist];
- if (/*status == -11 || */status == 10 || status == 11) {
- nslogist = [self textAtColumn:59 statement:statement];
- };
-
- 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;
- NSDictionary *shipping_item = @{
- @"title":@"Shipping",
- @"value":shipping
- };
- [price_data setObject:shipping_item forKey:@"item_1"];
-
- 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];
- NSString *liftgate_value = [NSString stringWithFormat:@"$%.2f",lift_gate];
- if (sqlite3_column_int(statement, 57)) {
- // ret[@"Liftgate Fee(No loading dock)"] = @"Shipping To Be Quoted";
- liftgate_value = @"Shipping To Be Quoted";
- }
- NSDictionary *liftgate_item = @{
- @"title":@"Liftgate Fee(No loading dock)",
- @"value":liftgate_value
- };
- [price_data setObject:liftgate_item forKey:@"item_2"];
-
- // if ([nslogist isEqualToString:@"WILL CALL"]) {
- // [ret removeObjectForKey:@"Shipping"];
- // [ret removeObjectForKey:@"Liftgate Fee(No loading dock)"];
- // }
- //
- // if (have_lift_gate) {
- // [ret removeObjectForKey:@"Liftgate Fee(No loading dock)"];
- // }
-
- char *general_notes = (char*)sqlite3_column_text(statement, 14);
- if(general_notes==nil)
- general_notes= "";
- NSString *nsgeneral_notes= [NSString stringWithFormat:@"MUST MAKE APPOINTMENT BEFORE DELIVERY = %@;<br/>%@",must_call ? @"YES" : @"NO",[[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;
-
- // id -> show
- __block NSString *show_pay_type = nspayment_type;
- [iSalesDB jk_query:[NSString stringWithFormat:@"select pay_type from payment_type where type_id = '%@';",nspayment_type] db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- char *show_typ_ch = (char*)sqlite3_column_text(stmt, 0);
- if (show_typ_ch != NULL) {
- show_pay_type = [NSString stringWithUTF8String:show_typ_ch];
- }
-
- }];
-
- if([nspayment_type isEqualToString:@"Credit Card"] || [nspayment_type isEqualToString:@"Visa/Master"])
- {
- 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:@"Payment_Type" withString:show_pay_type];
- 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];
- shipToAddr = [shipToAddr stringByReplacingOccurrencesOfString:@"\r\n" withString:@"<br/>"];
- shipToAddr = [shipToAddr stringByReplacingOccurrencesOfString:@"\r" withString:@"<br/>"]; // 手动输入的可能是\r 或 \n
- shipToAddr = [shipToAddr stringByReplacingOccurrencesOfString:@"\n" withString:@"<br/>"];
- 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];
- shipFromAddr = [shipFromAddr stringByReplacingOccurrencesOfString:@"\r\n" withString:@"<br/>"];
- shipFromAddr = [shipFromAddr stringByReplacingOccurrencesOfString:@"\r" withString:@"<br/>"];
- shipFromAddr = [shipFromAddr stringByReplacingOccurrencesOfString:@"\n" withString:@"<br/>"];
- 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];
- freightBillToAddr = [freightBillToAddr stringByReplacingOccurrencesOfString:@"\r\n" withString:@"<br/>"];
- freightBillToAddr = [freightBillToAddr stringByReplacingOccurrencesOfString:@"\r" withString:@"<br/>"];
- freightBillToAddr = [freightBillToAddr stringByReplacingOccurrencesOfString:@"\n" withString:@"<br/>"];
- 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];
- merchandiseBillToAddr = [merchandiseBillToAddr stringByReplacingOccurrencesOfString:@"\r\n" withString:@"<br/>"];
- merchandiseBillToAddr = [merchandiseBillToAddr stringByReplacingOccurrencesOfString:@"\r" withString:@"<br/>"];
- merchandiseBillToAddr = [merchandiseBillToAddr stringByReplacingOccurrencesOfString:@"\n" withString:@"<br/>"];
- 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];
- returnToAddr = [returnToAddr stringByReplacingOccurrencesOfString:@"\r\n" withString:@"<br/>"];
- returnToAddr = [returnToAddr stringByReplacingOccurrencesOfString:@"\r" withString:@"<br/>"];
- returnToAddr = [returnToAddr stringByReplacingOccurrencesOfString:@"\n" withString:@"<br/>"];
- 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];
- NSString *handling_fee_value = [NSString stringWithFormat:@"$%.2f",handlingFee];
- if (sqlite3_column_int(statement, 58)) {
- // ret[@"Handling Fee"] = @"Shipping To Be Quoted";
- handling_fee_value = @"Shipping To Be Quoted";
- }
- NSDictionary *handling_fee_item = @{
- @"title":@"Handling Fee",
- @"value":handling_fee_value
- };
- [price_data setObject:handling_fee_item forKey:@"item_3"];
- //
-
- // customer info
- customerID = [self textAtColumn:36 statement:statement];
-
- // mode
- ret[@"mode"] = params[@"mode"];
-
- // model_count
- ret[@"model_count"] = @(0);
-
- }
-
-
-
-
-
- sqlite3_finalize(statement);
-
-
-
-
- }
-
- [iSalesDB close_db:db];
-
- NSMutableDictionary *contactInfo = [[[self offline_contactinfo:[@{@"contactId":customerID,@"mode":params[@"mode"]} 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 NSMutableDictionary *model_data = [NSMutableDictionary dictionary];
- __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:customerID user:params[@"user"] 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 contactID:customerID user:params[@"user"]];
-
- // 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];
- // DebugLog(@"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];
-
- itemjson[@"type"] = @"order_item";
-
- model_data[[NSString stringWithFormat:@"item_%ld",(*count)++]] = itemjson;
- model_data[@"count"] = [NSNumber numberWithInteger:*count];
- ret[@"model_count"] = [NSNumber numberWithInteger:*count];
-
- allItemPrice += subTotal;
-
- }];
-
- section_3[@"data"] = model_data;
- section_3[@"type"] = @"sub_order";
- section_3[@"title"] = @"Models";
- section_3[@"switch"] = @(false);
- ret[@"section_3"] = section_3;
-
- 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[@"Sub-Total"] = [NSString stringWithFormat:@"$%.2f",payments_and_credist];
-
- NSDictionary *sub_total_item = @{
- @"title":@"Sub-Total",
- @"value":[NSString stringWithFormat:@"$%.2f",payments_and_credist]
- };
- [price_data setObject:sub_total_item forKey:@"item_0"];
-
- // // 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[@"Sub-Total"] = [NSString stringWithFormat:@"$%.2f",payments_and_credist];
- NSDictionary *sub_total_item = @{
- @"title":@"Sub-Total",
- @"value":[NSString stringWithFormat:@"$%.2f",payments_and_credist]
- };
- [price_data setObject:sub_total_item forKey:@"item_0"];
-
-
- }
- // total
- totalPrice = payments_and_credist + lift_gate + shippingFee + handlingFee;
- // ret[@"Total"] = [NSString stringWithFormat:@"$%.2f",totalPrice];
- if(discount>0)
- {
-
- NSDictionary *total_item = @{
- @"title":@"Total",
- @"value":[NSString stringWithFormat:@"$%.2f",totalPrice*(1-(discount/100.0))]
- };
-
- NSDictionary *discount_item = @{
- @"title":@"Order Discount",
- @"value":[NSString stringWithFormat:@"%d%% off",(int)discount]
- };
-
- [price_data setObject:discount_item forKey:@"item_4"];
- [price_data setObject:total_item forKey:@"item_5"];
- }
- else
- {
- NSDictionary *total_item = @{
- @"title":@"Total",
- @"value":[NSString stringWithFormat:@"$%.2f",totalPrice]
- };
- [price_data setObject:total_item forKey:@"item_4"];
- }
-
-
- [price_data setObject:@(price_data.allKeys.count) forKey:@"count"];
- section_4 = @{
- @"data":price_data,
- @"title":@"Price Info",
- @"type":@"price_info"
- }.mutableCopy;
- ret[@"section_4"] = section_4;
-
- // ret[@"order_info"]= orderinfo;
- section_0 = @{
- @"data":orderinfo,
- @"title":@"Order Info",
- @"type":@"order_info"
- }.mutableCopy;
- ret[@"section_0"] = section_0;
-
- // ret[@"more_order_info"] = moreInfo;
- section_2 = @{
- @"data":moreInfo,
- @"title":@"More Info",
- @"type":@"more_order_info"
- }.mutableCopy;
- ret[@"section_2"] = section_2;
-
- ret[@"count"] = @(5);
-
- return [RAConvertor 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;
- }
- case -11:
- {
- nsstatus = @"Ready For Submit";
- break;
- }
-
-
-
- default:
- break;
- }
-
- return nsstatus;
-
- }
- + (double) orderTotalPrice:(NSString *)so_id user:(NSString*) user 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];
-
- NSString *modelSql = [NSString stringWithFormat:@"select product_id,price,discount,item_count,item_id,customer_cid from (select c.product_id,decrypt(c.str_price) as price,c.discount,c.item_count,c.item_id,o.customer_cid from offline_cart as c left join offline_order as o on c.so_no = o.so_id where c.so_no='%@');",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 discount = sqlite3_column_int(stmt, 2);
- int item_count = sqlite3_column_int(stmt, 3);
-
- // int item_id = sqlite3_column_int(stmt, 7);
-
- int item_id = sqlite3_column_int(stmt, 4);
-
- char *customer_cid = (char *)sqlite3_column_text(stmt, 5);
- NSString *customerID = [NSString stringWithUTF8String:customer_cid];
-
- NSString* Price=nil;
- if(str_price==nil)
- {
- NSNumber* price = [self get_model_default_price:customerID user:user 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]];
- }
-
-
-
-
-
- itemjson[@"combine"]=[self model_bundle:item_id db:db1 compute_part:false contactID:customerID user:user];
-
- 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;
- __block double order_discount = 0;
- NSString *orderSql = [NSString stringWithFormat:@"select lift_gate,lift_gate_value,handling_fee_value,shipping,discount 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);
- order_discount = sqlite3_column_double(stmt, 4);
-
- }];
-
-
-
- if(order_discount>0)
- payments_and_credist= payments_and_credist*(1-order_discount/100.0);
- // total
- total = payments_and_credist + lift_gate + shippingFee + handlingFee;
-
-
- if (close) {
- [iSalesDB close_db:db1];
- }
- return total;
- }
- +(NSData*) offline_orderlist :(NSMutableDictionary *) params
- {
-
-
- assert(params[@"user"]!=nil);
-
- 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] intValue];
- if (status_value <= 1 || status_value == 3 || status_value == 15) {
-
- if (status_value == 15 || status_value == 3) {
- where = [where stringByAppendingString:[NSString stringWithFormat:@" and (o.status = 3 or o.erpOrderStatus = 15)"]];
- } else {
- 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 intValue];
- if (status_value <= 1 || status_value == 3 || status_value == 15) {
-
- if (status_value == 15 || status_value == 3) {
- where = [where stringByAppendingString:[NSString stringWithFormat:@" %@ (o.status = 3 or o.erpOrderStatus = 15)",condition]];
- } else {
- 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,o.order_id is null 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;
-
- [iSalesDB execSql:@"BEGIN TRANSACTION" db:db];
-
-
-
- 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];
-
- nscreate_time = [self changeDateTimeFormate:nscreate_time]; // 与在线统一
- // double total_price = sqlite3_column_double(statement, 7);
-
- double total_price = [self orderTotalPrice:[NSString stringWithUTF8String:soid] user:params[@"user"] db:db close:NO];
-
-
-
- NSString *customer_contact = [self textAtColumn:8 statement:statement];
-
- NSString* nsstatus = [self orderStatus:status erpStatus:erpStatus];
-
-
- int offline_edit = sqlite3_column_int(statement, 10);
-
- // ": "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;
- int statusCode = status;
- if (statusCode == 2) {
- statusCode = erpStatus;
- } else if (statusCode == 3) {
- statusCode = 15;
- }
- item[@"orderStatus"]= [NSString stringWithFormat:@"%d",statusCode];
- item[@"order_status"]= nsstatus;
- item[@"order_code"]= nssoid;//[NSString stringWithFormat:@"%d",order_id];
- item[@"offline_edit"] = [NSNumber numberWithInt:offline_edit];
- // 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 execSql:@"END TRANSACTION" db:db];
- [iSalesDB close_db:db];
-
- return [RAConvertor 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" translateSingleQuote:YES],[self valueInParams:params key:@"orderCode" translateSingleQuote:YES]];
- 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 [RAConvertor 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"];
-
- _id = [NSString stringWithFormat:@"(%@)",_id];
-
- NSString *sql = [NSString stringWithFormat:@"select product_id,item_count,item_id from offline_cart where so_no = '%@' and _id in %@;",orderCode,_id];
- sqlite3 *db = [iSalesDB get_db];
-
- __block NSString *product_id = @"";
- __block NSString *item_count_str = @"";
- // __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];
- int item_count = sqlite3_column_int(stmt, 1);
- // item_id = [self textAtColumn:2 statement:stmt];
- NSString *p_id = [self textAtColumn:0 statement:stmt];
- NSString *count_str = [NSString stringWithFormat:@"%d",item_count];
-
- if (p_id.length) {
- product_id = [product_id stringByAppendingString:[NSString stringWithFormat:@",%@",p_id]];
- item_count_str = [item_count_str stringByAppendingString:[NSString stringWithFormat:@",%@",count_str]];
- }
-
- }];
- [iSalesDB close_db:db];
- // 去除第一个,
- if (product_id.length > 1) {
- product_id = [product_id substringFromIndex:1];
- }
- if (item_count_str.length > 1) {
- item_count_str = [item_count_str substringFromIndex:1];
- }
-
- NSMutableDictionary *dic = [NSMutableDictionary dictionary];
-
- dic = [self offline_add2wishlist:@{@"product_id" : product_id,@"item_count" : item_count_str}.mutableCopy].mutableCopy;
-
-
-
- // 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];
-
- sqlite3 *db1 = [iSalesDB get_db];
-
- int wish_count = [iSalesDB get_recordcount:db1 table:@"wishlist" where:@"is_delete is NULL or is_delete != 1"];
-
- [dic setValue:@"Regular Mode" forKey:@"mode"];
-
- [dic setValue:[NSNumber numberWithInteger:wish_count] forKey:@"wish_count"];
-
- // 删除
-
- NSString *deleteSql = [NSString stringWithFormat:@"delete from offline_cart where _id in %@;",_id];
- int ret = [iSalesDB execSql:deleteSql db:db1];
- [dic setValue:[NSNumber numberWithInteger:ret] forKey:@"result"];
-
- [iSalesDB close_db:db1];
-
- return [RAConvertor 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"];
-
- _id = [NSString stringWithFormat:@"(%@)",_id];
-
- NSString *sql = [NSString stringWithFormat:@"delete from offline_cart where so_no = '%@' and _id in %@ ;",orderCode,_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 [RAConvertor dict2data:dic];
- }
- #pragma mark set order discount
- //+(NSDictionary*) offline_cartsetallprice :(NSMutableDictionary *) params
- //{
- // DebugLog(@"cart set price params: %@",params);
- // // "cartitem_id" = 1;
- // // discount = "0.000000";
- // // "item_note" = "";
- // // price = "269.000000";
- // NSString *order_code = [self valueInParams:params key:@"orderCode"];
- // //NSString *notes = [self valueInParams:params key:@"item_note"];
- // NSString *discount = [self valueInParams:params key:@"app_discount"];
- //// NSString *price = [self valueInParams:params key:@"price"];
- //
- // // bool badd_price_changed=false;
- // // sqlite3* db=[iSalesDB get_db];
- // // AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- // // NSNumber* default_price = [self get_model_default_price:appDelegate.contact_id product_id:nil item_id:_id db:db];
- // // NSRange range;
- // // range = [notes rangeOfString:@"PRICE MODIFIED"];
- // //
- // // if((default_price.doubleValue!=price.doubleValue || discount.intValue!=0 ) && range.location == NSNotFound)
- // // badd_price_changed=true;
- // // [iSalesDB close_db:db];
- // //
- // // if(badd_price_changed)
- // // {
- // // notes=[NSString stringWithFormat:@"%@\n%@",@"PRICE MODIFIED",notes];
- // // }
- // //
- //
- //
- //// price = [self translateSingleQuote:[AESCrypt fastencrypt:price]];
- //
- // NSString *sql = [NSString stringWithFormat:@"update offline_cart set discount = %f where so_no = '%@'",discount.doubleValue,order_code];
- //
- // 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 [RAConvertor dict2data:dic];
- // return dic;
- //
- //}
- +(NSDictionary*) offline_setorderdiscount :(NSMutableDictionary *) params
- {
- DebugLog(@"order set discount params: %@",params);
- // "cartitem_id" = 1;
- // discount = "0.000000";
- // "item_note" = "";
- // price = "269.000000";
- NSString *order_code = [self valueInParams:params key:@"orderCode"];
- //NSString *notes = [self valueInParams:params key:@"item_note"];
- NSString *discount = [self valueInParams:params key:@"app_discount"];
- // NSString *price = [self valueInParams:params key:@"price"];
-
- // bool badd_price_changed=false;
- // sqlite3* db=[iSalesDB get_db];
- // AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- // NSNumber* default_price = [self get_model_default_price:appDelegate.contact_id product_id:nil item_id:_id db:db];
- // NSRange range;
- // range = [notes rangeOfString:@"PRICE MODIFIED"];
- //
- // if((default_price.doubleValue!=price.doubleValue || discount.intValue!=0 ) && range.location == NSNotFound)
- // badd_price_changed=true;
- // [iSalesDB close_db:db];
- //
- // if(badd_price_changed)
- // {
- // notes=[NSString stringWithFormat:@"%@\n%@",@"PRICE MODIFIED",notes];
- // }
- //
- // sqlite3 *db = [iSalesDB get_db];
- // double total_price = [self orderTotalPrice:params[@"orderCode"] user:params[@"user"] db:db close:YES];
-
- // price = [self translateSingleQuote:[AESCrypt fastencrypt:price]];
-
- //NSString *sql = [NSString stringWithFormat:@"update offline_order set discount = %f, total_price=%f where so_id = '%@'",discount.doubleValue,total_price*(1-discount.doubleValue/100.0),order_code];
- NSString *sql = [NSString stringWithFormat:@"update offline_order set discount = %f where so_id = '%@'",discount.doubleValue,order_code];
-
- 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 [RAConvertor dict2data:dic];
- return dic;
-
- }
- +(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"];
-
- // bool badd_price_changed=false;
- // sqlite3* db=[iSalesDB get_db];
- // AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- // NSNumber* default_price = [self get_model_default_price:appDelegate.contact_id product_id:nil item_id:_id db:db];
- // NSRange range;
- // range = [notes rangeOfString:@"PRICE MODIFIED"];
- //
- // if((default_price.doubleValue!=price.doubleValue || discount.intValue!=0 ) && range.location == NSNotFound)
- // badd_price_changed=true;
- // [iSalesDB close_db:db];
- //
- // if(badd_price_changed)
- // {
- // notes=[NSString stringWithFormat:@"%@\n%@",@"PRICE MODIFIED",notes];
- // }
- //
-
-
- price = [self translateSingleQuote:[AESCrypt fastencrypt:price]];
-
- NSString *sql = [NSString stringWithFormat:@"update offline_cart set str_price = '%@',discount = %f, line_note='%@' where _id = %@",price,discount.doubleValue,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 [RAConvertor 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 [RAConvertor dict2data:dic];
- }
- #pragma mark set qty
- +(NSData*) offline_cartsetqty :(NSMutableDictionary *) params
- {
-
- assert(params[@"can_create_backorder"]!=nil);
-
-
- NSMutableDictionary *dic = [NSMutableDictionary dictionary];
-
- NSString *_id = [self valueInParams:params key:@"cartitem_id"];
- int item_count = [params[@"inputInt"] intValue];
-
- // 购买检查数量大于库存
- // AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- if (!params[@"can_create_backorder"]) {
- NSString *checkSql = [NSString stringWithFormat:@"select p.availability from product as p left join offline_cart as c on c.item_id = p.item_id where c._id = %@;",_id];
- __block BOOL out_of_stock = NO;
- [iSalesDB jk_query:checkSql completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- int availability = sqlite3_column_int(stmt, 0);
-
- if (availability < item_count) {
- out_of_stock = YES;
- }
-
- }];
-
- if (out_of_stock) { // 缺货
- [dic setValue:[NSNumber numberWithInteger:8] forKey:@"result"];
- [dic setObject:@"Item is out of stock" forKey:@"err_msg"];
- return [RAConvertor dict2data:dic];
- }
-
- }
-
- 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];
-
-
- [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 [RAConvertor 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,o.customer_email,o.customer_phone,o.customer_fax,c.zipcode,c.city,c.state,c.country,o.customer_contact 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 = [self textAtColumn:18 statement:stmt];
-
- // 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"];
-
- }];
-
- // setting
- NSDictionary *setting = params[@"setting"];
- NSNumber *hide = setting[@"CustomerHide"];
- [customer_dic setValue:hide forKey:@"hide"];
-
- return customer_dic;
- }
- + (NSDictionary *)shipToDic:(NSDictionary *)params db:(sqlite3 *)db {
-
- __block NSMutableDictionary *dic = [NSMutableDictionary dictionary];
-
- // setting
- NSDictionary *setting = params[@"setting"];
- NSNumber *hide = setting[@"ShipToHide"];
- [dic setValue:hide forKey:@"hide"];
-
-
-
- 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
- NSMutableDictionary *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
- NSMutableDictionary *ext_dic = [self infoName:@"receive_ext" aname:@"Address" control:@"text_view" keyboard:@"text" value:ext].mutableCopy;
- NSNumber *required = setting[@"ShippingToAddressRequire"];
- if ([required integerValue]) {
- [ext_dic setValue:@"true" forKey:@"required"];
- }
-
- [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];
-
- // setting
- NSDictionary *setting = params[@"setting"];
- NSNumber *hide = setting[@"ShipFromHide"];
- [dic setValue:hide forKey:@"hide"];
-
- 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];
-
- NSString *ship_from_default_sql = @"select contact_id,decrypt(company_name),decrypt(addr_1),first_name || ' ' || last_name,email,fax,phone from offline_contact where contact_id = 'NPD';";
-
- [iSalesDB jk_query:sql db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- __block NSString *cid = [self textAtColumn:0 statement:stmt];
- __block NSString *name = [self textAtColumn:1 statement:stmt];
- __block NSString *ext = [self textAtColumn:2 statement:stmt];
- __block NSString *contact = [self textAtColumn:3 statement:stmt];
- __block NSString *email = [self textAtColumn:4 statement:stmt];
- __block NSString *fax = [self textAtColumn:5 statement:stmt];
- __block NSString *phone = [self textAtColumn:6 statement:stmt];
-
- if (!cid.length) {
- [iSalesDB jk_query:ship_from_default_sql db:db close:NO completion:^(sqlite3_stmt *statment, NSMutableDictionary *container, long *count) {
-
- cid = [self textAtColumn:0 statement:statment];
- name = [self textAtColumn:1 statement:statment];
- ext = [self textAtColumn:2 statement:statment];
- contact = [self textAtColumn:3 statement:statment];
- email = [self textAtColumn:4 statement:statment];
- fax = [self textAtColumn:5 statement:statment];
- phone = [self textAtColumn:6 statement:statment];
-
- }];
- }
-
- // 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];
-
- // setting
- NSDictionary *setting = params[@"setting"];
- NSNumber *hide = setting[@"FreightBillToHide"];
- [dic setValue:hide forKey:@"hide"];
-
- 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
- NSMutableDictionary *ext_dic = [self infoName:@"shipping_billto_ext" aname:@"Address" control:@"text_view" keyboard:@"text" value:ext].mutableCopy;
- NSNumber *ext_required = setting[@"FreightBillToAddressRequire"];
- if ([ext_required integerValue]) {
- [ext_dic setValue:@"true" forKey:@"required"];
- }
-
- [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];
-
- // setting
- NSDictionary *setting = params[@"setting"];
- NSNumber *hide = setting[@"MerchandiseBillToHide"];
- [dic setValue:hide forKey:@"hide"];
-
- 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
- NSMutableDictionary *ext_dic = [self infoName:@"billing_ext" aname:@"Address" control:@"text_view" keyboard:@"text" value:ext].mutableCopy;
- NSNumber *ext_required = setting[@"MerchandiseBillToAddressRequire"];
- if ([ext_required integerValue]) {
- [ext_dic setValue:@"true" forKey:@"required"];
- }
-
- [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];
-
- // setting
- NSDictionary *setting = params[@"setting"];
- NSNumber *hide = setting[@"ReturnToHide"];
- [dic setValue:hide forKey:@"hide"];
-
- 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
- {
-
- assert(params[@"user"]!=nil);
- assert(params[@"contact_id"]!=nil);
-
- 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;
-
-
- // setting
- NSDictionary *setting = params[@"setting"];
- NSNumber *hide = setting[@"ModelInformationHide"];
- [dic setValue:hide forKey:@"hide"];
-
- NSString *sql = [NSString stringWithFormat:@"select c.item_id,c.item_count,m.stockUom,c.price,c.discount,m.name,m.description,c.line_note,m.availability 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:params[@"contact_id"] user:params[@"user"] 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];
-
- int avaulability = sqlite3_column_int(stmt, 8);
-
-
- // 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 contactID:params[@"contact_id"] user:params[@"user"]];
-
- 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"];
- [model_dic setValue:[NSNumber numberWithInt:avaulability] forKey:@"quantity_available"];
- 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];
- int mpack=[bsubtotaljson[@"mpack"] intValue];
-
- model_dic[@"mpack"]=[NSNumber numberWithInt:mpack];
-
- 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"];
-
- // setting
- NSDictionary *setting = params[@"setting"];
- NSNumber *hide = setting[@"RemarksContentHide"];
- [dic setValue:hide forKey:@"hide"];
-
- NSString *orderCode = [self valueInParams:params key:@"orderCode"];
- orderCode = [self translateSingleQuote:orderCode];
-
- NSString *sql = [NSString stringWithFormat:@"select poNumber,must_call,internal_notes,general_notes,schedule_date 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];
- NSString *schedule_date = [self textAtColumn:4 statement:stmt];
-
- NSDictionary *po_dic = @{
- @"aname" : @"PO#",
- @"control" : @"edit",
- @"keyboard" : @"text",
- @"name" : @"poNumber",
- @"value" : poNumber
- };
- #ifdef BUILD_CONTRAST
-
- NSString* nsdate = [self changeDateFormate:schedule_date]; // 与在线统一
- NSDictionary *schedule_dict = @{
- @"aname" : @"Schdule Date",
- @"control" : @"datepicker",
- @"type": @"date",
- @"required": @"true",
- @"name" : @"schedule_date_str",
- @"value" : nsdate
- };
- #endif
- 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
- // };
-
- #ifdef BUILD_CONTRAST
- [dic setValue:po_dic forKey:@"item_0"];
- [dic setValue:schedule_dict forKey:@"item_1"];
- [dic setValue:must_call_dic forKey:@"item_2"];
- [dic setValue:general_notes_dic forKey:@"item_3"];
-
- #else
-
-
- [dic setValue:po_dic forKey:@"item_0"];
- [dic setValue:must_call_dic forKey:@"item_1"];
- [dic setValue:general_notes_dic forKey:@"item_2"];
- #endif
- // [dic setValue:internal_notes_dic forKey:@"item_3"];
- }];
-
- #ifdef BUILD_CONTRAST
- [dic setValue:[NSNumber numberWithInteger:4] forKey:@"count"];
- #else
- [dic setValue:[NSNumber numberWithInteger:3] forKey:@"count"];
- #endif
-
- 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];
-
- // setting
- NSDictionary *setting = params[@"setting"];
- NSNumber *hide = setting[@"OrderTotalHide"];
- [dic setValue:hide forKey:@"hide"];
-
- NSString *sql = [NSString stringWithFormat:@"select lift_gate,lift_gate_value,shipping,handling_fee_value,discount from offline_order where so_id = '%@';",orderCode];
-
- __block double lift_gate_value = 0;
- __block double handling_fee = 0;
- __block double shipping = 0;
- __block double discount = 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);
- discount = sqlite3_column_double(stmt, 4);
-
- 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* (1-discount/100.0);
-
- [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"];
-
- // version 1.71 remove
- // 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;
-
- if (![[params objectForKey:@"logist"] isEqualToString:@"WILL CALL"]) {
- 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 {
-
- }
- }
-
- // version 1.71 remove
- // [dic setValue:handling_fee_dic forKey:[NSString stringWithFormat:@"item_%d",item_count++]];
- // NSString* strdiscount;
- if(discount>0)
- {
- NSDictionary *discount_dict = @{
- @"align" : @"right",
- @"aname" : @"Order Discount",
- @"control" : @"text",
- @"name" : @"orderDiscount",
- // @"type" : @"price",
- @"value" : [NSString stringWithFormat:@"%d%% off",(int)discount]
- };
- [dic setValue:discount_dict 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];
-
- // setting
- NSDictionary *setting = params[@"setting"];
- NSNumber *hide = setting[@"SignatureHide"];
- [dic setValue:hide forKey:@"hide"];
-
- [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];
-
- // setting
- NSDictionary *setting = params[@"setting"];
- NSNumber *hide = setting[@"ShippingMethodHide"];
- [dic setValue:hide forKey:@"hide"];
-
-
-
- NSString *orderCode = [self valueInParams:params key:@"orderCode"];
- orderCode = [self translateSingleQuote:orderCode];
-
- NSString *sql = [NSString stringWithFormat:@"select logist,lift_gate,logistic_note,carrier from offline_order where so_id = '%@';",orderCode];
-
-
- __block NSString *logist = @"";
- __block NSString *carrier = @"";
- __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];
- carrier = [self textAtColumn:3 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";
- }
-
- }
-
-
- // carrier = [self valueInParams:params key:@"carrier"];
- // if([carrier 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"];
- #ifdef BUILD_CONTRAST
- [params setValue:carrier forKey:@"carrier"];
- #endif
- }
-
- // NSString *Sql = [NSString stringWithFormat: @"select carrier from offline_contact where contact_id = %d;",contact_id];
- // NSString * code = [iSalesDB jk_queryText:Sql];
-
- // [self offline_getCarrierCode:offline_getCarrierCode];
-
- NSDictionary *carrierDic = [self offline_OrderCarrier:params[@"orderCode"] db:db];
-
- NSDictionary *val_1 = @{
- @"check" : [NSNumber numberWithInteger:common_carrier_check],
- @"sub_item" : @{
- @"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
- },
- #ifdef BUILD_CONTRAST
- @"count" : [NSNumber numberWithInteger:2],
- @"item_1" : @{
- @"aname" : @"Carrier",
- @"cadedate" :carrierDic,
- @"control" : @"enum",
- @"name" : @"carrier",
- @"required" : @"false",
- @"value" : @"",
- @"single_select" : @"true"
- }
- #else
- @"count" : [NSNumber numberWithInteger:1]
- #endif
-
- },
- @"value" : @"COMMON CARRIER",
- @"value_id" : @"COMMON CARRIER"
- };
-
- // cadedate
- NSDictionary *cadedate = @{
- @"count" : [NSNumber numberWithInteger:2],
- @"val_0" : val_0,
- @"val_1" : val_1
- };
-
-
- // item_0
- NSMutableDictionary *item_0 = @{
- @"aname" : @"Shipping",
- @"cadedate" : cadedate,
- @"control" : @"enum",
- @"name" : @"logist",
- @"refresh" : [NSNumber numberWithInteger:1],
- @"single_select" : @"true",
- }.mutableCopy;
- NSNumber *required = setting[@"ShippingMethodRequire"];
- if ([required integerValue]) {
- [item_0 setValue:@"true" forKey:@"required"];
- }
-
- [dic setValue:item_0 forKey:@"item_0"];
-
- if ([logist isEqualToString:@"WILL CALL"]) {
- [dic removeObjectForKey:@"lift_gate"];
- }
-
- 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
- NSMutableDictionary *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"
- }.mutableCopy;
-
-
- // setting
- NSDictionary *setting = params[@"setting"];
- NSNumber *hide = setting[@"OrderTypeHide"];
- [dic setValue:hide forKey:@"hide"];
-
- 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];
- [ret removeObjectForKey:@"result"];
- // 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 numberWithLong: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];
- }];
-
- NSString *required = @"true";
- // setting
- NSDictionary *setting = params[@"setting"];
-
- NSNumber *requiredNumber = setting[@"PaymentRequire"];
- if ([requiredNumber integerValue]) {
- required = @"true";
- } else {
- required = @"false";
- }
-
- __block NSMutableDictionary *cadedate = [NSMutableDictionary dictionary];
- // create table if not exists payment_type (_id integer primary key,type_id text,pay_type text,sort int);
- NSString *pay_type_sql = @"select type_id,pay_type,sort_id from payment_type order by sort_id asc";
- [iSalesDB jk_query:pay_type_sql db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- NSString *type_id = [self textAtColumn:0 statement:stmt];
- NSString *type = [self textAtColumn:1 statement:stmt];
-
- NSMutableDictionary *val = @{
- @"check" : [payType isEqualToString:type_id] ? @(1) : @(0),
- @"value" : type,
- @"value_id" : type_id
- }.mutableCopy;
-
- if ([type_id.lowercaseString isEqualToString:@"Visa/Master".lowercaseString] || [type_id.lowercaseString isEqualToString:@"Credit Card".lowercaseString]) {
- NSDictionary *sub_item =nil;
- #ifdef BUILD_CONTRAST
- sub_item = @{
- @"count" : @(3),
- @"item_0" : @{
- @"aname" : @"Number",
- @"control" : @"edit",
- @"keyboard" : @"int",
- @"length" : @"16",
- @"name" : @"credit_card_number",
- @"required" : @"false",
- @"value" : cardNumber
- },
- @"item_1" : @{
- @"aname" : @"Expiration Date",
- @"control" : @"monthpicker",
- @"name" : @"credit_card_expiration",
- @"required" : @"false",
- @"type" : @"date",
- @"value" : [month isEqualToString:@""] || [year isEqualToString:@""] ? @"" : [NSString stringWithFormat:@"%@/%@",month,year]
- },
- @"item_2" : @{
- @"aname" : @"Security Code",
- @"control" : @"edit",
- @"keyboard" : @"int",
- @"length" : @"4",
- @"name" : @"credit_card_security_code",
- @"required" : @"false",
- @"value" : securityCode
- },
-
- };
- #else
-
- 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" : @"VISA"/*@(0)*/
- },
- @"val_1" : @{
- @"check" : [cardType isEqualToString:@"MASTER CARD"] ? @(1) : @(0),
- @"value" : @"MASTER CARD",
- @"value_id" : @"MASTER CARD"/*@(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"
- }
- };
- #endif;
- [val setObject:sub_item forKey:@"sub_item"];
- }
-
- [cadedate setObject:val forKey:[NSString stringWithFormat:@"val_%ld",(*count)]];
- [cadedate setObject:[NSNumber numberWithInteger:(++*count)] forKey:@"count"];
- }];
-
- // "section_2"
- NSMutableDictionary *dic = @{
- @"count" : @(1),
- @"item_0" : @{
- @"aname" : @"Payment",
- @"required" : required,
- @"cadedate" : cadedate,
- // @{
- // @"count" : @(6),
- // @"val_3" : @{
- // @"check" : [payType isEqualToString:@"Check"] ? @(1) : @(0),
- // @"value" : @"Check",
- // @"value_id" : @"Check"
- // },
- // @"val_2" : @{
- // @"check" : [payType isEqualToString:@"Cash"] ? @(1) : @(0),
- // @"value" : @"Cash",
- // @"value_id" : @"Cash"
- // },
- // @"val_1" : @{
- // @"check" : [payType isEqualToString:@"NET 30"] ? @(1) : @(0),
- // @"value" : @"NET 60",
- // @"value_id" : @"NET 30"
- // },
- // @"val_4" : @{
- // @"check" : [payType isEqualToString:@"Wire Transfer"] ? @(1) : @(0),
- // @"value" : @"Wire Transfer",
- // @"value_id" : @"Wire Transfer"
- // },
- // @"val_0" : @{
- // @"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" : @"Visa/Master",
- // @"value_id" : @"Credit Card"
- // },
- // @"val_5" : @{
- // @"check" : [payType isEqualToString:@"FOLLOW EXISTING"] ? @(1) : @(0),
- // @"value" : @"FOLLOW EXISTING PAYMENT TYPE",
- // @"value_id" : @"FOLLOW EXISTING"
- // }
- // },
- @"control" : @"enum",
- @"name" : @"paymentType",
- @"single_select" : @"true"
- },
- @"title" : @"Payment Information"
- }.mutableCopy;
-
-
- NSNumber *hide = setting[@"PaymentInformationHide"];
- [dic setValue:hide forKey:@"hide"];
-
-
-
- return dic;
- }
- + (BOOL)orderOutOfStock:(NSDictionary *)params db:(sqlite3 *)db{
-
- // params
- NSString *orderCode = [self valueInParams:params key:@"orderCode"];
- orderCode = [self translateSingleQuote:orderCode];
-
- // 缺货检查
- NSString *out_of_stock_SQL = [NSString stringWithFormat:@"select p.availability,c.item_count from product as p left join offline_cart as c on p.product_id = c.product_id where c.so_no = '%@';",orderCode];
-
- __block BOOL outOfStock = NO;
- sqlite3 *database = db;
- if (!db) {
- database = [iSalesDB get_db];
- }
- [iSalesDB jk_query:out_of_stock_SQL db:database close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- int availability = sqlite3_column_int(stmt, 0);
- int item_qty = sqlite3_column_int(stmt, 1);
-
- outOfStock = outOfStock || (availability < item_qty ? YES : NO);
-
- }];
-
- if (!db) {
- [iSalesDB close_db:database];
- }
-
- return outOfStock;
- }
- +(NSData*) offline_placeorder :(NSMutableDictionary *) params
- {
- assert(params[@"user"]!=nil);
- assert(params[@"contact_id"]!=nil);
- assert(params[@"can_create_backorder"]!=nil);
-
- sqlite3 *db = [iSalesDB get_db];
- // params
- NSString *orderCode = [self valueInParams:params key:@"orderCode"];
- orderCode = [self translateSingleQuote:orderCode];
-
- // 缺货检查
- // AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- if (![params[@"can_create_backorder"] boolValue]) {
- BOOL out_of_stock = [self orderOutOfStock:params db:db];
- if (out_of_stock) {
- [iSalesDB close_db:db];
-
- NSMutableDictionary *resultDic = [NSMutableDictionary dictionary];
-
- [resultDic setObject:[NSString stringWithFormat:@"some item(s) are out of stock,please remove them from cart before placing order with %@ or try again after sync",COMPANY_SHORT_NAME] forKey:@"err_msg"];
- [resultDic setObject:[NSNumber numberWithInt:8] forKey:@"result"];
-
- return [RAConvertor dict2data:resultDic];
- }
-
- }
- // UISetting
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
- NSString *cachefolder = [paths objectAtIndex:0];
- NSString *img_cache = [cachefolder stringByAppendingPathComponent:@"offline_data/UISetting.json"];
-
-
- NSData* json =nil;
- json=[NSData dataWithContentsOfFile:img_cache];
- NSError *error=nil;
- NSMutableDictionary* menu = [[NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
- NSDictionary *setting = [menu objectForKey:@"placeOrder"];
-
- [params setObject:setting forKey:@"setting"];
-
- int section_count = 0;
-
-
-
- // 0 Order Type 1 Shipping Method 2 Payment Information
- __block NSMutableDictionary *ret = [self dictionaryFileName:@"placeOrderTemplate.json"];
-
- // 0 Order Type
- NSString *key0 = [NSString stringWithFormat:@"section_%d",section_count++];
- NSDictionary *order_type_dic = [self submitAsDic:params db:db];
- [ret setValue:order_type_dic forKey:key0];
-
- // 1 Shipping Method
- NSString *key1 = [NSString stringWithFormat:@"section_%d",section_count++];
- NSMutableDictionary *shipping_method_dic = [[self shippingMethodDic:params db:db] mutableCopy];
- [ret setValue:shipping_method_dic forKey:key1];
-
-
- // 2 Payment Information
- NSString *key2 = [NSString stringWithFormat:@"section_%d",section_count++];
- NSDictionary *payment_info_dic = [self paymentInfoDic:params db:db];
- [ret setValue:payment_info_dic forKey:key2];
-
-
-
- // 3 Customer
- NSString *key3 = [NSString stringWithFormat:@"section_%d",section_count++];
- NSDictionary *customer_dic = [self customerDic:params db:db];
- [ret setValue:customer_dic forKey:key3];
-
- // 4 Ship To
- NSString *key4 = [NSString stringWithFormat:@"section_%d",section_count++];
- NSDictionary *ship_to_dic = [self shipToDic:params db:db];
- [ret setValue:ship_to_dic forKey:key4];
-
- // 5 Ship From
- NSNumber *shipFromDisable = setting[@"ShipFromDisabled"];
- if (![shipFromDisable integerValue]) {
- NSString *key5 = [NSString stringWithFormat:@"section_%d",section_count++];
- NSDictionary *ship_from_dic = [self shipFromDic:params db:db];
- [ret setValue:ship_from_dic forKey:key5];
- }
-
- // 6 Freight Bill To
- NSNumber *freightBillToDisable = setting[@"FreightBillToDisabled"];
- if (![freightBillToDisable integerValue]) {
- NSString *key6 = [NSString stringWithFormat:@"section_%d",section_count++];
- NSDictionary *freight_bill_to = [self freightBillToDic:params db:db];
- [ret setValue:freight_bill_to forKey:key6];
- }
-
- // 7 Merchandise Bill To
- NSNumber *merchandiseBillToDisable = setting[@"MerchandiseBillToDisabled"];
- if (![merchandiseBillToDisable integerValue]) {
- NSString *key7 = [NSString stringWithFormat:@"section_%d",section_count++];
- NSDictionary *merchandise_bill_to_dic = [self merchandiseBillToDic:params db:db];
- [ret setValue:merchandise_bill_to_dic forKey:key7];
- }
-
-
- // 8 Return To
- NSNumber *returnToDisable = setting[@"ReturnToDisabled"];
- if (![returnToDisable integerValue]) {
- NSString *key8 = [NSString stringWithFormat:@"section_%d",section_count++];
- NSDictionary *return_to_dic = [self returnToDic:params db:db];
- [ret setValue:return_to_dic forKey:key8];
- }
-
- // 9 Model Information
- NSString *key9 = [NSString stringWithFormat:@"section_%d",section_count++];
- 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:key9];
-
- // 10 Remarks Content
- NSString *key10 = [NSString stringWithFormat:@"section_%d",section_count++];
- NSDictionary *remarks_content_dic = [self remarksContentDic:params db:db];
-
- [ret setValue:remarks_content_dic forKey:key10];
-
- // 11 Order Total
- NSString *key11 = [NSString stringWithFormat:@"section_%d",section_count++];
- NSDictionary *order_total_dic = [self orderTotalDic:params otherTotal:toOrderTotal db:db];
-
- [ret setValue:order_total_dic forKey:key11];
-
- // 12 Signature
- NSString *key12 = [NSString stringWithFormat:@"section_%d",section_count++];
- NSDictionary *sign_dic = [self signatureDic:params db:db];
-
- [ret setValue:sign_dic forKey:key12];
-
- [ret setValue:@(section_count) forKey:@"section_count"];
-
- [iSalesDB close_db:db];
-
- return [RAConvertor 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;
- // }
-
- NSString *country_code = nil;
- NSString *zipCode = nil;
- NSString *stateCode = nil;
- NSString *city = nil;
-
- if ([params.allKeys containsObject:@"refresh_trigger"]) {
-
- if([params[@"refresh_trigger"] isEqualToString:@"country"]) { // choose country
-
- NSString *code_id = params[@"country"];
- country_code = [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) {
-
- NSDictionary *dic = [self offline_dealZipCode:zip_code];
-
- country_code = [dic valueForKey:@"country_code"];
- if (!country_code) {
- // country_code = @"US";
- NSString *code_id = params[@"country"];
- country_code = [self countryCodeByid:code_id];
- }
-
- stateCode = [dic valueForKey:@"state_code"];
- if(!stateCode.length) {
- stateCode = params[@"state"];
- }
-
- city = [dic valueForKey:@"city"];
- if (!city.length) {
- city = params[@"city"];
- }
-
- // zip code
- // NSMutableDictionary *zipDic = [[section_0 valueForKey:@"item_11"] mutableCopy];
- // [zipDic setValue:zipCode forKey:@"value"];
- // [section_0 setValue:zipDic forKey:@"item_11"];
- } else {
-
- NSString *code_id = params[@"country"];
- country_code = [self countryCodeByid:code_id];
- stateCode = params[@"state"];
- city = params[@"city"];
- }
- }
-
- }
-
-
- 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_6"] 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_7"] add:YES] forKey:@"item_2"]; // Address 1*
- [new_section_0 setObject:section_0[@"item_8"] forKey:@"item_3"]; // Address 2
- [new_section_0 setObject:section_0[@"item_9"] forKey:@"item_4"]; // Address 3
- [new_section_0 setObject:section_0[@"item_10"] forKey:@"item_5"]; // Address 4
-
- NSMutableDictionary *zip_code_dic = [self anameDealWithStarAtItem:section_0[@"item_11"] add:YES];
- // [zip_code_dic removeObjectForKey:@"refresh"];
- [zip_code_dic setValue:zipCode ? zipCode :@"" forKey:@"value"];
- [new_section_0 setObject:zip_code_dic forKey:@"item_6"]; // Zip Code*
-
- [new_section_0 setObject:[self anameDealWithStarAtItem:section_0[@"item_12"] add:YES] forKey:@"item_7"]; // State/Province*
-
- [new_section_0 setObject:[self anameDealWithStarAtItem:section_0[@"item_13"] add:YES] forKey:@"item_8"]; // City*
- NSDictionary *cityDic = [[new_section_0 objectForKey:@"item_8"] mutableCopy];
- [cityDic setValue:city ? city : @"" forKey:@"value"];
- [new_section_0 setObject:cityDic forKey:@"item_8"];
-
- [new_section_0 setObject:section_0[@"item_14"] forKey:@"item_9"]; // Contact First Name
- [new_section_0 setObject:section_0[@"item_15"] forKey:@"item_10"]; // Contact Last Name
- [new_section_0 setObject:section_0[@"item_5"] forKey:@"item_11"]; // Phone*
- [new_section_0 setObject:section_0[@"item_16"] forKey:@"item_12"]; // Fax
- [new_section_0 setObject:[self anameDealWithStarAtItem:section_0[@"item_4"] add:NO] forKey:@"item_13"]; // Email
- [new_section_0 setObject:section_0[@"title"] forKey:@"title"];
-
-
- // country
- NSString *countryCode = country_code == nil ? @"US" : country_code;
- 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:stateCode] 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 [RAConvertor 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 *order_id = [self valueInParams:params key:@"orderId"];
- NSString *sql = [NSString stringWithFormat:@"update offline_order set status = 2,erpOrderStatus = 15 where so_id = '%@';",orderCode];
- if (order_id.length) {
- sql = [NSString stringWithFormat:@"update offline_order set status = 2,erpOrderStatus = 15 where _id = %@;",order_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 [RAConvertor dict2data:dic];
-
- }
- #pragma mark sign order
- +(NSData*) offline_signorder :(NSMutableDictionary *) params
- {
- //参考 offline_saveBusinesscard
- DebugLog(@"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 [RAConvertor 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 *)saveorder:(NSMutableDictionary *)param submit:(BOOL)submit {
- 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* schedule_date = [self valueInParams:param key:@"schedule_date_str"];
- if (schedule_date.length==0 ) {
- schedule_date = @"";
- } else {
- schedule_date = [self rchangeDateFormate:schedule_date];
- schedule_date = [NSString stringWithFormat:@"schedule_date = '%@',",schedule_date];
- }
-
- 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]; // submit as
-
-
-
- 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];
- if (receive_cid.length) {
- receive_cid = [NSString stringWithFormat:@"receive_cid = '%@',",receive_cid];
- }
-
- NSString *receive_name = [self valueInParams:param key:@"receive_name" translateSingleQuote:YES];
- if (receive_name.length) {
- receive_name = [NSString stringWithFormat:@"receive_name = '%@',",receive_name];
- }
-
-
- NSString *receive_ext = [self valueInParams:param key:@"receive_ext" translateSingleQuote:YES];
- if (receive_ext.length) {
- receive_ext = [NSString stringWithFormat:@"receive_ext = '%@',",receive_ext];
- }
-
-
- NSString *receive_contact = [self valueInParams:param key:@"receive_contact" translateSingleQuote:YES];
- if (receive_contact.length) {
- receive_contact = [NSString stringWithFormat:@"receive_contact = '%@',",receive_contact];
- }
-
-
- NSString *receive_phone = [self valueInParams:param key:@"receive_phone" translateSingleQuote:YES];
- if (receive_phone.length) {
- receive_phone = [NSString stringWithFormat:@"receive_phone = '%@',",receive_phone];
- }
-
-
- NSString *receive_email = [self valueInParams:param key:@"receive_email" translateSingleQuote:YES];
- if (receive_email.length) {
- receive_email = [NSString stringWithFormat:@"receive_email = '%@',",receive_email];
-
- }
-
-
- NSString *receive_fax = [self valueInParams:param key:@"receive_fax" translateSingleQuote:YES];
- if (receive_fax.length) {
- receive_fax = [NSString stringWithFormat:@"receive_fax = '%@',",receive_fax];
- }
-
-
-
-
- NSString *sender_cid = [self valueInParams:param key:@"sender_cid" translateSingleQuote:YES];
- if (sender_cid.length) {
- sender_cid = [NSString stringWithFormat:@"sender_cid = '%@',",sender_cid];
- }
-
- NSString *sender_name = [self valueInParams:param key:@"sender_name" translateSingleQuote:YES];
- if (sender_name.length) {
- sender_name = [NSString stringWithFormat:@"sender_name = '%@',",sender_name];
- }
-
- NSString *sender_ext = [self valueInParams:param key:@"sender_ext" translateSingleQuote:YES];
- if (sender_ext.length) {
- sender_ext = [NSString stringWithFormat:@"sender_ext = '%@',",sender_ext];
- }
-
- NSString *sender_contact = [self valueInParams:param key:@"sender_contact" translateSingleQuote:YES];
- if(sender_contact.length) {
- sender_contact = [NSString stringWithFormat:@"sender_contact = '%@',",sender_contact];
- }
-
- NSString *sender_phone = [self valueInParams:param key:@"sender_phone" translateSingleQuote:YES];
- if (sender_phone.length) {
- sender_phone = [NSString stringWithFormat:@"sender_phone = '%@',",sender_phone];
- }
-
-
- NSString *sender_fax = [self valueInParams:param key:@"sender_fax" translateSingleQuote:YES];
- if (sender_fax.length) {
- sender_fax = [NSString stringWithFormat:@"sender_fax = '%@',",sender_fax];
- }
-
- NSString *sender_email = [self valueInParams:param key:@"sender_email" translateSingleQuote:YES];
- if (sender_email.length) {
- sender_email = [NSString stringWithFormat:@"sender_email = '%@',",sender_email];
- }
-
- NSString *shipping_billto_cid = [self valueInParams:param key:@"shipping_billto_cid" translateSingleQuote:YES];
- if (shipping_billto_cid.length) {
- shipping_billto_cid = [NSString stringWithFormat:@"shipping_billto_cid = '%@',",shipping_billto_cid];
- }
-
-
- NSString *shipping_billto_name = [self valueInParams:param key:@"shipping_billto_name" translateSingleQuote:YES];
- if (shipping_billto_name.length) {
- shipping_billto_name = [NSString stringWithFormat:@"shipping_billto_name = '%@',",shipping_billto_name];
- }
-
-
- NSString *shipping_billto_ext = [self valueInParams:param key:@"shipping_billto_ext" translateSingleQuote:YES];
- if (shipping_billto_ext.length) {
- shipping_billto_ext = [NSString stringWithFormat:@"shipping_billto_ext = '%@',",shipping_billto_ext];
- }
-
- NSString *shipping_billto_contact = [self valueInParams:param key:@"shipping_billto_contact" translateSingleQuote:YES];
- if (shipping_billto_contact.length) {
- shipping_billto_contact = [NSString stringWithFormat:@"shipping_billto_contact = '%@',",shipping_billto_contact];
- }
-
- NSString *shipping_billto_phone = [self valueInParams:param key:@"shipping_billto_phone" translateSingleQuote:YES];
- if (shipping_billto_phone.length) {
- shipping_billto_phone = [NSString stringWithFormat:@"shipping_billto_phone = '%@',",shipping_billto_phone];
- }
-
- NSString *shipping_billto_fax = [self valueInParams:param key:@"shipping_billto_fax" translateSingleQuote:YES];
- if (shipping_billto_fax.length) {
- shipping_billto_fax = [NSString stringWithFormat:@"shipping_billto_fax = '%@',",shipping_billto_fax];
- }
-
- NSString *shipping_billto_email = [self valueInParams:param key:@"shipping_billto_email" translateSingleQuote:YES];
- if (shipping_billto_email.length) {
- shipping_billto_email = [NSString stringWithFormat:@"shipping_billto_email = '%@',",shipping_billto_email];
- }
-
-
- NSString *billing_cid = [self valueInParams:param key:@"billing_cid" translateSingleQuote:YES];
- if (billing_cid.length) {
- billing_cid = [NSString stringWithFormat:@"billing_cid = '%@',",billing_cid];
- }
-
- NSString *billing_name = [self valueInParams:param key:@"billing_name" translateSingleQuote:YES];
- if (billing_name.length) {
- billing_name = [NSString stringWithFormat:@"billing_name = '%@',",billing_name];
- }
-
- NSString *billing_ext = [self valueInParams:param key:@"billing_ext" translateSingleQuote:YES];
- if (billing_ext.length) {
- billing_ext = [NSString stringWithFormat:@"billing_ext = '%@',",billing_ext];
- }
-
- NSString *billing_contact = [self valueInParams:param key:@"billing_contact" translateSingleQuote:YES];
- if (billing_contact.length) {
- billing_contact = [NSString stringWithFormat:@"billing_contact = '%@',",billing_contact];
- }
-
- NSString *billing_phone = [self valueInParams:param key:@"billing_phone" translateSingleQuote:YES];
- if (billing_phone.length) {
- billing_phone = [NSString stringWithFormat:@"billing_phone = '%@',",billing_phone];
- }
-
- NSString *billing_fax = [self valueInParams:param key:@"billing_fax" translateSingleQuote:YES];
- if (billing_fax.length) {
- billing_fax = [NSString stringWithFormat:@"billing_fax = '%@',",billing_fax];
- }
-
- NSString *billing_email = [self valueInParams:param key:@"billing_email" translateSingleQuote:YES];
- if (billing_email.length) {
- billing_email = [NSString stringWithFormat:@"billing_email = '%@',",billing_email];
- }
-
-
- NSString *returnto_cid = [self valueInParams:param key:@"returnto_cid" translateSingleQuote:YES];
- if (returnto_cid.length) {
- returnto_cid = [NSString stringWithFormat:@"returnto_cid = '%@',",returnto_cid];
- }
-
- NSString *returnto_name = [self valueInParams:param key:@"returnto_name" translateSingleQuote:YES];
- if (returnto_name.length) {
- returnto_name = [NSString stringWithFormat:@"returnto_name = '%@',",returnto_name];
- }
-
- NSString *returnto_ext = [self valueInParams:param key:@"returnto_ext" translateSingleQuote:YES];
- if (returnto_ext.length) {
- returnto_ext = [NSString stringWithFormat:@"returnto_ext = '%@',",returnto_ext];
- }
-
- NSString *returnto_contact = [self valueInParams:param key:@"returnto_contact" translateSingleQuote:YES];
- if (returnto_contact.length) {
- returnto_contact = [NSString stringWithFormat:@"returnto_contact = '%@',",returnto_contact];
- }
-
- NSString *returnto_phone = [self valueInParams:param key:@"returnto_phone" translateSingleQuote:YES];
- if (returnto_phone.length) {
- returnto_phone = [NSString stringWithFormat:@"returnto_phone = '%@',",returnto_phone];
- }
-
- NSString *returnto_fax = [self valueInParams:param key:@"returnto_fax" translateSingleQuote:YES];
- if (returnto_fax.length) {
- returnto_fax = [NSString stringWithFormat:@"returnto_fax = '%@',",returnto_fax];
- }
-
- NSString *returnto_email = [self valueInParams:param key:@"returnto_email" translateSingleQuote:YES];
- if (returnto_email.length) {
- returnto_email = [NSString stringWithFormat:@"returnto_email = '%@',",returnto_email];
- }
-
- NSString *order_status = @"status = 1,";
- if (submit) {
- order_status = @"status = -11,";
- }
-
- // NSString *sync_data = [AESCrypt fastencrypt:[RAUtils dict2string:param]];
- NSString* carrier = [self offline_getCarrier:[param[@"carrier"] intValue]];
-
- NSString* scarrier = [NSString stringWithFormat:@"carrier = '%@',",carrier];
-
- NSString *sync_sql = @"";
- if (submit) {
- param[@"truck_carrier"]=carrier;
- NSString *sales_rep = [iSalesDB jk_queryText:[NSString stringWithFormat:@"select sales_rep from offline_order where so_id = '%@';",so_id]];
- [param setValue:sales_rep forKey:@"sales_rep"];
- NSString *sync_data = [self translateSingleQuote:[RAConvertor dict2string:param]];
- sync_sql = [NSString stringWithFormat:@",sync_data = '%@' ",sync_data];
- }
-
- NSString *orderSql = [NSString stringWithFormat:@"update offline_order set %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ %@ so_id = '%@' %@ where so_id = '%@';",schedule_date, 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,scarrier,so_id,sync_sql,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"];
- [dic setObject:so_id forKey:@"so#"];
- return [RAConvertor dict2data:dic];
-
- }
- +(NSData*) offline_saveorder :(NSMutableDictionary *) param
- {
-
- // id foo = nil;
- // NSMutableArray *a = @[].mutableCopy;
- // [a addObject:foo];
-
- return [self saveorder:param submit:NO];
- }
- #pragma mark add to cart by name
- +(NSData*) offline_add2cartbymodelQR :(NSMutableDictionary *) params
- {
-
- NSString *orderCode = [params objectForKey:@"orderCode"];
-
- NSDictionary *newParams = @{
- @"product_id" : params[@"product_id_string"],
- @"orderCode" : orderCode,
- @"can_create_backorder":params[@"can_create_backorder"]
- };
-
-
-
-
-
- return [self offline_add2cart:[newParams mutableCopy]];
- }
- +(NSData*) offline_add2cartbyupc :(NSMutableDictionary *) params
- {
-
- NSString *orderCode = [params objectForKey:@"orderCode"];
- NSString *upccode = [params objectForKey:@"upc_code"];
- // product_name = [self translateSingleQuote:product_name];
- // NSArray *product_name_array = [product_name componentsSeparatedByString:@","];
- // bool search_upc = [params[@"search_upc"] boolValue];
- sqlite3 *db = [iSalesDB get_db];
- __block NSMutableString *product_id_string = [NSMutableString string];
- // NSString *name = [product_name_array objectAtIndex:i];
- NSString *sql =nil;
- sql= [NSString stringWithFormat:@"select product_id from product where upc_code = '%@' or upc_code like '%@;%%' or upc_code like '%%;%@;%%' or upc_code like '%%;%@';",upccode,upccode,upccode,upccode];
- [iSalesDB jk_query:sql db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- int product_id = sqlite3_column_int(stmt, 0);
- [product_id_string appendFormat:@"%d",product_id];
- }];
-
-
- if (!orderCode) {
- orderCode = @"";
- }
- NSDictionary *newParams = @{
- @"product_id" : product_id_string,
- @"orderCode" : orderCode,
- @"can_create_backorder":params[@"can_create_backorder"]
- };
-
- [iSalesDB close_db:db];
-
-
-
- return [self offline_add2cart:[newParams mutableCopy]];
- }
- +(NSData*) offline_add2cartbyname :(NSMutableDictionary *) params
- {
-
- 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:@","];
- bool search_upc = [params[@"search_upc"] boolValue];
- 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 =nil;
- if(search_upc)
- sql= [NSString stringWithFormat:@"select product_id from product where upc_code = '%@' or upc_code like '%@;%%' or upc_code like '%%;%@;%%' or upc_code like '%%;%@';",name,name,name,name];
- else
- 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];
- }
-
- }];
- }
- if (!orderCode) {
- orderCode = @"";
- }
- NSDictionary *newParams = @{
- @"product_id" : product_id_string,
- @"orderCode" : orderCode,
- @"can_create_backorder":params[@"can_create_backorder"]
- };
-
- [iSalesDB close_db:db];
-
-
-
- return [self offline_add2cart:[newParams mutableCopy]];
- }
- #pragma mark reset order
- +(NSData*) offline_resetorder :(NSMutableDictionary *) params
- {
-
- // UIApplication * app = [UIApplication sharedApplication];
- // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
-
- [iSalesDB disable_trigger];
- [iSalesDB execSql:@"delete from offline_cart where so_no in (select so_id from offline_order where status = 0);"];
- [iSalesDB execSql:@"delete from offline_order where status=0;"];
- [iSalesDB enable_trigger];
-
- NSMutableDictionary *dic = [NSMutableDictionary dictionary];
- [dic setValue:[NSNumber numberWithInteger:2] forKey:@"result"];
- return [RAConvertor dict2data:dic];
- }
- #pragma mark submit order
- +(NSData*) offline_submitorder :(NSMutableDictionary *) params;
- {
- return [self saveorder:params submit:YES];
- }
- #pragma mark copy order
- +(NSData*) offline_copyorder :(NSMutableDictionary *) params;
- {
- NSMutableDictionary *ret = @{}.mutableCopy;
-
- NSString *order_code = [self valueInParams:params key:@"code" translateSingleQuote:YES];
-
- sqlite3 *db = [iSalesDB get_db];
- [iSalesDB execSql:@"BEGIN TRANSACTION" db:db];
-
- // 首先查看联系人是否active
- NSString *customer_sql = [NSString stringWithFormat:@"select is_active from offline_contact where contact_id in (select customer_cid from offline_order where so_id = '%@');",order_code];
- __block int customer_is_active = 1;
- [iSalesDB jk_query:customer_sql db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- customer_is_active = sqlite3_column_int(stmt, 0);
-
- }];
- if (!customer_is_active) {
- [ret setObject:[NSNumber numberWithInteger:RESULT_FALSE] forKey:@"result"];
- [iSalesDB execSql:@"END TRANSACTION" db:db];
- [iSalesDB close_db:db];
- return [RAConvertor dict2data:ret];
- }
-
- // new order
- // NSString *new_order_code = [NSString stringWithFormat:@"OFFLINE%@",[NSUUID UUID].UUIDString];
- NSString *new_order_code = [self get_offline_soid:db];
-
- NSString *user =params[@"user"];// ((AppDelegate *)[UIApplication sharedApplication].delegate).user;
- user = [self translateSingleQuote:user];
-
- NSString *insert_order_sql = [NSString stringWithFormat:@"insert into offline_order (so_id,status,submit_as,internal_notes,sales_rep,create_by,logist,lift_gate,logistic_note,customer_cid,customer_contact,customer_email,customer_phone,customer_fax,receive_cid,receive_name,receive_ext,receive_contact,receive_phone,receive_fax,receive_email,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,must_call,poNumber,comments,comments_ext,sales_terms) select '%@',1,submit_as,internal_notes,sales_rep,'%@',logist,lift_gate,logistic_note,customer_cid,customer_contact,customer_email,customer_phone,customer_fax,receive_cid,receive_name,receive_ext,receive_contact,receive_phone,receive_fax,receive_email,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,must_call,poNumber,comments,comments_ext,sales_terms from offline_order where so_id = '%@';",new_order_code,user,order_code]; // ,paymentsAndCredits,shipping,lift_gate_value,handling_fee_value
-
- __block int result = 1;
- result = [iSalesDB execSql:insert_order_sql db:db];
-
- if (!result) {
- [ret setObject:[NSNumber numberWithInteger:RESULT_FALSE] forKey:@"result"];
- [iSalesDB execSql:@"END TRANSACTION" db:db];
- [iSalesDB close_db:db];
- return [RAConvertor dict2data:ret];
- }
-
-
- // 查询product_id 及其对应的 is_active,若is_active = 0,那么就忽略之
- // __block NSString *product_id = @"";
-
- __weak typeof(self) weakSelf = self;
- NSString *product_id_sql = [NSString stringWithFormat:@"select product_id,is_active from product WHERE product_id in (select product_id from offline_cart where so_no = '%@');",order_code];
- [iSalesDB jk_query:product_id_sql db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- int is_active = sqlite3_column_int(stmt, 1);
- if (is_active) {
- // product_id = [product_id stringByAppendingString:[NSString stringWithFormat:@",%@",[weakSelf textAtColumn:0 statement:stmt]]];
- NSString *product_id = [weakSelf textAtColumn:0 statement:stmt];
- NSString *insert_cart_sql = [NSString stringWithFormat:@"insert into offline_cart (so_no,orderitem_id,product_id,item_id,item_count,bundle_item,type) select '%@',orderitem_id,product_id,item_id,item_count,bundle_item,type from offline_cart where product_id = %@ and so_no = '%@'",new_order_code,product_id,order_code];
- result = result && [iSalesDB execSql:insert_cart_sql db:db];
- }
-
- }];
- // product_id = [product_id substringFromIndex:1];
- //
- // [self offline_add2cart:@{}.mutableCopy];
-
- [iSalesDB execSql:@"END TRANSACTION" db:db];
- [iSalesDB close_db:db];
- if (result) {
- [ret setObject:[NSNumber numberWithInteger:RESULT_TRUE] forKey:@"result"];
- } else {
- [ret setObject:[NSNumber numberWithInteger:RESULT_FALSE] forKey:@"result"];
- }
- [ret setObject:new_order_code forKey:@"so_id"];
-
- return [RAConvertor dict2data:ret];
- }
- #pragma mark move wish list to cart
- + (NSData*)offline_movewish2cart:(NSMutableDictionary *)params {
-
- assert(params[@"can_create_backorder"]!=nil);
- // cart中存在的Model在wish list move to cart之后,cart中Model数量为1
- // AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- NSString *collectId = params[@"collectId"];
- NSString *sql = [NSString stringWithFormat:@"select w.product_id,w.qty,p.availability,w._id from wishlist as w left join product as p on w.product_id = p.product_id where w._id in (%@);",collectId];
-
- __block NSString *product_id = @"";
- __block NSString *qty = @"";
- __block int number_of_outOfStock = 0;
- __block NSMutableArray *delete_collectId = [NSMutableArray array];
- [iSalesDB jk_query:sql completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- int productId = sqlite3_column_int(stmt, 0);
-
- int item_qty = sqlite3_column_int(stmt, 1);
-
- int availability = sqlite3_column_int(stmt, 2);
-
- int _id = sqlite3_column_int(stmt, 3);
-
- if (![params[@"can_create_backorder"] boolValue]) {
- // 库存小于购买量为缺货
- if (availability >= item_qty) {
- product_id = [product_id stringByAppendingString:[NSString stringWithFormat:@",%d",productId]];
-
- qty = [qty stringByAppendingString:[NSString stringWithFormat:@",%d",item_qty]];
-
- [delete_collectId addObject:[NSString stringWithFormat:@"%d",_id]];
-
- } else {
- number_of_outOfStock++;
- }
- } else {
-
- product_id = [product_id stringByAppendingString:[NSString stringWithFormat:@",%d",productId]];
-
- qty = [qty stringByAppendingString:[NSString stringWithFormat:@",%d",item_qty]];
-
- [delete_collectId addObject:[NSString stringWithFormat:@"%d",_id]];
- }
-
- }];
-
- NSMutableDictionary *retDic = nil;
- if (![params[@"can_create_backorder"] boolValue]) {
- if (delete_collectId.count == 0) {
- retDic = [NSMutableDictionary dictionary];
- retDic[@"result"] = [NSNumber numberWithInteger:8];
- retDic[@"err_msg"] = [NSString stringWithFormat:@"%d item is out of stock",number_of_outOfStock];
- return [RAConvertor dict2data:retDic];
- }
-
- }
- if (product_id.length > 1) {
- product_id = [product_id substringFromIndex:1];
- }
- if (qty.length > 1) {
- qty = [qty substringFromIndex:1];
- }
-
- NSString *orderCode = params[@"orderCode"];
- if (!orderCode) {
- orderCode = @"";
- }
- NSDictionary *newParams = @{
- @"product_id" : product_id,
- @"orderCode" : orderCode,
- @"qty" : qty,
- @"can_create_backorder":params[@"can_create_backorder"]
- };
-
- NSData *data = [self offline_add2cart:newParams.mutableCopy];
- retDic = [[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil] mutableCopy];
-
- if ([retDic[@"result"] integerValue] == RESULT_TRUE) {
-
- NSMutableDictionary* wish_return = [[self offline_deletewishlist:@{@"collectId" : [delete_collectId componentsJoinedByString:@","]}.mutableCopy] mutableCopy];
- NSInteger ret = [wish_return[@"result"] intValue];
- retDic[@"wish_count"]=wish_return[@"wish_count"];
- retDic[@"result"] = [NSNumber numberWithInteger:ret];
-
- }
-
- if (![params[@"can_create_backorder"] boolValue]) {
- if (number_of_outOfStock > 0) {
- retDic[@"result"] = [NSNumber numberWithInteger:8];
- retDic[@"err_msg"] = [NSString stringWithFormat:@"%d item is out of stock",number_of_outOfStock];
- }
- }
-
-
- return [RAConvertor dict2data:retDic];
-
- }
- #pragma mark - portfolio
- + (NSData *)offline_portfolioList:(NSMutableDictionary *)params {
-
- // assert(params[@"contact_id"]!=nil);
- assert(params[@"user"]!=nil);
- assert(params[@"can_see_price"]!=nil);
-
- int sort = [[params valueForKey:@"sort"] intValue];
- int offset = [[params valueForKey:@"offset"] intValue];
- int limit = [[params valueForKey:@"limit"] intValue];
-
- NSString *orderBy = @"";
- switch (sort) {
- case 0:{
- orderBy = @"p.modify_time desc";
- }
- break;
- case 1:{
- orderBy = @"modify_time asc";
- }
- break;
- case 2:{
- orderBy = @"p.name asc";
- }
- break;
- case 3:{
- orderBy = @"p.name desc";
- }
- break;
- case 4:{
- orderBy = @"p.description asc";
- }
- break;
- case 5: {
- orderBy = @"m.default_category asc";
- }
-
- default:
- break;
- }
-
-
- // NSString *sql = [NSString stringWithFormat:@"select p.product_id,p.name,p.description,ifnull(p.sheet_price,'null'),p.sheet_discount,ifnull(p.available_qty,'null'),p.percentage,p.item_id,p.fashion_id,i.url,p.line_note,p.percent from offline_portfolio as p left join model_image as i on i.product_id = p.product_id where i.type = 1 and (p.is_delete is null or p.is_delete = 0) group by p.product_id order by %@ limit %d offset %d;",orderBy,limit,offset];
-
- NSString *sql = [NSString stringWithFormat:@"select * from (select p.product_id,p.name,p.description,ifnull(p.sheet_price,'null'),p.sheet_discount,ifnull(p.available_qty,'null'),p.percentage,p.item_id,p.fashion_id,i.url,p.line_note,p.percent,p.modify_time from offline_portfolio as p left join model_image as i on i.product_id = p.product_id where i.type = 1 and (p.is_delete is null or p.is_delete = 0) group by p.product_id limit %d offset %d) as p left join product as m on p.product_id = m.product_id order by %@;",limit,offset,orderBy];
-
- __block NSMutableDictionary *dic = [NSMutableDictionary dictionary];
-
- // AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
-
- sqlite3 *db = [iSalesDB get_db];
- NSDictionary *resultDic = [iSalesDB jk_query:sql db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- [dic setValue:[NSNumber numberWithInteger:RESULT_TRUE] forKey:@"result"];
-
- int product_id = sqlite3_column_int(stmt, 0);
- NSString *product_id_string = [NSString stringWithFormat:@"%d",product_id];
- NSString *name = [self textAtColumn:1 statement:stmt];
- NSString *description = [self textAtColumn:2 statement:stmt];
- double price = sqlite3_column_double(stmt, 3);
- double discount = sqlite3_column_double(stmt,4);
- int qty = sqlite3_column_int(stmt, 5);
- int percentage = sqlite3_column_int(stmt, 6);
- int item_id = sqlite3_column_int(stmt, 7);
- // int fashion_id = sqlite3_column_int(stmt, 8);
- NSString *img_path = [self textAtColumn:9 statement:stmt];
- NSString *line_note = [self textAtColumn:10 statement:stmt];
- double percent = sqlite3_column_double(stmt, 11);
-
- NSString *price_null = [self textAtColumn:3 statement:stmt];
- if ([price_null isEqualToString:@"null"]) {
- price = [[self get_model_default_price:params[@"contact_id"] user:params[@"user"] product_id:nil item_id:@(item_id) db:db] doubleValue];
- }
-
-
-
- NSMutableDictionary *item = @{
- @"linenotes": line_note,
- @"check": @(1),
- @"product_id": product_id_string,
- @"available_qty": @(qty),
- @"available_percent" : @(percent),
- @"description": [NSString stringWithFormat:@"%@\n%@",name,description],
- @"item_id": [NSString stringWithFormat:@"%d",item_id],
- @"fashion_id": [NSString stringWithFormat:@"%d",product_id],
- @"img": img_path,
- @"tear_sheet_discount": [NSString stringWithFormat:@"%f",discount],
- @"tear_sheet_price": [NSString stringWithFormat:@"%f",price]
- }.mutableCopy;
- if (percentage) {
- [item removeObjectForKey:@"available_qty"];
- } else {
- [item removeObjectForKey:@"available_percent"];
- }
-
- NSString *qty_null = [self textAtColumn:5 statement:stmt];
- if ([qty_null isEqualToString:@"null"]) {
- [item removeObjectForKey:@"available_qty"];
- }
-
-
- [dic setObject:item forKey:[NSString stringWithFormat:@"item_%ld",*count]];
- [dic setValue:[NSNumber numberWithLong:++(*count)] forKey:@"count"];
-
- }];
-
- if ([[resultDic objectForKey:@"result"] integerValue] == RESULT_FALSE) {
- [dic setValue:[NSNumber numberWithInteger:RESULT_FALSE] forKey:@"result"];
-
- [dic setValue:[NSNumber numberWithInteger:0] forKey:@"count"];
- }
-
- [iSalesDB close_db:db];
-
-
-
- [dic setValue:[NSNumber numberWithBool:[params[@"can_see_price"] boolValue]] forKey:@"can_see_price"];
- [dic setValue:@"" forKey:@"email_content"];
- [dic setValue:[dic objectForKey:@"count"] forKey:@"total_count"];
- [dic setValue:@"Regular Mode" forKey:@"mode"];
-
- return [RAConvertor dict2data:dic];
- }
- + (int)model_QTY:(NSString *)product_id db:(sqlite3 *)db {
-
- __block int qty = 0;
- NSString *sql = [NSString stringWithFormat:@"select availability from product where product_id = %@;",product_id];
- [iSalesDB jk_query:sql db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- qty = sqlite3_column_int(stmt, 0);
- }];
-
- return qty;
- }
- + (NSData *)offline_savePDF:(NSMutableDictionary *)params direct:(BOOL)direct contact_id:(NSString* ) contact_id
- {
- NSMutableDictionary *resultDictionary = [NSMutableDictionary dictionary];
- [resultDictionary setObject:@"Regular Mode" forKey:@"mode"];
-
- // NSMutableDictionary * values = params[@"replaceValue"];
- NSNumber *tear_sheet_id = [params objectForKey:@"tearsheetsId"]; // _id
-
- NSString *tear_name = [self valueInParams:params key:@"pdfName"];
-
- NSString *tear_note = [self valueInParams:params key:@"pdfNote"];
-
-
- NSString *configureParams = [self valueInParams:params key:@"configureParams"];
-
- NSString *pdf_path = @"";
- if (direct) {
-
- configureParams = [self valueInParams:params key:@"pdfUrl"];
-
- } else {
-
- pdf_path = [self valueInParams:params key:@"pdfPath"];
-
- }
-
-
- NSString *create_user = [self valueInParams:params key:@"user"];
- NSString *product_ids = [self valueInParams:params key:@"product_ids"];
- NSString *item_ids = [self valueInParams:params key:@"item_ids"];
-
-
- // model info
- // NSString *sql = [NSString stringWithFormat:@"select product_id,ifnull(sheet_price,'null'),ifnull(sheet_discount,'null'),ifnull(available_qty,'null'),percentage,item_id,line_note,percent from offline_portfolio where product_id in (%@);",product_ids];
-
- // V1.90 more color
- NSString *sql = [NSString stringWithFormat:@"select p.product_id,ifnull(p.sheet_price,'null'),ifnull(p.sheet_discount,'null'),ifnull(p.available_qty,'null'),p.percentage,p.item_id,p.line_note,p.percent,m.more_color from offline_portfolio as p left join product as m on p.product_id = m.product_id where p.product_id in (%@);",product_ids];
-
- __block NSMutableDictionary *dic = [NSMutableDictionary dictionary];
- __block NSMutableString *product_ids_string = [NSMutableString string]; // configure参数
-
- // AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
-
- sqlite3 *db = [iSalesDB get_db];
-
- NSDictionary *resultDic = [iSalesDB jk_query:sql db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- [dic setValue:[NSNumber numberWithInteger:RESULT_TRUE] forKey:@"result"];
-
- int product_id = sqlite3_column_int(stmt, 0);
- NSString *product_id_string = [NSString stringWithFormat:@"%d",product_id];
- double price = sqlite3_column_double(stmt, 1);
- double discount = sqlite3_column_double(stmt,2);
- int qty = sqlite3_column_int(stmt, 3);
- int percentage = sqlite3_column_int(stmt, 4);
- int item_id = sqlite3_column_int(stmt, 5);
- NSString *line_note = [self textAtColumn:6 statement:stmt];
- double percent = sqlite3_column_double(stmt, 7);
- int more_color = sqlite3_column_int(stmt, 8);
-
- NSString *price_null = [self textAtColumn:1 statement:stmt];
- /* if ([price_null isEqualToString:@"null"]) {
- price = [[self get_model_default_price:appDelegate.contact_id product_id:nil item_id:@(item_id) db:db] doubleValue];
- }
- */
- [product_ids_string appendFormat:@"%@,",product_id_string];
-
- // Regular Price
- int regular_price = [[params objectForKey:@"regular_price"] intValue];
- NSString *regular_price_str = [self get_portfolio_price:contact_id item_id:item_id price:regular_price db:db];
-
- // QTY
- NSString *qty_null = [self textAtColumn:3 statement:stmt];
- if ([qty_null isEqualToString:@"null"]) {
- // 查available
- qty = [self model_QTY:product_id_string db:db];
-
- }
- if (percentage) {
- qty = qty * percent / 100;
- }
-
- // Special Price
- if ([price_null isEqualToString:@"null"]) {
- // price = regular price
- price = [regular_price_str doubleValue];
- }
- NSString *discount_null = [self textAtColumn:2 statement:stmt];
- if (![discount_null isEqualToString:@"null"]) {
- price = price * (1 - discount / 100.0);
- }
-
-
-
-
- NSMutableDictionary *item = @{
- @"line_note": line_note,
- @"product_id": product_id_string,
- @"available_qty": @(qty),
- @"more_color":@(more_color),
- @"item_id": [NSString stringWithFormat:@"%d",item_id],
- @"regular_price" : regular_price_str,
- @"special_price" : [NSString stringWithFormat:@"%.2f",price]
- }.mutableCopy;
-
-
-
- [dic setObject:item forKey:[NSString stringWithFormat:@"item_%ld",*count]];
- [dic setValue:[NSNumber numberWithLong:++(*count)] forKey:@"count"];
-
- }];
-
- [iSalesDB close_db:db];
-
- if (product_ids_string.length > 0) {
- [product_ids_string deleteCharactersInRange:NSMakeRange(product_ids_string.length - 1, 1)];
- }
-
- if ([[resultDic objectForKey:@"result"] integerValue] != RESULT_TRUE) {
-
- [resultDictionary setObject:[resultDic objectForKey:@"result"] forKey:@"result"];
-
- return [RAConvertor dict2data:resultDictionary];
- }
-
- NSString *model_info = [RAConvertor dict2string:dic];
-
-
-
- // 创建PDF
-
- // 在preview情况下保存,则不需要新建了
- if (direct) {
- NSMutableDictionary *tear_sheet_params = params;
- // if (tear_sheet_id) {
- // tear_sheet_params = values;
- // }
- NSData *pdfData = [self offline_request_tearsheet:tear_sheet_params]; // 新建PDF,获取本地路径
-
- NSDictionary *pdfInfo = [NSJSONSerialization JSONObjectWithData:pdfData options:NSJSONReadingMutableContainers error:nil];
- pdf_path = [pdfInfo objectForKey:@"pdf_path"];
-
- if ([[pdfInfo objectForKey:@"result"] integerValue] == RESULT_TRUE) {
-
- resultDictionary = pdfInfo.mutableCopy;
-
- } else { // 创建PDF失败
- return pdfData;
- }
- } else {
- // pdf_path 就是本地路径
- [resultDictionary setObject:pdf_path forKey:@"pdf_path"];
- }
-
- // 将文件移动到PDF Cache文件夹
- NSString *newPath = [pdf_path lastPathComponent];
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
- NSString *cachefolder = [paths objectAtIndex:0];
- NSString *pdfFolder = [cachefolder stringByAppendingPathComponent:@"pdf_cache"];
- newPath = [pdfFolder stringByAppendingPathComponent:newPath];
- NSFileManager *fileManager = [NSFileManager defaultManager];
- NSError *error = nil;
- [fileManager moveItemAtPath:pdf_path toPath:newPath error:&error];
- if (error) { // 移动文件失败
- [resultDictionary setObject:[NSNumber numberWithInt:RESULT_FALSE] forKey:@"result"];
- return [RAConvertor dict2data:resultDictionary];
- }
- [resultDictionary setObject:newPath forKey:@"pdf_path"];
- pdf_path = [newPath lastPathComponent];
-
- // 保存信息
- // [params setObject:[params objectForKey:@"product_ids"] forKey:@"productIds"];
- NSString *off_params = [RAConvertor dict2string:params];
-
-
- // configureParams = [configureParams stringByAppendingFormat:@"productIds=%@",product_ids_string];
-
- pdf_path = [self translateSingleQuote:pdf_path];
- create_user = [self translateSingleQuote:create_user];
- tear_note = [self translateSingleQuote:tear_note];
- tear_name = [self translateSingleQuote:tear_name];
- model_info = [self translateSingleQuote:model_info];
- configureParams = [self translateSingleQuote:configureParams];
- off_params = [self translateSingleQuote:off_params];
-
- NSString *save_pdf_sql = [NSString stringWithFormat:@"insert into offline_pdf (pdf_path,create_user,tear_note,tear_name,model_info,configureParams,is_local,off_params) values ('%@','%@','%@','%@','%@','%@',1,'%@');",pdf_path,create_user,tear_note,tear_name,model_info,configureParams,off_params];
-
- if (tear_sheet_id) {
- int _id = [tear_sheet_id intValue];
- save_pdf_sql = [NSString stringWithFormat:@"update offline_pdf set pdf_path = '%@' where _id = %d;",pdf_path,_id];
- }
-
- int result = [iSalesDB execSql:save_pdf_sql];
-
- [resultDictionary setObject:[NSNumber numberWithInt:result] forKey:@"result"];
-
- //
- BOOL remove_Item = [[params objectForKey:@"remove_item"] boolValue];
- if (remove_Item) {
- // portfolioId
- [self offline_removePortfolio:@{@"portfolioId" : item_ids}.mutableCopy];
- }
-
- return [RAConvertor dict2data:resultDictionary];
- }
- + (NSData *)offline_direct_save_TearSheet:(NSMutableDictionary *)params {
-
- return [self offline_savePDF:params direct:YES contact_id:params[@"contact_id"]];
- }
- + (NSData *)offline_save_TearSheet:(NSMutableDictionary *)params {
- return [self offline_savePDF:params direct:NO contact_id:params[@"contact_id"]];
- }
- + (NSData *)offline_pdfList:(NSMutableDictionary *)params {
-
- int offset = [[params valueForKey:@"offset"] intValue];
- int limit = [[params valueForKey:@"limit"] intValue];
- NSString *keyword = [params valueForKey:@"keyWord"];
-
- NSString *where = @"where is_delete is null or is_delete = 0";
-
- if (keyword.length) {
- keyword = [self translateSingleQuote:keyword];
- where = [NSString stringWithFormat:@"where (is_delete is null or is_delete = 0 ) and lower(create_user) like '%%%@%%' or lower(tear_note) like '%%%@%%' or lower(tear_name) like '%%%@%%'",keyword.lowercaseString,keyword.lowercaseString,keyword.lowercaseString];
- }
-
- NSString *sql = [NSString stringWithFormat:@"select tear_name,tear_note,createtime,create_user,pdf_path,_id,model_info,off_params from offline_pdf %@ order by createtime desc limit %d offset %d;",where,limit,offset];// tearsheets_id ---> _id
-
- __block NSMutableDictionary *dic = [NSMutableDictionary dictionary];
-
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
- NSString *cachefolder = [paths objectAtIndex:0];
- NSString *pdfFolder = [cachefolder stringByAppendingPathComponent:@"pdf_cache"];
-
- [iSalesDB jk_query:sql completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- NSString *name = [self textAtColumn:0 statement:stmt];
- NSString *note = [self textAtColumn:1 statement:stmt];
- NSString *time = [self textAtColumn:2 statement:stmt];
- NSString *user = [self textAtColumn:3 statement:stmt];
- NSString *path = [self textAtColumn:4 statement:stmt];
-
- NSString *model_info = [self textAtColumn:6 statement:stmt];
- NSString *off_params = [self textAtColumn:7 statement:stmt];
- path = [pdfFolder stringByAppendingPathComponent:path];
-
-
- BOOL bdir=NO;
- NSFileManager* fileManager = [NSFileManager defaultManager];
- if(! [fileManager fileExistsAtPath:path isDirectory:&bdir]|| bdir)
- {
- //pdf文件不存在
- path=nil;
- }
-
- time = [self changeDateTimeFormate:time];
- time = [time stringByAppendingString:@" PST"];
-
-
- int sheet_id = sqlite3_column_int(stmt, 5);
-
-
- NSMutableDictionary *item = [[NSMutableDictionary alloc] init];
- item[@"tearsheetsId"]=@(sheet_id);
- item[@"pdf_path"]=path;
- item[@"create_time"]=time;
- item[@"create_user"]=user;
- item[@"tear_note"]=note;
- item[@"tear_name"]=name;
- item[@"isLocalFile"]=[NSNumber numberWithBool:YES];
- item[@"model_info"]=model_info;
- item[@"off_params"]=off_params;
-
-
- [dic setObject:item forKey:[NSString stringWithFormat:@"item_%ld",*count]];
- [dic setValue:[NSNumber numberWithLong:++(*count)] forKey:@"count"];
-
- } failure:^(NSMutableDictionary *container, NSString *err_msg) {
- [dic setValue:[NSNumber numberWithInteger:RESULT_FALSE] forKey:@"result"];
-
- [dic setValue:[NSNumber numberWithInteger:0] forKey:@"count"];
- }];
-
- [dic setValue:@"Regular Mode" forKey:@"mode"];
-
- return [RAConvertor dict2data:dic];
- }
- + (NSData *)offline_add2Portfolio:(NSMutableDictionary *)params {
-
- NSString *prodct_ids = [params objectForKey:@"product_id"];
- // NSString *user = [params objectForKey:@"user"];
- // NSString *sql = [NSString stringWithFormat:@"insert into offline_portfolio (product_id,name,description,item_id) select * from (select p.product_id,p.name,p.description,p.item_id from product as p where p.product_id in (%@) and (select count(0) from offline_portfolio where product_id in (%@) and (is_delete is null or is_delete = 0)) = 0);",prodct_ids,prodct_ids];
-
- NSString *sql = [NSString stringWithFormat:@"insert into offline_portfolio (product_id,name,description,item_id) select * from (select p.product_id,p.name,p.description,p.item_id from product as p where p.product_id in (%@) and p.product_id not in (select product_id from offline_portfolio));insert into offline_portfolio (product_id,name,description,item_id,is_delete) select * from (select p.product_id,p.name,p.description,p.item_id,0 from product as p left join offline_portfolio as f on p.product_id = f.product_id where p.product_id in (%@) and p.product_id in (select product_id from offline_portfolio) and f.is_delete = 1);delete from offline_portfolio where (select count(0) from offline_portfolio where product_id in (%@)) > 1 and is_delete = 1;",prodct_ids,prodct_ids,prodct_ids];
-
- int result = [iSalesDB execSql:sql];
-
- NSMutableDictionary *dic = [NSMutableDictionary dictionary];
- [dic setValue:[NSNumber numberWithInteger:result] forKey:@"result"];
-
- if (result == RESULT_TRUE) {
- /*NSArray *product_id_arr = [prodct_ids componentsSeparatedByString:@","];
- [dic setValue:[NSNumber numberWithInteger:product_id_arr.count] forKey:@"portfolio_count"];*/
- sqlite3 *db = [iSalesDB get_db];
-
- int count = [iSalesDB get_recordcount:db table:@"offline_portfolio" where:@"is_delete is null or is_delete = 0"];
- [dic setValue:[NSNumber numberWithInteger:count] forKey:@"portfolio_count"];
-
- [iSalesDB close_db:db];
- }
-
- [dic setValue:@"Regular Mode" forKey:@"mode"];
- return [RAConvertor dict2data:dic];
- }
- + (NSData *)offline_createTearSheet:(NSMutableDictionary *)params {
-
- NSMutableDictionary *dic = [self dictionaryFileName:@"TearSheet.json"];
-
- [dic setObject:[params objectForKey:@"product_ids"] forKey:@"product_ids"];
- [dic setObject:[params objectForKey:@"item_ids"] forKey:@"item_ids"];
-
- NSMutableDictionary *section_0 = [[dic objectForKey:@"section_0"] mutableCopy];
- NSDictionary *company_item = @{
- @"control": @"text",
- @"keyboard": @"text",
- @"name": @"company_name",
- @"value": COMPANY_FULL_NAME,
- @"aname": @"Company Name"
- };
- [section_0 setObject:company_item forKey:@"item_0"];
- [dic setObject:section_0 forKey:@"section_0"];
-
- // Regurlar Price
- NSMutableDictionary *section1 = [[dic objectForKey:@"section_1"] mutableCopy];
- NSMutableDictionary *price = [[section1 objectForKey:@"item_2"] mutableCopy];
- __block NSMutableDictionary *cadedate = [NSMutableDictionary dictionary];
- __block long val_count = 0;
- NSString *sql = @"select name,type,order_by from price order by order_by";
- [iSalesDB jk_query:sql completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- NSString *name = [self textAtColumn:0 statement:stmt];
- int type = sqlite3_column_int(stmt, 1);
- int order_by = sqlite3_column_int(stmt, 2);
-
- // AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
-
- NSDictionary *price_dic = @{
- @"value" : name,
- @"value_id" : [NSNumber numberWithInteger:type],
- @"check" : order_by == 0 ? @(1) : @(0)
- };
-
-
- [cadedate setObject:price_dic forKey:[NSString stringWithFormat:@"val_%ld",val_count]];
-
- val_count = ++(*count);
-
- } failure:^(NSMutableDictionary *container, NSString *err_msg) {
- val_count = 0;
- }];
-
- [cadedate setObject:@{@"value" : @"None",
- @"value_id" : @(0)} forKey:[NSString stringWithFormat:@"val_%ld",val_count]];
- val_count++;
-
- [cadedate setObject:[NSNumber numberWithInteger:val_count] forKey:@"count"];
-
- [price setObject:cadedate forKey:@"cadedate"];
- [section1 setObject:price forKey:@"item_2"];
- [dic setObject:section1 forKey:@"section_1"];
-
- return [RAConvertor dict2data:dic];
- }
- + (NSData *)offline_model_qty:(NSMutableDictionary *)params {
-
- NSString *product_id = [params objectForKey:@"fashionId"];
- NSString *sql = [NSString stringWithFormat:@"select availability from product where product_id = %@;",product_id];
-
- __block int result = RESULT_TRUE;
- __block int qty = 0;
- [iSalesDB jk_query:sql completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- qty = sqlite3_column_int(stmt, 0);
-
- } failure:^(NSMutableDictionary *container, NSString *err_msg) {
- result = RESULT_FALSE;
- }];
-
- NSMutableDictionary *dic = @{
- @"err_msg" : result == RESULT_FALSE ? @"Failed." : @"Success.",
- @"mode" : @"Regular Mode",
- @"quantity_available" : @(qty),
- @"result" : @(result),
- }.mutableCopy;
-
-
- return [RAConvertor dict2data:dic];
-
-
- }
- + (NSData *)offline_editPortfolio:(NSMutableDictionary *)params {
-
- NSString *item_ids = [params objectForKey:@"item_id"];
- NSString *line_notes = [params objectForKey:@"notes"];
- NSString *price_str = [params objectForKey:@"price"];
- NSString *discount_str = [params objectForKey:@"discount"];
- NSString *percent = [params objectForKey:@"available_percent"];
- NSString *qty = [params objectForKey:@"available_qty"];
-
- NSString *sql = [NSString stringWithFormat:@"update offline_portfolio set "];
- int dot = 0;
-
- if (line_notes) {
- line_notes = [self translateSingleQuote:line_notes];
- line_notes = [NSString stringWithFormat:@"line_note = '%@'",line_notes];
- sql = [sql stringByAppendingString:line_notes];
- dot = 1;
- } else {
- line_notes = @"";
- }
-
- if (price_str) {
- if (dot) {
- price_str = [NSString stringWithFormat:@",sheet_price = %@",price_str];
- } else {
- price_str = [NSString stringWithFormat:@"sheet_price = %@",price_str];
- dot = 1;
- }
- sql = [sql stringByAppendingString:price_str];
- } else {
- price_str = @"";
- }
-
- if (discount_str) {
- if (dot) {
- discount_str = [NSString stringWithFormat:@",sheet_discount = %@",discount_str];
- } else {
- discount_str = [NSString stringWithFormat:@"sheet_discount = %@",discount_str];
- dot = 1;
- }
- sql = [sql stringByAppendingString:discount_str];
- } else {
- discount_str = @"";
- }
-
- if (percent) {
- if (dot) {
- percent = [NSString stringWithFormat:@",percent = %@,percentage = 1",percent];
- } else {
- percent = [NSString stringWithFormat:@"percent = %@,percentage = 1",percent];
- dot = 1;
- }
- sql = [sql stringByAppendingString:percent];
- } else {
- percent = @"";
- }
-
- if (qty) {
- if (dot) {
- qty = [NSString stringWithFormat:@",available_qty = %@,percentage = 0",qty];
- } else {
- qty = [NSString stringWithFormat:@"available_qty = %@,percentage = 0",qty];
- dot = 1;
- }
- sql = [sql stringByAppendingString:qty];
- } else {
- qty = @"";
- }
-
- NSString *where = [NSString stringWithFormat:@" where item_id in (%@) and (is_delete is null or is_delete = 0);",item_ids];
- sql = [sql stringByAppendingString:where];
-
-
- NSMutableDictionary *dic = [NSMutableDictionary dictionary];
-
- int result = [iSalesDB execSql:sql];
-
- [dic setObject:[NSNumber numberWithInt:result] forKey:@"result"];
- [dic setObject:@"Regular Mode" forKey:@"mode"];
-
- return [RAConvertor dict2data:dic];
- }
- + (NSData *)offline_removePortfolio:(NSMutableDictionary *)params {
-
- NSString *portfolio_ids = [params objectForKey:@"portfolioId"];
-
- NSMutableDictionary *dic = [NSMutableDictionary dictionary];
-
- sqlite3 *db = [iSalesDB get_db];
-
- NSString *sql = [NSString stringWithFormat:@"update offline_portfolio set is_delete = 1 where item_id in (%@) and (is_delete is null or is_delete = 0);",portfolio_ids];
-
- int result = [iSalesDB execSql:sql db:db];
-
- [dic setObject:[NSNumber numberWithInt:result] forKey:@"result"];
- [dic setObject:@"Regular Mode" forKey:@"mode"];
-
- int count = [iSalesDB get_recordcount:db table:@"offline_portfolio" where:@"(is_delete is null or is_delete = 0)"];
-
- [dic setObject:[NSNumber numberWithInt:count] forKey:@"portfolio_count"];
-
- [iSalesDB close_db:db];
-
- return [RAConvertor dict2data:dic];
-
- }
- + (void)offline_removePDFWithName:(NSString *)name {
-
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
- NSString *cachefolder = [paths objectAtIndex:0];
- NSString *pdfFolder = [cachefolder stringByAppendingPathComponent:@"pdf_cache"];
- NSString *path = [pdfFolder stringByAppendingPathComponent:name];
-
- NSFileManager *fileManager = [NSFileManager defaultManager];
- [fileManager removeItemAtPath:path error:nil];
- }
- + (void)offline_clear_PDFCache {
- NSFileManager *fileManager = [NSFileManager defaultManager];
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
- NSString *cachefolder = [paths objectAtIndex:0];
- NSString *pdfFolder = [cachefolder stringByAppendingPathComponent:@"pdf_cache"];
-
- NSArray *pdf_files = [fileManager contentsOfDirectoryAtPath:pdfFolder error:nil];
-
- for (NSString *path in pdf_files) {
- [self offline_removePDFWithName:[path lastPathComponent]];
- }
-
- }
- + (NSData *)offline_removePDF:(NSMutableDictionary *)params {
-
- NSMutableDictionary *dic = [NSMutableDictionary dictionary];
-
- NSInteger tearsheetsId = [[params objectForKey:@"tearsheetsId"] integerValue];
- NSString *user = [params objectForKey:@"user"];
-
- NSString *create_user = [iSalesDB jk_queryText:[NSString stringWithFormat:@"select create_user from offline_pdf where _id = %ld;",(long)tearsheetsId]]; // tearsheets_id ---> _id
- if (![create_user isEqualToString:user]) {
- [dic setObject:[NSNumber numberWithInt:RESULT_FALSE] forKey:@"result"];
- [dic setObject:@"Regular Mode" forKey:@"mode"];
- [dic setObject:@"Only Delete Your Owns" forKey:@"err_msg"];
- return [RAConvertor dict2data:dic];
- }
-
- NSString *is_local_sql = [NSString stringWithFormat:@"select is_local,pdf_path from offline_pdf where _id = %ld and create_user = '%@';",(long)tearsheetsId,[self translateSingleQuote:user]];
-
- __block int is_local = 0;
- __block NSString *path = @"";
- [iSalesDB jk_query:is_local_sql completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- is_local = sqlite3_column_int(stmt, 0);
- path = [self textAtColumn:1 statement:stmt];
- }];
-
- NSString *sql = [NSString stringWithFormat:@"update offline_pdf set is_delete = 1 where _id = %ld and create_user = '%@';",(long)tearsheetsId,[self translateSingleQuote:user]];
-
- if (is_local == 1) {
- sql = [NSString stringWithFormat:@"delete from offline_pdf where _id = %ld and create_user = '%@';",(long)tearsheetsId,[self translateSingleQuote:user]];
-
- // 删除文件
- [self offline_removePDFWithName:path];
- }
-
-
- int result = [iSalesDB execSql:sql];
-
- [dic setObject:[NSNumber numberWithInt:result] forKey:@"result"];
- [dic setObject:@"Regular Mode" forKey:@"mode"];
-
- return [RAConvertor dict2data:dic];
- }
- +(NSMutableDictionary*) preparePortfolio:(NSString* ) serial params:(NSMutableDictionary*) add_params
- {
- // assert(add_params[@"contact_id"]!=nil);
- assert(add_params[@"user"]!=nil);
- NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
-
- NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
-
- NSString* ver = [defaults stringForKey:@"OfflineVer"] ;
-
-
- NSString* where=@"1=1";
-
- if (ver!=nil) {
-
- where=@"is_dirty=1";
-
- }
-
- NSString *sqlQuery =[NSString stringWithFormat:@"select _id,product_id,name,description,item_id,fashion_id,ifnull(available_qty,'null'),ifnull(percentage,'null'),ifnull(percent,'null'),ifnull(sheet_price,'null'),sheet_discount,img,line_note,is_delete,createtime,modify_time from offline_portfolio where %@",where];
-
-
- [ret setValue:[NSNumber numberWithInt:AP_USER_NOT_AUTH ] forKey:@"result"];
-
- // AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
-
- sqlite3 *db = [iSalesDB get_db];
-
- NSDictionary *queryDic = [iSalesDB jk_query:sqlQuery db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- NSMutableDictionary *item = [NSMutableDictionary dictionary];
-
- NSInteger _id = sqlite3_column_int(stmt, 0);
- NSInteger product_id = sqlite3_column_int(stmt, 1);
- NSString *name = [self textAtColumn:2 statement:stmt];
- NSString *desc = [self textAtColumn:3 statement:stmt];
- NSInteger item_id = sqlite3_column_int(stmt, 4);
- NSInteger fashion_id = sqlite3_column_int(stmt, 5);
- NSInteger qty = sqlite3_column_int(stmt, 6);
- NSInteger is_percent = sqlite3_column_int(stmt, 7);
- double percent = sqlite3_column_double(stmt, 8);
- double price = sqlite3_column_double(stmt, 9);
- double discount = sqlite3_column_double(stmt, 10);
- NSString *img = [self textAtColumn:11 statement:stmt];
- NSString *line_note = [self textAtColumn:12 statement:stmt];
- NSInteger is_delete = sqlite3_column_int(stmt, 13);
- NSString *create_time = [self textAtColumn:14 statement:stmt];
- NSString *modify_time = [self textAtColumn:15 statement:stmt];
-
- NSString *price_null = [self textAtColumn:9 statement:stmt];
- if ([price_null isEqualToString:@"null"]) {
- price = [[self get_model_default_price:add_params[@"contact_id"] user:add_params[@"user"] product_id:nil item_id:@(item_id) db:db] doubleValue];
- }
-
- NSString *qty_null = [self textAtColumn:6 statement:stmt];
- NSString *is_percent_null = [self textAtColumn:7 statement:stmt];
- NSString *percent_null = [self textAtColumn:8 statement:stmt];
-
- [item setValue:[NSNumber numberWithInteger:_id] forKey:@"_id"];
- [item setValue:[NSNumber numberWithInteger:product_id] forKey:@"product_id"];
- [item setValue:[NSNumber numberWithInteger:item_id] forKey:@"item_id"];
- [item setValue:[NSNumber numberWithInteger:fashion_id] forKey:@"fashion_id"];
- [item setValue:[NSNumber numberWithInteger:is_delete] forKey:@"is_delete"];
-
- if ([qty_null isEqualToString:@"null"]) {
- // [item setValue:@"null" forKey:@"available_qty"];
- } else {
- [item setValue:[NSNumber numberWithInteger:qty] forKey:@"available_qty"];
- }
-
- if ([is_percent_null isEqualToString:@"null"]) {
- // [item setValue:@"null" forKey:@"percentage"];
- } else {
- [item setValue:[NSNumber numberWithInteger:is_percent] forKey:@"percentage"];
- }
-
- if ([percent_null isEqualToString:@"null"]) {
- // [item setValue:@"null" forKey:@"percent"];
- } else {
- [item setValue:[NSNumber numberWithDouble:percent] forKey:@"percent"];
- }
-
- [item setValue:[NSNumber numberWithDouble:price] forKey:@"sheet_price"];
- [item setValue:[NSNumber numberWithDouble:discount] forKey:@"sheet_discount"];
-
- [item setValue:name forKey:@"name"];
- [item setValue:desc forKey:@"description"];
- [item setValue:img forKey:@"img"];
- [item setValue:line_note forKey:@"line_note"];
- [item setValue:create_time forKey:@"createtime"];
- [item setValue:modify_time forKey:@"modifytime"];
-
-
- [ret setObject:item forKey:[NSString stringWithFormat:@"item_%ld",(*count)++]];
- [ret setObject:[NSNumber numberWithInteger:RESULT_TRUE] forKey:@"result"];
- [ret setObject:[NSNumber numberWithInteger:*count] forKey:@"count"];
-
- }];
-
- [iSalesDB close_db:db];
-
- if ([[queryDic objectForKey:@"result"] integerValue] == RESULT_FALSE) {
- [ret setObject:[NSNumber numberWithInteger:RESULT_FALSE] forKey:@"result"];
- }
-
-
- return ret;
- }
- +(NSMutableDictionary*) preparePDF:(NSString* ) serial
- {
-
- NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
-
- NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
-
- NSString* ver = [defaults stringForKey:@"OfflineVer"] ;
-
-
- NSString* where=@"1=1";
-
- if (ver!=nil) {
-
- where=@"is_dirty=1";
-
- }
-
- NSString *sqlQuery =[NSString stringWithFormat:@"select _id,ifnull(tearsheets_id,'null'),pdf_path,create_user,tear_note,tear_name,model_info,createtime,modify_time,configureParams,off_params,is_delete,is_local from offline_pdf where %@",where];
-
-
- [ret setValue:[NSNumber numberWithInt:AP_USER_NOT_AUTH ] forKey:@"result"];
-
- [iSalesDB jk_query:sqlQuery completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- NSMutableDictionary *item = [NSMutableDictionary dictionary];
-
- NSInteger _id = sqlite3_column_int(stmt, 0);
- NSInteger tearsheets_id = sqlite3_column_int(stmt, 1);
- NSString *pdf_path = [self textAtColumn:2 statement:stmt];
- NSString *create_user = [self textAtColumn:3 statement:stmt];
- NSString *tear_note = [self textAtColumn:4 statement:stmt];
- NSString *tear_name = [self textAtColumn:5 statement:stmt];
- NSString *model_info = [self textAtColumn:6 statement:stmt];
- NSString *createtime = [self textAtColumn:7 statement:stmt];
- NSString *modifytime = [self textAtColumn:8 statement:stmt];
- NSString *urlParams = [self textAtColumn:9 statement:stmt];
- NSString *off_params = [self textAtColumn:10 statement:stmt];
- NSString *uuid = [NSUUID UUID].UUIDString;
- int is_delete = sqlite3_column_int(stmt, 11);
- NSString *tearsheet_id_null = [self textAtColumn:1 statement:stmt];
- int is_local = sqlite3_column_int(stmt, 12);
-
- [item setObject:[NSNumber numberWithInteger:_id] forKey:@"_id"];
- if (![tearsheet_id_null isEqualToString:@"null"]) {
- [item setObject:[NSNumber numberWithInteger:tearsheets_id] forKey:@"tearsheets_id"];
- }
- [item setObject:pdf_path forKey:@"pdf_path"];
- [item setObject:create_user forKey:@"create_user"];
- [item setObject:tear_note forKey:@"tear_note"];
- [item setObject:tear_name forKey:@"tear_name"];
- [item setObject:model_info forKey:@"model_info"];
- [item setObject:createtime forKey:@"createtime"];
- [item setObject:modifytime forKey:@"modifytime"];
- [item setObject:urlParams forKey:@"urlParams"];
- [item setObject:off_params forKey:@"off_params"];
- [item setObject:uuid forKey:@"pdf_token"];
- [item setObject:[NSNumber numberWithInt:is_delete] forKey:@"is_delete"];
-
- NSDictionary *off_Params_dic = [RAConvertor string2dict:off_params];
- [item setObject:[off_Params_dic objectForKey:@"product_ids"] forKey:@"product_ids"];
-
- if (!is_local && !is_delete) { // 已经同步过的,并且没被删除,就不需要上传。
-
- } else {
- [ret setObject:item forKey:[NSString stringWithFormat:@"item_%ld",(*count)++]];
- }
- [ret setObject:[NSNumber numberWithInteger:RESULT_TRUE] forKey:@"result"];
- [ret setObject:[NSNumber numberWithInteger:*count] forKey:@"count"];
-
- } failure:^(NSMutableDictionary *container, NSString *err_msg) {
-
- [ret setObject:[NSNumber numberWithInteger:RESULT_FALSE] forKey:@"result"];
-
- }];
-
- return ret;
- }
- #pragma mark 2020
- +(void) offline_contactlist :(NSMutableDictionary *) params completionHandler:(resultHandler)result
- {
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- 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"];
-
- // sqlQuery = @"select editable,decrypt(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 Sales_Order_Customer = 1 and is_active=1 order by decrypt(company_name) limit 25 offset 0";
-
- int i = 0;
- if (sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil) == SQLITE_OK)
- {
-
-
- 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=[RAConvertor 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 = [RAConvertor 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++;
-
-
-
- }
-
-
-
-
- sqlite3_finalize(statement);
- }
-
-
-
- [iSalesDB close_db:db];
-
-
-
-
- DebugLog(@"data string: %@",[RAConvertor dict2string:ret] );
- dispatch_async(dispatch_get_main_queue(), ^{
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- [ret setValue:appDelegate.mode forKey:@"mode"];
- [ret setValue:[NSNumber numberWithInt:i ] forKey:@"count"];
-
- result(ret);
- });
- return ;
- });
-
-
-
- }
- //+(void) offline_contactinfo :(NSMutableDictionary *) params completionHandler:(resultHandler)result
- //{
- //
- // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- //
- // 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,type 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];
- //
- // NSString *contact_type = [self textAtColumn:24 statement:statement];
- //
- //
- // {
- // // 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=[RAConvertor 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=[RAConvertor 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"];
- // [item setValue:contact_type forKey:@"customer_contact_type"];
- //
- //
- // [ret setObject:item forKey:@"customerInfo"];
- // // i++;
- //
- //
- //
- // }
- //
- //
- //
- //
- // sqlite3_finalize(statement);
- // }
- //
- //
- //
- // [iSalesDB close_db:db];
- //
- //
- //
- //
- // DebugLog(@"data string: %@",[RAConvertor dict2string:ret] );
- // dispatch_async(dispatch_get_main_queue(), ^{
- // UIApplication * app = [UIApplication sharedApplication];
- // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- // [ret setValue:appDelegate.mode forKey:@"mode"];
- // [ret setValue:[NSNumber numberWithInt:1 ] forKey:@"count"];
- // result(ret);
- // });
- //
- // return ;
- // });
- //}
- + (void)categoryList:(NSMutableDictionary *)params limited:(BOOL)limited completionHandler:(resultHandler)result
- {
-
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- NSString* order_code= appDelegate.order_code;
- NSString* user = appDelegate.user;
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- 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];
- NSString *limit_str = @"";
- if (limited) {
- limit_str = [NSString stringWithFormat:@"limit %d offset %d ",limit,offset];
- }
-
-
- 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,c._id,w.is_delete,m.category,m.more_color from product m left join wishlist w on m.product_id=w.product_id left join (select _id,product_id from offline_cart where so_no='%@') c on c.product_id=m.product_id where m.category like'%%#%@#%%' and m.is_active = 1 order by m.name %@ ;",order_code, category,limit_str];
-
-
- 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 (user && price != nil) {
- NSArray *priceTypeArray = [self get_contact_default_price_type:nil user:user 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];
-
- // cate mutiple selection
- NSString *category_id = params[@"category"];
- 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];
- }
-
- [cateWhere appendString:@"("];
- for (int i = 0; i < cate_id_array.count; i++) {
-
- if (i == 0) {
- [cateWhere appendFormat:@"category like'%%#%@#%%'",cate_id_array[i]];
- } else {
- [cateWhere appendFormat:@" or category like'%%#%@#%%'",cate_id_array[i]];
- }
-
- }
- [cateWhere appendString:@")"];
-
- }
-
- // 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,c._id,w.is_delete,m.category,m.more_color from (select name,description,product_id,closeout,best_seller,category,more_color from product where %@ %@ %@ %@ %@ %@ and is_active = 1) m left join wishlist w on m.product_id=w.product_id left join (select _id,product_id from offline_cart where so_no='%@') c on c.product_id=m.product_id order by %@ %@;",cateWhere,best_seller,alert,available_condition,qty,price,order_code,order_best_seller,limit_str];
-
-
- where =[NSString stringWithFormat:@"%@ %@ %@ %@ %@ %@ and is_active = 1",cateWhere,best_seller,alert,available_condition,qty,price];
-
- }
- DebugLog(@"offline category where: %@",where);
- count = [iSalesDB get_recordcount:db table:@"product" where:where];
-
- if (!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);
- int cid = sqlite3_column_int(statement, 5);
- int wisdelete = sqlite3_column_int(statement, 6);
- NSString *categoryStr = [self textAtColumn:7 statement:statement];
- int more_color = sqlite3_column_int(statement, 8);
-
- // Defaul Category ID
- __block NSString *categoryID = nil;
- NSString *defaultCateSQL = [NSString stringWithFormat:@"select default_category from product where product_id=%d;",product_id];
- [iSalesDB jk_query:defaultCateSQL db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- char *default_category = (char*)sqlite3_column_text(stmt, 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:@""];
-
- categoryID = nsdefault_category;
-
- }];
-
- if (!categoryID.length) {
- NSString *cateIDs = params[@"category"];
- NSArray *requestCategoryArr = [cateIDs componentsSeparatedByString:@","];
- NSArray *itemCategoryArr = [categoryStr componentsSeparatedByString:@","];
- for (NSString *cateID in requestCategoryArr) {
-
- BOOL needBreak = NO;
- for (NSString *itemCateIDBox in itemCategoryArr) {
-
- if (itemCateIDBox.length > 4) {
- NSString *itemCategoryID = [itemCateIDBox substringFromIndex:2];
- itemCategoryID = [itemCategoryID substringToIndex:itemCategoryID.length - 2];
-
- if ([itemCategoryID isEqualToString:cateID]) {
- needBreak = YES;
- categoryID = itemCategoryID;
- break;
- }
- }
-
- }
- if (needBreak) {
- break;
- }
-
- }
- }
-
- NSMutableDictionary* imgjson=[self category_img:product_id db:db];
-
- if(wid !=0 && wisdelete != 1)
- [item setValue:@"true" forKey:@"wish_exists"];
- else
- [item setValue:@"false" forKey:@"wish_exists"];
-
- if(closeout==0)
- [item setValue:@"false" forKey:@"is_closeout"];
- else
- [item setValue:@"true" forKey:@"is_closeout"];
-
-
- if(cid==0)
- [item setValue:@"false" forKey:@"cart_exists"];
- else
- [item setValue:@"true" forKey:@"cart_exists"];
-
- if (more_color == 0) {
- [item setObject:@(false) forKey:@"more_color"];
- } else if (more_color == 1) {
- [item setObject:@(true) forKey:@"more_color"];
- }
-
- [item addEntriesFromDictionary:imgjson];
-
-
- // [item setValue:nsurl forKey:@"img"];
- [item setValue:nsname forKey:@"name"];
- [item setValue:nsdescription forKey:@"description"];
- if (categoryID) {
- [item setValue:categoryID forKey:@"item_category_id"];
- }
- [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: %@",[RAConvertor dict2string:ret] );
-
- dispatch_async(dispatch_get_main_queue(), ^{
- // UIApplication * app = [UIApplication sharedApplication];
- // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- // [ret setValue:appDelegate.mode forKey:@"mode"];
- // [ret setValue:[NSNumber numberWithInt:1 ] forKey:@"count"];
- result(ret);
- });
-
- });
-
- // NSString* orderCode = [params valueForKey:@"orderCode"];
-
-
-
-
-
-
- }
- +(void) offline_category :(NSMutableDictionary *) params completionHandler:(resultHandler)result
- {
- [self categoryList:params limited:YES completionHandler:result];
- }
- + (void) search:(NSMutableDictionary *)params limited:(BOOL)limited completionHandler:(resultHandler)result
- {
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- NSString* order_code = appDelegate.order_code;
-
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- NSString* keyword = [params valueForKey:@"keyword"];
- keyword=keyword.lowercaseString;
-
- bool exactMatch = [[params valueForKey:@"exactMatch"] boolValue]; // search by factory code
-
-
- int limit = [[params valueForKey:@"limit"] intValue];
- int offset = [[params valueForKey:@"offset"] intValue];
-
- NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
-
-
- NSString *limit_str = @"";
- if (limited) {
- limit_str = [NSString stringWithFormat:@"limit %d offset %d ",limit,offset];
- }
-
-
- 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,c._id,w.is_delete,m.more_color from product m left join wishlist w on m.product_id=w.product_id left join (select _id,product_id from offline_cart where so_no='%@') c on c.product_id=m.product_id where lower(name) like'%@%%' and m.is_active = 1 order by m.name %@;",order_code, keyword,limit_str]; // 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,c._id,w.is_delete,m.more_color from product m left join wishlist w on m.product_id=w.product_id left join (select _id,product_id from offline_cart where so_no='%@') c on c.product_id=m.product_id where (lower(name) like'%%%@%%' or lower(description) like'%%%@%%' or lower(made_in) like '%%%@%%' or lower(material) like '%%%@%%' or lower(packaging) like '%%%@%%') and m.is_active = 1 order by m.name %@ ;",order_code, keyword,keyword,keyword,keyword,keyword,limit_str];// 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);
- int cid = sqlite3_column_int(statement, 5);
- int wisdelete = sqlite3_column_int(statement, 6);
- int more_color = sqlite3_column_int(statement, 7);
-
- NSMutableDictionary* imgjson=[self category_img:product_id db:db];
-
- if(wid !=0 && wisdelete != 1)
- [item setValue:@"true" forKey:@"wish_exists"];
- else
- [item setValue:@"false" forKey:@"wish_exists"];
-
- if(closeout==0)
- [item setValue:@"false" forKey:@"is_closeout"];
- else
- [item setValue:@"true" forKey:@"is_closeout"];
-
- if(cid==0)
- [item setValue:@"false" forKey:@"cart_exists"];
- else
- [item setValue:@"true" forKey:@"cart_exists"];
-
- if (more_color == 0) {
- [item setObject:@(false) forKey:@"more_color"];
- } else if (more_color == 1) {
- [item setObject:@(true) forKey:@"more_color"];
- }
-
- [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);
- }
- DebugLog(@"count:%d",count);
-
-
- [iSalesDB close_db:db];
-
-
-
-
- DebugLog(@"data string: %@",[RAConvertor dict2string:ret] );
- dispatch_async(dispatch_get_main_queue(), ^{
-
- result(ret);
- });
- });
-
-
-
- }
- +(void) offline_search:(NSMutableDictionary *) params completionHandler:(resultHandler)result
- {
- [self search:params limited:YES completionHandler:result];
- }
- //+ (void) itemsearch:(NSMutableDictionary *)params limited:(BOOL)limited completionHandler:(resultHandler)result
- //{
- // AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- // NSString* order_code = appDelegate.order_code;
- // NSString* user = appDelegate.user;
- // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- // 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];
- //
- // NSString *limit_str = @"";
- // if (limited) {
- // limit_str = [NSString stringWithFormat:@"limit %d offset %d",limit,offset];
- // }
- //
- //
- // 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,c._id,w.is_delete,m.more_color from product m left join wishlist w on m.product_id=w.product_id left join (select _id,product_id from offline_cart where so_no='%@') c on c.product_id=m.product_id where %@ order by %@ %@;",order_code, where,orderby,limit_str];
- //
- //
- // 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 (user) {
- // NSArray *priceTypeArray = [self get_contact_default_price_type:nil user:user 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];// 老子
- //
- // [cateWhere appendString:@"("];
- // 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];
- //
- // }
- //
- // } else if ([key1 isEqualToString:@"cid"]) { // 2017-03-10 修复Item Search父节点下没有子节点的情况下选中父节点查询没有结果
- //
- // if ([[category0 objectForKey:@"cid"] isEqualToString:cate_id_array[i]]) {
- //
- // cate_id_array[i] = [category0 objectForKey:@"id"];
- // if (i == 0) {
- // [cateWhere appendFormat:@"category like'%%#%@#%%'",cate_id_array[i]];
- // } else {
- // [cateWhere appendFormat:@" or category like'%%#%@#%%'",cate_id_array[i]];
- // }
- // [category0 setValue:[NSNumber numberWithInteger:1] forKey:@"check"];
- // [cateDic setValue:category0 forKey:key0];
- //
- // }
- //
- // }
- //
- // }
- //
- // }
- //
- // }
- //
- // }
- // [cateWhere appendString:@")"];
- //
- // [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,c._id,w.is_delete,m.more_color from (select name,description,product_id,closeout,best_seller,more_color from product where %@ %@ %@ %@ %@ %@ and is_active = 1) m left join wishlist w on m.product_id=w.product_id left join (select _id,product_id from offline_cart where so_no='%@') c on c.product_id=m.product_id order by %@ %@;", cateWhere,best_seller,alert,available_condition,qty,price,order_code,order_best_seller,limit_str];
- //
- //
- // // 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 (!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);
- // int cid = sqlite3_column_int(statement, 5);
- // int wisdelete = sqlite3_column_int(statement, 6);
- // int more_color = sqlite3_column_int(statement, 7);
- // NSMutableDictionary* imgjson=[self category_img:product_id db:db];
- //
- // if(wid !=0 && wisdelete != 1)
- // [item setValue:@"true" forKey:@"wish_exists"];
- // else
- // [item setValue:@"false" forKey:@"wish_exists"];
- //
- // if(closeout==0)
- // [item setValue:@"false" forKey:@"is_closeout"];
- // else
- // [item setValue:@"true" forKey:@"is_closeout"];
- //
- // if(cid==0)
- // [item setValue:@"false" forKey:@"cart_exists"];
- // else
- // [item setValue:@"true" forKey:@"cart_exists"];
- //
- // if (more_color == 0) {
- // [item setObject:@(false) forKey:@"more_color"];
- // } else if (more_color == 1) {
- // [item setObject:@(true) forKey:@"more_color"];
- // }
- //
- // [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: %@",[RAConvertor dict2string:ret] );
- //
- // DebugLog(@"data string: %@",[RAConvertor dict2string:ret] );
- // dispatch_async(dispatch_get_main_queue(), ^{
- //
- // result(ret);
- // });
- //
- // });
- //
- //
- //
- //}
- //+(void) offline_itemsearch :(NSMutableDictionary *) params completionHandler:(resultHandler)result
- //{
- // [self itemsearch:params limited:YES completionHandler:result];
- //}
- +(void) offline_commoneditor_partialrefresh :(NSMutableDictionary *) params completionHandler:(resultHandler)result
- {
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- NSString* offline_command=params[@"offline_Command"];
- NSMutableDictionary* ret=nil;
- if([offline_command isEqualToString:@"model_NIYMAL"])
- {
- NSString* category = params[@"category"];
- ret = [[self refresh_model_NIYMAL:category] mutableCopy];
- }
- dispatch_async(dispatch_get_main_queue(), ^{
-
- result(ret);
- });
-
- });
-
- }
- +(void) offline_wishlist :(NSMutableDictionary *) params completionHandler:(resultHandler)result;
- {
-
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- int sort = [[params objectForKey:@"sort"] intValue];
- NSString *sort_str = @"";
- switch (sort) {
- case 0:{
- sort_str = @"order by w.modify_time desc";
- }
- break;
- case 1:{
- sort_str = @"order by w.modify_time asc";
- }
- break;
- case 2:{
- sort_str = @"order by m.name asc";
- }
- break;
- case 3:{
- sort_str = @"order by m.name desc";
- }
- break;
- case 4:{
- sort_str = @"order by m.description asc";
- }
- break;
-
- default:
- break;
-
- }
-
-
- // NSString* user = appDelegate.user;
-
- sqlite3 *db = [iSalesDB get_db];
-
- // order by w.create_time
- NSString* sqlQuery = [NSString stringWithFormat:@"select w.product_id,m.name||'\n'||m.description,w._id,w.qty from wishlist as w left join product as m on w.product_id=m.product_id where w.is_delete is NULL or w.is_delete != 1 %@ ",sort_str];
-
- // NSString* sqlQuery = [NSString stringWithFormat:@"select m.product_id,(m.name||'\n'||m.description) as des,w._id from product as m,wishlist as w where m.product_id = w.product_id %@",sort_str];
-
-
- sqlite3_stmt * statement;
-
- NSDate *date1 = [NSDate date];
- // NSDate *date2 = nil;
-
- 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);
-
- NSDate *date_image = [NSDate date];
-
- NSString *nsurl=[self model_category_img:[NSString stringWithFormat:@"%@",[NSNumber numberWithInt:product_id]] model_name:nil db:db];
-
- printf("image : ");
- [self printTimeIntervalBetween:date_image and:[NSDate date]];
-
- // char *url = (char*)sqlite3_column_text(statement, 3);
- // if(url==nil)
- // url="";
- // NSString *nsurl = [[NSString alloc]initWithUTF8String:url];
-
- int qty = sqlite3_column_int(statement, 3);
-
-
- item[@"cart_count"] = [NSNumber numberWithInt:qty];
- 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++;
-
- }
- printf("total time:");
- [self printTimeIntervalBetween:date1 and:[NSDate date]];
-
- ret[@"count"]= [NSNumber numberWithInt:count];
- ret[@"total_count"]= [NSNumber numberWithInt:count];
- // ret[@"wish_count"]= [NSNumber numberWithInt:count];
- ret[@"result"]= [NSNumber numberWithInt:2];
-
-
-
- sqlite3_finalize(statement);
-
-
-
-
- }
-
- [iSalesDB close_db:db];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- appDelegate.wish_count =count;
-
- [appDelegate update_count_mark];
- result(ret);
- });
-
- });
-
- }
- +(void) offline_add2wishlist :(NSMutableDictionary *) params completionHandler:(resultHandler)result
- {
- // UIApplication * app = [UIApplication sharedApplication];
- // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- NSMutableDictionary* ret=[[NSMutableDictionary alloc]init];
- sqlite3 *db = [iSalesDB get_db];
-
- [iSalesDB execSql:@"BEGIN TRANSACTION" db:db];
-
- NSString* product_id=params[@"product_id"];
- NSString *item_count_str = params[@"item_count"];
-
-
- NSArray* arr=[RAConvertor string2arr:product_id separator:@","];
-
- NSArray *item_count_arr = item_count_str ? [RAConvertor string2arr:item_count_str separator:@","] : nil;
-
-
- NSString* sqlQuery = [NSString stringWithFormat:@"insert into wishlist(product_id,qty) values(?,?);"];
- // NSString *sql = @"";
- 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];
-
- __block int cart_count = 0;
- if (!item_count_str) {
- NSString *product_sold_qty_sql = [NSString stringWithFormat:@"select model_set from product where product_id = %@",arr[i]];
- [iSalesDB jk_query:product_sold_qty_sql db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- NSString *model_set = [self textAtColumn:0 statement:stmt];
- NSArray *model_set_components = [model_set componentsSeparatedByString:@" "];
- cart_count = [[model_set_components lastObject] intValue];
-
- }];
- }
-
- if(count==0)
- {
-
- sqlQuery = [NSString stringWithFormat:@"insert into wishlist(product_id,qty) values(?,?);"];
-
- sqlite3_stmt *stmt;
- sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &stmt, nil);
- sqlite3_bind_text(stmt,1,[arr[i] UTF8String],(int)[arr[i] length],NULL);
- if (item_count_arr) {
- sqlite3_bind_int(stmt,2,[item_count_arr[i] intValue]);
- } else {
- sqlite3_bind_int(stmt,2,cart_count);
- }
-
- if (sqlite3_step(stmt) == SQLITE_ERROR) {
- [iSalesDB execSql:@"ROLLBACK" db:db];
- ret[@"result"]=[NSNumber numberWithInt:RESULT_ERROR ];
-
- [iSalesDB close_db:db];
- DebugLog(@"add to wishlist error");
- dispatch_async(dispatch_get_main_queue(), ^{
- result(ret);
- });
- }
- } else {
- int qty = 0;
- if (item_count_arr) {
- qty = [item_count_arr[i] intValue];
- } else {
- qty = cart_count;
- }
- sqlQuery = [NSString stringWithFormat:@"update wishlist set qty = 1 where product_id = %@ and (is_delete is null or is_delete != 1);update wishlist set qty = %d,is_delete = 0 where product_id = %@ and is_delete = 1;",arr[i],qty,arr[i]];
-
- if ([iSalesDB execSql:sqlQuery db:db] == RESULT_FALSE) {
- [iSalesDB execSql:@"ROLLBACK" db:db];
- ret[@"result"]=[NSNumber numberWithInt:RESULT_ERROR];
-
- [iSalesDB close_db:db];
- DebugLog(@"add to wishlist error");
- dispatch_async(dispatch_get_main_queue(), ^{
- result(ret);
- });
-
- }
- }
-
- }
- // [iSalesDB execSql:sql db:db];
- int count=[iSalesDB get_recordcount:db table:@"wishlist" where:@"is_delete is NULL or is_delete != 1"];
- [iSalesDB execSql:@"END TRANSACTION" db:db];
-
- // int wish_count = [iSalesDB get_recordcount:db table:@"wishlist" where:@"1=1"];
- [ret setValue:[NSNumber numberWithInteger:count] forKey:@"wish_count"];
- [iSalesDB close_db:db];
-
-
- ret[@"result"]= [NSNumber numberWithInt:2];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- appDelegate.wish_count =count;
-
- [appDelegate update_count_mark];
- result(ret);
- });
-
- });
-
- }
- +(void) offline_model :(NSMutableDictionary *) params completionHandler:(resultHandler)result
- {
-
- AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
- bool bLogin = appDelegate.bLogin;
- __block NSString* contact_id = appDelegate.contact_id;
- __block NSString* user = appDelegate.user;
- __block NSString* order_code = appDelegate.order_code;
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- NSString* model_name = [params valueForKey:@"product_name"];
-
- NSString* product_id = [params valueForKey:@"product_id"];
- NSString* upc_code = [params valueForKey:@"upc_code"];
- NSString* category = [params valueForKey:@"category"];
-
- NSString *default_category_id = [self model_default_category:product_id model_name:model_name upc_code:upc_code];
- if(category==nil) {
- category = default_category_id;
- } else {
-
- NSArray *arr_0 = [category componentsSeparatedByString:@","];
- // 参数重有多个category id
- if (arr_0.count > 1) {
- NSArray *arr_1 = [[self categoryIdOfProduct:product_id name:model_name] componentsSeparatedByString:@","];
-
- // 取交集
- NSMutableSet *set_0 = [NSMutableSet setWithArray:arr_0];
- NSMutableSet *set_1 = [NSMutableSet setWithArray:arr_1];
- [set_0 intersectSet:set_1];
-
- if (set_0.count == 1) {
- category = (NSString *)[set_0 anyObject];
- } else {
- if ([set_0 containsObject:default_category_id]) {
- category = default_category_id;
- } else {
- category = (NSString *)[set_0 anyObject];
- }
- }
- }
- }
-
- 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)
- if(model_name==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,ETA,item_id,seat_dimension,product_content_writing from product where upc_code = '%@' or upc_code like '%@;%%' or upc_code like '%%;%@;%%' or upc_code like '%%;%@';",upc_code,upc_code,upc_code,upc_code]; // 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,ETA,item_id,seat_dimension,product_content_writing 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,ETA,item_id,seat_dimension,product_content_writing 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];
- [img_section setValue:[NSString stringWithFormat:@"%d",incoming_stock] forKey:@"incoming_stock"];
- 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 = @"Out of Stock";
-
- [img_section setValue:Availability forKey:@"Availability"];
- [img_section setValue:[NSString stringWithFormat:@"%d",stockUcom] forKey:@"stockUom"];
-
-
-
-
- char *eta = (char*)sqlite3_column_text(statement, 25);
- if(eta==nil)
- eta="";
- NSString *nseta = [[NSString alloc]initWithUTF8String:eta];
- if ([nseta isEqualToString:@"null"]) {
- nseta = @"";
- }
- if (availability <= 0) {
- [img_section setValue:nseta forKey:@"ETA"];
- }
-
-
- int item_id = sqlite3_column_int(statement, 26);
- NSString *seat_dimension = [self textAtColumn:27 statement:statement];
- NSString *content_writing = [self textAtColumn:28 statement:statement];
-
- NSString* Price=nil;
- if(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:contact_id user:user product_id:nil item_id:@(item_id) db:db];
- if(price==nil)
- Price=@"No Price.";
- else
- Price=[NSString stringWithFormat:@"%.2f",price.floatValue];
- }
-
- [img_section setObject:content_writing forKey:@"product_content_writing"];
- [img_section setValue:Price forKey:@"price"];
- [img_section setValue:nsname forKey:@"model_name"];
- [img_section setValue:nsdescription forKey:@"model_descrition"];
-
- if (order_code) { // 离线order code即so#
-
- NSString *cartQtySql = [NSString stringWithFormat:@"select c.item_count from offline_cart as c left join offline_order as o on c.so_no = o.so_id where o.so_id = '%@' and c.item_id = %d;",order_code,item_id];
- __block int cartQTY = 0;
- [iSalesDB jk_query:cartQtySql db:db close:NO completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
-
- cartQTY = sqlite3_column_int(stmt, 0);
-
- }];
-
- if (cartQTY > 0) {
- [img_section setObject:[NSNumber numberWithInt:cartQTY] forKey:@"Model QTY in cart"];
- }
- }
-
- [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:@"Seat Dimension" value:seat_dimension] 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:contact_id item_id:item_id user:user islogin:bLogin 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_priceKvItem: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"];
- }
- // DebugLog(@"count:%d",count);
-
-
- [iSalesDB close_db:db];
- DebugLog(@"data string: %@",[RAConvertor dict2string:ret] );
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
-
- result(ret);
- });
-
-
- });
-
-
- }
- //+(void) offline_deletewishlist :(NSMutableDictionary *) params completionHandler:(resultHandler)result;
- //{
- //
- // UIApplication * app = [UIApplication sharedApplication];
- // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- // 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];
- // NSString* sqlQuery = [NSString stringWithFormat:@"update wishlist set is_delete = 1 where _id in (%@);",collectId];
- // [iSalesDB execSql:sqlQuery db:db];
- // int count=[iSalesDB get_recordcount:db table:@"wishlist" where:@"is_delete is NULL or is_delete != 1"];
- // [iSalesDB close_db:db];
- //
- //
- // ret[@"result"]= [NSNumber numberWithInt:2];
- // dispatch_async(dispatch_get_main_queue(), ^{
- //
- // appDelegate.wish_count =count;
- //
- // [appDelegate update_count_mark];
- // result(ret);
- // });
- //
- // });
- //}
- +(void) offline_logout :(NSMutableDictionary *) params completionHandler:(resultHandler)result
- {
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
-
-
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- [iSalesDB disable_trigger];
- [iSalesDB execSql:@"delete from offline_cart where so_no in (select so_id from offline_order where status = 0);"];
- [iSalesDB execSql:@"delete from offline_order where status=0;"];
- [iSalesDB enable_trigger];
- dispatch_async(dispatch_get_main_queue(), ^{
-
-
- //
- // NSString* user = [params valueForKey:@"user"];
- //
- // NSString* password = [params valueForKey:@"password"];
-
-
-
- NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
-
- ret[@"result"]=[NSNumber numberWithInt:2 ];
-
-
-
- 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];
- result(ret);
- });
- });
-
-
-
-
- }
- +(void) offline_createorder :(NSMutableDictionary *) params completionHandler:(resultHandler)result
- {
-
- // iSalesDB.
- // UIApplication * app = [UIApplication sharedApplication];
- // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
-
-
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- [iSalesDB disable_trigger];
- [iSalesDB execSql:@"delete from offline_cart where so_no in (select so_id from offline_order where status = 0);"];
- [iSalesDB execSql:@"delete from offline_order where status=0;"];
- [iSalesDB enable_trigger];
- NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
-
- NSString *customer_name = [self translateSingleQuote:params[@"customer_name"]];
- 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=[RAConvertor arr2string:arr_name separator:@" " trim:true];
-
- // default ship from
- NSString *ship_from_default_sql = @"select contact_id,decrypt(company_name),decrypt(addr_1),first_name || ' ' || last_name,email,fax,decrypt(phone) from offline_contact where contact_id = 'NPD';";
-
- __block NSString *cid = @"";
- __block NSString *name = @"";
- __block NSString *ext = @"";
- __block NSString *contact = @"";
- __block NSString *email = @"";
- __block NSString *fax = @"";
- __block NSString *phone = @"";
-
- sqlite3 *db = [iSalesDB get_db];
-
- [iSalesDB jk_query:ship_from_default_sql db:db close:NO completion:^(sqlite3_stmt *statment, NSMutableDictionary *container, long *count) {
-
- cid = [self textAtColumn:0 statement:statment];
- name = [self textAtColumn:1 statement:statment];
- ext = [self textAtColumn:2 statement:statment];
- contact = [self textAtColumn:3 statement:statment];
- email = [self textAtColumn:4 statement:statment];
- fax = [self textAtColumn:5 statement:statment];
- phone = [self textAtColumn:6 statement:statment];
-
- }];
-
-
-
-
-
-
- // default carrier
- NSString *carrier_sql = [NSString stringWithFormat:@"select name from carrier where code_id = (select carrier from offline_contact where contact_id = '%@');",customer_cid];
-
- __block NSString *carrier = @"";
-
- [iSalesDB jk_query:carrier_sql db:db close:NO completion:^(sqlite3_stmt *statment, NSMutableDictionary *container, long *count) {
-
- carrier = [self textAtColumn:0 statement:statment];
-
-
- }];
-
- NSString* so_id = [self get_offline_soid:db];
- if(so_id==nil)
- so_id=[NSString stringWithFormat:@"OFFLINE%@",[NSUUID UUID].UUIDString ];
-
- 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,must_call,sender_cid,sender_name,sender_ext,sender_contact,sender_phone,sender_fax,sender_email,billing_cid,billing_name,billing_ext,billing_contact,billing_phone,billing_fax,billing_email,sales_terms,carrier) values('%@',0,'%@','%@','%@','%@','%@','%@','%@','%@',1,'%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','FOB','%@')",so_id,customer_cid,customer_contact,customer_email,customer_fax,customer_phone,customer_sales_rep,create_by ,contact_name,cid,name,ext,contact,phone,fax,email,customer_cid,customer_name,customer_contact_ext,customer_contact,customer_phone,customer_fax,customer_email,carrier];
-
-
-
- int result_code =[iSalesDB execSql:sql_neworder db:db];
- [ret setValue:[NSNumber numberWithInt:result_code] 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];
- dispatch_async(dispatch_get_main_queue(), ^{
-
-
-
- result(ret);
- });
- });
- }
- +(void) offline_requestcart :(NSMutableDictionary *) params completionHandler:(resultHandler)result;
- {
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
-
- bool can_create_backorder= appDelegate.can_create_backorder;
- NSString* user = appDelegate.user;
- NSString* contact_id = appDelegate.contact_id;
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
- sqlite3 *db = [iSalesDB get_db];
-
-
-
- NSString* orderCode=params[@"orderCode"];
-
- int sort = [[params objectForKey:@"sort"] intValue];
- NSString *sort_str = @"";
- switch (sort) {
- case 0:{
- sort_str = @"order by c.modify_time desc";
- }
- break;
- case 1:{
- sort_str = @"order by c.modify_time asc";
- }
- break;
- case 2:{
- sort_str = @"order by m.name asc";
- }
- break;
- case 3:{
- sort_str = @"order by m.name desc";
- }
- break;
- case 4:{
- sort_str = @"order by m.description asc";
- }
- break;
-
- default:
- break;
-
- }
-
- NSString* sqlorder = [ NSString stringWithFormat:@"select discount from offline_order where so_id='%@'",orderCode];
- sqlite3_stmt * statement1;
-
-
-
-
-
-
- double orderdiscount=0;
- int dbresult1=sqlite3_prepare_v2(db, [sqlorder UTF8String], -1, &statement1, nil);
- if ( dbresult1== SQLITE_OK)
- {
-
-
- if (sqlite3_step(statement1) == SQLITE_ROW)
- {
- // NSDate *row_date = [NSDate date];
-
-
- NSMutableDictionary* itemjson = [[NSMutableDictionary alloc] init];
-
-
-
-
- orderdiscount = sqlite3_column_double(statement1, 0);
-
- }
-
- sqlite3_finalize(statement1);
- }
-
- 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,m.availability from (select _id,product_id,decrypt(str_price) as price,discount,item_count,line_note,item_id,modify_time from offline_cart where so_no='%@') c left join product m on c.product_id=m.product_id %@",orderCode,sort_str ];
-
-
- // 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"];
-
- NSDate *date1 = [NSDate date];
-
- int count=0;
- int cart_count=0;
- int dbresult=sqlite3_prepare_v2(db, [sqlQuery UTF8String], -1, &statement, nil);
- if ( dbresult== SQLITE_OK)
- {
-
-
- while (sqlite3_step(statement) == SQLITE_ROW)
- {
- // NSDate *row_date = [NSDate date];
-
-
- 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];
- // NSDate *price_date = [NSDate date];
- NSNumber* price = [self get_model_default_price:contact_id user:user product_id:nil item_id:@(item_id) db:db];
- // DebugLog(@"price time interval");
- // [self printTimeIntervalBetween:price_date and:[NSDate date]];
-
- 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);
- int availability = sqlite3_column_int(statement, 10);
-
- // NSDate *subtotal_date = [NSDate date];
- NSDictionary* bsubtotaljson=[self model_subtotal:item_id count:item_count db:db compute_part:true];
- // DebugLog(@"subtotal_date time interval");
- // [self printTimeIntervalBetween:subtotal_date and:[NSDate date]];
-
- double cuft=[bsubtotaljson[@"cuft"] doubleValue];
- double weight=[bsubtotaljson[@"weight"] doubleValue];
- int carton=[bsubtotaljson[@"carton"] intValue];
- cart_count+=[bsubtotaljson[@"items"] allKeys].count;
- int mpack =[bsubtotaljson[@"mpack"] intValue];
-
- // itemjson[@"img_url"]= [self model_category_img:[NSString stringWithFormat:@"%@",[NSNumber numberWithInt:item_id]] model_name:nil db:db];
- // NSDate *img_date = [NSDate date];
- itemjson[@"img_url"] = [self item_image:[NSString stringWithFormat:@"%@",[NSNumber numberWithInt:item_id]] db:db];
- // DebugLog(@"img_date time interval");
- // [self printTimeIntervalBetween:img_date and:[NSDate date]];
-
- 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[@"mpack"]=[NSNumber numberWithInt:mpack];
- itemjson[@"note"]=nsline_note;
- if (!can_create_backorder) {
- itemjson[@"is_out_of_stock"] = [NSNumber numberWithBool:availability >= item_count ? NO : YES];
- }
- // NSDate *date2 = [NSDate date];
- itemjson[@"combine"]=[self model_bundle:item_id db:db compute_part:false contactID:contact_id user:user];
- // DebugLog(@"model_bundle time interval");
- // [self printTimeIntervalBetween:date2 and:[NSDate date]];
-
- ret[[NSString stringWithFormat:@"item_%d",count]]=itemjson;
- count++;
-
- // DebugLog(@"row time interval");
- // [self printTimeIntervalBetween:row_date and:[NSDate date]];
- }
-
-
- ret[@"result"]=[NSNumber numberWithInt:RESULT_TRUE ];
- sqlite3_finalize(statement);
- }
-
-
- DebugLog(@"request cart total time interval");
- [self printTimeIntervalBetween:date1 and:[NSDate date]];
-
-
- //int cart_count=[iSalesDB get_recordcount:db table:@"offline_cart" where:[NSString stringWithFormat:@"so_no='%@'",orderCode]];
-
- int wish_count=[iSalesDB get_recordcount:db table:@"wishlist" where:@"is_delete is NULL or is_delete != 1"];
- ret[@"wish_count"]=[NSNumber numberWithInt:wish_count ];
- ret[@"cart_count"]=[NSNumber numberWithInt:cart_count ];
- ret[@"count"]=[NSNumber numberWithInt:count ];
-
-
- if(orderdiscount>0)
- ret[@"orderDiscount"]=@(orderdiscount);
- 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;
-
- dispatch_async(dispatch_get_main_queue(), ^{
- result(ret);
- });
- });
- }
- @end
|