CartViewController.m 230 KB

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