CreateOrderViewController.m 132 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370
  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. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  2386. NSString *cartpath = [orderdir stringByAppendingPathComponent:@"cart.json"];
  2387. RASingleton.sharedInstance.scan_cart[@"price_type"] = @(RASingleton.sharedInstance.price_type);
  2388. [RAUtils dicttofile:cartpath dict:RASingleton.sharedInstance.scan_cart];
  2389. NSString * zippath= [orderdir stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.zip",appDelegate.order_code]];
  2390. // NSError *error=nil;
  2391. //
  2392. // [str writeToFile:jsonpath atomically:true encoding:NSUTF8StringEncoding error:&error];
  2393. NSArray* arr_files=[RAUtils allFilesAtPath:orderdir];
  2394. ZipArchive* zip = [[ZipArchive alloc] init];
  2395. // if ([[NSFileManager defaultManager] fileExistsAtPath:zippath]) {
  2396. //
  2397. //
  2398. // [[NSFileManager defaultManager] removeItemAtPath:zippath error:nil];
  2399. //
  2400. //
  2401. // }
  2402. BOOL r = [zip CreateZipFile2:zippath Password:@"usai2010"];
  2403. for(int i=0;i<arr_files.count;i++)
  2404. {
  2405. NSString* file=arr_files[i];
  2406. r = [zip addFileToZip:file newname:[file lastPathComponent]];
  2407. }
  2408. NSString * filepath=[[RADataProvider getSiteName] stringByAppendingPathComponent:appDelegate.user];
  2409. filepath=[filepath stringByAppendingPathComponent:appDelegate.order_code];
  2410. filepath=[filepath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.zip",appDelegate.order_code]];
  2411. if( ![zip CloseZipFile2] )
  2412. {
  2413. zippath = @"";
  2414. filepath =@"";
  2415. }
  2416. NSString *md5 = [RAUtils md5WithFile:zippath];
  2417. {
  2418. //括号内为单个文件上传
  2419. NSString *fileName = [zippath lastPathComponent];
  2420. NSData * file_data= [NSData dataWithContentsOfFile:zippath];
  2421. NSString* realuser;
  2422. NSString* realpassword;
  2423. if(self.realuser.length>0)
  2424. {
  2425. realuser = self.realuser;
  2426. realpassword = self.realpassword;
  2427. }
  2428. else
  2429. {
  2430. realuser = appDelegate.user;
  2431. realpassword = appDelegate.password;
  2432. }
  2433. NSDictionary* params = @{
  2434. // @"site_name":[RADataProvider getSiteName],
  2435. @"user":realuser,
  2436. @"_method":@"uploadOfflineOrder",
  2437. @"password" : realpassword,
  2438. @"md5":md5
  2439. };
  2440. [RANetwork request_fastupload:[params mutableCopy] filename:fileName data:file_data url:appDelegate.uploadurl completionHandler:^(NSMutableDictionary *result) {
  2441. int iresult = [result[@"result"] intValue];
  2442. if(iresult == RESULT_TRUE)
  2443. {
  2444. [self scanSave:upparams];
  2445. [OLDataProvider save2submitScanOrder];
  2446. [appDelegate closeOrder];
  2447. RASingleton.sharedInstance.scan_cart = nil;
  2448. #ifdef RA_NOTIFICATION
  2449. [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2450. #else
  2451. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  2452. [main_vc reloadCart:true immediately:false];
  2453. #endif
  2454. //
  2455. [self prepareReturn:nil];
  2456. [self.navigationController popViewControllerAnimated:true];
  2457. [((MainViewController*)appDelegate.main_vc) switchToOrder];
  2458. // NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
  2459. // ret[@"result"]=@2;
  2460. // ret[@"file"]=zippath;
  2461. // result(ret);
  2462. return;
  2463. }
  2464. else if(iresult==1)
  2465. {
  2466. self.fail_submit = true;
  2467. self.realuser = nil;
  2468. self.realpassword = nil;
  2469. [RAUtils message_alert:@"Can not submit the order, wrong password" title:@"Submit Order" controller:self];
  2470. }
  2471. else
  2472. {
  2473. self.fail_submit = true;
  2474. [RAUtils message_alert:@"Can not submit the order, please check your network" title:@"Submit Order" controller:self];
  2475. }
  2476. }];
  2477. }
  2478. // [self addTasks:filepath md5:md5];
  2479. //
  2480. // [OLDataProvider save2submitScanOrder];
  2481. //
  2482. // [appDelegate closeOrder];
  2483. // RASingleton.sharedInstance.scan_cart = nil;
  2484. //
  2485. // #ifdef RA_NOTIFICATION
  2486. // [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2487. // #else
  2488. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  2489. // [main_vc reloadCart:true immediately:false];
  2490. // #endif
  2491. //
  2492. ////
  2493. //
  2494. //
  2495. // [self prepareReturn:nil];
  2496. //
  2497. //
  2498. //
  2499. // [self.navigationController popViewControllerAnimated:true];
  2500. // [((MainViewController*)appDelegate.main_vc) switchToOrder];
  2501. //// NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
  2502. //// ret[@"result"]=@2;
  2503. //// ret[@"file"]=zippath;
  2504. //// result(ret);
  2505. return;
  2506. }
  2507. #endif
  2508. [upparams setValue:@"false" forKey:@"isHold"];
  2509. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Order Submission" completion:^{
  2510. [RANetwork request_commit_order:upparams completionHandler:^(NSMutableDictionary *result) {
  2511. NSDictionary* editor_json = result;
  2512. [waitalert dismissViewControllerAnimated:YES completion:^{
  2513. if([[editor_json valueForKey:@"result"] intValue]==2)
  2514. {
  2515. // debug aaa
  2516. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2517. NSString* company= appDelegate.customerInfo[@"customer_name"];
  2518. NSString* send_to =appDelegate.customerInfo[@"customer_email"];
  2519. [appDelegate closeOrder];
  2520. #ifdef RA_NOTIFICATION
  2521. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2522. #else
  2523. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2524. #endif
  2525. __block NSString* title=nil;
  2526. __block NSString* msg=nil;
  2527. #ifdef OFFLINE_MODE
  2528. if(appDelegate.offline_mode)
  2529. {
  2530. title=TITLE_OFFLINE_SUBMIT;
  2531. msg=MSG_OFFLINE_SUBMIT;
  2532. }
  2533. else
  2534. #endif
  2535. {
  2536. title=@"Order submitted sucessfully";
  2537. msg=[NSString stringWithFormat:@"Confirmation#: %@",[editor_json valueForKey:@"so#"]];
  2538. }
  2539. NSString* pdf_url = [editor_json valueForKey:@"pdf_url"];
  2540. NSString* email_content =[editor_json valueForKey:@"email_content"];
  2541. NSString* soid=[editor_json valueForKey:@"so#"];
  2542. NSMutableDictionary *value = [NSMutableDictionary dictionary];
  2543. if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  2544. {
  2545. //bbb
  2546. [((MainViewController*)appDelegate.main_vc) Loginout:false];
  2547. value[@"commitorder_logout"]=@"true";
  2548. }
  2549. [self prepareReturn:value];
  2550. __block UIViewController* message_parent = self.navigationController.topViewController;
  2551. [self.navigationController popToRootViewControllerAnimated:true];
  2552. if(pdf_url.length>0)
  2553. {
  2554. // [message_alert dismissViewControllerAnimated:YES completion:^{
  2555. // [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  2556. // [self.navigationController popToRootViewControllerAnimated:true];
  2557. [appDelegate printPdf:pdf_url company:company send_to:send_to soid:soid content:email_content];
  2558. // [appDelegate printPdf:pdf_url];
  2559. // }];
  2560. }
  2561. else
  2562. dispatch_async(dispatch_get_main_queue(), ^{
  2563. // UIAlertController* message_alert=
  2564. [RAUtils message_alert:msg title:title controller:message_parent];
  2565. });
  2566. // __block UIAlertController* message_alert=[RAUtils message_alert:msg title:title controller:self.parentViewController action_handler:^(UIAlertAction * _Nonnull action) {
  2567. //
  2568. //
  2569. //
  2570. //
  2571. //// [self.navigationController popToRootViewControllerAnimated:true];
  2572. //
  2573. //
  2574. // } completion:^{
  2575. //
  2576. // }];
  2577. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  2578. //
  2579. // [alert show];
  2580. //
  2581. }
  2582. else
  2583. {
  2584. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
  2585. }
  2586. }];
  2587. }];
  2588. }];
  2589. }
  2590. @end