Senior & Expert RoR Developers Discussion Forum by Nyros Technologies

HIRE Ruby on Rails Expert Developers Programmers Coders From India
Ruby on Rails PHP .Net Developers Community, Nyros Technologies, Kakinada
 
Log in  or IF not a member please REGISTER
Username:
Password:   


Keyword
Log in | Profile 

Generation of Account Code (ex: TEST0001)

 
Post new topic   Reply to topic    Senior & Expert RoR Developers Discussion Forum by Nyros Technologies Index -> A little Ruby programming (Basic programming in RoR)
View previous topic :: View next topic  
Author Message
Anu



Joined: 01 Jan 2010
Posts: 82

PostPosted: Tue Jul 13, 2010 11:06 am    Post subject: Generation of Account Code (ex: TEST0001) Reply with quote

Hi All,

In my project i met a requirment to generate the some code.its in a size of 8 digits.

For Example:

If your filling the company name of your organisation,then it have to generate the code automatically like the below,

Comapny name : NYROS Techonologies
(it has to generate the account code like (NYRO0001))
* If the company name again repated or anyother user enters the same company name then the code for that corresponding company should be NYRO0002.
* It means that the company code is diffrent from one and each other.

~~~~~~~~~~~
To Implement this written a method in the controller:

def generate_account_code(var)
if var
company_data = Company.find(:all, :conditions => ["code like ?, var])
if !company_data.blank?
var_size = company_data.size
var_size_final = var_size+1
if var_size >= 1 && var_size <= 9

return new_code = var+"000"+var_size_final.to_s
elsif var_size >= 10 && var_size <= 99
return new_code = var+"00"+var_size_final.to_s
elsif var_size >= 100 && var_size <= 999
return new_code = var+"0"+var_size_final.to_s
else
return new_code = var+var_size.to_s
end
else
return new_code = var+"0001"
end
end
end

In the above code iam taking the first 4 characters of the company name by using the strip method,and saved that data in the "code",variable.which is used as var above.

To extract the first 4 characters of the string,we need to use the strip method:

code = @company_name.strip[0,4]

and after that we are calculating the size of the same code strings(incase of same company names),if the company is name new ,then it will generate the code like the first 4 characters of the company name,and 0001.

If the company name is already existed,and founded the size of the code like 2,then the code added like "NYR00002"




Thank you,
Anu Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Senior & Expert RoR Developers Discussion Forum by Nyros Technologies Index -> A little Ruby programming (Basic programming in RoR)
Page 1 of 1

 latest topics 
 Topics   Replies   Author   Views   Last Post 
No new posts Chat utility in a ROR application
0 shobana 2 Thu Sep 09, 2010 9:45 am
shobana View latest post
No new posts How to customize Google Maps InfoWindow using ym4r_gm
0 kalyanallampalli 54 Thu Sep 02, 2010 5:34 pm
kalyanallampalli View latest post
No new posts Drag and Drop file upload
0 umamageshwari 51 Wed Sep 01, 2010 9:36 am
umamageshwari View latest post
No new posts Flex On Rails
0 Raghu 48 Wed Sep 01, 2010 3:00 am
Raghu View latest post
No new posts MongoDB
0 Raghu 45 Tue Aug 31, 2010 3:30 pm
Raghu View latest post
No new posts Problem with Dreamweaver / java error
3 Raja 37 Tue Aug 31, 2010 3:24 pm
Raghu View latest post
No new posts Generating Model
0 phani.galla 44 Tue Aug 31, 2010 2:09 pm
phani.galla View latest post
No new posts Hide Panels using JQuery
0 Anu 48 Tue Aug 31, 2010 1:50 pm
Anu View latest post
No new posts Load a text file using ajax in jquery
0 Anu 38 Tue Aug 31, 2010 1:39 pm
Anu View latest post
No new posts Generating Migrations
0 phani.galla 31 Tue Aug 31, 2010 1:38 pm
phani.galla View latest post




Hire an expert Ruby on Rails developer / coder / programmer or development team from India now!!

Other Forums : PHP   ::   .Net   |   Free unlimited HTML CSS templates download

Nyros Technologies   |   Kakinada City Portal   |   Developers Blog   |   About Ruby on Rails Experts   |   More