CreateOrderViewController.m 150 KB

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