CreateOrderViewController.m 156 KB

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