CreateOrderViewController.m 136 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497
  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_box:nil message:msg completion:nil] ;
  299. }
  300. } else {
  301. [RAUtils message_box:nil message:msg completion:nil] ;
  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_box:@"Warring" message:@"User can't be empty." completion:nil];
  562. return;
  563. }
  564. if(password.text.length<=0)
  565. {
  566. [RAUtils message_box:@"Warring" message:@"Password can't be empty." completion:nil];
  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_box:@"Message" message:@"Save Successfully" completion:^{
  769. [self.navigationController popViewControllerAnimated:true];
  770. }];
  771. return;
  772. }
  773. }];
  774. UIAlertAction *action_1 = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  775. [self.navigationController popViewControllerAnimated:true];
  776. }];
  777. UIAlertAction *action_3 = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  778. }];
  779. [alertController addAction:action_0];
  780. [alertController addAction:action_1];
  781. [alertController addAction:action_3];
  782. [self presentViewController:alertController animated:YES completion:nil];
  783. }
  784. return;
  785. #endif
  786. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  787. if (self.resumeOrder) {
  788. [appDelegate.main_vc.navigationController popViewControllerAnimated:YES];
  789. return;
  790. }
  791. //
  792. // NSRange range = [tempStr rangeOfString:@")\">"];//判断字符串是否包含
  793. //
  794. // //if (range.location ==NSNotFound)//不包含
  795. // if (range.length >0)//包含
  796. // {
  797. //
  798. //
  799. //
  800. // }
  801. // else//不包含
  802. // {
  803. //
  804. // }
  805. // UIAlertView * alert = nil;
  806. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Close" message:@"Choose your action" preferredStyle:UIAlertControllerStyleAlert];
  807. UIAlertAction *action_0 = [UIAlertAction actionWithTitle:@"Switch to cart" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  808. [((MainViewController*)appDelegate.main_vc) switchToCart];
  809. [self.navigationController popViewControllerAnimated:true];
  810. }];
  811. UIAlertAction *action_1 = [UIAlertAction actionWithTitle:@"Switch to order history" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  812. [self.navigationController popViewControllerAnimated:false];
  813. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  814. [((MainViewController*)appDelegate.main_vc) switchToOrder];
  815. }];
  816. NSString * a2Title=nil;
  817. if(appDelegate.order_status==0)
  818. a2Title=@"Close and cancel order";
  819. else
  820. a2Title=@"Close and release order";
  821. UIAlertAction *action_2 = [UIAlertAction actionWithTitle:a2Title style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  822. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  823. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Release Order" completion:^{
  824. PopWaitAlert* pop = [RAUtils waiting_pop:@"Release Order" completion:nil];
  825. #ifdef SCANNER_ORDER
  826. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  827. {
  828. [pop hide];
  829. // [waitalert dismissViewControllerAnimated:YES completion:^{
  830. [OLDataProvider deleteScanOrder:appDelegate.order_code];
  831. [appDelegate closeOrder];
  832. //
  833. [self prepareReturn:nil];
  834. [self.navigationController popViewControllerAnimated:true];
  835. [((MainViewController*)appDelegate.main_vc) switchToOrder];
  836. // }];
  837. return;
  838. }
  839. #endif
  840. [RANetwork request_release_order:appDelegate.order_code withScreen:nil completionHandler:^(NSMutableDictionary *result) {
  841. NSDictionary* order_json = result;
  842. // [waitalert dismissViewControllerAnimated:YES completion:^{
  843. [pop hide];
  844. if([[order_json valueForKey:@"result"] intValue]==2)
  845. {
  846. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  847. // appDelegate.order_code = nil;
  848. [appDelegate closeOrder];
  849. #ifdef RA_NOTIFICATION
  850. [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  851. #else
  852. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  853. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  854. #endif
  855. [((MainViewController*)appDelegate.main_vc) switchToHome];
  856. if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  857. {
  858. [((MainViewController*)appDelegate.main_vc) Loginout:false];
  859. }
  860. [self prepareReturn:nil];
  861. [self.navigationController popViewControllerAnimated:true];
  862. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  863. // ;
  864. // }];
  865. }
  866. else
  867. {
  868. [RAUtils message_box:@"Open Order" message:[order_json valueForKey:@"err_msg"] completion:nil] ;
  869. }
  870. // }];
  871. }];
  872. // }];
  873. }];
  874. UIAlertAction *action_3 = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  875. }];
  876. [alertController addAction:action_0];
  877. [alertController addAction:action_1];
  878. [alertController addAction:action_2];
  879. [alertController addAction:action_3];
  880. [self presentViewController:alertController animated:YES completion:nil];
  881. }
  882. - (void)didReceiveMemoryWarning {
  883. [super didReceiveMemoryWarning];
  884. // Dispose of any resources that can be recreated.
  885. }
  886. #ifdef SCANNER_ORDER
  887. -(void) scanSave:(NSMutableDictionary*) upparams
  888. {
  889. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  890. NSString *orderdir = [OLDataProvider getScanPath];
  891. NSString* userdir = [OLDataProvider getUserPath];
  892. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  893. [RAUtils dicttofile:orderPath dict:self.content_data_download];
  894. int section_count = [self.content_data_download[@"section_count"] intValue];
  895. for(int i=0;i<section_count;i++)
  896. {
  897. NSMutableDictionary* section = [self.content_data_download[[NSString stringWithFormat:@"section_%d",i]] mutableCopy];
  898. NSString* title = section[@"title"];
  899. // if([title isEqualToString:@"Model Information"])
  900. // {
  901. //
  902. // NSMutableDictionary* cart_section = RASingleton.sharedInstance.scan_cart[@"section_0"];
  903. // int cart_count = [cart_section[@"count"] intValue];
  904. // for(int j=0;j<cart_count;j++)
  905. // {
  906. // NSMutableDictionary* cart_item = [cart_section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  907. // cart_item[@"description"]= [NSString stringWithFormat:@"%@\n%@\n%@",cart_item[@"model"],cart_item[@"description"],cart_item[@"dimension"] ];
  908. // cart_item[@"control"]=@"model";
  909. // section[[NSString stringWithFormat:@"item_%d",j]] = cart_item;
  910. //
  911. // }
  912. // section[@"count"] = @(cart_count);
  913. // dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  914. // }
  915. // else
  916. if([title isEqualToString:@"Customer"])
  917. {
  918. // 订单信息会写customer info
  919. int scount = [section[@"count"] intValue];
  920. for(int j=0;j<scount;j++)
  921. {
  922. NSMutableDictionary * item = [section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  923. NSString * name = item[@"name"];
  924. if(item[@"value"]!=nil )
  925. appDelegate.customerInfo[name]=item[@"value"];
  926. }
  927. // NSDictionary* item_0=@{@"control":@"text",@"name":@"customer_cid",@"aname":@"Contact",@"value":appDelegate.contact_id};
  928. }
  929. // else
  930. // if([title isEqualToString:@"Remarks Content"])
  931. // {
  932. //
  933. // int scount = [section[@"count"] intValue];
  934. // for(int j=0;j<scount;j++)
  935. // {
  936. // NSMutableDictionary * item = [section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  937. // NSString * name = item[@"name"];
  938. //
  939. //
  940. // if([name isEqualToString:@"comments"])
  941. // {
  942. // item[@"value"] = RASingleton.sharedInstance.scan_cart[@"general_note"];
  943. // section[[NSString stringWithFormat:@"item_%d",j]] = item;
  944. // }
  945. //
  946. //
  947. // }
  948. //
  949. // // NSDictionary* item_0=@{@"control":@"text",@"name":@"customer_cid",@"aname":@"Contact",@"value":appDelegate.contact_id};
  950. // dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  951. //
  952. //
  953. // }
  954. // else if([title isEqualToString:@"Order Total"])
  955. // {
  956. //
  957. // int scount = [section[@"count"] intValue];
  958. // for(int j=0;j<scount;j++)
  959. // {
  960. // NSMutableDictionary * item = [section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  961. // NSString * name = item[@"name"];
  962. //
  963. //
  964. // if([name isEqualToString:@"totalPrice"])
  965. // {
  966. // item[@"value"] = [NSString stringWithFormat:@"%.2f",self.total];
  967. // section[[NSString stringWithFormat:@"item_%d",j]] = item;
  968. // }
  969. //
  970. //
  971. // }
  972. //
  973. // // NSDictionary* item_0=@{@"control":@"text",@"name":@"customer_cid",@"aname":@"Contact",@"value":appDelegate.contact_id};
  974. // dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  975. //
  976. //
  977. //
  978. // }
  979. }
  980. NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  981. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  982. NSString *cartpath = [orderdir stringByAppendingPathComponent:@"cart.json"];
  983. RASingleton.sharedInstance.scan_cart[@"price_type"] = @(RASingleton.sharedInstance.price_type);
  984. RASingleton.sharedInstance.scan_cart[@"price_group"] = appDelegate.price_group;
  985. [RAUtils dicttofile:cartpath dict:RASingleton.sharedInstance.scan_cart];
  986. NSMutableDictionary* orderlist = [OLDataProvider getScanOrderList];
  987. //
  988. // NSString *orderlistPath = [userdir stringByAppendingPathComponent:@"orderlist.json"];
  989. //
  990. //
  991. // if (![[NSFileManager defaultManager] fileExistsAtPath:orderlistPath]) {
  992. //
  993. //
  994. // orderlist = [NSMutableDictionary new];
  995. //
  996. //// [orderlist addObject:appDelegate.order_code];
  997. //// [RAUtils dicttofile:orderlistPath dict:orderlist];
  998. //
  999. // }
  1000. // else
  1001. // {
  1002. // orderlist=[[RAUtils dictfromfile:orderlistPath] mutableCopy];
  1003. //
  1004. //// [orderlist insertObject:appDelegate.order_code atIndex:0];
  1005. //
  1006. //// [RAUtils dicttofile:orderlistPath dict:orderlist];
  1007. // }
  1008. NSMutableDictionary* orderitem = [NSMutableDictionary new];
  1009. orderitem[@"create_by"] = appDelegate.user;
  1010. orderitem[@"price"] = upparams[@"totalPrice"];
  1011. // NSString*
  1012. NSString* company = upparams[@"customer_cid"];
  1013. if(company.length==0)
  1014. company = upparams[@"customer_name"];
  1015. orderitem[@"customer_name"] = company;
  1016. orderitem[@"purchase_time"] = [RAUtils current_date_time];
  1017. if(self.fail_submit)
  1018. orderitem[@"order_status"] = @"Unsubmitted Order";
  1019. else
  1020. orderitem[@"order_status"] = @"Saved Order";
  1021. orderitem[@"order_code"] = appDelegate.order_code;
  1022. NSMutableDictionary* section =RASingleton.sharedInstance.scan_cart[@"section_0"];
  1023. int order_qty=0;
  1024. for(int c=0;c<[section[@"count"] intValue];c++)
  1025. {
  1026. NSDictionary* item = section[[NSString stringWithFormat:@"item_%d",c]];
  1027. order_qty+=[item[@"count"] intValue];
  1028. }
  1029. orderitem[@"model_count"] =[ NSString stringWithFormat:@"%d",order_qty];//RASingleton.sharedInstance.scan_cart[@"section_0"][@"count"] ];
  1030. int count = [orderlist[@"count"] intValue];
  1031. NSMutableDictionary* newlist = [NSMutableDictionary new];
  1032. newlist[@"item_0"]=orderitem;
  1033. int newcount = 1;
  1034. int checkordercode = 0;
  1035. for(int i=0;i<count;i++)
  1036. {
  1037. NSMutableDictionary* item = orderlist[[NSString stringWithFormat:@"item_%d",i]];
  1038. if([item[@"order_code"] isEqualToString: appDelegate.order_code ])
  1039. {
  1040. checkordercode++;
  1041. if(checkordercode>1)
  1042. {
  1043. int dbg=1;
  1044. }
  1045. continue;
  1046. }
  1047. else
  1048. {
  1049. newlist[[NSString stringWithFormat:@"item_%d",newcount]] = item;
  1050. newcount++;
  1051. }
  1052. }
  1053. newlist[@"count"] = @(newcount);
  1054. [OLDataProvider saveScanOrderList:newlist];
  1055. // [RAUtils dicttofile:orderlistPath dict:newlist];
  1056. #ifdef RA_NOTIFICATION
  1057. [ActiveViewController Notify:@"CartViewController,ScanOrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1058. #else
  1059. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1060. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  1061. #endif
  1062. }
  1063. #endif
  1064. -(void) newScanOrder
  1065. {
  1066. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1067. if(appDelegate.order_code.length>0)
  1068. {
  1069. [OLDataProvider scanCloseOrder];
  1070. }
  1071. // RASingleton.sharedInstance.enable_OfflineOrder = true;
  1072. // __block MainViewController *brself= self;
  1073. // NSString* order_code = RASingleton.sharedInstance.scan_temp_code;
  1074. appDelegate.can_set_cart_price = true;
  1075. appDelegate.can_see_price = true;
  1076. RASingleton.sharedInstance.scan_cart = nil;
  1077. RASingleton.sharedInstance.price_type = 1;
  1078. {
  1079. NSString *orderdir = [OLDataProvider getScanPath];
  1080. // [OLDataProvider moveScanTemp2Order];
  1081. NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  1082. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  1083. }
  1084. #ifdef RA_NOTIFICATION
  1085. [ActiveViewController Notify:@"CartViewController,ScanOrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1086. #else
  1087. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  1088. [main_vc reloadCart:true immediately:false];
  1089. #endif
  1090. MainViewController * mainvc = (MainViewController*)appDelegate.main_vc;
  1091. [mainvc switchToCart];
  1092. }
  1093. - (IBAction)onSaveClick:(id)sender {
  1094. // id foo = nil;
  1095. // [[NSMutableArray array] addObject:foo];
  1096. // add params check here.
  1097. [self.lastedit endEditing:true];
  1098. [self.lasttextview endEditing:true];
  1099. NSMutableDictionary* upparams = [self check_cancommit:false];
  1100. // if(self.cancommit==false)
  1101. // return;
  1102. if([upparams[@"shipping"] isEqualToString:@"Shipping To Be Quoted"]||[upparams[@"shipping"] isEqualToString:@"To Be Quoted"])
  1103. upparams[@"shipping"] = nil;
  1104. #ifdef SCANNER_ORDER
  1105. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  1106. {
  1107. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  1108. // NSString *documents = [paths objectAtIndex:0];
  1109. [self scanSave:upparams];
  1110. [RAUtils message_box:@"Message" message:@"Save Successfully" completion:^{
  1111. [self newScanOrder];
  1112. [self.navigationController popViewControllerAnimated:true];
  1113. }];
  1114. return;
  1115. }
  1116. #endif
  1117. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Saving Order" completion:^{
  1118. PopWaitAlert* pop = [RAUtils waiting_pop:@"Saving Order" completion:nil];
  1119. [RANetwork request_save_order:upparams completionHandler:^(NSMutableDictionary *result) {
  1120. NSDictionary* editor_json =result;
  1121. // [waitalert dismissViewControllerAnimated:YES completion:^{
  1122. [pop hide];
  1123. if([[editor_json valueForKey:@"result"] intValue]==2)
  1124. {
  1125. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1126. NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  1127. if(appDelegate.user_type ==USER_ROLE_EMPLOYEE)
  1128. {
  1129. appDelegate.customerInfo = customerInfo;
  1130. appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  1131. }
  1132. NSString *msg = nil;
  1133. if ([editor_json objectForKey:@"so#"]) {
  1134. msg = [@"SO#:" stringByAppendingString:[editor_json objectForKey:@"so#"]];
  1135. }
  1136. [RAUtils message_box:@"Order Saved" message:msg completion:nil];
  1137. if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.save_order_logout && appDelegate.user_type ==USER_ROLE_EMPLOYEE)
  1138. {
  1139. [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1140. [self prepareReturn:nil];
  1141. [self.navigationController popViewControllerAnimated:true];
  1142. }
  1143. else{
  1144. #ifdef RA_NOTIFICATION
  1145. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1146. #else
  1147. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1148. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1149. #endif
  1150. }
  1151. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  1152. if (![RASingleton sharedInstance].currentOrderIsMerged) {
  1153. [self releaseOrderAfterSave];
  1154. }
  1155. }
  1156. }
  1157. else
  1158. {
  1159. [RAUtils message_box:@"Save Order" message:[editor_json valueForKey:@"err_msg"] completion:nil] ;
  1160. }
  1161. // }];
  1162. }];
  1163. // }];
  1164. }
  1165. - (void)textFieldDidEndEditing:(UITextField *)textField
  1166. {
  1167. [super textFieldDidEndEditing:textField];
  1168. UITableViewCell *cell = (UITableViewCell *) textField.superview.superview;
  1169. NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
  1170. NSMutableDictionary* section_json=nil;
  1171. // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row);
  1172. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  1173. NSString* name = [item_json valueForKey:@"name"];
  1174. if([name isEqualToString:@"shipping"]|| [name isEqualToString:@"handling_fee_value"]||[name isEqualToString:@"lift_gate_value"]||[name isEqualToString:@"tax_percentage"])
  1175. {
  1176. float shipping = [self getprice:@"shipping" section:indexPath.section];
  1177. float paymentsAndCredits = [self getprice:@"paymentsAndCredits" section:indexPath.section];
  1178. float handling_fee_value = [self getprice:@"handling_fee_value" section:indexPath.section];
  1179. float lift_gate =[self getprice:@"lift_gate_value" section:indexPath.section];
  1180. float tax = [self getprice:@"tax_percentage" section:indexPath.section]/100.0*paymentsAndCredits;
  1181. float totalprice=shipping+paymentsAndCredits+handling_fee_value+lift_gate+tax;
  1182. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  1183. int count=0;
  1184. count=[[section_json valueForKey:@"count"] intValue];
  1185. int total_row_idx=-1;
  1186. for(int i=0;i<count;i++)
  1187. {
  1188. NSDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]] mutableCopy];
  1189. if([[olditem valueForKey:@"name"] isEqualToString:@"totalPrice" ])
  1190. {
  1191. [olditem setValue:[NSString stringWithFormat:@"%.2f",totalprice] forKey:@"value"];
  1192. [olditem setValue:@"true" forKey:@"dirty"];
  1193. [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",i ]];
  1194. total_row_idx=i;
  1195. }
  1196. }
  1197. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  1198. self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data];
  1199. if(total_row_idx>=0)
  1200. {
  1201. NSUInteger newIndex[] = {indexPath.section, total_row_idx};
  1202. NSIndexPath *newPath = [[NSIndexPath alloc] initWithIndexes:newIndex length:2];
  1203. // DebugLog(@"before refresh %@",NSStringFromCGSize(self.editorTable.contentSize));
  1204. [self.editorTable reloadRowsAtIndexPaths:@[newPath]withRowAnimation:UITableViewRowAnimationMiddle];
  1205. // DebugLog(@"after refresh %@",NSStringFromCGSize(self.editorTable.contentSize));
  1206. // CGSize tablecontent =self.editorTable.contentSize;
  1207. // tablecontent.height=tablecontent.height+self.keyboard_h;
  1208. // self.editorTable.contentSize=tablecontent;
  1209. //
  1210. //
  1211. // DebugLog(@"resize to %@",NSStringFromCGSize(self.editorTable.contentSize));
  1212. }
  1213. // self.content_data = [editor_json mutableCopy];
  1214. // self.content_data = [self translate_json:editor_json];
  1215. // NSMutableDictionary* content_data1 = [self translate_json:self.content_data];
  1216. // [self.editorTable reloadData];
  1217. }
  1218. //
  1219. // [item_json setValue:@"true" forKey:@"dirty"];
  1220. // [item_json setValue:textField.text forKey:@"value"];
  1221. }
  1222. -(float) getprice:(NSString*) name section :(long) index
  1223. {
  1224. NSMutableDictionary* section_json=nil;
  1225. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",index ]] mutableCopy];
  1226. int count=0;
  1227. count=[[section_json valueForKey:@"count"] intValue];
  1228. for(int i=0;i<count;i++)
  1229. {
  1230. NSDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]] mutableCopy];
  1231. if([[olditem valueForKey:@"name"] isEqualToString:name])
  1232. {
  1233. return [[olditem valueForKey:@"value"] floatValue];
  1234. }
  1235. }
  1236. return 0;
  1237. }
  1238. /*
  1239. #pragma mark - Navigation
  1240. // In a storyboard-based application, you will often want to do a little preparation before navigation
  1241. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  1242. // Get the new view controller using [segue destinationViewController].
  1243. // Pass the selected object to the new view controller.
  1244. }
  1245. */
  1246. - (void)releaseOrderAfterSave {
  1247. dispatch_async(dispatch_get_main_queue(), ^{
  1248. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1249. // [RANetwork release_Order:appDelegate.order_code withScreen:nil];
  1250. [RANetwork request_release_order:appDelegate.order_code withScreen:nil completionHandler:nil];
  1251. [appDelegate closeOrder];
  1252. [appDelegate SetSo:nil];
  1253. appDelegate.cart_count=0;
  1254. [appDelegate update_count_mark];
  1255. [((MainViewController*)appDelegate.main_vc) switchToOrder];
  1256. [self prepareReturn:nil];
  1257. [self.navigationController popToRootViewControllerAnimated:false];
  1258. });
  1259. }
  1260. -(NSString* )create_customer_ext:(NSDictionary*)customerinfo
  1261. {
  1262. NSString* ret=nil;
  1263. NSString* customer_address1= [customerinfo valueForKey:@"customer_address1"];
  1264. NSString* customer_address2= [customerinfo valueForKey:@"customer_address2"];
  1265. NSString* customer_address3= [customerinfo valueForKey:@"customer_address3"];
  1266. NSString* customer_address4= [customerinfo valueForKey:@"customer_address4"];
  1267. NSMutableArray* arraddr = [[NSMutableArray alloc] init];
  1268. if(customer_address1.length>0)
  1269. [arraddr addObject:customer_address1];
  1270. if(customer_address2.length>0)
  1271. [arraddr addObject:customer_address2];
  1272. if(customer_address3.length>0)
  1273. [arraddr addObject:customer_address3];
  1274. if(customer_address4.length>0)
  1275. [arraddr addObject:customer_address4];
  1276. NSString *addr_string = [arraddr componentsJoinedByString:@"\r\n"];
  1277. NSString* customer_city= [customerinfo valueForKey:@"customer_city"];
  1278. NSString* customer_country= [customerinfo valueForKey:@"customer_country"];
  1279. NSString* customer_zipcode= [customerinfo valueForKey:@"customer_zipcode"];
  1280. NSString* customer_state= [customerinfo valueForKey:@"customer_state"];
  1281. NSMutableArray* arrcty = [[NSMutableArray alloc] init];
  1282. if(customer_city.length>0)
  1283. [arrcty addObject:customer_city];
  1284. if(customer_state.length>0)
  1285. [arrcty addObject:customer_state];
  1286. if(customer_zipcode.length>0)
  1287. [arrcty addObject:customer_zipcode];
  1288. if(customer_country.length>0)
  1289. [arrcty addObject:customer_country];
  1290. NSString *cty_string = [arrcty componentsJoinedByString:@", "];
  1291. // NSString* customer_phone= [customerinfo valueForKey:@"customer_phone"];
  1292. // NSString* customer_fax= [customerinfo valueForKey:@"customer_fax"];
  1293. //
  1294. // NSMutableArray* arrpho = [[NSMutableArray alloc] init];
  1295. // if(customer_phone.length>0)
  1296. // {
  1297. // customer_phone = [NSString stringWithFormat:@"TEL: %@",customer_phone];
  1298. // [arrpho addObject:customer_phone];
  1299. // }
  1300. // if(customer_fax.length>0)
  1301. // {
  1302. // customer_fax = [NSString stringWithFormat:@"FAX: %@",customer_fax];
  1303. // [arrpho addObject:customer_fax];
  1304. // }
  1305. // NSString *phone_string = [arrpho componentsJoinedByString:@", "];
  1306. //
  1307. //
  1308. // NSString* customer_contact= [customerinfo valueForKey:@"customer_contact"];
  1309. // if(customer_contact.length>0)
  1310. // {
  1311. // customer_contact = [NSString stringWithFormat:@"ATTN: %@",customer_contact];
  1312. //
  1313. // }
  1314. // NSString *contact_string = customer_contact;
  1315. //
  1316. //
  1317. // NSString* customer_email= [customerinfo valueForKey:@"customer_email"];
  1318. // if(customer_email.length>0)
  1319. // {
  1320. // customer_email = [NSString stringWithFormat:@"Email: %@",customer_email];
  1321. //
  1322. // }
  1323. // NSString *email_string = customer_email;
  1324. NSMutableArray* arrext = [[NSMutableArray alloc] init];
  1325. if(addr_string.length>0)
  1326. [arrext addObject:addr_string];
  1327. if(cty_string.length>0)
  1328. [arrext addObject:cty_string];
  1329. // if(phone_string.length>0)
  1330. // [arrext addObject:phone_string];
  1331. // if(contact_string.length>0)
  1332. // [arrext addObject:contact_string];
  1333. // if(email_string.length>0)
  1334. // [arrext addObject:email_string];
  1335. ret = [arrext componentsJoinedByString:@"\r\n"];
  1336. // NSString *string = [array componentsJoinedByString:@" "];
  1337. // NSString* customer_name= [customerinfo valueForKey:@"customer_name"];
  1338. return ret;
  1339. }
  1340. -(NSMutableDictionary*)create_value_map:(NSDictionary*)key_map
  1341. {
  1342. NSMutableDictionary* ret= [[NSMutableDictionary alloc] init];
  1343. NSArray *keys= [key_map allKeys];
  1344. //遍历keys
  1345. for(int i=0;i<[keys count];i++)
  1346. {
  1347. //得到当前key
  1348. NSString *key=[keys objectAtIndex:i];
  1349. //如果key不是pic,说明value是字符类型,比如name:Boris
  1350. NSString* valuefrom = [key_map valueForKey:key];
  1351. if(valuefrom.length==0)
  1352. continue;
  1353. NSString* value=[self getValue:valuefrom];
  1354. [ret setValue:value forKey:valuefrom];
  1355. }
  1356. NSDictionary * customerinfo =[self create_cusromer_info_from_table];
  1357. [ret setValue:[self create_customer_ext:customerinfo] forKey:@"customer_contact_ext"];
  1358. [ret setValue:customerinfo[@"customer_first_name"] forKey:@"customer_first_name"];
  1359. [ret setValue:customerinfo[@"customer_last_name"] forKey:@"customer_last_name"];
  1360. return ret;
  1361. }
  1362. -(NSMutableDictionary*)create_cusromer_info_from_table
  1363. {
  1364. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1365. NSMutableDictionary* ret= [appDelegate.customerInfo mutableCopy] ;
  1366. [ret setValue:[self getValue:@"customer_country"] forKey:@"customer_country"];
  1367. [ret setValue:[self getValue:@"customer_phone"] forKey:@"customer_phone"];
  1368. [ret setValue:[self getValue:@"customer_email"] forKey:@"customer_email"];
  1369. [ret setValue:[self getValue:@"customer_name"] forKey:@"customer_name"];
  1370. [ret setValue:[self getValue:@"customer_address4"] forKey:@"customer_address4"];
  1371. [ret setValue:[self getValue:@"customer_address3"] forKey:@"customer_address3"];
  1372. [ret setValue:[self getValue:@"customer_address2"] forKey:@"customer_address2"];
  1373. [ret setValue:[self getValue:@"customer_address1"] forKey:@"customer_address1"];
  1374. [ret setValue:[self getValue:@"customer_zipcode"] forKey:@"customer_zipcode"];
  1375. [ret setValue:[self getValue:@"customer_city"] forKey:@"customer_city"];
  1376. [ret setValue:[self getValue:@"customer_state"] forKey:@"customer_state"];
  1377. [ret setValue:[self getValue:@"customer_cid"] forKey:@"customer_cid"];
  1378. [ret setValue:[self getValue:@"customer_state"] forKey:@"customer_state"];
  1379. [ret setValue:[self getValue:@"customer_contact"] forKey:@"customer_contact"];
  1380. [ret setValue:[self getValue:@"customer_fax"] forKey:@"customer_fax"];
  1381. NSString * firstname =nil;
  1382. NSString* lastname = nil;
  1383. NSString* contact_name = [self getValue:@"customer_contact"];
  1384. if(contact_name!=nil)
  1385. {
  1386. NSArray *_arr = [contact_name componentsSeparatedByString:NSLocalizedString(@" ", nil)];
  1387. if(_arr.count>=1)
  1388. {
  1389. firstname =_arr[0];
  1390. if(_arr.count>1)
  1391. {
  1392. lastname=[[_arr subarrayWithRange:NSMakeRange(1, _arr.count-1)] componentsJoinedByString:@" "];
  1393. }
  1394. }
  1395. }
  1396. [ret setValue:firstname forKey:@"customer_first_name"];
  1397. [ret setValue:lastname forKey:@"customer_last_name"];
  1398. // [ret setValue:[self create_customer_ext:ret] forKey:@"customer_contact_ext"];
  1399. return ret;
  1400. }
  1401. #pragma mark - multi_action sub action clicked
  1402. - (void)MActionClicked:(UIButton *)sender {
  1403. UITableViewCell *cell = (UITableViewCell *) sender.superview.superview;
  1404. NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
  1405. int refresh =0;
  1406. NSMutableDictionary* section_json=nil;
  1407. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  1408. NSString* subid=[item_json valueForKey:@"subid"];
  1409. NSString* refresh_trigger = [item_json valueForKey:@"name"];
  1410. NSDictionary* sub_action = [item_json objectForKey:[NSString stringWithFormat:@"item_%ld",(long)sender.tag]];
  1411. NSString* type = [sub_action valueForKey:@"type"];
  1412. bool discardDirty = [[sub_action valueForKey:@"discard_dirty"] boolValue];
  1413. if([type isEqualToString:@"pull"])
  1414. {
  1415. [self.lastedit endEditing:true];
  1416. refresh = [[sub_action valueForKey:@"refresh"] intValue];
  1417. NSDictionary* keymap= [sub_action objectForKey:@"key_map"];
  1418. NSMutableDictionary* value=[self create_value_map:keymap];
  1419. if(subid==nil)
  1420. {
  1421. NSDictionary* jsonmap=[sub_action valueForKey:@"key_map"];
  1422. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  1423. int icount=[[section_json valueForKey:@"count"] intValue];
  1424. for (int ic=0;ic<icount;ic++)
  1425. {
  1426. NSMutableDictionary* modify_item= [[section_json objectForKey:[NSString stringWithFormat:@"item_%d",ic ]] mutableCopy];
  1427. NSString* mapto = [modify_item valueForKey:@"name"];
  1428. if(mapto.length==0)
  1429. continue;
  1430. NSString* valuefrom= [jsonmap valueForKey:[modify_item valueForKey:@"name"]];
  1431. if(valuefrom==nil)
  1432. continue;
  1433. NSString* valuestr=[value valueForKey:valuefrom];
  1434. // valuestr = [self getValue:valuefrom];
  1435. if(true)
  1436. {
  1437. if(valuestr.length>0)
  1438. [modify_item setValue:valuestr forKey:@"value"];
  1439. else
  1440. [modify_item setValue:@"" forKey:@"value"];
  1441. [modify_item setValue:@"true" forKey:@"dirty"];
  1442. [section_json setObject:modify_item forKey:[NSString stringWithFormat:@"item_%d",ic ]];
  1443. }
  1444. }
  1445. }
  1446. else
  1447. {
  1448. NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  1449. int section = [(NSString*)idarr[0] intValue];
  1450. int item=[(NSString*)idarr[1] intValue];
  1451. NSDictionary* jsonmap=[sub_action valueForKey:@"key_map"];
  1452. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  1453. NSMutableDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]] mutableCopy];
  1454. NSString* control_type = [olditem valueForKey:@"control"];
  1455. if([control_type isEqualToString:@"switch"])
  1456. olditem= [self fill_switch_subitem:olditem subid:nil source:value mapping:jsonmap ];
  1457. else if([control_type isEqualToString:@"enum"])
  1458. {
  1459. olditem= [self fill_enum_subitem:olditem subid:nil source:value mapping:jsonmap ];
  1460. }
  1461. else
  1462. {
  1463. [RAUtils message_box:@"Sorry" message:@"not impl" completion:nil];
  1464. }
  1465. [olditem setValue:@"true" forKey:@"dirty"];
  1466. [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",item ]];
  1467. }
  1468. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  1469. self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  1470. if(refresh==1)
  1471. {
  1472. // if(restore_json!=nil)
  1473. // {
  1474. // int rc=[[restore_json valueForKey:@"count"] intValue];
  1475. // for(int ir=0;ir<rc;ir++)
  1476. // {
  1477. // NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
  1478. //
  1479. //
  1480. // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  1481. // for(int i=0;i<section_count;i++)
  1482. // {
  1483. // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  1484. // // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  1485. // int item_count = [[sectionjson valueForKey:@"count"] intValue];
  1486. // for(int j=0;j<item_count;j++)
  1487. // {
  1488. // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  1489. // // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  1490. //
  1491. // if([[itemjson valueForKey:@"name"] isEqualToString:name])
  1492. // {
  1493. // [itemjson removeObjectForKey:@"dirty"];
  1494. // [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
  1495. // }
  1496. //
  1497. // }
  1498. // [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
  1499. // }
  1500. //
  1501. //
  1502. // }
  1503. //
  1504. // }
  1505. [self refresh:refresh_trigger discardDirty:discardDirty] ;
  1506. return ;
  1507. }
  1508. // DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  1509. [self.editorTable reloadData ];
  1510. }
  1511. else
  1512. {
  1513. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1514. NSDictionary * item_json = sub_action;
  1515. NSString* value = [item_json valueForKey:@"value"];
  1516. if([value isEqualToString:@"new_addr"])
  1517. {
  1518. AddressEditorViewController * addressVC = [[AddressEditorViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  1519. addressVC.url_type = URL_REMOTE;
  1520. addressVC.request_url=URL_ADDRESS_EDOTOR;
  1521. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  1522. // NSString * string = [checked componentsJoinedByString:@","];
  1523. // [params setValue:string forKey:@"cart2Checkbox"];
  1524. params[@"is_subaction"]=@"true";
  1525. params[@"subaction_tag"]= [NSString stringWithFormat:@"%ld",(long)sender.tag];
  1526. addressVC.params = params;
  1527. addressVC.delegate = self;
  1528. addressVC.from = indexPath;
  1529. // orderinfoVC.params = params;
  1530. [self.navigationController pushViewController:addressVC animated:true];
  1531. }else if([value isEqualToString:@"credit_card"])
  1532. {
  1533. CreditCardEditorViewController * cardVC = [[CreditCardEditorViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  1534. NSDictionary *data = [item_json objectForKey:@"data"];
  1535. if(data!=nil)
  1536. {
  1537. cardVC.content_data_download = [data mutableCopy];
  1538. cardVC.url_type = URL_NONE;
  1539. cardVC.request_url=nil;
  1540. }
  1541. else
  1542. {
  1543. cardVC.url_type = URL_REMOTE;
  1544. cardVC.request_url=URL_CREDITCARD_EDOTOR;
  1545. }
  1546. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  1547. params[@"orderCode"]=appDelegate.order_code;
  1548. params[@"is_subaction"]=@"true";
  1549. params[@"subaction_tag"]= [NSString stringWithFormat:@"%ld",(long)sender.tag];
  1550. cardVC.params = params;
  1551. cardVC.delegate = self;
  1552. cardVC.from = indexPath;
  1553. // orderinfoVC.params = params;
  1554. [self.navigationController pushViewController:cardVC animated:true];
  1555. }
  1556. else if([value isEqualToString:@"Sales_Order_Freight_Bill_To"])
  1557. {
  1558. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  1559. cvc.showNavibar = true;
  1560. cvc.contact_type = value;
  1561. cvc.is_subaction = @"true";
  1562. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  1563. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  1564. [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  1565. //
  1566. // if(self.returnValue)
  1567. // self.returnValue(value);
  1568. };
  1569. [self.navigationController pushViewController:cvc animated:true];
  1570. }
  1571. else if([value isEqualToString:@"Sales_Order_Ship_From"])
  1572. {
  1573. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  1574. cvc.showNavibar = true;
  1575. cvc.contact_type = value;
  1576. cvc.is_subaction = @"true";
  1577. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  1578. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  1579. [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  1580. //
  1581. // if(self.returnValue)
  1582. // self.returnValue(value);
  1583. };
  1584. [self.navigationController pushViewController:cvc animated:true];
  1585. }
  1586. else if([value isEqualToString:@"Sales_Order_Customer"])
  1587. {
  1588. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  1589. cvc.is_subaction = @"true";
  1590. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  1591. cvc.showNavibar = true;
  1592. cvc.contact_type = value;
  1593. __weak typeof(self) weakself = self;
  1594. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  1595. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  1596. //
  1597. // if(self.returnValue)
  1598. // self.returnValue(value);
  1599. };
  1600. [self.navigationController pushViewController:cvc animated:true];
  1601. }
  1602. else if([value isEqualToString:@"Sales_Order_Merchandise_Bill_To"])
  1603. {
  1604. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  1605. cvc.showNavibar = true;
  1606. cvc.contact_type = value;
  1607. cvc.is_subaction = @"true";
  1608. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  1609. __weak typeof(self) weakself = self;
  1610. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  1611. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  1612. //
  1613. // if(self.returnValue)
  1614. // self.returnValue(value);
  1615. };
  1616. [self.navigationController pushViewController:cvc animated:true];
  1617. }
  1618. else if([value isEqualToString:@"Contact_Return_To"])
  1619. {
  1620. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  1621. cvc.is_subaction = @"true";
  1622. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  1623. cvc.showNavibar = true;
  1624. cvc.contact_type = value;
  1625. __weak typeof(self) weakself = self;
  1626. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  1627. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  1628. //
  1629. // if(self.returnValue)
  1630. // self.returnValue(value);
  1631. };
  1632. [self.navigationController pushViewController:cvc animated:true];
  1633. }
  1634. else if([value isEqualToString:@"Sales_Order_Ship_To"])
  1635. {
  1636. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  1637. cvc.is_subaction = @"true";
  1638. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  1639. cvc.showNavibar = true;
  1640. cvc.contact_type = value;
  1641. __weak typeof(self) weakself = self;
  1642. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  1643. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  1644. //
  1645. // if(self.returnValue)
  1646. // self.returnValue(value);
  1647. };
  1648. [self.navigationController pushViewController:cvc animated:true];
  1649. }
  1650. }
  1651. }
  1652. #pragma mark - Urgency
  1653. -(void) viewWillDisappear:(BOOL)animated
  1654. {
  1655. [super viewWillDisappear:animated];
  1656. [self cancel_urgency_timer];
  1657. }
  1658. - (void)start_urgency_timer {
  1659. return;
  1660. if (!self.editable) {
  1661. return;
  1662. }
  1663. __weak typeof(self) weakSelf = self;
  1664. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  1665. [appDelegate.urgencyDic setValue:appDelegate.user forKey:@"user"];
  1666. #ifdef OFFLINE_MODE
  1667. [appDelegate.urgencyDic setValue:[NSNumber numberWithBool:appDelegate.offline_mode] forKey:@"offline_mode"];
  1668. #endif
  1669. MainViewController *mainVC = (MainViewController *)appDelegate.main_vc;
  1670. __block NSString *so = [mainVC.labelSo.text substringFromIndex:5];
  1671. [[JKTimerManager sharedTimerManager] scheduledDispatchTimerWithName:self.urgency_timer_name timeInterval:1 queue:nil repeats:YES action:^{
  1672. NSMutableDictionary *urgencyDic = [NSMutableDictionary dictionary];
  1673. // DebugLog(@"timer start....");
  1674. [urgencyDic setValue:weakSelf.content_data_download forKey:[NSString stringWithFormat:@"%@_restored_data",self.class_name]];
  1675. [urgencyDic setValue:weakSelf.class_name forKey:@"class_name"];
  1676. if ([weakSelf.class_name isEqualToString:@"CreateOrderViewController"]) {
  1677. // CreateOrderViewController
  1678. [urgencyDic setValue:appDelegate.order_code forKey:@"order_code"];
  1679. [urgencyDic setValue:so forKey:@"order_so"];
  1680. [urgencyDic setValue:[NSNumber numberWithInt:appDelegate.order_status ] forKey:@"order_status"];
  1681. [urgencyDic setValue:appDelegate.order_customer_id forKey:@"order_customer_id"];
  1682. }
  1683. dispatch_async(dispatch_get_main_queue(), ^{
  1684. [appDelegate.urgencyDic setValue:urgencyDic forKey:[NSString stringWithFormat:@"level_%d",weakSelf.level]];
  1685. [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:weakSelf.level + 1] forKey:@"count"];
  1686. });
  1687. }];
  1688. }
  1689. - (void)cancel_urgency_timer {
  1690. [[JKTimerManager sharedTimerManager] cancelTimerWithName:self.urgency_timer_name];
  1691. }
  1692. #pragma mark - Submit Order
  1693. - (void)customer_commit_order:(NSMutableDictionary *)upparams {
  1694. [upparams setValue:@"true" forKey:@"isHold"];
  1695. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Order Submission" completion:^{
  1696. PopWaitAlert* pop = [RAUtils waiting_pop:@"Order Submission" completion:nil];
  1697. [RANetwork request_commit_order:upparams completionHandler:^(NSMutableDictionary *result) {
  1698. NSDictionary* editor_json =result;
  1699. // [waitalert dismissViewControllerAnimated:YES completion:^{
  1700. if([[editor_json valueForKey:@"result"] intValue]==2)
  1701. {
  1702. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1703. // appDelegate.customerInfo = customerInfo;
  1704. [appDelegate closeOrder];
  1705. #ifdef RA_NOTIFICATION
  1706. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1707. #else
  1708. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1709. #endif
  1710. NSString* title=nil;
  1711. NSString* msg=nil;
  1712. #ifdef OFFLINE_MODE
  1713. if(appDelegate.offline_mode)
  1714. {
  1715. title=TITLE_OFFLINE_SUBMIT;
  1716. msg=MSG_OFFLINE_SUBMIT;
  1717. }
  1718. else
  1719. #endif
  1720. {
  1721. title=@"Order submitted sucessfully";
  1722. msg=[NSString stringWithFormat:@"Confirmation#: %@",[editor_json valueForKey:@"so#"]];
  1723. }
  1724. [RAUtils message_box:title message:msg completion:nil];
  1725. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  1726. // [alert show];
  1727. [self prepareReturn:nil];
  1728. [self.navigationController popToRootViewControllerAnimated:true];
  1729. }
  1730. else
  1731. {
  1732. [RAUtils message_box:@"Order Submission" message:[editor_json valueForKey:@"err_msg"] completion:nil];
  1733. }
  1734. // }];
  1735. }];
  1736. // }];
  1737. }
  1738. #ifdef SCANNER_ORDER
  1739. -(void)addTasks: (NSString*)filename md5:(NSString*) md5
  1740. {
  1741. AppDelegate* Appdelegate=(AppDelegate*)[UIApplication sharedApplication].delegate;
  1742. // if (![self shouldUploadWithCurrentNerworkStatus]) {
  1743. // [self.view makeToast:@"Current network is not WiFi,you can upload it manually when wifi connected." duration:3.0 position:CSToastPositionCenter];
  1744. // }
  1745. //prepare upload
  1746. // NSMutableArray* tasks = [NSMutableArray new];
  1747. // for(NSMutableDictionary* photo in self.photos)
  1748. NSMutableDictionary* task=[[NSMutableDictionary alloc]init];
  1749. // task[@"path"]=path;
  1750. task[@"file"]=filename;
  1751. task[@"url"]=Appdelegate.uploadurl;
  1752. NSDictionary* params = @{
  1753. @"site_name":[RADataProvider getSiteName],
  1754. @"user":Appdelegate.user,
  1755. @"_method":@"uploadOfflineOrder",
  1756. @"password" : Appdelegate.password,
  1757. @"md5":md5
  1758. };
  1759. task[@"params"]=params;
  1760. // NSString *file = photo[@"file"];
  1761. // [self moveTmpImageToCache:file];
  1762. // [tasks addObject:task];
  1763. // Signature
  1764. // NSDictionary *signatureTask = [self prepareSignatureTask];
  1765. // // add upload tasks;
  1766. [Appdelegate.uploadManager addTask:task];
  1767. // [self clear];
  1768. }
  1769. -(NSMutableDictionary*) convertScanitem :(NSMutableDictionary*) itemjson
  1770. {
  1771. // NSMutableArray* fields=[[NSMutableArray alloc] init];
  1772. NSMutableDictionary* upparams=[[NSMutableDictionary alloc] init];
  1773. if([[itemjson valueForKey:@"control"] isEqualToString:@"enum"])
  1774. {
  1775. NSString* single_select = [itemjson valueForKey:@"single_select"];
  1776. if([single_select isEqualToString:@"true"])
  1777. {
  1778. NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
  1779. int count = [[cadejson valueForKey:@"count"] intValue];
  1780. upparams[[itemjson valueForKey:@"name"]]=@"";
  1781. for(int cc=0;cc<count;cc++)
  1782. {
  1783. NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
  1784. if([[valjson valueForKey:@"check"]intValue]==1)
  1785. {
  1786. // NSString* vid = [valjson valueForKey:@"value_id"] ;
  1787. // if(vid.length==0)
  1788. // vid=@"";
  1789. [upparams setValue:[valjson valueForKey:@"value_id"] forKey:[itemjson valueForKey:@"name"]];
  1790. NSMutableDictionary* subitem = valjson[@"sub_item"];
  1791. if(subitem!=nil)
  1792. {
  1793. int scount = [subitem[@"count"]intValue];
  1794. for(int si=0;si<scount;si++)
  1795. {
  1796. NSMutableDictionary* sitem = subitem[[NSString stringWithFormat:@"item_%d",si]];
  1797. NSMutableDictionary* convertitem = [self convertScanitem:sitem];
  1798. [upparams addEntriesFromDictionary:convertitem];
  1799. }
  1800. }
  1801. break;
  1802. }
  1803. }
  1804. return upparams;
  1805. }
  1806. else //multiple select
  1807. {
  1808. NSMutableArray* checked = [[NSMutableArray alloc] init];
  1809. NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
  1810. int count = [[cadejson valueForKey:@"count"] intValue];
  1811. upparams[[itemjson valueForKey:@"name"]]=@"";
  1812. for(int cc=0;cc<count;cc++)
  1813. {
  1814. NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
  1815. if([[valjson valueForKey:@"check"]intValue]==1)
  1816. {
  1817. // NSString* vid = [valjson valueForKey:@"value_id"] ;
  1818. // if(vid.length==0)
  1819. // vid=@"";
  1820. // [checked addObject:[NSNumber numberWithInt:[[valjson valueForKey:@"value_id"] intValue]]];
  1821. [checked addObject:[NSString stringWithFormat:@"%@",[valjson valueForKey:@"value_id"]]];
  1822. }
  1823. }
  1824. {
  1825. NSString * string = [checked componentsJoinedByString:@","];
  1826. [upparams setValue:string forKey:[itemjson valueForKey:@"name"]];
  1827. }
  1828. return upparams;
  1829. }
  1830. /*
  1831. upparams setValue:itemjson forKey:<#(NSString *)#>
  1832. */
  1833. }
  1834. else
  1835. if([[itemjson valueForKey:@"control"] isEqualToString:@"action"])
  1836. {
  1837. return nil;
  1838. }
  1839. else if([[itemjson valueForKey:@"control"] isEqualToString:@"signature"])
  1840. {
  1841. NSString* valuestr = [itemjson valueForKey:@"value"];
  1842. if(valuestr.length==0)
  1843. valuestr=@"";
  1844. [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  1845. return upparams;
  1846. }
  1847. else if([[itemjson valueForKey:@"control"] isEqualToString:@"switch"])
  1848. {
  1849. NSString* valuestr = [itemjson valueForKey:@"value"];
  1850. [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  1851. NSString* value = [itemjson valueForKey:@"value"];
  1852. // NSMutableDictionary* boolitem=nil;
  1853. // NSMutableDictionary* subjson=nil;
  1854. if([value isEqualToString:@"true"])
  1855. {
  1856. // boolitem =[[itemjson objectForKey:@"true"] mutableCopy];
  1857. NSMutableDictionary* subitem = itemjson[@"sub_item"];
  1858. if(subitem!=nil)
  1859. {
  1860. int scount = [subitem[@"count"]intValue];
  1861. for(int si=0;si<scount;si++)
  1862. {
  1863. NSMutableDictionary* sitem = subitem[[NSString stringWithFormat:@"item_%d",si]];
  1864. NSMutableDictionary* convertitem = [self convertScanitem:sitem];
  1865. [upparams addEntriesFromDictionary:convertitem];
  1866. }
  1867. }
  1868. }
  1869. else
  1870. {
  1871. // boolitem =[[itemjson objectForKey:@"false"] mutableCopy];
  1872. }
  1873. // subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy];
  1874. // if( subjson!=nil /*&& !active*/)
  1875. // {
  1876. // int sub_count = [[subjson valueForKey:@"count"] intValue];
  1877. // for(int l=0;l<sub_count;l++)
  1878. // {
  1879. //// NSMutableDictionary * modify_item=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
  1880. //// if([modify_item valueForKey:@"value"]!=nil && ![[modify_item valueForKey:@"value"]isEqualToString:@""])
  1881. //// [upparams setValue:[modify_item valueForKey:@"value"] forKey:[modify_item valueForKey:@"name"]];
  1882. //
  1883. // }
  1884. // }
  1885. return upparams;
  1886. }
  1887. else if([[itemjson valueForKey:@"control"] isEqualToString:@"img"])
  1888. {
  1889. NSString* avalue = [itemjson valueForKey:@"avalue"];
  1890. if(avalue.length==0)
  1891. avalue=@"";
  1892. [upparams setValue:avalue forKey:[itemjson valueForKey:@"name"]];
  1893. return upparams;
  1894. }
  1895. else if([[itemjson valueForKey:@"control"] isEqualToString:@"edit"])
  1896. {
  1897. // int min_length = [[itemjson valueForKey:@"min_length"] intValue];
  1898. // NSString* check_len_val =itemjson[@"value"];
  1899. NSString* valuestr= [itemjson valueForKey:@"value"];
  1900. if(valuestr.length==0)
  1901. valuestr=@"";
  1902. [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  1903. // {
  1904. // NSString *keyboard_type = [itemjson objectForKey:@"keyboard"];
  1905. // BOOL check_max = [itemjson objectForKey:@"max_type"] != nil ? YES : NO;
  1906. // BOOL check_min = [itemjson objectForKey:@"min_type"] != nil ? YES : NO;
  1907. // if ([keyboard_type isEqualToString:@"number"] && (check_max || check_min)) {
  1908. // // 检查最大值最小值
  1909. // int max_type = [[itemjson objectForKey:@"max_type"] intValue];
  1910. // int min_type = [[itemjson objectForKey:@"min_type"] intValue];
  1911. //
  1912. // float max_value = MAXFLOAT;
  1913. // float min_value = 0;
  1914. //
  1915. // NSString *mfield = nil;
  1916. // float f_value = [check_len_val floatValue];
  1917. //
  1918. // if (check_max) {
  1919. //
  1920. // if (max_type > 0) {
  1921. // // key
  1922. // NSString *max_key = [itemjson objectForKey:@"max"];
  1923. // id max_obj = [self downloadValueForKey:max_key];
  1924. // if (max_obj) {
  1925. // max_value = [max_obj floatValue];
  1926. // }
  1927. //
  1928. // } else {
  1929. // // value
  1930. // id max_obj = [itemjson objectForKey:@"max"];
  1931. // if (max_obj != nil) {
  1932. // max_value = [max_obj floatValue];
  1933. // }
  1934. //
  1935. // }
  1936. //
  1937. // if (max_value < f_value) {
  1938. // mfield =[NSString stringWithFormat:@"%ld. the value of %@ must be not larger than %.2f",fields.count+1,itemjson[@"aname"],max_value];
  1939. // }
  1940. // }
  1941. //
  1942. // if (check_min) {
  1943. //
  1944. // if (min_type > 0) {
  1945. // // key
  1946. // NSString *min_key = [itemjson objectForKey:@"min"];
  1947. // id min_obj = [self downloadValueForKey:min_key];
  1948. // if (min_obj) {
  1949. // min_value = [min_obj floatValue];
  1950. // }
  1951. // } else {
  1952. // // value
  1953. // id min_obj = [itemjson objectForKey:@"min"];
  1954. // if (min_obj != nil) {
  1955. // min_value = [min_obj floatValue];
  1956. // }
  1957. // }
  1958. //
  1959. // if (min_value > f_value) {
  1960. // mfield =[NSString stringWithFormat:@"%ld. the value of %@ must be not smaller than %.2f",fields.count+1,itemjson[@"aname"],min_value];
  1961. // }
  1962. // }
  1963. //
  1964. //
  1965. // if (check_min && check_max) {
  1966. // if (f_value < min_value || f_value > max_value) {
  1967. // mfield =[NSString stringWithFormat:@"%ld. the value of %@ must between %.2f and %.2f",fields.count+1,itemjson[@"aname"],min_value,max_value];
  1968. // }
  1969. // }
  1970. //
  1971. //
  1972. // [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  1973. //
  1974. //
  1975. // } else {
  1976. // [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  1977. // }
  1978. //
  1979. // }
  1980. return upparams;
  1981. }
  1982. else
  1983. {
  1984. NSString* value = [itemjson valueForKey:@"value"];
  1985. if(value.length==0)
  1986. value=@"";
  1987. [upparams setValue:value forKey:[itemjson valueForKey:@"name"]];
  1988. return upparams;
  1989. }
  1990. return upparams;
  1991. }
  1992. -(NSMutableDictionary*) convertScanOrder :(NSMutableDictionary*) dict
  1993. {
  1994. [[[UIApplication sharedApplication] keyWindow] endEditing:YES];
  1995. // [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder)];
  1996. [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];
  1997. // self.first_miss_pos = nil;
  1998. NSMutableDictionary* upparams=[[NSMutableDictionary alloc] init];
  1999. // [upparams setValue:[self.params valueForKey:@"cart2Checkbox"] forKey:@"cart2Checkbox"];
  2000. int section_count=(int)self.content_data_control.count;//[[self.content_data_download valueForKey:@"section_count"] intValue];
  2001. // NSString* aaa = [RAUtils dict2string:self.content_data_control];
  2002. for(int i=0;i<section_count;i++)
  2003. {
  2004. DebugLog(@"debug...section:%d",i);
  2005. NSDictionary * sectionjson = [self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] ;
  2006. int item_count = [sectionjson[@"count"] intValue];
  2007. for(int j=0;j<item_count;j++)
  2008. {
  2009. NSMutableDictionary * itemjson=[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]];
  2010. NSString* key = [itemjson valueForKey:@"name"];
  2011. if(key==nil || key.length==0)
  2012. continue;
  2013. NSMutableDictionary* convertitem=[self convertScanitem:itemjson];
  2014. [upparams addEntriesFromDictionary:convertitem];
  2015. // subitem_data * data=[self subitem_param:itemjson addto:upparams alert:alert];
  2016. // upparams= data.params;
  2017. // fields=[[fields arrayByAddingObjectsFromArray:data.missingfields] mutableCopy];
  2018. }
  2019. }
  2020. upparams[@"price_type"] = @(RASingleton.sharedInstance.price_type);
  2021. return upparams;
  2022. }
  2023. -(NSString*) scan_stock
  2024. {
  2025. NSMutableArray* ret=[NSMutableArray new];
  2026. NSDictionary* section=self.content_data_download[@"section_0"];
  2027. int count = [section[@"count"] intValue];
  2028. for(int i=0;i<count;i++)
  2029. {
  2030. NSDictionary* item = section[[NSString stringWithFormat:@"item_%d",i]];
  2031. NSDictionary* newitem =@{@"count":item[@"count"],@"model":item[@"model"]}; //@"product_id":item[@"product_id"],
  2032. [ret addObject:newitem];
  2033. }
  2034. return [RAConvertor dict2string:ret];
  2035. }
  2036. -(NSMutableArray*) scan_split_models:(NSMutableArray*) smodels
  2037. {
  2038. NSMutableDictionary* cart_section = RASingleton.sharedInstance.scan_cart[@"section_0"];
  2039. int cart_count = [cart_section[@"count"] intValue];
  2040. for(int i=0;i<smodels.count;i++)
  2041. {
  2042. for(int j=0;j<cart_count;j++)
  2043. {
  2044. NSMutableDictionary* cart_item = [cart_section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  2045. if([cart_item[@"model"] isEqualToString:smodels[i][@"model"] ])
  2046. {
  2047. NSMutableDictionary* newitem = [[NSMutableDictionary dictionaryWithDictionary:cart_item] mutableCopy];
  2048. [newitem addEntriesFromDictionary:smodels[i]];
  2049. newitem[@"cuft"]=@([newitem[@"count"] intValue] * [newitem[@"unit_cuft"] doubleValue]);
  2050. // NSString * mpack=newitem[@"stockUom"];
  2051. newitem[@"control"]=@"model";
  2052. newitem[@"description"]= [NSString stringWithFormat:@"%@\n%@\n%@",cart_item[@"model"],cart_item[@"description"],cart_item[@"dimension"] ];
  2053. newitem[@"subtotal_price"] = @([newitem[@"count"] intValue]* [newitem[@"unit_price"] doubleValue]*(1-[newitem[@"discount"] doubleValue]/100.0));
  2054. smodels[i]=newitem;
  2055. break;
  2056. }
  2057. }
  2058. }
  2059. return smodels;
  2060. // for(int j=0;j<cart_count;j++)
  2061. // {
  2062. // NSMutableDictionary* cart_item = [cart_section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  2063. // cart_item[@"description"]= [NSString stringWithFormat:@"%@\n%@\n%@",cart_item[@"model"],cart_item[@"description"],cart_item[@"dimension"] ];
  2064. // cart_item[@"control"]=@"model";
  2065. // section[[NSString stringWithFormat:@"item_%d",j]] = cart_item;
  2066. //
  2067. // }
  2068. // section[@"count"] = @(cart_count);
  2069. // dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  2070. }
  2071. -(void) scan_commit:(NSMutableDictionary *)upparams newmodel:(NSMutableDictionary *)newmodel{
  2072. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2073. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  2074. NSString *documents = [paths objectAtIndex:0];
  2075. NSString *orderdir = [OLDataProvider getScanPath];
  2076. NSDictionary* price_group=[RADataProvider get_price_group:appDelegate.price_group];
  2077. // NSString *ordercontrol = [orderdir stringByAppendingPathComponent:@"order_control.json"];
  2078. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  2079. NSMutableDictionary* saveorder = [[NSMutableDictionary dictionaryWithDictionary:self.content_data_download] mutableCopy];
  2080. if(newmodel)
  2081. saveorder[@"section_0"]=newmodel;
  2082. NSMutableDictionary* cart_section = [saveorder[@"section_0"] mutableCopy];
  2083. for(int ci=0;ci<[cart_section[@"count"] intValue];ci++ )
  2084. {
  2085. NSMutableDictionary* item = [cart_section[[NSString stringWithFormat:@"item_%d",ci]] mutableCopy];
  2086. if(RASingleton.sharedInstance.price_type==0)
  2087. {
  2088. item[@"pg_price_type"] =price_group[@"price_0"];
  2089. }
  2090. else if([item[@"net_price"] boolValue])
  2091. {
  2092. item[@"pg_price_type"] =price_group[@"price_3"];
  2093. }
  2094. else if([item[@"special_price"] boolValue])
  2095. {
  2096. item[@"pg_price_type"] =price_group[@"price_2"];
  2097. }
  2098. else
  2099. {
  2100. item[@"pg_price_type"] =price_group[@"price_1"];
  2101. }
  2102. cart_section[[NSString stringWithFormat:@"item_%d",ci]] = item;
  2103. }
  2104. saveorder[@"section_0"] = cart_section;
  2105. // [RAUtils dicttofile:ordercontrol dict:self.content_data_control];
  2106. [RAUtils dicttofile:orderPath dict:saveorder];
  2107. for(int os=0;os<[self.content_data_download[@"section_count"] intValue];os++)
  2108. {
  2109. NSDictionary* section = self.content_data_download[[NSString stringWithFormat:@"section_%d",os]];
  2110. for(int oi=0;oi<[section[@"count"] intValue];oi++)
  2111. {
  2112. NSDictionary* item = section [[NSString stringWithFormat:@"item_%d",oi]];
  2113. if([item[@"control"] isEqualToString:@"img"])
  2114. {
  2115. // 复制图片到打包目录
  2116. NSString* img_url_0=item[@"img_url_0"];
  2117. NSString* img_url_1=item[@"img_url_1"];
  2118. NSString* img_url_2=item[@"img_url_2"];
  2119. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
  2120. NSString *cachefolder = [paths objectAtIndex:0];
  2121. // NSString *offline_createimg = [cachefolder stringByAppendingPathComponent:@"offline_createimg"];
  2122. NSString *img_cache = [cachefolder stringByAppendingPathComponent:@"img_cache"];
  2123. NSFileManager* fileManager=[NSFileManager defaultManager];
  2124. if(img_url_0.length>0&&[fileManager fileExistsAtPath:[img_cache stringByAppendingPathComponent:img_url_0]])
  2125. {
  2126. NSError* err;
  2127. [fileManager copyItemAtURL:[NSURL fileURLWithPath:[img_cache stringByAppendingPathComponent:img_url_0]] toURL:[NSURL fileURLWithPath:[orderdir stringByAppendingPathComponent:img_url_0]] error:&err];
  2128. int i=0;
  2129. }
  2130. if(img_url_1.length>0&&[fileManager fileExistsAtPath:[img_cache stringByAppendingPathComponent:img_url_1]])
  2131. {
  2132. NSError* err;
  2133. [fileManager copyItemAtURL:[NSURL fileURLWithPath:[img_cache stringByAppendingPathComponent:img_url_1]] toURL:[NSURL fileURLWithPath:[orderdir stringByAppendingPathComponent:img_url_1]] error:&err];
  2134. }
  2135. if(img_url_2.length>0&&[fileManager fileExistsAtPath:[img_cache stringByAppendingPathComponent:img_url_2]])
  2136. {
  2137. NSError* err;
  2138. [fileManager copyItemAtURL:[NSURL fileURLWithPath:[img_cache stringByAppendingPathComponent:img_url_2]] toURL:[NSURL fileURLWithPath:[orderdir stringByAppendingPathComponent:img_url_2]] error:&err];
  2139. }
  2140. }
  2141. else if([item[@"control"] isEqualToString:@"signature"])
  2142. {
  2143. // 复制图片到打包目录
  2144. NSString* img_url_0=item[@"value"];
  2145. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
  2146. NSString *cachefolder = [paths objectAtIndex:0];
  2147. // NSString *offline_createimg = [cachefolder stringByAppendingPathComponent:@"offline_createimg"];
  2148. NSString *img_cache = [cachefolder stringByAppendingPathComponent:@"img_cache"];
  2149. NSFileManager* fileManager=[NSFileManager defaultManager];
  2150. if(img_url_0.length>0&&[fileManager fileExistsAtPath:[img_cache stringByAppendingPathComponent:img_url_0]])
  2151. {
  2152. NSError* err;
  2153. [fileManager copyItemAtURL:[NSURL fileURLWithPath:[img_cache stringByAppendingPathComponent:img_url_0]] toURL:[NSURL fileURLWithPath:[orderdir stringByAppendingPathComponent:img_url_0]] error:&err];
  2154. }
  2155. }
  2156. }
  2157. }
  2158. NSString * parampath= [orderdir stringByAppendingPathComponent:@"param.json"];
  2159. NSDictionary* param=[self convertScanOrder:self.content_data_download];
  2160. [RAUtils dicttofile:parampath dict:param];
  2161. NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  2162. if(appDelegate.customerInfo==nil)
  2163. appDelegate.customerInfo = [NSMutableDictionary new];
  2164. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  2165. NSString *cartpath = [orderdir stringByAppendingPathComponent:@"cart.json"];
  2166. RASingleton.sharedInstance.scan_cart[@"price_type"] = @(RASingleton.sharedInstance.price_type);
  2167. NSMutableDictionary* savecart = [[NSMutableDictionary dictionaryWithDictionary:RASingleton.sharedInstance.scan_cart] mutableCopy];
  2168. if(newmodel)
  2169. savecart[@"section_0"]=newmodel;
  2170. // NSMutableDictionary*
  2171. cart_section = [savecart[@"section_0"] mutableCopy];
  2172. for(int ci=0;ci<[cart_section[@"count"] intValue];ci++ )
  2173. {
  2174. NSMutableDictionary* item = [cart_section[[NSString stringWithFormat:@"item_%d",ci]] mutableCopy];
  2175. if(RASingleton.sharedInstance.price_type==0)
  2176. {
  2177. item[@"pg_price_type"] =price_group[@"price_0"];
  2178. }
  2179. else if([item[@"net_price"] boolValue])
  2180. {
  2181. item[@"pg_price_type"] =price_group[@"price_3"];
  2182. }
  2183. else if([item[@"special_price"] boolValue])
  2184. {
  2185. item[@"pg_price_type"] =price_group[@"price_2"];
  2186. }
  2187. else
  2188. {
  2189. item[@"pg_price_type"] =price_group[@"price_1"];
  2190. }
  2191. cart_section[[NSString stringWithFormat:@"item_%d",ci]] = item;
  2192. }
  2193. savecart[@"section_0"]=cart_section;
  2194. [RAUtils dicttofile:cartpath dict:savecart];
  2195. NSString * zippath= [orderdir stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.zip",appDelegate.order_code]];
  2196. // NSError *error=nil;
  2197. //
  2198. // [str writeToFile:jsonpath atomically:true encoding:NSUTF8StringEncoding error:&error];
  2199. NSArray* arr_files=[RAUtils allFilesAtPath:orderdir];
  2200. ZipArchive* zip = [[ZipArchive alloc] init];
  2201. // if ([[NSFileManager defaultManager] fileExistsAtPath:zippath]) {
  2202. //
  2203. //
  2204. // [[NSFileManager defaultManager] removeItemAtPath:zippath error:nil];
  2205. //
  2206. //
  2207. // }
  2208. BOOL r = [zip CreateZipFile2:zippath Password:@"usai2010"];
  2209. for(int i=0;i<arr_files.count;i++)
  2210. {
  2211. NSString* file=arr_files[i];
  2212. r = [zip addFileToZip:file newname:[file lastPathComponent]];
  2213. }
  2214. NSString * filepath=[[RADataProvider getSiteName] stringByAppendingPathComponent:appDelegate.user];
  2215. filepath=[filepath stringByAppendingPathComponent:appDelegate.order_code];
  2216. filepath=[filepath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.zip",appDelegate.order_code]];
  2217. if( ![zip CloseZipFile2] )
  2218. {
  2219. zippath = @"";
  2220. filepath =@"";
  2221. }
  2222. NSString *md5 = [RAUtils md5WithFile:zippath];
  2223. {
  2224. //括号内为单个文件上传
  2225. NSString *fileName = [zippath lastPathComponent];
  2226. NSData * file_data= [NSData dataWithContentsOfFile:zippath];
  2227. NSString* realuser;
  2228. NSString* realpassword;
  2229. if(self.realuser.length>0)
  2230. {
  2231. realuser = self.realuser;
  2232. realpassword = self.realpassword;
  2233. }
  2234. else
  2235. {
  2236. realuser = appDelegate.user;
  2237. realpassword = appDelegate.password;
  2238. }
  2239. NSDictionary* params = @{
  2240. // @"site_name":[RADataProvider getSiteName],
  2241. @"user":realuser,
  2242. @"_method":@"uploadOfflineOrder",
  2243. @"password" : realpassword,
  2244. @"md5":md5
  2245. };
  2246. // self.btnSubmitOrder.enabled = false;
  2247. // NSLog(@"disable submit button");
  2248. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Order Submission" completion:^{
  2249. PopWaitAlert* pop = [RAUtils waiting_pop:@"Order Submission" completion:nil];
  2250. [RANetwork request_fastupload:[params mutableCopy] filename:fileName data:file_data url:appDelegate.uploadurl completionHandler:^(NSMutableDictionary *result) {
  2251. // [waitalert dismissViewControllerAnimated:false completion:^{
  2252. [pop hide];
  2253. int iresult = [result[@"result"] intValue];
  2254. if(iresult == RESULT_TRUE)
  2255. {
  2256. NSString* soid = result[@"so_id"];
  2257. if(soid.length==0)
  2258. soid=@"N/A";
  2259. // upparams[@"soid"]=soid;
  2260. // NSMutableDictionary* saveorder = [[NSMutableDictionary dictionaryWithDictionary:self.content_data_download] mutableCopy];
  2261. if(newmodel)
  2262. { self.content_data_download[@"section_0"]=newmodel;
  2263. }
  2264. self.content_data_download[@"readonly"]=@1;
  2265. [self scanSave:upparams];
  2266. NSString* company = upparams[@"customer_cid"];
  2267. if(company.length==0)
  2268. company = upparams[@"customer_name"];
  2269. [OLDataProvider save2submitScanOrder:soid company:company];
  2270. // [OLDataProvider scanCloseOrder];
  2271. [appDelegate closeOrder];
  2272. RASingleton.sharedInstance.scan_cart = nil;
  2273. #ifdef RA_NOTIFICATION
  2274. [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2275. #else
  2276. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  2277. [main_vc reloadCart:true immediately:false];
  2278. #endif
  2279. //
  2280. [self prepareReturn:nil];
  2281. [self.navigationController popViewControllerAnimated:true];
  2282. [((MainViewController*)appDelegate.main_vc) switchToOrder];
  2283. // NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
  2284. // ret[@"result"]=@2;
  2285. // ret[@"file"]=zippath;
  2286. // result(ret);
  2287. return;
  2288. }
  2289. else if(iresult==1)
  2290. {
  2291. self.fail_submit = true;
  2292. self.realuser = nil;
  2293. self.realpassword = nil;
  2294. [RAUtils message_box:@"Submit Order" message:@"Can not submit the order, wrong password" completion:nil];
  2295. if ([[NSFileManager defaultManager] fileExistsAtPath:zippath]) {
  2296. [[NSFileManager defaultManager] removeItemAtPath:zippath error:nil];
  2297. // [orderlist addObject:appDelegate.order_code];
  2298. // [RAUtils dicttofile:orderlistPath dict:orderlist];
  2299. }
  2300. }
  2301. else if([result[@"result"] intValue]==-4||[result[@"result"] intValue]==-3)
  2302. {
  2303. self.fail_submit = true;
  2304. self.realuser = nil;
  2305. self.realpassword = nil;
  2306. [RAUtils message_box:@"Submit Order" message:@"Order submission failed. Please check your internet and try later." completion:nil];
  2307. // if ([[NSFileManager defaultManager] fileExistsAtPath:zippath]) {
  2308. //
  2309. //
  2310. // [[NSFileManager defaultManager] removeItemAtPath:zippath error:nil];
  2311. //
  2312. // // [orderlist addObject:appDelegate.order_code];
  2313. // // [RAUtils dicttofile:orderlistPath dict:orderlist];
  2314. //
  2315. // }
  2316. return;
  2317. }
  2318. else if(iresult==9)
  2319. {
  2320. self.fail_submit = true;
  2321. self.realuser = nil;
  2322. self.realpassword = nil;
  2323. [RAUtils message_box:@"Submit Order" message:result[@"err_msg"] completion:nil];
  2324. }
  2325. else
  2326. {
  2327. self.fail_submit = true;
  2328. self.realuser = nil;
  2329. self.realpassword = nil;
  2330. [RAUtils message_box:@"Submit Order" message:@"Can not submit order, please contact administrator." completion:nil];
  2331. }
  2332. // }];
  2333. // self.btnSubmitOrder.enabled = true;
  2334. // NSLog(@"enable submit button");
  2335. }];
  2336. // }];
  2337. }
  2338. return;
  2339. }
  2340. #endif
  2341. - (void)empolyee_commit_order:(NSMutableDictionary *)upparams {
  2342. #ifdef SCANNER_ORDER
  2343. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2344. NSString* realuser;
  2345. NSString* realpassword;
  2346. if(self.realuser.length>0)
  2347. {
  2348. realuser = self.realuser;
  2349. realpassword = self.realpassword;
  2350. }
  2351. else
  2352. {
  2353. realuser = appDelegate.user;
  2354. realpassword = appDelegate.password;
  2355. }
  2356. if((appDelegate.user_type==USER_ROLE_CUSTOMER && [upparams[@"customer_cid"] stringValue].length>0) || [upparams[@"customer_cid"] stringValue].length>0 ||[appDelegate.user.uppercaseString isEqualToString:@"GUEST"])
  2357. {
  2358. NSMutableDictionary* param = [NSMutableDictionary new];
  2359. NSString* model = [self scan_stock];
  2360. param[@"models"]=model;
  2361. param[@"customer_cid"]=upparams[@"customer_cid"];
  2362. param[@"user"]=realuser;
  2363. param[@"password"]=realpassword;
  2364. [RADataProvider request_scan_stock:param completionHandler:^(NSMutableDictionary *result) {
  2365. if([result[@"result"] intValue]==2)
  2366. {
  2367. NSMutableArray* models = [result[@"models"] mutableCopy];
  2368. if(models.count==0)
  2369. {
  2370. //不可拆分,直接提交
  2371. [self scan_commit:upparams newmodel:nil];
  2372. }
  2373. else
  2374. {
  2375. StockViewController * vc =[[UIStoryboard storyboardWithName:@"SO" bundle:nil] instantiateViewControllerWithIdentifier:@"StockViewController"];
  2376. //
  2377. // 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];
  2378. NSMutableArray* testmodels =[[RAConvertor string2dict:@"[{\"model\":\"1420-1*\",\"count\":1,\"is_back_order\":false,\"etd\":\"2022-06-23\"}]"] mutableCopy];
  2379. // models = testmodels;
  2380. models = [self scan_split_models:models];
  2381. vc.data =models;
  2382. vc.returnValue = ^(NSMutableDictionary * _Nonnull models) {
  2383. // model
  2384. // int i=0;
  2385. // RASingleton.sharedInstance.scan_cart[@"section_0"]=models;
  2386. // self.content_data_download[@"section_0"]=models;
  2387. [self scan_commit:upparams newmodel:models];
  2388. return;
  2389. };
  2390. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  2391. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  2392. // navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  2393. [self presentViewController:navi animated:YES completion:^{
  2394. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  2395. DebugLog(@"StockViewController present.........");
  2396. // self.btop = false;
  2397. // <#code#>
  2398. }];
  2399. }
  2400. }
  2401. else if([result[@"result"] intValue]==1)
  2402. {
  2403. self.fail_submit = true;
  2404. self.realuser = nil;
  2405. self.realpassword = nil;
  2406. [RAUtils message_box:@"Submit Order" message:@"Can not submit the order, wrong password" completion:nil];
  2407. // if ([[NSFileManager defaultManager] fileExistsAtPath:zippath]) {
  2408. //
  2409. //
  2410. // [[NSFileManager defaultManager] removeItemAtPath:zippath error:nil];
  2411. //
  2412. // // [orderlist addObject:appDelegate.order_code];
  2413. // // [RAUtils dicttofile:orderlistPath dict:orderlist];
  2414. //
  2415. // }
  2416. return;
  2417. }
  2418. else if([result[@"result"] intValue]==-4||[result[@"result"] intValue]==-3)
  2419. {
  2420. self.fail_submit = true;
  2421. self.realuser = nil;
  2422. self.realpassword = nil;
  2423. [RAUtils message_box:@"Submit Order" message:@"Order submission failed. Please check your internet and try later." completion:nil];
  2424. // if ([[NSFileManager defaultManager] fileExistsAtPath:zippath]) {
  2425. //
  2426. //
  2427. // [[NSFileManager defaultManager] removeItemAtPath:zippath error:nil];
  2428. //
  2429. // // [orderlist addObject:appDelegate.order_code];
  2430. // // [RAUtils dicttofile:orderlistPath dict:orderlist];
  2431. //
  2432. // }
  2433. return;
  2434. }
  2435. else
  2436. {
  2437. self.fail_submit = true;
  2438. self.realuser = nil;
  2439. self.realpassword = nil;
  2440. [RAUtils message_box:@"Submit Order" message:@"Can not submit order, please contact administrator." completion:nil];
  2441. }
  2442. }];
  2443. }
  2444. else
  2445. {
  2446. //无contact 直接提交
  2447. [self scan_commit:upparams newmodel:nil];
  2448. }
  2449. return;
  2450. #endif
  2451. [upparams setValue:@"false" forKey:@"isHold"];
  2452. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Order Submission" completion:^{
  2453. PopWaitAlert* pop = [RAUtils waiting_pop:@"Order Submission" completion:nil];
  2454. [RANetwork request_commit_order:upparams completionHandler:^(NSMutableDictionary *result) {
  2455. NSDictionary* editor_json = result;
  2456. // [waitalert dismissViewControllerAnimated:YES completion:^{
  2457. [pop hide];
  2458. if([[editor_json valueForKey:@"result"] intValue]==2)
  2459. {
  2460. // debug aaa
  2461. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2462. NSString* company= appDelegate.customerInfo[@"customer_name"];
  2463. NSString* send_to =appDelegate.customerInfo[@"customer_email"];
  2464. [appDelegate closeOrder];
  2465. #ifdef RA_NOTIFICATION
  2466. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2467. #else
  2468. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2469. #endif
  2470. __block NSString* title=nil;
  2471. __block NSString* msg=nil;
  2472. #ifdef OFFLINE_MODE
  2473. if(appDelegate.offline_mode)
  2474. {
  2475. title=TITLE_OFFLINE_SUBMIT;
  2476. msg=MSG_OFFLINE_SUBMIT;
  2477. }
  2478. else
  2479. #endif
  2480. {
  2481. title=@"Order submitted sucessfully";
  2482. msg=[NSString stringWithFormat:@"Confirmation#: %@",[editor_json valueForKey:@"so#"]];
  2483. }
  2484. NSString* pdf_url = [editor_json valueForKey:@"pdf_url"];
  2485. NSString* email_content =[editor_json valueForKey:@"email_content"];
  2486. NSString* soid=[editor_json valueForKey:@"so#"];
  2487. NSMutableDictionary *value = [NSMutableDictionary dictionary];
  2488. if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  2489. {
  2490. //bbb
  2491. [((MainViewController*)appDelegate.main_vc) Loginout:false];
  2492. value[@"commitorder_logout"]=@"true";
  2493. }
  2494. [self prepareReturn:value];
  2495. __block UIViewController* message_parent = self.navigationController.topViewController;
  2496. [self.navigationController popToRootViewControllerAnimated:true];
  2497. if(pdf_url.length>0)
  2498. {
  2499. [appDelegate printPdf:pdf_url company:company send_to:send_to soid:soid content:email_content];
  2500. // [appDelegate printPdf:pdf_url];
  2501. // }];
  2502. }
  2503. else
  2504. dispatch_async(dispatch_get_main_queue(), ^{
  2505. [RAUtils message_box:title message:msg completion:nil];
  2506. });
  2507. }
  2508. else
  2509. {
  2510. [RAUtils message_box:@"Order Submission" message:[editor_json valueForKey:@"err_msg"] completion:nil];
  2511. }
  2512. // }];
  2513. }];
  2514. // }];
  2515. }
  2516. @end