PortfolioViewController.m 73 KB

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