CreateOrderViewController.m 134 KB

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