CartViewController.m 207 KB

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