CreateOrderViewController.m 159 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057
  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. NSString* company = upparams[@"customer_cid"];
  1067. if(company.length==0)
  1068. company = upparams[@"customer_name"];
  1069. orderitem[@"customer_name"] = company;
  1070. orderitem[@"purchase_time"] = [RAUtils current_date_time];
  1071. if(self.fail_submit)
  1072. orderitem[@"order_status"] = @"Unsubmitted Order";
  1073. else
  1074. orderitem[@"order_status"] = @"Saved Order";
  1075. orderitem[@"order_code"] = appDelegate.order_code;
  1076. NSMutableDictionary* section =RASingleton.sharedInstance.scan_cart[@"section_0"];
  1077. int order_qty=0;
  1078. for(int c=0;c<[section[@"count"] intValue];c++)
  1079. {
  1080. NSDictionary* item = section[[NSString stringWithFormat:@"item_%d",c]];
  1081. order_qty+=[item[@"count"] intValue];
  1082. }
  1083. orderitem[@"model_count"] =[ NSString stringWithFormat:@"%d",order_qty];//RASingleton.sharedInstance.scan_cart[@"section_0"][@"count"] ];
  1084. int count = [orderlist[@"count"] intValue];
  1085. NSMutableDictionary* newlist = [NSMutableDictionary new];
  1086. newlist[@"item_0"]=orderitem;
  1087. int newcount = 1;
  1088. for(int i=0;i<count;i++)
  1089. {
  1090. NSMutableDictionary* item = orderlist[[NSString stringWithFormat:@"item_%d",i]];
  1091. if([item[@"order_code"] isEqualToString: appDelegate.order_code ])
  1092. continue;
  1093. else
  1094. {
  1095. newlist[[NSString stringWithFormat:@"item_%d",newcount]] = item;
  1096. newcount++;
  1097. }
  1098. }
  1099. newlist[@"count"] = @(newcount);
  1100. [RAUtils dicttofile:orderlistPath dict:newlist];
  1101. #ifdef RA_NOTIFICATION
  1102. [ActiveViewController Notify:@"CartViewController,ScanOrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1103. #else
  1104. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1105. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  1106. #endif
  1107. }
  1108. #endif
  1109. -(void) newScanOrder
  1110. {
  1111. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1112. // if(appDelegate.user.length<=0)
  1113. // {
  1114. // [RAUtils message_alert:@"Please login first." title:@"Warring" controller:self];
  1115. // return;
  1116. // }
  1117. if(appDelegate.order_code.length>0)
  1118. {
  1119. // 当前订单先关闭
  1120. // [OLDataProvider deleteScanOrder:appDelegate.order_code];
  1121. appDelegate.order_code = nil;
  1122. RASingleton.sharedInstance.scan_temp_code = nil;
  1123. if(appDelegate.customer_type!=USER_ROLE_CUSTOMER ) //customer 角色不清空customer info
  1124. { appDelegate.customerInfo = nil;
  1125. appDelegate.contact_id = nil;
  1126. }
  1127. RASingleton.sharedInstance.scan_cart = nil;
  1128. RASingleton.sharedInstance.price_type = 1;
  1129. // [appDelegate updateScanButton:false];
  1130. [appDelegate update_count_mark];
  1131. [appDelegate closeOrder];
  1132. }
  1133. // RASingleton.sharedInstance.enable_OfflineOrder = true;
  1134. // __block MainViewController *brself= self;
  1135. NSString* order_code = RASingleton.sharedInstance.scan_temp_code;
  1136. appDelegate.can_set_cart_price = true;
  1137. appDelegate.can_see_price = true;
  1138. RASingleton.sharedInstance.scan_cart = nil;
  1139. RASingleton.sharedInstance.price_type = 1;
  1140. {
  1141. NSString *orderdir = [OLDataProvider getScanPath];
  1142. [OLDataProvider moveScanTemp2Order];
  1143. NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  1144. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  1145. }
  1146. #ifdef RA_NOTIFICATION
  1147. [ActiveViewController Notify:@"CartViewController,ScanOrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1148. #else
  1149. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  1150. [main_vc reloadCart:true immediately:false];
  1151. #endif
  1152. MainViewController * mainvc = (MainViewController*)appDelegate.main_vc;
  1153. [mainvc switchToCart];
  1154. }
  1155. - (IBAction)onSaveClick:(id)sender {
  1156. // id foo = nil;
  1157. // [[NSMutableArray array] addObject:foo];
  1158. // add params check here.
  1159. [self.lastedit endEditing:true];
  1160. [self.lasttextview endEditing:true];
  1161. NSMutableDictionary* upparams = [self check_cancommit:false];
  1162. // if(self.cancommit==false)
  1163. // return;
  1164. if([upparams[@"shipping"] isEqualToString:@"Shipping To Be Quoted"]||[upparams[@"shipping"] isEqualToString:@"To Be Quoted"])
  1165. upparams[@"shipping"] = nil;
  1166. #ifdef SCANNER_ORDER
  1167. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  1168. {
  1169. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  1170. // NSString *documents = [paths objectAtIndex:0];
  1171. [self scanSave:upparams];
  1172. [RAUtils message_alert:@"Save Successfully" title:@"Message" controller:self action_handler:^(UIAlertAction * _Nonnull action) {
  1173. [self newScanOrder];
  1174. [self.navigationController popViewControllerAnimated:true];
  1175. } completion:nil];
  1176. return;
  1177. }
  1178. #endif
  1179. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Saving Order" completion:^{
  1180. [RANetwork request_save_order:upparams completionHandler:^(NSMutableDictionary *result) {
  1181. NSDictionary* editor_json =result;
  1182. [waitalert dismissViewControllerAnimated:YES completion:^{
  1183. if([[editor_json valueForKey:@"result"] intValue]==2)
  1184. {
  1185. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1186. NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  1187. if(appDelegate.user_type ==USER_ROLE_EMPLOYEE)
  1188. {
  1189. appDelegate.customerInfo = customerInfo;
  1190. appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  1191. }
  1192. NSString *msg = nil;
  1193. if ([editor_json objectForKey:@"so#"]) {
  1194. msg = [@"SO#:" stringByAppendingString:[editor_json objectForKey:@"so#"]];
  1195. }
  1196. [RAUtils message_alert:msg title:@"Order Saved" controller:self] ;
  1197. if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.save_order_logout && appDelegate.user_type ==USER_ROLE_EMPLOYEE)
  1198. {
  1199. [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1200. [self prepareReturn:nil];
  1201. [self.navigationController popViewControllerAnimated:true];
  1202. }
  1203. else{
  1204. #ifdef RA_NOTIFICATION
  1205. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1206. #else
  1207. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1208. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1209. #endif
  1210. }
  1211. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  1212. if (![RASingleton sharedInstance].currentOrderIsMerged) {
  1213. [self releaseOrderAfterSave];
  1214. }
  1215. }
  1216. // if ([[upparams valueForKey:@"close_on_save"] boolValue]) {
  1217. // appDelegate.order_code = nil;
  1218. //
  1219. // }
  1220. // // self.labelContact.text=appDelegate.contact_name;
  1221. //
  1222. // NSDictionary * customerinfo = appDelegate.customerInfo;
  1223. // [self prepareReturn:nil];
  1224. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  1225. //
  1226. //
  1227. // ;
  1228. // }];
  1229. }
  1230. else
  1231. {
  1232. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Save Order" controller:self] ;
  1233. }
  1234. }];
  1235. }];
  1236. }];
  1237. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1238. //
  1239. // NSDictionary* editor_json = [RANetwork save_Order:upparams];
  1240. //
  1241. // dispatch_async(dispatch_get_main_queue(), ^{
  1242. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  1243. //
  1244. //
  1245. // if([[editor_json valueForKey:@"result"] intValue]==2)
  1246. // {
  1247. //
  1248. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1249. //
  1250. //
  1251. //
  1252. // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  1253. //
  1254. //
  1255. // if(appDelegate.user_type ==USER_ROLE_EMPLOYEE)
  1256. // {
  1257. // appDelegate.customerInfo = customerInfo;
  1258. // appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  1259. // }
  1260. // NSString *msg = nil;
  1261. // if ([editor_json objectForKey:@"so#"]) {
  1262. // msg = [@"SO#:" stringByAppendingString:[editor_json objectForKey:@"so#"]];
  1263. // }
  1264. // [RAUtils message_alert:msg title:@"Order Saved" controller:self] ;
  1265. //
  1266. // if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.save_order_logout && appDelegate.user_type ==USER_ROLE_EMPLOYEE)
  1267. // {
  1268. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1269. // [self prepareReturn:nil];
  1270. // [self.navigationController popViewControllerAnimated:true];
  1271. // }
  1272. // else{
  1273. //
  1274. //
  1275. //#ifdef RA_NOTIFICATION
  1276. // [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1277. //#else
  1278. //
  1279. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1280. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1281. //#endif
  1282. // }
  1283. //
  1284. // if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  1285. //
  1286. // if (![Singleton sharedInstance].currentOrderIsMerged) {
  1287. // [self releaseOrderAfterSave];
  1288. // }
  1289. //
  1290. //
  1291. // }
  1292. //
  1293. //
  1294. // // if ([[upparams valueForKey:@"close_on_save"] boolValue]) {
  1295. // // appDelegate.order_code = nil;
  1296. // //
  1297. // // }
  1298. // // // self.labelContact.text=appDelegate.contact_name;
  1299. // //
  1300. // // NSDictionary * customerinfo = appDelegate.customerInfo;
  1301. // // [self prepareReturn:nil];
  1302. // // [self.navigationController dismissViewControllerAnimated:true completion:^{
  1303. // //
  1304. // //
  1305. // // ;
  1306. // // }];
  1307. //
  1308. // }
  1309. // else
  1310. // {
  1311. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Save Order" controller:self] ;
  1312. // }
  1313. //
  1314. //
  1315. //
  1316. //
  1317. // });
  1318. // });
  1319. }
  1320. - (void)textFieldDidEndEditing:(UITextField *)textField
  1321. {
  1322. [super textFieldDidEndEditing:textField];
  1323. UITableViewCell *cell = (UITableViewCell *) textField.superview.superview;
  1324. NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
  1325. NSMutableDictionary* section_json=nil;
  1326. // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row);
  1327. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  1328. NSString* name = [item_json valueForKey:@"name"];
  1329. if([name isEqualToString:@"shipping"]|| [name isEqualToString:@"handling_fee_value"]||[name isEqualToString:@"lift_gate_value"]||[name isEqualToString:@"tax_percentage"])
  1330. {
  1331. float shipping = [self getprice:@"shipping" section:indexPath.section];
  1332. float paymentsAndCredits = [self getprice:@"paymentsAndCredits" section:indexPath.section];
  1333. float handling_fee_value = [self getprice:@"handling_fee_value" section:indexPath.section];
  1334. float lift_gate =[self getprice:@"lift_gate_value" section:indexPath.section];
  1335. float tax = [self getprice:@"tax_percentage" section:indexPath.section]/100.0*paymentsAndCredits;
  1336. float totalprice=shipping+paymentsAndCredits+handling_fee_value+lift_gate+tax;
  1337. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  1338. int count=0;
  1339. count=[[section_json valueForKey:@"count"] intValue];
  1340. int total_row_idx=-1;
  1341. for(int i=0;i<count;i++)
  1342. {
  1343. NSDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]] mutableCopy];
  1344. if([[olditem valueForKey:@"name"] isEqualToString:@"totalPrice" ])
  1345. {
  1346. [olditem setValue:[NSString stringWithFormat:@"%.2f",totalprice] forKey:@"value"];
  1347. [olditem setValue:@"true" forKey:@"dirty"];
  1348. [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",i ]];
  1349. total_row_idx=i;
  1350. }
  1351. }
  1352. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  1353. self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data];
  1354. if(total_row_idx>=0)
  1355. {
  1356. NSUInteger newIndex[] = {indexPath.section, total_row_idx};
  1357. NSIndexPath *newPath = [[NSIndexPath alloc] initWithIndexes:newIndex length:2];
  1358. // DebugLog(@"before refresh %@",NSStringFromCGSize(self.editorTable.contentSize));
  1359. [self.editorTable reloadRowsAtIndexPaths:@[newPath]withRowAnimation:UITableViewRowAnimationMiddle];
  1360. // DebugLog(@"after refresh %@",NSStringFromCGSize(self.editorTable.contentSize));
  1361. // CGSize tablecontent =self.editorTable.contentSize;
  1362. // tablecontent.height=tablecontent.height+self.keyboard_h;
  1363. // self.editorTable.contentSize=tablecontent;
  1364. //
  1365. //
  1366. // DebugLog(@"resize to %@",NSStringFromCGSize(self.editorTable.contentSize));
  1367. }
  1368. // self.content_data = [editor_json mutableCopy];
  1369. // self.content_data = [self translate_json:editor_json];
  1370. // NSMutableDictionary* content_data1 = [self translate_json:self.content_data];
  1371. // [self.editorTable reloadData];
  1372. }
  1373. //
  1374. // [item_json setValue:@"true" forKey:@"dirty"];
  1375. // [item_json setValue:textField.text forKey:@"value"];
  1376. }
  1377. -(float) getprice:(NSString*) name section :(long) index
  1378. {
  1379. NSMutableDictionary* section_json=nil;
  1380. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",index ]] mutableCopy];
  1381. int count=0;
  1382. count=[[section_json valueForKey:@"count"] intValue];
  1383. for(int i=0;i<count;i++)
  1384. {
  1385. NSDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]] mutableCopy];
  1386. if([[olditem valueForKey:@"name"] isEqualToString:name])
  1387. {
  1388. return [[olditem valueForKey:@"value"] floatValue];
  1389. }
  1390. }
  1391. return 0;
  1392. }
  1393. /*
  1394. #pragma mark - Navigation
  1395. // In a storyboard-based application, you will often want to do a little preparation before navigation
  1396. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  1397. // Get the new view controller using [segue destinationViewController].
  1398. // Pass the selected object to the new view controller.
  1399. }
  1400. */
  1401. //#pragma mark - UIAlertViewDelegate
  1402. //// Called when a button is clicked. The view will be automatically dismissed after this call returns
  1403. //- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  1404. //{
  1405. //
  1406. // if(alertView.tag == CLOSE_ACTION)
  1407. // {
  1408. // if(buttonIndex==1)
  1409. // {
  1410. //
  1411. // [self.navigationController popViewControllerAnimated:true];
  1412. // // back to cart;
  1413. // // [self.navigationController dismissViewControllerAnimated:true completion:^{
  1414. // // ;
  1415. // // }];
  1416. // // if ([[upparams valueForKey:@"close_on_save"] boolValue]) {
  1417. // // appDelegate.order_code = nil;
  1418. // //
  1419. // // }
  1420. // }
  1421. // if(buttonIndex==2)
  1422. // {
  1423. //
  1424. // [self.navigationController popViewControllerAnimated:false];
  1425. //
  1426. //
  1427. //
  1428. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1429. //
  1430. //
  1431. // [((MainViewController*)appDelegate.main_vc) switchToOrder];
  1432. // // back to cart;
  1433. // // [self.navigationController dismissViewControllerAnimated:true completion:^{
  1434. // // ;
  1435. // // }];
  1436. // // if ([[upparams valueForKey:@"close_on_save"] boolValue]) {
  1437. // // appDelegate.order_code = nil;
  1438. // //
  1439. // // }
  1440. // }
  1441. // else if(buttonIndex==3)
  1442. // {
  1443. // // close order;
  1444. //
  1445. //
  1446. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1447. // UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Release Order"];
  1448. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1449. //
  1450. // NSDictionary* order_json = [RANetwork release_Order:appDelegate.order_code withScreen:nil];
  1451. //
  1452. // dispatch_async(dispatch_get_main_queue(), ^{
  1453. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  1454. // if([[order_json valueForKey:@"result"] intValue]==2)
  1455. // {
  1456. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1457. // // appDelegate.order_code = nil;
  1458. //
  1459. // [appDelegate closeOrder];
  1460. //
  1461. //
  1462. //#ifdef RA_NOTIFICATION
  1463. // [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1464. //#else
  1465. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  1466. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1467. //#endif
  1468. //
  1469. // [((MainViewController*)appDelegate.main_vc) switchToHome];
  1470. //
  1471. // if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  1472. // {
  1473. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1474. // }
  1475. //
  1476. // [self prepareReturn:nil];
  1477. //
  1478. //
  1479. // [self.navigationController popViewControllerAnimated:true];
  1480. // // [self.navigationController dismissViewControllerAnimated:true completion:^{
  1481. // // ;
  1482. // // }];
  1483. //
  1484. // }
  1485. // else
  1486. // {
  1487. // [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order"controller:self] ;
  1488. // }
  1489. //
  1490. //
  1491. //
  1492. // });
  1493. // });
  1494. //
  1495. //
  1496. //
  1497. //
  1498. //
  1499. // //
  1500. // // }
  1501. // }
  1502. // }
  1503. //}
  1504. //
  1505. //
  1506. //-(void) downloadpdf:(NSString* )url
  1507. //{
  1508. // UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Printing..."];
  1509. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1510. //
  1511. //
  1512. // NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60*5];
  1513. //
  1514. // //设置请求方式为get
  1515. //
  1516. // [request setHTTPMethod:@"GET"];
  1517. //
  1518. // //添加用户会话id
  1519. //
  1520. // [request addValue:@"text/html" forHTTPHeaderField:@"Content-Type"];
  1521. //
  1522. // //连接发送请求
  1523. //
  1524. //
  1525. // NSHTTPURLResponse* urlResponse = nil;
  1526. //
  1527. // NSError *error = [[NSError alloc] init];
  1528. //
  1529. // NSData* content= [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];
  1530. //
  1531. // // self.filename = [urlResponse suggestedFilename];
  1532. //
  1533. //
  1534. // dispatch_async(dispatch_get_main_queue(), ^{
  1535. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  1536. // // self.navigationItem.title = self.save_name;
  1537. // // UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  1538. // // self.content=nil;
  1539. // if(content!=nil&&content.length>0)
  1540. // {
  1541. //
  1542. //
  1543. // [self startAirPrintWithData:content];
  1544. //
  1545. //
  1546. // }
  1547. // else
  1548. // {
  1549. // [RAUtils message_alert:nil title:@"Open PDF Failed" controller:self];
  1550. // // self.content = [self.url dataUsingEncoding:NSUTF8StringEncoding];
  1551. // }
  1552. //
  1553. // ;
  1554. // // DebugLog(@"%@",[[NSString alloc] initWithData:self.content encoding:NSASCIIStringEncoding]);
  1555. // //
  1556. //
  1557. //
  1558. // // [self.webView loadData:self.content MIMEType:urlResponse.MIMEType textEncodingName:nil baseURL:nil];
  1559. //
  1560. //
  1561. //
  1562. //
  1563. // });
  1564. // });
  1565. //}
  1566. //
  1567. //- (void)startAirPrintWithData:(id )data
  1568. //{
  1569. //
  1570. //
  1571. //
  1572. //
  1573. // UIPrintInteractionController* airPrinterController=[UIPrintInteractionController sharedPrintController];
  1574. // UIPrintInfo *printInfo = [UIPrintInfo printInfo];
  1575. // printInfo.outputType = UIPrintInfoOutputGeneral;
  1576. // printInfo.orientation = UIPrintInfoOrientationPortrait;
  1577. // printInfo.jobName = @"CoolVisitAirPrint";
  1578. // airPrinterController.printInfo = printInfo;
  1579. // airPrinterController.printingItem = data;
  1580. // airPrinterController.delegate = self;
  1581. //
  1582. //
  1583. // airPrinterController.showsNumberOfCopies=true;
  1584. // airPrinterController.showsPageRange = true;
  1585. // airPrinterController.showsPaperSelectionForLoadedPapers=true;
  1586. //
  1587. // void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
  1588. // if(completed && error)
  1589. // 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);
  1590. // };
  1591. //
  1592. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1593. //
  1594. // UIPrinter *airPrinter = [UIPrinter printerWithURL:[NSURL URLWithString:appDelegate.printerURL] ];///*self.printer;*/
  1595. //
  1596. //
  1597. //
  1598. //
  1599. // [[UIPrinter printerWithURL:[NSURL URLWithString:appDelegate.printerURL]] contactPrinter:^(BOOL available)
  1600. // {
  1601. // if (available&& appDelegate.printerURL.length>0)
  1602. // {
  1603. //
  1604. // [airPrinterController printToPrinter:airPrinter completionHandler:completionHandler];
  1605. // DebugLog(@"AIRPRINTER AVAILABLE");
  1606. // }
  1607. // else
  1608. // {
  1609. //
  1610. // // [airPrinterController presentFromRect:CGRectMake(0, 0, 300, 500) inView:self.view animated:YES completionHandler:
  1611. // //
  1612. // //
  1613. // //
  1614. // // // [printPicker presentAnimated:YES completionHandler:
  1615. // // ^(UIPrintInteractionController *printerController, BOOL userDidSelect, NSError *error)
  1616. // // {
  1617. // // if (userDidSelect)
  1618. // // {
  1619. // // NSString* sid= printerController.printInfo.printerID;
  1620. // // UIPrintPaper*paper= printerController.printPaper;
  1621. // //
  1622. // // }
  1623. // // }];
  1624. //
  1625. //
  1626. // DebugLog(@"AIRPRINTER NOT AVAILABLE");
  1627. //
  1628. //
  1629. //
  1630. // if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1)
  1631. // {
  1632. // UIPrinterPickerController *printPicker = [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:nil];
  1633. // // [printPicker presentFromBarButtonItem:self.btnSubmitOrder animated:yes completionHandler:
  1634. //
  1635. //
  1636. //
  1637. // [ printPicker presentFromBarButtonItem:self.btnSubmitOrder animated:YES completionHandler:
  1638. //
  1639. //
  1640. // // [printPicker presentFromRect:CGRectMake(0, 0, 300, 500) inView:self.view animated:YES completionHandler:
  1641. //
  1642. //
  1643. //
  1644. // // [printPicker presentAnimated:YES completionHandler:
  1645. // ^(UIPrinterPickerController *printerPicker, BOOL userDidSelect, NSError *error)
  1646. // {
  1647. // if (userDidSelect)
  1648. // {
  1649. // //User selected the item in the UIPrinterPickerController and got the printer details.
  1650. //
  1651. // [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:printerPicker.selectedPrinter];
  1652. //
  1653. // //Here you will get the printer and printer details.ie,
  1654. // // printerPicker.selectedPrinter, printerPicker.selectedPrinter.displayName, printerPicker.selectedPrinter.URL etc. So you can display the printer name in your label text or button title.
  1655. //
  1656. //
  1657. //
  1658. //
  1659. // appDelegate.printerURL =printerPicker.selectedPrinter.URL.absoluteString;
  1660. //
  1661. // [self startAirPrintWithData:data];
  1662. //
  1663. // }
  1664. // else
  1665. // {
  1666. //
  1667. //
  1668. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1669. // if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
  1670. // {
  1671. //
  1672. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1673. // }
  1674. // [self prepareReturn:nil];
  1675. //
  1676. // [self.navigationController popViewControllerAnimated:true];
  1677. // }
  1678. // }];
  1679. // }
  1680. // }
  1681. // }];
  1682. //
  1683. //
  1684. //
  1685. //}
  1686. //
  1687. //#pragma mark - UIPrintInteractionControllerDelegate
  1688. //- (UIPrintPaper *)printInteractionController:(UIPrintInteractionController *)printInteractionController choosePaper:(NSArray<UIPrintPaper *> *)paperList
  1689. //{
  1690. //
  1691. // ;
  1692. //
  1693. // // (int) width = 29700
  1694. // // Printing description of (*( (int *)0x7caa3a40)):
  1695. // // (int) height = 42000
  1696. // //设置纸张大小
  1697. //
  1698. //
  1699. // for(UIPrintPaper* paper in paperList)
  1700. // {
  1701. // if (CGSizeEqualToSize(paper.paperSize, CGSizeMake(612, 792)))
  1702. // return paper;
  1703. //
  1704. // }
  1705. // CGSize paperSize = CGSizeMake(612, 792);
  1706. // UIPrintPaper * p=[UIPrintPaper bestPaperForPageSize:paperSize withPapersFromArray:paperList];
  1707. // return p;
  1708. //}
  1709. //- (void)printInteractionControllerWillPresentPrinterOptions:(UIPrintInteractionController *)printInteractionController
  1710. //{
  1711. //
  1712. //}
  1713. //- (void)printInteractionControllerDidPresentPrinterOptions:(UIPrintInteractionController *)printInteractionController
  1714. //{
  1715. //
  1716. //}
  1717. //- (void)printInteractionControllerWillDismissPrinterOptions:(UIPrintInteractionController *)printInteractionController
  1718. //{
  1719. //
  1720. //}
  1721. //- (void)printInteractionControllerDidDismissPrinterOptions:(UIPrintInteractionController *)printInteractionController
  1722. //{
  1723. //
  1724. //}
  1725. //
  1726. //- (void)printInteractionControllerWillStartJob:(UIPrintInteractionController *)printInteractionController
  1727. //{
  1728. //
  1729. //}
  1730. //- (void)printInteractionControllerDidFinishJob:(UIPrintInteractionController *)printInteractionController
  1731. //{
  1732. //
  1733. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1734. // if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
  1735. // {
  1736. //
  1737. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1738. // }
  1739. //
  1740. // [self prepareReturn:nil];
  1741. //
  1742. // [self.navigationController popViewControllerAnimated:true];
  1743. //}
  1744. //
  1745. //- (NSString *)currentPriceTypeName {
  1746. // NSInteger priceType = [Singleton sharedInstance].npd_shop_price_type;
  1747. //
  1748. // NSString* pricename = nil;
  1749. // switch (priceType) {
  1750. // case 0:
  1751. // pricename=[Singleton sharedInstance].deliveryString;
  1752. // break;
  1753. // case 1:
  1754. // pricename=flat_price;
  1755. // break;
  1756. // case 2:
  1757. // pricename=given_price;
  1758. // break;
  1759. // default:
  1760. // break;
  1761. // }
  1762. // return pricename;
  1763. //}
  1764. - (void)releaseOrderAfterSave {
  1765. dispatch_async(dispatch_get_main_queue(), ^{
  1766. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1767. // [RANetwork release_Order:appDelegate.order_code withScreen:nil];
  1768. [RANetwork request_release_order:appDelegate.order_code withScreen:nil completionHandler:nil];
  1769. [appDelegate closeOrder];
  1770. [appDelegate SetSo:nil];
  1771. appDelegate.cart_count=0;
  1772. [appDelegate update_count_mark];
  1773. [((MainViewController*)appDelegate.main_vc) switchToOrder];
  1774. [self prepareReturn:nil];
  1775. [self.navigationController popToRootViewControllerAnimated:false];
  1776. });
  1777. }
  1778. -(NSString* )create_customer_ext:(NSDictionary*)customerinfo
  1779. {
  1780. NSString* ret=nil;
  1781. NSString* customer_address1= [customerinfo valueForKey:@"customer_address1"];
  1782. NSString* customer_address2= [customerinfo valueForKey:@"customer_address2"];
  1783. NSString* customer_address3= [customerinfo valueForKey:@"customer_address3"];
  1784. NSString* customer_address4= [customerinfo valueForKey:@"customer_address4"];
  1785. NSMutableArray* arraddr = [[NSMutableArray alloc] init];
  1786. if(customer_address1.length>0)
  1787. [arraddr addObject:customer_address1];
  1788. if(customer_address2.length>0)
  1789. [arraddr addObject:customer_address2];
  1790. if(customer_address3.length>0)
  1791. [arraddr addObject:customer_address3];
  1792. if(customer_address4.length>0)
  1793. [arraddr addObject:customer_address4];
  1794. NSString *addr_string = [arraddr componentsJoinedByString:@"\r\n"];
  1795. NSString* customer_city= [customerinfo valueForKey:@"customer_city"];
  1796. NSString* customer_country= [customerinfo valueForKey:@"customer_country"];
  1797. NSString* customer_zipcode= [customerinfo valueForKey:@"customer_zipcode"];
  1798. NSString* customer_state= [customerinfo valueForKey:@"customer_state"];
  1799. NSMutableArray* arrcty = [[NSMutableArray alloc] init];
  1800. if(customer_city.length>0)
  1801. [arrcty addObject:customer_city];
  1802. if(customer_state.length>0)
  1803. [arrcty addObject:customer_state];
  1804. if(customer_zipcode.length>0)
  1805. [arrcty addObject:customer_zipcode];
  1806. if(customer_country.length>0)
  1807. [arrcty addObject:customer_country];
  1808. NSString *cty_string = [arrcty componentsJoinedByString:@", "];
  1809. // NSString* customer_phone= [customerinfo valueForKey:@"customer_phone"];
  1810. // NSString* customer_fax= [customerinfo valueForKey:@"customer_fax"];
  1811. //
  1812. // NSMutableArray* arrpho = [[NSMutableArray alloc] init];
  1813. // if(customer_phone.length>0)
  1814. // {
  1815. // customer_phone = [NSString stringWithFormat:@"TEL: %@",customer_phone];
  1816. // [arrpho addObject:customer_phone];
  1817. // }
  1818. // if(customer_fax.length>0)
  1819. // {
  1820. // customer_fax = [NSString stringWithFormat:@"FAX: %@",customer_fax];
  1821. // [arrpho addObject:customer_fax];
  1822. // }
  1823. // NSString *phone_string = [arrpho componentsJoinedByString:@", "];
  1824. //
  1825. //
  1826. // NSString* customer_contact= [customerinfo valueForKey:@"customer_contact"];
  1827. // if(customer_contact.length>0)
  1828. // {
  1829. // customer_contact = [NSString stringWithFormat:@"ATTN: %@",customer_contact];
  1830. //
  1831. // }
  1832. // NSString *contact_string = customer_contact;
  1833. //
  1834. //
  1835. // NSString* customer_email= [customerinfo valueForKey:@"customer_email"];
  1836. // if(customer_email.length>0)
  1837. // {
  1838. // customer_email = [NSString stringWithFormat:@"Email: %@",customer_email];
  1839. //
  1840. // }
  1841. // NSString *email_string = customer_email;
  1842. NSMutableArray* arrext = [[NSMutableArray alloc] init];
  1843. if(addr_string.length>0)
  1844. [arrext addObject:addr_string];
  1845. if(cty_string.length>0)
  1846. [arrext addObject:cty_string];
  1847. // if(phone_string.length>0)
  1848. // [arrext addObject:phone_string];
  1849. // if(contact_string.length>0)
  1850. // [arrext addObject:contact_string];
  1851. // if(email_string.length>0)
  1852. // [arrext addObject:email_string];
  1853. ret = [arrext componentsJoinedByString:@"\r\n"];
  1854. // NSString *string = [array componentsJoinedByString:@" "];
  1855. // NSString* customer_name= [customerinfo valueForKey:@"customer_name"];
  1856. return ret;
  1857. }
  1858. -(NSMutableDictionary*)create_value_map:(NSDictionary*)key_map
  1859. {
  1860. NSMutableDictionary* ret= [[NSMutableDictionary alloc] init];
  1861. NSArray *keys= [key_map allKeys];
  1862. //遍历keys
  1863. for(int i=0;i<[keys count];i++)
  1864. {
  1865. //得到当前key
  1866. NSString *key=[keys objectAtIndex:i];
  1867. //如果key不是pic,说明value是字符类型,比如name:Boris
  1868. NSString* valuefrom = [key_map valueForKey:key];
  1869. if(valuefrom.length==0)
  1870. continue;
  1871. NSString* value=[self getValue:valuefrom];
  1872. [ret setValue:value forKey:valuefrom];
  1873. }
  1874. NSDictionary * customerinfo =[self create_cusromer_info_from_table];
  1875. [ret setValue:[self create_customer_ext:customerinfo] forKey:@"customer_contact_ext"];
  1876. [ret setValue:customerinfo[@"customer_first_name"] forKey:@"customer_first_name"];
  1877. [ret setValue:customerinfo[@"customer_last_name"] forKey:@"customer_last_name"];
  1878. return ret;
  1879. }
  1880. -(NSMutableDictionary*)create_cusromer_info_from_table
  1881. {
  1882. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1883. NSMutableDictionary* ret= [appDelegate.customerInfo mutableCopy] ;
  1884. [ret setValue:[self getValue:@"customer_country"] forKey:@"customer_country"];
  1885. [ret setValue:[self getValue:@"customer_phone"] forKey:@"customer_phone"];
  1886. [ret setValue:[self getValue:@"customer_email"] forKey:@"customer_email"];
  1887. [ret setValue:[self getValue:@"customer_name"] forKey:@"customer_name"];
  1888. [ret setValue:[self getValue:@"customer_address4"] forKey:@"customer_address4"];
  1889. [ret setValue:[self getValue:@"customer_address3"] forKey:@"customer_address3"];
  1890. [ret setValue:[self getValue:@"customer_address2"] forKey:@"customer_address2"];
  1891. [ret setValue:[self getValue:@"customer_address1"] forKey:@"customer_address1"];
  1892. [ret setValue:[self getValue:@"customer_zipcode"] forKey:@"customer_zipcode"];
  1893. [ret setValue:[self getValue:@"customer_city"] forKey:@"customer_city"];
  1894. [ret setValue:[self getValue:@"customer_state"] forKey:@"customer_state"];
  1895. [ret setValue:[self getValue:@"customer_cid"] forKey:@"customer_cid"];
  1896. [ret setValue:[self getValue:@"customer_state"] forKey:@"customer_state"];
  1897. [ret setValue:[self getValue:@"customer_contact"] forKey:@"customer_contact"];
  1898. [ret setValue:[self getValue:@"customer_fax"] forKey:@"customer_fax"];
  1899. NSString * firstname =nil;
  1900. NSString* lastname = nil;
  1901. NSString* contact_name = [self getValue:@"customer_contact"];
  1902. if(contact_name!=nil)
  1903. {
  1904. NSArray *_arr = [contact_name componentsSeparatedByString:NSLocalizedString(@" ", nil)];
  1905. if(_arr.count>=1)
  1906. {
  1907. firstname =_arr[0];
  1908. if(_arr.count>1)
  1909. {
  1910. lastname=[[_arr subarrayWithRange:NSMakeRange(1, _arr.count-1)] componentsJoinedByString:@" "];
  1911. }
  1912. }
  1913. }
  1914. [ret setValue:firstname forKey:@"customer_first_name"];
  1915. [ret setValue:lastname forKey:@"customer_last_name"];
  1916. // [ret setValue:[self create_customer_ext:ret] forKey:@"customer_contact_ext"];
  1917. return ret;
  1918. }
  1919. #pragma mark - multi_action sub action clicked
  1920. - (void)MActionClicked:(UIButton *)sender {
  1921. UITableViewCell *cell = (UITableViewCell *) sender.superview.superview;
  1922. NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
  1923. int refresh =0;
  1924. NSMutableDictionary* section_json=nil;
  1925. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  1926. NSString* subid=[item_json valueForKey:@"subid"];
  1927. NSString* refresh_trigger = [item_json valueForKey:@"name"];
  1928. NSDictionary* sub_action = [item_json objectForKey:[NSString stringWithFormat:@"item_%ld",(long)sender.tag]];
  1929. NSString* type = [sub_action valueForKey:@"type"];
  1930. bool discardDirty = [[sub_action valueForKey:@"discard_dirty"] boolValue];
  1931. if([type isEqualToString:@"pull"])
  1932. {
  1933. [self.lastedit endEditing:true];
  1934. refresh = [[sub_action valueForKey:@"refresh"] intValue];
  1935. NSDictionary* keymap= [sub_action objectForKey:@"key_map"];
  1936. NSMutableDictionary* value=[self create_value_map:keymap];
  1937. if(subid==nil)
  1938. {
  1939. NSDictionary* jsonmap=[sub_action valueForKey:@"key_map"];
  1940. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  1941. int icount=[[section_json valueForKey:@"count"] intValue];
  1942. for (int ic=0;ic<icount;ic++)
  1943. {
  1944. NSMutableDictionary* modify_item= [[section_json objectForKey:[NSString stringWithFormat:@"item_%d",ic ]] mutableCopy];
  1945. NSString* mapto = [modify_item valueForKey:@"name"];
  1946. if(mapto.length==0)
  1947. continue;
  1948. NSString* valuefrom= [jsonmap valueForKey:[modify_item valueForKey:@"name"]];
  1949. if(valuefrom==nil)
  1950. continue;
  1951. NSString* valuestr=[value valueForKey:valuefrom];
  1952. // valuestr = [self getValue:valuefrom];
  1953. if(true)
  1954. {
  1955. if(valuestr.length>0)
  1956. [modify_item setValue:valuestr forKey:@"value"];
  1957. else
  1958. [modify_item setValue:@"" forKey:@"value"];
  1959. [modify_item setValue:@"true" forKey:@"dirty"];
  1960. [section_json setObject:modify_item forKey:[NSString stringWithFormat:@"item_%d",ic ]];
  1961. }
  1962. }
  1963. }
  1964. else
  1965. {
  1966. NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  1967. int section = [(NSString*)idarr[0] intValue];
  1968. int item=[(NSString*)idarr[1] intValue];
  1969. NSDictionary* jsonmap=[sub_action valueForKey:@"key_map"];
  1970. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  1971. NSMutableDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]] mutableCopy];
  1972. NSString* control_type = [olditem valueForKey:@"control"];
  1973. if([control_type isEqualToString:@"switch"])
  1974. olditem= [self fill_switch_subitem:olditem subid:nil source:value mapping:jsonmap ];
  1975. else if([control_type isEqualToString:@"enum"])
  1976. {
  1977. olditem= [self fill_enum_subitem:olditem subid:nil source:value mapping:jsonmap ];
  1978. }
  1979. else
  1980. {
  1981. [RAUtils message_alert:@"not impl" title:@"Sorry" controller:self];
  1982. // [RAUtils alert_view:@"" title:@"not impl"];
  1983. }
  1984. [olditem setValue:@"true" forKey:@"dirty"];
  1985. [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",item ]];
  1986. }
  1987. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  1988. self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  1989. if(refresh==1)
  1990. {
  1991. // if(restore_json!=nil)
  1992. // {
  1993. // int rc=[[restore_json valueForKey:@"count"] intValue];
  1994. // for(int ir=0;ir<rc;ir++)
  1995. // {
  1996. // NSString* name = [restore_json valueForKey:[NSString stringWithFormat:@"item_%d",ir]];
  1997. //
  1998. //
  1999. // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  2000. // for(int i=0;i<section_count;i++)
  2001. // {
  2002. // NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  2003. // // NSMutableDictionary * to_sectionjson = [[to objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  2004. // int item_count = [[sectionjson valueForKey:@"count"] intValue];
  2005. // for(int j=0;j<item_count;j++)
  2006. // {
  2007. // NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  2008. // // NSMutableDictionary * to_itemjson=[[to_sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  2009. //
  2010. // if([[itemjson valueForKey:@"name"] isEqualToString:name])
  2011. // {
  2012. // [itemjson removeObjectForKey:@"dirty"];
  2013. // [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j ]];
  2014. // }
  2015. //
  2016. // }
  2017. // [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i ]];
  2018. // }
  2019. //
  2020. //
  2021. // }
  2022. //
  2023. // }
  2024. [self refresh:refresh_trigger discardDirty:discardDirty] ;
  2025. return ;
  2026. }
  2027. // DebugLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  2028. [self.editorTable reloadData ];
  2029. }
  2030. else
  2031. {
  2032. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2033. NSDictionary * item_json = sub_action;
  2034. NSString* value = [item_json valueForKey:@"value"];
  2035. if([value isEqualToString:@"new_addr"])
  2036. {
  2037. AddressEditorViewController * addressVC = [[AddressEditorViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  2038. addressVC.url_type = URL_REMOTE;
  2039. addressVC.request_url=URL_ADDRESS_EDOTOR;
  2040. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  2041. // NSString * string = [checked componentsJoinedByString:@","];
  2042. // [params setValue:string forKey:@"cart2Checkbox"];
  2043. params[@"is_subaction"]=@"true";
  2044. params[@"subaction_tag"]= [NSString stringWithFormat:@"%ld",(long)sender.tag];
  2045. addressVC.params = params;
  2046. addressVC.delegate = self;
  2047. addressVC.from = indexPath;
  2048. // orderinfoVC.params = params;
  2049. [self.navigationController pushViewController:addressVC animated:true];
  2050. }else if([value isEqualToString:@"credit_card"])
  2051. {
  2052. CreditCardEditorViewController * cardVC = [[CreditCardEditorViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  2053. NSDictionary *data = [item_json objectForKey:@"data"];
  2054. if(data!=nil)
  2055. {
  2056. cardVC.content_data_download = [data mutableCopy];
  2057. cardVC.url_type = URL_NONE;
  2058. cardVC.request_url=nil;
  2059. }
  2060. else
  2061. {
  2062. cardVC.url_type = URL_REMOTE;
  2063. cardVC.request_url=URL_CREDITCARD_EDOTOR;
  2064. }
  2065. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  2066. params[@"orderCode"]=appDelegate.order_code;
  2067. params[@"is_subaction"]=@"true";
  2068. params[@"subaction_tag"]= [NSString stringWithFormat:@"%ld",(long)sender.tag];
  2069. cardVC.params = params;
  2070. cardVC.delegate = self;
  2071. cardVC.from = indexPath;
  2072. // orderinfoVC.params = params;
  2073. [self.navigationController pushViewController:cardVC animated:true];
  2074. }
  2075. else if([value isEqualToString:@"Sales_Order_Freight_Bill_To"])
  2076. {
  2077. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  2078. cvc.showNavibar = true;
  2079. cvc.contact_type = value;
  2080. cvc.is_subaction = @"true";
  2081. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  2082. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  2083. [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  2084. //
  2085. // if(self.returnValue)
  2086. // self.returnValue(value);
  2087. };
  2088. [self.navigationController pushViewController:cvc animated:true];
  2089. }
  2090. else if([value isEqualToString:@"Sales_Order_Ship_From"])
  2091. {
  2092. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  2093. cvc.showNavibar = true;
  2094. cvc.contact_type = value;
  2095. cvc.is_subaction = @"true";
  2096. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  2097. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  2098. [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  2099. //
  2100. // if(self.returnValue)
  2101. // self.returnValue(value);
  2102. };
  2103. [self.navigationController pushViewController:cvc animated:true];
  2104. }
  2105. else if([value isEqualToString:@"Sales_Order_Customer"])
  2106. {
  2107. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  2108. cvc.is_subaction = @"true";
  2109. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  2110. cvc.showNavibar = true;
  2111. cvc.contact_type = value;
  2112. __weak typeof(self) weakself = self;
  2113. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  2114. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  2115. //
  2116. // if(self.returnValue)
  2117. // self.returnValue(value);
  2118. };
  2119. [self.navigationController pushViewController:cvc animated:true];
  2120. }
  2121. else if([value isEqualToString:@"Sales_Order_Merchandise_Bill_To"])
  2122. {
  2123. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  2124. cvc.showNavibar = true;
  2125. cvc.contact_type = value;
  2126. cvc.is_subaction = @"true";
  2127. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  2128. __weak typeof(self) weakself = self;
  2129. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  2130. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  2131. //
  2132. // if(self.returnValue)
  2133. // self.returnValue(value);
  2134. };
  2135. [self.navigationController pushViewController:cvc animated:true];
  2136. }
  2137. else if([value isEqualToString:@"Contact_Return_To"])
  2138. {
  2139. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  2140. cvc.is_subaction = @"true";
  2141. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  2142. cvc.showNavibar = true;
  2143. cvc.contact_type = value;
  2144. __weak typeof(self) weakself = self;
  2145. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  2146. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  2147. //
  2148. // if(self.returnValue)
  2149. // self.returnValue(value);
  2150. };
  2151. [self.navigationController pushViewController:cvc animated:true];
  2152. }
  2153. else if([value isEqualToString:@"Sales_Order_Ship_To"])
  2154. {
  2155. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  2156. cvc.is_subaction = @"true";
  2157. cvc.subaction_tag =[NSString stringWithFormat:@"%ld",(long)sender.tag];
  2158. cvc.showNavibar = true;
  2159. cvc.contact_type = value;
  2160. __weak typeof(self) weakself = self;
  2161. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  2162. [weakself handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  2163. //
  2164. // if(self.returnValue)
  2165. // self.returnValue(value);
  2166. };
  2167. [self.navigationController pushViewController:cvc animated:true];
  2168. }
  2169. }
  2170. }
  2171. #pragma mark - Urgency
  2172. -(void) viewWillDisappear:(BOOL)animated
  2173. {
  2174. [super viewWillDisappear:animated];
  2175. [self cancel_urgency_timer];
  2176. }
  2177. - (void)start_urgency_timer {
  2178. return;
  2179. if (!self.editable) {
  2180. return;
  2181. }
  2182. __weak typeof(self) weakSelf = self;
  2183. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  2184. [appDelegate.urgencyDic setValue:appDelegate.user forKey:@"user"];
  2185. #ifdef OFFLINE_MODE
  2186. [appDelegate.urgencyDic setValue:[NSNumber numberWithBool:appDelegate.offline_mode] forKey:@"offline_mode"];
  2187. #endif
  2188. MainViewController *mainVC = (MainViewController *)appDelegate.main_vc;
  2189. __block NSString *so = [mainVC.labelSo.text substringFromIndex:5];
  2190. [[JKTimerManager sharedTimerManager] scheduledDispatchTimerWithName:self.urgency_timer_name timeInterval:1 queue:nil repeats:YES action:^{
  2191. NSMutableDictionary *urgencyDic = [NSMutableDictionary dictionary];
  2192. // DebugLog(@"timer start....");
  2193. [urgencyDic setValue:weakSelf.content_data_download forKey:[NSString stringWithFormat:@"%@_restored_data",self.class_name]];
  2194. [urgencyDic setValue:weakSelf.class_name forKey:@"class_name"];
  2195. if ([weakSelf.class_name isEqualToString:@"CreateOrderViewController"]) {
  2196. // CreateOrderViewController
  2197. [urgencyDic setValue:appDelegate.order_code forKey:@"order_code"];
  2198. [urgencyDic setValue:so forKey:@"order_so"];
  2199. [urgencyDic setValue:[NSNumber numberWithInt:appDelegate.order_status ] forKey:@"order_status"];
  2200. [urgencyDic setValue:appDelegate.order_customer_id forKey:@"order_customer_id"];
  2201. }
  2202. dispatch_async(dispatch_get_main_queue(), ^{
  2203. [appDelegate.urgencyDic setValue:urgencyDic forKey:[NSString stringWithFormat:@"level_%d",weakSelf.level]];
  2204. [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:weakSelf.level + 1] forKey:@"count"];
  2205. });
  2206. }];
  2207. }
  2208. - (void)cancel_urgency_timer {
  2209. [[JKTimerManager sharedTimerManager] cancelTimerWithName:self.urgency_timer_name];
  2210. }
  2211. #pragma mark - Submit Order
  2212. - (void)customer_commit_order:(NSMutableDictionary *)upparams {
  2213. [upparams setValue:@"true" forKey:@"isHold"];
  2214. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Order Submission" completion:^{
  2215. [RANetwork request_commit_order:upparams completionHandler:^(NSMutableDictionary *result) {
  2216. NSDictionary* editor_json =result;
  2217. [waitalert dismissViewControllerAnimated:YES completion:^{
  2218. if([[editor_json valueForKey:@"result"] intValue]==2)
  2219. {
  2220. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2221. // appDelegate.customerInfo = customerInfo;
  2222. [appDelegate closeOrder];
  2223. #ifdef RA_NOTIFICATION
  2224. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2225. #else
  2226. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2227. #endif
  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. [RAUtils message_alert:msg title:title controller:self];
  2243. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  2244. // [alert show];
  2245. [self prepareReturn:nil];
  2246. [self.navigationController popToRootViewControllerAnimated:true];
  2247. }
  2248. else
  2249. {
  2250. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
  2251. }
  2252. }];
  2253. }];
  2254. }];
  2255. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2256. //
  2257. // NSDictionary* editor_json = [RANetwork saveandcommit_Order:upparams];
  2258. //
  2259. // dispatch_async(dispatch_get_main_queue(), ^{
  2260. //
  2261. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  2262. //
  2263. // if([[editor_json valueForKey:@"result"] intValue]==2)
  2264. // {
  2265. //
  2266. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2267. // // appDelegate.customerInfo = customerInfo;
  2268. //
  2269. // [appDelegate closeOrder];
  2270. //
  2271. //
  2272. //#ifdef RA_NOTIFICATION
  2273. // [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2274. //#else
  2275. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2276. //#endif
  2277. //
  2278. // NSString* title=nil;
  2279. // NSString* msg=nil;
  2280. //#ifdef OFFLINE_MODE
  2281. // if(appDelegate.offline_mode)
  2282. // {
  2283. // title=TITLE_OFFLINE_SUBMIT;
  2284. // msg=MSG_OFFLINE_SUBMIT;
  2285. // }
  2286. // else
  2287. //#endif
  2288. // {
  2289. // title=@"Order submitted sucessfully";
  2290. // msg=[NSString stringWithFormat:@"Confirmation#: %@",[editor_json valueForKey:@"so#"]];
  2291. // }
  2292. //
  2293. // [RAUtils message_alert:msg title:title controller:self];
  2294. //// UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  2295. //
  2296. //// [alert show];
  2297. //
  2298. // [self prepareReturn:nil];
  2299. // [self.navigationController popToRootViewControllerAnimated:true];
  2300. //
  2301. //
  2302. // }
  2303. // else
  2304. // {
  2305. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
  2306. // }
  2307. // });
  2308. // });
  2309. }
  2310. -(void)addTasks: (NSString*)filename md5:(NSString*) md5
  2311. {
  2312. AppDelegate* Appdelegate=(AppDelegate*)[UIApplication sharedApplication].delegate;
  2313. // if (![self shouldUploadWithCurrentNerworkStatus]) {
  2314. // [self.view makeToast:@"Current network is not WiFi,you can upload it manually when wifi connected." duration:3.0 position:CSToastPositionCenter];
  2315. // }
  2316. //prepare upload
  2317. // NSMutableArray* tasks = [NSMutableArray new];
  2318. // for(NSMutableDictionary* photo in self.photos)
  2319. NSMutableDictionary* task=[[NSMutableDictionary alloc]init];
  2320. // task[@"path"]=path;
  2321. task[@"file"]=filename;
  2322. task[@"url"]=Appdelegate.uploadurl;
  2323. NSDictionary* params = @{
  2324. @"site_name":[RADataProvider getSiteName],
  2325. @"user":Appdelegate.user,
  2326. @"_method":@"uploadOfflineOrder",
  2327. @"password" : Appdelegate.password,
  2328. @"md5":md5
  2329. };
  2330. task[@"params"]=params;
  2331. // NSString *file = photo[@"file"];
  2332. // [self moveTmpImageToCache:file];
  2333. // [tasks addObject:task];
  2334. // Signature
  2335. // NSDictionary *signatureTask = [self prepareSignatureTask];
  2336. // // add upload tasks;
  2337. [Appdelegate.uploadManager addTask:task];
  2338. // [self clear];
  2339. }
  2340. -(NSMutableDictionary*) convertScanitem :(NSMutableDictionary*) itemjson
  2341. {
  2342. // NSMutableArray* fields=[[NSMutableArray alloc] init];
  2343. NSMutableDictionary* upparams=[[NSMutableDictionary alloc] init];
  2344. if([[itemjson valueForKey:@"control"] isEqualToString:@"enum"])
  2345. {
  2346. NSString* single_select = [itemjson valueForKey:@"single_select"];
  2347. if([single_select isEqualToString:@"true"])
  2348. {
  2349. NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
  2350. int count = [[cadejson valueForKey:@"count"] intValue];
  2351. upparams[[itemjson valueForKey:@"name"]]=@"";
  2352. for(int cc=0;cc<count;cc++)
  2353. {
  2354. NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
  2355. if([[valjson valueForKey:@"check"]intValue]==1)
  2356. {
  2357. // NSString* vid = [valjson valueForKey:@"value_id"] ;
  2358. // if(vid.length==0)
  2359. // vid=@"";
  2360. [upparams setValue:[valjson valueForKey:@"value_id"] forKey:[itemjson valueForKey:@"name"]];
  2361. NSMutableDictionary* subitem = valjson[@"sub_item"];
  2362. if(subitem!=nil)
  2363. {
  2364. int scount = [subitem[@"count"]intValue];
  2365. for(int si=0;si<scount;si++)
  2366. {
  2367. NSMutableDictionary* sitem = subitem[[NSString stringWithFormat:@"item_%d",si]];
  2368. NSMutableDictionary* convertitem = [self convertScanitem:sitem];
  2369. [upparams addEntriesFromDictionary:convertitem];
  2370. }
  2371. }
  2372. break;
  2373. }
  2374. }
  2375. return upparams;
  2376. }
  2377. else //multiple select
  2378. {
  2379. NSMutableArray* checked = [[NSMutableArray alloc] init];
  2380. NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
  2381. int count = [[cadejson valueForKey:@"count"] intValue];
  2382. upparams[[itemjson valueForKey:@"name"]]=@"";
  2383. for(int cc=0;cc<count;cc++)
  2384. {
  2385. NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
  2386. if([[valjson valueForKey:@"check"]intValue]==1)
  2387. {
  2388. // NSString* vid = [valjson valueForKey:@"value_id"] ;
  2389. // if(vid.length==0)
  2390. // vid=@"";
  2391. // [checked addObject:[NSNumber numberWithInt:[[valjson valueForKey:@"value_id"] intValue]]];
  2392. [checked addObject:[NSString stringWithFormat:@"%@",[valjson valueForKey:@"value_id"]]];
  2393. }
  2394. }
  2395. {
  2396. NSString * string = [checked componentsJoinedByString:@","];
  2397. [upparams setValue:string forKey:[itemjson valueForKey:@"name"]];
  2398. }
  2399. return upparams;
  2400. }
  2401. /*
  2402. upparams setValue:itemjson forKey:<#(NSString *)#>
  2403. */
  2404. }
  2405. else
  2406. if([[itemjson valueForKey:@"control"] isEqualToString:@"action"])
  2407. {
  2408. return nil;
  2409. }
  2410. else if([[itemjson valueForKey:@"control"] isEqualToString:@"signature"])
  2411. {
  2412. NSString* valuestr = [itemjson valueForKey:@"value"];
  2413. if(valuestr.length==0)
  2414. valuestr=@"";
  2415. [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  2416. return upparams;
  2417. }
  2418. else if([[itemjson valueForKey:@"control"] isEqualToString:@"switch"])
  2419. {
  2420. NSString* valuestr = [itemjson valueForKey:@"value"];
  2421. [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  2422. NSString* value = [itemjson valueForKey:@"value"];
  2423. // NSMutableDictionary* boolitem=nil;
  2424. // NSMutableDictionary* subjson=nil;
  2425. if([value isEqualToString:@"true"])
  2426. {
  2427. // boolitem =[[itemjson objectForKey:@"true"] mutableCopy];
  2428. NSMutableDictionary* subitem = itemjson[@"sub_item"];
  2429. if(subitem!=nil)
  2430. {
  2431. int scount = [subitem[@"count"]intValue];
  2432. for(int si=0;si<scount;si++)
  2433. {
  2434. NSMutableDictionary* sitem = subitem[[NSString stringWithFormat:@"item_%d",si]];
  2435. NSMutableDictionary* convertitem = [self convertScanitem:sitem];
  2436. [upparams addEntriesFromDictionary:convertitem];
  2437. }
  2438. }
  2439. }
  2440. else
  2441. {
  2442. // boolitem =[[itemjson objectForKey:@"false"] mutableCopy];
  2443. }
  2444. // subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy];
  2445. // if( subjson!=nil /*&& !active*/)
  2446. // {
  2447. // int sub_count = [[subjson valueForKey:@"count"] intValue];
  2448. // for(int l=0;l<sub_count;l++)
  2449. // {
  2450. //// NSMutableDictionary * modify_item=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
  2451. //// if([modify_item valueForKey:@"value"]!=nil && ![[modify_item valueForKey:@"value"]isEqualToString:@""])
  2452. //// [upparams setValue:[modify_item valueForKey:@"value"] forKey:[modify_item valueForKey:@"name"]];
  2453. //
  2454. // }
  2455. // }
  2456. return upparams;
  2457. }
  2458. else if([[itemjson valueForKey:@"control"] isEqualToString:@"img"])
  2459. {
  2460. NSString* avalue = [itemjson valueForKey:@"avalue"];
  2461. if(avalue.length==0)
  2462. avalue=@"";
  2463. [upparams setValue:avalue forKey:[itemjson valueForKey:@"name"]];
  2464. return upparams;
  2465. }
  2466. else if([[itemjson valueForKey:@"control"] isEqualToString:@"edit"])
  2467. {
  2468. // int min_length = [[itemjson valueForKey:@"min_length"] intValue];
  2469. // NSString* check_len_val =itemjson[@"value"];
  2470. NSString* valuestr= [itemjson valueForKey:@"value"];
  2471. if(valuestr.length==0)
  2472. valuestr=@"";
  2473. [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  2474. // {
  2475. // NSString *keyboard_type = [itemjson objectForKey:@"keyboard"];
  2476. // BOOL check_max = [itemjson objectForKey:@"max_type"] != nil ? YES : NO;
  2477. // BOOL check_min = [itemjson objectForKey:@"min_type"] != nil ? YES : NO;
  2478. // if ([keyboard_type isEqualToString:@"number"] && (check_max || check_min)) {
  2479. // // 检查最大值最小值
  2480. // int max_type = [[itemjson objectForKey:@"max_type"] intValue];
  2481. // int min_type = [[itemjson objectForKey:@"min_type"] intValue];
  2482. //
  2483. // float max_value = MAXFLOAT;
  2484. // float min_value = 0;
  2485. //
  2486. // NSString *mfield = nil;
  2487. // float f_value = [check_len_val floatValue];
  2488. //
  2489. // if (check_max) {
  2490. //
  2491. // if (max_type > 0) {
  2492. // // key
  2493. // NSString *max_key = [itemjson objectForKey:@"max"];
  2494. // id max_obj = [self downloadValueForKey:max_key];
  2495. // if (max_obj) {
  2496. // max_value = [max_obj floatValue];
  2497. // }
  2498. //
  2499. // } else {
  2500. // // value
  2501. // id max_obj = [itemjson objectForKey:@"max"];
  2502. // if (max_obj != nil) {
  2503. // max_value = [max_obj floatValue];
  2504. // }
  2505. //
  2506. // }
  2507. //
  2508. // if (max_value < f_value) {
  2509. // mfield =[NSString stringWithFormat:@"%ld. the value of %@ must be not larger than %.2f",fields.count+1,itemjson[@"aname"],max_value];
  2510. // }
  2511. // }
  2512. //
  2513. // if (check_min) {
  2514. //
  2515. // if (min_type > 0) {
  2516. // // key
  2517. // NSString *min_key = [itemjson objectForKey:@"min"];
  2518. // id min_obj = [self downloadValueForKey:min_key];
  2519. // if (min_obj) {
  2520. // min_value = [min_obj floatValue];
  2521. // }
  2522. // } else {
  2523. // // value
  2524. // id min_obj = [itemjson objectForKey:@"min"];
  2525. // if (min_obj != nil) {
  2526. // min_value = [min_obj floatValue];
  2527. // }
  2528. // }
  2529. //
  2530. // if (min_value > f_value) {
  2531. // mfield =[NSString stringWithFormat:@"%ld. the value of %@ must be not smaller than %.2f",fields.count+1,itemjson[@"aname"],min_value];
  2532. // }
  2533. // }
  2534. //
  2535. //
  2536. // if (check_min && check_max) {
  2537. // if (f_value < min_value || f_value > max_value) {
  2538. // mfield =[NSString stringWithFormat:@"%ld. the value of %@ must between %.2f and %.2f",fields.count+1,itemjson[@"aname"],min_value,max_value];
  2539. // }
  2540. // }
  2541. //
  2542. //
  2543. // [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  2544. //
  2545. //
  2546. // } else {
  2547. // [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  2548. // }
  2549. //
  2550. // }
  2551. return upparams;
  2552. }
  2553. else
  2554. {
  2555. NSString* value = [itemjson valueForKey:@"value"];
  2556. if(value.length==0)
  2557. value=@"";
  2558. [upparams setValue:value forKey:[itemjson valueForKey:@"name"]];
  2559. return upparams;
  2560. }
  2561. return upparams;
  2562. }
  2563. -(NSMutableDictionary*) convertScanOrder :(NSMutableDictionary*) dict
  2564. {
  2565. [[[UIApplication sharedApplication] keyWindow] endEditing:YES];
  2566. // [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder)];
  2567. [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];
  2568. // self.first_miss_pos = nil;
  2569. NSMutableDictionary* upparams=[[NSMutableDictionary alloc] init];
  2570. // [upparams setValue:[self.params valueForKey:@"cart2Checkbox"] forKey:@"cart2Checkbox"];
  2571. int section_count=(int)self.content_data_control.count;//[[self.content_data_download valueForKey:@"section_count"] intValue];
  2572. // NSString* aaa = [RAUtils dict2string:self.content_data_control];
  2573. for(int i=0;i<section_count;i++)
  2574. {
  2575. DebugLog(@"debug...section:%d",i);
  2576. NSDictionary * sectionjson = [self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] ;
  2577. int item_count = [sectionjson[@"count"] intValue];
  2578. for(int j=0;j<item_count;j++)
  2579. {
  2580. NSMutableDictionary * itemjson=[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]];
  2581. NSString* key = [itemjson valueForKey:@"name"];
  2582. if(key==nil || key.length==0)
  2583. continue;
  2584. NSMutableDictionary* convertitem=[self convertScanitem:itemjson];
  2585. [upparams addEntriesFromDictionary:convertitem];
  2586. // subitem_data * data=[self subitem_param:itemjson addto:upparams alert:alert];
  2587. // upparams= data.params;
  2588. // fields=[[fields arrayByAddingObjectsFromArray:data.missingfields] mutableCopy];
  2589. }
  2590. }
  2591. upparams[@"price_type"] = @(RASingleton.sharedInstance.price_type);
  2592. return upparams;
  2593. }
  2594. -(NSString*) scan_stock
  2595. {
  2596. NSMutableArray* ret=[NSMutableArray new];
  2597. NSDictionary* section=self.content_data_download[@"section_0"];
  2598. int count = [section[@"count"] intValue];
  2599. for(int i=0;i<count;i++)
  2600. {
  2601. NSDictionary* item = section[[NSString stringWithFormat:@"item_%d",i]];
  2602. NSDictionary* newitem =@{@"count":item[@"count"],@"model":item[@"model"]}; //@"product_id":item[@"product_id"],
  2603. [ret addObject:newitem];
  2604. }
  2605. return [RAConvertor dict2string:ret];
  2606. }
  2607. -(NSMutableArray*) scan_split_models:(NSMutableArray*) smodels
  2608. {
  2609. NSMutableDictionary* cart_section = RASingleton.sharedInstance.scan_cart[@"section_0"];
  2610. int cart_count = [cart_section[@"count"] intValue];
  2611. for(int i=0;i<smodels.count;i++)
  2612. {
  2613. for(int j=0;j<cart_count;j++)
  2614. {
  2615. NSMutableDictionary* cart_item = [cart_section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  2616. if([cart_item[@"model"] isEqualToString:smodels[i][@"model"] ])
  2617. {
  2618. NSMutableDictionary* newitem = [[NSMutableDictionary dictionaryWithDictionary:cart_item] mutableCopy];
  2619. [newitem addEntriesFromDictionary:smodels[i]];
  2620. newitem[@"cuft"]=@([newitem[@"count"] intValue] * [newitem[@"unit_cuft"] doubleValue]);
  2621. // NSString * mpack=newitem[@"stockUom"];
  2622. newitem[@"control"]=@"model";
  2623. newitem[@"description"]= [NSString stringWithFormat:@"%@\n%@\n%@",cart_item[@"model"],cart_item[@"description"],cart_item[@"dimension"] ];
  2624. newitem[@"subtotal_price"] = @([newitem[@"count"] intValue]* [newitem[@"unit_price"] doubleValue]*(1-[newitem[@"discount"] doubleValue]/100.0));
  2625. smodels[i]=newitem;
  2626. break;
  2627. }
  2628. }
  2629. }
  2630. return smodels;
  2631. // for(int j=0;j<cart_count;j++)
  2632. // {
  2633. // NSMutableDictionary* cart_item = [cart_section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  2634. // cart_item[@"description"]= [NSString stringWithFormat:@"%@\n%@\n%@",cart_item[@"model"],cart_item[@"description"],cart_item[@"dimension"] ];
  2635. // cart_item[@"control"]=@"model";
  2636. // section[[NSString stringWithFormat:@"item_%d",j]] = cart_item;
  2637. //
  2638. // }
  2639. // section[@"count"] = @(cart_count);
  2640. // dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  2641. }
  2642. -(void) scan_commit:(NSMutableDictionary *)upparams newmodel:(NSMutableDictionary *)newmodel{
  2643. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2644. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  2645. NSString *documents = [paths objectAtIndex:0];
  2646. NSString *orderdir = [OLDataProvider getScanPath];
  2647. // NSString *ordercontrol = [orderdir stringByAppendingPathComponent:@"order_control.json"];
  2648. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  2649. NSMutableDictionary* saveorder = [[NSMutableDictionary dictionaryWithDictionary:self.content_data_download] mutableCopy];
  2650. if(newmodel)
  2651. saveorder[@"section_0"]=newmodel;
  2652. // [RAUtils dicttofile:ordercontrol dict:self.content_data_control];
  2653. [RAUtils dicttofile:orderPath dict:saveorder];
  2654. for(int os=0;os<[self.content_data_download[@"section_count"] intValue];os++)
  2655. {
  2656. NSDictionary* section = self.content_data_download[[NSString stringWithFormat:@"section_%d",os]];
  2657. for(int oi=0;oi<[section[@"count"] intValue];oi++)
  2658. {
  2659. NSDictionary* item = section [[NSString stringWithFormat:@"item_%d",oi]];
  2660. if([item[@"control"] isEqualToString:@"img"])
  2661. {
  2662. // 复制图片到打包目录
  2663. NSString* img_url_0=item[@"img_url_0"];
  2664. NSString* img_url_1=item[@"img_url_1"];
  2665. NSString* img_url_2=item[@"img_url_2"];
  2666. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
  2667. NSString *cachefolder = [paths objectAtIndex:0];
  2668. // NSString *offline_createimg = [cachefolder stringByAppendingPathComponent:@"offline_createimg"];
  2669. NSString *img_cache = [cachefolder stringByAppendingPathComponent:@"img_cache"];
  2670. NSFileManager* fileManager=[NSFileManager defaultManager];
  2671. if(img_url_0.length>0&&[fileManager fileExistsAtPath:[img_cache stringByAppendingPathComponent:img_url_0]])
  2672. {
  2673. NSError* err;
  2674. [fileManager copyItemAtURL:[NSURL fileURLWithPath:[img_cache stringByAppendingPathComponent:img_url_0]] toURL:[NSURL fileURLWithPath:[orderdir stringByAppendingPathComponent:img_url_0]] error:&err];
  2675. int i=0;
  2676. }
  2677. if(img_url_1.length>0&&[fileManager fileExistsAtPath:[img_cache stringByAppendingPathComponent:img_url_1]])
  2678. {
  2679. NSError* err;
  2680. [fileManager copyItemAtURL:[NSURL fileURLWithPath:[img_cache stringByAppendingPathComponent:img_url_1]] toURL:[NSURL fileURLWithPath:[orderdir stringByAppendingPathComponent:img_url_1]] error:&err];
  2681. }
  2682. if(img_url_2.length>0&&[fileManager fileExistsAtPath:[img_cache stringByAppendingPathComponent:img_url_2]])
  2683. {
  2684. NSError* err;
  2685. [fileManager copyItemAtURL:[NSURL fileURLWithPath:[img_cache stringByAppendingPathComponent:img_url_2]] toURL:[NSURL fileURLWithPath:[orderdir stringByAppendingPathComponent:img_url_2]] error:&err];
  2686. }
  2687. }
  2688. else if([item[@"control"] isEqualToString:@"signature"])
  2689. {
  2690. // 复制图片到打包目录
  2691. NSString* img_url_0=item[@"value"];
  2692. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
  2693. NSString *cachefolder = [paths objectAtIndex:0];
  2694. // NSString *offline_createimg = [cachefolder stringByAppendingPathComponent:@"offline_createimg"];
  2695. NSString *img_cache = [cachefolder stringByAppendingPathComponent:@"img_cache"];
  2696. NSFileManager* fileManager=[NSFileManager defaultManager];
  2697. if(img_url_0.length>0&&[fileManager fileExistsAtPath:[img_cache stringByAppendingPathComponent:img_url_0]])
  2698. {
  2699. NSError* err;
  2700. [fileManager copyItemAtURL:[NSURL fileURLWithPath:[img_cache stringByAppendingPathComponent:img_url_0]] toURL:[NSURL fileURLWithPath:[orderdir stringByAppendingPathComponent:img_url_0]] error:&err];
  2701. }
  2702. }
  2703. }
  2704. }
  2705. NSString * parampath= [orderdir stringByAppendingPathComponent:@"param.json"];
  2706. NSDictionary* param=[self convertScanOrder:self.content_data_download];
  2707. [RAUtils dicttofile:parampath dict:param];
  2708. NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  2709. if(appDelegate.customerInfo==nil)
  2710. appDelegate.customerInfo = [NSMutableDictionary new];
  2711. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  2712. NSString *cartpath = [orderdir stringByAppendingPathComponent:@"cart.json"];
  2713. RASingleton.sharedInstance.scan_cart[@"price_type"] = @(RASingleton.sharedInstance.price_type);
  2714. NSMutableDictionary* savecart = [[NSMutableDictionary dictionaryWithDictionary:RASingleton.sharedInstance.scan_cart] mutableCopy];
  2715. if(newmodel)
  2716. savecart[@"section_0"]=newmodel;
  2717. [RAUtils dicttofile:cartpath dict:savecart];
  2718. NSString * zippath= [orderdir stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.zip",appDelegate.order_code]];
  2719. // NSError *error=nil;
  2720. //
  2721. // [str writeToFile:jsonpath atomically:true encoding:NSUTF8StringEncoding error:&error];
  2722. NSArray* arr_files=[RAUtils allFilesAtPath:orderdir];
  2723. ZipArchive* zip = [[ZipArchive alloc] init];
  2724. // if ([[NSFileManager defaultManager] fileExistsAtPath:zippath]) {
  2725. //
  2726. //
  2727. // [[NSFileManager defaultManager] removeItemAtPath:zippath error:nil];
  2728. //
  2729. //
  2730. // }
  2731. BOOL r = [zip CreateZipFile2:zippath Password:@"usai2010"];
  2732. for(int i=0;i<arr_files.count;i++)
  2733. {
  2734. NSString* file=arr_files[i];
  2735. r = [zip addFileToZip:file newname:[file lastPathComponent]];
  2736. }
  2737. NSString * filepath=[[RADataProvider getSiteName] stringByAppendingPathComponent:appDelegate.user];
  2738. filepath=[filepath stringByAppendingPathComponent:appDelegate.order_code];
  2739. filepath=[filepath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.zip",appDelegate.order_code]];
  2740. if( ![zip CloseZipFile2] )
  2741. {
  2742. zippath = @"";
  2743. filepath =@"";
  2744. }
  2745. NSString *md5 = [RAUtils md5WithFile:zippath];
  2746. {
  2747. //括号内为单个文件上传
  2748. NSString *fileName = [zippath lastPathComponent];
  2749. NSData * file_data= [NSData dataWithContentsOfFile:zippath];
  2750. NSString* realuser;
  2751. NSString* realpassword;
  2752. if(self.realuser.length>0)
  2753. {
  2754. realuser = self.realuser;
  2755. realpassword = self.realpassword;
  2756. }
  2757. else
  2758. {
  2759. realuser = appDelegate.user;
  2760. realpassword = appDelegate.password;
  2761. }
  2762. NSDictionary* params = @{
  2763. // @"site_name":[RADataProvider getSiteName],
  2764. @"user":realuser,
  2765. @"_method":@"uploadOfflineOrder",
  2766. @"password" : realpassword,
  2767. @"md5":md5
  2768. };
  2769. [RANetwork request_fastupload:[params mutableCopy] filename:fileName data:file_data url:appDelegate.uploadurl completionHandler:^(NSMutableDictionary *result) {
  2770. int iresult = [result[@"result"] intValue];
  2771. if(iresult == RESULT_TRUE)
  2772. {
  2773. NSString* soid = result[@"so_id"];
  2774. if(soid.length==0)
  2775. soid=@"N/A";
  2776. // upparams[@"soid"]=soid;
  2777. // NSMutableDictionary* saveorder = [[NSMutableDictionary dictionaryWithDictionary:self.content_data_download] mutableCopy];
  2778. if(newmodel)
  2779. { self.content_data_download[@"section_0"]=newmodel;
  2780. self.content_data_download[@"readonly"]=@1;
  2781. }
  2782. [self scanSave:upparams];
  2783. NSString* company = upparams[@"customer_cid"];
  2784. if(company.length==0)
  2785. company = upparams[@"customer_name"];
  2786. [OLDataProvider save2submitScanOrder:soid company:company];
  2787. [appDelegate closeOrder];
  2788. RASingleton.sharedInstance.scan_cart = nil;
  2789. #ifdef RA_NOTIFICATION
  2790. [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2791. #else
  2792. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  2793. [main_vc reloadCart:true immediately:false];
  2794. #endif
  2795. //
  2796. [self prepareReturn:nil];
  2797. [self.navigationController popViewControllerAnimated:true];
  2798. [((MainViewController*)appDelegate.main_vc) switchToOrder];
  2799. // NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
  2800. // ret[@"result"]=@2;
  2801. // ret[@"file"]=zippath;
  2802. // result(ret);
  2803. return;
  2804. }
  2805. else if(iresult==1)
  2806. {
  2807. self.fail_submit = true;
  2808. self.realuser = nil;
  2809. self.realpassword = nil;
  2810. [RAUtils message_alert:@"Can not submit the order, wrong password" title:@"Submit Order" controller:self];
  2811. if ([[NSFileManager defaultManager] fileExistsAtPath:zippath]) {
  2812. [[NSFileManager defaultManager] removeItemAtPath:zippath error:nil];
  2813. // [orderlist addObject:appDelegate.order_code];
  2814. // [RAUtils dicttofile:orderlistPath dict:orderlist];
  2815. }
  2816. }
  2817. else if([result[@"result"] intValue]==-4||[result[@"result"] intValue]==4-3)
  2818. {
  2819. self.fail_submit = true;
  2820. self.realuser = nil;
  2821. self.realpassword = nil;
  2822. [RAUtils message_alert:@"Order submission failed. Please check your internet and try later." title:@"Submit Order" controller:self];
  2823. // if ([[NSFileManager defaultManager] fileExistsAtPath:zippath]) {
  2824. //
  2825. //
  2826. // [[NSFileManager defaultManager] removeItemAtPath:zippath error:nil];
  2827. //
  2828. // // [orderlist addObject:appDelegate.order_code];
  2829. // // [RAUtils dicttofile:orderlistPath dict:orderlist];
  2830. //
  2831. // }
  2832. return;
  2833. }
  2834. else
  2835. {
  2836. self.fail_submit = true;
  2837. self.realuser = nil;
  2838. self.realpassword = nil;
  2839. [RAUtils message_alert:@"Can not submit order, please contact administrator." title:@"Submit Order" controller:self];
  2840. }
  2841. }];
  2842. }
  2843. return;
  2844. }
  2845. - (void)empolyee_commit_order:(NSMutableDictionary *)upparams {
  2846. #ifdef SCANNER_ORDER
  2847. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2848. NSString* realuser;
  2849. NSString* realpassword;
  2850. if(self.realuser.length>0)
  2851. {
  2852. realuser = self.realuser;
  2853. realpassword = self.realpassword;
  2854. }
  2855. else
  2856. {
  2857. realuser = appDelegate.user;
  2858. realpassword = appDelegate.password;
  2859. }
  2860. if(appDelegate.user_type==USER_ROLE_CUSTOMER || [upparams[@"customer_cid"] stringValue].length>0 ||[appDelegate.user.uppercaseString isEqualToString:@"GUEST"])
  2861. {
  2862. NSMutableDictionary* param = [NSMutableDictionary new];
  2863. NSString* model = [self scan_stock];
  2864. param[@"models"]=model;
  2865. param[@"customer_cid"]=upparams[@"customer_cid"];
  2866. param[@"user"]=realuser;
  2867. param[@"password"]=realpassword;
  2868. [RADataProvider request_scan_stock:param completionHandler:^(NSMutableDictionary *result) {
  2869. if([result[@"result"] intValue]==2)
  2870. {
  2871. NSMutableArray* models = [result[@"models"] mutableCopy];
  2872. if(models.count==0)
  2873. {
  2874. //不可拆分,直接提交
  2875. [self scan_commit:upparams newmodel:nil];
  2876. }
  2877. else
  2878. {
  2879. StockViewController * vc =[[UIStoryboard storyboardWithName:@"SO" bundle:nil] instantiateViewControllerWithIdentifier:@"StockViewController"];
  2880. //
  2881. // 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];
  2882. NSMutableArray* testmodels =[[RAConvertor string2dict:@"[{\"model\":\"1420-1*\",\"count\":1,\"is_back_order\":false,\"etd\":\"2022-06-23\"}]"] mutableCopy];
  2883. // models = testmodels;
  2884. models = [self scan_split_models:models];
  2885. vc.data =models;
  2886. vc.returnValue = ^(NSMutableDictionary * _Nonnull models) {
  2887. // model
  2888. // int i=0;
  2889. // RASingleton.sharedInstance.scan_cart[@"section_0"]=models;
  2890. // self.content_data_download[@"section_0"]=models;
  2891. [self scan_commit:upparams newmodel:models];
  2892. return;
  2893. };
  2894. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  2895. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  2896. // navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  2897. [self presentViewController:navi animated:YES completion:^{
  2898. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  2899. DebugLog(@"EditModelPriceViewController present.........");
  2900. // self.btop = false;
  2901. // <#code#>
  2902. }];
  2903. }
  2904. }
  2905. else if([result[@"result"] intValue]==1)
  2906. {
  2907. self.fail_submit = true;
  2908. self.realuser = nil;
  2909. self.realpassword = nil;
  2910. [RAUtils message_alert:@"Can not submit the order, wrong password" title:@"Submit Order" controller:self];
  2911. // if ([[NSFileManager defaultManager] fileExistsAtPath:zippath]) {
  2912. //
  2913. //
  2914. // [[NSFileManager defaultManager] removeItemAtPath:zippath error:nil];
  2915. //
  2916. // // [orderlist addObject:appDelegate.order_code];
  2917. // // [RAUtils dicttofile:orderlistPath dict:orderlist];
  2918. //
  2919. // }
  2920. return;
  2921. }
  2922. else if([result[@"result"] intValue]==-4||[result[@"result"] intValue]==4-3)
  2923. {
  2924. self.fail_submit = true;
  2925. self.realuser = nil;
  2926. self.realpassword = nil;
  2927. [RAUtils message_alert:@"Order submission failed. Please check your internet and try later." title:@"Submit Order" controller:self];
  2928. // if ([[NSFileManager defaultManager] fileExistsAtPath:zippath]) {
  2929. //
  2930. //
  2931. // [[NSFileManager defaultManager] removeItemAtPath:zippath error:nil];
  2932. //
  2933. // // [orderlist addObject:appDelegate.order_code];
  2934. // // [RAUtils dicttofile:orderlistPath dict:orderlist];
  2935. //
  2936. // }
  2937. return;
  2938. }
  2939. else
  2940. {
  2941. self.fail_submit = true;
  2942. self.realuser = nil;
  2943. self.realpassword = nil;
  2944. [RAUtils message_alert:@"Can not submit order, please contact administrator." title:@"Submit Order" controller:self];
  2945. }
  2946. }];
  2947. }
  2948. else
  2949. {
  2950. //无contact 直接提交
  2951. [self scan_commit:upparams newmodel:nil];
  2952. // [RANetwork request_fastupload:[params mutableCopy] filename:fileName data:file_data url:appDelegate.uploadurl completionHandler:^(NSMutableDictionary *result) {
  2953. // int iresult = [result[@"result"] intValue];
  2954. // if(iresult == RESULT_TRUE)
  2955. // {
  2956. // NSString* soid = result[@"so_id"];
  2957. // if(soid.length==0)
  2958. // soid=@"N/A";
  2959. //// upparams[@"soid"]=soid;
  2960. // [self scanSave:upparams];
  2961. // NSString* company = upparams[@"customer_name"];
  2962. // [OLDataProvider save2submitScanOrder:soid company:company];
  2963. // [appDelegate closeOrder];
  2964. // RASingleton.sharedInstance.scan_cart = nil;
  2965. //
  2966. // #ifdef RA_NOTIFICATION
  2967. // [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2968. // #else
  2969. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  2970. // [main_vc reloadCart:true immediately:false];
  2971. // #endif
  2972. //
  2973. // //
  2974. //
  2975. //
  2976. // [self prepareReturn:nil];
  2977. //
  2978. //
  2979. //
  2980. // [self.navigationController popViewControllerAnimated:true];
  2981. // [((MainViewController*)appDelegate.main_vc) switchToOrder];
  2982. // // NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
  2983. // // ret[@"result"]=@2;
  2984. // // ret[@"file"]=zippath;
  2985. // // result(ret);
  2986. // return;
  2987. // }
  2988. // else if(iresult==1)
  2989. // {
  2990. // self.fail_submit = true;
  2991. // self.realuser = nil;
  2992. // self.realpassword = nil;
  2993. // [RAUtils message_alert:@"Can not submit the order, wrong password" title:@"Submit Order" controller:self];
  2994. // if ([[NSFileManager defaultManager] fileExistsAtPath:zippath]) {
  2995. //
  2996. //
  2997. // [[NSFileManager defaultManager] removeItemAtPath:zippath error:nil];
  2998. //
  2999. // // [orderlist addObject:appDelegate.order_code];
  3000. // // [RAUtils dicttofile:orderlistPath dict:orderlist];
  3001. //
  3002. // }
  3003. //
  3004. //
  3005. // }
  3006. // else
  3007. // {
  3008. // self.fail_submit = true;
  3009. // [RAUtils message_alert:@"Can not submit the order, please check your network" title:@"Submit Order" controller:self];
  3010. //
  3011. // if ([[NSFileManager defaultManager] fileExistsAtPath:zippath]) {
  3012. //
  3013. //
  3014. // [[NSFileManager defaultManager] removeItemAtPath:zippath error:nil];
  3015. //
  3016. // // [orderlist addObject:appDelegate.order_code];
  3017. // // [RAUtils dicttofile:orderlistPath dict:orderlist];
  3018. //
  3019. // }
  3020. //
  3021. // }
  3022. // }];
  3023. }
  3024. return;
  3025. #endif
  3026. [upparams setValue:@"false" forKey:@"isHold"];
  3027. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Order Submission" completion:^{
  3028. [RANetwork request_commit_order:upparams completionHandler:^(NSMutableDictionary *result) {
  3029. NSDictionary* editor_json = result;
  3030. [waitalert dismissViewControllerAnimated:YES completion:^{
  3031. if([[editor_json valueForKey:@"result"] intValue]==2)
  3032. {
  3033. // debug aaa
  3034. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3035. NSString* company= appDelegate.customerInfo[@"customer_name"];
  3036. NSString* send_to =appDelegate.customerInfo[@"customer_email"];
  3037. [appDelegate closeOrder];
  3038. #ifdef RA_NOTIFICATION
  3039. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  3040. #else
  3041. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  3042. #endif
  3043. __block NSString* title=nil;
  3044. __block NSString* msg=nil;
  3045. #ifdef OFFLINE_MODE
  3046. if(appDelegate.offline_mode)
  3047. {
  3048. title=TITLE_OFFLINE_SUBMIT;
  3049. msg=MSG_OFFLINE_SUBMIT;
  3050. }
  3051. else
  3052. #endif
  3053. {
  3054. title=@"Order submitted sucessfully";
  3055. msg=[NSString stringWithFormat:@"Confirmation#: %@",[editor_json valueForKey:@"so#"]];
  3056. }
  3057. NSString* pdf_url = [editor_json valueForKey:@"pdf_url"];
  3058. NSString* email_content =[editor_json valueForKey:@"email_content"];
  3059. NSString* soid=[editor_json valueForKey:@"so#"];
  3060. NSMutableDictionary *value = [NSMutableDictionary dictionary];
  3061. if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  3062. {
  3063. //bbb
  3064. [((MainViewController*)appDelegate.main_vc) Loginout:false];
  3065. value[@"commitorder_logout"]=@"true";
  3066. }
  3067. [self prepareReturn:value];
  3068. __block UIViewController* message_parent = self.navigationController.topViewController;
  3069. [self.navigationController popToRootViewControllerAnimated:true];
  3070. if(pdf_url.length>0)
  3071. {
  3072. // [message_alert dismissViewControllerAnimated:YES completion:^{
  3073. // [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  3074. // [self.navigationController popToRootViewControllerAnimated:true];
  3075. [appDelegate printPdf:pdf_url company:company send_to:send_to soid:soid content:email_content];
  3076. // [appDelegate printPdf:pdf_url];
  3077. // }];
  3078. }
  3079. else
  3080. dispatch_async(dispatch_get_main_queue(), ^{
  3081. // UIAlertController* message_alert=
  3082. [RAUtils message_alert:msg title:title controller:message_parent];
  3083. });
  3084. // __block UIAlertController* message_alert=[RAUtils message_alert:msg title:title controller:self.parentViewController action_handler:^(UIAlertAction * _Nonnull action) {
  3085. //
  3086. //
  3087. //
  3088. //
  3089. //// [self.navigationController popToRootViewControllerAnimated:true];
  3090. //
  3091. //
  3092. // } completion:^{
  3093. //
  3094. // }];
  3095. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  3096. //
  3097. // [alert show];
  3098. //
  3099. }
  3100. else
  3101. {
  3102. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Order Submission" controller:self] ;
  3103. }
  3104. }];
  3105. }];
  3106. }];
  3107. }
  3108. @end