CartViewController.m 239 KB

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