PortfolioViewController.m 54 KB

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