CartViewController.m 244 KB

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