CreateOrderViewController.m 164 KB

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