CartViewController.m 256 KB

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