CreateOrderViewController.m 160 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070
  1. //
  2. // CreateOrderViewController.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 8/24/15.
  6. // Copyright (c) 2015 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "CreateOrderViewController.h"
  9. #import "RANetwork.h"
  10. #import "MainViewController.h"
  11. #import "RASingleton.h"
  12. #import "config.h"
  13. #import "CustomIOSAlertView.h"
  14. #import "AddressEditorViewController.h"
  15. #import "CreditCardEditorViewController.h"
  16. #import "JKTimerManager.h"
  17. #import "ZipArchive.h"
  18. #ifdef SCANNER_ORDER
  19. #import "StockViewController.h"
  20. #endif
  21. #define SUBMIT_CONFIRM 123
  22. #define KEEP_TAIL 456
  23. #define CLOSE_ACTION 567
  24. @interface CreateOrderViewController ()
  25. // static const char associatedkey;
  26. @property (nonatomic,assign) BOOL isResume;///<恢复
  27. @property (nonatomic,assign) NSInteger userType;///<恢复使用
  28. @end
  29. @implementation CreateOrderViewController
  30. - (void)onScanSwitchUserTypeClick:(id)sender
  31. {
  32. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  33. NSString *orderdir =[OLDataProvider getScanPath];
  34. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Select Customer type" message:@"" preferredStyle:UIAlertControllerStyleAlert];
  35. //block代码块取代了delegate
  36. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Existing Customer" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  37. NSMutableDictionary* dict = nil;
  38. dict=[OLDataProvider loadScanTemplate:@"e_order.json"];
  39. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  40. [RAUtils dicttofile:orderPath dict:dict];
  41. NSString *orderdir = [OLDataProvider getScanPath];
  42. // NSMutableDictionary* dict= [[RAUtils dictfromfile:[orderdir stringByAppendingPathComponent:@"order.json"]] mutableCopy];
  43. int section_count = [dict[@"section_count"] intValue];
  44. for(int i=0;i<section_count;i++)
  45. {
  46. NSMutableDictionary* section = [dict[[NSString stringWithFormat:@"section_%d",i]] mutableCopy];
  47. NSString* title = section[@"title"];
  48. if([title isEqualToString:@"Model Information"])
  49. {
  50. NSMutableDictionary* cart_section = RASingleton.sharedInstance.scan_cart[@"section_0"];
  51. int cart_count = [cart_section[@"count"] intValue];
  52. for(int j=0;j<cart_count;j++)
  53. {
  54. NSMutableDictionary* cart_item = [cart_section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  55. cart_item[@"description"]= [NSString stringWithFormat:@"%@\n%@\n%@",cart_item[@"model"],cart_item[@"description"],cart_item[@"dimension"] ];
  56. cart_item[@"control"]=@"model";
  57. section[[NSString stringWithFormat:@"item_%d",j]] = cart_item;
  58. }
  59. section[@"count"] = @(cart_count);
  60. dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  61. }
  62. else
  63. if([title isEqualToString:@"Customer"])
  64. {
  65. int scount = [section[@"count"] intValue];
  66. for(int j=0;j<scount;j++)
  67. {
  68. NSMutableDictionary * item = [section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  69. NSString * name = item[@"name"];
  70. if([name isEqualToString:@"business_card"])
  71. {
  72. NSArray*arr =[RAConvertor string2arr:appDelegate.customerInfo[name] separator:@","];
  73. for(int l=0;l<arr.count;l++)
  74. {
  75. item[[NSString stringWithFormat:@"img_url_%d",l] ]=arr[l];
  76. }
  77. }
  78. else
  79. {
  80. if(item[@"value"]==nil ||[item[@"value"] stringValue].length==0) //order 内没有值才从customer 复制
  81. item[@"value"]=appDelegate.customerInfo[name];
  82. }
  83. section[[NSString stringWithFormat:@"item_%d",j]] = item;
  84. }
  85. // NSDictionary* item_0=@{@"control":@"text",@"name":@"customer_cid",@"aname":@"Contact",@"value":appDelegate.contact_id};
  86. dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  87. }
  88. else
  89. if([title isEqualToString:@"Remarks Content"])
  90. {
  91. int scount = [section[@"count"] intValue];
  92. for(int j=0;j<scount;j++)
  93. {
  94. NSMutableDictionary * item = [section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  95. NSString * name = item[@"name"];
  96. if([name isEqualToString:@"comments"])
  97. {
  98. item[@"value"] = RASingleton.sharedInstance.scan_cart[@"general_note"];
  99. section[[NSString stringWithFormat:@"item_%d",j]] = item;
  100. }
  101. }
  102. // NSDictionary* item_0=@{@"control":@"text",@"name":@"customer_cid",@"aname":@"Contact",@"value":appDelegate.contact_id};
  103. dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  104. }
  105. else if([title isEqualToString:@"Order Total"])
  106. {
  107. //
  108. // int scount = [section[@"count"] intValue];
  109. // for(int j=0;j<scount;j++)
  110. // {
  111. // NSMutableDictionary * item = [section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  112. // NSString * name = item[@"name"];
  113. //
  114. //
  115. // if([name isEqualToString:@"totalPrice"])
  116. // {
  117. // item[@"value"] = [NSString stringWithFormat:@"%.2f",self.total];
  118. // section[[NSString stringWithFormat:@"item_%d",j]] = item;
  119. // }
  120. //
  121. //
  122. // }
  123. //
  124. // // NSDictionary* item_0=@{@"control":@"text",@"name":@"customer_cid",@"aname":@"Contact",@"value":appDelegate.contact_id};
  125. // dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  126. //
  127. //
  128. }
  129. }
  130. // NSString *path = NSTemporaryDirectory();
  131. //
  132. // NSString* file=[NSString stringWithFormat:@"SO_%@.json",appDelegate.order_code];
  133. // NSString *filePath = [path stringByAppendingPathComponent:file];
  134. //
  135. //
  136. //
  137. [RAUtils dicttofile:[orderdir stringByAppendingPathComponent:@"order.json"] dict:dict];
  138. NSData* json =nil;
  139. if(self.url_type== URL_LOCAL)
  140. json=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:self.request_url ofType:@"json" ]];
  141. else
  142. json=[NSData dataWithContentsOfFile:self.request_url];
  143. NSError *error=nil;
  144. self.content_data_download = [[NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:nil] mutableCopy];
  145. self.content_data_control=[self translate_json:self.content_data_download changed:self.changed_data];
  146. self.navigationItem.title = [self.content_data_download valueForKey:@"title"] ;
  147. [self.editorTable reloadData];
  148. // self refresh:<#(NSString *)#> discardDirty:<#(bool)#>
  149. //
  150. // NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  151. //
  152. //
  153. //
  154. // [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  155. //
  156. // [self scanPlaceOrder];
  157. //
  158. }];
  159. UIAlertAction *alert2 = [UIAlertAction actionWithTitle:@"New customer" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  160. NSMutableDictionary* dict = nil;
  161. dict=[OLDataProvider loadScanTemplate:@"n_order.json"];
  162. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  163. [RAUtils dicttofile:orderPath dict:dict];
  164. NSString *orderdir = [OLDataProvider getScanPath];
  165. // NSMutableDictionary* dict= [[RAUtils dictfromfile:[orderdir stringByAppendingPathComponent:@"order.json"]] mutableCopy];
  166. int section_count = [dict[@"section_count"] intValue];
  167. for(int i=0;i<section_count;i++)
  168. {
  169. NSMutableDictionary* section = [dict[[NSString stringWithFormat:@"section_%d",i]] mutableCopy];
  170. NSString* title = section[@"title"];
  171. if([title isEqualToString:@"Model Information"])
  172. {
  173. NSMutableDictionary* cart_section = RASingleton.sharedInstance.scan_cart[@"section_0"];
  174. int cart_count = [cart_section[@"count"] intValue];
  175. for(int j=0;j<cart_count;j++)
  176. {
  177. NSMutableDictionary* cart_item = [cart_section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  178. cart_item[@"description"]= [NSString stringWithFormat:@"%@\n%@\n%@",cart_item[@"model"],cart_item[@"description"],cart_item[@"dimension"] ];
  179. cart_item[@"control"]=@"model";
  180. section[[NSString stringWithFormat:@"item_%d",j]] = cart_item;
  181. }
  182. section[@"count"] = @(cart_count);
  183. dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  184. }
  185. else
  186. if([title isEqualToString:@"Customer"])
  187. {
  188. int scount = [section[@"count"] intValue];
  189. for(int j=0;j<scount;j++)
  190. {
  191. NSMutableDictionary * item = [section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  192. NSString * name = item[@"name"];
  193. if([name isEqualToString:@"business_card"])
  194. {
  195. NSArray*arr =[RAConvertor string2arr:appDelegate.customerInfo[name] separator:@","];
  196. for(int l=0;l<arr.count;l++)
  197. {
  198. item[[NSString stringWithFormat:@"img_url_%d",l] ]=arr[l];
  199. }
  200. }
  201. else
  202. {
  203. if(item[@"value"]==nil ||[item[@"value"] stringValue].length==0) //order 内没有值才从customer 复制
  204. item[@"value"]=appDelegate.customerInfo[name];
  205. }
  206. section[[NSString stringWithFormat:@"item_%d",j]] = item;
  207. }
  208. // NSDictionary* item_0=@{@"control":@"text",@"name":@"customer_cid",@"aname":@"Contact",@"value":appDelegate.contact_id};
  209. dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  210. }
  211. else
  212. if([title isEqualToString:@"Remarks Content"])
  213. {
  214. int scount = [section[@"count"] intValue];
  215. for(int j=0;j<scount;j++)
  216. {
  217. NSMutableDictionary * item = [section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  218. NSString * name = item[@"name"];
  219. if([name isEqualToString:@"comments"])
  220. {
  221. item[@"value"] = RASingleton.sharedInstance.scan_cart[@"general_note"];
  222. section[[NSString stringWithFormat:@"item_%d",j]] = item;
  223. }
  224. }
  225. // NSDictionary* item_0=@{@"control":@"text",@"name":@"customer_cid",@"aname":@"Contact",@"value":appDelegate.contact_id};
  226. dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  227. }
  228. else if([title isEqualToString:@"Order Total"])
  229. {
  230. //
  231. // int scount = [section[@"count"] intValue];
  232. // for(int j=0;j<scount;j++)
  233. // {
  234. // NSMutableDictionary * item = [section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  235. // NSString * name = item[@"name"];
  236. //
  237. //
  238. // if([name isEqualToString:@"totalPrice"])
  239. // {
  240. // item[@"value"] = [NSString stringWithFormat:@"%.2f",self.total];
  241. // section[[NSString stringWithFormat:@"item_%d",j]] = item;
  242. // }
  243. //
  244. //
  245. // }
  246. //
  247. // // NSDictionary* item_0=@{@"control":@"text",@"name":@"customer_cid",@"aname":@"Contact",@"value":appDelegate.contact_id};
  248. // dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  249. //
  250. //
  251. }
  252. }
  253. // NSString *path = NSTemporaryDirectory();
  254. //
  255. // NSString* file=[NSString stringWithFormat:@"SO_%@.json",appDelegate.order_code];
  256. // NSString *filePath = [path stringByAppendingPathComponent:file];
  257. //
  258. //
  259. //
  260. [RAUtils dicttofile:[orderdir stringByAppendingPathComponent:@"order.json"] dict:dict];
  261. NSData* json =nil;
  262. if(self.url_type== URL_LOCAL)
  263. json=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:self.request_url ofType:@"json" ]];
  264. else
  265. json=[NSData dataWithContentsOfFile:self.request_url];
  266. NSError *error=nil;
  267. self.content_data_download = [[NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:nil] mutableCopy];
  268. self.content_data_control=[self translate_json:self.content_data_download changed:self.changed_data];
  269. self.navigationItem.title = [self.content_data_download valueForKey:@"title"] ;
  270. [self.editorTable reloadData];
  271. }];
  272. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  273. DebugLog(@"No");
  274. }];
  275. [alertControl addAction:actionOne];
  276. [alertControl addAction:alert2];
  277. [alertControl addAction:alertthree];
  278. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  279. [self presentViewController:alertControl animated:YES completion:nil];
  280. }
  281. - (void)alertMessage:(NSString *)msg {
  282. if (notifyMe_switch) {
  283. if ([self.class_name isEqualToString:@"CreateOrderViewController"]) {
  284. NSString *err_msg = msg;
  285. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Attention!!" message:err_msg preferredStyle:UIAlertControllerStyleAlert];
  286. __weak typeof(self) weakself = self;
  287. UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  288. [weakself.navigationController popViewControllerAnimated:YES];
  289. }];
  290. [alertVC addAction:action];
  291. [self presentViewController:alertVC animated:YES completion:nil];
  292. } else {
  293. [RAUtils message_alert:msg title:nil controller:self] ;
  294. }
  295. } else {
  296. [RAUtils message_alert:msg title:nil controller:self] ;
  297. }
  298. }
  299. -(void) commonAction:(NSString *)value index:(NSIndexPath*) indexPath data:(NSMutableDictionary*) item_json
  300. {
  301. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  302. if([value isEqualToString:@"new_addr"])
  303. {
  304. AddressEditorViewController * addressVC = [[AddressEditorViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  305. addressVC.url_type = URL_REMOTE;
  306. addressVC.request_url=URL_ADDRESS_EDOTOR;
  307. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  308. // NSString * string = [checked componentsJoinedByString:@","];
  309. // [params setValue:string forKey:@"cart2Checkbox"];
  310. addressVC.params = params;
  311. addressVC.delegate = self;
  312. addressVC.from = indexPath;
  313. // orderinfoVC.params = params;
  314. [self.navigationController pushViewController:addressVC animated:true];
  315. }else if([value isEqualToString:@"credit_card"])
  316. {
  317. CreditCardEditorViewController * cardVC = [[CreditCardEditorViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  318. NSDictionary *data = [item_json objectForKey:@"data"];
  319. if(data!=nil)
  320. {
  321. cardVC.content_data_download = [data mutableCopy];
  322. cardVC.url_type = URL_NONE;
  323. cardVC.request_url=nil;
  324. }
  325. else
  326. {
  327. cardVC.url_type = URL_REMOTE;
  328. cardVC.request_url=URL_CREDITCARD_EDOTOR;
  329. }
  330. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  331. params[@"orderCode"]=appDelegate.order_code;
  332. cardVC.params = params;
  333. cardVC.delegate = self;
  334. cardVC.from = indexPath;
  335. // orderinfoVC.params = params;
  336. [self.navigationController pushViewController:cardVC animated:true];
  337. }
  338. else if([value isEqualToString:@"Sales_Order_Freight_Bill_To"])
  339. {
  340. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  341. cvc.showNavibar = true;
  342. cvc.contact_type = value;
  343. __weak typeof(self) weakself = self;
  344. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  345. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  346. //
  347. // if(self.returnValue)
  348. // self.returnValue(value);
  349. };
  350. [self.navigationController pushViewController:cvc animated:true];
  351. }
  352. else if([value isEqualToString:@"Sales_Order_Ship_From"])
  353. {
  354. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  355. cvc.showNavibar = true;
  356. cvc.contact_type = value;
  357. __weak typeof(self) weakself = self;
  358. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  359. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  360. //
  361. // if(self.returnValue)
  362. // self.returnValue(value);
  363. };
  364. [self.navigationController pushViewController:cvc animated:true];
  365. }
  366. else if([value isEqualToString:@"Sales_Order_Customer"])
  367. {
  368. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  369. cvc.contact_type = value;
  370. cvc.showNavibar = true;
  371. __weak typeof(self) weakself = self;
  372. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  373. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  374. //
  375. // if(self.returnValue)
  376. // self.returnValue(value);
  377. };
  378. [self.navigationController pushViewController:cvc animated:true];
  379. }
  380. else if([value isEqualToString:@"Sales_Order_Merchandise_Bill_To"])
  381. {
  382. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  383. cvc.showNavibar = true;
  384. cvc.contact_type = value;
  385. __weak typeof(self) weakself = self;
  386. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  387. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  388. //
  389. // if(self.returnValue)
  390. // self.returnValue(value);
  391. };
  392. [self.navigationController pushViewController:cvc animated:true];
  393. }
  394. else if([value isEqualToString:@"Contact_Return_To"])
  395. {
  396. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  397. cvc.showNavibar = true;
  398. cvc.contact_type = value;
  399. __weak typeof(self) weakself = self;
  400. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  401. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  402. //
  403. // if(self.returnValue)
  404. // self.returnValue(value);
  405. };
  406. [self.navigationController pushViewController:cvc animated:true];
  407. }
  408. else if([value isEqualToString:@"Sales_Order_Ship_To"])
  409. {
  410. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  411. cvc.showNavibar = true;
  412. cvc.contact_type = value;
  413. __weak typeof(self) weakself = self;
  414. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  415. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  416. //
  417. // if(self.returnValue)
  418. // self.returnValue(value);
  419. };
  420. [self.navigationController pushViewController:cvc animated:true];
  421. }
  422. }
  423. - (void)dealloc {
  424. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  425. [appDelegate.urgencyDic removeObjectForKey:[NSString stringWithFormat:@"level_%d",self.level]];
  426. [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:self.level] forKey:@"count"];
  427. if (self.isResume && self.userType == USER_ROLE_CUSTOMER) {
  428. [self releaseOrderAfterSave];
  429. }
  430. }
  431. -(void) viewWillAppear:(BOOL)animated
  432. {
  433. [super viewWillAppear:animated];
  434. [self start_urgency_timer];
  435. self.isResume = [[[NSUserDefaults standardUserDefaults] objectForKey:@"urgency_resume"] boolValue];
  436. self.userType = [[[NSUserDefaults standardUserDefaults] objectForKey:@"urgency_userType"] integerValue];
  437. BOOL canSubmit = [[[NSUserDefaults standardUserDefaults] objectForKey:@"urgency_submitOrder"] boolValue];
  438. // 检查权限
  439. NSMutableArray * items = [[NSMutableArray alloc]init];
  440. UIBarButtonItem *savebtn = nil;
  441. savebtn = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"save"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  442. style:UIBarButtonItemStylePlain
  443. target:self
  444. action:@selector(onSaveClick:)];
  445. UIImage *submit_img = [[UIImage imageNamed:@"commit"] imageWithRenderingMode:UIImageRenderingModeAutomatic];
  446. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)|| defined (BUILD_CONTRAST)
  447. submit_img = [[UIImage imageNamed:@"submit_red"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  448. #endif
  449. self.btnSubmitOrder = nil;
  450. self.btnSubmitOrder =[[UIBarButtonItem alloc] initWithImage:submit_img
  451. style:UIBarButtonItemStylePlain
  452. target:self
  453. action:@selector(onCommitOrderClick:)];
  454. UIBarButtonItem *fixedItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
  455. fixedItem.width = 20.0f;
  456. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  457. // if(appDelegate.user_type ==USER_ROLE_EMPLOYEE)
  458. {
  459. [items addObject:savebtn];
  460. [items addObject:fixedItem];
  461. }
  462. #ifdef SCANNER_ORDER
  463. [items addObject:self.btnSubmitOrder];
  464. [items addObject:fixedItem];
  465. UIBarButtonItem *switchbtn = nil;
  466. switchbtn = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"select"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  467. style:UIBarButtonItemStylePlain
  468. target:self
  469. action:@selector(onScanSwitchUserTypeClick:)];
  470. // [items addObject:switchbtn];
  471. if([self.content_data_download[@"readonly"] boolValue])
  472. [items removeAllObjects];
  473. #else
  474. if (!self.isResume) {
  475. // 正常情况
  476. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  477. // customer的订单必须是Sales Order并且有提交权限才能提交
  478. if ([RASingleton sharedInstance].currentOrderIsMerged && [RASingleton sharedInstance].permissions_submit_order) {
  479. [items addObject:self.btnSubmitOrder];
  480. }
  481. } else {
  482. [items addObject:self.btnSubmitOrder];
  483. }
  484. } else {
  485. // 恢复
  486. if (self.userType == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  487. // customer的订单必须是Sales Order并且有提交权限才能提交
  488. if (canSubmit) {
  489. [items addObject:self.btnSubmitOrder];
  490. }
  491. } else {
  492. [items addObject:self.btnSubmitOrder];
  493. }
  494. [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"urgency_resume"];
  495. [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"urgency_userType"];
  496. [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"urgency_submitOrder"];
  497. }
  498. #endif
  499. // [items addObject:item2];
  500. self.navigationItem.rightBarButtonItems=items;
  501. if(appDelegate.can_submit_order)
  502. {
  503. [self.btnSubmitOrder setImage:submit_img];
  504. self.btnSubmitOrder.enabled = true;
  505. }
  506. else
  507. {
  508. [self.btnSubmitOrder setImage:nil];
  509. self.btnSubmitOrder.enabled = false;
  510. }
  511. self.navigationController.navigationBarHidden=false;
  512. }
  513. -(void) download_success
  514. {
  515. // 用于处理不同child,在成功去的数据后,需要附加的操作。
  516. self.have_tail=[[self.content_data_download valueForKey:@"has_reItem"] boolValue];
  517. NSString* order_customerid=[self getValue:@"customer_cid"];
  518. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  519. appDelegate.order_customer_id = order_customerid;
  520. }
  521. - (void)viewDidLoad {
  522. [super viewDidLoad];
  523. self.editable = YES;
  524. UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"close"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  525. style:UIBarButtonItemStylePlain
  526. target:self
  527. action:@selector(onCloseClick:)];
  528. //[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Close", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onCloseClick:)];
  529. // closeButton.title = @"Close";
  530. self.navigationItem.leftBarButtonItem = closeButton;
  531. // self.navigationItem.rightBarButtonItem = switchbtn;
  532. // self.navigationItem.backBarButtonItem = backButton;
  533. // Do any additional setup after loading the view.
  534. self.origincontent = [RAConvertor dict2string:self.content_data_download];
  535. }
  536. - (void)onCommitOrderClick:(id)sender {
  537. // get customer info
  538. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  539. #ifdef SCANNER_ORDER
  540. if([appDelegate.user isEqualToString:@"GUEST"]&& self.realuser.length==0)
  541. {
  542. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Submit Order" message:@"Please enter your user name and password." preferredStyle:UIAlertControllerStyleAlert];
  543. [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
  544. textField.placeholder = @"User";
  545. // textField.secureTextEntry = YES;
  546. }];
  547. [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
  548. textField.placeholder = @"Password";
  549. textField.secureTextEntry = YES;
  550. }];
  551. UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  552. UITextField *user = alertController.textFields[0];
  553. UITextField *password = alertController.textFields[1];
  554. if(user.text.length<=0)
  555. {
  556. [RAUtils message_alert:@"User can't be empty." title:@"Warring" controller:self];
  557. return;
  558. }
  559. if(password.text.length<=0)
  560. {
  561. [RAUtils message_alert:@"Password can't be empty." title:@"Warring" controller:self];
  562. return;
  563. }
  564. self.realuser =user.text;
  565. self.realpassword =password.text;
  566. [self onCommitOrderClick:sender];
  567. return;
  568. // if (![user.text isEqualToString:@""]) {
  569. //
  570. // //change password
  571. //
  572. // }
  573. // else{
  574. // [self presentViewController:alertController animated:YES completion:nil];
  575. // }
  576. }];
  577. [alertController addAction:okAction];
  578. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  579. NSLog(@"Canelled");
  580. }];
  581. [alertController addAction:cancelAction];
  582. [self presentViewController:alertController animated:YES completion:nil];
  583. return;
  584. }
  585. #endif
  586. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  587. //
  588. // // 检查价格类型
  589. // // 提货价才能提交订单
  590. // /** 价格类型
  591. // * 0 提货价
  592. // * 1 统一价
  593. // * 2 计算价
  594. // */
  595. // NSInteger priceType = [Singleton sharedInstance].npd_shop_price_type;
  596. // if (priceType != 0) {
  597. //
  598. // NSString* pricename = nil;
  599. // switch (priceType) {
  600. // case 1:
  601. // pricename=flat_price;
  602. // break;
  603. // case 2:
  604. // pricename=given_price;
  605. // break;
  606. // default:
  607. // break;
  608. // }
  609. //
  610. // UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"Current price is %@, please change to %@ and try again.",pricename,[Singleton sharedInstance].deliveryString] preferredStyle:UIAlertControllerStyleAlert];
  611. //
  612. // UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  613. //
  614. // [alertVC dismissViewControllerAnimated:YES completion:nil];
  615. //
  616. // }];
  617. //
  618. //
  619. // [alertVC addAction:cancelAction];
  620. //
  621. // [self presentViewController:alertVC animated:YES completion:nil];
  622. //
  623. // return;
  624. // }
  625. // }
  626. NSString* msg;
  627. #ifdef OFFLINE_MODE
  628. if(appDelegate.offline_mode)
  629. {
  630. msg=@"Are you sure to mark offline order as ready for submit?";
  631. }
  632. else
  633. #endif
  634. {
  635. msg=@"Submit order now?";
  636. }
  637. //
  638. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Order Submission" message:msg preferredStyle:UIAlertControllerStyleAlert];
  639. UIAlertAction *yesAction = [UIAlertAction actionWithTitle:@"YES" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  640. {
  641. // add params check here.
  642. [self.lastedit endEditing:true];
  643. [self.lasttextview endEditing:true];
  644. NSMutableDictionary* upparams = [self check_cancommit:true];
  645. if(self.cancommit==false)
  646. return;
  647. // 2018-1-2 Modify
  648. #ifndef SCANNER_ORDER
  649. if(appDelegate.user_type == USER_ROLE_CUSTOMER)
  650. {
  651. [self customer_commit_order:upparams];
  652. }
  653. else // USER_ROLE_EMPLOYEE
  654. {
  655. #endif
  656. if([upparams[@"shipping"] isEqualToString:@"Shipping To Be Quoted"]||[upparams[@"shipping"] isEqualToString:@"To Be Quoted"])
  657. {
  658. upparams[@"shipping"] = nil;
  659. }
  660. if(upparams[@"shipping"]==nil || [upparams[@"shipping"] doubleValue]!=0)
  661. [self empolyee_commit_order:upparams];
  662. else
  663. {
  664. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Shipping is $0.00, continue submit?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  665. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action)
  666. {
  667. //yes
  668. [self empolyee_commit_order:upparams];
  669. }];
  670. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  671. //DebugLog(@"Cancel");
  672. }];
  673. [alertControl addAction:actionOne];
  674. [alertControl addAction:alertthree];
  675. [self presentViewController:alertControl animated:YES completion:nil];
  676. }
  677. #ifndef SCANNER_ORDER
  678. }
  679. #endif
  680. }
  681. }];
  682. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"NO" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  683. }];
  684. [alertVC addAction:yesAction];
  685. [alertVC addAction:cancelAction];
  686. [self presentViewController:alertVC animated:yesAction completion:nil];
  687. }
  688. - (UIView *)createDemoView:(NSString*) msg
  689. {
  690. UIView *demoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 290, 200)];
  691. // UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 270, 180)];
  692. // [imageView setImage:[UIImage imageNamed:@"demo"]];
  693. UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 270, 10)];
  694. titleLabel.font = [UIFont boldSystemFontOfSize:20];
  695. titleLabel.text=@"Order Submission";
  696. titleLabel.numberOfLines = 0;
  697. titleLabel.lineBreakMode =NSLineBreakByWordWrapping;
  698. // titleLabel.textAlignment = NSTextAlignmentRight;
  699. titleLabel.textAlignment = NSTextAlignmentCenter;
  700. CGSize constraintkey = CGSizeMake(270, 20000.0f);//key label width is 40% cell width;
  701. // CGSize sizetitle = [titleLabel.text=@"Order Submission" sizeWithFont:[UIFont systemFontOfSize:20.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  702. CGSize sizetitle = [RAUtils sizeWithFont:titleLabel.text=@"Order Submission" font:[UIFont systemFontOfSize:20.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  703. //[titleLabel sizeToFit];
  704. // titleLabel.center.x = demoView.center.x;
  705. titleLabel.frame = CGRectMake(10, 10, 270, sizetitle.height);
  706. [demoView addSubview:titleLabel];
  707. UILabel *lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 260, 10)];
  708. lineLabel.font = [UIFont systemFontOfSize:17];
  709. lineLabel.text=msg;
  710. lineLabel.numberOfLines = 0;
  711. lineLabel.lineBreakMode =NSLineBreakByWordWrapping;
  712. // CGSize sizemsg = [msg sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  713. CGSize sizemsg = [RAUtils sizeWithFont:msg font:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
  714. lineLabel.frame = CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 260, sizemsg.height);
  715. //[lineLabel sizeToFit];
  716. [demoView addSubview:lineLabel];
  717. demoView.frame = CGRectMake(0, 0, 290, lineLabel.frame.origin.y+lineLabel.frame.size.height+25);
  718. return demoView;
  719. }
  720. -(bool)checkDirty
  721. {
  722. return self.isdirty;
  723. // bool dirty = false;
  724. // int isection =[self.content_data_download[@"section_count"] intValue];
  725. // for(int i = 0;i <isection;i++ )
  726. // {
  727. // NSDictionary * section = self.content_data_download[[NSString stringWithFormat:@"section_%d",i]];
  728. // int iitem =[section[@"count"] intValue];
  729. // for(int j = 0;j <iitem;j++ )
  730. // {
  731. // NSDictionary * item = section[[NSString stringWithFormat:@"item_%d",j]];
  732. // if([item[@"dirty"] boolValue])
  733. // return true;
  734. // }
  735. // }
  736. // return false;
  737. }
  738. - (void)onCloseClick:(UIButton *)sender {
  739. #ifdef SCANNER_ORDER
  740. [self.lastedit endEditing:true];
  741. [self.lasttextview endEditing:true];
  742. if(![self checkDirty])
  743. [self.navigationController popViewControllerAnimated:true];
  744. else
  745. {
  746. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Close" message:@"Do you want to save your changes?" preferredStyle:UIAlertControllerStyleAlert];
  747. UIAlertAction *action_0 = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  748. [self onSaveClick:nil];
  749. }];
  750. UIAlertAction *action_1 = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  751. [self.navigationController popViewControllerAnimated:true];
  752. }];
  753. UIAlertAction *action_3 = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  754. }];
  755. [alertController addAction:action_0];
  756. [alertController addAction:action_1];
  757. [alertController addAction:action_3];
  758. [self presentViewController:alertController animated:YES completion:nil];
  759. }
  760. return;
  761. #endif
  762. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  763. if (self.resumeOrder) {
  764. [appDelegate.main_vc.navigationController popViewControllerAnimated:YES];
  765. return;
  766. }
  767. //
  768. // NSRange range = [tempStr rangeOfString:@")\">"];//判断字符串是否包含
  769. //
  770. // //if (range.location ==NSNotFound)//不包含
  771. // if (range.length >0)//包含
  772. // {
  773. //
  774. //
  775. //
  776. // }
  777. // else//不包含
  778. // {
  779. //
  780. // }
  781. // UIAlertView * alert = nil;
  782. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Close" message:@"Choose your action" preferredStyle:UIAlertControllerStyleAlert];
  783. UIAlertAction *action_0 = [UIAlertAction actionWithTitle:@"Switch to cart" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  784. [((MainViewController*)appDelegate.main_vc) switchToCart];
  785. [self.navigationController popViewControllerAnimated:true];
  786. }];
  787. UIAlertAction *action_1 = [UIAlertAction actionWithTitle:@"Switch to order history" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  788. [self.navigationController popViewControllerAnimated:false];
  789. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  790. [((MainViewController*)appDelegate.main_vc) switchToOrder];
  791. }];
  792. NSString * a2Title=nil;
  793. if(appDelegate.order_status==0)
  794. a2Title=@"Close and cancel order";
  795. else
  796. a2Title=@"Close and release order";
  797. UIAlertAction *action_2 = [UIAlertAction actionWithTitle:a2Title style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  798. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  799. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Release Order" completion:^{
  800. #ifdef SCANNER_ORDER
  801. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  802. {
  803. [waitalert dismissViewControllerAnimated:YES completion:^{
  804. [OLDataProvider deleteScanOrder:appDelegate.order_code];
  805. [appDelegate closeOrder];
  806. //
  807. [self prepareReturn:nil];
  808. [self.navigationController popViewControllerAnimated:true];
  809. [((MainViewController*)appDelegate.main_vc) switchToOrder];
  810. }];
  811. return;
  812. }
  813. #endif
  814. [RANetwork request_release_order:appDelegate.order_code withScreen:nil completionHandler:^(NSMutableDictionary *result) {
  815. NSDictionary* order_json = result;
  816. [waitalert dismissViewControllerAnimated:YES completion:^{
  817. if([[order_json valueForKey:@"result"] intValue]==2)
  818. {
  819. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  820. // appDelegate.order_code = nil;
  821. [appDelegate closeOrder];
  822. #ifdef RA_NOTIFICATION
  823. [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  824. #else
  825. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  826. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  827. #endif
  828. [((MainViewController*)appDelegate.main_vc) switchToHome];
  829. if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  830. {
  831. [((MainViewController*)appDelegate.main_vc) Loginout:false];
  832. }
  833. [self prepareReturn:nil];
  834. [self.navigationController popViewControllerAnimated:true];
  835. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  836. // ;
  837. // }];
  838. }
  839. else
  840. {
  841. [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order"controller:self] ;
  842. }
  843. }];
  844. }];
  845. }];
  846. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  847. //
  848. // NSDictionary* order_json = [RANetwork release_Order:appDelegate.order_code withScreen:nil];
  849. //
  850. // dispatch_async(dispatch_get_main_queue(), ^{
  851. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  852. // if([[order_json valueForKey:@"result"] intValue]==2)
  853. // {
  854. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  855. // // appDelegate.order_code = nil;
  856. //
  857. // [appDelegate closeOrder];
  858. //
  859. //
  860. //#ifdef RA_NOTIFICATION
  861. // [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  862. //#else
  863. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  864. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  865. //#endif
  866. //
  867. // [((MainViewController*)appDelegate.main_vc) switchToHome];
  868. //
  869. // if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  870. // {
  871. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  872. // }
  873. //
  874. // [self prepareReturn:nil];
  875. //
  876. //
  877. // [self.navigationController popViewControllerAnimated:true];
  878. // // [self.navigationController dismissViewControllerAnimated:true completion:^{
  879. // // ;
  880. // // }];
  881. //
  882. // }
  883. // else
  884. // {
  885. // [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order"controller:self] ;
  886. // }
  887. //
  888. //
  889. //
  890. // });
  891. // });
  892. }];
  893. UIAlertAction *action_3 = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  894. }];
  895. [alertController addAction:action_0];
  896. [alertController addAction:action_1];
  897. [alertController addAction:action_2];
  898. [alertController addAction:action_3];
  899. [self presentViewController:alertController animated:YES completion:nil];
  900. // alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Choose your action", nil) message:NSLocalizedString(@"", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Switch to cart", nil),@"Switch to order history",NSLocalizedString(@"Close and cancel order", nil), nil];
  901. // else
  902. // {
  903. //
  904. // UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Close" message:@"Choose your action" preferredStyle:UIAlertControllerStyleAlert];
  905. //
  906. //
  907. // UIAlertAction *action_0 = [UIAlertAction actionWithTitle:@"Switch to cart" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  908. //
  909. //
  910. //
  911. // }];
  912. //
  913. // UIAlertAction *action_1 = [UIAlertAction actionWithTitle:@"Switch to order history" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  914. //
  915. //
  916. //
  917. // }];
  918. // UIAlertAction *action_2 = [UIAlertAction actionWithTitle:@"Close and release order" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  919. //
  920. //
  921. //
  922. // }];
  923. // UIAlertAction *action_3 = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  924. //
  925. //
  926. //
  927. // }];
  928. // [alertController addAction:action_0];
  929. // [alertController addAction:action_1];
  930. // [alertController addAction:action_2];
  931. // [alertController addAction:action_3];
  932. //
  933. //
  934. // [self presentViewController:alertController animated:YES completion:nil];
  935. //
  936. //
  937. //// alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Choose your action", nil) message:NSLocalizedString(@"", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Switch to cart", nil),@"Switch to order history",NSLocalizedString(@"Close and release order", nil), nil];
  938. //
  939. // }
  940. // alert.tag = CLOSE_ACTION;
  941. // // alert.
  942. // [alert show];
  943. // if ([[upparams valueForKey:@"close_on_save"] boolValue]) {
  944. // appDelegate.order_code = nil;
  945. //
  946. // }
  947. }
  948. - (void)didReceiveMemoryWarning {
  949. [super didReceiveMemoryWarning];
  950. // Dispose of any resources that can be recreated.
  951. }
  952. #ifdef SCANNER_ORDER
  953. -(void) scanSave:(NSMutableDictionary*) upparams
  954. {
  955. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  956. NSString *orderdir = [OLDataProvider getScanPath];
  957. NSString* userdir = [OLDataProvider getUserPath];
  958. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  959. [RAUtils dicttofile:orderPath dict:self.content_data_download];
  960. int section_count = [self.content_data_download[@"section_count"] intValue];
  961. for(int i=0;i<section_count;i++)
  962. {
  963. NSMutableDictionary* section = [self.content_data_download[[NSString stringWithFormat:@"section_%d",i]] mutableCopy];
  964. NSString* title = section[@"title"];
  965. // if([title isEqualToString:@"Model Information"])
  966. // {
  967. //
  968. // NSMutableDictionary* cart_section = RASingleton.sharedInstance.scan_cart[@"section_0"];
  969. // int cart_count = [cart_section[@"count"] intValue];
  970. // for(int j=0;j<cart_count;j++)
  971. // {
  972. // NSMutableDictionary* cart_item = [cart_section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  973. // cart_item[@"description"]= [NSString stringWithFormat:@"%@\n%@\n%@",cart_item[@"model"],cart_item[@"description"],cart_item[@"dimension"] ];
  974. // cart_item[@"control"]=@"model";
  975. // section[[NSString stringWithFormat:@"item_%d",j]] = cart_item;
  976. //
  977. // }
  978. // section[@"count"] = @(cart_count);
  979. // dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  980. // }
  981. // else
  982. if([title isEqualToString:@"Customer"])
  983. {
  984. // 订单信息会写customer info
  985. int scount = [section[@"count"] intValue];
  986. for(int j=0;j<scount;j++)
  987. {
  988. NSMutableDictionary * item = [section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  989. NSString * name = item[@"name"];
  990. if(item[@"value"]!=nil )
  991. appDelegate.customerInfo[name]=item[@"value"];
  992. }
  993. // NSDictionary* item_0=@{@"control":@"text",@"name":@"customer_cid",@"aname":@"Contact",@"value":appDelegate.contact_id};
  994. }
  995. // else
  996. // if([title isEqualToString:@"Remarks Content"])
  997. // {
  998. //
  999. // int scount = [section[@"count"] intValue];
  1000. // for(int j=0;j<scount;j++)
  1001. // {
  1002. // NSMutableDictionary * item = [section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  1003. // NSString * name = item[@"name"];
  1004. //
  1005. //
  1006. // if([name isEqualToString:@"comments"])
  1007. // {
  1008. // item[@"value"] = RASingleton.sharedInstance.scan_cart[@"general_note"];
  1009. // section[[NSString stringWithFormat:@"item_%d",j]] = item;
  1010. // }
  1011. //
  1012. //
  1013. // }
  1014. //
  1015. // // NSDictionary* item_0=@{@"control":@"text",@"name":@"customer_cid",@"aname":@"Contact",@"value":appDelegate.contact_id};
  1016. // dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  1017. //
  1018. //
  1019. // }
  1020. // else if([title isEqualToString:@"Order Total"])
  1021. // {
  1022. //
  1023. // int scount = [section[@"count"] intValue];
  1024. // for(int j=0;j<scount;j++)
  1025. // {
  1026. // NSMutableDictionary * item = [section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  1027. // NSString * name = item[@"name"];
  1028. //
  1029. //
  1030. // if([name isEqualToString:@"totalPrice"])
  1031. // {
  1032. // item[@"value"] = [NSString stringWithFormat:@"%.2f",self.total];
  1033. // section[[NSString stringWithFormat:@"item_%d",j]] = item;
  1034. // }
  1035. //
  1036. //
  1037. // }
  1038. //
  1039. // // NSDictionary* item_0=@{@"control":@"text",@"name":@"customer_cid",@"aname":@"Contact",@"value":appDelegate.contact_id};
  1040. // dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  1041. //
  1042. //
  1043. //
  1044. // }
  1045. }
  1046. NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  1047. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  1048. NSString *cartpath = [orderdir stringByAppendingPathComponent:@"cart.json"];
  1049. RASingleton.sharedInstance.scan_cart[@"price_type"] = @(RASingleton.sharedInstance.price_type);
  1050. [RAUtils dicttofile:cartpath dict:RASingleton.sharedInstance.scan_cart];
  1051. NSMutableDictionary* orderlist = nil;
  1052. NSString *orderlistPath = [userdir stringByAppendingPathComponent:@"orderlist.json"];
  1053. if (![[NSFileManager defaultManager] fileExistsAtPath:orderlistPath]) {
  1054. orderlist = [NSMutableDictionary new];
  1055. // [orderlist addObject:appDelegate.order_code];
  1056. // [RAUtils dicttofile:orderlistPath dict:orderlist];
  1057. }
  1058. else
  1059. {
  1060. orderlist=[[RAUtils dictfromfile:orderlistPath] mutableCopy];
  1061. // [orderlist insertObject:appDelegate.order_code atIndex:0];
  1062. // [RAUtils dicttofile:orderlistPath dict:orderlist];
  1063. }
  1064. NSMutableDictionary* orderitem = [NSMutableDictionary new];
  1065. orderitem[@"create_by"] = appDelegate.user;
  1066. orderitem[@"price"] = upparams[@"totalPrice"];
  1067. // NSString*
  1068. NSString* company = upparams[@"customer_cid"];
  1069. if(company.length==0)
  1070. company = upparams[@"customer_name"];
  1071. orderitem[@"customer_name"] = company;
  1072. orderitem[@"purchase_time"] = [RAUtils current_date_time];
  1073. if(self.fail_submit)
  1074. orderitem[@"order_status"] = @"Unsubmitted Order";
  1075. else
  1076. orderitem[@"order_status"] = @"Saved Order";
  1077. orderitem[@"order_code"] = appDelegate.order_code;
  1078. NSMutableDictionary* section =RASingleton.sharedInstance.scan_cart[@"section_0"];
  1079. int order_qty=0;
  1080. for(int c=0;c<[section[@"count"] intValue];c++)
  1081. {
  1082. NSDictionary* item = section[[NSString stringWithFormat:@"item_%d",c]];
  1083. order_qty+=[item[@"count"] intValue];
  1084. }
  1085. orderitem[@"model_count"] =[ NSString stringWithFormat:@"%d",order_qty];//RASingleton.sharedInstance.scan_cart[@"section_0"][@"count"] ];
  1086. int count = [orderlist[@"count"] intValue];
  1087. NSMutableDictionary* newlist = [NSMutableDictionary new];
  1088. newlist[@"item_0"]=orderitem;
  1089. int newcount = 1;
  1090. for(int i=0;i<count;i++)
  1091. {
  1092. NSMutableDictionary* item = orderlist[[NSString stringWithFormat:@"item_%d",i]];
  1093. if([item[@"order_code"] isEqualToString: appDelegate.order_code ])
  1094. continue;
  1095. else
  1096. {
  1097. newlist[[NSString stringWithFormat:@"item_%d",newcount]] = item;
  1098. newcount++;
  1099. }
  1100. }
  1101. newlist[@"count"] = @(newcount);
  1102. [RAUtils dicttofile:orderlistPath dict:newlist];
  1103. #ifdef RA_NOTIFICATION
  1104. [ActiveViewController Notify:@"CartViewController,ScanOrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1105. #else
  1106. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1107. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  1108. #endif
  1109. }
  1110. #endif
  1111. -(void) newScanOrder
  1112. {
  1113. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1114. // if(appDelegate.user.length<=0)
  1115. // {
  1116. // [RAUtils message_alert:@"Please login first." title:@"Warring" controller:self];
  1117. // return;
  1118. // }
  1119. if(appDelegate.order_code.length>0)
  1120. {
  1121. // 当前订单先关闭
  1122. // [OLDataProvider deleteScanOrder:appDelegate.order_code];
  1123. appDelegate.order_code = nil;
  1124. RASingleton.sharedInstance.scan_temp_code = nil;
  1125. if(appDelegate.customer_type!=USER_ROLE_CUSTOMER ) //customer 角色不清空customer info
  1126. { appDelegate.customerInfo = nil;
  1127. appDelegate.contact_id = nil;
  1128. }
  1129. RASingleton.sharedInstance.scan_cart = nil;
  1130. RASingleton.sharedInstance.price_type = 1;
  1131. // [appDelegate updateScanButton:false];
  1132. [appDelegate update_count_mark];
  1133. [appDelegate closeOrder];
  1134. }
  1135. // RASingleton.sharedInstance.enable_OfflineOrder = true;
  1136. // __block MainViewController *brself= self;
  1137. NSString* order_code = RASingleton.sharedInstance.scan_temp_code;
  1138. appDelegate.can_set_cart_price = true;
  1139. appDelegate.can_see_price = true;
  1140. RASingleton.sharedInstance.scan_cart = nil;
  1141. RASingleton.sharedInstance.price_type = 1;
  1142. {
  1143. NSString *orderdir = [OLDataProvider getScanPath];
  1144. [OLDataProvider moveScanTemp2Order];
  1145. NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  1146. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  1147. }
  1148. #ifdef RA_NOTIFICATION
  1149. [ActiveViewController Notify:@"CartViewController,ScanOrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1150. #else
  1151. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  1152. [main_vc reloadCart:true immediately:false];
  1153. #endif
  1154. MainViewController * mainvc = (MainViewController*)appDelegate.main_vc;
  1155. [mainvc switchToCart];
  1156. }
  1157. - (IBAction)onSaveClick:(id)sender {
  1158. // id foo = nil;
  1159. // [[NSMutableArray array] addObject:foo];
  1160. // add params check here.
  1161. [self.lastedit endEditing:true];
  1162. [self.lasttextview endEditing:true];
  1163. NSMutableDictionary* upparams = [self check_cancommit:false];
  1164. // if(self.cancommit==false)
  1165. // return;
  1166. if([upparams[@"shipping"] isEqualToString:@"Shipping To Be Quoted"]||[upparams[@"shipping"] isEqualToString:@"To Be Quoted"])
  1167. upparams[@"shipping"] = nil;
  1168. #ifdef SCANNER_ORDER
  1169. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  1170. {
  1171. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  1172. // NSString *documents = [paths objectAtIndex:0];
  1173. [self scanSave:upparams];
  1174. [RAUtils message_alert:@"Save Successfully" title:@"Message" controller:self action_handler:^(UIAlertAction * _Nonnull action) {
  1175. [self newScanOrder];
  1176. [self.navigationController popViewControllerAnimated:true];
  1177. } completion:nil];
  1178. return;
  1179. }
  1180. #endif
  1181. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Saving Order" completion:^{
  1182. [RANetwork request_save_order:upparams completionHandler:^(NSMutableDictionary *result) {
  1183. NSDictionary* editor_json =result;
  1184. [waitalert dismissViewControllerAnimated:YES completion:^{
  1185. if([[editor_json valueForKey:@"result"] intValue]==2)
  1186. {
  1187. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1188. NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  1189. if(appDelegate.user_type ==USER_ROLE_EMPLOYEE)
  1190. {
  1191. appDelegate.customerInfo = customerInfo;
  1192. appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  1193. }
  1194. NSString *msg = nil;
  1195. if ([editor_json objectForKey:@"so#"]) {
  1196. msg = [@"SO#:" stringByAppendingString:[editor_json objectForKey:@"so#"]];
  1197. }
  1198. [RAUtils message_alert:msg title:@"Order Saved" controller:self] ;
  1199. if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.save_order_logout && appDelegate.user_type ==USER_ROLE_EMPLOYEE)
  1200. {
  1201. [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1202. [self prepareReturn:nil];
  1203. [self.navigationController popViewControllerAnimated:true];
  1204. }
  1205. else{
  1206. #ifdef RA_NOTIFICATION
  1207. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1208. #else
  1209. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1210. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1211. #endif
  1212. }
  1213. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  1214. if (![RASingleton sharedInstance].currentOrderIsMerged) {
  1215. [self releaseOrderAfterSave];
  1216. }
  1217. }
  1218. // if ([[upparams valueForKey:@"close_on_save"] boolValue]) {
  1219. // appDelegate.order_code = nil;
  1220. //
  1221. // }
  1222. // // self.labelContact.text=appDelegate.contact_name;
  1223. //
  1224. // NSDictionary * customerinfo = appDelegate.customerInfo;
  1225. // [self prepareReturn:nil];
  1226. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  1227. //
  1228. //
  1229. // ;
  1230. // }];
  1231. }
  1232. else
  1233. {
  1234. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Save Order" controller:self] ;
  1235. }
  1236. }];
  1237. }];
  1238. }];
  1239. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1240. //
  1241. // NSDictionary* editor_json = [RANetwork save_Order:upparams];
  1242. //
  1243. // dispatch_async(dispatch_get_main_queue(), ^{
  1244. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  1245. //
  1246. //
  1247. // if([[editor_json valueForKey:@"result"] intValue]==2)
  1248. // {
  1249. //
  1250. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1251. //
  1252. //
  1253. //
  1254. // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  1255. //
  1256. //
  1257. // if(appDelegate.user_type ==USER_ROLE_EMPLOYEE)
  1258. // {
  1259. // appDelegate.customerInfo = customerInfo;
  1260. // appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  1261. // }
  1262. // NSString *msg = nil;
  1263. // if ([editor_json objectForKey:@"so#"]) {
  1264. // msg = [@"SO#:" stringByAppendingString:[editor_json objectForKey:@"so#"]];
  1265. // }
  1266. // [RAUtils message_alert:msg title:@"Order Saved" controller:self] ;
  1267. //
  1268. // if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.save_order_logout && appDelegate.user_type ==USER_ROLE_EMPLOYEE)
  1269. // {
  1270. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1271. // [self prepareReturn:nil];
  1272. // [self.navigationController popViewControllerAnimated:true];
  1273. // }
  1274. // else{
  1275. //
  1276. //
  1277. //#ifdef RA_NOTIFICATION
  1278. // [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1279. //#else
  1280. //
  1281. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1282. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1283. //#endif
  1284. // }
  1285. //
  1286. // if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  1287. //
  1288. // if (![Singleton sharedInstance].currentOrderIsMerged) {
  1289. // [self releaseOrderAfterSave];
  1290. // }
  1291. //
  1292. //
  1293. // }
  1294. //
  1295. //
  1296. // // if ([[upparams valueForKey:@"close_on_save"] boolValue]) {
  1297. // // appDelegate.order_code = nil;
  1298. // //
  1299. // // }
  1300. // // // self.labelContact.text=appDelegate.contact_name;
  1301. // //
  1302. // // NSDictionary * customerinfo = appDelegate.customerInfo;
  1303. // // [self prepareReturn:nil];
  1304. // // [self.navigationController dismissViewControllerAnimated:true completion:^{
  1305. // //
  1306. // //
  1307. // // ;
  1308. // // }];
  1309. //
  1310. // }
  1311. // else
  1312. // {
  1313. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Save Order" controller:self] ;
  1314. // }
  1315. //
  1316. //
  1317. //
  1318. //
  1319. // });
  1320. // });
  1321. }
  1322. - (void)textFieldDidEndEditing:(UITextField *)textField
  1323. {
  1324. [super textFieldDidEndEditing:textField];
  1325. UITableViewCell *cell = (UITableViewCell *) textField.superview.superview;
  1326. NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
  1327. NSMutableDictionary* section_json=nil;
  1328. // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row);
  1329. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  1330. NSString* name = [item_json valueForKey:@"name"];
  1331. if([name isEqualToString:@"shipping"]|| [name isEqualToString:@"handling_fee_value"]||[name isEqualToString:@"lift_gate_value"]||[name isEqualToString:@"tax_percentage"])
  1332. {
  1333. float shipping = [self getprice:@"shipping" section:indexPath.section];
  1334. float paymentsAndCredits = [self getprice:@"paymentsAndCredits" section:indexPath.section];
  1335. float handling_fee_value = [self getprice:@"handling_fee_value" section:indexPath.section];
  1336. float lift_gate =[self getprice:@"lift_gate_value" section:indexPath.section];
  1337. float tax = [self getprice:@"tax_percentage" section:indexPath.section]/100.0*paymentsAndCredits;
  1338. float totalprice=shipping+paymentsAndCredits+handling_fee_value+lift_gate+tax;
  1339. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  1340. int count=0;
  1341. count=[[section_json valueForKey:@"count"] intValue];
  1342. int total_row_idx=-1;
  1343. for(int i=0;i<count;i++)
  1344. {
  1345. NSDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]] mutableCopy];
  1346. if([[olditem valueForKey:@"name"] isEqualToString:@"totalPrice" ])
  1347. {
  1348. [olditem setValue:[NSString stringWithFormat:@"%.2f",totalprice] forKey:@"value"];
  1349. [olditem setValue:@"true" forKey:@"dirty"];
  1350. [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",i ]];
  1351. total_row_idx=i;
  1352. }
  1353. }
  1354. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  1355. self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data];
  1356. if(total_row_idx>=0)
  1357. {
  1358. NSUInteger newIndex[] = {indexPath.section, total_row_idx};
  1359. NSIndexPath *newPath = [[NSIndexPath alloc] initWithIndexes:newIndex length:2];
  1360. // DebugLog(@"before refresh %@",NSStringFromCGSize(self.editorTable.contentSize));
  1361. [self.editorTable reloadRowsAtIndexPaths:@[newPath]withRowAnimation:UITableViewRowAnimationMiddle];
  1362. // DebugLog(@"after refresh %@",NSStringFromCGSize(self.editorTable.contentSize));
  1363. // CGSize tablecontent =self.editorTable.contentSize;
  1364. // tablecontent.height=tablecontent.height+self.keyboard_h;
  1365. // self.editorTable.contentSize=tablecontent;
  1366. //
  1367. //
  1368. // DebugLog(@"resize to %@",NSStringFromCGSize(self.editorTable.contentSize));
  1369. }
  1370. // self.content_data = [editor_json mutableCopy];
  1371. // self.content_data = [self translate_json:editor_json];
  1372. // NSMutableDictionary* content_data1 = [self translate_json:self.content_data];
  1373. // [self.editorTable reloadData];
  1374. }
  1375. //
  1376. // [item_json setValue:@"true" forKey:@"dirty"];
  1377. // [item_json setValue:textField.text forKey:@"value"];
  1378. }
  1379. -(float) getprice:(NSString*) name section :(long) index
  1380. {
  1381. NSMutableDictionary* section_json=nil;
  1382. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",index ]] mutableCopy];
  1383. int count=0;
  1384. count=[[section_json valueForKey:@"count"] intValue];
  1385. for(int i=0;i<count;i++)
  1386. {
  1387. NSDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]] mutableCopy];
  1388. if([[olditem valueForKey:@"name"] isEqualToString:name])
  1389. {
  1390. return [[olditem valueForKey:@"value"] floatValue];
  1391. }
  1392. }
  1393. return 0;
  1394. }
  1395. /*
  1396. #pragma mark - Navigation
  1397. // In a storyboard-based application, you will often want to do a little preparation before navigation
  1398. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  1399. // Get the new view controller using [segue destinationViewController].
  1400. // Pass the selected object to the new view controller.
  1401. }
  1402. */
  1403. //#pragma mark - UIAlertViewDelegate
  1404. //// Called when a button is clicked. The view will be automatically dismissed after this call returns
  1405. //- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  1406. //{
  1407. //
  1408. // if(alertView.tag == CLOSE_ACTION)
  1409. // {
  1410. // if(buttonIndex==1)
  1411. // {
  1412. //
  1413. // [self.navigationController popViewControllerAnimated:true];
  1414. // // back to cart;
  1415. // // [self.navigationController dismissViewControllerAnimated:true completion:^{
  1416. // // ;
  1417. // // }];
  1418. // // if ([[upparams valueForKey:@"close_on_save"] boolValue]) {
  1419. // // appDelegate.order_code = nil;
  1420. // //
  1421. // // }
  1422. // }
  1423. // if(buttonIndex==2)
  1424. // {
  1425. //
  1426. // [self.navigationController popViewControllerAnimated:false];
  1427. //
  1428. //
  1429. //
  1430. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1431. //
  1432. //
  1433. // [((MainViewController*)appDelegate.main_vc) switchToOrder];
  1434. // // back to cart;
  1435. // // [self.navigationController dismissViewControllerAnimated:true completion:^{
  1436. // // ;
  1437. // // }];
  1438. // // if ([[upparams valueForKey:@"close_on_save"] boolValue]) {
  1439. // // appDelegate.order_code = nil;
  1440. // //
  1441. // // }
  1442. // }
  1443. // else if(buttonIndex==3)
  1444. // {
  1445. // // close order;
  1446. //
  1447. //
  1448. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1449. // UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Release Order"];
  1450. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1451. //
  1452. // NSDictionary* order_json = [RANetwork release_Order:appDelegate.order_code withScreen:nil];
  1453. //
  1454. // dispatch_async(dispatch_get_main_queue(), ^{
  1455. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  1456. // if([[order_json valueForKey:@"result"] intValue]==2)
  1457. // {
  1458. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1459. // // appDelegate.order_code = nil;
  1460. //
  1461. // [appDelegate closeOrder];
  1462. //
  1463. //
  1464. //#ifdef RA_NOTIFICATION
  1465. // [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1466. //#else
  1467. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  1468. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1469. //#endif
  1470. //
  1471. // [((MainViewController*)appDelegate.main_vc) switchToHome];
  1472. //
  1473. // if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  1474. // {
  1475. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1476. // }
  1477. //
  1478. // [self prepareReturn:nil];
  1479. //
  1480. //
  1481. // [self.navigationController popViewControllerAnimated:true];
  1482. // // [self.navigationController dismissViewControllerAnimated:true completion:^{
  1483. // // ;
  1484. // // }];
  1485. //
  1486. // }
  1487. // else
  1488. // {
  1489. // [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order"controller:self] ;
  1490. // }
  1491. //
  1492. //
  1493. //
  1494. // });
  1495. // });
  1496. //
  1497. //
  1498. //
  1499. //
  1500. //
  1501. // //
  1502. // // }
  1503. // }
  1504. // }
  1505. //}
  1506. //
  1507. //
  1508. //-(void) downloadpdf:(NSString* )url
  1509. //{
  1510. // UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Printing..."];
  1511. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1512. //
  1513. //
  1514. // NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60*5];
  1515. //
  1516. // //设置请求方式为get
  1517. //
  1518. // [request setHTTPMethod:@"GET"];
  1519. //
  1520. // //添加用户会话id
  1521. //
  1522. // [request addValue:@"text/html" forHTTPHeaderField:@"Content-Type"];
  1523. //
  1524. // //连接发送请求
  1525. //
  1526. //
  1527. // NSHTTPURLResponse* urlResponse = nil;
  1528. //
  1529. // NSError *error = [[NSError alloc] init];
  1530. //
  1531. // NSData* content= [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];
  1532. //
  1533. // // self.filename = [urlResponse suggestedFilename];
  1534. //
  1535. //
  1536. // dispatch_async(dispatch_get_main_queue(), ^{
  1537. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  1538. // // self.navigationItem.title = self.save_name;
  1539. // // UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  1540. // // self.content=nil;
  1541. // if(content!=nil&&content.length>0)
  1542. // {
  1543. //
  1544. //
  1545. // [self startAirPrintWithData:content];
  1546. //
  1547. //
  1548. // }
  1549. // else
  1550. // {
  1551. // [RAUtils message_alert:nil title:@"Open PDF Failed" controller:self];
  1552. // // self.content = [self.url dataUsingEncoding:NSUTF8StringEncoding];
  1553. // }
  1554. //
  1555. // ;
  1556. // // DebugLog(@"%@",[[NSString alloc] initWithData:self.content encoding:NSASCIIStringEncoding]);
  1557. // //
  1558. //
  1559. //
  1560. // // [self.webView loadData:self.content MIMEType:urlResponse.MIMEType textEncodingName:nil baseURL:nil];
  1561. //
  1562. //
  1563. //
  1564. //
  1565. // });
  1566. // });
  1567. //}
  1568. //
  1569. //- (void)startAirPrintWithData:(id )data
  1570. //{
  1571. //
  1572. //
  1573. //
  1574. //
  1575. // UIPrintInteractionController* airPrinterController=[UIPrintInteractionController sharedPrintController];
  1576. // UIPrintInfo *printInfo = [UIPrintInfo printInfo];
  1577. // printInfo.outputType = UIPrintInfoOutputGeneral;
  1578. // printInfo.orientation = UIPrintInfoOrientationPortrait;
  1579. // printInfo.jobName = @"CoolVisitAirPrint";
  1580. // airPrinterController.printInfo = printInfo;
  1581. // airPrinterController.printingItem = data;
  1582. // airPrinterController.delegate = self;
  1583. //
  1584. //
  1585. // airPrinterController.showsNumberOfCopies=true;
  1586. // airPrinterController.showsPageRange = true;
  1587. // airPrinterController.showsPaperSelectionForLoadedPapers=true;
  1588. //
  1589. // void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
  1590. // if(completed && error)
  1591. // DebugLog(@"Printing failed due to error in domain %@ with error code %lu. Localized description: %@, and failure reason: %@", error.domain, (long)error.code, error.localizedDescription, error.localizedFailureReason);
  1592. // };
  1593. //
  1594. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1595. //
  1596. // UIPrinter *airPrinter = [UIPrinter printerWithURL:[NSURL URLWithString:appDelegate.printerURL] ];///*self.printer;*/
  1597. //
  1598. //
  1599. //
  1600. //
  1601. // [[UIPrinter printerWithURL:[NSURL URLWithString:appDelegate.printerURL]] contactPrinter:^(BOOL available)
  1602. // {
  1603. // if (available&& appDelegate.printerURL.length>0)
  1604. // {
  1605. //
  1606. // [airPrinterController printToPrinter:airPrinter completionHandler:completionHandler];
  1607. // DebugLog(@"AIRPRINTER AVAILABLE");
  1608. // }
  1609. // else
  1610. // {
  1611. //
  1612. // // [airPrinterController presentFromRect:CGRectMake(0, 0, 300, 500) inView:self.view animated:YES completionHandler:
  1613. // //
  1614. // //
  1615. // //
  1616. // // // [printPicker presentAnimated:YES completionHandler:
  1617. // // ^(UIPrintInteractionController *printerController, BOOL userDidSelect, NSError *error)
  1618. // // {
  1619. // // if (userDidSelect)
  1620. // // {
  1621. // // NSString* sid= printerController.printInfo.printerID;
  1622. // // UIPrintPaper*paper= printerController.printPaper;
  1623. // //
  1624. // // }
  1625. // // }];
  1626. //
  1627. //
  1628. // DebugLog(@"AIRPRINTER NOT AVAILABLE");
  1629. //
  1630. //
  1631. //
  1632. // if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1)
  1633. // {
  1634. // UIPrinterPickerController *printPicker = [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:nil];
  1635. // // [printPicker presentFromBarButtonItem:self.btnSubmitOrder animated:yes completionHandler:
  1636. //
  1637. //
  1638. //
  1639. // [ printPicker presentFromBarButtonItem:self.btnSubmitOrder animated:YES completionHandler:
  1640. //
  1641. //
  1642. // // [printPicker presentFromRect:CGRectMake(0, 0, 300, 500) inView:self.view animated:YES completionHandler:
  1643. //
  1644. //
  1645. //
  1646. // // [printPicker presentAnimated:YES completionHandler:
  1647. // ^(UIPrinterPickerController *printerPicker, BOOL userDidSelect, NSError *error)
  1648. // {
  1649. // if (userDidSelect)
  1650. // {
  1651. // //User selected the item in the UIPrinterPickerController and got the printer details.
  1652. //
  1653. // [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:printerPicker.selectedPrinter];
  1654. //
  1655. // //Here you will get the printer and printer details.ie,
  1656. // // printerPicker.selectedPrinter, printerPicker.selectedPrinter.displayName, printerPicker.selectedPrinter.URL etc. So you can display the printer name in your label text or button title.
  1657. //
  1658. //
  1659. //
  1660. //
  1661. // appDelegate.printerURL =printerPicker.selectedPrinter.URL.absoluteString;
  1662. //
  1663. // [self startAirPrintWithData:data];
  1664. //
  1665. // }
  1666. // else
  1667. // {
  1668. //
  1669. //
  1670. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1671. // if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
  1672. // {
  1673. //
  1674. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1675. // }
  1676. // [self prepareReturn:nil];
  1677. //
  1678. // [self.navigationController popViewControllerAnimated:true];
  1679. // }
  1680. // }];
  1681. // }
  1682. // }
  1683. // }];
  1684. //
  1685. //
  1686. //
  1687. //}
  1688. //
  1689. //#pragma mark - UIPrintInteractionControllerDelegate
  1690. //- (UIPrintPaper *)printInteractionController:(UIPrintInteractionController *)printInteractionController choosePaper:(NSArray<UIPrintPaper *> *)paperList
  1691. //{
  1692. //
  1693. // ;
  1694. //
  1695. // // (int) width = 29700
  1696. // // Printing description of (*( (int *)0x7caa3a40)):
  1697. // // (int) height = 42000
  1698. // //设置纸张大小
  1699. //
  1700. //
  1701. // for(UIPrintPaper* paper in paperList)
  1702. // {
  1703. // if (CGSizeEqualToSize(paper.paperSize, CGSizeMake(612, 792)))
  1704. // return paper;
  1705. //
  1706. // }
  1707. // CGSize paperSize = CGSizeMake(612, 792);
  1708. // UIPrintPaper * p=[UIPrintPaper bestPaperForPageSize:paperSize withPapersFromArray:paperList];
  1709. // return p;
  1710. //}
  1711. //- (void)printInteractionControllerWillPresentPrinterOptions:(UIPrintInteractionController *)printInteractionController
  1712. //{
  1713. //
  1714. //}
  1715. //- (void)printInteractionControllerDidPresentPrinterOptions:(UIPrintInteractionController *)printInteractionController
  1716. //{
  1717. //
  1718. //}
  1719. //- (void)printInteractionControllerWillDismissPrinterOptions:(UIPrintInteractionController *)printInteractionController
  1720. //{
  1721. //
  1722. //}
  1723. //- (void)printInteractionControllerDidDismissPrinterOptions:(UIPrintInteractionController *)printInteractionController
  1724. //{
  1725. //
  1726. //}
  1727. //
  1728. //- (void)printInteractionControllerWillStartJob:(UIPrintInteractionController *)printInteractionController
  1729. //{
  1730. //
  1731. //}
  1732. //- (void)printInteractionControllerDidFinishJob:(UIPrintInteractionController *)printInteractionController
  1733. //{
  1734. //
  1735. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1736. // if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
  1737. // {
  1738. //
  1739. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1740. // }
  1741. //
  1742. // [self prepareReturn:nil];
  1743. //
  1744. // [self.navigationController popViewControllerAnimated:true];
  1745. //}
  1746. //
  1747. //- (NSString *)currentPriceTypeName {
  1748. // NSInteger priceType = [Singleton sharedInstance].npd_shop_price_type;
  1749. //
  1750. // NSString* pricename = nil;
  1751. // switch (priceType) {
  1752. // case 0:
  1753. // pricename=[Singleton sharedInstance].deliveryString;
  1754. // break;
  1755. // case 1:
  1756. // pricename=flat_price;
  1757. // break;
  1758. // case 2:
  1759. // pricename=given_price;
  1760. // break;
  1761. // default:
  1762. // break;
  1763. // }
  1764. // return pricename;
  1765. //}
  1766. - (void)releaseOrderAfterSave {
  1767. dispatch_async(dispatch_get_main_queue(), ^{
  1768. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1769. // [RANetwork release_Order:appDelegate.order_code withScreen:nil];
  1770. [RANetwork request_release_order:appDelegate.order_code withScreen:nil completionHandler:nil];
  1771. [appDelegate closeOrder];
  1772. [appDelegate SetSo:nil];
  1773. appDelegate.cart_count=0;
  1774. [appDelegate update_count_mark];
  1775. [((MainViewController*)appDelegate.main_vc) switchToOrder];
  1776. [self prepareReturn:nil];
  1777. [self.navigationController popToRootViewControllerAnimated:false];
  1778. });
  1779. }
  1780. -(NSString* )create_customer_ext:(NSDictionary*)customerinfo
  1781. {
  1782. NSString* ret=nil;
  1783. NSString* customer_address1= [customerinfo valueForKey:@"customer_address1"];
  1784. NSString* customer_address2= [customerinfo valueForKey:@"customer_address2"];
  1785. NSString* customer_address3= [customerinfo valueForKey:@"customer_address3"];
  1786. NSString* customer_address4= [customerinfo valueForKey:@"customer_address4"];
  1787. NSMutableArray* arraddr = [[NSMutableArray alloc] init];
  1788. if(customer_address1.length>0)
  1789. [arraddr addObject:customer_address1];
  1790. if(customer_address2.length>0)
  1791. [arraddr addObject:customer_address2];
  1792. if(customer_address3.length>0)
  1793. [arraddr addObject:customer_address3];
  1794. if(customer_address4.length>0)
  1795. [arraddr addObject:customer_address4];
  1796. NSString *addr_string = [arraddr componentsJoinedByString:@"\r\n"];
  1797. NSString* customer_city= [customerinfo valueForKey:@"customer_city"];
  1798. NSString* customer_country= [customerinfo valueForKey:@"customer_country"];
  1799. NSString* customer_zipcode= [customerinfo valueForKey:@"customer_zipcode"];
  1800. NSString* customer_state= [customerinfo valueForKey:@"customer_state"];
  1801. NSMutableArray* arrcty = [[NSMutableArray alloc] init];
  1802. if(customer_city.length>0)
  1803. [arrcty addObject:customer_city];
  1804. if(customer_state.length>0)
  1805. [arrcty addObject:customer_state];
  1806. if(customer_zipcode.length>0)
  1807. [arrcty addObject:customer_zipcode];
  1808. if(customer_country.length>0)
  1809. [arrcty addObject:customer_country];
  1810. NSString *cty_string = [arrcty componentsJoinedByString:@", "];
  1811. // NSString* customer_phone= [customerinfo valueForKey:@"customer_phone"];
  1812. // NSString* customer_fax= [customerinfo valueForKey:@"customer_fax"];
  1813. //
  1814. // NSMutableArray* arrpho = [[NSMutableArray alloc] init];
  1815. // if(customer_phone.length>0)
  1816. // {
  1817. // customer_phone = [NSString stringWithFormat:@"TEL: %@",customer_phone];
  1818. // [arrpho addObject:customer_phone];
  1819. // }
  1820. // if(customer_fax.length>0)
  1821. // {
  1822. // customer_fax = [NSString stringWithFormat:@"FAX: %@",customer_fax];
  1823. // [arrpho addObject:customer_fax];
  1824. // }
  1825. // NSString *phone_string = [arrpho componentsJoinedByString:@", "];
  1826. //
  1827. //
  1828. // NSString* customer_contact= [customerinfo valueForKey:@"customer_contact"];
  1829. // if(customer_contact.length>0)
  1830. // {
  1831. // customer_contact = [NSString stringWithFormat:@"ATTN: %@",customer_contact];
  1832. //
  1833. // }
  1834. // NSString *contact_string = customer_contact;
  1835. //
  1836. //
  1837. // NSString* customer_email= [customerinfo valueForKey:@"customer_email"];
  1838. // if(customer_email.length>0)
  1839. // {
  1840. // customer_email = [NSString stringWithFormat:@"Email: %@",customer_email];
  1841. //
  1842. // }
  1843. // NSString *email_string = customer_email;
  1844. NSMutableArray* arrext = [[NSMutableArray alloc] init];
  1845. if(addr_string.length>0)
  1846. [arrext addObject:addr_string];
  1847. if(cty_string.length>0)
  1848. [arrext addObject:cty_string];
  1849. // if(phone_string.length>0)
  1850. // [arrext addObject:phone_string];
  1851. // if(contact_string.length>0)
  1852. // [arrext addObject:contact_string];
  1853. // if(email_string.length>0)
  1854. // [arrext addObject:email_string];
  1855. ret = [arrext componentsJoinedByString:@"\r\n"];
  1856. // NSString *string = [array componentsJoinedByString:@" "];
  1857. // NSString* customer_name= [customerinfo valueForKey:@"customer_name"];
  1858. return ret;
  1859. }
  1860. -(NSMutableDictionary*)create_value_map:(NSDictionary*)key_map
  1861. {
  1862. NSMutableDictionary* ret= [[NSMutableDictionary alloc] init];
  1863. NSArray *keys= [key_map allKeys];
  1864. //遍历keys
  1865. for(int i=0;i<[keys count];i++)
  1866. {
  1867. //得到当前key
  1868. NSString *key=[keys objectAtIndex:i];
  1869. //如果key不是pic,说明value是字符类型,比如name:Boris
  1870. NSString* valuefrom = [key_map valueForKey:key];
  1871. if(valuefrom.length==0)
  1872. continue;
  1873. NSString* value=[self getValue:valuefrom];
  1874. [ret setValue:value forKey:valuefrom];
  1875. }
  1876. NSDictionary * customerinfo =[self create_cusromer_info_from_table];
  1877. [ret setValue:[self create_customer_ext:customerinfo] forKey:@"customer_contact_ext"];
  1878. [ret setValue:customerinfo[@"customer_first_name"] forKey:@"customer_first_name"];
  1879. [ret setValue:customerinfo[@"customer_last_name"] forKey:@"customer_last_name"];
  1880. return ret;
  1881. }
  1882. -(NSMutableDictionary*)create_cusromer_info_from_table
  1883. {
  1884. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1885. NSMutableDictionary* ret= [appDelegate.customerInfo mutableCopy] ;
  1886. [ret setValue:[self getValue:@"customer_country"] forKey:@"customer_country"];
  1887. [ret setValue:[self getValue:@"customer_phone"] forKey:@"customer_phone"];
  1888. [ret setValue:[self getValue:@"customer_email"] forKey:@"customer_email"];
  1889. [ret setValue:[self getValue:@"customer_name"] forKey:@"customer_name"];
  1890. [ret setValue:[self getValue:@"customer_address4"] forKey:@"customer_address4"];
  1891. [ret setValue:[self getValue:@"customer_address3"] forKey:@"customer_address3"];
  1892. [ret setValue:[self getValue:@"customer_address2"] forKey:@"customer_address2"];
  1893. [ret setValue:[self getValue:@"customer_address1"] forKey:@"customer_address1"];
  1894. [ret setValue:[self getValue:@"customer_zipcode"] forKey:@"customer_zipcode"];
  1895. [ret setValue:[self getValue:@"customer_city"] forKey:@"customer_city"];
  1896. [ret setValue:[self getValue:@"customer_state"] forKey:@"customer_state"];
  1897. [ret setValue:[self getValue:@"customer_cid"] forKey:@"customer_cid"];
  1898. [ret setValue:[self getValue:@"customer_state"] forKey:@"customer_state"];
  1899. [ret setValue:[self getValue:@"customer_contact"] forKey:@"customer_contact"];
  1900. [ret setValue:[self getValue:@"customer_fax"] forKey:@"customer_fax"];
  1901. NSString * firstname =nil;
  1902. NSString* lastname = nil;
  1903. NSString* contact_name = [self getValue:@"customer_contact"];
  1904. if(contact_name!=nil)
  1905. {
  1906. NSArray *_arr = [contact_name componentsSeparatedByString:NSLocalizedString(@" ", nil)];
  1907. if(_arr.count>=1)
  1908. {
  1909. firstname =_arr[0];
  1910. if(_arr.count>1)
  1911. {
  1912. lastname=[[_arr subarrayWithRange:NSMakeRange(1, _arr.count-1)] componentsJoinedByString:@" "];
  1913. }
  1914. }
  1915. }
  1916. [ret setValue:firstname forKey:@"customer_first_name"];
  1917. [ret setValue:lastname forKey:@"customer_last_name"];
  1918. // [ret setValue:[self create_customer_ext:ret] forKey:@"customer_contact_ext"];
  1919. return ret;
  1920. }
  1921. #pragma mark - multi_action sub action clicked
  1922. - (void)MActionClicked:(UIButton *)sender {
  1923. UITableViewCell *cell = (UITableViewCell *) sender.superview.superview;
  1924. NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
  1925. int refresh =0;
  1926. NSMutableDictionary* section_json=nil;
  1927. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  1928. NSString* subid=[item_json valueForKey:@"subid"];
  1929. NSString* refresh_trigger = [item_json valueForKey:@"name"];
  1930. NSDictionary* sub_action = [item_json objectForKey:[NSString stringWithFormat:@"item_%ld",(long)sender.tag]];
  1931. NSString* type = [sub_action valueForKey:@"type"];
  1932. bool discardDirty = [[sub_action valueForKey:@"discard_dirty"] boolValue];
  1933. if([type isEqualToString:@"pull"])
  1934. {
  1935. [self.lastedit endEditing:true];
  1936. refresh = [[sub_action valueForKey:@"refresh"] intValue];
  1937. NSDictionary* keymap= [sub_action objectForKey:@"key_map"];
  1938. NSMutableDictionary* value=[self create_value_map:keymap];
  1939. if(subid==nil)
  1940. {
  1941. NSDictionary* jsonmap=[sub_action valueForKey:@"key_map"];
  1942. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  1943. int icount=[[section_json valueForKey:@"count"] intValue];
  1944. for (int ic=0;ic<icount;ic++)
  1945. {
  1946. NSMutableDictionary* modify_item= [[section_json objectForKey:[NSString stringWithFormat:@"item_%d",ic ]] mutableCopy];
  1947. NSString* mapto = [modify_item valueForKey:@"name"];
  1948. if(mapto.length==0)
  1949. continue;
  1950. NSString* valuefrom= [jsonmap valueForKey:[modify_item valueForKey:@"name"]];
  1951. if(valuefrom==nil)
  1952. continue;
  1953. NSString* valuestr=[value valueForKey:valuefrom];
  1954. // valuestr = [self getValue:valuefrom];
  1955. if(true)
  1956. {
  1957. if(valuestr.length>0)
  1958. [modify_item setValue:valuestr forKey:@"value"];
  1959. else
  1960. [modify_item setValue:@"" forKey:@"value"];
  1961. [modify_item setValue:@"true" forKey:@"dirty"];
  1962. [section_json setObject:modify_item forKey:[NSString stringWithFormat:@"item_%d",ic ]];
  1963. }
  1964. }
  1965. }
  1966. else
  1967. {
  1968. NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  1969. int section = [(NSString*)idarr[0] intValue];
  1970. int item=[(NSString*)idarr[1] intValue];
  1971. NSDictionary* jsonmap=[sub_action valueForKey:@"key_map"];
  1972. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  1973. NSMutableDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]] mutableCopy];
  1974. NSString* control_type = [olditem valueForKey:@"control"];
  1975. if([control_type isEqualToString:@"switch"])
  1976. olditem= [self fill_switch_subitem:olditem subid:nil source:value mapping:jsonmap ];
  1977. else if([control_type isEqualToString:@"enum"])
  1978. {
  1979. olditem= [self fill_enum_subitem:olditem subid:nil source:value mapping:jsonmap ];
  1980. }
  1981. else
  1982. {
  1983. [RAUtils message_alert:@"not impl" title:@"Sorry" controller:self];
  1984. // [RAUtils alert_view:@"" title:@"not impl"];
  1985. }
  1986. [olditem setValue:@"true" forKey:@"dirty"];
  1987. [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",item ]];
  1988. }
  1989. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  1990. self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  1991. if(refresh==1)
  1992. {
  1993. // if(restore_json!=nil)
  1994. // {
  1995. // int rc=[[restore_json valueForKey:@"count"] intValue];
  1996. // for(int ir=0;ir<rc;ir++)
  1997. // {
  1998. // NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
  1999. //
  2000. //
  2001. // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  2002. // for(int i=0;i<section_count;i++)
  2003. // {
  2004. // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  2005. // // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  2006. // int item_count = [[sectionjson valueForKey:@"count"] intValue];
  2007. // for(int j=0;j<item_count;j++)
  2008. // {
  2009. // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  2010. // // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  2011. //
  2012. // if([[itemjson valueForKey:@"name"] isEqualToString:name])
  2013. // {
  2014. // [itemjson removeObjectForKey:@"dirty"];
  2015. // [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
  2016. // }
  2017. //
  2018. // }
  2019. // [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
  2020. // }
  2021. //
  2022. //
  2023. // }
  2024. //
  2025. // }
  2026. [self refresh:refresh_trigger discardDirty:discardDirty] ;
  2027. return ;
  2028. }
  2029. // DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  2030. [self.editorTable reloadData ];
  2031. }
  2032. else
  2033. {
  2034. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2035. NSDictionary * item_json = sub_action;
  2036. NSString* value = [item_json valueForKey:@"value"];
  2037. if([value isEqualToString:@"new_addr"])
  2038. {
  2039. AddressEditorViewController * addressVC = [[AddressEditorViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  2040. addressVC.url_type = URL_REMOTE;
  2041. addressVC.request_url=URL_ADDRESS_EDOTOR;
  2042. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  2043. // NSString * string = [checked componentsJoinedByString:@","];
  2044. // [params setValue:string forKey:@"cart2Checkbox"];
  2045. params[@"is_subaction"]=@"true";
  2046. params[@"subaction_tag"]= [NSString stringWithFormat:@"%ld",(long)sender.tag];
  2047. addressVC.params = params;
  2048. addressVC.delegate = self;
  2049. addressVC.from = indexPath;
  2050. // orderinfoVC.params = params;
  2051. [self.navigationController pushViewController:addressVC animated:true];
  2052. }else if([value isEqualToString:@"credit_card"])
  2053. {
  2054. CreditCardEditorViewController * cardVC = [[CreditCardEditorViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  2055. NSDictionary *data = [item_json objectForKey:@"data"];
  2056. if(data!=nil)
  2057. {
  2058. cardVC.content_data_download = [data mutableCopy];
  2059. cardVC.url_type = URL_NONE;
  2060. cardVC.request_url=nil;
  2061. }
  2062. else
  2063. {
  2064. cardVC.url_type = URL_REMOTE;
  2065. cardVC.request_url=URL_CREDITCARD_EDOTOR;
  2066. }
  2067. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  2068. params[@"orderCode"]=appDelegate.order_code;
  2069. params[@"is_subaction"]=@"true";
  2070. params[@"subaction_tag"]= [NSString stringWithFormat:@"%ld",(long)sender.tag];
  2071. cardVC.params = params;
  2072. cardVC.delegate = self;
  2073. cardVC.from = indexPath;
  2074. // orderinfoVC.params = params;
  2075. [self.navigationController pushViewController:cardVC animated:true];
  2076. }
  2077. else if([value isEqualToString:@"Sales_Order_Freight_Bill_To"])
  2078. {
  2079. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  2080. cvc.showNavibar = true;
  2081. cvc.contact_type = value;
  2082. cvc.is_subaction = @"true";
  2083. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  2084. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  2085. [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  2086. //
  2087. // if(self.returnValue)
  2088. // self.returnValue(value);
  2089. };
  2090. [self.navigationController pushViewController:cvc animated:true];
  2091. }
  2092. else if([value isEqualToString:@"Sales_Order_Ship_From"])
  2093. {
  2094. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  2095. cvc.showNavibar = true;
  2096. cvc.contact_type = value;
  2097. cvc.is_subaction = @"true";
  2098. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  2099. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  2100. [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  2101. //
  2102. // if(self.returnValue)
  2103. // self.returnValue(value);
  2104. };
  2105. [self.navigationController pushViewController:cvc animated:true];
  2106. }
  2107. else if([value isEqualToString:@"Sales_Order_Customer"])
  2108. {
  2109. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  2110. cvc.is_subaction = @"true";
  2111. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  2112. cvc.showNavibar = true;
  2113. cvc.contact_type = value;
  2114. __weak typeof(self) weakself = self;
  2115. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  2116. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  2117. //
  2118. // if(self.returnValue)
  2119. // self.returnValue(value);
  2120. };
  2121. [self.navigationController pushViewController:cvc animated:true];
  2122. }
  2123. else if([value isEqualToString:@"Sales_Order_Merchandise_Bill_To"])
  2124. {
  2125. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  2126. cvc.showNavibar = true;
  2127. cvc.contact_type = value;
  2128. cvc.is_subaction = @"true";
  2129. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  2130. __weak typeof(self) weakself = self;
  2131. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  2132. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  2133. //
  2134. // if(self.returnValue)
  2135. // self.returnValue(value);
  2136. };
  2137. [self.navigationController pushViewController:cvc animated:true];
  2138. }
  2139. else if([value isEqualToString:@"Contact_Return_To"])
  2140. {
  2141. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  2142. cvc.is_subaction = @"true";
  2143. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  2144. cvc.showNavibar = true;
  2145. cvc.contact_type = value;
  2146. __weak typeof(self) weakself = self;
  2147. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  2148. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  2149. //
  2150. // if(self.returnValue)
  2151. // self.returnValue(value);
  2152. };
  2153. [self.navigationController pushViewController:cvc animated:true];
  2154. }
  2155. else if([value isEqualToString:@"Sales_Order_Ship_To"])
  2156. {
  2157. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  2158. cvc.is_subaction = @"true";
  2159. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  2160. cvc.showNavibar = true;
  2161. cvc.contact_type = value;
  2162. __weak typeof(self) weakself = self;
  2163. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  2164. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  2165. //
  2166. // if(self.returnValue)
  2167. // self.returnValue(value);
  2168. };
  2169. [self.navigationController pushViewController:cvc animated:true];
  2170. }
  2171. }
  2172. }
  2173. #pragma mark - Urgency
  2174. -(void) viewWillDisappear:(BOOL)animated
  2175. {
  2176. [super viewWillDisappear:animated];
  2177. [self cancel_urgency_timer];
  2178. }
  2179. - (void)start_urgency_timer {
  2180. return;
  2181. if (!self.editable) {
  2182. return;
  2183. }
  2184. __weak typeof(self) weakSelf = self;
  2185. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  2186. [appDelegate.urgencyDic setValue:appDelegate.user forKey:@"user"];
  2187. #ifdef OFFLINE_MODE
  2188. [appDelegate.urgencyDic setValue:[NSNumber numberWithBool:appDelegate.offline_mode] forKey:@"offline_mode"];
  2189. #endif
  2190. MainViewController *mainVC = (MainViewController *)appDelegate.main_vc;
  2191. __block NSString *so = [mainVC.labelSo.text substringFromIndex:5];
  2192. [[JKTimerManager sharedTimerManager] scheduledDispatchTimerWithName:self.urgency_timer_name timeInterval:1 queue:nil repeats:YES action:^{
  2193. NSMutableDictionary *urgencyDic = [NSMutableDictionary dictionary];
  2194. // DebugLog(@"timer start....");
  2195. [urgencyDic setValue:weakSelf.content_data_download forKey:[NSString stringWithFormat:@"%@_restored_data",self.class_name]];
  2196. [urgencyDic setValue:weakSelf.class_name forKey:@"class_name"];
  2197. if ([weakSelf.class_name isEqualToString:@"CreateOrderViewController"]) {
  2198. // CreateOrderViewController
  2199. [urgencyDic setValue:appDelegate.order_code forKey:@"order_code"];
  2200. [urgencyDic setValue:so forKey:@"order_so"];
  2201. [urgencyDic setValue:[NSNumber numberWithInt:appDelegate.order_status ] forKey:@"order_status"];
  2202. [urgencyDic setValue:appDelegate.order_customer_id forKey:@"order_customer_id"];
  2203. }
  2204. dispatch_async(dispatch_get_main_queue(), ^{
  2205. [appDelegate.urgencyDic setValue:urgencyDic forKey:[NSString stringWithFormat:@"level_%d",weakSelf.level]];
  2206. [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:weakSelf.level + 1] forKey:@"count"];
  2207. });
  2208. }];
  2209. }
  2210. - (void)cancel_urgency_timer {
  2211. [[JKTimerManager sharedTimerManager] cancelTimerWithName:self.urgency_timer_name];
  2212. }
  2213. #pragma mark - Submit Order
  2214. - (void)customer_commit_order:(NSMutableDictionary *)upparams {
  2215. [upparams setValue:@"true" forKey:@"isHold"];
  2216. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Order Submission" completion:^{
  2217. [RANetwork request_commit_order:upparams completionHandler:^(NSMutableDictionary *result) {
  2218. NSDictionary* editor_json =result;
  2219. [waitalert dismissViewControllerAnimated:YES completion:^{
  2220. if([[editor_json valueForKey:@"result"] intValue]==2)
  2221. {
  2222. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2223. // appDelegate.customerInfo = customerInfo;
  2224. [appDelegate closeOrder];
  2225. #ifdef RA_NOTIFICATION
  2226. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2227. #else
  2228. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2229. #endif
  2230. NSString* title=nil;
  2231. NSString* msg=nil;
  2232. #ifdef OFFLINE_MODE
  2233. if(appDelegate.offline_mode)
  2234. {
  2235. title=TITLE_OFFLINE_SUBMIT;
  2236. msg=MSG_OFFLINE_SUBMIT;
  2237. }
  2238. else
  2239. #endif
  2240. {
  2241. title=@"Order submitted sucessfully";
  2242. msg=[NSString stringWithFormat:@"Confirmation#: %@",[editor_json valueForKey:@"so#"]];
  2243. }
  2244. [RAUtils message_alert:msg title:title controller:self];
  2245. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  2246. // [alert show];
  2247. [self prepareReturn:nil];
  2248. [self.navigationController popToRootViewControllerAnimated:true];
  2249. }
  2250. else
  2251. {
  2252. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
  2253. }
  2254. }];
  2255. }];
  2256. }];
  2257. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2258. //
  2259. // NSDictionary* editor_json = [RANetwork saveandcommit_Order:upparams];
  2260. //
  2261. // dispatch_async(dispatch_get_main_queue(), ^{
  2262. //
  2263. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  2264. //
  2265. // if([[editor_json valueForKey:@"result"] intValue]==2)
  2266. // {
  2267. //
  2268. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2269. // // appDelegate.customerInfo = customerInfo;
  2270. //
  2271. // [appDelegate closeOrder];
  2272. //
  2273. //
  2274. //#ifdef RA_NOTIFICATION
  2275. // [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2276. //#else
  2277. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2278. //#endif
  2279. //
  2280. // NSString* title=nil;
  2281. // NSString* msg=nil;
  2282. //#ifdef OFFLINE_MODE
  2283. // if(appDelegate.offline_mode)
  2284. // {
  2285. // title=TITLE_OFFLINE_SUBMIT;
  2286. // msg=MSG_OFFLINE_SUBMIT;
  2287. // }
  2288. // else
  2289. //#endif
  2290. // {
  2291. // title=@"Order submitted sucessfully";
  2292. // msg=[NSString stringWithFormat:@"Confirmation#: %@",[editor_json valueForKey:@"so#"]];
  2293. // }
  2294. //
  2295. // [RAUtils message_alert:msg title:title controller:self];
  2296. //// UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  2297. //
  2298. //// [alert show];
  2299. //
  2300. // [self prepareReturn:nil];
  2301. // [self.navigationController popToRootViewControllerAnimated:true];
  2302. //
  2303. //
  2304. // }
  2305. // else
  2306. // {
  2307. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
  2308. // }
  2309. // });
  2310. // });
  2311. }
  2312. -(void)addTasks: (NSString*)filename md5:(NSString*) md5
  2313. {
  2314. AppDelegate* Appdelegate=(AppDelegate*)[UIApplication sharedApplication].delegate;
  2315. // if (![self shouldUploadWithCurrentNerworkStatus]) {
  2316. // [self.view makeToast:@"Current network is not WiFi,you can upload it manually when wifi connected." duration:3.0 position:CSToastPositionCenter];
  2317. // }
  2318. //prepare upload
  2319. // NSMutableArray* tasks = [NSMutableArray new];
  2320. // for(NSMutableDictionary* photo in self.photos)
  2321. NSMutableDictionary* task=[[NSMutableDictionary alloc]init];
  2322. // task[@"path"]=path;
  2323. task[@"file"]=filename;
  2324. task[@"url"]=Appdelegate.uploadurl;
  2325. NSDictionary* params = @{
  2326. @"site_name":[RADataProvider getSiteName],
  2327. @"user":Appdelegate.user,
  2328. @"_method":@"uploadOfflineOrder",
  2329. @"password" : Appdelegate.password,
  2330. @"md5":md5
  2331. };
  2332. task[@"params"]=params;
  2333. // NSString *file = photo[@"file"];
  2334. // [self moveTmpImageToCache:file];
  2335. // [tasks addObject:task];
  2336. // Signature
  2337. // NSDictionary *signatureTask = [self prepareSignatureTask];
  2338. // // add upload tasks;
  2339. [Appdelegate.uploadManager addTask:task];
  2340. // [self clear];
  2341. }
  2342. #ifdef SCANNER_ORDER
  2343. -(NSMutableDictionary*) convertScanitem :(NSMutableDictionary*) itemjson
  2344. {
  2345. // NSMutableArray* fields=[[NSMutableArray alloc] init];
  2346. NSMutableDictionary* upparams=[[NSMutableDictionary alloc] init];
  2347. if([[itemjson valueForKey:@"control"] isEqualToString:@"enum"])
  2348. {
  2349. NSString* single_select = [itemjson valueForKey:@"single_select"];
  2350. if([single_select isEqualToString:@"true"])
  2351. {
  2352. NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
  2353. int count = [[cadejson valueForKey:@"count"] intValue];
  2354. upparams[[itemjson valueForKey:@"name"]]=@"";
  2355. for(int cc=0;cc<count;cc++)
  2356. {
  2357. NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
  2358. if([[valjson valueForKey:@"check"]intValue]==1)
  2359. {
  2360. // NSString* vid = [valjson valueForKey:@"value_id"] ;
  2361. // if(vid.length==0)
  2362. // vid=@"";
  2363. [upparams setValue:[valjson valueForKey:@"value_id"] forKey:[itemjson valueForKey:@"name"]];
  2364. NSMutableDictionary* subitem = valjson[@"sub_item"];
  2365. if(subitem!=nil)
  2366. {
  2367. int scount = [subitem[@"count"]intValue];
  2368. for(int si=0;si<scount;si++)
  2369. {
  2370. NSMutableDictionary* sitem = subitem[[NSString stringWithFormat:@"item_%d",si]];
  2371. NSMutableDictionary* convertitem = [self convertScanitem:sitem];
  2372. [upparams addEntriesFromDictionary:convertitem];
  2373. }
  2374. }
  2375. break;
  2376. }
  2377. }
  2378. return upparams;
  2379. }
  2380. else //multiple select
  2381. {
  2382. NSMutableArray* checked = [[NSMutableArray alloc] init];
  2383. NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
  2384. int count = [[cadejson valueForKey:@"count"] intValue];
  2385. upparams[[itemjson valueForKey:@"name"]]=@"";
  2386. for(int cc=0;cc<count;cc++)
  2387. {
  2388. NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
  2389. if([[valjson valueForKey:@"check"]intValue]==1)
  2390. {
  2391. // NSString* vid = [valjson valueForKey:@"value_id"] ;
  2392. // if(vid.length==0)
  2393. // vid=@"";
  2394. // [checked addObject:[NSNumber numberWithInt:[[valjson valueForKey:@"value_id"] intValue]]];
  2395. [checked addObject:[NSString stringWithFormat:@"%@",[valjson valueForKey:@"value_id"]]];
  2396. }
  2397. }
  2398. {
  2399. NSString * string = [checked componentsJoinedByString:@","];
  2400. [upparams setValue:string forKey:[itemjson valueForKey:@"name"]];
  2401. }
  2402. return upparams;
  2403. }
  2404. /*
  2405. upparams setValue:itemjson forKey:<#(NSString *)#>
  2406. */
  2407. }
  2408. else
  2409. if([[itemjson valueForKey:@"control"] isEqualToString:@"action"])
  2410. {
  2411. return nil;
  2412. }
  2413. else if([[itemjson valueForKey:@"control"] isEqualToString:@"signature"])
  2414. {
  2415. NSString* valuestr = [itemjson valueForKey:@"value"];
  2416. if(valuestr.length==0)
  2417. valuestr=@"";
  2418. [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  2419. return upparams;
  2420. }
  2421. else if([[itemjson valueForKey:@"control"] isEqualToString:@"switch"])
  2422. {
  2423. NSString* valuestr = [itemjson valueForKey:@"value"];
  2424. [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  2425. NSString* value = [itemjson valueForKey:@"value"];
  2426. // NSMutableDictionary* boolitem=nil;
  2427. // NSMutableDictionary* subjson=nil;
  2428. if([value isEqualToString:@"true"])
  2429. {
  2430. // boolitem =[[itemjson objectForKey:@"true"] mutableCopy];
  2431. NSMutableDictionary* subitem = itemjson[@"sub_item"];
  2432. if(subitem!=nil)
  2433. {
  2434. int scount = [subitem[@"count"]intValue];
  2435. for(int si=0;si<scount;si++)
  2436. {
  2437. NSMutableDictionary* sitem = subitem[[NSString stringWithFormat:@"item_%d",si]];
  2438. NSMutableDictionary* convertitem = [self convertScanitem:sitem];
  2439. [upparams addEntriesFromDictionary:convertitem];
  2440. }
  2441. }
  2442. }
  2443. else
  2444. {
  2445. // boolitem =[[itemjson objectForKey:@"false"] mutableCopy];
  2446. }
  2447. // subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy];
  2448. // if( subjson!=nil /*&& !active*/)
  2449. // {
  2450. // int sub_count = [[subjson valueForKey:@"count"] intValue];
  2451. // for(int l=0;l<sub_count;l++)
  2452. // {
  2453. //// NSMutableDictionary * modify_item=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
  2454. //// if([modify_item valueForKey:@"value"]!=nil && ![[modify_item valueForKey:@"value"]isEqualToString:@""])
  2455. //// [upparams setValue:[modify_item valueForKey:@"value"] forKey:[modify_item valueForKey:@"name"]];
  2456. //
  2457. // }
  2458. // }
  2459. return upparams;
  2460. }
  2461. else if([[itemjson valueForKey:@"control"] isEqualToString:@"img"])
  2462. {
  2463. NSString* avalue = [itemjson valueForKey:@"avalue"];
  2464. if(avalue.length==0)
  2465. avalue=@"";
  2466. [upparams setValue:avalue forKey:[itemjson valueForKey:@"name"]];
  2467. return upparams;
  2468. }
  2469. else if([[itemjson valueForKey:@"control"] isEqualToString:@"edit"])
  2470. {
  2471. // int min_length = [[itemjson valueForKey:@"min_length"] intValue];
  2472. // NSString* check_len_val =itemjson[@"value"];
  2473. NSString* valuestr= [itemjson valueForKey:@"value"];
  2474. if(valuestr.length==0)
  2475. valuestr=@"";
  2476. [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  2477. // {
  2478. // NSString *keyboard_type = [itemjson objectForKey:@"keyboard"];
  2479. // BOOL check_max = [itemjson objectForKey:@"max_type"] != nil ? YES : NO;
  2480. // BOOL check_min = [itemjson objectForKey:@"min_type"] != nil ? YES : NO;
  2481. // if ([keyboard_type isEqualToString:@"number"] && (check_max || check_min)) {
  2482. // // 检查最大值最小值
  2483. // int max_type = [[itemjson objectForKey:@"max_type"] intValue];
  2484. // int min_type = [[itemjson objectForKey:@"min_type"] intValue];
  2485. //
  2486. // float max_value = MAXFLOAT;
  2487. // float min_value = 0;
  2488. //
  2489. // NSString *mfield = nil;
  2490. // float f_value = [check_len_val floatValue];
  2491. //
  2492. // if (check_max) {
  2493. //
  2494. // if (max_type > 0) {
  2495. // // key
  2496. // NSString *max_key = [itemjson objectForKey:@"max"];
  2497. // id max_obj = [self downloadValueForKey:max_key];
  2498. // if (max_obj) {
  2499. // max_value = [max_obj floatValue];
  2500. // }
  2501. //
  2502. // } else {
  2503. // // value
  2504. // id max_obj = [itemjson objectForKey:@"max"];
  2505. // if (max_obj != nil) {
  2506. // max_value = [max_obj floatValue];
  2507. // }
  2508. //
  2509. // }
  2510. //
  2511. // if (max_value < f_value) {
  2512. // mfield =[NSString stringWithFormat:@"%ld. the value of %@ must be not larger than %.2f",fields.count+1,itemjson[@"aname"],max_value];
  2513. // }
  2514. // }
  2515. //
  2516. // if (check_min) {
  2517. //
  2518. // if (min_type > 0) {
  2519. // // key
  2520. // NSString *min_key = [itemjson objectForKey:@"min"];
  2521. // id min_obj = [self downloadValueForKey:min_key];
  2522. // if (min_obj) {
  2523. // min_value = [min_obj floatValue];
  2524. // }
  2525. // } else {
  2526. // // value
  2527. // id min_obj = [itemjson objectForKey:@"min"];
  2528. // if (min_obj != nil) {
  2529. // min_value = [min_obj floatValue];
  2530. // }
  2531. // }
  2532. //
  2533. // if (min_value > f_value) {
  2534. // mfield =[NSString stringWithFormat:@"%ld. the value of %@ must be not smaller than %.2f",fields.count+1,itemjson[@"aname"],min_value];
  2535. // }
  2536. // }
  2537. //
  2538. //
  2539. // if (check_min && check_max) {
  2540. // if (f_value < min_value || f_value > max_value) {
  2541. // mfield =[NSString stringWithFormat:@"%ld. the value of %@ must between %.2f and %.2f",fields.count+1,itemjson[@"aname"],min_value,max_value];
  2542. // }
  2543. // }
  2544. //
  2545. //
  2546. // [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  2547. //
  2548. //
  2549. // } else {
  2550. // [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  2551. // }
  2552. //
  2553. // }
  2554. return upparams;
  2555. }
  2556. else
  2557. {
  2558. NSString* value = [itemjson valueForKey:@"value"];
  2559. if(value.length==0)
  2560. value=@"";
  2561. [upparams setValue:value forKey:[itemjson valueForKey:@"name"]];
  2562. return upparams;
  2563. }
  2564. return upparams;
  2565. }
  2566. -(NSMutableDictionary*) convertScanOrder :(NSMutableDictionary*) dict
  2567. {
  2568. [[[UIApplication sharedApplication] keyWindow] endEditing:YES];
  2569. // [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder)];
  2570. [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];
  2571. // self.first_miss_pos = nil;
  2572. NSMutableDictionary* upparams=[[NSMutableDictionary alloc] init];
  2573. // [upparams setValue:[self.params valueForKey:@"cart2Checkbox"] forKey:@"cart2Checkbox"];
  2574. int section_count=(int)self.content_data_control.count;//[[self.content_data_download valueForKey:@"section_count"] intValue];
  2575. // NSString* aaa = [RAUtils dict2string:self.content_data_control];
  2576. for(int i=0;i<section_count;i++)
  2577. {
  2578. DebugLog(@"debug...section:%d",i);
  2579. NSDictionary * sectionjson = [self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] ;
  2580. int item_count = [sectionjson[@"count"] intValue];
  2581. for(int j=0;j<item_count;j++)
  2582. {
  2583. NSMutableDictionary * itemjson=[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]];
  2584. NSString* key = [itemjson valueForKey:@"name"];
  2585. if(key==nil || key.length==0)
  2586. continue;
  2587. NSMutableDictionary* convertitem=[self convertScanitem:itemjson];
  2588. [upparams addEntriesFromDictionary:convertitem];
  2589. // subitem_data * data=[self subitem_param:itemjson addto:upparams alert:alert];
  2590. // upparams= data.params;
  2591. // fields=[[fields arrayByAddingObjectsFromArray:data.missingfields] mutableCopy];
  2592. }
  2593. }
  2594. upparams[@"price_type"] = @(RASingleton.sharedInstance.price_type);
  2595. return upparams;
  2596. }
  2597. -(NSString*) scan_stock
  2598. {
  2599. NSMutableArray* ret=[NSMutableArray new];
  2600. NSDictionary* section=self.content_data_download[@"section_0"];
  2601. int count = [section[@"count"] intValue];
  2602. for(int i=0;i<count;i++)
  2603. {
  2604. NSDictionary* item = section[[NSString stringWithFormat:@"item_%d",i]];
  2605. NSDictionary* newitem =@{@"count":item[@"count"],@"model":item[@"model"]}; //@"product_id":item[@"product_id"],
  2606. [ret addObject:newitem];
  2607. }
  2608. return [RAConvertor dict2string:ret];
  2609. }
  2610. -(NSMutableArray*) scan_split_models:(NSMutableArray*) smodels
  2611. {
  2612. NSMutableDictionary* cart_section = RASingleton.sharedInstance.scan_cart[@"section_0"];
  2613. int cart_count = [cart_section[@"count"] intValue];
  2614. for(int i=0;i<smodels.count;i++)
  2615. {
  2616. for(int j=0;j<cart_count;j++)
  2617. {
  2618. NSMutableDictionary* cart_item = [cart_section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  2619. if([cart_item[@"model"] isEqualToString:smodels[i][@"model"] ])
  2620. {
  2621. NSMutableDictionary* newitem = [[NSMutableDictionary dictionaryWithDictionary:cart_item] mutableCopy];
  2622. [newitem addEntriesFromDictionary:smodels[i]];
  2623. newitem[@"cuft"]=@([newitem[@"count"] intValue] * [newitem[@"unit_cuft"] doubleValue]);
  2624. // NSString * mpack=newitem[@"stockUom"];
  2625. newitem[@"control"]=@"model";
  2626. newitem[@"description"]= [NSString stringWithFormat:@"%@\n%@\n%@",cart_item[@"model"],cart_item[@"description"],cart_item[@"dimension"] ];
  2627. newitem[@"subtotal_price"] = @([newitem[@"count"] intValue]* [newitem[@"unit_price"] doubleValue]*(1-[newitem[@"discount"] doubleValue]/100.0));
  2628. smodels[i]=newitem;
  2629. break;
  2630. }
  2631. }
  2632. }
  2633. return smodels;
  2634. // for(int j=0;j<cart_count;j++)
  2635. // {
  2636. // NSMutableDictionary* cart_item = [cart_section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  2637. // cart_item[@"description"]= [NSString stringWithFormat:@"%@\n%@\n%@",cart_item[@"model"],cart_item[@"description"],cart_item[@"dimension"] ];
  2638. // cart_item[@"control"]=@"model";
  2639. // section[[NSString stringWithFormat:@"item_%d",j]] = cart_item;
  2640. //
  2641. // }
  2642. // section[@"count"] = @(cart_count);
  2643. // dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  2644. }
  2645. -(void) scan_commit:(NSMutableDictionary *)upparams newmodel:(NSMutableDictionary *)newmodel{
  2646. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2647. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  2648. NSString *documents = [paths objectAtIndex:0];
  2649. NSString *orderdir = [OLDataProvider getScanPath];
  2650. // NSString *ordercontrol = [orderdir stringByAppendingPathComponent:@"order_control.json"];
  2651. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  2652. NSMutableDictionary* saveorder = [[NSMutableDictionary dictionaryWithDictionary:self.content_data_download] mutableCopy];
  2653. if(newmodel)
  2654. saveorder[@"section_0"]=newmodel;
  2655. // [RAUtils dicttofile:ordercontrol dict:self.content_data_control];
  2656. [RAUtils dicttofile:orderPath dict:saveorder];
  2657. for(int os=0;os<[self.content_data_download[@"section_count"] intValue];os++)
  2658. {
  2659. NSDictionary* section = self.content_data_download[[NSString stringWithFormat:@"section_%d",os]];
  2660. for(int oi=0;oi<[section[@"count"] intValue];oi++)
  2661. {
  2662. NSDictionary* item = section [[NSString stringWithFormat:@"item_%d",oi]];
  2663. if([item[@"control"] isEqualToString:@"img"])
  2664. {
  2665. // 复制图片到打包目录
  2666. NSString* img_url_0=item[@"img_url_0"];
  2667. NSString* img_url_1=item[@"img_url_1"];
  2668. NSString* img_url_2=item[@"img_url_2"];
  2669. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
  2670. NSString *cachefolder = [paths objectAtIndex:0];
  2671. // NSString *offline_createimg = [cachefolder stringByAppendingPathComponent:@"offline_createimg"];
  2672. NSString *img_cache = [cachefolder stringByAppendingPathComponent:@"img_cache"];
  2673. NSFileManager* fileManager=[NSFileManager defaultManager];
  2674. if(img_url_0.length>0&&[fileManager fileExistsAtPath:[img_cache stringByAppendingPathComponent:img_url_0]])
  2675. {
  2676. NSError* err;
  2677. [fileManager copyItemAtURL:[NSURL fileURLWithPath:[img_cache stringByAppendingPathComponent:img_url_0]] toURL:[NSURL fileURLWithPath:[orderdir stringByAppendingPathComponent:img_url_0]] error:&err];
  2678. int i=0;
  2679. }
  2680. if(img_url_1.length>0&&[fileManager fileExistsAtPath:[img_cache stringByAppendingPathComponent:img_url_1]])
  2681. {
  2682. NSError* err;
  2683. [fileManager copyItemAtURL:[NSURL fileURLWithPath:[img_cache stringByAppendingPathComponent:img_url_1]] toURL:[NSURL fileURLWithPath:[orderdir stringByAppendingPathComponent:img_url_1]] error:&err];
  2684. }
  2685. if(img_url_2.length>0&&[fileManager fileExistsAtPath:[img_cache stringByAppendingPathComponent:img_url_2]])
  2686. {
  2687. NSError* err;
  2688. [fileManager copyItemAtURL:[NSURL fileURLWithPath:[img_cache stringByAppendingPathComponent:img_url_2]] toURL:[NSURL fileURLWithPath:[orderdir stringByAppendingPathComponent:img_url_2]] error:&err];
  2689. }
  2690. }
  2691. else if([item[@"control"] isEqualToString:@"signature"])
  2692. {
  2693. // 复制图片到打包目录
  2694. NSString* img_url_0=item[@"value"];
  2695. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
  2696. NSString *cachefolder = [paths objectAtIndex:0];
  2697. // NSString *offline_createimg = [cachefolder stringByAppendingPathComponent:@"offline_createimg"];
  2698. NSString *img_cache = [cachefolder stringByAppendingPathComponent:@"img_cache"];
  2699. NSFileManager* fileManager=[NSFileManager defaultManager];
  2700. if(img_url_0.length>0&&[fileManager fileExistsAtPath:[img_cache stringByAppendingPathComponent:img_url_0]])
  2701. {
  2702. NSError* err;
  2703. [fileManager copyItemAtURL:[NSURL fileURLWithPath:[img_cache stringByAppendingPathComponent:img_url_0]] toURL:[NSURL fileURLWithPath:[orderdir stringByAppendingPathComponent:img_url_0]] error:&err];
  2704. }
  2705. }
  2706. }
  2707. }
  2708. NSString * parampath= [orderdir stringByAppendingPathComponent:@"param.json"];
  2709. NSDictionary* param=[self convertScanOrder:self.content_data_download];
  2710. [RAUtils dicttofile:parampath dict:param];
  2711. NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  2712. if(appDelegate.customerInfo==nil)
  2713. appDelegate.customerInfo = [NSMutableDictionary new];
  2714. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  2715. NSString *cartpath = [orderdir stringByAppendingPathComponent:@"cart.json"];
  2716. RASingleton.sharedInstance.scan_cart[@"price_type"] = @(RASingleton.sharedInstance.price_type);
  2717. NSMutableDictionary* savecart = [[NSMutableDictionary dictionaryWithDictionary:RASingleton.sharedInstance.scan_cart] mutableCopy];
  2718. if(newmodel)
  2719. savecart[@"section_0"]=newmodel;
  2720. [RAUtils dicttofile:cartpath dict:savecart];
  2721. NSString * zippath= [orderdir stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.zip",appDelegate.order_code]];
  2722. // NSError *error=nil;
  2723. //
  2724. // [str writeToFile:jsonpath atomically:true encoding:NSUTF8StringEncoding error:&error];
  2725. NSArray* arr_files=[RAUtils allFilesAtPath:orderdir];
  2726. ZipArchive* zip = [[ZipArchive alloc] init];
  2727. // if ([[NSFileManager defaultManager] fileExistsAtPath:zippath]) {
  2728. //
  2729. //
  2730. // [[NSFileManager defaultManager] removeItemAtPath:zippath error:nil];
  2731. //
  2732. //
  2733. // }
  2734. BOOL r = [zip CreateZipFile2:zippath Password:@"usai2010"];
  2735. for(int i=0;i<arr_files.count;i++)
  2736. {
  2737. NSString* file=arr_files[i];
  2738. r = [zip addFileToZip:file newname:[file lastPathComponent]];
  2739. }
  2740. NSString * filepath=[[RADataProvider getSiteName] stringByAppendingPathComponent:appDelegate.user];
  2741. filepath=[filepath stringByAppendingPathComponent:appDelegate.order_code];
  2742. filepath=[filepath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.zip",appDelegate.order_code]];
  2743. if( ![zip CloseZipFile2] )
  2744. {
  2745. zippath = @"";
  2746. filepath =@"";
  2747. }
  2748. NSString *md5 = [RAUtils md5WithFile:zippath];
  2749. {
  2750. //括号内为单个文件上传
  2751. NSString *fileName = [zippath lastPathComponent];
  2752. NSData * file_data= [NSData dataWithContentsOfFile:zippath];
  2753. NSString* realuser;
  2754. NSString* realpassword;
  2755. if(self.realuser.length>0)
  2756. {
  2757. realuser = self.realuser;
  2758. realpassword = self.realpassword;
  2759. }
  2760. else
  2761. {
  2762. realuser = appDelegate.user;
  2763. realpassword = appDelegate.password;
  2764. }
  2765. NSDictionary* params = @{
  2766. // @"site_name":[RADataProvider getSiteName],
  2767. @"user":realuser,
  2768. @"_method":@"uploadOfflineOrder",
  2769. @"password" : realpassword,
  2770. @"md5":md5
  2771. };
  2772. [RANetwork request_fastupload:[params mutableCopy] filename:fileName data:file_data url:appDelegate.uploadurl completionHandler:^(NSMutableDictionary *result) {
  2773. int iresult = [result[@"result"] intValue];
  2774. if(iresult == RESULT_TRUE)
  2775. {
  2776. NSString* soid = result[@"so_id"];
  2777. if(soid.length==0)
  2778. soid=@"N/A";
  2779. // upparams[@"soid"]=soid;
  2780. // NSMutableDictionary* saveorder = [[NSMutableDictionary dictionaryWithDictionary:self.content_data_download] mutableCopy];
  2781. if(newmodel)
  2782. { self.content_data_download[@"section_0"]=newmodel;
  2783. self.content_data_download[@"readonly"]=@1;
  2784. }
  2785. [self scanSave:upparams];
  2786. NSString* company = upparams[@"customer_cid"];
  2787. if(company.length==0)
  2788. company = upparams[@"customer_name"];
  2789. [OLDataProvider save2submitScanOrder:soid company:company];
  2790. [appDelegate closeOrder];
  2791. RASingleton.sharedInstance.scan_cart = nil;
  2792. #ifdef RA_NOTIFICATION
  2793. [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2794. #else
  2795. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  2796. [main_vc reloadCart:true immediately:false];
  2797. #endif
  2798. //
  2799. [self prepareReturn:nil];
  2800. [self.navigationController popViewControllerAnimated:true];
  2801. [((MainViewController*)appDelegate.main_vc) switchToOrder];
  2802. // NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
  2803. // ret[@"result"]=@2;
  2804. // ret[@"file"]=zippath;
  2805. // result(ret);
  2806. return;
  2807. }
  2808. else if(iresult==1)
  2809. {
  2810. self.fail_submit = true;
  2811. self.realuser = nil;
  2812. self.realpassword = nil;
  2813. [RAUtils message_alert:@"Can not submit the order, wrong password" title:@"Submit Order" controller:self];
  2814. if ([[NSFileManager defaultManager] fileExistsAtPath:zippath]) {
  2815. [[NSFileManager defaultManager] removeItemAtPath:zippath error:nil];
  2816. // [orderlist addObject:appDelegate.order_code];
  2817. // [RAUtils dicttofile:orderlistPath dict:orderlist];
  2818. }
  2819. }
  2820. else if([result[@"result"] intValue]==-4||[result[@"result"] intValue]==-3)
  2821. {
  2822. self.fail_submit = true;
  2823. self.realuser = nil;
  2824. self.realpassword = nil;
  2825. [RAUtils message_alert:@"Order submission failed. Please check your internet and try later." title:@"Submit Order" controller:self];
  2826. // if ([[NSFileManager defaultManager] fileExistsAtPath:zippath]) {
  2827. //
  2828. //
  2829. // [[NSFileManager defaultManager] removeItemAtPath:zippath error:nil];
  2830. //
  2831. // // [orderlist addObject:appDelegate.order_code];
  2832. // // [RAUtils dicttofile:orderlistPath dict:orderlist];
  2833. //
  2834. // }
  2835. return;
  2836. }
  2837. else if(iresult==9)
  2838. {
  2839. self.fail_submit = true;
  2840. self.realuser = nil;
  2841. self.realpassword = nil;
  2842. [RAUtils message_alert:result[@"err_msg"] title:@"Submit Order" controller:self];
  2843. }
  2844. else
  2845. {
  2846. self.fail_submit = true;
  2847. self.realuser = nil;
  2848. self.realpassword = nil;
  2849. [RAUtils message_alert:@"Can not submit order, please contact administrator." title:@"Submit Order" controller:self];
  2850. }
  2851. }];
  2852. }
  2853. return;
  2854. }
  2855. #endif
  2856. - (void)empolyee_commit_order:(NSMutableDictionary *)upparams {
  2857. #ifdef SCANNER_ORDER
  2858. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2859. NSString* realuser;
  2860. NSString* realpassword;
  2861. if(self.realuser.length>0)
  2862. {
  2863. realuser = self.realuser;
  2864. realpassword = self.realpassword;
  2865. }
  2866. else
  2867. {
  2868. realuser = appDelegate.user;
  2869. realpassword = appDelegate.password;
  2870. }
  2871. if((appDelegate.user_type==USER_ROLE_CUSTOMER && [upparams[@"customer_cid"] stringValue].length>0) || [upparams[@"customer_cid"] stringValue].length>0 ||[appDelegate.user.uppercaseString isEqualToString:@"GUEST"])
  2872. {
  2873. NSMutableDictionary* param = [NSMutableDictionary new];
  2874. NSString* model = [self scan_stock];
  2875. param[@"models"]=model;
  2876. param[@"customer_cid"]=upparams[@"customer_cid"];
  2877. param[@"user"]=realuser;
  2878. param[@"password"]=realpassword;
  2879. [RADataProvider request_scan_stock:param completionHandler:^(NSMutableDictionary *result) {
  2880. if([result[@"result"] intValue]==2)
  2881. {
  2882. NSMutableArray* models = [result[@"models"] mutableCopy];
  2883. if(models.count==0)
  2884. {
  2885. //不可拆分,直接提交
  2886. [self scan_commit:upparams newmodel:nil];
  2887. }
  2888. else
  2889. {
  2890. StockViewController * vc =[[UIStoryboard storyboardWithName:@"SO" bundle:nil] instantiateViewControllerWithIdentifier:@"StockViewController"];
  2891. //
  2892. // NSMutableArray* testmodels =[[RAConvertor string2dict:@"[{\"model\":\"1420-1*\",\"count\":1,\"is_back_order\":true,\"etd\":\"2022-06-23\"},{\"model\":\"1420-1*\",\"count\":1,\"is_back_order\":false,\"etd\":\"2022-06-23\"}]"] mutableCopy];
  2893. NSMutableArray* testmodels =[[RAConvertor string2dict:@"[{\"model\":\"1420-1*\",\"count\":1,\"is_back_order\":false,\"etd\":\"2022-06-23\"}]"] mutableCopy];
  2894. // models = testmodels;
  2895. models = [self scan_split_models:models];
  2896. vc.data =models;
  2897. vc.returnValue = ^(NSMutableDictionary * _Nonnull models) {
  2898. // model
  2899. // int i=0;
  2900. // RASingleton.sharedInstance.scan_cart[@"section_0"]=models;
  2901. // self.content_data_download[@"section_0"]=models;
  2902. [self scan_commit:upparams newmodel:models];
  2903. return;
  2904. };
  2905. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  2906. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  2907. // navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  2908. [self presentViewController:navi animated:YES completion:^{
  2909. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  2910. DebugLog(@"EditModelPriceViewController present.........");
  2911. // self.btop = false;
  2912. // <#code#>
  2913. }];
  2914. }
  2915. }
  2916. else if([result[@"result"] intValue]==1)
  2917. {
  2918. self.fail_submit = true;
  2919. self.realuser = nil;
  2920. self.realpassword = nil;
  2921. [RAUtils message_alert:@"Can not submit the order, wrong password" title:@"Submit Order" controller:self];
  2922. // if ([[NSFileManager defaultManager] fileExistsAtPath:zippath]) {
  2923. //
  2924. //
  2925. // [[NSFileManager defaultManager] removeItemAtPath:zippath error:nil];
  2926. //
  2927. // // [orderlist addObject:appDelegate.order_code];
  2928. // // [RAUtils dicttofile:orderlistPath dict:orderlist];
  2929. //
  2930. // }
  2931. return;
  2932. }
  2933. else if([result[@"result"] intValue]==-4||[result[@"result"] intValue]==-3)
  2934. {
  2935. self.fail_submit = true;
  2936. self.realuser = nil;
  2937. self.realpassword = nil;
  2938. [RAUtils message_alert:@"Order submission failed. Please check your internet and try later." title:@"Submit Order" controller:self];
  2939. // if ([[NSFileManager defaultManager] fileExistsAtPath:zippath]) {
  2940. //
  2941. //
  2942. // [[NSFileManager defaultManager] removeItemAtPath:zippath error:nil];
  2943. //
  2944. // // [orderlist addObject:appDelegate.order_code];
  2945. // // [RAUtils dicttofile:orderlistPath dict:orderlist];
  2946. //
  2947. // }
  2948. return;
  2949. }
  2950. else
  2951. {
  2952. self.fail_submit = true;
  2953. self.realuser = nil;
  2954. self.realpassword = nil;
  2955. [RAUtils message_alert:@"Can not submit order, please contact administrator." title:@"Submit Order" controller:self];
  2956. }
  2957. }];
  2958. }
  2959. else
  2960. {
  2961. //无contact 直接提交
  2962. [self scan_commit:upparams newmodel:nil];
  2963. // [RANetwork request_fastupload:[params mutableCopy] filename:fileName data:file_data url:appDelegate.uploadurl completionHandler:^(NSMutableDictionary *result) {
  2964. // int iresult = [result[@"result"] intValue];
  2965. // if(iresult == RESULT_TRUE)
  2966. // {
  2967. // NSString* soid = result[@"so_id"];
  2968. // if(soid.length==0)
  2969. // soid=@"N/A";
  2970. //// upparams[@"soid"]=soid;
  2971. // [self scanSave:upparams];
  2972. // NSString* company = upparams[@"customer_name"];
  2973. // [OLDataProvider save2submitScanOrder:soid company:company];
  2974. // [appDelegate closeOrder];
  2975. // RASingleton.sharedInstance.scan_cart = nil;
  2976. //
  2977. // #ifdef RA_NOTIFICATION
  2978. // [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2979. // #else
  2980. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  2981. // [main_vc reloadCart:true immediately:false];
  2982. // #endif
  2983. //
  2984. // //
  2985. //
  2986. //
  2987. // [self prepareReturn:nil];
  2988. //
  2989. //
  2990. //
  2991. // [self.navigationController popViewControllerAnimated:true];
  2992. // [((MainViewController*)appDelegate.main_vc) switchToOrder];
  2993. // // NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
  2994. // // ret[@"result"]=@2;
  2995. // // ret[@"file"]=zippath;
  2996. // // result(ret);
  2997. // return;
  2998. // }
  2999. // else if(iresult==1)
  3000. // {
  3001. // self.fail_submit = true;
  3002. // self.realuser = nil;
  3003. // self.realpassword = nil;
  3004. // [RAUtils message_alert:@"Can not submit the order, wrong password" title:@"Submit Order" controller:self];
  3005. // if ([[NSFileManager defaultManager] fileExistsAtPath:zippath]) {
  3006. //
  3007. //
  3008. // [[NSFileManager defaultManager] removeItemAtPath:zippath error:nil];
  3009. //
  3010. // // [orderlist addObject:appDelegate.order_code];
  3011. // // [RAUtils dicttofile:orderlistPath dict:orderlist];
  3012. //
  3013. // }
  3014. //
  3015. //
  3016. // }
  3017. // else
  3018. // {
  3019. // self.fail_submit = true;
  3020. // [RAUtils message_alert:@"Can not submit the order, please check your network" title:@"Submit Order" controller:self];
  3021. //
  3022. // if ([[NSFileManager defaultManager] fileExistsAtPath:zippath]) {
  3023. //
  3024. //
  3025. // [[NSFileManager defaultManager] removeItemAtPath:zippath error:nil];
  3026. //
  3027. // // [orderlist addObject:appDelegate.order_code];
  3028. // // [RAUtils dicttofile:orderlistPath dict:orderlist];
  3029. //
  3030. // }
  3031. //
  3032. // }
  3033. // }];
  3034. }
  3035. return;
  3036. #endif
  3037. [upparams setValue:@"false" forKey:@"isHold"];
  3038. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Order Submission" completion:^{
  3039. [RANetwork request_commit_order:upparams completionHandler:^(NSMutableDictionary *result) {
  3040. NSDictionary* editor_json = result;
  3041. [waitalert dismissViewControllerAnimated:YES completion:^{
  3042. if([[editor_json valueForKey:@"result"] intValue]==2)
  3043. {
  3044. // debug aaa
  3045. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3046. NSString* company= appDelegate.customerInfo[@"customer_name"];
  3047. NSString* send_to =appDelegate.customerInfo[@"customer_email"];
  3048. [appDelegate closeOrder];
  3049. #ifdef RA_NOTIFICATION
  3050. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  3051. #else
  3052. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  3053. #endif
  3054. __block NSString* title=nil;
  3055. __block NSString* msg=nil;
  3056. #ifdef OFFLINE_MODE
  3057. if(appDelegate.offline_mode)
  3058. {
  3059. title=TITLE_OFFLINE_SUBMIT;
  3060. msg=MSG_OFFLINE_SUBMIT;
  3061. }
  3062. else
  3063. #endif
  3064. {
  3065. title=@"Order submitted sucessfully";
  3066. msg=[NSString stringWithFormat:@"Confirmation#: %@",[editor_json valueForKey:@"so#"]];
  3067. }
  3068. NSString* pdf_url = [editor_json valueForKey:@"pdf_url"];
  3069. NSString* email_content =[editor_json valueForKey:@"email_content"];
  3070. NSString* soid=[editor_json valueForKey:@"so#"];
  3071. NSMutableDictionary *value = [NSMutableDictionary dictionary];
  3072. if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  3073. {
  3074. //bbb
  3075. [((MainViewController*)appDelegate.main_vc) Loginout:false];
  3076. value[@"commitorder_logout"]=@"true";
  3077. }
  3078. [self prepareReturn:value];
  3079. __block UIViewController* message_parent = self.navigationController.topViewController;
  3080. [self.navigationController popToRootViewControllerAnimated:true];
  3081. if(pdf_url.length>0)
  3082. {
  3083. // [message_alert dismissViewControllerAnimated:YES completion:^{
  3084. // [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  3085. // [self.navigationController popToRootViewControllerAnimated:true];
  3086. [appDelegate printPdf:pdf_url company:company send_to:send_to soid:soid content:email_content];
  3087. // [appDelegate printPdf:pdf_url];
  3088. // }];
  3089. }
  3090. else
  3091. dispatch_async(dispatch_get_main_queue(), ^{
  3092. // UIAlertController* message_alert=
  3093. [RAUtils message_alert:msg title:title controller:message_parent];
  3094. });
  3095. // __block UIAlertController* message_alert=[RAUtils message_alert:msg title:title controller:self.parentViewController action_handler:^(UIAlertAction * _Nonnull action) {
  3096. //
  3097. //
  3098. //
  3099. //
  3100. //// [self.navigationController popToRootViewControllerAnimated:true];
  3101. //
  3102. //
  3103. // } completion:^{
  3104. //
  3105. // }];
  3106. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  3107. //
  3108. // [alert show];
  3109. //
  3110. }
  3111. else
  3112. {
  3113. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
  3114. }
  3115. }];
  3116. }];
  3117. }];
  3118. }
  3119. @end