| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317 |
- //
- // CustomerEditViewController.m
- // RedAnt ERP Mobile
- //
- // Created by Ray on 11/4/15.
- // Copyright © 2015 United Software Applications, Inc. All rights reserved.
- //
- #import "CustomerEditViewController.h"
- #import "iSalesNetwork.h"
- #import "MainViewController.h"
- @interface CustomerEditViewController ()
- @end
- @implementation CustomerEditViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
-
-
- UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
- style:UIBarButtonItemStylePlain
- target:self
- action:@selector(onBackClick:)];
- //[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Close", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onCloseClick:)];
- // closeButton.title = @"Close";
-
- self.navigationItem.leftBarButtonItem = closeButton;
-
-
-
- // NSMutableArray * items = [[NSMutableArray alloc]init];
-
-
- UIBarButtonItem *savebtn = nil;//[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onSaveClick:)];
-
- savebtn = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"save"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
- style:UIBarButtonItemStylePlain
- target:self
- action:@selector(onSaveClick:)];
-
-
- self.navigationItem.rightBarButtonItem = savebtn;
-
- // UIBarButtonItem *btnCommit = nil;
- // btnCommit =[[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"commit"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
- // style:UIBarButtonItemStylePlain
- // target:self
- // action:@selector(onCommitOrderClick:)];
- //
- //
- //
- //
- // //savebtn setBackgroundImage:(nullable UIImage *) forState:<#(UIControlState)#> style:<#(UIBarButtonItemStyle)#> barMetrics:<#(UIBarMetrics)#>
- // //[savebtn setImage:[UIImage imageNamed:@"save"] ];
- //
- //
- // /*
- // UIBarMetricsDefault,
- // UIBarMetricsCompact,
- // UIBarMetricsDefaultPrompt = 101, // Applicable only in bars with the prompt property, such as UINavigationBar and UISearchBar
- // UIBarMetricsCompactPrompt
- //
- // */
- // // [savebtn setBackgroundImage:[UIImage imageNamed:@"save"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
- // // UIBarButtonItem *item1 = [[UIBarButtonItem alloc] init];
- // // item1.title = @"item1";
- // //// item1.image = [UIImage imageNamed:@"rect_setting"];
- // // UIBarButtonItem *item2 = [[UIBarButtonItem alloc] init];
- // //// item2.image = [UIImage imageNamed:@"rect_about"];
- // // item2.title = @"item2";
- //
- //
- // UIBarButtonItem *fixedItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
- // fixedItem.width = 20.0f;
- //
- // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- //
- // if(appDelegate.user_type ==USER_ROLE_EMPLOYEE)
- // {
- // [items addObject:savebtn];
- //
- // [items addObject:fixedItem];
- // }
- // [items addObject:btnCommit];
- // // [items addObject:item2];
- // self.navigationItem.rightBarButtonItems=items;
-
-
- // Do any additional setup after loading the view.
- }
- - (void)onBackClick:(UIButton *)sender {
- [self.navigationController popViewControllerAnimated:false];
- }
- - (void)onSaveClick:(UIButton *)sender {
- // add params check here.
- [self.lastedit endEditing:true];
- [self.lasttextview endEditing:true];
- self.cancommit=true;
- NSMutableDictionary* upparams=[[NSMutableDictionary alloc] init];
- // [upparams setValue:[self.params valueForKey:@"cart2Checkbox"] forKey:@"cart2Checkbox"];
- int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
- for(int i=0;i<section_count;i++)
- {
- NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
- int item_count = [[sectionjson valueForKey:@"count"] intValue];
- for(int j=0;j<item_count;j++)
- {
- NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
- NSString* key = [itemjson valueForKey:@"name"];
- if(key==nil || key.length==0)
- continue;
- if([[itemjson valueForKey:@"control"] isEqualToString:@"enum"])
- {
- NSString* single_select = [itemjson valueForKey:@"single_select"];
- if([single_select isEqualToString:@"true"])
- {
- NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
- int count = [[cadejson valueForKey:@"count"] intValue];
- bool setvalue = false;
- for(int cc=0;cc<count;cc++)
- {
- NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
- if([[valjson valueForKey:@"check"]intValue]==1)
- {
- [upparams setValue:[valjson valueForKey:@"value_id"] forKey:[itemjson valueForKey:@"name"]];
- setvalue=true;
- break;
- }
- }
- if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && setvalue==false)
- {
- self.cancommit = false;
- }
- }
- else
- {
-
- NSMutableArray* checked = [[NSMutableArray alloc] init];
- NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
- int count = [[cadejson valueForKey:@"count"] intValue];
- // bool setvalue = false;
- for(int cc=0;cc<count;cc++)
- {
- NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
- if([[valjson valueForKey:@"check"]intValue]==1)
- {
-
- [checked addObject:[NSNumber numberWithInt:[[valjson valueForKey:@"value_id"] intValue]]];
- // [upparams setValue:[valjson valueForKey:@"value_id"] forKey:[itemjson valueForKey:@"name"]];
- // setvalue=true;
- // break;
- }
- }
- if([[itemjson valueForKey:@"required"] isEqualToString: @"true"]&&checked.count==0)
- {
- self.cancommit = false;
- }
- else
- {
- NSString * string = [checked componentsJoinedByString:@","];
- [upparams setValue:string forKey:[itemjson valueForKey:@"name"]];
- }
- }
- /*
- upparams setValue:itemjson forKey:<#(NSString *)#>
-
- */
- }else
- if([[itemjson valueForKey:@"control"] isEqualToString:@"action"])
- {
- if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"data"]==nil)
- self.cancommit = false;
- }
- else if([[itemjson valueForKey:@"control"] isEqualToString:@"switch"])
- {
- NSString* valuestr = [itemjson valueForKey:@"value"];
- [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
-
- NSString* value = [itemjson valueForKey:@"value"];
- NSMutableDictionary* boolitem=nil;
- NSMutableDictionary* subjson=nil;
- if([value isEqualToString:@"true"])
- {
- boolitem =[[itemjson objectForKey:@"true"] mutableCopy];
-
- }
- else
- {
- boolitem =[[itemjson objectForKey:@"false"] mutableCopy];
-
- }
- subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy];
- if( subjson!=nil /*&& !active*/)
- {
- int sub_count = [[subjson valueForKey:@"count"] intValue];
- for(int l=0;l<sub_count;l++)
- {
- NSMutableDictionary * modify_item=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
-
-
-
-
- if([modify_item valueForKey:@"value"]!=nil && ![[modify_item valueForKey:@"value"]isEqualToString:@""])
- [upparams setValue:[modify_item valueForKey:@"value"] forKey:[modify_item valueForKey:@"name"]];
- else
- {
- if([[modify_item valueForKey:@"required"] isEqualToString: @"true"] )
- self.cancommit = false;
- }
- }
-
-
-
- }
- }
- else
- if([[itemjson valueForKey:@"control"] isEqualToString:@"img"])
- {
- if([itemjson valueForKey:@"avalue"]!=nil && ![[itemjson valueForKey:@"avalue"]isEqualToString:@""])
- [upparams setValue:[itemjson valueForKey:@"avalue"] forKey:[itemjson valueForKey:@"name"]];
- else
- {
- if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
- self.cancommit = false;
- }
- }
- else
- {
- if([itemjson valueForKey:@"value"]!=nil && ![[itemjson valueForKey:@"value"]isEqualToString:@""])
- [upparams setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]];
- else
- {
- if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
- self.cancommit = false;
- }
- }
- upparams= [self subitem_param:itemjson addto:upparams ];
- }
- }
- if(self.cancommit==false)
- {
- [RAUtils alert_view:@"Fields with * mark cannot be empty." title:@"Some Requried Fields Are Missing."];
- self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
- //NSLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
- //[self.editorTable reloadData ];
- [self.editorTable reloadData];
- return;
- }
- UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Saving Contact"];
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSDictionary* editor_json = nil;
- // NSString* contactId=[upparams valueForKey:@"contactId"];
- if(self.bnewcustomer )
- editor_json=[iSalesNetwork save_newCustomer:upparams];
- else
- editor_json=[iSalesNetwork update_Customer:upparams];
-
- dispatch_async(dispatch_get_main_queue(), ^{
- [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
-
-
- if([[editor_json valueForKey:@"result"] intValue]==2)
- {
- // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
- //
- //
- // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- // appDelegate.customerInfo = customerInfo;
- // appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
- // // self.labelContact.text=appDelegate.contact_name;
- //
- // NSDictionary * customerinfo = appDelegate.customerInfo;
- [self prepareReturn:nil];
- if(self.bnewcustomer )
- [self.navigationController popViewControllerAnimated:false];
- else
- [self.navigationController popToRootViewControllerAnimated:false];
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- [((MainViewController*)appDelegate.main_vc) reloadContact:true immediately:false];
-
-
-
- }
- else
- {
- [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Save Order" controller:self] ;
- }
-
-
-
-
- });
- });
-
-
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- /*
- #pragma mark - Navigation
-
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|