CreateOrderViewController.m 136 KB

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