CartViewController.m 247 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350
  1. //
  2. // CartViewController.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 14-6-6.
  6. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "RAUtils.h"
  9. #import "CartViewController.h"
  10. #import "ModelItemCell.h"
  11. #import "RANetwork.h"
  12. //#import "CommonGridViewController.h"
  13. #import "CreateOrderViewController.h"
  14. #import "DetailViewController.h"
  15. #import "EditModelPriceViewController.h"
  16. #import "MainViewController.h"
  17. #import "LoginViewController.h"
  18. #import "ItemNotesViewController.h"
  19. #import "CartGeneralNotesViewController.h"
  20. #import "DefaultAppearance.h"
  21. #import "DefaultTableHeaderView.h"
  22. #import "SortItemViewController.h"
  23. #import "SortButton.h"
  24. #import "NotificationNameCenter.h"
  25. #import "RASingleton.h"
  26. #import "JKMessageBoxController.h"
  27. #import "RAPDFViewController.h"
  28. #ifdef SCANNER_ORDER
  29. #import "ScanCartItemCell.h"
  30. #import "ScanDiscountViewController.h"
  31. #else
  32. #endif
  33. #ifdef BUILD_CONTRAST
  34. #import "OrderDiscountViewController.h"
  35. #endif
  36. #ifdef BACKORDER_PROCESS
  37. #import "RAOrderEditorViewController.h"
  38. #endif
  39. #import "CustomerEditViewController.h"
  40. //#define ALERT_FREE 1024
  41. //#define ALERT_DEL 1025
  42. //#define ALERT_SET_FREE 1026
  43. //#define ALERT_RESTORE_FREE 1027
  44. @interface CartViewController ()
  45. {
  46. CGRect cancelButtonFrame;
  47. }
  48. @property (nonatomic,strong) SortItemViewController *sortItemController;
  49. @property (nonatomic,assign) int sortIndex;
  50. @property (nonatomic,strong) SortButton *sortButton;
  51. @property (strong, nonatomic) IBOutlet UIButton *placeOrderButton;
  52. @property (strong, nonatomic) IBOutlet UIButton *cancelOrderButton;
  53. @property (nonatomic,strong) NSOperationQueue *dataOperationQueue;
  54. @property (strong, nonatomic) IBOutlet UIButton *emailButton;
  55. @property (strong, nonatomic) IBOutlet UIButton *printButton;
  56. @property (weak, nonatomic) IBOutlet UIButton *editButton;
  57. @property (weak, nonatomic) IBOutlet UIButton *continueButton;
  58. @property (weak, nonatomic) IBOutlet UILabel *labelTotalcuft;
  59. @property (weak, nonatomic) IBOutlet UILabel *labelTotalWeight;
  60. @property (weak, nonatomic) IBOutlet UILabel *labelTotalCarton;
  61. @property (weak, nonatomic) IBOutlet UILabel *valuecuft;
  62. @property (weak, nonatomic) IBOutlet UILabel *valueweight;
  63. @property (weak, nonatomic) IBOutlet UILabel *valuecarton;
  64. @property (nonatomic,assign) BOOL currentOrderIsMerged;
  65. @property (nonatomic,strong) DefaultTableHeaderView *cartIndicatorBar;
  66. @property (nonatomic,assign) BOOL back_order_flag;
  67. @property (nonatomic,strong) NSDictionary *cart_json;
  68. @property (nonatomic,copy) NSString *print_url;
  69. @property (nonatomic,assign) BOOL available;///<所有Model均有库存,才能Place Order。
  70. @end
  71. @implementation CartViewController
  72. - (NSOperationQueue *)dataOperationQueue {
  73. if (!_dataOperationQueue) {
  74. _dataOperationQueue = [[NSOperationQueue alloc] init];
  75. _dataOperationQueue.maxConcurrentOperationCount = 1;
  76. }
  77. return _dataOperationQueue;
  78. }
  79. - (void)dealloc {
  80. #ifndef RA_NOTIFICATION
  81. [[NSNotificationCenter defaultCenter] removeObserver:self];
  82. #endif
  83. }
  84. -(void) logout
  85. {
  86. [super logout];
  87. [self.content_arr removeAllObjects];
  88. [self refresh_ui];
  89. self.cart_json = nil;
  90. }
  91. - (IBAction)OnEditSelectClick:(id)sender {
  92. NSMutableArray* arr_ids = [[NSMutableArray alloc] init];
  93. long count = self.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  94. if(count==0)
  95. {
  96. [RAUtils message_alert:@"No item in the cart" title:@"Cart" controller:self] ;
  97. return;
  98. }
  99. for(int i=0;i<count;i++)
  100. {
  101. NSMutableDictionary * item_json = [self.content_arr[i] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  102. [arr_ids addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"cart_item_id"] intValue]]];
  103. }
  104. NSString * ids = [arr_ids componentsJoinedByString:@","];
  105. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Select all model and" message:nil preferredStyle:UIAlertControllerStyleAlert];
  106. //block代码块取代了delegate
  107. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Delete" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  108. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure remove all models from cart?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  109. //block代码块取代了delegate
  110. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  111. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Remove Models From Cart" completion:^{
  112. [RANetwork request_remove_cart:ids completionHandler:^(NSMutableDictionary *result) {
  113. NSMutableDictionary* cart_json =result;
  114. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  115. [waitalert dismissViewControllerAnimated:YES completion:^{
  116. if([[cart_json valueForKey:@"result"] intValue]==2)
  117. {
  118. [self end_edit];
  119. #ifdef RA_NOTIFICATION
  120. [ActiveViewController Notify:@"CartViewController,CategoryViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  121. #else
  122. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  123. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:true];
  124. [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:true];
  125. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  126. #endif
  127. }
  128. else
  129. {
  130. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
  131. }
  132. }];
  133. }];
  134. }];
  135. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  136. //
  137. // NSDictionary* cart_json = [RANetwork cart_remove:ids];
  138. //
  139. // dispatch_async(dispatch_get_main_queue(), ^{
  140. //
  141. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  142. //
  143. // if([[cart_json valueForKey:@"result"] intValue]==2)
  144. // {
  145. //
  146. // [self end_edit];
  147. //
  148. //
  149. //
  150. //#ifdef RA_NOTIFICATION
  151. // [ActiveViewController Notify:@"CartViewController,CategoryViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  152. //#else
  153. // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  154. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:true];
  155. // [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:true];
  156. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  157. //#endif
  158. // }
  159. // else
  160. // {
  161. // [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
  162. // }
  163. //
  164. //
  165. //
  166. // });
  167. // });
  168. }];
  169. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  170. DebugLog(@"No");
  171. }];
  172. [alertControl addAction:actionOne];
  173. [alertControl addAction:alertthree];
  174. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  175. [self presentViewController:alertControl animated:YES completion:nil];
  176. DebugLog(@"%@",self.edit_select_arr);
  177. }];
  178. UIAlertAction *actionTwo = [UIAlertAction actionWithTitle:@"Move To Wish List" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  179. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Move Models To Wish List" completion:^{
  180. [RANetwork request_move_cart2wish:ids completionHandler:^(NSMutableDictionary *result) {
  181. NSDictionary* cart_json =result;
  182. [waitalert dismissViewControllerAnimated:YES completion:^{
  183. if([[cart_json valueForKey:@"result"] intValue]==2)
  184. {
  185. #ifdef RA_NOTIFICATION
  186. [ActiveViewController Notify:@"WatchListViewController,CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  187. #else
  188. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  189. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  190. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:true];
  191. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  192. #endif
  193. [self end_edit];
  194. }
  195. else
  196. {
  197. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Move Models To Wish List" controller:self] ;
  198. }
  199. }];
  200. }];
  201. }];
  202. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  203. //
  204. // NSDictionary* cart_json = [RANetwork move_cart2wish:ids];
  205. //
  206. // dispatch_async(dispatch_get_main_queue(), ^{
  207. //
  208. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  209. //
  210. // if([[cart_json valueForKey:@"result"] intValue]==2)
  211. // {
  212. //
  213. //
  214. //
  215. //
  216. //#ifdef RA_NOTIFICATION
  217. // [ActiveViewController Notify:@"WatchListViewController,CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  218. //#else
  219. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  220. // [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  221. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:true];
  222. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  223. //#endif
  224. //
  225. //
  226. // [self end_edit];
  227. // }
  228. // else
  229. // {
  230. // [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Move Models To Wish List" controller:self] ;
  231. // }
  232. //
  233. //
  234. //
  235. // });
  236. // });
  237. }];
  238. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  239. DebugLog(@"No");
  240. }];
  241. [alertControl addAction:actionOne];
  242. [alertControl addAction:actionTwo];
  243. [alertControl addAction:alertthree];
  244. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  245. [self presentViewController:alertControl animated:YES completion:nil];
  246. DebugLog(@"%@",self.edit_select_arr);
  247. }
  248. - (IBAction)onEditAddWishClick:(id)sender {
  249. if(self.edit_select_arr.count==0)
  250. {
  251. [RAUtils message_alert:@"You must select at least one model." title:@"Cannot Move To Wish List" controller:self] ;
  252. return;
  253. }
  254. NSString * ids = [self.edit_select_arr componentsJoinedByString:@","];
  255. // UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure remove selected models from cart?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  256. // //block代码块取代了delegate
  257. //
  258. //
  259. //
  260. // UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  261. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Move Models To Wish List" completion:^{
  262. [RANetwork request_move_cart2wish:ids completionHandler:^(NSMutableDictionary *result) {
  263. NSDictionary* cart_json = result;
  264. [waitalert dismissViewControllerAnimated:YES completion:^{
  265. if([[cart_json valueForKey:@"result"] intValue]==2)
  266. {
  267. [self end_edit];
  268. #ifdef RA_NOTIFICATION
  269. [ActiveViewController Notify:@"WatchListViewController,CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  270. #else
  271. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  272. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  273. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:true];
  274. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  275. #endif
  276. }
  277. else
  278. {
  279. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Move To Wish List" controller:self] ;
  280. }
  281. }];
  282. }];
  283. }];
  284. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  285. //
  286. // NSDictionary* cart_json = [RANetwork move_cart2wish:ids];
  287. //
  288. // dispatch_async(dispatch_get_main_queue(), ^{
  289. //
  290. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  291. //
  292. // if([[cart_json valueForKey:@"result"] intValue]==2)
  293. // {
  294. //
  295. // [self end_edit];
  296. //
  297. //#ifdef RA_NOTIFICATION
  298. // [ActiveViewController Notify:@"WatchListViewController,CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  299. //#else
  300. // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  301. // [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  302. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:true];
  303. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  304. //#endif
  305. //
  306. // }
  307. // else
  308. // {
  309. // [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Move To Wish List" controller:self] ;
  310. // }
  311. //
  312. //
  313. //
  314. // });
  315. // });
  316. // }];
  317. // UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  318. // DebugLog(@"No");
  319. // }];
  320. // [alertControl addAction:actionOne];
  321. //
  322. // [alertControl addAction:alertthree];
  323. //
  324. // //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  325. //
  326. //
  327. // [self presentViewController:alertControl animated:YES completion:nil];
  328. //
  329. // DebugLog(@"%@",self.edit_select_arr);
  330. }
  331. - (IBAction)onEditDelClick:(id)sender {
  332. if(self.edit_select_arr.count==0)
  333. {
  334. [RAUtils message_alert:@"You must select at least one model." title:@"Cannot Delete From Cart" controller:self] ;
  335. return;
  336. }
  337. NSString * ids = [self.edit_select_arr componentsJoinedByString:@","];
  338. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure remove selected models from cart?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  339. //block代码块取代了delegate
  340. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  341. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Remove Models From Cart" completion:^{
  342. [RANetwork request_remove_cart:ids completionHandler:^(NSMutableDictionary *result) {
  343. NSMutableDictionary* cart_json =result;
  344. [waitalert dismissViewControllerAnimated:YES completion:^{
  345. if([[cart_json valueForKey:@"result"] intValue]==2)
  346. {
  347. [self end_edit];
  348. #ifdef RA_NOTIFICATION
  349. [ActiveViewController Notify:@"CartViewController,CategoryViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  350. #else
  351. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  352. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:true];
  353. [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:true];
  354. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  355. #endif
  356. }
  357. else
  358. {
  359. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
  360. }
  361. }];
  362. }];
  363. }];
  364. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  365. //
  366. // NSDictionary* cart_json = [RANetwork cart_remove:ids];
  367. //
  368. // dispatch_async(dispatch_get_main_queue(), ^{
  369. //
  370. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  371. //
  372. // if([[cart_json valueForKey:@"result"] intValue]==2)
  373. // {
  374. //
  375. // [self end_edit];
  376. //
  377. //
  378. //#ifdef RA_NOTIFICATION
  379. // [ActiveViewController Notify:@"CartViewController,CategoryViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  380. //#else
  381. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  382. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:true];
  383. // [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:true];
  384. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  385. //#endif
  386. // }
  387. // else
  388. // {
  389. // [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
  390. // }
  391. //
  392. //
  393. //
  394. // });
  395. // });
  396. }];
  397. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  398. DebugLog(@"No");
  399. }];
  400. [alertControl addAction:actionOne];
  401. [alertControl addAction:alertthree];
  402. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  403. [self presentViewController:alertControl animated:YES completion:nil];
  404. DebugLog(@"%@",self.edit_select_arr);
  405. }
  406. - (IBAction)onEndEditClick:(id)sender {
  407. [self end_edit];
  408. }
  409. -(void)begin_edit
  410. {
  411. self.toolpanel.hidden = true;
  412. self.toolbar.hidden = false;
  413. // DebugLog(@"begin edit %@",NSStringFromCGRect(self.cartItemView.frame));
  414. UIInterfaceOrientation orientation = [[UIApplication sharedApplication]statusBarOrientation];
  415. if ( UIInterfaceOrientationIsPortrait(orientation))
  416. self.cartItemView.frame = CGRectMake(0,40,768,840);
  417. else
  418. self.cartItemView.frame = CGRectMake(0,40,1024,584);
  419. [self.itemListTable setEditing:true animated:YES];
  420. [self.itemListTable reloadData];
  421. }
  422. -(void) end_edit
  423. {
  424. self.toolpanel.hidden=false;
  425. self.toolbar.hidden=true;
  426. // DebugLog(@"end edit %@",NSStringFromCGRect(self.cartItemView.frame));
  427. UIInterfaceOrientation orientation = [[UIApplication sharedApplication]statusBarOrientation];
  428. if ( UIInterfaceOrientationIsPortrait(orientation))
  429. self.cartItemView.frame = CGRectMake(0,40,768,760);
  430. else
  431. self.cartItemView.frame = CGRectMake(0,40,1024,508);
  432. [self.itemListTable setEditing:false animated:YES];
  433. [self.edit_select_arr removeAllObjects];
  434. [self.itemListTable reloadData];
  435. // [self reload_data];
  436. }
  437. - (IBAction)onEditClick:(id)sender {
  438. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  439. //
  440. // [appDelegate test_onDecodedDataResult:@"4400022"];
  441. //
  442. //
  443. // return;
  444. [self begin_edit];
  445. }
  446. #ifndef RA_NOTIFICATION
  447. -(void) reload_container_getdata:(bool) update_data
  448. {
  449. [super reload_container_getdata:update_data];
  450. if(update_data)
  451. [self reload_data];
  452. else
  453. {
  454. [self.itemListTable reloadData];
  455. [self refresh_total];
  456. }
  457. }
  458. #endif
  459. -(void) showHidePrice
  460. {
  461. #ifndef RA_NOTIFICATION
  462. [self reload_container_getdata:false];
  463. #endif
  464. // [self refresh_total];
  465. }
  466. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  467. {
  468. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  469. if (self) {
  470. // Custom initialization
  471. }
  472. return self;
  473. }
  474. - (IBAction)imgbtnClick:(UIButton *)sender {
  475. #ifdef SCANNER_ORDER
  476. return;
  477. #endif
  478. UITableViewCell* cell =(UITableViewCell*) sender.superview.superview;
  479. NSIndexPath * indexPath = [self.itemListTable indexPathForCell:cell];
  480. // DebugLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
  481. NSDictionary * item_json = nil;
  482. if (self.back_order_flag) {
  483. item_json = [self itemJsonAtIndexPath:indexPath];
  484. } else {
  485. item_json = self.content_arr[indexPath.row];//[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  486. }
  487. NSString* product_id = [item_json valueForKey:@"product_id"];
  488. NSString *name = [item_json valueForKey:@"model"];
  489. int is_rate = [item_json[@"is_rate"] intValue];
  490. if(is_rate==1)
  491. return;
  492. DetailViewController* dvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Model" bundle:nil] instantiateViewControllerWithIdentifier:@"DetailViewController" ];
  493. // dvc
  494. dvc.product_id=product_id;
  495. dvc.category_id=nil;
  496. dvc.ispush=true;
  497. dvc.model_name = name;
  498. [dvc reload];
  499. [self.navigationController pushViewController:dvc animated:true];
  500. }
  501. -(void)viewWillLayoutSubviews
  502. {
  503. // if(self.showDetail==true)
  504. // {
  505. // UIInterfaceOrientation orientation =[UIApplication sharedApplication].statusBarOrientation;
  506. // int width=175;
  507. // // int height;
  508. // if(orientation == UIDeviceOrientationLandscapeLeft ||orientation == UIDeviceOrientationLandscapeRight)
  509. // {
  510. // width = 370;
  511. // // height = 400;
  512. // }
  513. // else
  514. // {
  515. // // height = 300;
  516. // width = 175;
  517. // }
  518. //
  519. //
  520. // CGRect frame = CGRectMake(0, 64, width, self.view.bounds.size.height-64);
  521. //
  522. // self.collectionview.frame=frame;
  523. //
  524. //
  525. //
  526. // CGRect framedetail = CGRectMake(width,64 ,self.view.bounds.size.width-width,self.view.bounds.size.height-64);
  527. // self.detailView.frame = framedetail;
  528. // }
  529. self.toolpanel.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.toolpanel.bounds].CGPath;
  530. // self.collectionview.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.collectionview.bounds].CGPath;
  531. }
  532. - (void)viewWillAppear:(BOOL)animated
  533. {
  534. [super viewWillAppear:animated];
  535. // print 13 email 19 cancel 24 place order
  536. // Shop 权限检查
  537. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  538. if (appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  539. if (![RASingleton sharedInstance].permissions_edit_order) {
  540. CGRect frame0 = self.cancelOrderButton.frame;
  541. CGRect frame1 = self.placeOrderButton.frame;
  542. CGRect frame2 = self.emailButton.frame;
  543. CGRect frame3 = self.printButton.frame;
  544. CGFloat x = CGRectGetMaxX(frame1) - frame0.size.width;
  545. frame0.origin.x = x;
  546. self.cancelOrderButton.frame = frame0;
  547. x -= 20 + CGRectGetWidth(frame2);
  548. frame2.origin.x = x;
  549. self.emailButton.frame = frame2;
  550. x -= 20 + CGRectGetWidth(frame3);
  551. frame3.origin.x = x;
  552. self.printButton.frame = frame3;
  553. self.placeOrderButton.hidden = YES;
  554. } else {
  555. self.placeOrderButton.hidden = NO;
  556. CGSize size = cancelButtonFrame.size;
  557. CGFloat x = CGRectGetMinX(self.placeOrderButton.frame) - 24 - size.width;
  558. CGFloat y = CGRectGetMinY(self.placeOrderButton.frame);
  559. self.cancelOrderButton.frame = CGRectMake(x, y, size.width, size.height);
  560. CGRect frame2 = self.emailButton.frame;
  561. x -= 20 + CGRectGetWidth(frame2);
  562. frame2.origin.x = x;
  563. self.emailButton.frame = frame2;
  564. CGRect frame3 = self.printButton.frame;
  565. x -= 20 + CGRectGetWidth(frame3);
  566. frame3.origin.x = x;
  567. self.printButton.frame = frame3;
  568. }
  569. } else {
  570. // self.cancelOrderButton.frame = cancelButtonFrame;
  571. self.placeOrderButton.hidden = NO;
  572. CGSize size = cancelButtonFrame.size;
  573. CGFloat x = CGRectGetMinX(self.placeOrderButton.frame) - 24 - size.width;
  574. CGFloat y = CGRectGetMinY(self.placeOrderButton.frame);
  575. self.cancelOrderButton.frame = CGRectMake(x, y, size.width, size.height);
  576. CGRect frame2 = self.emailButton.frame;
  577. x -= 20 + CGRectGetWidth(frame2);
  578. frame2.origin.x = x;
  579. self.emailButton.frame = frame2;
  580. CGRect frame3 = self.printButton.frame;
  581. x -= 20 + CGRectGetWidth(frame3);
  582. frame3.origin.x = x;
  583. self.printButton.frame = frame3;
  584. }
  585. #ifdef OFFLINE_MODE
  586. // 离线隐藏Email
  587. self.emailButton.hidden = appDelegate.offline_mode;
  588. // 离线隐藏Print
  589. self.printButton.hidden = appDelegate.offline_mode;
  590. #endif
  591. [[self navigationController] setNavigationBarHidden:YES animated:NO];
  592. #ifdef SCANNER_ORDER
  593. if(appDelegate.user_type == USER_ROLE_EMPLOYEE)
  594. {
  595. self.btnBulkDiscount.hidden = false;
  596. }
  597. else
  598. self.btnBulkDiscount.hidden = true;
  599. #endif
  600. }
  601. - (void)checkProductAvailable:(NSArray *)contents {
  602. if (contents == nil) {
  603. self.available = NO;
  604. return;
  605. }
  606. [contents enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  607. if ([obj isKindOfClass:[NSDictionary class]]) {
  608. NSDictionary *item_json = (NSDictionary *)obj;
  609. BOOL isAvailable = ![[item_json valueForKey:@"is_out_of_stock"] boolValue];
  610. self.available = self.available && isAvailable;
  611. }
  612. }];
  613. }
  614. - (void)clearContent {
  615. dispatch_async(dispatch_get_main_queue(), ^{
  616. self.freejson = nil;
  617. self.notes = nil;
  618. self.content_arr = nil;
  619. self.currentOrderIsMerged = nil;
  620. self.cart_json = nil;
  621. [RASingleton sharedInstance].currentOrderIsMerged = NO;
  622. self.print_url = nil;
  623. [self checkProductAvailable:self.content_arr];
  624. [self refresh_total];
  625. [self.itemListTable reloadData];
  626. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  627. appDelegate.cart_count = 0;
  628. [appDelegate update_count_mark];
  629. });
  630. }
  631. -(void) operation_reload_data
  632. {
  633. if (self.dataOperationQueue.operationCount > 1) {
  634. return;
  635. }
  636. __block AppDelegate *appDelegate = nil;
  637. dispatch_sync(dispatch_get_main_queue(), ^{
  638. //some UI methods ej
  639. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  640. });
  641. // AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  642. #ifndef SCANNER_ORDER
  643. //扫码订单允许后建订单
  644. if (appDelegate.order_code == nil || appDelegate.order_code.length == 0) {
  645. [self clearContent];
  646. return;
  647. }
  648. #endif
  649. __weak typeof(self) weakself = self;
  650. dispatch_async(dispatch_get_main_queue(), ^{
  651. if(weakself.isrefreshing)
  652. return;
  653. weakself.available = YES;
  654. weakself.itemListTable.hidden = true;
  655. weakself.label_net_err.hidden=true;
  656. weakself.isrefreshing=true;
  657. // [self.content_data removeAllObjects];
  658. // [self.itemListTable reloadData];
  659. // UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  660. //
  661. // [reF endRefreshing];
  662. //
  663. // reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  664. weakself.mum.center = weakself.view.center;
  665. weakself.mum.hidden = YES;
  666. // [self.mum startAnimating];
  667. DebugLog(@"reloading...");
  668. __block UIAlertController *loadingView = [RAUtils waiting_alert:self title:@"Loading" completion:^{
  669. [RANetwork request_cart:weakself.sortIndex completionHandler:^(NSMutableDictionary *result) {
  670. DebugLog(@"BEGIN LOAD CART");
  671. NSDictionary* cart_json = result;
  672. //
  673. // [self.mum stopAnimating];
  674. [loadingView dismissViewControllerAnimated:YES completion:^{
  675. // [loadingView dismissWithClickedButtonIndex:0 animated:YES];
  676. // self.content_data = [cart_json mutableCopy];
  677. #ifdef BACKORDER_PROCESS
  678. weakself.back_order_flag = [[cart_json objectForKey:@"back_order_version"] boolValue];
  679. #else
  680. weakself.back_order_flag = NO;
  681. #endif
  682. if (!weakself.back_order_flag) {
  683. weakself.freejson = [cart_json objectForKey:@"freeGiveaway"];
  684. weakself.notes = [cart_json valueForKey:@"general_note"];
  685. weakself.content_arr = [RAUtils dictionary2array:cart_json count_fields:@"count" item_mark:@"item_" items_mark:nil];
  686. weakself.currentOrderIsMerged = [[cart_json valueForKey:@"is_merged_order"] boolValue];
  687. [RASingleton sharedInstance].currentOrderIsMerged = weakself.currentOrderIsMerged;
  688. [weakself.itemListTable reloadData];
  689. weakself.print_url = [cart_json valueForKey:@"cart_print_url"];
  690. [weakself checkProductAvailable:weakself.content_arr];
  691. [weakself refresh_total];
  692. } else {
  693. // v1.94
  694. weakself.freejson = [cart_json objectForKey:@"freeGiveaway"];
  695. weakself.notes = [cart_json valueForKey:@"general_note"];
  696. weakself.cart_json = cart_json;
  697. [weakself.itemListTable reloadData];
  698. weakself.print_url = [cart_json valueForKey:@"cart_print_url"];
  699. [weakself checkProductAvailable:weakself.content_arr];
  700. }
  701. int result_code=[[cart_json valueForKey:@"result"] intValue];
  702. if (weakself.dataOperationQueue.operationCount > 1) {
  703. weakself.isrefreshing=false;
  704. return;
  705. }
  706. if(result_code==2||result_code==1||result_code==0)
  707. {
  708. [weakself.edit_select_arr removeAllObjects];
  709. weakself.itemListTable.hidden = false;
  710. // UIApplication * app = [UIApplication sharedApplication];
  711. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  712. // appDelegate.cart_count =weakself.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  713. weakself.itemListTable.hidden=false;
  714. if(weakself.onFinishLoad)
  715. weakself.onFinishLoad();
  716. }
  717. else
  718. if(result_code==RESULT_NET_ERROR)
  719. {
  720. weakself.label_net_err.hidden=false;
  721. weakself.itemListTable.hidden=true;
  722. }
  723. else
  724. {
  725. if(result_code!=1)
  726. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Loading Cart" controller:weakself] ;
  727. }
  728. weakself.isrefreshing=false;
  729. DebugLog(@"FINISH LOAD CART");
  730. }];
  731. }];
  732. }];
  733. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  734. // DebugLog(@"BEGIN LOAD CART");
  735. // NSDictionary* cart_json = [RANetwork request_Cart:weakself.sortIndex];
  736. //
  737. // dispatch_async(dispatch_get_main_queue(), ^{
  738. // //
  739. //// [self.mum stopAnimating];
  740. // [loadingView dismissWithClickedButtonIndex:0 animated:YES];
  741. //
  742. // // self.content_data = [cart_json mutableCopy];
  743. //#ifdef BACKORDER_PROCESS
  744. // weakself.back_order_flag = [[cart_json objectForKey:@"back_order_version"] boolValue];
  745. //#else
  746. // weakself.back_order_flag = NO;
  747. //#endif
  748. //
  749. // if (!weakself.back_order_flag) {
  750. // weakself.freejson = [cart_json objectForKey:@"freeGiveaway"];
  751. // weakself.notes = [cart_json valueForKey:@"general_note"];
  752. // weakself.content_arr = [RAUtils dictionary2array:cart_json count_fields:@"count" item_mark:@"item_" items_mark:nil];
  753. // weakself.currentOrderIsMerged = [[cart_json valueForKey:@"is_merged_order"] boolValue];
  754. // [Singleton sharedInstance].currentOrderIsMerged = weakself.currentOrderIsMerged;
  755. // [weakself.itemListTable reloadData];
  756. // weakself.print_url = [cart_json valueForKey:@"cart_print_url"];
  757. //
  758. //
  759. // [weakself checkProductAvailable:weakself.content_arr];
  760. //
  761. //
  762. // [weakself refresh_total];
  763. // } else {
  764. // // v1.94
  765. // weakself.freejson = [cart_json objectForKey:@"freeGiveaway"];
  766. // weakself.notes = [cart_json valueForKey:@"general_note"];
  767. // weakself.cart_json = cart_json;
  768. // [weakself.itemListTable reloadData];
  769. // weakself.print_url = [cart_json valueForKey:@"cart_print_url"];
  770. // [weakself checkProductAvailable:weakself.content_arr];
  771. // }
  772. //
  773. // int result=[[cart_json valueForKey:@"result"] intValue];
  774. //
  775. // if (weakself.dataOperationQueue.operationCount > 1) {
  776. // weakself.isrefreshing=false;
  777. // return;
  778. // }
  779. //
  780. // if(result==2||result==1||result==0)
  781. // {
  782. //
  783. // [weakself.edit_select_arr removeAllObjects];
  784. //
  785. // weakself.itemListTable.hidden = false;
  786. //// UIApplication * app = [UIApplication sharedApplication];
  787. //// AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  788. //// appDelegate.cart_count =weakself.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  789. // weakself.itemListTable.hidden=false;
  790. // if(weakself.onFinishLoad)
  791. // weakself.onFinishLoad();
  792. // }
  793. // else
  794. // if(result==RESULT_NET_ERROR)
  795. // {
  796. // weakself.label_net_err.hidden=false;
  797. // weakself.itemListTable.hidden=true;
  798. // }
  799. // else
  800. // {
  801. // if(result!=1)
  802. // [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Loading Cart" controller:weakself] ;
  803. // }
  804. //
  805. // weakself.isrefreshing=false;
  806. // DebugLog(@"FINISH LOAD CART");
  807. //
  808. // });
  809. // });
  810. });
  811. // [[self navigationController] setNavigationBarHidden:YES animated:NO];
  812. }
  813. -(void)manually_refresh
  814. {
  815. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  816. if(self.isrefreshing)
  817. {
  818. [reF endRefreshing];
  819. return;
  820. }
  821. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing"];
  822. [self performSelector:@selector(ReloadData) withObject:nil afterDelay:1];
  823. // DebugLog(@"refresh!!!!!!!!");
  824. }
  825. -(void) ReloadData
  826. {
  827. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  828. [reF endRefreshing];
  829. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  830. [self reload_data];
  831. }
  832. - (void)viewDidLayoutSubviews {
  833. [super viewDidLayoutSubviews];
  834. [self layoutCartIndicatorBar];
  835. }
  836. - (DefaultTableHeaderView *)setupCartIndicatorBar {
  837. NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
  838. if(value==nil)
  839. value=@"";
  840. unsigned long color = strtoul([value UTF8String],0,16);
  841. DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 40)];
  842. // myView.backgroundColor = UIColorFromRGB(0x996633);
  843. myView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  844. myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath;
  845. myView.layer.shadowColor = [UIColor blackColor].CGColor;
  846. myView.layer.shadowOffset = CGSizeMake(0, 0);
  847. myView.layer.shadowOpacity = 0.5;
  848. myView.layer.shadowRadius = 2.0;
  849. #ifndef SCANNER_ORDER
  850. self.sortButton.tag = 5678 + 0;
  851. [myView addSubview:self.sortButton];
  852. #endif
  853. UILabel *solabel = [[UILabel alloc] initWithFrame:CGRectMake(130, 9, 90, 22)];
  854. solabel.tag = 5678 + 1;
  855. solabel.textColor=UIColorFromRGB(color);
  856. solabel.backgroundColor = [UIColor clearColor];
  857. solabel.autoresizingMask=UIViewAutoresizingFlexibleRightMargin;
  858. solabel.text=NSLocalizedString(@"Description", nil);
  859. [solabel sizeToFit];
  860. [myView addSubview:solabel];
  861. CGFloat x = self.itemListTable.bounds.size.width - (768 - 320);
  862. UILabel *contactlabel = [[UILabel alloc] initWithFrame:CGRectMake(x, 9, 90, 22)];
  863. contactlabel.tag = 5678 + 2;
  864. contactlabel.textColor=UIColorFromRGB(color);
  865. contactlabel.autoresizingMask=UIViewAutoresizingFlexibleRightMargin;
  866. contactlabel.backgroundColor = [UIColor clearColor];
  867. #ifdef SCANNER_ORDER
  868. NSString* pricename;
  869. NSDictionary *addressDic = [[NSUserDefaults standardUserDefaults] valueForKey:@"ScanAddress"];
  870. NSString* servername = [addressDic objectForKey:@"show_name"];
  871. NSArray* arrsn = [RAConvertor string2arr:servername separator:@","];
  872. NSString * shortname = arrsn[0];
  873. if(shortname.length==0)
  874. shortname = servername;
  875. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  876. NSDictionary* price_group = [RADataProvider get_price_group:appDelegate.price_group];
  877. // self.labelPrice0.text = price_group[@"price_0"][@"display"];//appDelegate.price0_name;
  878. // self.labelPrice1.text = price_group[@"price_1"][@"display"];//appDelegate.price1_name;
  879. switch(RASingleton.sharedInstance.price_type)
  880. {
  881. case 0:
  882. // pricename =[NSString stringWithFormat:@"%@_DDP",shortname];
  883. pricename = price_group[@"price_0"][@"display"];
  884. break;;
  885. case 1:
  886. // pricename = [NSString stringWithFormat:@"%@_WHSE",shortname];;
  887. pricename=price_group[@"price_1"][@"display"];//@"WHSE";
  888. break;;
  889. // case 2: pricename = @"25%";
  890. // break;
  891. }
  892. contactlabel.text=pricename;
  893. // contactlabel.frame= CGRectMake(x-100, 9, 90, 22);
  894. // contactlabel.tran
  895. #else
  896. contactlabel.text=NSLocalizedString(@"Unit price", nil);
  897. #endif
  898. [contactlabel sizeToFit];
  899. [myView addSubview:contactlabel];
  900. x = self.itemListTable.bounds.size.width - (768 - 470);
  901. UILabel *modellabel = [[UILabel alloc] initWithFrame:CGRectMake(x, 9, 90, 22)];
  902. modellabel.tag = 5678 + 3;
  903. modellabel.textColor=UIColorFromRGB(color);
  904. modellabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  905. modellabel.backgroundColor = [UIColor clearColor];
  906. modellabel.text=NSLocalizedString(@"Discount/QTY", nil);
  907. [modellabel sizeToFit];
  908. [myView addSubview:modellabel];
  909. x = self.itemListTable.bounds.size.width - (768 - 640);
  910. UILabel *pricelabel = [[UILabel alloc] initWithFrame:CGRectMake(x, 9, 90, 22)];
  911. pricelabel.tag = 5678 + 4;
  912. pricelabel.textColor=UIColorFromRGB(color);
  913. pricelabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  914. pricelabel.backgroundColor = [UIColor clearColor];
  915. pricelabel.text=NSLocalizedString(@"Set/Subtotal", nil);
  916. [pricelabel sizeToFit];
  917. [myView addSubview:pricelabel];
  918. return myView;
  919. }
  920. - (void)layoutCartIndicatorBar {
  921. CGFloat x = self.itemListTable.bounds.size.width - (768 - 320);
  922. UILabel *solabel = [self.cartIndicatorBar viewWithTag:5678 + 1];
  923. [solabel sizeToFit];
  924. UILabel *contactlabel = [self.cartIndicatorBar viewWithTag:5678 + 2];
  925. contactlabel.frame = CGRectMake(x, 9, 90, 22);
  926. [contactlabel sizeToFit];
  927. x = self.itemListTable.bounds.size.width - (768 - 470);
  928. UILabel *modellabel = [self.cartIndicatorBar viewWithTag:5678 + 3];
  929. modellabel.frame = CGRectMake(x, 9, 90, 22);
  930. [modellabel sizeToFit];
  931. x = self.itemListTable.bounds.size.width - (768 - 640);
  932. UILabel *pricelabel = [self.cartIndicatorBar viewWithTag:5678 + 4];
  933. pricelabel.frame = CGRectMake(x, 9, 90, 22);
  934. [pricelabel sizeToFit];
  935. }
  936. - (void)viewDidLoad
  937. {
  938. [super viewDidLoad];
  939. #ifdef BUILD_CONTRAST
  940. self.btnOrderDiscount.hidden=false;
  941. #endif
  942. #ifdef SCANNER_ORDER
  943. self.printButton.hidden = true;
  944. self.emailButton.hidden = true;
  945. self.editButton.hidden = true;
  946. self.continueButton.hidden = true;
  947. self.labelTotalcuft.hidden = false;
  948. self.labelTotalWeight.hidden = true;
  949. self.labelTotalCarton.hidden = true;
  950. self.valuecuft.hidden = false;
  951. self.valueweight.hidden = true;
  952. self.valuecarton.hidden = true;
  953. #endif
  954. #ifdef RA_NOTIFICATION
  955. self.support_scanner = true;
  956. #endif
  957. self.edit_select_arr= [[NSMutableArray alloc] init];
  958. self.label_net_err.layer.borderColor = [UIColor darkGrayColor].CGColor;
  959. self.label_net_err.layer.borderWidth = 2.0;
  960. self.label_net_err.layer.cornerRadius=15;
  961. self.label_net_err.layer.masksToBounds=true;
  962. #ifdef SCANNER_ORDER
  963. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(cartrefresh:) name:@"RA_NOTIFICATION_CART_REFRESH" object:nil];
  964. #endif
  965. #ifndef RA_NOTIFICATION
  966. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(priceTypeChanged:) name:Change_Price_Type_Notification object:nil];
  967. #endif
  968. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(refresh_btn_click:)];
  969. // tap.minimumPressDuration = 0.8; //定义按的时间
  970. [self.label_net_err addGestureRecognizer:tap];
  971. UIRefreshControl *ref = [[UIRefreshControl alloc]init];
  972. ref.tag = 200 ;
  973. ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  974. ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  975. // ref.hidden = true;
  976. [ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged];
  977. [self.itemListTable addSubview:ref];
  978. self.sortIndex = 0;
  979. self.currentOrderIsMerged = NO;
  980. self.toolpanel.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.toolpanel.bounds].CGPath;
  981. self.toolpanel.layer.masksToBounds = false;
  982. //添加四个边阴影
  983. self.toolpanel.layer.shadowColor = [UIColor blackColor].CGColor;
  984. self.toolpanel.layer.shadowOffset = CGSizeMake(0, 0);
  985. self.toolpanel.layer.shadowOpacity = 0.5;
  986. self.toolpanel.layer.shadowRadius = 2.0;
  987. cancelButtonFrame = self.cancelOrderButton.frame;
  988. // CGRect frame =self.orderInfoTableView.tableHeaderView.frame;
  989. // self.orderInfoTableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.orderInfoTableView.bounds.size.width, 0.0001)];
  990. // self.orderInfoTableView.tableHeaderView.backgroundColor = [UIColor redColor];
  991. // // self.detailTable.sectionHeaderHeight = 0.0001;
  992. // self.orderInfoTableView.sectionFooterHeight = 0.0001;
  993. // Do any additional setup after loading the view.
  994. self.cartIndicatorBar = [self setupCartIndicatorBar];
  995. [self.view addSubview:self.cartIndicatorBar];
  996. }
  997. -(void) cartrefresh: (NSNotification *)notification
  998. {
  999. [OLDataProvider scanRefreshCart];
  1000. [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1001. // [self refresh_total];
  1002. // [self refresh_ui];
  1003. }
  1004. //-(void)SelectOrder:(NSString *)orderid
  1005. //{
  1006. //// self.editOrderID.text=orderid;
  1007. //// self.btnAddToOrder.enabled = true;
  1008. //}
  1009. - (void)didReceiveMemoryWarning
  1010. {
  1011. [super didReceiveMemoryWarning];
  1012. // Dispose of any resources that can be recreated.
  1013. }
  1014. //- (IBAction)stepperAction:(UIStepper *)sender {
  1015. //
  1016. //
  1017. //}
  1018. - (IBAction)onContinueShoppingClick:(id)sender {
  1019. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1020. [appDelegate switchToPreviousVC];
  1021. }
  1022. - (IBAction)onOrderDiscount:(id)sender {
  1023. #ifdef BUILD_CONTRAST
  1024. OrderDiscountViewController * vc =[[UIStoryboard storyboardWithName:@"ERP_Mobile_Cart" bundle:nil] instantiateViewControllerWithIdentifier:@"OrderDiscountViewController"];
  1025. // vc.discount=[[item_json valueForKey:@"discount"] floatValue];
  1026. // vc.price = [[item_json valueForKey:@"unit_price"] floatValue];
  1027. // vc.cart_id = [item_json valueForKey:@"cart_item_id"];//[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  1028. // __block NSString* cartid=[item_json valueForKey:@"cart_item_id"];
  1029. // vc.delegate = parentvc.self;
  1030. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1031. vc.onSetValue = ^(double discount){
  1032. // bool bmodify=false;
  1033. // if(discount>0)
  1034. // bmodify=true;
  1035. // NSString* notes = [item_json valueForKey:@"note"];
  1036. // if(notes.length==0)
  1037. // notes=@"";
  1038. // if(bmodify)
  1039. // {
  1040. //
  1041. //
  1042. // // if([notes isEqualToString:@""])
  1043. //// notes=[NSString stringWithFormat:@"Note: discount %d%% off.",(int)discount];
  1044. ////
  1045. //// NSRange range;
  1046. //// range = [notes rangeOfString:@"PRICE MODIFIED"];
  1047. //// if (range.location != NSNotFound) {
  1048. ////
  1049. //// }else{
  1050. //// notes= [notes stringByAppendingString:@"\nPRICE MODIFIED"];
  1051. //// }
  1052. // }
  1053. // else
  1054. //
  1055. // {
  1056. //// notes =@"";
  1057. // }
  1058. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Update Discount" completion:^{
  1059. [RANetwork request_order_discount:discount completionHandler:^(NSMutableDictionary *result) {
  1060. [waitalert dismissViewControllerAnimated:YES completion:^{
  1061. int iresult = [result[@"result"] intValue];
  1062. if(iresult==RESULT_TRUE)
  1063. {
  1064. [self reload_data];
  1065. }
  1066. else
  1067. {
  1068. [RAUtils message_alert:@"Can't set order discount, please contact administrator" title:@"Set Order Discount" controller:self];
  1069. }
  1070. // if([[cart_json valueForKey:@"result"] intValue]==2)
  1071. // {
  1072. // [item_json setValue:[NSNumber numberWithDouble:price ] forKey:@"unit_price"];
  1073. //
  1074. // [item_json setValue:[NSNumber numberWithDouble:discount ] forKey:@"discount"];
  1075. // // [item_json setValue:notes forKey:@"note"];
  1076. //
  1077. // // RASingleton.sharedInstance.scan_cart[@"section_0"][[NSString stringWithFormat:@"item_%d",indexPath.row]]=item_json;
  1078. // // if (self.back_order_flag) {
  1079. // // [self updateItemJson:item_json atIndexPath:indexPath];
  1080. // // } else {
  1081. // // self.content_arr[indexPath.row ] = item_json;
  1082. // // }
  1083. // // tableView.editing = false;
  1084. // // [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  1085. // // [self refresh_total];
  1086. //
  1087. //
  1088. // [self reload_data];
  1089. //
  1090. // #ifdef RA_NOTIFICATION
  1091. // [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1092. // #else
  1093. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1094. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1095. // #endif
  1096. // }
  1097. // else
  1098. // {
  1099. // [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Update Price" controller:self] ;
  1100. // }
  1101. }];
  1102. }];
  1103. // [RANetwork request_update_cart_modelprice:cartid price:price discount:discount notes:nil completionHandler:^(NSMutableDictionary *result) {
  1104. // NSDictionary* cart_json = result;
  1105. //
  1106. // [waitalert dismissViewControllerAnimated:YES completion:^{
  1107. // if([[cart_json valueForKey:@"result"] intValue]==2)
  1108. // {
  1109. // [item_json setValue:[NSNumber numberWithDouble:price ] forKey:@"unit_price"];
  1110. //
  1111. // [item_json setValue:[NSNumber numberWithDouble:discount ] forKey:@"discount"];
  1112. //// [item_json setValue:notes forKey:@"note"];
  1113. //
  1114. //// RASingleton.sharedInstance.scan_cart[@"section_0"][[NSString stringWithFormat:@"item_%d",indexPath.row]]=item_json;
  1115. //// if (self.back_order_flag) {
  1116. //// [self updateItemJson:item_json atIndexPath:indexPath];
  1117. //// } else {
  1118. //// self.content_arr[indexPath.row ] = item_json;
  1119. //// }
  1120. //// tableView.editing = false;
  1121. // // [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  1122. // // [self refresh_total];
  1123. //
  1124. //
  1125. // [self reload_data];
  1126. //
  1127. // #ifdef RA_NOTIFICATION
  1128. // [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1129. // #else
  1130. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1131. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1132. // #endif
  1133. // }
  1134. // else
  1135. // {
  1136. // [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Update Price" controller:self] ;
  1137. // }
  1138. // }];
  1139. //
  1140. //
  1141. //
  1142. //
  1143. //
  1144. //
  1145. // }];
  1146. }];
  1147. };
  1148. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  1149. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1150. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  1151. [self presentViewController:navi animated:YES completion:^{
  1152. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1153. DebugLog(@"EditModelPriceViewController present.........");
  1154. // self.btop = false;
  1155. // <#code#>
  1156. }];
  1157. #endif
  1158. }
  1159. - (IBAction)onPlaceOrder:(UIButton *)sender {
  1160. #ifndef SCANNER_ORDER
  1161. if (![self isOrderAvailable]) {
  1162. return;
  1163. }
  1164. #endif
  1165. [self placeOrder];
  1166. }
  1167. -(void) scanPlaceOrder
  1168. {
  1169. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1170. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  1171. // NSString * string = [checked componentsJoinedByString:@","];
  1172. // [params setValue:string forKey:@"cart2Checkbox"];
  1173. // NSData* data=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:URL_SO_ORDER ofType:@"json" ]];
  1174. // NSError *error=nil;
  1175. // NSMutableDictionary* dict=[[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
  1176. //
  1177. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  1178. // NSString *documents = [paths objectAtIndex:0];
  1179. NSString *orderdir = [OLDataProvider getScanPath];
  1180. NSMutableDictionary* dict= [[RAUtils dictfromfile:[orderdir stringByAppendingPathComponent:@"order.json"]] mutableCopy];
  1181. int section_count = [dict[@"section_count"] intValue];
  1182. for(int i=0;i<section_count;i++)
  1183. {
  1184. NSMutableDictionary* section = [dict[[NSString stringWithFormat:@"section_%d",i]] mutableCopy];
  1185. NSString* title = section[@"title"];
  1186. if([title isEqualToString:@"Model Information"])
  1187. {
  1188. NSMutableDictionary* cart_section = RASingleton.sharedInstance.scan_cart[@"section_0"];
  1189. int cart_count = [cart_section[@"count"] intValue];
  1190. for(int j=0;j<cart_count;j++)
  1191. {
  1192. NSMutableDictionary* cart_item = [cart_section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  1193. cart_item[@"description"]= [NSString stringWithFormat:@"%@\n%@\n%@",cart_item[@"model"],cart_item[@"description"],cart_item[@"dimension"] ];
  1194. cart_item[@"control"]=@"model";
  1195. section[[NSString stringWithFormat:@"item_%d",j]] = cart_item;
  1196. }
  1197. section[@"count"] = @(cart_count);
  1198. dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  1199. }
  1200. else
  1201. if([title isEqualToString:@"Customer"])
  1202. {
  1203. int scount = [section[@"count"] intValue];
  1204. for(int j=0;j<scount;j++)
  1205. {
  1206. NSMutableDictionary * item = [section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  1207. NSString * name = item[@"name"];
  1208. if([name isEqualToString:@"business_card"])
  1209. {
  1210. NSArray*arr =[RAConvertor string2arr:appDelegate.customerInfo[name] separator:@","];
  1211. for(int l=0;l<arr.count;l++)
  1212. {
  1213. item[[NSString stringWithFormat:@"img_url_%d",l] ]=arr[l];
  1214. }
  1215. }
  1216. else
  1217. {
  1218. if(item[@"value"]==nil ||[item[@"value"] stringValue].length==0) //order 内没有值才从customer 复制
  1219. item[@"value"]=appDelegate.customerInfo[name];
  1220. }
  1221. section[[NSString stringWithFormat:@"item_%d",j]] = item;
  1222. }
  1223. // NSDictionary* item_0=@{@"control":@"text",@"name":@"customer_cid",@"aname":@"Contact",@"value":appDelegate.contact_id};
  1224. dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  1225. }
  1226. else
  1227. if([title isEqualToString:@"Remarks Content"])
  1228. {
  1229. int scount = [section[@"count"] intValue];
  1230. for(int j=0;j<scount;j++)
  1231. {
  1232. NSMutableDictionary * item = [section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  1233. NSString * name = item[@"name"];
  1234. if([name isEqualToString:@"comments"])
  1235. {
  1236. item[@"value"] = RASingleton.sharedInstance.scan_cart[@"general_note"];
  1237. section[[NSString stringWithFormat:@"item_%d",j]] = item;
  1238. }
  1239. }
  1240. // NSDictionary* item_0=@{@"control":@"text",@"name":@"customer_cid",@"aname":@"Contact",@"value":appDelegate.contact_id};
  1241. dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  1242. }
  1243. else if([title isEqualToString:@"Order Total"])
  1244. {
  1245. int scount = [section[@"count"] intValue];
  1246. for(int j=0;j<scount;j++)
  1247. {
  1248. NSMutableDictionary * item = [section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  1249. NSString * name = item[@"name"];
  1250. if([name isEqualToString:@"totalPrice"])
  1251. {
  1252. item[@"value"] = [RAConvertor currencyNumber:self.total+self.surcharge];//[NSString stringWithFormat:@"%.2f",self.total+self.surcharge];
  1253. section[[NSString stringWithFormat:@"item_%d",j]] = item;
  1254. }
  1255. else if([name isEqualToString:@"subtotalPrice"])
  1256. {
  1257. item[@"value"] = [RAConvertor currencyNumber:self.total];//[NSString stringWithFormat:@"%.2f",self.total];
  1258. section[[NSString stringWithFormat:@"item_%d",j]] = item;
  1259. }
  1260. else if([name isEqualToString:@"surcharge"])
  1261. {
  1262. item[@"value"] = [RAConvertor currencyNumber:self.surcharge];//[NSString stringWithFormat:@"%.2f",self.surcharge];
  1263. section[[NSString stringWithFormat:@"item_%d",j]] = item;
  1264. }
  1265. }
  1266. // NSDictionary* item_0=@{@"control":@"text",@"name":@"customer_cid",@"aname":@"Contact",@"value":appDelegate.contact_id};
  1267. dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  1268. }
  1269. }
  1270. // NSString *path = NSTemporaryDirectory();
  1271. //
  1272. // NSString* file=[NSString stringWithFormat:@"SO_%@.json",appDelegate.order_code];
  1273. // NSString *filePath = [path stringByAppendingPathComponent:file];
  1274. //
  1275. //
  1276. //
  1277. [RAUtils dicttofile:[orderdir stringByAppendingPathComponent:@"order.json"] dict:dict];
  1278. CreateOrderViewController * orderinfoVC = [[CreateOrderViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  1279. orderinfoVC.disable_dropdown_refresh=true;
  1280. orderinfoVC.url_type = URL_FILE;
  1281. orderinfoVC.request_url=[orderdir stringByAppendingPathComponent:@"order.json"];
  1282. orderinfoVC.params = params;
  1283. orderinfoVC.title=@"";
  1284. orderinfoVC.delegate=self;
  1285. //
  1286. // if(checked.count==count)
  1287. // {
  1288. // orderinfoVC.have_tail = true
  1289. // }
  1290. [self.navigationController pushViewController:orderinfoVC animated:true];
  1291. return;
  1292. }
  1293. - (IBAction)onBulkDiscount:(id)sender {
  1294. #ifdef SCANNER_ORDER
  1295. ScanDiscountViewController * vc =[[UIStoryboard storyboardWithName:@"SO" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanDiscountViewController"];
  1296. vc.bulk = true;
  1297. vc.discount=0;
  1298. // vc.price = 0;
  1299. // vc.cart_id = [item_json valueForKey:@"cart_item_id"];//[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  1300. // __block NSString* cartid=[item_json valueForKey:@"cart_item_id"];
  1301. // vc.delegate = parentvc.self;
  1302. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1303. vc.onSetValue = ^(double price,double discount){
  1304. bool bmodify=false;
  1305. if(discount>0)
  1306. bmodify=true;
  1307. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Update Price" completion:^{
  1308. [RANetwork request_scan_bulkdiscount:discount notes:nil completionHandler:^(NSMutableDictionary *result) {
  1309. NSDictionary* cart_json = result;
  1310. [waitalert dismissViewControllerAnimated:YES completion:^{
  1311. if([[cart_json valueForKey:@"result"] intValue]==2)
  1312. {
  1313. // [item_json setValue:[NSNumber numberWithDouble:price ] forKey:@"unit_price"];
  1314. //
  1315. // [item_json setValue:[NSNumber numberWithDouble:discount ] forKey:@"discount"];
  1316. // [item_json setValue:notes forKey:@"note"];
  1317. // RASingleton.sharedInstance.scan_cart[@"section_0"][[NSString stringWithFormat:@"item_%d",indexPath.row]]=item_json;
  1318. // if (self.back_order_flag) {
  1319. // [self updateItemJson:item_json atIndexPath:indexPath];
  1320. // } else {
  1321. // self.content_arr[indexPath.row ] = item_json;
  1322. // }
  1323. // tableView.editing = false;
  1324. // [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  1325. // [self refresh_total];
  1326. [self reload_data];
  1327. #ifdef RA_NOTIFICATION
  1328. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1329. #else
  1330. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1331. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1332. #endif
  1333. }
  1334. else
  1335. {
  1336. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Update Price" controller:self] ;
  1337. }
  1338. }];
  1339. }];
  1340. }];
  1341. };
  1342. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  1343. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1344. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  1345. [self presentViewController:navi animated:YES completion:^{
  1346. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1347. DebugLog(@"EditModelPriceViewController present.........");
  1348. // self.btop = false;
  1349. // <#code#>
  1350. }];
  1351. #endif
  1352. }
  1353. - (IBAction)onChangePrice:(id)sender {
  1354. #ifdef SCANNER_ORDER
  1355. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1356. if(RASingleton.sharedInstance.scan_cart ==nil)
  1357. {
  1358. // NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:URL_SO_CART ofType:@"json" ]];
  1359. NSMutableDictionary* cartTemplate=[OLDataProvider loadScanTemplate:@"scan_cart.json"];
  1360. RASingleton.sharedInstance.scan_cart=cartTemplate;//[[RAConvertor data2dict:json] mutableCopy];
  1361. }
  1362. NSDictionary* price_group = [RADataProvider get_price_group:appDelegate.price_group];
  1363. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Change Price Type" message:nil preferredStyle:UIAlertControllerStyleAlert];
  1364. UIAlertAction *action1 = [UIAlertAction actionWithTitle:price_group[@"price_0"][@"display"] style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  1365. self.btnBulkDiscount.hidden = true;
  1366. // self.btnPrice.titleLabel.text = @"FOB CTNR";
  1367. [self.btnPrice setTitle: price_group[@"price_0"][@"display"] forState:UIControlStateNormal];
  1368. RASingleton.sharedInstance.price_type=0;
  1369. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  1370. int count = [section[@"count"] intValue];
  1371. for(int i=0;i<count;i++)
  1372. {
  1373. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  1374. item[@"price"]=item[ price_group[@"price_0"][@"name"]];
  1375. item[@"unit_price"]= item[price_group[@"price_0"][@"name"]];
  1376. item[@"erp_unit_price"]= item[price_group[@"price_0"][@"name"]];
  1377. item[@"discount"]=@(0);
  1378. item[@"note"]=@"";
  1379. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  1380. }
  1381. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  1382. RASingleton.sharedInstance.scan_cart[@"price_type"] = @0;
  1383. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  1384. [self.cartIndicatorBar removeFromSuperview];
  1385. self.cartIndicatorBar = [self setupCartIndicatorBar];
  1386. [self.view addSubview:self.cartIndicatorBar];
  1387. [self reload_data];
  1388. }];
  1389. UIAlertAction *action2 = [UIAlertAction actionWithTitle:price_group[@"price_1"][@"display"] style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  1390. self.btnBulkDiscount.hidden = false;
  1391. [self.btnPrice setTitle: price_group[@"price_1"][@"display"] forState:UIControlStateNormal];
  1392. RASingleton.sharedInstance.price_type=1;
  1393. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  1394. int count = [section[@"count"] intValue];
  1395. for(int i=0;i<count;i++)
  1396. {
  1397. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  1398. NSString * unit_price;
  1399. if(item [@"net_price"])
  1400. unit_price=item[price_group[@"price_3"][@"name"]];
  1401. else if(item [@"special_price"])
  1402. {
  1403. unit_price= item[price_group[@"price_2"][@"name"]];
  1404. }
  1405. else
  1406. {
  1407. unit_price= item[price_group[@"price_1"][@"name"]];
  1408. }
  1409. if([unit_price isEqualToString:@"N/A"])
  1410. unit_price = @"0";
  1411. else
  1412. {
  1413. unit_price = [NSString stringWithFormat:@"%.2f", [unit_price doubleValue]];
  1414. }
  1415. item[@"unit_price"] = unit_price;
  1416. item[@"erp_unit_price"] = unit_price;
  1417. item[@"price"]= unit_price;//item[@"price1"];
  1418. // item[@"unit_price"]= item[@"price1"];
  1419. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  1420. }
  1421. RASingleton.sharedInstance.scan_cart[@"price_type"] = @1;
  1422. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  1423. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  1424. [self.cartIndicatorBar removeFromSuperview];
  1425. self.cartIndicatorBar = [self setupCartIndicatorBar];
  1426. [self.view addSubview:self.cartIndicatorBar];
  1427. [self reload_data];
  1428. }];
  1429. UIAlertAction *action3 = [UIAlertAction actionWithTitle:@"%25" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  1430. // self.btnPrice.titleLabel.text = @"%25";
  1431. [self.btnPrice setTitle: @"%25" forState:UIControlStateNormal];
  1432. RASingleton.sharedInstance.price_type=2;
  1433. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  1434. int count = [section[@"count"] intValue];
  1435. for(int i=0;i<count;i++)
  1436. {
  1437. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  1438. item[@"price"]= item[price_group[@"price_2"][@"name"]];
  1439. item[@"unit_price"]= item[price_group[@"price_2"][@"name"]];
  1440. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  1441. }
  1442. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  1443. RASingleton.sharedInstance.scan_cart[@"price_type"] = @2;
  1444. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  1445. [self.cartIndicatorBar removeFromSuperview];
  1446. self.cartIndicatorBar = [self setupCartIndicatorBar];
  1447. [self.view addSubview:self.cartIndicatorBar];
  1448. [self reload_data];
  1449. }];
  1450. UIAlertAction *alertCancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1451. }];
  1452. [alertControl addAction:action1];
  1453. [alertControl addAction:action2];
  1454. // [alertControl addAction:action3];
  1455. // [alertControl addAction:alertthree];
  1456. [alertControl addAction:alertCancel];
  1457. [self presentViewController:alertControl animated:YES completion:nil];
  1458. #endif
  1459. }
  1460. -(void) newoloorder
  1461. {
  1462. NSString *orderdir =[OLDataProvider getScanPath];
  1463. // NSString* order_code = RASingleton.sharedInstance.scan_temp_code;
  1464. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1465. // appDelegate.order_code = order_code;
  1466. // if(appDelegate.user.length==0)
  1467. // {
  1468. // [RAUtils message_alert:@"Please login first." title:@"Warring" controller:self];
  1469. // return;
  1470. // }
  1471. // NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:URL_SO_CART ofType:@"json" ]];
  1472. // NSMutableDictionary* cartTemplate=[OLDataProvider loadScanTemplate:@"scan_cart.json"];
  1473. // RASingleton.sharedInstance.scan_cart=cartTemplate;//[[RAConvertor data2dict:json] mutableCopy];
  1474. // appDelegate.user_type = USER_ROLE_EMPLOYEE;
  1475. appDelegate.can_set_cart_price = true;
  1476. appDelegate.can_see_price = true;
  1477. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  1478. // NSString *documents = [paths objectAtIndex:0];
  1479. {
  1480. // [OLDataProvider moveScanTemp2Order];
  1481. // NSError *error = nil;
  1482. // bool bsuccess=[[NSFileManager defaultManager] createDirectoryAtPath:orderdir withIntermediateDirectories:YES attributes:nil error:&error];
  1483. // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  1484. // NSString * string = [checked componentsJoinedByString:@","];
  1485. // [params setValue:string forKey:@"cart2Checkbox"];
  1486. // NSData* data=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:URL_SO_ORDER ofType:@"json" ]];
  1487. // NSMutableDictionary* dict=[[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
  1488. // __block NSMutableDictionary* block_dict = dict;
  1489. if(appDelegate.user_type== USER_ROLE_EMPLOYEE)
  1490. {
  1491. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Select Customer type" message:@"" preferredStyle:UIAlertControllerStyleAlert];
  1492. //block代码块取代了delegate
  1493. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Existing Customer" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  1494. NSMutableDictionary* dict = nil;
  1495. // NSMutableDictionary* dict = nil;
  1496. NSString* ordertemplate = nil;
  1497. if([RADataProvider getSiteHasERP])
  1498. ordertemplate =@"e_order.json";
  1499. else
  1500. ordertemplate =@"e_order_noerp.json";
  1501. dict=[OLDataProvider loadScanTemplate:ordertemplate];
  1502. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  1503. [RAUtils dicttofile:orderPath dict:dict];
  1504. NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  1505. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  1506. [self scanPlaceOrder];
  1507. }];
  1508. UIAlertAction *alert2 = [UIAlertAction actionWithTitle:@"New customer" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  1509. NSMutableDictionary* dict = nil;
  1510. dict=[OLDataProvider loadScanTemplate:@"n_order.json"];
  1511. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  1512. [RAUtils dicttofile:orderPath dict:dict];
  1513. NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  1514. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  1515. [self scanPlaceOrder];
  1516. }];
  1517. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1518. appDelegate.order_code = nil;
  1519. DebugLog(@"No");
  1520. }];
  1521. [alertControl addAction:actionOne];
  1522. [alertControl addAction:alert2];
  1523. [alertControl addAction:alertthree];
  1524. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  1525. [self presentViewController:alertControl animated:YES completion:nil];
  1526. DebugLog(@"%@",self.edit_select_arr);
  1527. }
  1528. else
  1529. {
  1530. NSMutableDictionary* dict = nil;
  1531. if([appDelegate.customerInfo[@"customer_cid"] stringValue].length ==0 )
  1532. {
  1533. dict=[OLDataProvider loadScanTemplate:@"nc_order.json"];
  1534. }
  1535. else
  1536. dict=[OLDataProvider loadScanTemplate:@"c_order.json"];
  1537. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  1538. [RAUtils dicttofile:orderPath dict:dict];
  1539. NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  1540. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  1541. [self scanPlaceOrder];
  1542. }
  1543. // NSMutableDictionary* dict=[OLDataProvider loadScanTemplate:@"scan_order.json"];
  1544. }
  1545. // MainViewController * mainvc=(MainViewController * )appDelegate.main_vc;
  1546. // mainvc.btnScan.enabled = true;
  1547. // [appDelegate updateScanButton:true];
  1548. }
  1549. -(void) newoloorder1
  1550. {
  1551. // NSString* order_code = RASingleton.sharedInstance.scan_temp_code;
  1552. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1553. // appDelegate.order_code = order_code;
  1554. // if(appDelegate.user.length==0)
  1555. // {
  1556. // [RAUtils message_alert:@"Please login first." title:@"Warring" controller:self];
  1557. // return;
  1558. // }
  1559. // NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:URL_SO_CART ofType:@"json" ]];
  1560. // NSMutableDictionary* cartTemplate=[OLDataProvider loadScanTemplate:@"scan_cart.json"];
  1561. // RASingleton.sharedInstance.scan_cart=cartTemplate;//[[RAConvertor data2dict:json] mutableCopy];
  1562. // appDelegate.user_type = USER_ROLE_EMPLOYEE;
  1563. appDelegate.can_set_cart_price = true;
  1564. appDelegate.can_see_price = true;
  1565. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  1566. // NSString *documents = [paths objectAtIndex:0];
  1567. {
  1568. NSString *orderdir =[OLDataProvider getScanPath];
  1569. // [OLDataProvider moveScanTemp2Order];
  1570. // NSError *error = nil;
  1571. // bool bsuccess=[[NSFileManager defaultManager] createDirectoryAtPath:orderdir withIntermediateDirectories:YES attributes:nil error:&error];
  1572. // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  1573. // NSString * string = [checked componentsJoinedByString:@","];
  1574. // [params setValue:string forKey:@"cart2Checkbox"];
  1575. // NSData* data=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:URL_SO_ORDER ofType:@"json" ]];
  1576. // NSMutableDictionary* dict=[[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
  1577. // __block NSMutableDictionary* block_dict = dict;
  1578. if(appDelegate.user_type== USER_ROLE_EMPLOYEE)
  1579. {
  1580. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Select Customer type" message:@"" preferredStyle:UIAlertControllerStyleAlert];
  1581. //block代码块取代了delegate
  1582. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Existing Customer" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  1583. NSMutableDictionary* dict = nil;
  1584. NSString* ordertemplate = nil;
  1585. if([RADataProvider getSiteHasERP])
  1586. ordertemplate =@"e_order.json";
  1587. else
  1588. ordertemplate =@"e_order_noerp.json";
  1589. dict=[OLDataProvider loadScanTemplate:ordertemplate];
  1590. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  1591. [RAUtils dicttofile:orderPath dict:dict];
  1592. NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  1593. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  1594. [self scanPlaceOrder];
  1595. }];
  1596. UIAlertAction *alert2 = [UIAlertAction actionWithTitle:@"New customer" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  1597. NSMutableDictionary* dict = nil;
  1598. dict=[OLDataProvider loadScanTemplate:@"n_order.json"];
  1599. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  1600. [RAUtils dicttofile:orderPath dict:dict];
  1601. NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  1602. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  1603. [self scanPlaceOrder];
  1604. }];
  1605. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1606. appDelegate.order_code = nil;
  1607. DebugLog(@"No");
  1608. }];
  1609. [alertControl addAction:actionOne];
  1610. [alertControl addAction:alert2];
  1611. [alertControl addAction:alertthree];
  1612. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  1613. [self presentViewController:alertControl animated:YES completion:nil];
  1614. DebugLog(@"%@",self.edit_select_arr);
  1615. }
  1616. else
  1617. {
  1618. NSMutableDictionary* dict = nil;
  1619. if([appDelegate.customerInfo[@"customer_cid"] stringValue].length ==0 )
  1620. {
  1621. dict=[OLDataProvider loadScanTemplate:@"nc_order.json"];
  1622. }
  1623. else
  1624. dict=[OLDataProvider loadScanTemplate:@"c_order.json"];
  1625. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  1626. [RAUtils dicttofile:orderPath dict:dict];
  1627. NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  1628. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  1629. [self scanPlaceOrder];
  1630. }
  1631. // NSMutableDictionary* dict=[OLDataProvider loadScanTemplate:@"scan_order.json"];
  1632. }
  1633. // MainViewController * mainvc=(MainViewController * )appDelegate.main_vc;
  1634. // mainvc.btnScan.enabled = true;
  1635. // [appDelegate updateScanButton:true];
  1636. }
  1637. -(void)newScanOrder1
  1638. {
  1639. //
  1640. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1641. //
  1642. //
  1643. // if(appDelegate.order_code.length>0)
  1644. // {
  1645. //// 当前订单先关闭
  1646. //// [OLDataProvider deleteScanOrder:appDelegate.order_code];
  1647. // appDelegate.order_code = nil;
  1648. // appDelegate.customerInfo = nil;
  1649. // RASingleton.sharedInstance.scan_cart = nil;
  1650. // appDelegate.contact_id = nil;
  1651. //// [appDelegate updateScanButton:false];
  1652. //
  1653. // [appDelegate update_count_mark];
  1654. // [appDelegate closeOrder];
  1655. //
  1656. // }
  1657. //
  1658. //
  1659. {
  1660. [self newoloorder1];
  1661. }
  1662. }
  1663. -(void)newScanOrder
  1664. {
  1665. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1666. //if(appDelegate.user.length<=0)
  1667. //{
  1668. // [RAUtils message_alert:@"Please select a sales first." title:@"Warring" controller:self];
  1669. // return;
  1670. //}
  1671. // if(appDelegate.order_code.length>0)
  1672. // {
  1673. //// 当前订单先关闭
  1674. //// [OLDataProvider deleteScanOrder:appDelegate.order_code];
  1675. // appDelegate.order_code = nil;
  1676. // appDelegate.customerInfo = nil;
  1677. // RASingleton.sharedInstance.scan_cart = nil;
  1678. // appDelegate.contact_id = nil;
  1679. //// [appDelegate updateScanButton:false];
  1680. //
  1681. // [appDelegate update_count_mark];
  1682. // [appDelegate closeOrder];
  1683. //
  1684. // }
  1685. // RASingleton.sharedInstance.enable_OfflineOrder = true;
  1686. // __block MainViewController *brself= self;
  1687. // if(appDelegate.contact_id.length<=0)
  1688. // {
  1689. //
  1690. // UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"New Offline Order" message:nil preferredStyle:UIAlertControllerStyleAlert];
  1691. // UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"With Offline Contact" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  1692. //
  1693. //// if(appDelegate.order_code && appDelegate.order_code.length>0)
  1694. //// {
  1695. //// [RAUtils message_alert:@"Please close current order and try again." title:@"" controller:self];
  1696. //// }
  1697. //// NSLog(@"new click");
  1698. //
  1699. // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  1700. //
  1701. //// NSString *path = [[NSBundle mainBundle] pathForResource:@"editContact.json" ofType:nil];
  1702. //
  1703. // CustomerEditViewController * cuseditVC = [[CustomerEditViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  1704. // cuseditVC.bnewcustomer=true;
  1705. // cuseditVC.bolocustomer = true;
  1706. // cuseditVC.url_type = URL_FILE;
  1707. // cuseditVC.request_url=[OLDataProvider scanTemplatePath:@"scan_contact.json"];
  1708. //
  1709. // cuseditVC.params = params;
  1710. //
  1711. // cuseditVC.returnValue=^(NSMutableDictionary* value)
  1712. // {
  1713. // if(value==nil)
  1714. // {
  1715. // [RAUtils message_alert:@"Cannot create order without customer infomation." title:@"" controller:self];
  1716. // }
  1717. // else
  1718. // {
  1719. // NSString* contact_id=[[NSUUID new] UUIDString];
  1720. //
  1721. //
  1722. // //---------------- construct customer_contact----------------------
  1723. // NSString* customer_first_name = [value valueForKey:@"customer_first_name"];
  1724. // if(customer_first_name==nil)
  1725. // customer_first_name=@"";
  1726. //
  1727. // NSString* customer_last_name= [value valueForKey:@"customer_last_name"];
  1728. // if(customer_last_name==nil)
  1729. // customer_last_name=@"";
  1730. // NSString* customer_contact = [NSString stringWithFormat:@"%@ %@",customer_first_name,customer_last_name];
  1731. // customer_contact=[customer_contact stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
  1732. // [value setValue:customer_contact forKey:@"customer_contact"];
  1733. //
  1734. //
  1735. //
  1736. // value [@"customer_cid"] = contact_id;
  1737. // appDelegate.contact_id=contact_id;
  1738. // appDelegate.customerInfo = value;
  1739. //
  1740. //
  1741. //
  1742. //
  1743. //
  1744. //
  1745. //// [brself refreshContactDisplay];
  1746. // [self newoloorder];
  1747. //
  1748. // [self scanPlaceOrder];
  1749. //
  1750. //// [brself switchToCart:nil];
  1751. //
  1752. // }
  1753. // };
  1754. //
  1755. //
  1756. // // cuseditVC.delegate=self;
  1757. // //
  1758. // // if(checked.count==count)
  1759. // // {
  1760. // // orderinfoVC.have_tail = true
  1761. // // }
  1762. //
  1763. // [[self navigationController] setNavigationBarHidden:NO animated:NO];
  1764. // [self.navigationController pushViewController:cuseditVC animated:false];
  1765. //
  1766. //// [self dismissViewControllerAnimated:NO completion:^{
  1767. ////// [(UINavigationController*)[self parentViewController] pushViewController:cuseditVC animated:false];;
  1768. ////// [[self navigationController] setNavigationBarHidden:NO animated:NO];
  1769. ////
  1770. ////// [self pushViewController:cuseditVC animated:false];
  1771. //// }];
  1772. //
  1773. //// [[self navigationController] setNavigationBarHidden:NO animated:NO];
  1774. //// [self.navigationController pushViewController:cuseditVC animated:false];
  1775. //
  1776. //
  1777. // }];
  1778. //
  1779. //
  1780. //
  1781. // UIAlertAction *alertCancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1782. //
  1783. // }];
  1784. //
  1785. // [alertControl addAction:actionOne];
  1786. //
  1787. //// [alertControl addAction:alertthree];
  1788. // [alertControl addAction:alertCancel];
  1789. //
  1790. // [self presentViewController:alertControl animated:YES completion:nil];
  1791. // }
  1792. // else
  1793. {
  1794. [self newoloorder];
  1795. }
  1796. }
  1797. -(void)placeOrder
  1798. {
  1799. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1800. #ifndef SCANNER_ORDER
  1801. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  1802. if (![RASingleton sharedInstance].permissions_edit_order) {
  1803. return;
  1804. }
  1805. // if (!self.available) {
  1806. //
  1807. // [RAUtils message_alert:@"There are some products is not available" title:@"Warning" controller:self];
  1808. // return;
  1809. // }
  1810. }
  1811. #endif
  1812. // NSMutableArray* checked = [[NSMutableArray alloc] init];
  1813. bool have_free = false;
  1814. long count = self.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  1815. if(count==0)
  1816. {
  1817. [RAUtils message_alert:@"Add some model first." title:@"Cart Is Empty." controller:self] ;
  1818. return;
  1819. }
  1820. for(int i=0;i<count;i++)
  1821. {
  1822. NSMutableDictionary * item_json = [self.content_arr[i] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  1823. // bool check = [[item_json valueForKey:@"check"] boolValue];
  1824. NSString* product_id = [item_json valueForKey:@"product_id"];
  1825. // if(check)
  1826. // {
  1827. // [checked addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"cart_item_id"] intValue]]];
  1828. //
  1829. // }
  1830. if(product_id.length==0)
  1831. {
  1832. [RAUtils message_alert:@"Some models in cart does not exist, you must remove them before place order." title:@"No Such Model" controller:self] ;
  1833. return;
  1834. }
  1835. bool is_free = [[item_json valueForKey:@"is_free"]boolValue];
  1836. if(is_free)
  1837. have_free=true;
  1838. }
  1839. // disable for debug
  1840. // if(checked.count==0)
  1841. // {
  1842. // [RAUtils message_alert:@"You must select at least one model." title:@"Cannot Place Order" controller:self] ;
  1843. // return;
  1844. // }
  1845. // NSDictionary * freejson = [self.content_data objectForKey:@"freeGiveaway"];
  1846. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1847. /* FREE GIVE AWAY
  1848. int free_count = [[self.freejson valueForKey:@"count"]intValue];
  1849. for(int ic=free_count-1;ic>=0;ic--)
  1850. {
  1851. float compare_price = [[self.freejson valueForKey:[NSString stringWithFormat:@"item_%d",ic]] floatValue];
  1852. if(self.total>=compare_price && !have_free&&appDelegate.can_set_cart_price)
  1853. {
  1854. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Free give away available.", nil) message:[NSString stringWithFormat:@"Order total price more than %.2f, do you want to add free give away item before place order?", compare_price] delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
  1855. alert.tag = ALERT_FREE;
  1856. [alert show];
  1857. return;
  1858. }
  1859. }
  1860. */
  1861. #ifdef SCANNER_ORDER
  1862. if(appDelegate.bLogin==false)
  1863. {
  1864. LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  1865. // loginvc.delegate = self;
  1866. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1867. loginvc.returnValue = ^(bool blogin){
  1868. if(blogin)
  1869. {
  1870. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1871. if(appDelegate.order_code.length==0)
  1872. {
  1873. [self newScanOrder];
  1874. }
  1875. }
  1876. };
  1877. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  1878. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1879. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  1880. [self presentViewController:navi animated:YES completion:^{
  1881. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1882. DebugLog(@"LoginViewController present.........");
  1883. // self.btop = false;
  1884. // <#code#>
  1885. }];
  1886. return;
  1887. }
  1888. else
  1889. {
  1890. NSString *orderdir =[OLDataProvider getScanPath];
  1891. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  1892. if(appDelegate.order_code.length==0 )
  1893. {
  1894. [self newScanOrder];
  1895. }
  1896. else if( ![[NSFileManager defaultManager] fileExistsAtPath:orderPath])
  1897. {
  1898. [self newScanOrder1];
  1899. }
  1900. else
  1901. {
  1902. [self scanPlaceOrder];
  1903. //place order
  1904. }
  1905. return;
  1906. }
  1907. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  1908. // {
  1909. //
  1910. // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  1911. // // NSString * string = [checked componentsJoinedByString:@","];
  1912. // // [params setValue:string forKey:@"cart2Checkbox"];
  1913. //
  1914. //// NSData* data=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:URL_SO_ORDER ofType:@"json" ]];
  1915. //// NSError *error=nil;
  1916. //// NSMutableDictionary* dict=[[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
  1917. ////
  1918. //
  1919. //
  1920. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  1921. // NSString *documents = [paths objectAtIndex:0];
  1922. //
  1923. //
  1924. //
  1925. // NSString *orderdir = [documents stringByAppendingPathComponent:appDelegate.order_code];
  1926. //
  1927. // NSMutableDictionary* dict= [[RAUtils dictfromfile:[orderdir stringByAppendingPathComponent:@"order.json"]] mutableCopy];
  1928. //
  1929. // int section_count = [dict[@"section_count"] intValue];
  1930. //
  1931. // for(int i=0;i<section_count;i++)
  1932. // {
  1933. // NSMutableDictionary* section = [dict[[NSString stringWithFormat:@"section_%d",i]] mutableCopy];
  1934. // NSString* title = section[@"title"];
  1935. // if([title isEqualToString:@"Model Information"])
  1936. // {
  1937. //
  1938. // NSMutableDictionary* cart_section = RASingleton.sharedInstance.scan_cart[@"section_0"];
  1939. // int cart_count = [cart_section[@"count"] intValue];
  1940. // for(int j=0;j<cart_count;j++)
  1941. // {
  1942. // NSMutableDictionary* cart_item = [cart_section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  1943. // cart_item[@"control"]=@"model";
  1944. // section[[NSString stringWithFormat:@"item_%d",j]] = cart_item;
  1945. //
  1946. // }
  1947. // section[@"count"] = @(cart_count);
  1948. // dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  1949. // }
  1950. // else
  1951. // if([title isEqualToString:@"Customer"])
  1952. // {
  1953. //
  1954. // int scount = [section[@"count"] intValue];
  1955. // for(int j=0;j<scount;j++)
  1956. // {
  1957. // NSMutableDictionary * item = [section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  1958. // NSString * name = item[@"name"];
  1959. //
  1960. // if([name isEqualToString:@"business_card"])
  1961. // {
  1962. // NSArray*arr =[RAConvertor string2arr:appDelegate.customerInfo[name] separator:@","];
  1963. // for(int l=0;l<arr.count;l++)
  1964. // {
  1965. // item[[NSString stringWithFormat:@"img_url_%d",l] ]=arr[l];
  1966. // }
  1967. // }
  1968. // else
  1969. // item[@"value"]=appDelegate.customerInfo[name];
  1970. //
  1971. // section[[NSString stringWithFormat:@"item_%d",j]] = item;
  1972. // }
  1973. //
  1974. //// NSDictionary* item_0=@{@"control":@"text",@"name":@"customer_cid",@"aname":@"Contact",@"value":appDelegate.contact_id};
  1975. // dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  1976. //
  1977. //
  1978. // }
  1979. // else
  1980. // if([title isEqualToString:@"Remarks Content"])
  1981. // {
  1982. //
  1983. // int scount = [section[@"count"] intValue];
  1984. // for(int j=0;j<scount;j++)
  1985. // {
  1986. // NSMutableDictionary * item = [section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  1987. // NSString * name = item[@"name"];
  1988. //
  1989. //
  1990. // if([name isEqualToString:@"comments"])
  1991. // {
  1992. // item[@"value"] = RASingleton.sharedInstance.scan_cart[@"general_note"];
  1993. // section[[NSString stringWithFormat:@"item_%d",j]] = item;
  1994. // }
  1995. //
  1996. //
  1997. // }
  1998. //
  1999. // // NSDictionary* item_0=@{@"control":@"text",@"name":@"customer_cid",@"aname":@"Contact",@"value":appDelegate.contact_id};
  2000. // dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  2001. //
  2002. //
  2003. // }
  2004. // else if([title isEqualToString:@"Order Total"])
  2005. // {
  2006. //
  2007. // int scount = [section[@"count"] intValue];
  2008. // for(int j=0;j<scount;j++)
  2009. // {
  2010. // NSMutableDictionary * item = [section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  2011. // NSString * name = item[@"name"];
  2012. //
  2013. //
  2014. // if([name isEqualToString:@"totalPrice"])
  2015. // {
  2016. // item[@"value"] = [NSString stringWithFormat:@"%.2f",self.total];
  2017. // section[[NSString stringWithFormat:@"item_%d",j]] = item;
  2018. // }
  2019. //
  2020. //
  2021. // }
  2022. //
  2023. //// NSDictionary* item_0=@{@"control":@"text",@"name":@"customer_cid",@"aname":@"Contact",@"value":appDelegate.contact_id};
  2024. // dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  2025. //
  2026. //
  2027. //
  2028. // }
  2029. //
  2030. //
  2031. //
  2032. //
  2033. // }
  2034. //
  2035. //// NSString *path = NSTemporaryDirectory();
  2036. ////
  2037. //// NSString* file=[NSString stringWithFormat:@"SO_%@.json",appDelegate.order_code];
  2038. //// NSString *filePath = [path stringByAppendingPathComponent:file];
  2039. ////
  2040. ////
  2041. ////
  2042. // [RAUtils dicttofile:[orderdir stringByAppendingPathComponent:@"order.json"] dict:dict];
  2043. //
  2044. // CreateOrderViewController * orderinfoVC = [[CreateOrderViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  2045. //
  2046. //
  2047. //
  2048. // orderinfoVC.disable_dropdown_refresh=true;
  2049. // orderinfoVC.url_type = URL_FILE;
  2050. // orderinfoVC.request_url=[orderdir stringByAppendingPathComponent:@"order.json"];
  2051. //
  2052. // orderinfoVC.params = params;
  2053. // orderinfoVC.title=@"";
  2054. // orderinfoVC.delegate=self;
  2055. // //
  2056. // // if(checked.count==count)
  2057. // // {
  2058. // // orderinfoVC.have_tail = true
  2059. // // }
  2060. //
  2061. // [self.navigationController pushViewController:orderinfoVC animated:true];
  2062. //
  2063. // return;
  2064. // }
  2065. #endif
  2066. #ifdef BACKORDER_PROCESS
  2067. if (self.back_order_flag) {
  2068. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  2069. [params setObject:@(0) forKey:@"step"];
  2070. RAOrderEditorViewController *orderEditorVC =[[UIStoryboard storyboardWithName:@"ERP_Mobile_Order" bundle:nil] instantiateViewControllerWithIdentifier:@"RAOrderEditorViewController"];
  2071. //[[RAOrderEditorViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  2072. orderEditorVC.disable_dropdown_refresh=true;
  2073. orderEditorVC.url_type = URL_REMOTE;
  2074. orderEditorVC.request_url=URL_CARTDELIVERY;
  2075. orderEditorVC.params = params;
  2076. orderEditorVC.delegate=self;
  2077. orderEditorVC.title=@"";
  2078. [self.navigationController pushViewController:orderEditorVC animated:true];
  2079. }
  2080. else
  2081. #endif
  2082. {
  2083. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  2084. // NSString * string = [checked componentsJoinedByString:@","];
  2085. // [params setValue:string forKey:@"cart2Checkbox"];
  2086. CreateOrderViewController * orderinfoVC = [[CreateOrderViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  2087. orderinfoVC.disable_dropdown_refresh=true;
  2088. orderinfoVC.url_type = URL_REMOTE;
  2089. orderinfoVC.request_url=URL_CARTDELIVERY;
  2090. orderinfoVC.params = params;
  2091. orderinfoVC.title=@"";
  2092. orderinfoVC.delegate=self;
  2093. //
  2094. // if(checked.count==count)
  2095. // {
  2096. // orderinfoVC.have_tail = true
  2097. // }
  2098. [self.navigationController pushViewController:orderinfoVC animated:true];
  2099. }
  2100. }
  2101. - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
  2102. {
  2103. return NO;
  2104. }
  2105. //- (IBAction)onDelete:(UIButton *)sender {
  2106. // return ;
  2107. // NSMutableArray* checked = [[NSMutableArray alloc] init];
  2108. //
  2109. //
  2110. //
  2111. // long count = self.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  2112. // for(int i=0;i<count;i++)
  2113. // {
  2114. // NSMutableDictionary * item_json = [self.content_arr[i] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  2115. // bool check = [[item_json valueForKey:@"check"] boolValue];
  2116. // if(check)
  2117. // {
  2118. // [checked addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"cart_item_id"] intValue]]];
  2119. //
  2120. // }
  2121. // }
  2122. // // disable for debug
  2123. // if(checked.count==0)
  2124. // return;
  2125. //
  2126. // // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  2127. // NSString * string = [checked componentsJoinedByString:@","];
  2128. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2129. //
  2130. // NSDictionary* cart_json = [RANetwork cart_remove:string];
  2131. //
  2132. // dispatch_async(dispatch_get_main_queue(), ^{
  2133. //
  2134. //
  2135. //
  2136. // if([[cart_json valueForKey:@"result"] intValue]==2)
  2137. // {
  2138. //
  2139. // [self reload_data];
  2140. // }
  2141. // else
  2142. // {
  2143. // [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
  2144. // }
  2145. //
  2146. //
  2147. //
  2148. // });
  2149. // });
  2150. //}
  2151. - (IBAction)onScanDiscount:(UIButton*)sender {
  2152. #ifdef SCANNER_ORDER
  2153. UITableViewCell* cell =(UITableViewCell*) sender.superview.superview;
  2154. NSIndexPath * indexPath = [self.itemListTable indexPathForCell:cell];
  2155. UIViewController* parentvc=self;
  2156. // EditModelPriceViewController
  2157. ScanDiscountViewController * vc =[[UIStoryboard storyboardWithName:@"SO" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanDiscountViewController"];
  2158. NSMutableDictionary * item_json = nil;
  2159. if (self.back_order_flag) {
  2160. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  2161. } else {
  2162. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2163. }
  2164. vc.discount=[[item_json valueForKey:@"discount"] floatValue];
  2165. vc.price = [[item_json valueForKey:@"unit_price"] floatValue];
  2166. vc.cart_id = [item_json valueForKey:@"cart_item_id"];//[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  2167. __block NSString* cartid=[item_json valueForKey:@"cart_item_id"];
  2168. // vc.delegate = parentvc.self;
  2169. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  2170. vc.onSetValue = ^(double price,double discount){
  2171. bool bmodify=false;
  2172. if(discount>0)
  2173. bmodify=true;
  2174. // NSString* notes = [item_json valueForKey:@"note"];
  2175. // if(notes.length==0)
  2176. // notes=@"";
  2177. // if(bmodify)
  2178. // {
  2179. //
  2180. //
  2181. // // if([notes isEqualToString:@""])
  2182. //// notes=[NSString stringWithFormat:@"Note: discount %d%% off.",(int)discount];
  2183. ////
  2184. //// NSRange range;
  2185. //// range = [notes rangeOfString:@"PRICE MODIFIED"];
  2186. //// if (range.location != NSNotFound) {
  2187. ////
  2188. //// }else{
  2189. //// notes= [notes stringByAppendingString:@"\nPRICE MODIFIED"];
  2190. //// }
  2191. // }
  2192. // else
  2193. //
  2194. // {
  2195. //// notes =@"";
  2196. // }
  2197. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Update Price" completion:^{
  2198. [RANetwork request_update_cart_modelprice:cartid price:price discount:discount notes:nil completionHandler:^(NSMutableDictionary *result) {
  2199. NSDictionary* cart_json = result;
  2200. [waitalert dismissViewControllerAnimated:YES completion:^{
  2201. if([[cart_json valueForKey:@"result"] intValue]==2)
  2202. {
  2203. // [item_json setValue:[NSNumber numberWithDouble:price ] forKey:@"unit_price"];
  2204. //
  2205. // [item_json setValue:[NSNumber numberWithDouble:discount ] forKey:@"discount"];
  2206. // [item_json setValue:notes forKey:@"note"];
  2207. // RASingleton.sharedInstance.scan_cart[@"section_0"][[NSString stringWithFormat:@"item_%d",indexPath.row]]=item_json;
  2208. // if (self.back_order_flag) {
  2209. // [self updateItemJson:item_json atIndexPath:indexPath];
  2210. // } else {
  2211. // self.content_arr[indexPath.row ] = item_json;
  2212. // }
  2213. // tableView.editing = false;
  2214. // [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  2215. // [self refresh_total];
  2216. [self reload_data];
  2217. #ifdef RA_NOTIFICATION
  2218. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2219. #else
  2220. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2221. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2222. #endif
  2223. }
  2224. else
  2225. {
  2226. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Update Price" controller:self] ;
  2227. }
  2228. }];
  2229. }];
  2230. }];
  2231. };
  2232. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  2233. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  2234. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  2235. [parentvc presentViewController:navi animated:YES completion:^{
  2236. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  2237. DebugLog(@"EditModelPriceViewController present.........");
  2238. // self.btop = false;
  2239. // <#code#>
  2240. }];
  2241. #endif
  2242. }
  2243. -(void)refresh_total
  2244. {
  2245. self.total=0;
  2246. self.total_carton=0;
  2247. self.total_cuft=0;
  2248. self.total_weight=0;
  2249. self.total_QTY=0;
  2250. self.total_item=0;
  2251. self.surcharge=0;
  2252. #ifdef SCANNER_ORDER
  2253. NSString* pricename;
  2254. NSDictionary *addressDic = [[NSUserDefaults standardUserDefaults] valueForKey:@"ScanAddress"];
  2255. NSString* servername = [addressDic objectForKey:@"show_name"];
  2256. NSArray* arrsn = [RAConvertor string2arr:servername separator:@","];
  2257. NSString * shortname = arrsn[0];
  2258. if(shortname.length==0)
  2259. shortname = servername;
  2260. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2261. NSDictionary* price_group = [RADataProvider get_price_group:appDelegate.price_group];
  2262. switch(RASingleton.sharedInstance.price_type )
  2263. {
  2264. case 0: pricename =price_group[@"price_0"][@"display"];//@"DDP";//[NSString stringWithFormat:@"%@_DDP",shortname];
  2265. break;;
  2266. case 1: pricename =price_group[@"price_1"][@"display"];//@"WHSE";//[NSString stringWithFormat:@"%@_WHSE",shortname];;
  2267. break;;
  2268. // case 2: pricename = @"25%";
  2269. // break;
  2270. }
  2271. [self.btnPrice setTitle:pricename forState:UIControlStateNormal];
  2272. // self.cartIndicatorBar = [self setupCartIndicatorBar];
  2273. [self.cartIndicatorBar removeFromSuperview];
  2274. self.cartIndicatorBar = [self setupCartIndicatorBar];
  2275. [self.view addSubview:self.cartIndicatorBar];
  2276. #endif
  2277. long count =self.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  2278. for(int i=0;i<count;i++)
  2279. {
  2280. NSMutableDictionary * item_json = [self.content_arr[i] mutableCopy];// [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  2281. bool bcheck = [[item_json valueForKey:@"check"]boolValue];
  2282. if(bcheck)
  2283. {
  2284. double unitprice = [[item_json valueForKey:@"unit_price"] doubleValue];
  2285. double discount = [[item_json valueForKey:@"discount"] doubleValue];
  2286. int count=[[item_json valueForKey:@"count"] intValue];
  2287. double totalprice =count*unitprice*(1-discount/100.0);
  2288. double cuft=[[item_json valueForKey:@"cuft"] doubleValue];
  2289. double weight=[[item_json valueForKey:@"weight"] doubleValue];
  2290. int carton=/*count**/[[item_json valueForKey:@"carton"] intValue];
  2291. int item_count=1;
  2292. int item_qty=1;
  2293. // NSDictionary * bundle_item =[item_json objectForKey:@"combine"];
  2294. double msurcharge =0;
  2295. if(RASingleton.sharedInstance.price_type==1)
  2296. {
  2297. if([item_json[@"special_price"] boolValue])
  2298. {
  2299. msurcharge=([item_json[price_group[@"price_3"][@"name"]] doubleValue]-[item_json[price_group[@"price_2"][@"name"]] doubleValue])*count*(1-discount/100.0);
  2300. if(msurcharge<0)
  2301. msurcharge = 0;
  2302. }
  2303. else
  2304. {
  2305. msurcharge=([item_json[price_group[@"price_3"][@"name"]] doubleValue]-[item_json[price_group[@"price_1"][@"name"]] doubleValue])*count*(1-discount/100.0);
  2306. if(msurcharge<0)
  2307. msurcharge = 0;
  2308. }
  2309. }
  2310. // double dprice=0;
  2311. // if(bundle_item!=nil)
  2312. // {
  2313. // // int citem=0;
  2314. //
  2315. // int bcount=[[bundle_item valueForKey:@"count"] intValue];
  2316. // for(int bc=0;bc<bcount;bc++)
  2317. // {
  2318. // NSDictionary * bitem = [bundle_item objectForKey:[NSString stringWithFormat:@"item_%d",bc]];
  2319. // int modulus= [[bitem valueForKey:@"modulus"] intValue];
  2320. // // citem+= modulus;
  2321. // item_count+=1;
  2322. // item_qty+=modulus;
  2323. // double uprice= [[bitem valueForKey:@"unit_price"]doubleValue];
  2324. // dprice+= uprice*modulus*count;
  2325. //
  2326. // }
  2327. // }
  2328. // totalprice+= dprice;
  2329. self.surcharge+=msurcharge;
  2330. self.total+=totalprice;
  2331. self.total_cuft+=cuft;
  2332. self.total_carton+=carton;
  2333. self.total_weight+=weight;
  2334. self.total_item+=item_count;
  2335. self.total_QTY+=(item_qty)*count;
  2336. }
  2337. }
  2338. NSString* subtotal = [RAConvertor currencyNumber:self.total];//[NSString stringWithFormat:@"$%@",];
  2339. NSString* subcuft = [NSString stringWithFormat:@"%.2f",self.total_cuft];
  2340. NSString* subcarton = [NSString stringWithFormat:@"%d",self.total_carton];
  2341. NSString* subweight = [NSString stringWithFormat:@"%.2f lbs",self.total_weight];
  2342. NSString* surcharge = [RAConvertor currencyNumber:self.surcharge];//[NSString stringWithFormat:@"$%@",];
  2343. NSString* totalprice = [RAConvertor currencyNumber:(self.total+self.surcharge)];//[NSString stringWithFormat:@"$%@",];
  2344. NSString* subitems = [NSString stringWithFormat:@"%d",self.total_item];
  2345. NSString* subqty = [NSString stringWithFormat:@"%d",self.total_QTY];
  2346. #ifndef SCANNER_ORDER
  2347. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2348. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  2349. {
  2350. }
  2351. else
  2352. {
  2353. subtotal=nil;
  2354. }
  2355. #else
  2356. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2357. [OLDataProvider updateScanOrder:appDelegate.order_code];
  2358. #endif
  2359. self.labelTotalSurcharge.text = surcharge;
  2360. self.labelTotalPrice.text = totalprice;
  2361. self.labelTotal.text=subtotal;
  2362. self.label_cuft.text=subcuft;
  2363. self.label_carton.text=subcarton;
  2364. self.label_weight.text=subweight;
  2365. self.label_items.text = subitems;
  2366. self.label_qty.text = subqty;
  2367. self.label_notes.text = [self.notes stringByReplacingOccurrencesOfString:@"\n" withString:@" "];
  2368. }
  2369. - (IBAction)onEditGeneralNotes:(id)sender {
  2370. #ifndef SCANNER_ORDER
  2371. if (![self isOrderAvailable]) {
  2372. return;
  2373. }
  2374. #endif
  2375. UIViewController* parentvc=self;
  2376. CartGeneralNotesViewController * vc =[[UIStoryboard storyboardWithName:@"ERP_Mobile_Cart" bundle:nil] instantiateViewControllerWithIdentifier:@"CartGeneralNotesViewController"];
  2377. // NSMutableDictionary * item_json = [self.content_arr[indexPath.row ] mutableCopy];// [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2378. vc.notes=self.notes;
  2379. // vc.delegate = parentvc.self;
  2380. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  2381. vc.onSetValue = ^(NSString* notes){
  2382. self.notes = notes;
  2383. [self refresh_total];
  2384. };
  2385. //
  2386. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  2387. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  2388. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  2389. [parentvc presentViewController:navi animated:YES completion:^{
  2390. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  2391. DebugLog(@"general notes editor present.........");
  2392. // self.btop = false;
  2393. // <#code#>
  2394. }];
  2395. }
  2396. //- (IBAction)onSelectAll:(UIButton *)sender {
  2397. //
  2398. //
  2399. // NSMutableArray* arr_ids = [[NSMutableArray alloc] init];
  2400. //
  2401. //
  2402. //
  2403. //
  2404. //
  2405. //
  2406. // if([self.btnselect.titleLabel.text isEqualToString:@"Select all"])
  2407. // {
  2408. //
  2409. // long count = self.content_arr.count;// [[self.content_data valueForKey:@"count"] intValue];
  2410. // for(int i=0;i<count;i++)
  2411. // {
  2412. // NSMutableDictionary * item_json = [self.content_arr[i] mutableCopy]; //[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  2413. // if(![[item_json valueForKey:@"check"] boolValue])
  2414. // [arr_ids addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"cart_item_id"] intValue]]];
  2415. //
  2416. // }
  2417. // [self.btnselect setTitle: @"Deselect all" forState: UIControlStateNormal];
  2418. // }
  2419. // else
  2420. // {
  2421. // long count = self.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  2422. // for(int i=0;i<count;i++)
  2423. // {
  2424. // NSMutableDictionary * item_json = [self.content_arr[i] mutableCopy]; //[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  2425. // if([[item_json valueForKey:@"check"] boolValue])
  2426. // [arr_ids addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"cart_item_id"] intValue]]];
  2427. //
  2428. // }
  2429. // [self.btnselect setTitle: @"Select all" forState: UIControlStateNormal];
  2430. // }
  2431. //
  2432. // NSString * ids = [arr_ids componentsJoinedByString:@","];
  2433. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2434. //
  2435. //
  2436. // NSDictionary* check_json = [iSalesNetwork cart_check:ids];
  2437. //
  2438. // dispatch_async(dispatch_get_main_queue(), ^{
  2439. //
  2440. //
  2441. //
  2442. // if([[check_json valueForKey:@"result"] intValue]==2)
  2443. // {
  2444. //
  2445. // long count = self.content_arr.count;
  2446. // for(int i=0;i<count;i++)
  2447. // {
  2448. // NSMutableDictionary * item_json = [self.content_arr[i] mutableCopy];
  2449. // if([item_json[@"check"] boolValue])
  2450. // item_json[@"check"]= @"false";
  2451. // else
  2452. // item_json[@"check"]= @"true";
  2453. //
  2454. // self.content_arr[i] = item_json;
  2455. // //[self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i]];
  2456. // }
  2457. //
  2458. // [self reload_container_getdata:false];
  2459. //
  2460. // // [self reload_data];
  2461. // }
  2462. // else
  2463. // {
  2464. // [RAUtils message_alert:[check_json valueForKey:@"err_msg"] title:nil controller:self] ;
  2465. // }
  2466. //
  2467. //
  2468. //
  2469. // });
  2470. // });
  2471. //
  2472. //
  2473. //
  2474. //
  2475. //
  2476. //
  2477. // // [self refresh_total];
  2478. // // self.labelTotal.text=[NSString stringWithFormat:@"$%.2f",self.total];
  2479. // // DebugLog(self.btnselect.titleLabel.text);
  2480. // // if(self.btnselect.titleLabel.text)
  2481. //}
  2482. //#pragma mark - MODEL cell delegate
  2483. //-(void) returnQTY:(int)qty
  2484. //{
  2485. // NSMutableDictionary * item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2486. //
  2487. // int count=[[item_json valueForKey:@"count"] intValue];
  2488. //
  2489. // if(count==qty)
  2490. // return;
  2491. // [item_json setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"count"];
  2492. // double unit_price = [[item_json valueForKey:@"unit_price"] doubleValue];
  2493. // // double sub_total=[[item_json valueForKey:@"subtotal_price"] doubleValue];
  2494. // [item_json setValue:[NSString stringWithFormat:@"%f",unit_price*qty] forKey:@"subtotal_price"];
  2495. // self.content_arr[indexPath.row]= item_json;
  2496. // // [self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  2497. // [self refresh_total];
  2498. // // self.total+=(unit_price*qty-sub_total);
  2499. // // self.labelTotal.text=[NSString stringWithFormat:@"$%.2f",self.total];
  2500. //
  2501. //
  2502. //}
  2503. - (IBAction)OnCancelOrderClicked:(id)sender {
  2504. // if (![self isOrderAvailable]) {
  2505. // return;
  2506. // }
  2507. //
  2508. // UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Cancel Order" message:@"Are you sure to cancel the order in cart ?" preferredStyle:UIAlertControllerStyleAlert];
  2509. // //block代码块取代了delegate
  2510. //
  2511. //
  2512. //
  2513. // UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  2514. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2515. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Cancel Order" completion:^{
  2516. //
  2517. //#ifdef SCANNER_ORDER
  2518. //// if(RASingleton.sharedInstance.enable_OfflineOrder)
  2519. // {
  2520. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  2521. // [OLDataProvider deleteScanOrder:appDelegate.order_code];
  2522. // [appDelegate closeOrder];
  2523. // return;
  2524. // }
  2525. //#endif
  2526. // [RANetwork request_cancel_order:nil order_code:appDelegate.order_code completionHandler:^(NSMutableDictionary *result) {
  2527. // [waitalert dismissViewControllerAnimated:YES completion:^{
  2528. // NSDictionary* return_json = result;
  2529. //
  2530. // if([[return_json valueForKey:@"result"] intValue]==2)
  2531. // {
  2532. // //if([appDelegate.order_code isEqualToString: [self.content_data[indexPath.row] valueForKey:@"order_code"]])
  2533. // {
  2534. // appDelegate.order_code = nil;
  2535. // //appDelegate.user_type = 0;
  2536. // appDelegate.customerInfo = nil;
  2537. // appDelegate.contact_id = nil;
  2538. // appDelegate.order_customer_id = nil;
  2539. // [appDelegate SetSo:nil];
  2540. // appDelegate.cart_count=0;
  2541. // [appDelegate update_count_mark];
  2542. //
  2543. //
  2544. // }
  2545. // #ifdef RA_NOTIFICATION
  2546. // [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2547. // #else
  2548. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2549. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2550. // #endif
  2551. // //[RAUtils message_alert:nil title:@"Order Canceled" controller:self] ;
  2552. // //[self ReloadData];
  2553. //
  2554. // // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2555. // // // appDelegate.order_code = nil;
  2556. // //
  2557. // // [appDelegate closeOrder];
  2558. // // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  2559. // [((MainViewController*)appDelegate.main_vc) switchToHome];
  2560. //
  2561. // // if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  2562. // // {
  2563. // // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  2564. // // }
  2565. // }
  2566. // else
  2567. // {
  2568. // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Cancel Order" controller:self] ;
  2569. // }
  2570. // }];
  2571. //
  2572. //
  2573. //
  2574. //
  2575. //
  2576. //
  2577. // }];
  2578. //
  2579. // }];
  2580. //
  2581. //// dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2582. ////
  2583. //// NSDictionary* return_json = [RANetwork cancel_Order:nil order_code:appDelegate.order_code];
  2584. ////
  2585. //// dispatch_async(dispatch_get_main_queue(), ^{
  2586. //// [waitalert dismissViewControllerAnimated:YES completion:nil];
  2587. ////
  2588. ////
  2589. //// if([[return_json valueForKey:@"result"] intValue]==2)
  2590. //// {
  2591. //// //if([appDelegate.order_code isEqualToString: [self.content_data[indexPath.row] valueForKey:@"order_code"]])
  2592. //// {
  2593. //// appDelegate.order_code= nil;
  2594. //// //appDelegate.user_type = 0;
  2595. //// appDelegate.customerInfo = nil;
  2596. //// appDelegate.contact_id = nil;
  2597. //// appDelegate.order_customer_id = nil;
  2598. //// [appDelegate SetSo:nil];
  2599. //// appDelegate.cart_count=0;
  2600. //// [appDelegate update_count_mark];
  2601. ////
  2602. ////
  2603. //// }
  2604. ////#ifdef RA_NOTIFICATION
  2605. //// [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2606. ////#else
  2607. //// AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2608. //// [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2609. ////#endif
  2610. //// //[RAUtils message_alert:nil title:@"Order Canceled" controller:self] ;
  2611. //// //[self ReloadData];
  2612. ////
  2613. ////// AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2614. ////// // appDelegate.order_code = nil;
  2615. //////
  2616. ////// [appDelegate closeOrder];
  2617. ////// [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  2618. //// [((MainViewController*)appDelegate.main_vc) switchToHome];
  2619. ////
  2620. ////// if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  2621. ////// {
  2622. ////// [((MainViewController*)appDelegate.main_vc) Loginout:false];
  2623. ////// }
  2624. //// }
  2625. //// else
  2626. //// {
  2627. //// [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Cancel Order" controller:self] ;
  2628. //// }
  2629. ////
  2630. ////
  2631. ////
  2632. ////
  2633. //// });
  2634. //// });
  2635. //
  2636. //
  2637. // }];
  2638. //
  2639. // UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  2640. // DebugLog(@"No");
  2641. // }];
  2642. // [alertControl addAction:actionOne];
  2643. //
  2644. // [alertControl addAction:alertthree];
  2645. //
  2646. // //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  2647. //
  2648. //
  2649. // [self presentViewController:alertControl animated:YES completion:nil];
  2650. //
  2651. // DebugLog(@"%@",self.edit_select_arr);
  2652. //
  2653. //
  2654. }
  2655. #pragma mark - Private
  2656. - (BOOL)isOrderAvailable {
  2657. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2658. if (appDelegate.order_code.length == 0) {
  2659. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:@"please create a new order first" preferredStyle:UIAlertControllerStyleAlert];
  2660. UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  2661. }];
  2662. [alertVC addAction:okAction];
  2663. [self presentViewController:alertVC animated:YES completion:nil];
  2664. return NO;
  2665. }
  2666. return YES;
  2667. }
  2668. #pragma mark - commoneditor controller delegate
  2669. -(void) returnValue:(NSMutableDictionary *)value indexPath :(NSIndexPath*) indexPath
  2670. {
  2671. // [self reload_data];
  2672. if([value[@"commitorder_logout"] boolValue])
  2673. [self logout];
  2674. [[self navigationController] setNavigationBarHidden:YES animated:NO];
  2675. }
  2676. #pragma mark - Table view data source
  2677. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
  2678. {
  2679. NSDictionary * item_json = nil;
  2680. if (self.back_order_flag) {
  2681. item_json = [self itemJsonAtIndexPath:indexPath];
  2682. } else {
  2683. item_json = self.content_arr[indexPath.row ];// [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2684. }
  2685. NSString* notes =[item_json valueForKey:@"note"];
  2686. if(notes.length>0)
  2687. {
  2688. return 146;
  2689. }
  2690. else
  2691. return 120;
  2692. }
  2693. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  2694. //{
  2695. // return 0;
  2696. //}
  2697. //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  2698. //{
  2699. // return 0;
  2700. //}
  2701. //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  2702. //{
  2703. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  2704. // return myView;
  2705. //
  2706. //}
  2707. //- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  2708. //{
  2709. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  2710. //// myView.backgroundColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  2711. //// UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 90, 22)];
  2712. //// titleLabel.textColor=[UIColor whiteColor];
  2713. //// titleLabel.backgroundColor = [UIColor clearColor];
  2714. //// if(section==0)
  2715. //// titleLabel.text=NSLocalizedString(@"display_items", nil);
  2716. //// else
  2717. //// titleLabel.text=NSLocalizedString(@"hide_items", nil);
  2718. //// [titleLabel sizeToFit];
  2719. //// [myView addSubview:titleLabel];
  2720. ////
  2721. // return myView;
  2722. //}
  2723. //
  2724. //- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  2725. // if(section==0)
  2726. // return nil;
  2727. // else
  2728. // return @"detail section";
  2729. //}
  2730. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  2731. {
  2732. if (self.back_order_flag) {
  2733. return [[self.cart_json objectForKey:@"section_count"] integerValue];
  2734. } else {
  2735. return 1;
  2736. }
  2737. }
  2738. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  2739. {
  2740. #ifdef SCANNER_ORDER
  2741. return 0;
  2742. #endif
  2743. if (self.back_order_flag) {
  2744. return 50;
  2745. } else {
  2746. return 0;
  2747. }
  2748. }
  2749. - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  2750. {
  2751. #ifdef SCANNER_ORDER
  2752. return nil;
  2753. #endif
  2754. if (self.back_order_flag) {
  2755. // UIView *header = [tableView dequeueReusableCellWithIdentifier:@"section_header_cell"];
  2756. // UILabel *title_lb = [header viewWithTag:8520];
  2757. UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(tableView.bounds), 50.0f)];
  2758. header.backgroundColor = [UIColor colorWithRed:128 / 255.0 green:95 / 255.0 blue:54 / 255.0 alpha:1];
  2759. header.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  2760. UILabel *title_lb = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, CGRectGetWidth(header.bounds) - 10, 50.0f)];
  2761. title_lb.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  2762. title_lb.font = [UIFont systemFontOfSize:25.0f];
  2763. title_lb.textColor = [UIColor whiteColor];
  2764. [header addSubview:title_lb];
  2765. title_lb.text = [self titleForSection:section];
  2766. return header;
  2767. } else {
  2768. return nil;
  2769. }
  2770. }
  2771. #ifdef SCANNER_ORDER
  2772. - (IBAction)onScanChangeCustomerType:(id)sender {
  2773. return;
  2774. NSString *orderdir =[OLDataProvider getScanPath];
  2775. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Select Customer type" message:@"" preferredStyle:UIAlertControllerStyleAlert];
  2776. //block代码块取代了delegate
  2777. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Existing Customer" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  2778. NSMutableDictionary* dict = nil;
  2779. NSString* ordertemplate = nil;
  2780. if([RADataProvider getSiteHasERP])
  2781. ordertemplate =@"e_order.json";
  2782. else
  2783. ordertemplate =@"e_order_noerp.json";
  2784. dict=[OLDataProvider loadScanTemplate:ordertemplate];
  2785. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  2786. [RAUtils dicttofile:orderPath dict:dict];
  2787. //
  2788. // NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  2789. //
  2790. //
  2791. //
  2792. // [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  2793. //
  2794. // [self scanPlaceOrder];
  2795. //
  2796. }];
  2797. UIAlertAction *alert2 = [UIAlertAction actionWithTitle:@"New customer" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  2798. NSMutableDictionary* dict = nil;
  2799. dict=[OLDataProvider loadScanTemplate:@"n_order.json"];
  2800. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  2801. [RAUtils dicttofile:orderPath dict:dict];
  2802. //
  2803. //
  2804. // NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  2805. //
  2806. //
  2807. //
  2808. // [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  2809. // [self scanPlaceOrder];
  2810. }];
  2811. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  2812. DebugLog(@"No");
  2813. }];
  2814. [alertControl addAction:actionOne];
  2815. [alertControl addAction:alert2];
  2816. [alertControl addAction:alertthree];
  2817. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  2818. [self presentViewController:alertControl animated:YES completion:nil];
  2819. DebugLog(@"%@",self.edit_select_arr);
  2820. }
  2821. #endif
  2822. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  2823. {
  2824. if (self.back_order_flag) {
  2825. return [self itemCountInSection:section];
  2826. } else {
  2827. // NSDictionary * item_json = [self.content_data objectForKey:@"items"];
  2828. long count =self.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  2829. return count;
  2830. }
  2831. }
  2832. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  2833. {
  2834. // if(tableView==self.itemListTable)
  2835. // {
  2836. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2837. NSString *CellIdentifier;
  2838. #ifdef SCANNER_ORDER
  2839. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2840. CellIdentifier = @"ScanCartItemCell";
  2841. ScanCartItemCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2842. NSDictionary * item_json = nil;//[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  2843. item_json = [self itemJsonAtIndexPath:indexPath];
  2844. NSString* notes = [item_json valueForKey:@"note"];
  2845. if(notes.length>0)
  2846. {
  2847. cell.labelNotes.text = notes;
  2848. }
  2849. else
  2850. {
  2851. cell.labelNotes.text = nil;
  2852. }
  2853. NSString* description =[item_json valueForKey:@"description"];
  2854. NSString* model =[item_json valueForKey:@"model"];
  2855. NSString* dimension =[item_json valueForKey:@"dimension"] ;
  2856. int count =[[item_json valueForKey:@"count"] intValue];
  2857. int stockUom =[[item_json valueForKey:@"stockUom"] intValue];
  2858. double unitprice=[[item_json valueForKey:@"unit_price"] doubleValue];
  2859. double discount=[[item_json valueForKey:@"discount"] doubleValue];
  2860. cell.discount = discount;
  2861. if(appDelegate.user_type == USER_ROLE_CUSTOMER)
  2862. {
  2863. cell.btnScanDiscount.hidden = true;
  2864. }
  2865. else
  2866. {
  2867. switch(RASingleton.sharedInstance.price_type)
  2868. {
  2869. case 0: cell.btnScanDiscount.hidden = true;
  2870. break;;
  2871. case 1:
  2872. {
  2873. if(![item_json[@"special_price"] boolValue]&&![item_json[@"net_price"] boolValue])
  2874. cell.btnScanDiscount.hidden = false;
  2875. else
  2876. cell.btnScanDiscount.hidden = true;
  2877. }
  2878. break;;
  2879. // case 2: pricename = @"25%";
  2880. // break;
  2881. }
  2882. }
  2883. NSString* product_id = [item_json valueForKey:@"product_id"];
  2884. CGRect frame = cell.frame;
  2885. cell.labelMpack.text =[NSString stringWithFormat:@"Sold in QTY of:%d", stockUom];
  2886. __weak typeof(self) weakSelf = self;
  2887. cell.onReturnQTY=^(int qty,NSDictionary* ext)
  2888. {
  2889. int result = [[ext objectForKey:@"result"] intValue];
  2890. BOOL refresh = [[ext objectForKey:@"refresh"] boolValue];
  2891. if (result == 2 && refresh) {
  2892. [self ReloadData];
  2893. return;
  2894. }
  2895. NSMutableDictionary * item_json = nil;
  2896. if (weakSelf.back_order_flag) {
  2897. item_json = [[weakSelf itemJsonAtIndexPath:indexPath] mutableCopy];
  2898. } else {
  2899. item_json = [weakSelf.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2900. }
  2901. // int count=[[item_json valueForKey:@"count"] intValue];
  2902. // if(count==qty)
  2903. // return;
  2904. if ([[ext valueForKey:@"result"] integerValue] == 8) {
  2905. return ;
  2906. }
  2907. [item_json setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"count"];
  2908. double unit_cuft = [[item_json valueForKey:@"unit_cuft"] doubleValue];
  2909. [item_json setValue:[NSString stringWithFormat:@"%f",unit_cuft*qty] forKey:@"cuft"];
  2910. // [item_json setValue:[ext valueForKey:@"carton"] forKey:@"carton"];
  2911. // [item_json setValue:[ext valueForKey:@"weight"] forKey:@"weight"];
  2912. double unit_price = [[item_json valueForKey:@"unit_price"] doubleValue];
  2913. // double sub_total=[[item_json valueForKey:@"subtotal_price"] doubleValue];
  2914. [item_json setValue:[NSString stringWithFormat:@"%f",unit_price*qty*(1-discount/100.0)] forKey:@"subtotal_price"];
  2915. if (weakSelf.back_order_flag) {
  2916. [weakSelf updateItemJson:item_json atIndexPath:indexPath];
  2917. } else {
  2918. weakSelf.content_arr[indexPath.row]= item_json;
  2919. }
  2920. // [self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  2921. [weakSelf refresh_total];
  2922. #ifdef RA_NOTIFICATION
  2923. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2924. #else
  2925. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2926. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2927. #endif
  2928. };
  2929. // cell.delegate=self;
  2930. // cell.from=indexPath;
  2931. NSDictionary* price_group = [RADataProvider get_price_group:appDelegate.price_group];
  2932. if(RASingleton.sharedInstance.price_type==1&&([item_json[@"net_price"] boolValue]||[item_json[@"special_price"] boolValue]||discount>0))
  2933. {
  2934. cell.labelUnitPrice.textColor= [UIColor redColor];
  2935. if([item_json[@"special_price"] boolValue]||discount>0)
  2936. {
  2937. cell.labelOldPrice.hidden = false;
  2938. // if([item_json[@"special_price"] boolValue])
  2939. // {
  2940. cell.labelOldPrice.text=[RAConvertor currencyNumber:[item_json[price_group[@"price_1"][@"name"]] doubleValue]];//[NSString stringWithFormat:@"%.2f",[item_json[@"price1"] doubleValue]];
  2941. // }
  2942. // else
  2943. // {
  2944. // }
  2945. }
  2946. else
  2947. cell.labelOldPrice.hidden = true;
  2948. }
  2949. else
  2950. {
  2951. cell.labelUnitPrice.textColor= [UIColor blackColor];
  2952. cell.labelOldPrice.hidden = true;
  2953. }
  2954. // if(discount>0)
  2955. // {
  2956. // cell.labelNotes.text = [NSString stringWithFormat:@"Note: discount %d%% off.",(int)discount];
  2957. // cell.labelOldPrice.hidden = false;
  2958. //// cell.labelOldPrice.textColor = [UIColor redColor];
  2959. // cell.labelUnitPrice.textColor= [UIColor redColor];
  2960. // cell.labelOldPrice.text=[item_json[@"unit_price"] stringValue];
  2961. // frame.size.height = 120;
  2962. // }
  2963. // else
  2964. // {
  2965. //
  2966. //
  2967. // cell.labelOldPrice.hidden = true;
  2968. // cell.labelNotes.text = nil;
  2969. // frame.size.height = 94;
  2970. // }
  2971. cell.unit_price = unitprice;
  2972. // cell.labelAttribute.text = attribute;
  2973. // cell.labelCurrency.text = currency;
  2974. NSString* subtotal = [RAConvertor currencyNumber:unitprice*count*(1-discount/100)];//[NSString stringWithFormat:@"%.2f",unitprice*count*(1-discount/100)];
  2975. NSString* newunitprice = [RAConvertor currencyNumber:unitprice*(1-discount/100)];//[NSString stringWithFormat:@"%.2f",unitprice*(1-discount/100)];
  2976. cell.labelModel.text = model;
  2977. cell.labelDescription.text = [NSString stringWithFormat:@"%@\n%@",description,dimension];
  2978. // if(noprice&&unitprice==0.0)
  2979. // {
  2980. // cell.labelPrice.text = @"No Price";
  2981. //
  2982. // cell.labelUnitPrice.text = @"No Price";
  2983. // }
  2984. // else
  2985. {
  2986. cell.labelSubtotal.text = subtotal;
  2987. cell.labelUnitPrice.text = newunitprice;
  2988. }
  2989. bool check = [[item_json valueForKey:@"check"] boolValue];
  2990. NSString* cart_item_id= [item_json valueForKey:@"cart_item_id"];
  2991. cell.cart_id = cart_item_id;
  2992. if(/*appDelegate.user_type==USER_ROLE_CUSTOMER*/ true)
  2993. [cell init_Stepper:stockUom max:9999 min:stockUom value:count];
  2994. // else
  2995. // [cell init_Stepper:1 max:9999 min:1 value:count];
  2996. [cell set_Count:count];
  2997. // Button 设置了大小约束,Size就不会随内容变化
  2998. cell.backgroundColor = [UIColor whiteColor];
  2999. return cell;
  3000. #else
  3001. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3002. CellIdentifier = @"CartItemCell";
  3003. ModelItemCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  3004. NSDictionary * item_json = nil;//[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  3005. if (self.back_order_flag) {
  3006. item_json = [self itemJsonAtIndexPath:indexPath];
  3007. } else {
  3008. item_json = self.content_arr[indexPath.row];
  3009. }
  3010. NSDictionary * combine_json =[item_json objectForKey:@"combine"];
  3011. NSDictionary * master_json = [item_json objectForKey:@"combine_master"];
  3012. if (cell.masterBtn != nil) {
  3013. if (master_json == nil) {
  3014. cell.masterBtn.hidden = YES;
  3015. } else{
  3016. cell.masterBtn.hidden = NO;
  3017. cell.master_items = master_json;
  3018. }
  3019. }
  3020. bool isfree = [[item_json valueForKey:@"is_free"]boolValue];
  3021. NSString* notes = [item_json valueForKey:@"note"];
  3022. BOOL is_out_of_stock = [[item_json valueForKey:@"is_out_of_stock"] boolValue];
  3023. bool noprice =[[item_json valueForKey:@"is_no_price"]boolValue];
  3024. cell.noprice = noprice;
  3025. cell.enable_longpress = true;
  3026. cell.bundle_item=combine_json;
  3027. NSString* img_url = [item_json valueForKey:@"img_url"];
  3028. NSString* description = [item_json valueForKey:@"description"];
  3029. // NSString* identifier = [item_json valueForKey:@"identifier"];
  3030. // NSString* attribute = [item_json valueForKey:@"attribute"];
  3031. // NSString* currency = [item_json valueForKey:@"currency"];
  3032. int count =[[item_json valueForKey:@"count"] intValue];
  3033. int stockUom =[[item_json valueForKey:@"stockUom"] intValue];
  3034. // double totalprice =[[item_json valueForKey:@"subtotal_price"] doubleValue];
  3035. double unitprice=[[item_json valueForKey:@"unit_price"] doubleValue];
  3036. double discount =[[item_json valueForKey:@"discount"] doubleValue];
  3037. NSString* product_id = [item_json valueForKey:@"product_id"];
  3038. // handle no such model
  3039. if(product_id.length==0)
  3040. cell.labelNoSuchModel.hidden=false;
  3041. else
  3042. cell.labelNoSuchModel.hidden=true;
  3043. //if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  3044. if (!is_out_of_stock) {
  3045. cell.labelOutOfStock.hidden = YES;
  3046. } else {
  3047. cell.labelOutOfStock.hidden = NO;
  3048. }
  3049. // } else {
  3050. // cell.labelOutOfStock.hidden = YES;
  3051. // }
  3052. // discount = 5.0;
  3053. cell.discount = discount;
  3054. CGRect frame = cell.frame;
  3055. if(notes.length>0)
  3056. {
  3057. cell.labelNotes.text = [@"Note: " stringByAppendingString:[notes stringByReplacingOccurrencesOfString:@"\n" withString:@" "]];
  3058. frame.size.height = 146;
  3059. }
  3060. else
  3061. {
  3062. cell.labelNotes.text = nil;
  3063. frame.size.height = 120;
  3064. }
  3065. // cell.frame = frame;
  3066. NSString* discountstr=[NSString stringWithFormat:@"%@%% off", [RAUtils FloatFormat:discount]];
  3067. if(isfree)
  3068. {
  3069. cell.labelOldPrice.hidden = false;
  3070. cell.labelOldPrice.textColor = [UIColor redColor];
  3071. cell.labelOldPrice.text=@"Free";
  3072. cell.labelOldPrice.hideline = true;
  3073. cell.labelDiscount.hidden = true;
  3074. }
  3075. else
  3076. {
  3077. cell.labelOldPrice.textColor = [UIColor blackColor];
  3078. cell.labelOldPrice.hideline = false;
  3079. if(discount==0)
  3080. {
  3081. cell.labelOldPrice.hidden = true;
  3082. cell.labelDiscount.hidden = true;
  3083. }
  3084. else
  3085. {
  3086. cell.labelOldPrice.hidden = false;
  3087. cell.labelDiscount.hidden = false;
  3088. }
  3089. }
  3090. __weak typeof(self) weakSelf = self;
  3091. cell.onReturnQTY=^(int qty,NSDictionary* ext)
  3092. {
  3093. int result = [[ext objectForKey:@"result"] intValue];
  3094. BOOL refresh = [[ext objectForKey:@"refresh"] boolValue];
  3095. if (result == 2 && refresh) {
  3096. [self ReloadData];
  3097. return;
  3098. }
  3099. NSMutableDictionary * item_json = nil;
  3100. if (weakSelf.back_order_flag) {
  3101. item_json = [[weakSelf itemJsonAtIndexPath:indexPath] mutableCopy];
  3102. } else {
  3103. item_json = [weakSelf.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  3104. }
  3105. // int count=[[item_json valueForKey:@"count"] intValue];
  3106. // if(count==qty)
  3107. // return;
  3108. if ([[ext valueForKey:@"result"] integerValue] == 8) {
  3109. return ;
  3110. }
  3111. [item_json setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"count"];
  3112. [item_json setValue:[ext valueForKey:@"cuft"] forKey:@"cuft"];
  3113. [item_json setValue:[ext valueForKey:@"carton"] forKey:@"carton"];
  3114. [item_json setValue:[ext valueForKey:@"weight"] forKey:@"weight"];
  3115. double unit_price = [[item_json valueForKey:@"unit_price"] doubleValue];
  3116. // double sub_total=[[item_json valueForKey:@"subtotal_price"] doubleValue];
  3117. [item_json setValue:[NSString stringWithFormat:@"%f",unit_price*qty] forKey:@"subtotal_price"];
  3118. if (weakSelf.back_order_flag) {
  3119. [weakSelf updateItemJson:item_json atIndexPath:indexPath];
  3120. } else {
  3121. weakSelf.content_arr[indexPath.row]= item_json;
  3122. }
  3123. // [self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  3124. [weakSelf refresh_total];
  3125. #ifdef RA_NOTIFICATION
  3126. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  3127. #else
  3128. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3129. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  3130. #endif
  3131. };
  3132. // cell.delegate=self;
  3133. // cell.from=indexPath;
  3134. cell.unit_price = unitprice;
  3135. // cell.labelAttribute.text = attribute;
  3136. // cell.labelCurrency.text = currency;
  3137. NSString* oldprice =[NSString stringWithFormat:@"%.2f",unitprice];
  3138. NSString* newprice = [NSString stringWithFormat:@"%.2f",unitprice* (1.0-discount/100)*count];
  3139. NSString* newunitprice = [NSString stringWithFormat:@"%.2f",unitprice* (1.0-discount/100)];
  3140. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  3141. {
  3142. }
  3143. else
  3144. {
  3145. oldprice=nil;
  3146. newprice=nil;
  3147. newunitprice=nil;
  3148. }
  3149. cell.labelDiscount.text = discountstr;
  3150. cell.labelOldPrice.text = oldprice;
  3151. cell.labelMasterpack.text =[NSString stringWithFormat:@"Sold in QTY of:%d", stockUom];
  3152. cell.labelDescription.text = description;
  3153. // cell.labelIdentifier.text = identifier;
  3154. if(noprice&&unitprice==0.0)
  3155. {
  3156. cell.labelPrice.text = @"No Price";
  3157. cell.labelUnitPrice.text = @"No Price";
  3158. }
  3159. else
  3160. {
  3161. cell.labelPrice.text = newprice;
  3162. cell.labelUnitPrice.text = newunitprice;
  3163. }
  3164. bool check = [[item_json valueForKey:@"check"] boolValue];
  3165. if(check)
  3166. {
  3167. cell.img_checkmark.hidden=false;
  3168. // [item_json setValue:@"0" forKey:@"check"];
  3169. }
  3170. else
  3171. {
  3172. // [item_json setValue:@"1" forKey:@"check"];
  3173. cell.img_checkmark.hidden=true;
  3174. }
  3175. NSString* cart_item_id= [item_json valueForKey:@"cart_item_id"];
  3176. cell.cart_id = cart_item_id;
  3177. if(/*appDelegate.user_type==USER_ROLE_CUSTOMER*/ true)
  3178. {
  3179. #ifdef IGNORE_MPACK
  3180. [cell init_Stepper:1 max:9999 min:1 value:count];
  3181. #else
  3182. [cell init_Stepper:stockUom max:9999 min:stockUom value:count];
  3183. #endif
  3184. }
  3185. // else
  3186. // [cell init_Stepper:1 max:9999 min:1 value:count];
  3187. [cell set_Count:count];
  3188. // Button 设置了大小约束,Size就不会随内容变化
  3189. [cell.btnImage setContentMode:UIViewContentModeScaleAspectFit];
  3190. [cell.btnImage setContentEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
  3191. [cell.btnImage setContentHorizontalAlignment:UIControlContentHorizontalAlignmentFill];
  3192. [cell.btnImage setContentVerticalAlignment:UIControlContentVerticalAlignmentFill];
  3193. cell.btnImage.imageView.contentMode = UIViewContentModeScaleAspectFit;
  3194. if (![cell.imageName isEqualToString:img_url]) {
  3195. cell.imageName = img_url;
  3196. // [cell.btnImage setBackgroundImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal];
  3197. [cell.btnImage setImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal];
  3198. NSString* file_name=[img_url lastPathComponent];
  3199. NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  3200. if(img_data!=nil)
  3201. {
  3202. UIImage * img =[UIImage imageWithData:img_data];
  3203. // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  3204. [cell.btnImage setImage:img forState:UIControlStateNormal];
  3205. }
  3206. else
  3207. {
  3208. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  3209. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  3210. dispatch_async(dispatch_get_main_queue(), ^{
  3211. if(downloadimg_data!=nil)
  3212. {
  3213. [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
  3214. UIImage * img =[UIImage imageWithData:downloadimg_data];
  3215. // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  3216. [cell.btnImage setImage:img forState:UIControlStateNormal];
  3217. }
  3218. else
  3219. {
  3220. // [cell.btnImage setBackgroundImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
  3221. [cell.btnImage setImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
  3222. }
  3223. });
  3224. });
  3225. }
  3226. }
  3227. cell.backgroundColor = [UIColor whiteColor];
  3228. if(self.itemListTable.editing)
  3229. {
  3230. cell.editCount.enabled = false;
  3231. cell.stepper.hidden=true;
  3232. }
  3233. else
  3234. {
  3235. cell.editCount.enabled=true;
  3236. cell.stepper.hidden=false;
  3237. }
  3238. return cell;
  3239. // }
  3240. // else
  3241. // {
  3242. // NSString *CellIdentifier = @"OrderInfoListItem";
  3243. // UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  3244. // return cell;
  3245. // }
  3246. #endif
  3247. }
  3248. -(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
  3249. {
  3250. if(!self.itemListTable.editing)
  3251. return;
  3252. // NSMutableDictionary * item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  3253. NSMutableDictionary * item_json = nil;
  3254. if (self.back_order_flag) {
  3255. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  3256. } else {
  3257. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  3258. }
  3259. NSString *cart_item_id=[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  3260. if ([self.edit_select_arr containsObject:cart_item_id])
  3261. {
  3262. [self.edit_select_arr removeObject:cart_item_id];
  3263. }
  3264. }
  3265. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  3266. {
  3267. #ifdef SCANNER_ORDER
  3268. return;
  3269. #endif
  3270. NSMutableDictionary * item_json = nil;
  3271. if (self.back_order_flag) {
  3272. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  3273. } else {
  3274. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  3275. }
  3276. // NSMutableDictionary * item_json =[self.content_arr[indexPath.row] mutableCopy];// [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  3277. if(self.itemListTable.editing)
  3278. {
  3279. NSString *cart_item_id=[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  3280. if (![self.edit_select_arr containsObject:cart_item_id]) {
  3281. [self.edit_select_arr addObject:cart_item_id];
  3282. }
  3283. return;
  3284. }
  3285. // no checkmark support anymore for cart
  3286. return;
  3287. // ModelItemCell* cell = (ModelItemCell*)[tableView cellForRowAtIndexPath:indexPath];
  3288. //
  3289. //
  3290. // cell.selected = false;
  3291. // // self.dirty = true;
  3292. //
  3293. //
  3294. // bool check = [[item_json valueForKey:@"check"] boolValue];
  3295. // if(check)
  3296. // {
  3297. // [item_json setValue:@"false" forKey:@"check"];
  3298. // cell.img_checkmark.hidden=true;
  3299. // [self.btnselect setTitle: @"Select all" forState: UIControlStateNormal];
  3300. // // double totalprice =[[item_json valueForKey:@"subtotal_price"] doubleValue];
  3301. // // self.total-=totalprice;
  3302. // }
  3303. // else
  3304. // {
  3305. // [item_json setValue:@"true" forKey:@"check"];
  3306. // cell.img_checkmark.hidden=false;
  3307. // // double totalprice =[[item_json valueForKey:@"subtotal_price"] doubleValue];
  3308. // // self.total+=totalprice;
  3309. // }
  3310. //
  3311. //
  3312. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  3313. //
  3314. //
  3315. // NSString *ids=[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  3316. //
  3317. // NSDictionary* check_json = [iSalesNetwork cart_check:ids];
  3318. //
  3319. // dispatch_async(dispatch_get_main_queue(), ^{
  3320. //
  3321. //
  3322. //
  3323. // if([[check_json valueForKey:@"result"] intValue]==2)
  3324. // {
  3325. //
  3326. //
  3327. // if([item_json[@"check"] boolValue]==false)
  3328. // item_json[@"check"]= @"false";
  3329. // else
  3330. // item_json[@"check"]= @"true";
  3331. //
  3332. // self.content_arr[indexPath.row] = item_json;
  3333. // //[self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  3334. //
  3335. //
  3336. // [self reload_container_getdata:false];
  3337. //
  3338. //
  3339. // }
  3340. // else
  3341. // {
  3342. // [RAUtils message_alert:[check_json valueForKey:@"err_msg"] title:nil controller:self] ;
  3343. // }
  3344. //
  3345. //
  3346. //
  3347. // });
  3348. // });
  3349. //
  3350. // //debug
  3351. // //[self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  3352. //
  3353. // [self refresh_total];
  3354. //self.labelTotal.text=[NSString stringWithFormat:@"$%.2f",self.total];
  3355. }
  3356. - (UITableViewCellEditingStyle)tableView:(UITableView *)tv editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
  3357. if(self.itemListTable.editing)
  3358. return UITableViewCellEditingStyleDelete | UITableViewCellEditingStyleInsert;
  3359. else
  3360. return UITableViewCellEditingStyleDelete;
  3361. }
  3362. #pragma mark 在滑动手势删除某一行的时候,显示出更多的按钮
  3363. - (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
  3364. {
  3365. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3366. // 添加一个删除按钮
  3367. self.indexPath=indexPath;
  3368. NSMutableDictionary * item_json = nil;
  3369. if (self.back_order_flag) {
  3370. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  3371. } else {
  3372. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  3373. }
  3374. NSString* productID = [item_json valueForKey:@"product_id"];
  3375. BOOL outOfStock = [[item_json valueForKey:@"is_out_of_stock"] boolValue];
  3376. __weak typeof(self) weakself = self;
  3377. UITableViewRowAction *deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@" Delete " handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  3378. DebugLog(@"delete click");
  3379. //[self.itemListTable setEditing:false animated:YES];
  3380. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Confirm Deletion" message:@"Are you sure to delete this model?" preferredStyle:UIAlertControllerStyleAlert];
  3381. UIAlertAction *action_2 = [UIAlertAction actionWithTitle:@"YES" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  3382. // [self.itemListTable reloadRowsAtIndexPaths:@[self.indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  3383. NSMutableDictionary * item_json = nil;
  3384. if (self.back_order_flag) {
  3385. item_json = [[self itemJsonAtIndexPath:self.indexPath] mutableCopy];
  3386. } else {
  3387. item_json = [self.content_arr[self.indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  3388. }
  3389. NSString *ids=[NSString stringWithFormat:@"%@",[item_json valueForKey:@"cart_item_id"] ];
  3390. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Remove Model" completion:^{
  3391. [RANetwork request_remove_cart:ids completionHandler:^(NSMutableDictionary *result) {
  3392. NSMutableDictionary* cart_json = result;
  3393. [waitalert dismissViewControllerAnimated:YES completion:^{
  3394. if([[cart_json valueForKey:@"result"] intValue]==2)
  3395. {
  3396. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3397. if (self.back_order_flag) {
  3398. NSInteger section_count = [self sectionCount];
  3399. for (int i = 0; i < section_count; i++) {
  3400. NSInteger item_count = [self itemCountInSection:i];
  3401. BOOL ready_break = NO;
  3402. for (int j = 0; j < item_count; j++) {
  3403. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:j inSection:i];
  3404. NSDictionary* obj_json = [self itemJsonAtIndexPath:indexPath];
  3405. NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  3406. if([_id isEqualToString:ids])
  3407. {
  3408. [self updateItemJson:nil atIndexPath:indexPath];
  3409. ready_break = YES;
  3410. break;
  3411. }
  3412. }
  3413. if (ready_break) {
  3414. break;
  3415. }
  3416. }
  3417. } else {
  3418. for(int i=0;i<self.content_arr.count;i++)
  3419. {
  3420. NSDictionary* obj_json = self.content_arr[i];
  3421. NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  3422. if([_id isEqualToString:ids])
  3423. {
  3424. [self.content_arr removeObjectAtIndex:i];
  3425. // [self.itemListTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:self.indexPath] withRowAnimation:UITableViewRowAnimationLeft];
  3426. break;
  3427. // appDelegate.cart_count--;
  3428. // [appDelegate update_count_mark];
  3429. }
  3430. }
  3431. }
  3432. #ifdef SCANNER_ORDER
  3433. self.cart_json = cart_json;
  3434. #endif
  3435. [self.itemListTable reloadData];
  3436. [self refresh_total];
  3437. #ifdef RA_NOTIFICATION
  3438. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  3439. #else
  3440. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3441. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  3442. #endif
  3443. // [self reload_data];
  3444. }
  3445. else
  3446. {
  3447. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
  3448. }
  3449. }];
  3450. }];
  3451. }];
  3452. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  3453. //
  3454. // NSDictionary* cart_json = [RANetwork cart_remove:ids];
  3455. //
  3456. // dispatch_async(dispatch_get_main_queue(), ^{
  3457. //
  3458. //
  3459. //
  3460. // if([[cart_json valueForKey:@"result"] intValue]==2)
  3461. // {
  3462. // // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3463. // if (self.back_order_flag) {
  3464. //
  3465. // NSInteger section_count = [self sectionCount];
  3466. // for (int i = 0; i < section_count; i++) {
  3467. // NSInteger item_count = [self itemCountInSection:i];
  3468. // BOOL ready_break = NO;
  3469. //
  3470. // for (int j = 0; j < item_count; j++) {
  3471. // NSIndexPath *indexPath = [NSIndexPath indexPathForRow:j inSection:i];
  3472. // NSDictionary* obj_json = [self itemJsonAtIndexPath:indexPath];
  3473. // NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  3474. // if([_id isEqualToString:ids])
  3475. // {
  3476. // [self updateItemJson:nil atIndexPath:indexPath];
  3477. // ready_break = YES;
  3478. // break;
  3479. // }
  3480. // }
  3481. //
  3482. // if (ready_break) {
  3483. // break;
  3484. // }
  3485. // }
  3486. //
  3487. // } else {
  3488. // for(int i=0;i<self.content_arr.count;i++)
  3489. // {
  3490. // NSDictionary* obj_json = self.content_arr[i];
  3491. // NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  3492. // if([_id isEqualToString:ids])
  3493. // {
  3494. // [self.content_arr removeObjectAtIndex:i];
  3495. // // [self.itemListTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:self.indexPath] withRowAnimation:UITableViewRowAnimationLeft];
  3496. // break;
  3497. // // appDelegate.cart_count--;
  3498. // // [appDelegate update_count_mark];
  3499. // }
  3500. //
  3501. // }
  3502. // }
  3503. // [self.itemListTable reloadData];
  3504. // [self refresh_total];
  3505. // #ifdef RA_NOTIFICATION
  3506. // [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  3507. // #else
  3508. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3509. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  3510. // #endif
  3511. // // [self reload_data];
  3512. // }
  3513. // else
  3514. // {
  3515. // [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
  3516. // }
  3517. //
  3518. // });
  3519. // });
  3520. }];
  3521. UIAlertAction *action_3 = [UIAlertAction actionWithTitle:@"NO" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  3522. }];
  3523. [alertController addAction:action_2];
  3524. [alertController addAction:action_3];
  3525. [self presentViewController:alertController animated:YES completion:nil];
  3526. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Delete confirm", nil) message:NSLocalizedString(@"Are you sure remove model from cart?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
  3527. // alert.tag = ALERT_DEL;
  3528. // // alert.
  3529. // [alert show];
  3530. }];
  3531. deleteRowAction.backgroundColor = [UIColor redColor];
  3532. UITableViewRowAction *notifyMeAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Notify Me" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
  3533. {
  3534. __block UIAlertController *waitting_alert = [RAUtils waiting_alert:self title:@"Sending Email" completion:^{
  3535. [RANetwork request_notifymodel:productID emailAddr:nil withScreen:ScreenCodeCart completionHandler:^(NSMutableDictionary *result) {
  3536. NSMutableDictionary *dic = result;
  3537. // [waitting_alert dismissWithClickedButtonIndex:0 animated:NO];
  3538. [waitting_alert dismissViewControllerAnimated:YES completion:^{
  3539. int result_code = [[dic valueForKey:@"result"] intValue];
  3540. if (result_code != RESULT_TRUE && result_code != RESULT_NO_EMAIL_ADDRESS)
  3541. {
  3542. NSString *msg = [NSString stringWithFormat:@"The email send failed"];
  3543. if ([dic valueForKey:@"err_msg"]) {
  3544. msg = [dic valueForKey:@"err_msg"];
  3545. }
  3546. UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
  3547. UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  3548. }];
  3549. [errorAlertVC addAction:action];
  3550. [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  3551. } else if (result_code == RESULT_TRUE){
  3552. [RAUtils message_alert:@"Notification is sent to default email address." title:@"Message" controller:weakself];
  3553. } else if (result_code == RESULT_NO_EMAIL_ADDRESS) {
  3554. [weakself showAddressBoxToEmailProduct:productID];
  3555. }
  3556. }];
  3557. }];
  3558. }];
  3559. // dispatch_async(dispatch_get_global_queue(0,0), ^{
  3560. //
  3561. // NSDictionary *dic = [RANetwork notifyModel:productID emailAddr:nil withScreen:ScreenCodeCart];
  3562. //
  3563. // dispatch_async(dispatch_get_main_queue(), ^{
  3564. //
  3565. // [waitting_alert dismissWithClickedButtonIndex:0 animated:NO];
  3566. //
  3567. // NSInteger result = [[dic valueForKey:@"result"] integerValue];
  3568. //
  3569. // if (result != RESULT_TRUE && result != RESULT_NO_EMAIL_ADDRESS) {
  3570. //
  3571. // NSString *msg = [NSString stringWithFormat:@"The email send failed"];
  3572. //
  3573. // if ([dic valueForKey:@"err_msg"]) {
  3574. // msg = [dic valueForKey:@"err_msg"];
  3575. // }
  3576. //
  3577. //
  3578. // UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
  3579. // UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  3580. //
  3581. // }];
  3582. //
  3583. // [errorAlertVC addAction:action];
  3584. // [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  3585. //
  3586. // } else if (result == RESULT_TRUE){
  3587. //
  3588. // [RAUtils message_alert:@"Notification is sent to default email address." title:@"Message" controller:weakself];
  3589. //
  3590. // } else if (result == RESULT_NO_EMAIL_ADDRESS) {
  3591. //
  3592. // [weakself showAddressBoxToEmailProduct:productID];
  3593. //
  3594. // }
  3595. // });
  3596. //
  3597. //
  3598. // });
  3599. };
  3600. }];
  3601. notifyMeAction.backgroundColor = UIColorFromRGB(0x9BBF5A);
  3602. UITableViewRowAction *addWatchAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Move To Wish List" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  3603. DebugLog(@"Wishlist click");
  3604. NSMutableDictionary * item_json = nil;
  3605. if (self.back_order_flag) {
  3606. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  3607. } else {
  3608. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  3609. }
  3610. NSString* cart_item_id = [item_json valueForKey:@"cart_item_id"];
  3611. [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  3612. [RANetwork request_move_cart2wish:cart_item_id completionHandler:^(NSMutableDictionary *result) {
  3613. NSDictionary* return_json = result;
  3614. if([[return_json valueForKey:@"result"] intValue]==2)
  3615. {
  3616. #ifdef RA_NOTIFICATION
  3617. [ActiveViewController Notify:@"WatchListViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  3618. #else
  3619. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3620. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  3621. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  3622. #endif
  3623. for(int i=0;i<self.content_arr.count;i++)
  3624. {
  3625. NSDictionary* obj_json = self.content_arr[i];
  3626. NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  3627. if([_id isEqualToString:cart_item_id])
  3628. {
  3629. if (self.back_order_flag) {
  3630. [self updateItemJson:nil atIndexPath:indexPath];
  3631. } else {
  3632. [self.content_arr removeObjectAtIndex:i];
  3633. }
  3634. [self.itemListTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
  3635. appDelegate.cart_count--;
  3636. [appDelegate update_count_mark];
  3637. [self refresh_total];
  3638. }
  3639. }
  3640. [self.itemListTable reloadData];
  3641. }
  3642. else
  3643. {
  3644. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Move To Wish List" controller:self] ;
  3645. }
  3646. }];
  3647. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  3648. //// ModelItemCell* cell=[self.itemListTable cellForRowAtIndexPath:indexPath];
  3649. //// [cell cancel_setQTY];
  3650. //
  3651. // NSDictionary* return_json = [RANetwork move_cart2wish:cart_item_id ];
  3652. //
  3653. // dispatch_async(dispatch_get_main_queue(), ^{
  3654. //
  3655. // if([[return_json valueForKey:@"result"] intValue]==2)
  3656. // {
  3657. //
  3658. //
  3659. //
  3660. //
  3661. //
  3662. //
  3663. //#ifdef RA_NOTIFICATION
  3664. // [ActiveViewController Notify:@"WatchListViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  3665. //#else
  3666. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3667. // [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  3668. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  3669. //
  3670. //#endif
  3671. //
  3672. //
  3673. // for(int i=0;i<self.content_arr.count;i++)
  3674. // {
  3675. // NSDictionary* obj_json = self.content_arr[i];
  3676. // NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  3677. // if([_id isEqualToString:cart_item_id])
  3678. // {
  3679. // if (self.back_order_flag) {
  3680. // [self updateItemJson:nil atIndexPath:indexPath];
  3681. // } else {
  3682. // [self.content_arr removeObjectAtIndex:i];
  3683. // }
  3684. // [self.itemListTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
  3685. // appDelegate.cart_count--;
  3686. // [appDelegate update_count_mark];
  3687. //
  3688. //
  3689. // [self refresh_total];
  3690. // }
  3691. //
  3692. // }
  3693. //
  3694. // [self.itemListTable reloadData];
  3695. //
  3696. // }
  3697. // else
  3698. // {
  3699. // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Move To Wish List" controller:self] ;
  3700. // }
  3701. //
  3702. //
  3703. //
  3704. // });
  3705. // });
  3706. }];
  3707. addWatchAction.backgroundColor = UIColorFromRGB(0x339966);
  3708. // 添加一个编辑按钮
  3709. UITableViewRowAction *editRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Edit Price"handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  3710. DebugLog(@"edit click");
  3711. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  3712. if (self.currentOrderIsMerged) { // 合并过的订单不能编辑价格
  3713. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Warning" message:@"Purchase Order Can't Edit Price" preferredStyle:UIAlertControllerStyleAlert];
  3714. UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  3715. [alert dismissViewControllerAnimated:YES completion:nil];
  3716. }];
  3717. [alert addAction:action];
  3718. if (weakself) {
  3719. __strong typeof(weakself) strongself = weakself;
  3720. [strongself presentViewController:alert animated:YES completion:nil];
  3721. }
  3722. return ;
  3723. }
  3724. if ([RASingleton sharedInstance].npd_shop_price_type == 0) { // 提货价不能编辑价格
  3725. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"Current Price Type is %@,You Can't Change it",[RASingleton sharedInstance].deliveryString] preferredStyle:UIAlertControllerStyleAlert];
  3726. UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  3727. [alert dismissViewControllerAnimated:YES completion:nil];
  3728. }];
  3729. [alert addAction:action];
  3730. if (weakself) {
  3731. __strong typeof(weakself) strongself = weakself;
  3732. [strongself presentViewController:alert animated:YES completion:nil];
  3733. }
  3734. return ;
  3735. }
  3736. }
  3737. UIViewController* parentvc=self;
  3738. EditModelPriceViewController * vc =[[UIStoryboard storyboardWithName:@"ERP_Mobile_Cart" bundle:nil] instantiateViewControllerWithIdentifier:@"EditModelPriceViewController"];
  3739. NSMutableDictionary * item_json = nil;
  3740. if (self.back_order_flag) {
  3741. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  3742. } else {
  3743. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  3744. }
  3745. vc.discount=[[item_json valueForKey:@"discount"] floatValue];
  3746. vc.price = [[item_json valueForKey:@"unit_price"] floatValue];
  3747. vc.cart_id = [item_json valueForKey:@"cart_item_id"];//[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  3748. __block NSString* cartid=[item_json valueForKey:@"cart_item_id"];
  3749. // vc.delegate = parentvc.self;
  3750. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  3751. vc.onSetValue = ^(double price,double discount){
  3752. bool bmodify=false;
  3753. if(price!= [[item_json valueForKey:@"unit_price"] floatValue])
  3754. bmodify=true;
  3755. NSString* notes = [item_json valueForKey:@"note"];
  3756. if(notes.length==0)
  3757. notes=@"";
  3758. if(bmodify)
  3759. {
  3760. if([notes isEqualToString:@""])
  3761. notes=@"PRICE MODIFIED";
  3762. NSRange range;
  3763. range = [notes rangeOfString:@"PRICE MODIFIED"];
  3764. if (range.location != NSNotFound) {
  3765. }else{
  3766. notes= [notes stringByAppendingString:@"\nPRICE MODIFIED"];
  3767. }
  3768. }
  3769. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Update Price" completion:^{
  3770. [RANetwork request_update_cart_modelprice:cartid price:price discount:discount notes:notes completionHandler:^(NSMutableDictionary *result) {
  3771. NSDictionary* cart_json = result;
  3772. [waitalert dismissViewControllerAnimated:YES completion:^{
  3773. if([[cart_json valueForKey:@"result"] intValue]==2)
  3774. {
  3775. [item_json setValue:[NSNumber numberWithDouble:price ] forKey:@"unit_price"];
  3776. [item_json setValue:[NSNumber numberWithDouble:discount ] forKey:@"discount"];
  3777. [item_json setValue:notes forKey:@"note"];
  3778. if (self.back_order_flag) {
  3779. [self updateItemJson:item_json atIndexPath:indexPath];
  3780. } else {
  3781. self.content_arr[indexPath.row ] = item_json;
  3782. }
  3783. tableView.editing = false;
  3784. // [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  3785. // [self refresh_total];
  3786. [weakself reload_data];
  3787. #ifdef RA_NOTIFICATION
  3788. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  3789. #else
  3790. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3791. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  3792. #endif
  3793. }
  3794. else
  3795. {
  3796. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Update Price" controller:self] ;
  3797. }
  3798. }];
  3799. }];
  3800. }];
  3801. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  3802. //
  3803. //
  3804. //
  3805. // NSDictionary* cart_json = nil;
  3806. //
  3807. // cart_json = [RANetwork cart_setPrice:[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]] price:price discount:discount notes:notes];
  3808. //
  3809. // dispatch_async(dispatch_get_main_queue(), ^{
  3810. //
  3811. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  3812. //
  3813. // if([[cart_json valueForKey:@"result"] intValue]==2)
  3814. // {
  3815. // [item_json setValue:[NSNumber numberWithDouble:price ] forKey:@"unit_price"];
  3816. //
  3817. // [item_json setValue:[NSNumber numberWithDouble:discount ] forKey:@"discount"];
  3818. // [item_json setValue:notes forKey:@"note"];
  3819. // if (self.back_order_flag) {
  3820. // [self updateItemJson:item_json atIndexPath:indexPath];
  3821. // } else {
  3822. // self.content_arr[indexPath.row ] = item_json;
  3823. // }
  3824. // tableView.editing = false;
  3825. //// [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  3826. //// [self refresh_total];
  3827. //
  3828. //
  3829. // [weakself reload_data];
  3830. //
  3831. //#ifdef RA_NOTIFICATION
  3832. // [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  3833. //#else
  3834. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3835. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  3836. //#endif
  3837. // }
  3838. // else
  3839. // {
  3840. // [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Update Price" controller:self] ;
  3841. // }
  3842. //
  3843. //
  3844. //
  3845. //
  3846. // });
  3847. // });
  3848. // [self reload_data];//[main_vc checklogin:true];
  3849. };
  3850. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  3851. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  3852. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  3853. [parentvc presentViewController:navi animated:YES completion:^{
  3854. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  3855. DebugLog(@"EditModelPriceViewController present.........");
  3856. // self.btop = false;
  3857. // <#code#>
  3858. }];
  3859. // [self.itemListTable setEditing:false animated:YES];
  3860. //[tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  3861. }];
  3862. editRowAction.backgroundColor = UIColorFromRGB(0xff9933);
  3863. // // 添加一个更多按钮
  3864. //
  3865. // UITableViewRowAction *moreRowAction = [UITableView RowActionrowActionWithStyle:UITableViewRowActionStyleNormal title:@"更多" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  3866. //
  3867. // DebugLog(@点击了更多);
  3868. //
  3869. //
  3870. // [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  3871. //
  3872. // }];
  3873. //
  3874. // moreRowAction.backgroundEffect = [UIBlurEffecteffectWithStyle:UIBlurEffectStyleDark];
  3875. //
  3876. // 将设置好的按钮放到数组中返回
  3877. // UITableViewRowAction *freeRowAction = nil;
  3878. //
  3879. //
  3880. // NSDictionary * item_json = [self.content_arr[indexPath.row] mutableCopy];//[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  3881. //
  3882. // bool isfree = [[item_json valueForKey:@"is_free"]boolValue];
  3883. //
  3884. // if(!isfree)
  3885. // {
  3886. //
  3887. // freeRowAction=[UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Set Free" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  3888. //
  3889. // DebugLog(@"free click");
  3890. //
  3891. //
  3892. //
  3893. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Free give away confirm", nil) message:NSLocalizedString(@"Are you sure make this model free?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
  3894. // alert.tag = ALERT_SET_FREE;
  3895. // // alert.
  3896. // [alert show];
  3897. // }];
  3898. // }
  3899. // else
  3900. // {
  3901. //
  3902. // freeRowAction=[UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Not Free" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  3903. //
  3904. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Restore free model confirm", nil) message:NSLocalizedString(@"Are you sure restore free model?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
  3905. // alert.tag = ALERT_RESTORE_FREE;
  3906. // // alert.
  3907. // [alert show];
  3908. // }];
  3909. // }
  3910. //
  3911. //
  3912. //
  3913. // freeRowAction.backgroundColor = [UIColor lightGrayColor];
  3914. UITableViewRowAction *noteRowAction = nil;
  3915. // NSDictionary * item_json = [self.content_arr[indexPath.row] mutableCopy];//[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  3916. noteRowAction=[UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Edit note" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  3917. DebugLog(@"item note click");
  3918. UIViewController* parentvc=self;
  3919. ItemNotesViewController * vc =[[UIStoryboard storyboardWithName:@"ERP_Mobile_Cart" bundle:nil] instantiateViewControllerWithIdentifier:@"ItemNotesViewController"];
  3920. NSMutableDictionary * item_json = nil;
  3921. if (self.back_order_flag) {
  3922. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  3923. } else {
  3924. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  3925. }
  3926. vc.onSaveNote=^(NSString* notes){
  3927. [item_json setValue:notes forKey:@"note"];
  3928. if (self.back_order_flag) {
  3929. [self updateItemJson:item_json atIndexPath:indexPath];
  3930. } else {
  3931. self.content_arr[indexPath.row ] = item_json;
  3932. }
  3933. tableView.editing = false;
  3934. [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  3935. };
  3936. vc.notes=[item_json valueForKey:@"note"];
  3937. vc.cart_id = [item_json valueForKey:@"cart_item_id"];//[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  3938. // vc.delegate = parentvc.self;
  3939. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  3940. // vc.onSetValue = ^(){
  3941. // [self reload_data];//[main_vc checklogin:true];
  3942. // };
  3943. //
  3944. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  3945. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  3946. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  3947. [parentvc presentViewController:navi animated:YES completion:^{
  3948. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  3949. DebugLog(@"EditModelPriceViewController present.........");
  3950. // self.btop = false;
  3951. // <#code#>
  3952. }];
  3953. // [self.itemListTable setEditing:false animated:YES];
  3954. // [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  3955. }];
  3956. noteRowAction.backgroundColor = [UIColor lightGrayColor];
  3957. UITableViewRowAction *move2BackAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Move to Back Order" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
  3958. NSDictionary *item_json = [self itemJsonAtIndexPath:indexPath];
  3959. NSString* cart_item_id = [item_json valueForKey:@"cart_item_id"];
  3960. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Move To Back Order" completion:^{
  3961. [RANetwork request_movetobackorder:cart_item_id completionHandler:^(NSMutableDictionary *result) {
  3962. NSMutableDictionary* return_json =result ;
  3963. [waitalert dismissViewControllerAnimated:YES completion:^{
  3964. if([[return_json valueForKey:@"result"] intValue]==2) {
  3965. [self reload_data];
  3966. } // if 2
  3967. else {
  3968. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Move To Back Order" controller:self] ;
  3969. }
  3970. }];
  3971. }];
  3972. }];
  3973. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  3974. //
  3975. // NSDictionary* return_json = [RANetwork movetobackorder:cart_item_id];
  3976. //
  3977. // dispatch_async(dispatch_get_main_queue(), ^{
  3978. //
  3979. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  3980. //
  3981. // if([[return_json valueForKey:@"result"] intValue]==2) {
  3982. //
  3983. // [self reload_data];
  3984. //
  3985. // } // if 2
  3986. // else {
  3987. // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Move To Back Order" controller:self] ;
  3988. // }
  3989. //
  3990. // }); // main
  3991. //
  3992. // }); // global
  3993. }];
  3994. move2BackAction.backgroundColor = UIColorFromRGB(0x336699);
  3995. if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  3996. {
  3997. NSMutableDictionary * item_json = nil;
  3998. if (self.back_order_flag) {
  3999. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  4000. } else {
  4001. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  4002. }
  4003. NSString* product_id = [item_json valueForKey:@"product_id"];
  4004. int is_rate = [item_json[@"is_rate"] intValue];
  4005. NSMutableArray* arr=[@[] mutableCopy];
  4006. BOOL condition = outOfStock;
  4007. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)|| defined (BUILD_CONTRAST)
  4008. #ifdef OFFLINE_MODE
  4009. condition = !appDelegate.offline_mode && outOfStock;
  4010. #endif
  4011. if (condition) {
  4012. [arr addObject:notifyMeAction];
  4013. }
  4014. NSDictionary *section_json = [self jsonAtSection:indexPath.section];
  4015. BOOL available = [[section_json objectForKey:@"available"] boolValue]; // available list
  4016. if (self.back_order_flag && available) {
  4017. [arr addObject:move2BackAction];
  4018. }
  4019. #endif
  4020. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  4021. #ifdef OFFLINE_MODE
  4022. condition = !appDelegate.offline_mode && outOfStock;
  4023. #endif
  4024. if (condition) {
  4025. [arr addObject:notifyMeAction];
  4026. }
  4027. #endif
  4028. if(product_id.length>0)
  4029. [arr addObject:noteRowAction];
  4030. [arr addObject:deleteRowAction];
  4031. #ifndef SCANNER_ORDER
  4032. if(product_id.length>0&& is_rate==0)
  4033. [arr addObject:addWatchAction];
  4034. if(appDelegate.can_set_cart_price && product_id.length>0&& is_rate==0)
  4035. {
  4036. [arr addObject:editRowAction];
  4037. // [arr addObject:freeRowAction];
  4038. }
  4039. #endif
  4040. return arr;
  4041. // return @[deleteRowAction,addWatchAction, editRowAction,freeRowAction];
  4042. } else if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  4043. if (appDelegate.customer_type == CustomerTypeStore) {
  4044. #ifndef SCANNER_ORDER
  4045. return @[notifyMeAction,deleteRowAction,addWatchAction,editRowAction];
  4046. #else
  4047. return @[deleteRowAction];
  4048. #endif
  4049. } else {
  4050. // normal
  4051. // NSArray *actionArray = @[notifyMeAction,deleteRowAction,addWatchAction];
  4052. NSMutableArray *actionArray = [NSMutableArray array];
  4053. // move to backorder
  4054. NSDictionary *section_json = [self jsonAtSection:indexPath.section];
  4055. BOOL available = [[section_json objectForKey:@"available"] boolValue]; // available list
  4056. if (self.back_order_flag && available) {
  4057. // actionArray = @[move2BackAction,notifyMeAction,deleteRowAction,addWatchAction];
  4058. [actionArray addObject:move2BackAction];
  4059. }
  4060. [actionArray addObjectsFromArray:@[notifyMeAction,deleteRowAction,addWatchAction]];
  4061. // edit price
  4062. NSMutableDictionary * item_json = nil;
  4063. if (self.back_order_flag) {
  4064. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  4065. } else {
  4066. item_json = [self.content_arr[indexPath.row] mutableCopy];
  4067. }
  4068. NSString* product_id = [item_json valueForKey:@"product_id"];
  4069. int is_rate = [item_json[@"is_rate"] intValue];
  4070. if(appDelegate.can_set_cart_price && product_id.length>0&& is_rate==0) {
  4071. // actionArray = @[move2BackAction,notifyMeAction,deleteRowAction,addWatchAction,editRowAction];
  4072. [actionArray addObject:editRowAction];
  4073. }
  4074. return actionArray;
  4075. }
  4076. }
  4077. else
  4078. #ifndef SCANNER_ORDER
  4079. return @[deleteRowAction,addWatchAction];
  4080. #else
  4081. return @[deleteRowAction];
  4082. #endif
  4083. }
  4084. - (void)tableView:(UITableView *)tableView
  4085. commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  4086. // NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  4087. //
  4088. // NSString *ids=[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  4089. //
  4090. //
  4091. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4092. //
  4093. // NSDictionary* cart_json = [iSalesNetwork cart_remove:ids];
  4094. //
  4095. // dispatch_async(dispatch_get_main_queue(), ^{
  4096. //
  4097. //
  4098. //
  4099. // if(cart_json!=nil)
  4100. // {
  4101. //
  4102. // [self reload_data];
  4103. // }
  4104. //
  4105. // });
  4106. // });
  4107. // sqlite3* db = [ApexMobileDB get_db];
  4108. // NSString* sql = [NSString stringWithFormat:@"delete from history where _id=%@",[self.data.pagedata[indexPath.row] valueForKey:@"_id"]];
  4109. // [ApexMobileDB execSql:sql db:db];
  4110. // [iSalesDB close_db:db];
  4111. //
  4112. // [self.data.pagedata removeObjectAtIndex:indexPath.row];
  4113. //
  4114. // [tableView reloadData];
  4115. }
  4116. //#pragma mark - UIAlertViewDelegate
  4117. //// Called when a button is clicked. The view will be automatically dismissed after this call returns
  4118. //- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  4119. //{
  4120. //
  4121. // if(alertView.tag==ALERT_DEL)
  4122. // {
  4123. // if(buttonIndex!=alertView.cancelButtonIndex)
  4124. // {
  4125. // // [self.itemListTable reloadRowsAtIndexPaths:@[self.indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  4126. // NSMutableDictionary * item_json = nil;
  4127. // if (self.back_order_flag) {
  4128. // item_json = [[self itemJsonAtIndexPath:self.indexPath] mutableCopy];
  4129. // } else {
  4130. // item_json = [self.content_arr[self.indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  4131. //
  4132. // }
  4133. //
  4134. // NSString *ids=[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  4135. // [RANetwork request_remove_cart:ids completionHandler:^(NSMutableDictionary *result) {
  4136. // NSMutableDictionary* cart_json = result;
  4137. //
  4138. //
  4139. //
  4140. //
  4141. // if([[cart_json valueForKey:@"result"] intValue]==2)
  4142. // {
  4143. // // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  4144. // if (self.back_order_flag) {
  4145. //
  4146. // NSInteger section_count = [self sectionCount];
  4147. // for (int i = 0; i < section_count; i++) {
  4148. // NSInteger item_count = [self itemCountInSection:i];
  4149. // BOOL ready_break = NO;
  4150. //
  4151. // for (int j = 0; j < item_count; j++) {
  4152. // NSIndexPath *indexPath = [NSIndexPath indexPathForRow:j inSection:i];
  4153. // NSDictionary* obj_json = [self itemJsonAtIndexPath:indexPath];
  4154. // NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  4155. // if([_id isEqualToString:ids])
  4156. // {
  4157. // [self updateItemJson:nil atIndexPath:indexPath];
  4158. // ready_break = YES;
  4159. // break;
  4160. // }
  4161. // }
  4162. //
  4163. // if (ready_break) {
  4164. // break;
  4165. // }
  4166. // }
  4167. //
  4168. // } else {
  4169. // for(int i=0;i<self.content_arr.count;i++)
  4170. // {
  4171. // NSDictionary* obj_json = self.content_arr[i];
  4172. // NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  4173. // if([_id isEqualToString:ids])
  4174. // {
  4175. // [self.content_arr removeObjectAtIndex:i];
  4176. // // [self.itemListTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:self.indexPath] withRowAnimation:UITableViewRowAnimationLeft];
  4177. // break;
  4178. // // appDelegate.cart_count--;
  4179. // // [appDelegate update_count_mark];
  4180. // }
  4181. //
  4182. // }
  4183. // }
  4184. // [self.itemListTable reloadData];
  4185. // [self refresh_total];
  4186. //#ifdef RA_NOTIFICATION
  4187. // [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  4188. //#else
  4189. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  4190. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  4191. //#endif
  4192. // // [self reload_data];
  4193. // }
  4194. // else
  4195. // {
  4196. // [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
  4197. // }
  4198. //
  4199. //
  4200. // }];
  4201. //
  4202. //// dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4203. ////
  4204. //// NSDictionary* cart_json = [RANetwork cart_remove:ids];
  4205. ////
  4206. //// dispatch_async(dispatch_get_main_queue(), ^{
  4207. ////
  4208. ////
  4209. ////
  4210. //// if([[cart_json valueForKey:@"result"] intValue]==2)
  4211. //// {
  4212. //// // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  4213. //// if (self.back_order_flag) {
  4214. ////
  4215. //// NSInteger section_count = [self sectionCount];
  4216. //// for (int i = 0; i < section_count; i++) {
  4217. //// NSInteger item_count = [self itemCountInSection:i];
  4218. //// BOOL ready_break = NO;
  4219. ////
  4220. //// for (int j = 0; j < item_count; j++) {
  4221. //// NSIndexPath *indexPath = [NSIndexPath indexPathForRow:j inSection:i];
  4222. //// NSDictionary* obj_json = [self itemJsonAtIndexPath:indexPath];
  4223. //// NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  4224. //// if([_id isEqualToString:ids])
  4225. //// {
  4226. //// [self updateItemJson:nil atIndexPath:indexPath];
  4227. //// ready_break = YES;
  4228. //// break;
  4229. //// }
  4230. //// }
  4231. ////
  4232. //// if (ready_break) {
  4233. //// break;
  4234. //// }
  4235. //// }
  4236. ////
  4237. //// } else {
  4238. //// for(int i=0;i<self.content_arr.count;i++)
  4239. //// {
  4240. //// NSDictionary* obj_json = self.content_arr[i];
  4241. //// NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  4242. //// if([_id isEqualToString:ids])
  4243. //// {
  4244. //// [self.content_arr removeObjectAtIndex:i];
  4245. //// // [self.itemListTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:self.indexPath] withRowAnimation:UITableViewRowAnimationLeft];
  4246. //// break;
  4247. //// // appDelegate.cart_count--;
  4248. //// // [appDelegate update_count_mark];
  4249. //// }
  4250. ////
  4251. //// }
  4252. //// }
  4253. //// [self.itemListTable reloadData];
  4254. //// [self refresh_total];
  4255. ////#ifdef RA_NOTIFICATION
  4256. //// [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  4257. ////#else
  4258. //// AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  4259. //// [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  4260. ////#endif
  4261. //// // [self reload_data];
  4262. //// }
  4263. //// else
  4264. //// {
  4265. //// [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
  4266. //// }
  4267. ////
  4268. //// });
  4269. //// });
  4270. //
  4271. // }
  4272. // }
  4273. //
  4274. //}
  4275. #pragma mark - Support scanner
  4276. -(void) onDecodedData:(NSString*) value
  4277. {
  4278. int cqty=0;
  4279. if (self.back_order_flag) {
  4280. NSInteger section_count = [self sectionCount];
  4281. for (int i = 0; i < section_count; i++) {
  4282. NSInteger item_count = [self itemCountInSection:i];
  4283. for (int j = 0; j < item_count; j++) {
  4284. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:j inSection:i];
  4285. NSDictionary* item = [self itemJsonAtIndexPath:indexPath];
  4286. if([item[@"model"] isEqualToString:value]) {
  4287. cqty=[item[@"count"] intValue];
  4288. }
  4289. }
  4290. }
  4291. } else {
  4292. for(int i=0;i<self.content_arr.count;i++)
  4293. {
  4294. NSDictionary* item= self.content_arr[i];
  4295. if([item[@"model"] isEqualToString:value])
  4296. cqty=[item[@"count"]intValue];
  4297. }
  4298. }
  4299. if(cqty>0)
  4300. {
  4301. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"QTY: %d of this model already in cart. Continue ?",cqty] message:nil preferredStyle:UIAlertControllerStyleAlert];
  4302. //block代码块取代了delegate
  4303. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  4304. [self addtocart:value];
  4305. }];
  4306. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  4307. DebugLog(@"No");
  4308. }];
  4309. [alertControl addAction:actionOne];
  4310. [alertControl addAction:alertthree];
  4311. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  4312. [self presentViewController:alertControl animated:YES completion:nil];
  4313. }
  4314. else
  4315. [self addtocart:value];
  4316. }
  4317. -(void) addtocart:(NSString*) modelname
  4318. {
  4319. [RANetwork request_addto_cart_byname:modelname withScreen:ScreenCodeCart completionHandler:^(NSMutableDictionary *result) {
  4320. NSDictionary* return_json =result;
  4321. if([[return_json valueForKey:@"result"] intValue]==2)
  4322. {
  4323. NSDictionary* newitem = [return_json objectForKey:@"item_0"];
  4324. NSString* item_id = [newitem valueForKey:@"cart_item_id"];
  4325. // bool isnew=false;
  4326. //
  4327. // [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  4328. if (self.back_order_flag) {
  4329. NSInteger section_count = [self sectionCount];
  4330. for (int i = 0; i < section_count; i++) {
  4331. NSInteger item_count = [self itemCountInSection:i];
  4332. BOOL ready_break = NO;
  4333. for (int j = 0; j < item_count; j++) {
  4334. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:j inSection:i];
  4335. NSDictionary* obj_json = [self itemJsonAtIndexPath:indexPath];
  4336. NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  4337. if([_id isEqualToString:item_id])
  4338. {
  4339. [self updateItemJson:nil atIndexPath:indexPath];
  4340. ready_break = YES;
  4341. break;
  4342. }
  4343. }
  4344. if (ready_break) {
  4345. break;
  4346. }
  4347. }
  4348. } else {
  4349. for(int i=0;i<self.content_arr.count;i++)
  4350. {
  4351. NSDictionary* obj_json = self.content_arr[i];
  4352. NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  4353. if([_id isEqualToString:item_id])
  4354. {
  4355. // self.content_arr[i] = newitem;
  4356. [self.content_arr removeObjectAtIndex:i];
  4357. break;
  4358. // [self.content_arr removeObjectAtIndex:i];
  4359. // [self.itemListTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
  4360. // appDelegate.cart_count--;
  4361. // [appDelegate update_count_mark];
  4362. }
  4363. }
  4364. }
  4365. AppDelegate *appDelegate =nil;
  4366. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4367. #ifdef OFFLINE_MODE
  4368. if(appDelegate.offline_mode)
  4369. {
  4370. [self ReloadData];
  4371. }
  4372. else
  4373. #endif
  4374. {
  4375. if (self.back_order_flag) {
  4376. [self ReloadData];
  4377. } else {
  4378. [self.content_arr insertObject:newitem atIndex:0];
  4379. [self.itemListTable reloadData];
  4380. [self refresh_total];
  4381. }
  4382. }
  4383. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  4384. #ifdef RA_NOTIFICATION
  4385. [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  4386. #else
  4387. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  4388. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  4389. #endif
  4390. }
  4391. else
  4392. {
  4393. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
  4394. }
  4395. }];
  4396. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4397. //
  4398. // NSDictionary* return_json = [RANetwork add_toCart_byName: modelname withScreen:ScreenCodeCart];
  4399. //
  4400. // dispatch_async(dispatch_get_main_queue(), ^{
  4401. //
  4402. //
  4403. //
  4404. // if([[return_json valueForKey:@"result"] intValue]==2)
  4405. // {
  4406. // NSDictionary* newitem = [return_json objectForKey:@"item_0"];
  4407. // NSString* item_id = [newitem valueForKey:@"cart_item_id"];
  4408. // // bool isnew=false;
  4409. ////
  4410. // // [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  4411. //
  4412. // if (self.back_order_flag) {
  4413. //
  4414. // NSInteger section_count = [self sectionCount];
  4415. // for (int i = 0; i < section_count; i++) {
  4416. // NSInteger item_count = [self itemCountInSection:i];
  4417. // BOOL ready_break = NO;
  4418. // for (int j = 0; j < item_count; j++) {
  4419. // NSIndexPath *indexPath = [NSIndexPath indexPathForRow:j inSection:i];
  4420. // NSDictionary* obj_json = [self itemJsonAtIndexPath:indexPath];
  4421. // NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  4422. // if([_id isEqualToString:item_id])
  4423. // {
  4424. // [self updateItemJson:nil atIndexPath:indexPath];
  4425. // ready_break = YES;
  4426. // break;
  4427. // }
  4428. // }
  4429. // if (ready_break) {
  4430. // break;
  4431. // }
  4432. //
  4433. //
  4434. // }
  4435. //
  4436. // } else {
  4437. //
  4438. // for(int i=0;i<self.content_arr.count;i++)
  4439. // {
  4440. // NSDictionary* obj_json = self.content_arr[i];
  4441. // NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  4442. // if([_id isEqualToString:item_id])
  4443. // {
  4444. // // self.content_arr[i] = newitem;
  4445. //
  4446. //
  4447. // [self.content_arr removeObjectAtIndex:i];
  4448. //
  4449. // break;
  4450. // // [self.content_arr removeObjectAtIndex:i];
  4451. // // [self.itemListTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
  4452. // // appDelegate.cart_count--;
  4453. // // [appDelegate update_count_mark];
  4454. // }
  4455. //
  4456. //
  4457. // }
  4458. // }
  4459. //
  4460. // AppDelegate *appDelegate =nil;
  4461. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4462. //#ifdef OFFLINE_MODE
  4463. //
  4464. // if(appDelegate.offline_mode)
  4465. // {
  4466. //
  4467. // [self ReloadData];
  4468. //
  4469. // }
  4470. // else
  4471. //#endif
  4472. // {
  4473. //
  4474. // if (self.back_order_flag) {
  4475. // [self ReloadData];
  4476. // } else {
  4477. // [self.content_arr insertObject:newitem atIndex:0];
  4478. //
  4479. // [self.itemListTable reloadData];
  4480. // [self refresh_total];
  4481. // }
  4482. //
  4483. // }
  4484. //
  4485. // // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  4486. //
  4487. //
  4488. //
  4489. //
  4490. //#ifdef RA_NOTIFICATION
  4491. // [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  4492. //#else
  4493. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  4494. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  4495. //#endif
  4496. //
  4497. //
  4498. // }
  4499. // else
  4500. // {
  4501. //
  4502. // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
  4503. // }
  4504. //
  4505. //
  4506. //
  4507. //
  4508. // });
  4509. // });
  4510. }
  4511. #pragma mark - sort button
  4512. - (void)cartSortButtonClicked:(UIButton *)sender {
  4513. DebugLog(@"cart sort button clicked");
  4514. [self.view addSubview:self.sortItemController.view];
  4515. }
  4516. - (SortItemViewController *)sortItemController {
  4517. if (!_sortItemController) {
  4518. _sortItemController = [[SortItemViewController alloc] initWithTableOrigin:CGPointMake(20, 50)];
  4519. _sortItemController.sortIndex = self.sortIndex;
  4520. _sortItemController.sortData = @[
  4521. @{@"title":@"Last",@"icon":@"TX_18"},
  4522. @{@"title":@"First",@"icon":@"TS_18"},
  4523. @{@"title":@"Item number a-z",@"icon":@"IX_18"},
  4524. @{@"title":@"Item number z-a",@"icon":@"IS_18"},
  4525. @{@"title":@"Description",@"icon":@"DX_18"},
  4526. ];
  4527. __weak typeof(self) weakSelf = self;
  4528. _sortItemController.sortBlock = ^(int sort){
  4529. weakSelf.sortIndex = sort;
  4530. [weakSelf reload_data];
  4531. };
  4532. }
  4533. // _sortItemController.sortIndex = self.sortIndex;
  4534. return _sortItemController;
  4535. }
  4536. - (SortButton *)sortButton {
  4537. if (!_sortButton) {
  4538. _sortButton = [SortButton sortButtonWithHeight:40];
  4539. _sortButton.autoresizingMask=UIViewAutoresizingFlexibleRightMargin;
  4540. [_sortButton addTarget:self action:@selector(cartSortButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
  4541. }
  4542. return _sortButton;
  4543. }
  4544. - (void)setSortIndex:(int)sortIndex {
  4545. _sortIndex = sortIndex;
  4546. NSString *selectedImageName = @"";
  4547. switch (sortIndex) {
  4548. case 0:{
  4549. selectedImageName = @"TX_22";
  4550. }
  4551. break;
  4552. case 1:{
  4553. selectedImageName = @"TS_22";
  4554. }
  4555. break;
  4556. case 2:{
  4557. selectedImageName = @"IX_22";
  4558. }
  4559. break;
  4560. case 3:{
  4561. selectedImageName = @"IS_22";
  4562. }
  4563. break;
  4564. case 4:{
  4565. selectedImageName = @"DX_22";
  4566. }
  4567. break;
  4568. default:
  4569. break;
  4570. }
  4571. self.sortButton.imageView.image = [UIImage imageNamed:selectedImageName];
  4572. }
  4573. #pragma mark - rotation
  4574. //- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
  4575. //
  4576. // self.sortItemController.view.frame = self.view.bounds;
  4577. //}
  4578. - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
  4579. [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
  4580. [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
  4581. // what ever you want to prepare
  4582. } completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
  4583. // self.sortItemController.view.frame = self.view.bounds;
  4584. self.sortItemController.view.frame = self.view.bounds;
  4585. self.toolpanel.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.toolpanel.bounds].CGPath;
  4586. // [self.itemListTable reloadData];
  4587. self.cartIndicatorBar.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.cartIndicatorBar.bounds].CGPath;
  4588. [self layoutCartIndicatorBar];
  4589. }];
  4590. }
  4591. -(BOOL) shouldAutorotate
  4592. {
  4593. return YES;
  4594. }
  4595. //- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  4596. // return YES;
  4597. //}
  4598. //- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
  4599. // self.sortItemController.view.frame = self.view.bounds;
  4600. // self.toolpanel.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.toolpanel.bounds].CGPath;
  4601. //
  4602. //// [self.itemListTable reloadData];
  4603. //
  4604. // self.cartIndicatorBar.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.cartIndicatorBar.bounds].CGPath;
  4605. // [self layoutCartIndicatorBar];
  4606. //}
  4607. #pragma mark - notification action
  4608. - (void)priceTypeChanged:(id)notification {
  4609. [self reload_data];
  4610. #ifdef RA_NOTIFICATION
  4611. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  4612. #else
  4613. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  4614. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  4615. #endif
  4616. }
  4617. #pragma mark - button action
  4618. - (IBAction)emailButtonClick:(UIButton *)sender {
  4619. if (![self isOrderAvailable]) {
  4620. return;
  4621. }
  4622. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  4623. JKMessageBoxController *emailAddrVC = [JKMessageBoxController messageBoxControllerWithTip:@"Please enter email address"];
  4624. emailAddrVC.textFiled.secureTextEntry = NO;
  4625. emailAddrVC.yesButtonTitle = @"send";
  4626. __weak typeof(emailAddrVC) weakVC = emailAddrVC;
  4627. __weak typeof(self) weakself = self;
  4628. emailAddrVC.textHandler = ^(NSString *text){
  4629. // 验证邮箱格式是否正确
  4630. // NSString *match = EMAIL_MATCHES;
  4631. // NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",match];
  4632. // BOOL isEmailAddr = [predicate evaluateWithObject:text];
  4633. BOOL isEmailAddr = YES;
  4634. if (isEmailAddr) {
  4635. // 验证是邮件地址,发送邮件
  4636. [weakVC dismissViewControllerAnimated:YES completion:^{
  4637. __block UIAlertController *waitting_alert = [RAUtils waiting_alert:self title:@"Sending Email" completion:^{
  4638. [RANetwork request_qouteorder:appDelegate.order_code emailAddr:text completionHandler:^(NSMutableDictionary *result) {
  4639. DebugLog(@"email cart result: %@",result);
  4640. [waitting_alert dismissViewControllerAnimated:YES completion:^{
  4641. // [waitting_alert dismissWithClickedButtonIndex:0 animated:YES];
  4642. if ([[result objectForKey:@"result"] integerValue] != RESULT_TRUE) {
  4643. UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"The email send to %@ failed",text] preferredStyle:UIAlertControllerStyleAlert];
  4644. UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  4645. }];
  4646. [errorAlertVC addAction:action];
  4647. [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  4648. }else {
  4649. [RAUtils message_alert:@"Send Email Success" title:@"Message" controller:weakself];
  4650. }
  4651. }];
  4652. }];
  4653. }];
  4654. // dispatch_async(dispatch_get_global_queue(0, 0), ^{
  4655. //
  4656. // NSDictionary *result = [RANetwork quoteOrder:appDelegate.order_code emailAddr:text];
  4657. // DebugLog(@"email cart result: %@",result);
  4658. // dispatch_async(dispatch_get_main_queue(), ^{
  4659. //
  4660. // [waitting_alert dismissWithClickedButtonIndex:0 animated:YES];
  4661. //
  4662. // if ([[result objectForKey:@"result"] integerValue] != RESULT_TRUE) {
  4663. //
  4664. // UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"The email send to %@ failed",text] preferredStyle:UIAlertControllerStyleAlert];
  4665. // UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  4666. //
  4667. // }];
  4668. //
  4669. // [errorAlertVC addAction:action];
  4670. // [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  4671. //
  4672. // }else {
  4673. //
  4674. // [RAUtils message_alert:@"Send Email Success" title:@"Message" controller:weakself];
  4675. //
  4676. // }
  4677. //
  4678. // });
  4679. //
  4680. // });
  4681. }];
  4682. } else {
  4683. // 非邮件地址,警告
  4684. [weakVC warning:@"Please enter right email address"];
  4685. }
  4686. };
  4687. [self presentViewController:emailAddrVC animated:YES completion:nil];
  4688. }
  4689. - (IBAction)printCartButtonClick:(UIButton *)sender {
  4690. if (![self isOrderAvailable]) {
  4691. return;
  4692. }
  4693. RAPDFViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"RAPDFViewController"];
  4694. ViewController.url = self.print_url;
  4695. ViewController.canSave = false;
  4696. ViewController.isLocalfile=NO;
  4697. NSString* subject;
  4698. subject =@"Cart Print";
  4699. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  4700. NSString* customer_email= [appDelegate.customerInfo valueForKey:@"customer_email"];
  4701. NSMutableArray* send_to = [[NSMutableArray alloc]init];
  4702. if(customer_email.length>0)
  4703. {
  4704. send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
  4705. }
  4706. ViewController.mail_to = send_to;
  4707. ViewController.filename = [NSString stringWithFormat:@"%@_Product_List.pdf",COMPANY_SHORT_NAME];
  4708. ViewController.mail_subject = subject;
  4709. ViewController.hidenavi = false;
  4710. [self.navigationController pushViewController:ViewController animated:YES];
  4711. }
  4712. - (void)showAddressBoxToEmailProduct:(NSString *)productID {
  4713. // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  4714. JKMessageBoxController *emailAddrVC = [JKMessageBoxController messageBoxControllerWithTip:@"E-mail not setup, please enter your default e-mail address" ContentSize:CGSizeMake(400, 150)];
  4715. emailAddrVC.textFiled.secureTextEntry = NO;
  4716. emailAddrVC.yesButtonTitle = @"send";
  4717. __weak typeof(emailAddrVC) weakVC = emailAddrVC;
  4718. __weak typeof(self) weakself = self;
  4719. emailAddrVC.textHandler = ^(NSString *text){
  4720. // 验证邮箱格式是否正确
  4721. // NSString *match = EMAIL_MATCHES;
  4722. // NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",match];
  4723. // BOOL isEmailAddr = [predicate evaluateWithObject:text];
  4724. BOOL isEmailAddr = YES;
  4725. if (isEmailAddr) {
  4726. // 验证是邮件地址,发送邮件
  4727. [weakVC dismissViewControllerAnimated:YES completion:^{
  4728. __block UIAlertController *waitting_alert = [RAUtils waiting_alert:self title:@"Sending Email" completion:^{
  4729. [RANetwork request_notifymodel:productID emailAddr:text withScreen:ScreenCodeCart completionHandler:^(NSMutableDictionary *result) {
  4730. // [waitting_alert dismissWithClickedButtonIndex:0 animated:NO];
  4731. [waitting_alert dismissViewControllerAnimated:YES completion:^{
  4732. int resultStatus = [[result objectForKey:@"result"] intValue];
  4733. if (resultStatus != RESULT_TRUE && resultStatus != RESULT_NO_EMAIL_ADDRESS) {
  4734. NSString *msg = [NSString stringWithFormat:@"The email send failed"];
  4735. if ([result valueForKey:@"err_msg"]) {
  4736. msg = [result valueForKey:@"err_msg"];
  4737. }
  4738. UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
  4739. UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  4740. }];
  4741. [errorAlertVC addAction:action];
  4742. [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  4743. }else if(resultStatus == RESULT_TRUE){
  4744. [RAUtils message_alert:@"Notification is sent to default email address." title:@"Message" controller:weakself];
  4745. } else if (resultStatus == RESULT_NO_EMAIL_ADDRESS) {
  4746. [weakself showAddressBoxToEmailProduct:productID];
  4747. }
  4748. }];
  4749. }];
  4750. }];
  4751. // dispatch_async(dispatch_get_global_queue(0, 0), ^{
  4752. //
  4753. // NSDictionary *result = [RANetwork notifyModel:productID emailAddr:text withScreen:ScreenCodeCart];
  4754. //
  4755. // dispatch_async(dispatch_get_main_queue(), ^{
  4756. //
  4757. // [waitting_alert dismissWithClickedButtonIndex:0 animated:NO];
  4758. //
  4759. // int resultStatus = [[result objectForKey:@"result"] intValue];
  4760. // if (resultStatus != RESULT_TRUE && resultStatus != RESULT_NO_EMAIL_ADDRESS) {
  4761. //
  4762. // NSString *msg = [NSString stringWithFormat:@"The email send failed"];
  4763. // if ([result valueForKey:@"err_msg"]) {
  4764. // msg = [result valueForKey:@"err_msg"];
  4765. // }
  4766. //
  4767. //
  4768. // UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
  4769. // UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  4770. //
  4771. // }];
  4772. //
  4773. // [errorAlertVC addAction:action];
  4774. // [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  4775. //
  4776. // }else if(resultStatus == RESULT_TRUE){
  4777. //
  4778. // [RAUtils message_alert:@"Notification is sent to default email address." title:@"Message" controller:weakself];
  4779. //
  4780. // } else if (resultStatus == RESULT_NO_EMAIL_ADDRESS) {
  4781. //
  4782. // [weakself showAddressBoxToEmailProduct:productID];
  4783. //
  4784. // }
  4785. //
  4786. // });
  4787. //
  4788. // });
  4789. }];
  4790. } else {
  4791. // 非邮件地址,警告
  4792. [weakVC warning:@"Please enter right email address"];
  4793. }
  4794. };
  4795. [self presentViewController:emailAddrVC animated:YES completion:nil];
  4796. }
  4797. #pragma mark - Back Order
  4798. - (void) setCart_json:(NSDictionary *)cart_json {
  4799. _cart_json = cart_json;
  4800. [self fillContentArray];
  4801. }
  4802. - (void)fillContentArray {
  4803. NSMutableArray *arr = [NSMutableArray array];
  4804. for (int i = 0; i < [self sectionCount]; i++) {
  4805. NSInteger item_count = [self itemCountInSection:i];
  4806. for (int j = 0; j < item_count; j++) {
  4807. NSDictionary *item = [self itemJsonAtIndexPath:[NSIndexPath indexPathForRow:j inSection:i]];
  4808. [arr addObject:item];
  4809. }
  4810. }
  4811. self.content_arr = arr;
  4812. [self refresh_total];
  4813. }
  4814. - (NSInteger)sectionCount {
  4815. return [[self.cart_json objectForKey:@"section_count"] integerValue];
  4816. }
  4817. - (NSDictionary *)jsonAtSection:(NSInteger)section {
  4818. return [self.cart_json objectForKey:[NSString stringWithFormat:@"section_%ld",section]];
  4819. }
  4820. - (NSInteger)itemCountInSection:(NSInteger)section {
  4821. NSDictionary *section_json = [self jsonAtSection:section];
  4822. return [[section_json objectForKey:@"count"] integerValue];
  4823. }
  4824. - (NSString *)titleForSection:(NSInteger)section {
  4825. NSDictionary *section_json = [self jsonAtSection:section];
  4826. return [section_json objectForKey:@"title"];
  4827. }
  4828. - (NSDictionary *)itemJsonAtIndexPath:(NSIndexPath *)indexPath {
  4829. NSDictionary *section = [self jsonAtSection:indexPath.section];
  4830. return [section objectForKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]];
  4831. }
  4832. - (void)updateItemJson:(NSDictionary *)new_item_json atIndexPath:(NSIndexPath *)indexPath {
  4833. NSMutableDictionary *new_cart_json = [self.cart_json mutableCopy];
  4834. NSMutableDictionary *new_section_json = [[self jsonAtSection:indexPath.section] mutableCopy];
  4835. NSString *section_key = [NSString stringWithFormat:@"section_%ld",indexPath.section];
  4836. NSString *item_key = [NSString stringWithFormat:@"item_%ld",indexPath.row];
  4837. if (new_item_json) {
  4838. // 更新Item
  4839. [new_section_json setObject:new_item_json forKey:item_key];
  4840. } else {
  4841. // 删除Item
  4842. NSInteger item_count = [self itemCountInSection:indexPath.section];
  4843. for (NSInteger i = 0; i < item_count; i++) {
  4844. if (i >= indexPath.row) {
  4845. if (i < item_count - 1) {
  4846. item_key = [NSString stringWithFormat:@"item_%ld",i + 1];
  4847. NSDictionary *followed_item_json = [new_section_json objectForKey:item_key];
  4848. item_key = [NSString stringWithFormat:@"item_%ld",i];
  4849. [new_section_json setObject:followed_item_json forKey:item_key];
  4850. } else {
  4851. item_key = [NSString stringWithFormat:@"item_%ld",i];
  4852. [new_section_json removeObjectForKey:item_key];
  4853. }
  4854. }
  4855. }
  4856. [new_section_json setObject:@(item_count - 1) forKey:@"count"];
  4857. }
  4858. [new_cart_json setObject:new_section_json forKey:section_key];
  4859. self.cart_json = [new_cart_json copy];
  4860. }
  4861. - (void)reRefreshView {
  4862. [self.itemListTable reloadData];
  4863. }
  4864. #pragma mark - RA_NOTIFICAITON
  4865. -(void) refresh_ui
  4866. {
  4867. [self.itemListTable reloadData];
  4868. [self refresh_total];
  4869. }
  4870. -(void) refresh_price
  4871. {
  4872. [self refresh_ui];
  4873. }
  4874. - (void) reload_data {
  4875. __weak typeof(self) weakself = self;
  4876. self.currentOrderIsMerged = NO;
  4877. NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
  4878. if (weakself) {
  4879. __strong typeof(weakself) strongself = weakself;
  4880. [strongself operation_reload_data];
  4881. }
  4882. }];
  4883. [self.dataOperationQueue addOperation:operation];
  4884. }
  4885. @end