CreateOrderViewController.m 155 KB

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