CartViewController.m 193 KB

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