PortfolioViewController.m 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409
  1. //
  2. // PortfolioViewController.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 12/7/15.
  6. // Copyright © 2015 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "PortfolioViewController.h"
  9. #import "iSalesNetwork.h"
  10. #import "ModelItemCell.h"
  11. #import "DetailViewController.h"
  12. #import "LoginViewController.h"
  13. #import "MainViewController.h"
  14. #import "TearSheetParamViewController.h"
  15. #import "EditModelPriceViewController.h"
  16. #import "ContactListViewController.h"
  17. #import "PortfolioEditQTYViewController.h"
  18. #import "PDFViewController.h"
  19. #define ALERT_DEL 1025
  20. @interface PortfolioViewController ()
  21. @end
  22. @implementation PortfolioViewController
  23. -(void) logout
  24. {
  25. self.content_data = nil;
  26. }
  27. -(void) reload_container_getdata:(bool) update_data
  28. {
  29. [super reload_container_getdata:update_data];
  30. if(update_data)
  31. [self reload_data];
  32. else
  33. [self.itemListTable reloadData];
  34. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  35. if(appDelegate.can_create_portfolio)
  36. {
  37. [self.btnCreatePort setTitle:@"Create Portfolio"];
  38. self.btnCreatePort.enabled = true;
  39. }
  40. else
  41. {
  42. [self.btnCreatePort setTitle:@""];
  43. self.btnCreatePort.enabled = false;
  44. }
  45. }
  46. -(void) showHidePrice
  47. {
  48. [self reload_container_getdata:false];
  49. // [self refresh_total];
  50. }
  51. - (IBAction)onAddtoCart:(id)sender {
  52. UIApplication * app = [UIApplication sharedApplication];
  53. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  54. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  55. if(appDelegate.bLogin==false)
  56. {
  57. LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  58. // loginvc.delegate = self;
  59. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  60. loginvc.returnValue = ^(bool blogin){
  61. // UIApplication * app = [UIApplication sharedApplication];
  62. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  63. if(blogin)
  64. {
  65. if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  66. {
  67. [main_vc checklogin:false];
  68. if(appDelegate.can_create_order)
  69. {
  70. NSString* msg =@"";
  71. if(appDelegate.contact_id.length>0)
  72. {
  73. msg = [msg stringByAppendingString:@"\n\nCustomer:"];
  74. msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
  75. }
  76. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Add to cart", nil) message:msg delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Check for saved order", nil),NSLocalizedString(@"Create new order", nil), nil];
  77. // alert.
  78. [alert show];
  79. }
  80. else
  81. {
  82. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Add to cart", nil) message:NSLocalizedString(@"", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Check for saved order", nil), nil];
  83. // alert.
  84. [alert show];
  85. }
  86. }
  87. else
  88. {
  89. [main_vc checklogin:true];
  90. }
  91. }
  92. // self.offset = 0;
  93. // [self.content_data removeAllObjects];
  94. // [self loadpage];
  95. //
  96. // [[self navigationController] setNavigationBarHidden:YES animated:NO];
  97. };
  98. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  99. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  100. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  101. [self presentViewController:navi animated:YES completion:^{
  102. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  103. NSLog(@"LoginViewController present.........");
  104. // self.btop = false;
  105. // <#code#>
  106. }];
  107. }
  108. else
  109. {
  110. if(appDelegate.user_type==USER_ROLE_EMPLOYEE&&/*appDelegate.contact_id==nil&&*/appDelegate.order_code==nil)
  111. {
  112. [main_vc checklogin:false];
  113. if(appDelegate.can_create_order)
  114. {
  115. NSString* msg =@"";
  116. if(appDelegate.contact_id.length>0)
  117. {
  118. msg = [msg stringByAppendingString:@"\n\nCustomer:"];
  119. msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
  120. }
  121. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Add to cart", nil) message:msg delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Check for saved order", nil),NSLocalizedString(@"Create new order", nil), nil];
  122. // alert.
  123. [alert show];
  124. }
  125. else
  126. {
  127. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Add to cart", nil) message:NSLocalizedString(@"", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Check for saved order", nil), nil];
  128. // alert.
  129. [alert show];
  130. }
  131. }
  132. else
  133. {
  134. if(appDelegate.order_code==nil)
  135. [ self neworder];
  136. else
  137. [self addtocart];
  138. }
  139. }
  140. }
  141. -(void) addtocart
  142. {
  143. NSMutableArray* checked = [[NSMutableArray alloc] init];
  144. NSMutableArray* checked_iid = [[NSMutableArray alloc] init];
  145. int count = [[self.content_data valueForKey:@"count"] intValue];
  146. for(int i=0;i<count;i++)
  147. {
  148. NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  149. bool check = [[item_json valueForKey:@"check"] boolValue];
  150. if(check)
  151. {
  152. [checked addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"product_id"] intValue]]];
  153. [checked_iid addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"item_id"] intValue]]];
  154. }
  155. }
  156. if(checked.count==0)
  157. {
  158. [RAUtils message_alert:@"You must select at least one model." title:@"Cannot Add to cart." controller:self] ;
  159. return;
  160. }
  161. NSString * ids = [checked componentsJoinedByString:@","];
  162. self.btnCreatePort.enabled = false;
  163. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  164. NSDictionary* return_json = [iSalesNetwork add_toCart:ids count:-1];
  165. dispatch_async(dispatch_get_main_queue(), ^{
  166. self.btnCreatePort.enabled = true;
  167. if([[return_json valueForKey:@"result"] intValue]==2)
  168. {
  169. // int result=[[return_json valueForKey:@"result"] intValue];
  170. // if(result==2)
  171. // {
  172. // //successed.
  173. // NSString* order_code = [return_json valueForKey:@"order_code"];
  174. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  175. // appDelegate.order_code = order_code;
  176. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  177. // appDelegate.order_code = order_code;
  178. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false ];
  179. NSString * msg = nil;
  180. if(checked.count==1)
  181. {
  182. msg=@"1 item added to Cart";
  183. }
  184. else
  185. {
  186. msg=[NSString stringWithFormat:@"%lu items added to Cart",(unsigned long)checked.count];
  187. }
  188. [RAUtils message_alert:nil title:msg controller:self] ;
  189. // [self end_select];
  190. // }
  191. }
  192. else
  193. {
  194. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
  195. }
  196. });
  197. });
  198. }
  199. -(void) neworder
  200. {
  201. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Create Order"];
  202. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  203. NSDictionary* return_json = [iSalesNetwork new_Order];
  204. dispatch_async(dispatch_get_main_queue(), ^{
  205. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  206. if([[return_json valueForKey:@"result"] intValue]==2)
  207. {
  208. int result=[[return_json valueForKey:@"result"] intValue];
  209. if(result==2)
  210. {
  211. //successed.
  212. NSString* order_code = [return_json valueForKey:@"orderCode"];
  213. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  214. appDelegate.order_code = order_code;
  215. [self addtocart];
  216. // [self ReloadData];
  217. // if(self.shopCartBlock!=nil)
  218. // {
  219. // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  220. //
  221. //
  222. // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  223. // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  224. // iv.image = img;
  225. // // [self.contentView addSubview:iv];
  226. // self.shopCartBlock(iv);
  227. //
  228. // }
  229. }
  230. }
  231. else
  232. {
  233. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
  234. }
  235. });
  236. });
  237. }
  238. - (IBAction)onCreateTearSheet:(id)sender {
  239. self.pdf_url= nil;
  240. NSMutableArray* checked = [[NSMutableArray alloc] init];
  241. NSMutableArray* checked_iid = [[NSMutableArray alloc] init];
  242. int count = [[self.content_data valueForKey:@"count"] intValue];
  243. for(int i=0;i<count;i++)
  244. {
  245. NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  246. bool check = [[item_json valueForKey:@"check"] boolValue];
  247. if(check)
  248. {
  249. [checked addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"product_id"] intValue]]];
  250. [checked_iid addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"item_id"] intValue]]];
  251. }
  252. }
  253. // disable for debug
  254. if(checked.count==0)
  255. {
  256. [RAUtils message_alert:@"You must select at least one model." title:@"Cannot Create Portfolio." controller:self] ;
  257. return;
  258. }
  259. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  260. NSString * string = [checked componentsJoinedByString:@","];
  261. NSString * string_iid = [checked_iid componentsJoinedByString:@","];
  262. [params setValue:string forKey:@"product_ids"];
  263. [params setValue:string_iid forKey:@"item_ids"];
  264. TearSheetParamViewController * VC =[ self.storyboard instantiateViewControllerWithIdentifier:@"TearSheetParamViewController"];
  265. VC.url_type = URL_REMOTE;
  266. VC.request_url=URL_DM_PARAMS;
  267. VC.params = params;
  268. // VC.delegate=self;
  269. VC.return_url=^(NSString* url,NSString* path, bool remove_item)
  270. {
  271. self.pdf_url = url;
  272. self.path = path;
  273. self.remove_item = remove_item;
  274. };
  275. VC.onSaved=^(NSString* url,NSString* name)
  276. {
  277. // NSString* name=[self.content_data[indexPath.row] valueForKey:@"tear_name"];
  278. // NSString* url= [self.content_data[indexPath.row] valueForKey:@"pdf_path"];
  279. PDFViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PDFViewController"];
  280. ViewController.url = url;
  281. ViewController.canSave = false;
  282. NSString* subject;
  283. // if (company.length==0) {
  284. NSString* cur_time =[RAUtils current_date];
  285. subject =name;//[NSString stringWithFormat:@"NPD Product List %@",cur_time];
  286. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  287. NSString* customer_email= [appDelegate.customerInfo valueForKey:@"customer_email"];
  288. NSMutableArray* send_to = [[NSMutableArray alloc]init];
  289. if(customer_email.length>0)
  290. {
  291. send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
  292. // customer_email compo
  293. // [send_to addObject:customer_email];
  294. }
  295. ViewController.mail_to = send_to;
  296. // }
  297. // else
  298. // {
  299. // subject = [NSString stringWithFormat:@"Tear sheet for %@",company ];
  300. // }
  301. ViewController.attachment_name = [NSString stringWithFormat:@"NPD_Product_List %@.pdf",cur_time];
  302. ViewController.mail_subject = subject;
  303. ViewController.hidenavi = false;
  304. [self.navigationController pushViewController:ViewController animated:YES];
  305. };
  306. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  307. VC.onDismiss=^(NSString* catelog_name)
  308. {
  309. };
  310. //
  311. // if(checked.count==count)
  312. // {
  313. // orderinfoVC.have_tail = true
  314. // }
  315. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:VC] ;
  316. navi.modalPresentationStyle = UIModalPresentationPageSheet;//有三种状态,自己看看是哪种
  317. [self presentViewController:navi animated:YES completion:^{
  318. NSLog(@"TearSheetParamViewController present.........");
  319. // self.btop = false;
  320. // <#code#>
  321. }];
  322. [self.btnselect setTitle:@"Select all"];
  323. }
  324. - (void)viewDidLoad
  325. {
  326. [super viewDidLoad];
  327. UIRefreshControl *ref = [[UIRefreshControl alloc]init];
  328. ref.tag = 200 ;
  329. ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  330. ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  331. // ref.hidden = true;
  332. [ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged];
  333. [self.itemListTable addSubview:ref];
  334. [[UIToolbar appearance] setBackgroundColor: [UIColor whiteColor]];
  335. self.label_net_err.layer.borderColor = [UIColor darkGrayColor].CGColor;
  336. self.label_net_err.layer.borderWidth = 2.0;
  337. self.label_net_err.layer.cornerRadius=15;
  338. self.label_net_err.layer.masksToBounds=true;
  339. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(refresh_btn_click:)];
  340. // tap.minimumPressDuration = 0.8; //定义按的时间
  341. [self.label_net_err addGestureRecognizer:tap];
  342. // self.toolbar.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.toolbar.bounds].CGPath;
  343. // self.toolbar.layer.masksToBounds = false;
  344. //// //添加四个边阴影
  345. //
  346. // self.toolbar.layer.shadowColor = [UIColor blackColor].CGColor;
  347. // self.toolbar.layer.shadowOffset = CGSizeMake(0, 0);
  348. // self.toolbar.layer.shadowOpacity = 0.5;
  349. // self.toolbar.layer.shadowRadius = 2.0;
  350. //
  351. // self.toolbar.layer.borderWidth = 1;
  352. // self.toolbar.layer.borderColor = [[UIColor blackColor] CGColor];
  353. //
  354. // self.toolbar.clipsToBounds = YES;
  355. // [self reload_data];
  356. }
  357. -(void)manually_refresh
  358. {
  359. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  360. if(self.isrefreshing)
  361. {
  362. [reF endRefreshing];
  363. return;
  364. }
  365. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing"];
  366. if ([self respondsToSelector:@selector(reload_data)])
  367. [self performSelector:@selector(reload_data) withObject:nil afterDelay:1];
  368. // DebugLog(@"refresh!!!!!!!!");
  369. }
  370. - (IBAction)onSelectClick:(id)sender {
  371. // self.total=0;
  372. if([self.btnselect.title isEqualToString:@"Select all"])
  373. {
  374. int count =[[self.content_data valueForKey:@"count"] intValue];
  375. for(int i=0;i<count;i++)
  376. {
  377. NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  378. [item_json setValue:@"1" forKey:@"check"];
  379. ModelItemCell* cell=(ModelItemCell*)[self.itemListTable cellForRowAtIndexPath:[NSIndexPath indexPathForItem:i inSection:0]];
  380. cell.img_checkmark.hidden=false;
  381. // double totalprice =[[item_json valueForKey:@"subtotal_price"] doubleValue];
  382. [self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i]];
  383. }
  384. [self.btnselect setTitle:@"Deselect all"];
  385. }
  386. else
  387. {
  388. int count =[[self.content_data valueForKey:@"count"] intValue];
  389. for(int i=0;i<count;i++)
  390. {
  391. NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)i]] mutableCopy];
  392. [item_json setValue:@"0" forKey:@"check"];
  393. ModelItemCell* cell=(ModelItemCell*)[self.itemListTable cellForRowAtIndexPath:[NSIndexPath indexPathForItem:i inSection:0]];
  394. cell.img_checkmark.hidden=true;
  395. [self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i]];
  396. }
  397. [self.btnselect setTitle:@"Select all"];
  398. // self.btnselect.titleLabel.text=@"Select all";
  399. }
  400. }
  401. - (IBAction)onEditClick:(id)sender {
  402. NSMutableArray* checked = [[NSMutableArray alloc] init];
  403. int count = [[self.content_data valueForKey:@"count"] intValue];
  404. for(int i=0;i<count;i++)
  405. {
  406. NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  407. int check = [[item_json valueForKey:@"check"] intValue];
  408. if(check==1)
  409. {
  410. [checked addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"item_id"] intValue]]];
  411. }
  412. }
  413. // disable for debug
  414. if(checked.count==0)
  415. return;
  416. // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  417. NSString * ids = [checked componentsJoinedByString:@","];
  418. {
  419. NSLog(@"edit click");
  420. UIViewController* parentvc=self;
  421. PortfolioEditQTYViewController * vc =[ parentvc.storyboard instantiateViewControllerWithIdentifier:@"PortfolioEditQTYViewController"];
  422. // NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  423. vc.arr_fashion_ids = checked;
  424. // vc.fashionid = [NSString stringWithFormat:@"%d",[[item_json valueForKey:@"fashion_id"] intValue]];
  425. // vc.qty = [[item_json valueForKey:@"available_qty"] intValue];
  426. //
  427. // vc.discount=[[item_json valueForKey:@"tear_sheet_discount"] floatValue];
  428. // vc.price = [[item_json valueForKey:@"tear_sheet_price"] floatValue];
  429. // vc.delegate = parentvc.self;
  430. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  431. vc.onSetValue = ^(int qty,double price, double discount , NSString* notes){
  432. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Updating Quantity"];
  433. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  434. NSDictionary* cart_json = nil;
  435. cart_json= [iSalesNetwork portfolio_setPrice:ids price:price discount:discount QTY:qty notes:notes];
  436. dispatch_async(dispatch_get_main_queue(), ^{
  437. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  438. if([[cart_json valueForKey:@"result"] intValue]==2)
  439. {
  440. [self reload_data];
  441. }
  442. else
  443. {
  444. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Edit QTY" controller:self] ;
  445. }
  446. });
  447. });
  448. //
  449. //
  450. //
  451. // [self reload_data];//[main_vc checklogin:true];
  452. };
  453. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  454. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  455. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  456. [parentvc presentViewController:navi animated:YES completion:^{
  457. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  458. NSLog(@"EditModelPriceViewController present.........");
  459. // self.btop = false;
  460. // <#code#>
  461. }];
  462. // [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  463. }
  464. }
  465. - (IBAction)onDeleteClick:(id)sender {
  466. NSMutableArray* checked = [[NSMutableArray alloc] init];
  467. int count = [[self.content_data valueForKey:@"count"] intValue];
  468. for(int i=0;i<count;i++)
  469. {
  470. NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  471. int check = [[item_json valueForKey:@"check"] intValue];
  472. if(check==1)
  473. {
  474. [checked addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"item_id"] intValue]]];
  475. }
  476. }
  477. // disable for debug
  478. if(checked.count==0)
  479. return;
  480. // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  481. NSString * string = [checked componentsJoinedByString:@","];
  482. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  483. NSDictionary* cart_json = [iSalesNetwork portfolio_remove:string];
  484. dispatch_async(dispatch_get_main_queue(), ^{
  485. if([[cart_json valueForKey:@"result"] intValue]==2)
  486. {
  487. [self reload_data];
  488. }
  489. else
  490. {
  491. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Remove Model From Portfolio" controller:self] ;
  492. }
  493. });
  494. });
  495. }
  496. -(void) viewWillAppear:(BOOL)animated
  497. {
  498. [super viewWillAppear:animated];
  499. [[self navigationController] setNavigationBarHidden:YES animated:NO];
  500. }
  501. -(void) reload_data
  502. {
  503. dispatch_async(dispatch_get_main_queue(), ^{
  504. if(self.isrefreshing)
  505. return;
  506. self.isrefreshing=true;
  507. self.label_net_err.hidden=true;
  508. self.itemListTable.hidden=true;
  509. [self.content_data removeAllObjects];
  510. [self.itemListTable reloadData];
  511. self.mum.center = self.view.center;
  512. self.mum.hidden = false;
  513. [self.mum startAnimating];
  514. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  515. [reF endRefreshing];
  516. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  517. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  518. NSDictionary* cart_json = [iSalesNetwork request_Portfolio];
  519. dispatch_async(dispatch_get_main_queue(), ^{
  520. [self.mum stopAnimating];
  521. int result=[[cart_json valueForKey:@"result"] intValue];
  522. if(result==2||result==1||result==0)
  523. {
  524. self.itemListTable.hidden=false;
  525. self.content_data = [cart_json mutableCopy];
  526. [self.itemListTable reloadData];
  527. [self.btnselect setTitle: @"Deselect all"];
  528. UIApplication * app = [UIApplication sharedApplication];
  529. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  530. appDelegate.port_count =[[self.content_data valueForKey:@"count"] intValue];
  531. }
  532. else
  533. if(result==RESULT_NET_ERROR)
  534. {
  535. self.label_net_err.hidden=false;
  536. self.itemListTable.hidden=true;
  537. }
  538. else
  539. {
  540. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Loading Portfolio" controller:self] ;
  541. }
  542. self.isrefreshing=false;
  543. });
  544. });
  545. });
  546. }
  547. - (void)didReceiveMemoryWarning
  548. {
  549. [super didReceiveMemoryWarning];
  550. // Dispose of any resources that can be recreated.
  551. }
  552. #pragma mark - Table view data source
  553. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  554. //{
  555. // return 0;
  556. //}
  557. //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  558. //{
  559. // return 0;
  560. //}
  561. //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  562. //{
  563. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  564. // return myView;
  565. //
  566. //}
  567. //- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  568. //{
  569. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  570. //// myView.backgroundColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  571. //// UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 90, 22)];
  572. //// titleLabel.textColor=[UIColor whiteColor];
  573. //// titleLabel.backgroundColor = [UIColor clearColor];
  574. //// if(section==0)
  575. //// titleLabel.text=NSLocalizedString(@"display_items", nil);
  576. //// else
  577. //// titleLabel.text=NSLocalizedString(@"hide_items", nil);
  578. //// [titleLabel sizeToFit];
  579. //// [myView addSubview:titleLabel];
  580. ////
  581. // return myView;
  582. //}
  583. //
  584. //- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  585. // if(section==0)
  586. // return nil;
  587. // else
  588. // return @"detail section";
  589. //}
  590. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  591. {
  592. return 1;
  593. }
  594. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  595. {
  596. // NSDictionary * item_json = [self.content_data objectForKey:@"items"];
  597. int count =[[self.content_data valueForKey:@"count"] intValue];
  598. return count;
  599. }
  600. - (IBAction)imgbtnClicked:(UIButton *)sender {
  601. UITableViewCell* cell =(UITableViewCell*) sender.superview.superview;
  602. NSIndexPath * indexPath = [self.itemListTable indexPathForCell:cell];
  603. // NSLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
  604. NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  605. NSString* product_id = [item_json valueForKey:@"product_id"];
  606. DetailViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailViewController" ];
  607. // dvc
  608. dvc.product_id=product_id;
  609. dvc.category_id=nil;
  610. dvc.ispush=true;
  611. [dvc reload];
  612. [self.navigationController pushViewController:dvc animated:true];
  613. }
  614. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  615. {
  616. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  617. // if(tableView==self.itemListTable)
  618. // {
  619. NSString *CellIdentifier = @"WatchListItemCell";
  620. ModelItemCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  621. NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  622. NSString* img_url = [item_json valueForKey:@"img"];
  623. NSString* description = [item_json valueForKey:@"description"];
  624. // NSString* identifier = [item_json valueForKey:@"identifier"];
  625. // NSString* attribute = [item_json valueForKey:@"attribute"];
  626. // NSString* currency = [item_json valueForKey:@"currency"];
  627. // int count =[[item_json valueForKey:@"count"] intValue];
  628. float discount = [[item_json valueForKey:@"tear_sheet_discount"] floatValue];
  629. float price =[[item_json valueForKey:@"tear_sheet_price"] floatValue];
  630. // cell.labelAttribute.text = attribute;
  631. // cell.labelCurrency.text = currency;
  632. cell.labelDescription.text = description;
  633. // cell.labelIdentifier.text = identifier;
  634. int qty= [[item_json valueForKey:@"available_qty"] intValue];
  635. if(![[item_json allKeys] containsObject:@"available_qty"])
  636. {
  637. cell.available_qty_label.hidden=true;
  638. cell.available_qty_value_label.hidden=true;
  639. }
  640. else
  641. {
  642. cell.available_qty_label.hidden=false;
  643. cell.available_qty_value_label.hidden=false;
  644. cell.available_qty_value_label.text = [NSString stringWithFormat:@"%d",qty];
  645. }
  646. NSString* str_price =[NSString stringWithFormat:@"%.2f",price * (1.0-discount/100)];
  647. if(price<0)
  648. str_price=@"No Price";
  649. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  650. {
  651. }
  652. else
  653. {
  654. str_price=nil;
  655. }
  656. cell.labelPrice.text = str_price;
  657. // cell.labelPrice.text = price;
  658. // cell.editCount.text =[NSString stringWithFormat:@"%d",count];
  659. // NSDictionary* val_json =[cadedate_json objectForKey:[NSString stringWithFormat:@"val_%d",i]];
  660. int check = [[item_json valueForKey:@"check"] intValue];
  661. if(check==1)
  662. cell.img_checkmark.hidden=false;
  663. else
  664. cell.img_checkmark.hidden=true;
  665. // UIImageView* iv =cell.btnImage.imageView;
  666. [cell.btnImage setBackgroundImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal];
  667. NSString* file_name=[img_url lastPathComponent];
  668. NSData* img_data=[iSalesDB load_cached_img:file_name];
  669. if(img_data!=nil)
  670. {
  671. UIImage * img =[UIImage imageWithData:img_data];
  672. [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  673. // cell.btnImage.imageView.image = img;
  674. }
  675. else
  676. {
  677. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  678. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  679. dispatch_async(dispatch_get_main_queue(), ^{
  680. if(downloadimg_data!=nil)
  681. {
  682. [iSalesDB cache_img:downloadimg_data :file_name ];
  683. UIImage * img =[UIImage imageWithData:downloadimg_data];
  684. [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  685. }
  686. else
  687. [cell.btnImage setBackgroundImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
  688. });
  689. });
  690. }
  691. cell.backgroundColor = [UIColor whiteColor];// [UIColor whiteColor];;
  692. return cell;
  693. }
  694. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  695. {
  696. ModelItemCell* cell = (ModelItemCell*)[tableView cellForRowAtIndexPath:indexPath];
  697. cell.selected = false;
  698. // self.dirty = true;
  699. NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  700. int check = [[item_json valueForKey:@"check"] intValue];
  701. if(check==1)
  702. {
  703. [item_json setValue:@"0" forKey:@"check"];
  704. cell.img_checkmark.hidden=true;
  705. [self.btnselect setTitle: @"Select all"];
  706. }
  707. else
  708. {
  709. [item_json setValue:@"1" forKey:@"check"];
  710. cell.img_checkmark.hidden=false;
  711. }
  712. [self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  713. }
  714. - (UITableViewCellEditingStyle)tableView:(UITableView *)tv editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
  715. return UITableViewCellEditingStyleDelete;
  716. }
  717. //#pragma mark - UIAlertViewDelegate
  718. //// Called when a button is clicked. The view will be automatically dismissed after this call returns
  719. //- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  720. //{
  721. //
  722. //
  723. //
  724. //}
  725. - (BOOL)isPureFloat:(NSString*)string{
  726. NSScanner* scan = [NSScanner scannerWithString:string];
  727. float val;
  728. return[scan scanFloat:&val] && [scan isAtEnd];
  729. }
  730. #pragma mark 在滑动手势删除某一行的时候,显示出更多的按钮
  731. - (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
  732. {
  733. // 添加一个删除按钮
  734. self.indexPath=indexPath;
  735. UITableViewRowAction *deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  736. NSLog(@"delete click");
  737. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Delete confirm", nil) message:NSLocalizedString(@"Are you sure remove model from portfolio?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
  738. alert.tag = ALERT_DEL;
  739. // alert.
  740. [alert show];
  741. }];
  742. deleteRowAction.backgroundColor = UIColorFromRGB(0x336699);
  743. // // 添加一个编辑按钮
  744. //
  745. // UITableViewRowAction *editRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@" Edit "handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  746. //
  747. // NSLog(@"edit click");
  748. //
  749. //
  750. //
  751. // UIViewController* parentvc=self;
  752. //
  753. //
  754. //
  755. //
  756. // EditModelPriceViewController * vc =[ parentvc.storyboard instantiateViewControllerWithIdentifier:@"EditModelPriceViewController"];
  757. //
  758. //
  759. // NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  760. //
  761. //
  762. //
  763. // vc.set_watch_list=true;
  764. // vc.discount=[[item_json valueForKey:@"tear_sheet_discount"] floatValue];
  765. // vc.price = [[item_json valueForKey:@"tear_sheet_price"] floatValue];
  766. // vc.cart_id = [NSString stringWithFormat:@"%d",[[item_json valueForKey:@"item_id"] intValue]];
  767. // // vc.delegate = parentvc.self;
  768. // // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  769. // vc.onSetValue = ^(double price,double discount){
  770. //
  771. //
  772. // UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Update Price"];
  773. //
  774. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  775. //
  776. // NSDictionary* cart_json = nil;
  777. //
  778. // cart_json= [iSalesNetwork portfolio_setPrice:[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"item_id"] intValue]] price:price discount:discount];
  779. //
  780. // dispatch_async(dispatch_get_main_queue(), ^{
  781. // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  782. //
  783. //
  784. // if([[cart_json valueForKey:@"result"] intValue]==2)
  785. // {
  786. // [self reload_data];
  787. // }
  788. // else
  789. // {
  790. // [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Edit Price" controller:self] ;
  791. // }
  792. //
  793. //
  794. //
  795. //
  796. // });
  797. // });
  798. //
  799. //
  800. //
  801. //
  802. // };
  803. //
  804. //
  805. // UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  806. //
  807. //
  808. //
  809. //
  810. //
  811. // // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  812. //
  813. // navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  814. // [parentvc presentViewController:navi animated:YES completion:^{
  815. //
  816. // // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  817. //
  818. // NSLog(@"EditModelPriceViewController present.........");
  819. //
  820. // // self.btop = false;
  821. // // <#code#>
  822. // }];
  823. //
  824. // [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  825. //
  826. //
  827. // }];
  828. // editRowAction.backgroundColor = UIColorFromRGB(0xff9933);
  829. //
  830. // edit qty
  831. UITableViewRowAction *EditQTYAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@" Edit " handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  832. NSLog(@"edit click");
  833. UIViewController* parentvc=self;
  834. PortfolioEditQTYViewController * vc =[ parentvc.storyboard instantiateViewControllerWithIdentifier:@"PortfolioEditQTYViewController"];
  835. NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  836. vc.arr_fashion_ids = [[NSArray arrayWithObject:[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"fashion_id"] intValue]]] mutableCopy];
  837. // vc.fashionid = [NSString stringWithFormat:@"%d",[[item_json valueForKey:@"fashion_id"] intValue]];
  838. vc.qty = [[item_json valueForKey:@"available_qty"] intValue];
  839. vc.linenotes=[item_json valueForKey:@"linenotes"] ;
  840. vc.discount=[[item_json valueForKey:@"tear_sheet_discount"] floatValue];
  841. vc.price = [[item_json valueForKey:@"tear_sheet_price"] floatValue];
  842. // vc.delegate = parentvc.self;
  843. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  844. vc.onSetValue = ^(int qty,double price, double discount , NSString* notes){
  845. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Updating Quantity"];
  846. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  847. NSDictionary* cart_json = nil;
  848. cart_json= [iSalesNetwork portfolio_setPrice:[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"item_id"] intValue]] price:price discount:discount QTY:qty notes:notes];
  849. dispatch_async(dispatch_get_main_queue(), ^{
  850. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  851. if([[cart_json valueForKey:@"result"] intValue]==2)
  852. {
  853. [self reload_data];
  854. }
  855. else
  856. {
  857. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Edit QTY" controller:self] ;
  858. }
  859. });
  860. });
  861. //
  862. //
  863. //
  864. // [self reload_data];//[main_vc checklogin:true];
  865. };
  866. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  867. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  868. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  869. [parentvc presentViewController:navi animated:YES completion:^{
  870. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  871. NSLog(@"EditModelPriceViewController present.........");
  872. // self.btop = false;
  873. // <#code#>
  874. }];
  875. [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  876. }];
  877. EditQTYAction.backgroundColor = UIColorFromRGB(0xff9933);
  878. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  879. if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  880. {
  881. NSMutableArray* arr=[@[] mutableCopy];
  882. [arr addObject:deleteRowAction];
  883. if(appDelegate.can_set_tearsheet_price)
  884. {
  885. //[arr addObject:editRowAction];
  886. [arr addObject:EditQTYAction];
  887. }
  888. return arr;
  889. // return @[deleteRowAction, editRowAction];
  890. }
  891. else
  892. return @[deleteRowAction];
  893. }
  894. - (void)tableView:(UITableView *)tableView
  895. commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  896. }
  897. #pragma mark - UIAlertViewDelegate
  898. // Called when a button is clicked. The view will be automatically dismissed after this call returns
  899. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  900. {
  901. UIApplication * app = [UIApplication sharedApplication];
  902. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  903. // if(alertView.tag==1234)
  904. // {
  905. //
  906. // // availability warring;
  907. //
  908. //
  909. // if(buttonIndex!=alertView.cancelButtonIndex)
  910. // {
  911. // if(appDelegate.order_code==nil)
  912. // {
  913. // [self neworder];
  914. // }
  915. // else
  916. // {
  917. // [self addtocart];
  918. // }
  919. // }
  920. // return;
  921. // }
  922. // int count=[self.quantity_text.text intValue];
  923. if(alertView.tag==ALERT_DEL)
  924. {
  925. if(buttonIndex!=alertView.cancelButtonIndex)
  926. {
  927. [self.itemListTable reloadRowsAtIndexPaths:@[self.indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  928. NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)self.indexPath.row]] mutableCopy];
  929. NSString *ids=[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"item_id"] intValue]];
  930. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  931. NSDictionary* cart_json = [iSalesNetwork portfolio_remove:ids];
  932. dispatch_async(dispatch_get_main_queue(), ^{
  933. if([[cart_json valueForKey:@"result"] intValue]==2)
  934. {
  935. [self reload_data];
  936. }
  937. else
  938. {
  939. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
  940. }
  941. });
  942. });
  943. }
  944. return;
  945. }
  946. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  947. if(buttonIndex==alertView.cancelButtonIndex)
  948. {
  949. }
  950. else if(buttonIndex==1)
  951. {
  952. //open exist
  953. OrderListViewController* ovc =[ self.storyboard instantiateViewControllerWithIdentifier:@"OrderListViewController"];
  954. ovc.showNavibar = true;
  955. ovc.selectOrder = ^(NSMutableDictionary* order_detail){
  956. if(appDelegate.order_code==nil)
  957. {
  958. [self neworder];
  959. }
  960. else
  961. {
  962. [self addtocart];
  963. [main_vc checklogin:true];
  964. }
  965. };
  966. ovc.init_style = OL_OPEN;
  967. ovc.onCancel = ^(){
  968. [main_vc checklogin:true];
  969. };
  970. [self.navigationController pushViewController:ovc animated:true];
  971. }
  972. else
  973. {
  974. //create new;
  975. if(appDelegate.customerInfo==nil)// select contact if current contact not exist
  976. {
  977. ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  978. cvc.showNavibar = true;
  979. cvc.contact_type = @"Sales_Order_Customer";
  980. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  981. appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  982. appDelegate.customerInfo = value;
  983. if(appDelegate.order_code==nil)
  984. [self neworder];
  985. // [main_vc checklogin:true];
  986. // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  987. //
  988. // if(self.returnValue)
  989. // self.returnValue(value);
  990. };
  991. cvc.onCancel = ^(){
  992. [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"" controller:self];
  993. };
  994. cvc.onReset = ^(){
  995. [main_vc checklogin:true];
  996. };
  997. [self.navigationController pushViewController:cvc animated:true];
  998. }
  999. else
  1000. {
  1001. [self neworder];
  1002. }
  1003. }
  1004. }
  1005. /*
  1006. #pragma mark - Navigation
  1007. // In a storyboard-based application, you will often want to do a little preparation before navigation
  1008. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  1009. // Get the new view controller using [segue destinationViewController].
  1010. // Pass the selected object to the new view controller.
  1011. }
  1012. */
  1013. @end