CreateOrderViewController.m 136 KB

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