PortfolioViewController.m 76 KB

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