PortfolioViewController.m 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990
  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 "RANetwork.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 "RAPDFViewController.h"
  19. #import "DefaultTableHeaderView.h"
  20. #import "DefaultAppearance.h"
  21. #import "SortItemViewController.h"
  22. #import "SortButton.h"
  23. #import "TextUtils.h"
  24. #import "FileCache.h"
  25. #ifdef BUILD_UWAVER
  26. //#import "RAPortfolioInputDialog.h"
  27. #endif
  28. //#define ALERT_DEL 1025
  29. #define checked_Count @"checkedCount"
  30. @interface PortfolioViewController ()
  31. @property (nonatomic,strong) SortItemViewController *sortItemController;
  32. @property (nonatomic,assign) int sortIndex;
  33. @property (nonatomic,strong) SortButton *sortButton;
  34. @property (nonatomic,assign) NSInteger editedRow;
  35. @property (nonatomic,assign) NSInteger deletedRow;
  36. @property (strong, nonatomic) NSIndexPath *deleteIndexPath;// 点击delete action
  37. @end
  38. @implementation PortfolioViewController
  39. -(void) logout
  40. {
  41. self.content_data = nil;
  42. [self refresh_ui];
  43. }
  44. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  45. {
  46. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  47. if (self) {
  48. // Custom initialization
  49. }
  50. return self;
  51. }
  52. #ifndef RA_NOTIFICATION
  53. -(void) reload_container_getdata:(bool) update_data
  54. {
  55. [super reload_container_getdata:update_data];
  56. if(update_data)
  57. [self reload_data];
  58. else
  59. [self.itemListTable reloadData];
  60. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  61. if(appDelegate.can_create_portfolio)
  62. {
  63. //#ifdef BUILD_UWAVER
  64. // self.btnCreatePort.title = @"Create Hang Tag";
  65. //#else
  66. [self.btnCreatePort setTitle:@"Create Portfolio"];
  67. //#endif
  68. self.btnCreatePort.enabled = true;
  69. }
  70. else
  71. {
  72. [self.btnCreatePort setTitle:@""];
  73. self.btnCreatePort.enabled = false;
  74. }
  75. }
  76. #endif
  77. -(void) showHidePrice
  78. {
  79. #ifndef RA_NOTIFICATION
  80. [self reload_container_getdata:false];
  81. // [self refresh_total];
  82. #endif
  83. }
  84. //- (IBAction)onAddtoCart:(id)sender {
  85. // UIApplication * app = [UIApplication sharedApplication];
  86. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  87. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  88. // if(appDelegate.bLogin==false)
  89. // {
  90. //
  91. // LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  92. // // loginvc.delegate = self;
  93. // // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  94. //
  95. // loginvc.returnValue = ^(bool blogin){
  96. //
  97. //
  98. // // UIApplication * app = [UIApplication sharedApplication];
  99. // // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  100. //
  101. //
  102. //
  103. //
  104. // if(blogin)
  105. // {
  106. // if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  107. // {
  108. //
  109. // [main_vc checklogin:false];
  110. //
  111. // if(appDelegate.can_create_order)
  112. // {
  113. // NSString* msg =@"";
  114. // if(appDelegate.contact_id.length>0)
  115. // {
  116. // msg = [msg stringByAppendingString:@"\n\nCustomer:"];
  117. // msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
  118. //
  119. // }
  120. // 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];
  121. //
  122. //
  123. //
  124. // // alert.
  125. // [alert show];
  126. // }
  127. // else
  128. // {
  129. // 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];
  130. //
  131. // // alert.
  132. // [alert show];
  133. // }
  134. // }
  135. // else
  136. // {
  137. // [main_vc checklogin:true];
  138. // }
  139. // }
  140. //
  141. // // self.offset = 0;
  142. // // [self.content_data removeAllObjects];
  143. // // [self loadpage];
  144. // //
  145. // // [[self navigationController] setNavigationBarHidden:YES animated:NO];
  146. //
  147. // };
  148. //
  149. // UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  150. //
  151. //
  152. //
  153. //
  154. //
  155. // // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  156. //
  157. // navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  158. // [self presentViewController:navi animated:YES completion:^{
  159. //
  160. // // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  161. //
  162. // DebugLog(@"LoginViewController present.........");
  163. //
  164. // // self.btop = false;
  165. // // <#code#>
  166. // }];
  167. // }
  168. // else
  169. // {
  170. // if(appDelegate.user_type==USER_ROLE_EMPLOYEE&&/*appDelegate.contact_id==nil&&*/appDelegate.order_code==nil)
  171. // {
  172. // [main_vc checklogin:false];
  173. // if(appDelegate.can_create_order)
  174. // {
  175. // NSString* msg =@"";
  176. // if(appDelegate.contact_id.length>0)
  177. // {
  178. // msg = [msg stringByAppendingString:@"\n\nCustomer:"];
  179. // msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
  180. //
  181. // }
  182. // 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];
  183. //
  184. // // alert.
  185. // [alert show];
  186. // }
  187. // else
  188. // {
  189. // 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];
  190. //
  191. // // alert.
  192. // [alert show];
  193. // }
  194. // }
  195. // else
  196. // {
  197. //
  198. // if(appDelegate.order_code==nil)
  199. // [ self neworder];
  200. // else
  201. // [self addtocart];
  202. //
  203. //
  204. //
  205. // }
  206. // }
  207. //
  208. //}
  209. -(void) addtocart
  210. {
  211. NSMutableArray* checked = [[NSMutableArray alloc] init];
  212. NSMutableArray* checked_iid = [[NSMutableArray alloc] init];
  213. int count = [[self.content_data valueForKey:@"count"] intValue];
  214. for(int i=0;i<count;i++)
  215. {
  216. NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  217. bool check = [[item_json valueForKey:@"check"] boolValue];
  218. if(check)
  219. {
  220. [checked addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"product_id"] intValue]]];
  221. [checked_iid addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"item_id"] intValue]]];
  222. }
  223. }
  224. if(checked.count==0)
  225. {
  226. [RAUtils message_box:@"Cannot Add to cart." message:@"You must select at least one model." completion:nil];
  227. return;
  228. }
  229. NSString * ids = [checked componentsJoinedByString:@","];
  230. self.btnCreatePort.enabled = false;
  231. [RANetwork request_addto_cart:ids count:-1 name:nil completionHandler:^(NSMutableDictionary *result) {
  232. NSDictionary* return_json = result;
  233. self.btnCreatePort.enabled = true;
  234. if([[return_json valueForKey:@"result"] intValue]==2)
  235. {
  236. #ifdef RA_NOTIFICATION
  237. [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  238. #else
  239. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  240. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  241. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false ];
  242. #endif
  243. NSString * msg = nil;
  244. if(checked.count==1)
  245. {
  246. msg=@"1 item added to Cart";
  247. }
  248. else
  249. {
  250. msg=[NSString stringWithFormat:@"%lu items added to Cart",(unsigned long)checked.count];
  251. }
  252. [RAUtils message_box:msg message:nil completion:nil];
  253. // [self end_select];
  254. // }
  255. }
  256. else
  257. {
  258. [RAUtils message_box:@"Add To Cart" message:[return_json valueForKey:@"err_msg"] completion:nil];
  259. }
  260. }];
  261. }
  262. -(void) neworder
  263. {
  264. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Create Order" completion:^{
  265. PopWaitAlert* pop = [RAUtils waiting_pop:@"Create Order" completion:nil];
  266. [RANetwork request_create_order:^(NSMutableDictionary *result) {
  267. NSMutableDictionary* return_json = result;
  268. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  269. // [waitalert dismissViewControllerAnimated:YES completion:^{
  270. [pop hide];
  271. if([[return_json valueForKey:@"result"] intValue]==2)
  272. {
  273. int result=[[return_json valueForKey:@"result"] intValue];
  274. if(result==2)
  275. {
  276. //successed.
  277. NSString* order_code = [return_json valueForKey:@"orderCode"];
  278. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  279. appDelegate.order_code = order_code;
  280. [self addtocart];
  281. }
  282. }
  283. else
  284. {
  285. [RAUtils message_box:@"Add To Cart" message:[return_json valueForKey:@"err_msg"] completion:nil];
  286. }
  287. // }];
  288. }];
  289. // }];
  290. }
  291. - (IBAction)onCreateTearSheet:(id)sender {
  292. //#ifdef BUILD_UWAVER
  293. //
  294. // [self createPreviewPortfolio];
  295. //
  296. //#else
  297. [self createTearSheet];
  298. //#endif
  299. }
  300. - (void)createTearSheet {
  301. self.pdf_url= nil;
  302. NSMutableArray* checked = [[NSMutableArray alloc] init];
  303. NSMutableArray* checked_iid = [[NSMutableArray alloc] init];
  304. int count = [[self.content_data valueForKey:@"count"] intValue];
  305. for(int i=0;i<count;i++)
  306. {
  307. NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  308. bool check = [[item_json valueForKey:@"check"] boolValue];
  309. if(check)
  310. {
  311. [checked addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"product_id"] intValue]]];
  312. [checked_iid addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"item_id"] intValue]]];
  313. }
  314. }
  315. // disable for debug
  316. if(checked.count==0)
  317. {
  318. NSString *title = @"Cannot Create Portfolio.";
  319. //#ifdef BUILD_UWAVER
  320. // title = @"Cannot Create Hang Tag.";
  321. //#else
  322. title=@"Cannot Create Portfolio.";
  323. //#endif
  324. [RAUtils message_box:title message:@"You must select at least one model." completion:nil];
  325. return;
  326. }
  327. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  328. NSString * string = [checked componentsJoinedByString:@","];
  329. NSString * string_iid = [checked_iid componentsJoinedByString:@","];
  330. [params setValue:string forKey:@"product_ids"];
  331. [params setValue:string_iid forKey:@"item_ids"];
  332. [params setObject:@(self.sortIndex) forKey:@"sort"];
  333. TearSheetParamViewController * VC=[[TearSheetParamViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  334. VC.url_type = URL_REMOTE;
  335. VC.request_url=URL_DM_PARAMS;
  336. VC.params = params;
  337. VC.product_ids=string;
  338. VC.item_ids=string_iid;
  339. // VC.delegate=self;
  340. VC.return_url=^(NSString* url,NSString* path, bool remove_item)
  341. {
  342. self.pdf_url = url;
  343. self.path = path;
  344. self.remove_item = remove_item;
  345. };
  346. VC.onSaved=^(NSString* url,NSString* name,bool isLocalFile)
  347. {
  348. // NSString* name=[self.content_data[indexPath.row] valueForKey:@"tear_name"];
  349. // NSString* url= [self.content_data[indexPath.row] valueForKey:@"pdf_path"];
  350. RAPDFViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"RAPDFViewController"];
  351. ViewController.url = url;
  352. ViewController.canSave = false;
  353. ViewController.isLocalfile=isLocalFile;
  354. NSString* subject;
  355. // if (company.length==0) {
  356. // NSString* cur_time =[RAUtils current_date];
  357. subject =name;//[NSString stringWithFormat:@"NPD Product List %@",cur_time];
  358. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  359. NSString* customer_email= [appDelegate.customerInfo valueForKey:@"customer_email"];
  360. NSMutableArray* send_to = [[NSMutableArray alloc]init];
  361. if(customer_email.length>0)
  362. {
  363. send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
  364. // customer_email compo
  365. // [send_to addObject:customer_email];
  366. }
  367. ViewController.mail_to = send_to;
  368. // }
  369. // else
  370. // {
  371. // subject = [NSString stringWithFormat:@"Tear sheet for %@",company ];
  372. // }
  373. // ViewController.attachment_name = [NSString stringWithFormat:@"NPD_Product_List %@.pdf",cur_time];
  374. ViewController.filename = [NSString stringWithFormat:@"%@.pdf",[TextUtils legalFilename:name]];
  375. ViewController.mail_subject = subject;
  376. ViewController.hidenavi = false;
  377. [self.navigationController pushViewController:ViewController animated:YES];
  378. };
  379. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  380. VC.onDismiss=^(NSString* catelog_name)
  381. {
  382. };
  383. //
  384. // if(checked.count==count)
  385. // {
  386. // orderinfoVC.have_tail = true
  387. // }
  388. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:VC] ;
  389. navi.modalPresentationStyle = UIModalPresentationPageSheet;//有三种状态,自己看看是哪种
  390. [self presentViewController:navi animated:YES completion:^{
  391. DebugLog(@"TearSheetParamViewController present.........");
  392. // self.btop = false;
  393. // <#code#>
  394. }];
  395. [self.btnselect setTitle:@"Select all"];
  396. }
  397. - (void)createPreviewPortfolio:(NSString *)catelog_name Note:(NSString *)internal_note ProductIds:(NSArray *)productIds ItemIds:(NSArray *)itemIds {
  398. if (catelog_name.length == 0) {
  399. NSString *msg = @"Portfolio name can not be empty";
  400. //#ifdef BUILD_UWAVER
  401. // msg = @"hang tag name can not be empty";
  402. //#else
  403. msg = @"Portfolio name can not be empty";
  404. //#endif
  405. [RAUtils message_box:@"Warning" message:msg completion:nil];
  406. return;
  407. }
  408. self.pdf_url= nil;
  409. NSString* pdf_url = [self.content_data valueForKey:@"pdf_url"];
  410. if (!pdf_url) {
  411. pdf_url = @"";
  412. }
  413. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  414. NSString * string = [productIds componentsJoinedByString:@","];
  415. NSString * string_iid = [itemIds componentsJoinedByString:@","];
  416. [params setValue:string forKey:@"product_ids"];
  417. [params setValue:string_iid forKey:@"item_ids"];
  418. [params setObject:@(self.sortIndex) forKey:@"sort"];
  419. [params setObject:pdf_url forKey:@"pdfUrl"];
  420. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Processing" completion:^{
  421. PopWaitAlert* pop = [RAUtils waiting_pop:@"Processing" completion:nil];
  422. [RANetwork request_portfoliopreview:params completionHandler:^(NSMutableDictionary *result) {
  423. NSDictionary* editor_json = result;
  424. // [waitalert dismissViewControllerAnimated:YES completion:^{
  425. [pop hide];
  426. if([[editor_json valueForKey:@"result"] intValue]==2)
  427. {
  428. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  429. NSString* url = [editor_json valueForKey:@"pdf_path"];
  430. NSString* path = [editor_json valueForKey:@"pdf_real_path"];
  431. bool isLocalFile = [[editor_json valueForKey:@"isLocalFile"] boolValue];
  432. RAPDFViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"RAPDFViewController"];
  433. ViewController.url = url;
  434. ViewController.canSave = true;
  435. ViewController.isLocalfile=isLocalFile;
  436. ViewController.filename = [NSString stringWithFormat:@"%@.pdf",[TextUtils legalFilename:catelog_name]];
  437. ViewController.save_name =catelog_name;
  438. ViewController.save_note =internal_note;
  439. NSString* company= [appDelegate.customerInfo valueForKey:@"customer_name"];
  440. if(company==nil)
  441. company=@"";
  442. NSString* customer_email= [appDelegate.customerInfo valueForKey:@"customer_email"];
  443. NSMutableArray* send_to = [[NSMutableArray alloc]init];
  444. if(customer_email.length>0)
  445. {
  446. send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
  447. }
  448. ViewController.mail_to = send_to;
  449. NSString* subject;
  450. subject =catelog_name;
  451. ViewController.mail_subject = subject;
  452. ViewController.onSavePDF=^(NSString* name,NSString* file)
  453. {
  454. NSString* del_ids = nil;
  455. #ifdef OFFLINE_MODE
  456. if (appDelegate.offline_mode)
  457. {
  458. [params setValue:url forKey:@"pdfPath"];
  459. }
  460. else
  461. #endif
  462. {
  463. [params setValue:path forKey:@"pdfPath"];
  464. }
  465. [params setValue:name forKey:@"pdfName"];
  466. [params setValue:internal_note forKey:@"pdfNote"];
  467. [params setValue:del_ids forKey:@"itemIds"];
  468. [params setValue:pdf_url forKey:@"configureParams"];
  469. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Saving..." completion:^{
  470. PopWaitAlert* pop = [RAUtils waiting_pop:@"Saving..." completion:nil];
  471. [RANetwork request_save_portfolio:params completionHandler:^(NSMutableDictionary *result) {
  472. NSDictionary* json =result;
  473. // [waitalert dismissViewControllerAnimated:YES completion:^{
  474. [pop hide];
  475. if([[json valueForKey:@"result"] intValue]==2)
  476. {
  477. [RAUtils message_box:@"Save Portfolio" message:@"Portfolio saved. You can find it from View Portfolios" completion:nil];
  478. // [RAUtils alert_view:nil title:@"Portfolio saved. You can find it from View Portfolios" ] ;
  479. [self.navigationController dismissViewControllerAnimated:true completion:^{
  480. #ifdef RA_NOTIFICATION
  481. [ActiveViewController Notify:@"PortfolioViewController,PDFListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  482. #else
  483. [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:true];
  484. [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
  485. #endif
  486. }];
  487. }
  488. else
  489. {
  490. [RAUtils message_box:@"Save Portfolio" message:[json valueForKey:@"err_msg"] completion:nil];
  491. }
  492. // }];
  493. }];
  494. // }];
  495. };
  496. ViewController.hidenavi = false;
  497. [self.navigationController pushViewController:ViewController animated:YES];
  498. }
  499. else
  500. {
  501. [RAUtils message_box:@"Create Portfolio" message:[editor_json valueForKey:@"err_msg"] completion:nil];
  502. }
  503. // }];
  504. }];
  505. // }];
  506. }
  507. - (void)viewDidLoad
  508. {
  509. [super viewDidLoad];
  510. // UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0.000001)];
  511. // [line setBackgroundColor:[UIColor clearColor]];
  512. // self.itemListTable.tableHeaderView = line;
  513. //
  514. UIRefreshControl *ref = [[UIRefreshControl alloc]init];
  515. ref.tag = 200 ;
  516. ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  517. ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  518. // ref.hidden = true;
  519. [ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged];
  520. [self.itemListTable addSubview:ref];
  521. // [[UIToolbar appearance] setBackgroundColor: [UIColor whiteColor]];
  522. self.label_net_err.layer.borderColor = [UIColor darkGrayColor].CGColor;
  523. self.label_net_err.layer.borderWidth = 2.0;
  524. self.label_net_err.layer.cornerRadius=15;
  525. self.label_net_err.layer.masksToBounds=true;
  526. self.sortIndex = 0;
  527. self.editedRow = -1;
  528. self.deletedRow = -1;
  529. self.indexPath = [NSIndexPath indexPathForRow:-1 inSection:0];
  530. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(refresh_btn_click:)];
  531. // tap.minimumPressDuration = 0.8; //定义按的时间
  532. [self.label_net_err addGestureRecognizer:tap];
  533. //#ifdef BUILD_UWAVER
  534. // self.btnCreatePort.title = @"Create Hang Tag";
  535. // self.btnEdit.title = nil;
  536. // self.btnEdit.enabled = NO;
  537. //#endif
  538. [self initCheckedCount];
  539. }
  540. -(void)manually_refresh
  541. {
  542. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  543. if(self.isrefreshing)
  544. {
  545. [reF endRefreshing];
  546. return;
  547. }
  548. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing"];
  549. if ([self respondsToSelector:@selector(reload_data)])
  550. [self performSelector:@selector(reload_data) withObject:nil afterDelay:1];
  551. // DebugLog(@"refresh!!!!!!!!");
  552. }
  553. - (IBAction)onSelectClick:(id)sender {
  554. // self.total=0;
  555. int count =[[self.content_data valueForKey:@"count"] intValue];
  556. if (count) {
  557. if([self.btnselect.title isEqualToString:@"Select all"])
  558. {
  559. for(int i=0;i<count;i++)
  560. {
  561. NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  562. [item_json setValue:@"1" forKey:@"check"];
  563. ModelItemCell* cell=(ModelItemCell*)[self.itemListTable cellForRowAtIndexPath:[NSIndexPath indexPathForItem:i inSection:0]];
  564. cell.img_checkmark.hidden=false;
  565. // double totalprice =[[item_json valueForKey:@"subtotal_price"] doubleValue];
  566. [self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i]];
  567. }
  568. [self initCheckedCount];
  569. [self.btnselect setTitle:@"Deselect all"];
  570. }
  571. else
  572. {
  573. // int count =[[self.content_data valueForKey:@"count"] intValue];
  574. for(int i=0;i<count;i++)
  575. {
  576. NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)i]] mutableCopy];
  577. [item_json setValue:@"0" forKey:@"check"];
  578. ModelItemCell* cell=(ModelItemCell*)[self.itemListTable cellForRowAtIndexPath:[NSIndexPath indexPathForItem:i inSection:0]];
  579. cell.img_checkmark.hidden=true;
  580. [self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i]];
  581. }
  582. [self clearCheckedCount];
  583. [self.btnselect setTitle:@"Select all"];
  584. // self.btnselect.titleLabel.text=@"Select all";
  585. }
  586. }
  587. }
  588. - (IBAction)onEditClick:(id)sender {
  589. NSMutableArray* checked = [[NSMutableArray alloc] init];
  590. NSMutableArray* fashion_ids = [[NSMutableArray alloc] init];
  591. int count = [[self.content_data valueForKey:@"count"] intValue];
  592. int single_idx=0;
  593. for(int i=0;i<count;i++)
  594. {
  595. NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  596. int check = [[item_json valueForKey:@"check"] intValue];
  597. if(check==1)
  598. {
  599. single_idx = i;
  600. [checked addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"item_id"] intValue]]];
  601. [fashion_ids addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"fashion_id"] intValue]]];
  602. }
  603. }
  604. // disable for debug
  605. if(checked.count==0)
  606. return;
  607. if(checked.count==1)
  608. {
  609. //只选中一个和右滑一样处理。
  610. {
  611. DebugLog(@"edit click");
  612. UIViewController* parentvc=self;
  613. PortfolioEditQTYViewController * vc =[ [UIStoryboard storyboardWithName:@"ERP_Mobile_Portfolio" bundle:nil] instantiateViewControllerWithIdentifier:@"PortfolioEditQTYViewController"];
  614. NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",single_idx]] mutableCopy];
  615. vc.arr_fashion_ids = fashion_ids;
  616. // vc.fashionid = [NSString stringWithFormat:@"%d",[[item_json valueForKey:@"fashion_id"] intValue]];
  617. if([[item_json allKeys] containsObject:@"available_qty"])
  618. vc.qty = [[item_json valueForKey:@"available_qty"] intValue];
  619. else
  620. vc.qty=-1;
  621. if([[item_json allKeys] containsObject:@"available_percent"])
  622. vc.qty_p = [[item_json valueForKey:@"available_percent"] intValue];
  623. else
  624. vc.qty_p=-1;
  625. vc.linenotes=[item_json valueForKey:@"linenotes"] ;
  626. vc.discount=[[item_json valueForKey:@"tear_sheet_discount"] floatValue];
  627. vc.price = [[item_json valueForKey:@"tear_sheet_price"] floatValue];
  628. vc.title=@"Edit Portfolio";
  629. // vc.delegate = parentvc.self;
  630. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  631. vc.onSetValue = ^(int qty,double qty_p, double price, double discount , NSString* notes){
  632. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Updating Quantity" completion:^{
  633. PopWaitAlert* pop = [RAUtils waiting_pop:@"Updating Quantity" completion:nil];
  634. [RANetwork request_update_portfolio_price:[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"item_id"] intValue]] price:price discount:discount QTY:qty qty_p:qty_p notes:notes completionHandler:^(NSMutableDictionary *result) {
  635. NSDictionary* cart_json = result;
  636. // [waitalert dismissViewControllerAnimated:YES completion:^{
  637. [pop hide];
  638. if([[cart_json valueForKey:@"result"] intValue]==2)
  639. {
  640. if (!(qty == -INT32_MAX && qty_p == -MAXFLOAT)) {
  641. // qty
  642. if (qty != -INT32_MAX)
  643. item_json[@"available_qty"]=[NSNumber numberWithInt:qty];
  644. else
  645. [item_json removeObjectForKey:@"available_qty"];
  646. // qty_p
  647. if (qty_p != -MAXFLOAT)
  648. item_json[@"available_percent"]=[NSNumber numberWithInt:qty_p];
  649. else
  650. [item_json removeObjectForKey:@"available_percent"];
  651. }
  652. if (notes) {
  653. item_json[@"linenotes"]=notes;
  654. }
  655. if (discount != -MAXFLOAT) {
  656. item_json[@"tear_sheet_discount"]=[NSString stringWithFormat:@"%.2f",discount];
  657. }
  658. if (price != -MAXFLOAT) {
  659. item_json[@"tear_sheet_price"]=[NSString stringWithFormat:@"%.2f",price];
  660. }
  661. self.content_data[[NSString stringWithFormat:@"item_%d",single_idx]]=item_json;
  662. // item_json[@"available_qty"]=[NSNumber numberWithInt:qty];
  663. [self.itemListTable reloadData];
  664. }
  665. else
  666. {
  667. [RAUtils message_box:@"Edit Portfolio" message:[cart_json valueForKey:@"err_msg"] completion:nil];
  668. }
  669. // }];
  670. }];
  671. // }];
  672. };
  673. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  674. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  675. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  676. [parentvc presentViewController:navi animated:YES completion:^{
  677. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  678. DebugLog(@"EditModelPriceViewController present.........");
  679. // self.btop = false;
  680. // <#code#>
  681. }];
  682. // [//tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  683. }
  684. return;
  685. }
  686. // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  687. NSString * ids = [checked componentsJoinedByString:@","];
  688. {
  689. DebugLog(@"edit click");
  690. UIViewController* parentvc=self;
  691. PortfolioEditQTYViewController * vc =[ [UIStoryboard storyboardWithName:@"ERP_Mobile_Portfolio" bundle:nil] instantiateViewControllerWithIdentifier:@"PortfolioEditQTYViewController"];
  692. // NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  693. vc.arr_fashion_ids = nil;
  694. vc.ids_count=(int)checked.count;
  695. // vc.fashionid = [NSString stringWithFormat:@"%d",[[item_json valueForKey:@"fashion_id"] intValue]];
  696. // vc.qty = [[item_json valueForKey:@"available_qty"] intValue];
  697. //
  698. // vc.discount=[[item_json valueForKey:@"tear_sheet_discount"] floatValue];
  699. // vc.price = [[item_json valueForKey:@"tear_sheet_price"] floatValue];
  700. // vc.delegate = parentvc.self;
  701. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  702. vc.onSetValue = ^(int qty,double qty_p,double price, double discount , NSString* notes){
  703. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Updating Quantity" completion:^{
  704. PopWaitAlert* pop = [RAUtils waiting_pop:@"Updating Quantity" completion:nil];
  705. [RANetwork request_update_portfolio_price:ids price:price discount:discount QTY:qty qty_p:qty_p notes:notes completionHandler:^(NSMutableDictionary *result) {
  706. NSDictionary* cart_json = result;
  707. // [waitalert dismissViewControllerAnimated:YES completion:^{
  708. [pop hide];
  709. if([[cart_json valueForKey:@"result"] intValue]==2)
  710. {
  711. [RAUtils message_box:@"Edit Portfolio" message:[NSString stringWithFormat:@"%ld items saved.",checked.count] completion:nil];
  712. [self reload_data];
  713. }
  714. else
  715. {
  716. [RAUtils message_box:@"Edit Portfolio" message:[cart_json valueForKey:@"err_msg"] completion:nil];
  717. }
  718. // }];
  719. }];
  720. // }];
  721. };
  722. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  723. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  724. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  725. [parentvc presentViewController:navi animated:YES completion:^{
  726. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  727. DebugLog(@"EditModelPriceViewController present.........");
  728. // self.btop = false;
  729. // <#code#>
  730. }];
  731. // [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  732. }
  733. }
  734. - (IBAction)onDeleteClick:(id)sender {
  735. NSMutableArray* checked = [[NSMutableArray alloc] init];
  736. int count = [[self.content_data valueForKey:@"count"] intValue];
  737. for(int i=0;i<count;i++)
  738. {
  739. NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  740. int check = [[item_json valueForKey:@"check"] intValue];
  741. if(check==1)
  742. {
  743. [checked addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"item_id"] intValue]]];
  744. }
  745. }
  746. // disable for debug
  747. if(checked.count==0)
  748. return;
  749. // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  750. NSString * string = [checked componentsJoinedByString:@","];
  751. [RANetwork request_removeportfolio:string completionHandler:^(NSMutableDictionary *result) {
  752. NSMutableDictionary* cart_json =result;
  753. if([[cart_json valueForKey:@"result"] intValue]==2)
  754. {
  755. [self reload_data];
  756. }
  757. else
  758. {
  759. [RAUtils message_box:@"Remove Model From Portfolio" message:[cart_json valueForKey:@"err_msg"] completion:nil];
  760. }
  761. }];
  762. }
  763. -(void) viewWillAppear:(BOOL)animated
  764. {
  765. [super viewWillAppear:animated];
  766. [[self navigationController] setNavigationBarHidden:YES animated:NO];
  767. }
  768. - (void)didReceiveMemoryWarning
  769. {
  770. [super didReceiveMemoryWarning];
  771. // Dispose of any resources that can be recreated.
  772. }
  773. //-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
  774. //{
  775. //
  776. // [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
  777. //
  778. //
  779. //
  780. // [self.itemListTable reloadData];
  781. //
  782. //
  783. //
  784. //}
  785. #pragma mark - Table view data source
  786. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  787. //{
  788. // return 0;
  789. //}
  790. //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  791. //{
  792. // return 0;
  793. //}
  794. //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  795. //{
  796. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  797. // return myView;
  798. //
  799. //}
  800. //- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  801. //{
  802. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  803. //// myView.backgroundColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  804. //// UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 90, 22)];
  805. //// titleLabel.textColor=[UIColor whiteColor];
  806. //// titleLabel.backgroundColor = [UIColor clearColor];
  807. //// if(section==0)
  808. //// titleLabel.text=NSLocalizedString(@"display_items", nil);
  809. //// else
  810. //// titleLabel.text=NSLocalizedString(@"hide_items", nil);
  811. //// [titleLabel sizeToFit];
  812. //// [myView addSubview:titleLabel];
  813. ////
  814. // return myView;
  815. //}
  816. //
  817. //- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  818. // if(section==0)
  819. // return nil;
  820. // else
  821. // return @"detail section";
  822. //}
  823. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  824. {
  825. return 33;
  826. }
  827. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  828. {
  829. NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
  830. if(value==nil)
  831. value=@"";
  832. unsigned long color = strtoul([value UTF8String],0,16);
  833. NSString *sectionTitle = @"Portfolio";
  834. //#ifdef BUILD_UWAVER
  835. // sectionTitle = @"Hang Tag";
  836. //#endif
  837. DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 33)];
  838. // UIButton *sortButton = [UIButton buttonWithType:UIButtonTypeCustom];
  839. // sortButton.frame = CGRectMake(20, 5.5, (33 - 5.5 * 2), (33 - 5.5 * 2));
  840. // [sortButton setImage:[UIImage imageNamed:@"check_1_24"] forState:UIControlStateNormal];
  841. // [sortButton addTarget:self action:@selector(portfolioSortButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
  842. [myView addSubview:self.sortButton];
  843. UILabel *titlelabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 5.5, tableView.bounds.size.width, 22)];
  844. titlelabel.textColor=UIColorFromRGB(color);
  845. titlelabel.textAlignment=NSTextAlignmentCenter;
  846. titlelabel.autoresizingMask=UIViewAutoresizingFlexibleWidth;
  847. titlelabel.text=sectionTitle;
  848. titlelabel.center = myView.center;
  849. myView.autoresizesSubviews=true;
  850. [myView addSubview:titlelabel];
  851. return myView;
  852. }
  853. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  854. {
  855. return 1;
  856. }
  857. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  858. {
  859. // NSDictionary * item_json = [self.content_data objectForKey:@"items"];
  860. int count =[[self.content_data valueForKey:@"count"] intValue];
  861. return count;
  862. }
  863. - (IBAction)imgbtnClicked:(UIButton *)sender {
  864. UITableViewCell* cell =(UITableViewCell*) sender.superview.superview;
  865. NSIndexPath * indexPath = [self.itemListTable indexPathForCell:cell];
  866. // DebugLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
  867. NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  868. NSString *name = [item_json objectForKey:@"description"];
  869. NSRange subRange = [name rangeOfString:@"\n"];
  870. name = [name substringToIndex:subRange.location];
  871. NSString* product_id = [item_json valueForKey:@"product_id"];
  872. DetailViewController* dvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Model" bundle:nil] instantiateViewControllerWithIdentifier:@"DetailViewController" ];
  873. // dvc
  874. dvc.product_id=product_id;
  875. dvc.category_id=nil;
  876. dvc.ispush=true;
  877. dvc.model_name = name;
  878. [dvc reload];
  879. [self.navigationController pushViewController:dvc animated:true];
  880. }
  881. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  882. {
  883. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  884. // if(tableView==self.itemListTable)
  885. // {
  886. NSString *CellIdentifier = @"WatchListItemCell";
  887. ModelItemCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  888. NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  889. // Button 设置了大小约束,Size就不会随内容变化
  890. [cell.btnImage setContentMode:UIViewContentModeScaleAspectFit];
  891. #if __IPHONE_OS_VERSION_MIN_REQUIRED <150000
  892. [cell.btnImage setContentEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
  893. #endif
  894. [cell.btnImage setContentHorizontalAlignment:UIControlContentHorizontalAlignmentFill];
  895. [cell.btnImage setContentVerticalAlignment:UIControlContentVerticalAlignmentFill];
  896. cell.btnImage.imageView.contentMode = UIViewContentModeScaleAspectFit;
  897. NSString* img_url = [item_json valueForKey:@"img"];
  898. NSString* description = [item_json valueForKey:@"description"];
  899. // NSString* identifier = [item_json valueForKey:@"identifier"];
  900. // NSString* attribute = [item_json valueForKey:@"attribute"];
  901. // NSString* currency = [item_json valueForKey:@"currency"];
  902. // int count =[[item_json valueForKey:@"count"] intValue];
  903. float discount = [[item_json valueForKey:@"tear_sheet_discount"] floatValue];
  904. float price =[[item_json valueForKey:@"tear_sheet_price"] floatValue];
  905. // cell.labelAttribute.text = attribute;
  906. // cell.labelCurrency.text = currency;
  907. cell.labelDescription.text = description;
  908. // cell.labelIdentifier.text = identifier;
  909. int qty;
  910. if([[item_json allKeys] containsObject:@"available_qty"])
  911. qty= [[item_json valueForKey:@"available_qty"] intValue];
  912. else
  913. qty=-1;
  914. float qty_p;
  915. if([[item_json allKeys] containsObject:@"available_percent"])
  916. qty_p= [[item_json valueForKey:@"available_percent"] floatValue];
  917. else
  918. qty_p=-1;
  919. // if(![[item_json allKeys] containsObject:@"available_qty"])
  920. // {
  921. // cell.available_qty_label.hidden=true;
  922. // cell.available_qty_value_label.hidden=true;
  923. // }
  924. // else
  925. // {
  926. // cell.available_qty_label.hidden=false;
  927. // cell.available_qty_value_label.hidden=false;
  928. // cell.available_qty_value_label.text = [NSString stringWithFormat:@"%d",qty];
  929. //
  930. // }
  931. if(qty>=0)
  932. {
  933. cell.available_qty_label.hidden=false;
  934. cell.available_qty_value_label.hidden=false;
  935. cell.available_qty_value_label.text = [NSString stringWithFormat:@"%d",qty];
  936. }
  937. else if(qty_p>=0)
  938. {
  939. cell.available_qty_label.hidden=false;
  940. cell.available_qty_value_label.hidden=false;
  941. cell.available_qty_value_label.text = [NSString stringWithFormat:@"%.2f %%",qty_p];
  942. }
  943. else
  944. {
  945. cell.available_qty_label.hidden=true;
  946. cell.available_qty_value_label.hidden=true;
  947. }
  948. NSString* str_price =[NSString stringWithFormat:@"%.2f",price * (1.0-discount/100)];
  949. bool noprice =[[item_json valueForKey:@"is_no_price"]boolValue];
  950. if(noprice)
  951. str_price=@"No Price";
  952. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  953. {
  954. }
  955. else
  956. {
  957. str_price=nil;
  958. }
  959. cell.labelPrice.text = str_price;
  960. // cell.labelPrice.text = price;
  961. // cell.editCount.text =[NSString stringWithFormat:@"%d",count];
  962. // NSDictionary* val_json =[cadedate_json objectForKey:[NSString stringWithFormat:@"val_%d",i]];
  963. int check = [[item_json valueForKey:@"check"] intValue];
  964. if(check==1)
  965. cell.img_checkmark.hidden=false;
  966. else
  967. cell.img_checkmark.hidden=true;
  968. // UIImageView* iv =cell.btnImage.imageView;
  969. // [cell.btnImage setBackgroundImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal];
  970. [cell.btnImage setImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal];
  971. NSString* file_name=[img_url lastPathComponent];
  972. NSData* img_data=[FileCache load_cached_img:file_name loadFrom:img_url];
  973. if(img_data!=nil)
  974. {
  975. UIImage * img =[UIImage imageWithData:img_data];
  976. // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  977. [cell.btnImage setImage:img forState:UIControlStateNormal];
  978. // cell.btnImage.imageView.image = img;
  979. }
  980. else
  981. {
  982. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  983. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  984. dispatch_async(dispatch_get_main_queue(), ^{
  985. if(downloadimg_data!=nil)
  986. {
  987. [FileCache cache_img:downloadimg_data filename:file_name saveTo:img_url];
  988. UIImage * img =[UIImage imageWithData:downloadimg_data];
  989. // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  990. [cell.btnImage setImage:img forState:UIControlStateNormal];
  991. }
  992. else
  993. // [cell.btnImage setBackgroundImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
  994. [cell.btnImage setImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
  995. });
  996. });
  997. }
  998. cell.backgroundColor = [UIColor whiteColor];// [UIColor whiteColor];;
  999. // if (indexPath.row == self.editedRow) {
  1000. // cell.backgroundColor = UIColorFromRGB(0xEAEBED);
  1001. // }
  1002. // if (indexPath.row == self.deletedRow) {
  1003. // cell.backgroundColor = UIColorFromRGB(0xEAEBED);
  1004. // }
  1005. if (indexPath.row == self.indexPath.row) {
  1006. cell.backgroundColor = UIColorFromRGB(0xEAEBED);
  1007. }
  1008. return cell;
  1009. }
  1010. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  1011. {
  1012. ModelItemCell* cell = (ModelItemCell*)[tableView cellForRowAtIndexPath:indexPath];
  1013. cell.selected = false;
  1014. // self.dirty = true;
  1015. NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  1016. int check = [[item_json valueForKey:@"check"] intValue];
  1017. if(check==1)
  1018. {
  1019. [item_json setValue:@"0" forKey:@"check"];
  1020. cell.img_checkmark.hidden=true;
  1021. [self.btnselect setTitle: @"Select all"];
  1022. [self checkedCountRise:NO];
  1023. }
  1024. else
  1025. {
  1026. [item_json setValue:@"1" forKey:@"check"];
  1027. cell.img_checkmark.hidden=false;
  1028. [self checkedCountRise:YES];
  1029. if ([self allChecked]) {
  1030. [self.btnselect setTitle: @"DeSelect all"];
  1031. }
  1032. }
  1033. [self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  1034. }
  1035. - (UITableViewCellEditingStyle)tableView:(UITableView *)tv editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
  1036. return UITableViewCellEditingStyleDelete;
  1037. }
  1038. //#pragma mark - UIAlertViewDelegate
  1039. //// Called when a button is clicked. The view will be automatically dismissed after this call returns
  1040. //- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  1041. //{
  1042. //
  1043. //
  1044. //
  1045. //}
  1046. - (BOOL)isPureFloat:(NSString*)string{
  1047. NSScanner* scan = [NSScanner scannerWithString:string];
  1048. float val;
  1049. return[scan scanFloat:&val] && [scan isAtEnd];
  1050. }
  1051. #pragma mark 在滑动手势删除某一行的时候,显示出更多的按钮
  1052. //- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
  1053. - (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath
  1054. {
  1055. // 添加一个删除按钮
  1056. // self.indexPath=indexPath;
  1057. // ModelItemCell * cell = [tableView cellForRowAtIndexPath:indexPath];
  1058. // UITableViewRowAction *deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  1059. UIContextualAction* deleteRowAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"Delete" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
  1060. DebugLog(@"delete click");
  1061. self.deleteIndexPath = indexPath;
  1062. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Delete confirm" message:@"Are you sure remove model from portfolio?" preferredStyle:UIAlertControllerStyleAlert];
  1063. UIAlertAction *action_2 = [UIAlertAction actionWithTitle:@"YES" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1064. self.indexPath = self.deleteIndexPath;
  1065. int count =[[self.content_data valueForKey:@"count"] intValue];
  1066. BOOL delete_last = self.indexPath.row == count - 1 ? YES : NO;
  1067. [self.itemListTable reloadRowsAtIndexPaths:@[self.indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  1068. NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)self.indexPath.row]] mutableCopy];
  1069. NSString *ids=[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"item_id"] intValue]];
  1070. [RANetwork request_removeportfolio:ids completionHandler:^(NSMutableDictionary *result) {
  1071. NSMutableDictionary* cart_json =result;
  1072. if([[cart_json valueForKey:@"result"] intValue]==2)
  1073. {
  1074. self.deletedRow = delete_last ? -1 : self.indexPath.row;
  1075. if (delete_last) {
  1076. self.indexPath = [NSIndexPath indexPathForRow:count - 2 inSection:0];
  1077. }
  1078. [self reload_data];
  1079. }
  1080. else
  1081. {
  1082. [RAUtils message_box:@"Delete Model" message:[cart_json valueForKey:@"err_msg"] completion:nil];
  1083. }
  1084. }];
  1085. self.deleteIndexPath = nil;
  1086. return;
  1087. }];
  1088. UIAlertAction *action_3 = [UIAlertAction actionWithTitle:@"NO" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  1089. self.deleteIndexPath = nil;
  1090. return;
  1091. }];
  1092. [alertController addAction:action_2];
  1093. [alertController addAction:action_3];
  1094. [self presentViewController:alertController animated:YES completion:nil];
  1095. // 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];
  1096. // alert.tag = ALERT_DEL;
  1097. // // alert.
  1098. // [alert show];
  1099. }];
  1100. deleteRowAction.backgroundColor = UIColorFromRGB(0x336699);
  1101. // edit qty
  1102. // UITableViewRowAction *EditQTYAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@" Edit " handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  1103. UIContextualAction* EditQTYAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@" Edit " handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
  1104. DebugLog(@"edit click");
  1105. UIViewController* parentvc=self;
  1106. PortfolioEditQTYViewController * vc =[ [UIStoryboard storyboardWithName:@"ERP_Mobile_Portfolio" bundle:nil] instantiateViewControllerWithIdentifier:@"PortfolioEditQTYViewController"];
  1107. __block NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  1108. vc.arr_fashion_ids = [[NSArray arrayWithObject:[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"fashion_id"] intValue]]] mutableCopy];
  1109. // vc.fashionid = [NSString stringWithFormat:@"%d",[[item_json valueForKey:@"fashion_id"] intValue]];
  1110. if([[item_json allKeys] containsObject:@"available_qty"])
  1111. vc.qty = [[item_json valueForKey:@"available_qty"] intValue];
  1112. else
  1113. vc.qty=-1;
  1114. if([[item_json allKeys] containsObject:@"available_percent"])
  1115. vc.qty_p = [[item_json valueForKey:@"available_percent"] intValue];
  1116. else
  1117. vc.qty_p=-1;
  1118. vc.linenotes=[item_json valueForKey:@"linenotes"] ;
  1119. vc.discount=[[item_json valueForKey:@"tear_sheet_discount"] floatValue];
  1120. vc.price = [[item_json valueForKey:@"tear_sheet_price"] floatValue];
  1121. vc.title=@"Edit Portfolio";
  1122. // vc.delegate = parentvc.self;
  1123. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1124. vc.onSetValue = ^(int qty,double qty_p, double price, double discount , NSString* notes){
  1125. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Updating Quantity" completion:^{
  1126. PopWaitAlert* pop = [RAUtils waiting_pop:@"Updating Quantity" completion:nil];
  1127. [RANetwork request_update_portfolio_price:[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"item_id"] intValue]] price:price discount:discount QTY:qty qty_p:qty_p notes:notes completionHandler:^(NSMutableDictionary *result) {
  1128. NSDictionary* cart_json = result;
  1129. // [waitalert dismissViewControllerAnimated:YES completion:^{
  1130. [pop hide];
  1131. if([[cart_json valueForKey:@"result"] intValue]==2)
  1132. {
  1133. self.editedRow = indexPath.row;
  1134. if (!(qty == -INT32_MAX && qty_p == -MAXFLOAT)) {
  1135. // qty
  1136. if (qty != -INT32_MAX)
  1137. item_json[@"available_qty"]=[NSNumber numberWithInt:qty];
  1138. else
  1139. [item_json removeObjectForKey:@"available_qty"];
  1140. // qty_p
  1141. if (qty_p != -MAXFLOAT)
  1142. item_json[@"available_percent"]=[NSNumber numberWithInt:qty_p];
  1143. else
  1144. [item_json removeObjectForKey:@"available_percent"];
  1145. }
  1146. if (notes) {
  1147. item_json[@"linenotes"]=notes;
  1148. }
  1149. if (discount != -MAXFLOAT) {
  1150. item_json[@"tear_sheet_discount"]=[NSString stringWithFormat:@"%.2f",discount];
  1151. }
  1152. if (price != -MAXFLOAT) {
  1153. item_json[@"tear_sheet_price"]=[NSString stringWithFormat:@"%.2f",price];
  1154. }
  1155. self.content_data[[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]]=item_json;
  1156. // item_json[@"available_qty"]=[NSNumber numberWithInt:qty];
  1157. self.indexPath=indexPath;
  1158. [self.itemListTable reloadData];
  1159. }
  1160. else
  1161. {
  1162. [RAUtils message_box:@"Edit Portfolio" message:[cart_json valueForKey:@"err_msg"] completion:nil];
  1163. }
  1164. // }];
  1165. }];
  1166. };
  1167. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  1168. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1169. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1170. [parentvc presentViewController:navi animated:YES completion:^{
  1171. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1172. DebugLog(@"EditModelPriceViewController present.........");
  1173. // self.btop = false;
  1174. // <#code#>
  1175. }];
  1176. [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  1177. }];
  1178. EditQTYAction.backgroundColor = UIColorFromRGB(0xff9933);
  1179. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1180. if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  1181. {
  1182. NSMutableArray* arr=[@[] mutableCopy];
  1183. [arr addObject:deleteRowAction];
  1184. if(appDelegate.can_set_tearsheet_price)
  1185. {
  1186. //[arr addObject:editRowAction];
  1187. [arr addObject:EditQTYAction];
  1188. }
  1189. // return arr;
  1190. return [UISwipeActionsConfiguration configurationWithActions:arr];
  1191. // return @[deleteRowAction, editRowAction];
  1192. }
  1193. else if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  1194. if (appDelegate.customer_type == CustomerTypeStore) {
  1195. // return @[deleteRowAction];
  1196. return [UISwipeActionsConfiguration configurationWithActions:@[deleteRowAction]];
  1197. } else {
  1198. if(appDelegate.can_set_tearsheet_price) {
  1199. // return @[deleteRowAction,EditQTYAction];
  1200. return [UISwipeActionsConfiguration configurationWithActions:@[deleteRowAction,EditQTYAction]];
  1201. } else {
  1202. // return @[deleteRowAction];
  1203. return [UISwipeActionsConfiguration configurationWithActions:@[deleteRowAction]];
  1204. }
  1205. }
  1206. }
  1207. else
  1208. // return @[deleteRowAction];
  1209. return [UISwipeActionsConfiguration configurationWithActions:@[deleteRowAction]];
  1210. }
  1211. - (void)tableView:(UITableView *)tableView
  1212. commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  1213. }
  1214. /*
  1215. #pragma mark - Navigation
  1216. // In a storyboard-based application, you will often want to do a little preparation before navigation
  1217. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  1218. // Get the new view controller using [segue destinationViewController].
  1219. // Pass the selected object to the new view controller.
  1220. }
  1221. */
  1222. #pragma mark - Jack
  1223. - (BOOL)allChecked {
  1224. int checkedCount = [[self.content_data objectForKey:checked_Count] intValue];
  1225. int count = [[self.content_data objectForKey:@"count"] intValue];
  1226. return checkedCount == count;
  1227. }
  1228. - (void)initCheckedCount {
  1229. NSNumber *count = [self.content_data objectForKey:@"count"];
  1230. if (!count) {
  1231. count = [NSNumber numberWithInteger:0];
  1232. }
  1233. [self.content_data setObject:count forKey:checked_Count];
  1234. }
  1235. - (void)clearCheckedCount {
  1236. [self.content_data setObject:[NSNumber numberWithInteger:0] forKey:checked_Count];
  1237. }
  1238. - (void)checkedCountRise:(BOOL)rise {
  1239. int checkedCount = [[self.content_data objectForKey:checked_Count] intValue];
  1240. if (rise) {
  1241. checkedCount++;
  1242. } else {
  1243. checkedCount--;
  1244. }
  1245. [self.content_data setObject:[NSNumber numberWithInteger:checkedCount] forKey:checked_Count];
  1246. }
  1247. - (SortItemViewController *)sortItemController {
  1248. if (!_sortItemController) {
  1249. _sortItemController = [[SortItemViewController alloc] initWithTableOrigin:CGPointMake(40, 40)];
  1250. _sortItemController.sortIndex = self.sortIndex;
  1251. _sortItemController.sortData = @[
  1252. @{@"title":@"Last",@"icon":@"TX_18"},
  1253. @{@"title":@"First",@"icon":@"TS_18"},
  1254. @{@"title":@"Item number a-z",@"icon":@"IX_18"},
  1255. @{@"title":@"Item number z-a",@"icon":@"IS_18"},
  1256. @{@"title":@"Description",@"icon":@"DX_18"},
  1257. @{@"title":@"Category",@"icon":@"cs_18"}
  1258. ];
  1259. __weak typeof(self) weakSelf = self;
  1260. _sortItemController.sortBlock = ^(int sort){
  1261. weakSelf.sortIndex = sort;
  1262. [weakSelf reload_data];
  1263. };
  1264. }
  1265. // _sortItemController.sortIndex = self.sortIndex;
  1266. return _sortItemController;
  1267. }
  1268. - (void)portfolioSortButtonClicked:(UIButton *)sender {
  1269. [self.view addSubview:self.sortItemController.view];
  1270. }
  1271. - (SortButton *)sortButton {
  1272. if (!_sortButton) {
  1273. _sortButton = [SortButton sortButtonWithHeight:33];
  1274. [_sortButton addTarget:self action:@selector(portfolioSortButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
  1275. }
  1276. return _sortButton;
  1277. }
  1278. - (void)setSortIndex:(int)sortIndex {
  1279. _sortIndex = sortIndex;
  1280. NSString *selectedImageName = @"";
  1281. switch (sortIndex) {
  1282. case 0:{
  1283. selectedImageName = @"TX_22";
  1284. }
  1285. break;
  1286. case 1:{
  1287. selectedImageName = @"TS_22";
  1288. }
  1289. break;
  1290. case 2:{
  1291. selectedImageName = @"IX_22";
  1292. }
  1293. break;
  1294. case 3:{
  1295. selectedImageName = @"IS_22";
  1296. }
  1297. break;
  1298. case 4:{
  1299. selectedImageName = @"DX_22";
  1300. }
  1301. break;
  1302. case 5: {
  1303. selectedImageName = @"cs_22";
  1304. }
  1305. default:
  1306. break;
  1307. }
  1308. self.sortButton.imageView.image = [UIImage imageNamed:selectedImageName];
  1309. }
  1310. #pragma mark - rotation
  1311. //- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
  1312. //
  1313. // self.sortItemController.view.frame = self.view.bounds;
  1314. //}
  1315. - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
  1316. [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
  1317. [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
  1318. // what ever you want to prepare
  1319. } completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
  1320. self.sortItemController.view.frame = self.view.bounds;
  1321. }];
  1322. }
  1323. //- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  1324. // return YES;
  1325. //}
  1326. - (BOOL)shouldAutorotate{
  1327. return YES;
  1328. }
  1329. //
  1330. //- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
  1331. // self.sortItemController.view.frame = self.view.bounds;
  1332. //}
  1333. - (void)reRefreshView {
  1334. [self.itemListTable reloadData];
  1335. }
  1336. #pragma mark - RA_NOTIFICAITON
  1337. -(void) refresh_ui
  1338. {
  1339. [self.itemListTable reloadData];
  1340. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1341. if(appDelegate.can_create_portfolio)
  1342. {
  1343. //#ifdef BUILD_UWAVER
  1344. // self.btnCreatePort.title = @"Create Hang Tag";
  1345. //#else
  1346. [self.btnCreatePort setTitle:@"Create Portfolio"];
  1347. //#endif
  1348. self.btnCreatePort.enabled = true;
  1349. }
  1350. else
  1351. {
  1352. [self.btnCreatePort setTitle:@""];
  1353. self.btnCreatePort.enabled = false;
  1354. }
  1355. }
  1356. -(void) reload_data
  1357. {
  1358. dispatch_async(dispatch_get_main_queue(), ^{
  1359. if(self.isrefreshing)
  1360. return;
  1361. self.isrefreshing=true;
  1362. self.label_net_err.hidden=true;
  1363. self.itemListTable.hidden=true;
  1364. [self.content_data removeAllObjects];
  1365. [self.itemListTable reloadData];
  1366. self.mum.center = self.view.center;
  1367. self.mum.hidden = false;
  1368. [self.mum startAnimating];
  1369. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  1370. [reF endRefreshing];
  1371. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  1372. [RANetwork request_portfoliolist:self.sortIndex completionHandler:^(NSMutableDictionary *result) {
  1373. NSMutableDictionary* cart_json =result;
  1374. [self.mum stopAnimating];
  1375. int result_code=[[cart_json valueForKey:@"result"] intValue];
  1376. if(result_code==2||result_code==1||result_code==0)
  1377. {
  1378. self.itemListTable.hidden=false;
  1379. self.content_data = [cart_json mutableCopy];
  1380. [self.itemListTable reloadData];
  1381. [self initCheckedCount];
  1382. [self.btnselect setTitle: @"Deselect all"];
  1383. UIApplication * app = [UIApplication sharedApplication];
  1384. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1385. appDelegate.port_count =[[self.content_data valueForKey:@"count"] intValue];
  1386. }
  1387. else
  1388. if(result_code==RESULT_NET_ERROR)
  1389. {
  1390. self.label_net_err.hidden=false;
  1391. self.itemListTable.hidden=true;
  1392. }
  1393. else
  1394. {
  1395. [RAUtils message_box:@"Loading Portfolio" message:[cart_json valueForKey:@"err_msg"] completion:nil];
  1396. }
  1397. self.isrefreshing=false;
  1398. }];
  1399. });
  1400. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1401. if(appDelegate.can_create_portfolio)
  1402. {
  1403. //#ifdef BUILD_UWAVER
  1404. // self.btnCreatePort.title = @"Create Hang Tag";
  1405. //#else
  1406. [self.btnCreatePort setTitle:@"Create Portfolio"];
  1407. //#endif
  1408. self.btnCreatePort.enabled = true;
  1409. }
  1410. else
  1411. {
  1412. [self.btnCreatePort setTitle:@""];
  1413. self.btnCreatePort.enabled = false;
  1414. }
  1415. }
  1416. -(void) refresh_price
  1417. {
  1418. [self refresh_ui];
  1419. }
  1420. @end