CartViewController.m 193 KB

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