Skip to content

Commit

Permalink
Merge pull request #78 from dhanasingh/dev
Browse files Browse the repository at this point in the history
v2.5.2
  • Loading branch information
karthickmadhiazhagan authored Nov 18, 2016
2 parents eb3367d + 1c30860 commit ca484c0
Show file tree
Hide file tree
Showing 20 changed files with 289 additions and 136 deletions.
4 changes: 2 additions & 2 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ If an apache passenger module is used then make sure the following settings are
b) RailsAppSpawnerIdleTime 0
c) PassengerPreStart http://rails-app-url/

Release Notes for 2.5.1
Release Notes for 2.5.2
Features:
- Billing module is introduced.
BugFixing:
- Payroll usersettings tab not working.
- Fixed: Account validation not working on mac safari.

Customization:
For any Customization/Support, please contact us, our consulting team will be happy to help you
Expand Down
27 changes: 15 additions & 12 deletions app/controllers/wkaccount_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ def edit
@accountEntry = nil
unless params[:account_id].blank?
@accountEntry = WkAccount.find(params[:account_id])
else
@accountEntry = @accountEntry
end
end

def update
errorMsg = nil
wkaddress = nil
if params[:address_id].blank? || params[:address_id].to_i == 0
wkaddress = WkAddress.new
else
Expand All @@ -52,32 +52,35 @@ def update
wkaddress.address1 = params[:address1]
wkaddress.address2 = params[:address2]
wkaddress.work_phone = params[:work_phone]
wkaddress.home_phone = params[:home_phone]
wkaddress.city = params[:city]
wkaddress.state = params[:state]
wkaddress.pin = params[:pin]
wkaddress.mobile = params[:mobile]
wkaddress.email = params[:email]
wkaddress.country = params[:country]
wkaddress.fax = params[:fax]
wkaddress.save()
address_id = wkaddress.id
unless wkaddress.valid?
errorMsg = wkaddress.errors.full_messages.join("<br>")
end
if params[:account_id].blank? || params[:account_id].to_i == 0
wkaccount = WkAccount.new
else
wkaccount = WkAccount.find(params[:account_id].to_i)
end
wkaccount.address_id = address_id
#wkaccount.address_id = wkaddress.id
wkaccount.name = params[:name]
wkaccount.account_type = 'A'
wkaccount.account_billing = params[:account_billing].blank? ? 0 : params[:account_billing]
wkaccount.save()
if wkaccount.save()
unless wkaccount.valid?
errorMsg = errorMsg.blank? ? wkaccount.errors.full_messages.join("<br>") : wkaccount.errors.full_messages.join("<br>") + "<br/>" + errorMsg
end
if errorMsg.nil?
wkaddress.save
wkaccount.address_id = wkaddress.id
wkaccount.save
redirect_to :controller => 'wkaccount',:action => 'index' , :tab => 'wkaccount'
flash[:notice] = l(:notice_successful_update)
else
redirect_to :controller => 'wkaccount',:action => 'edit' , :tab => 'wkaccount'
flash[:error] = wkaccount.errors.full_messages.join("<br>")
flash[:error] = errorMsg #wkaccount.errors.full_messages.join("<br>")
redirect_to :controller => 'wkaccount',:action => 'edit', :account_id => wkaccount.id
end
end

Expand Down
39 changes: 32 additions & 7 deletions app/controllers/wkinvoice_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def edit
@invoice = WkInvoice.find(params[:invoice_id].to_i)
@invoiceItem = @invoice.invoice_items
unless params[:is_report].blank? || !to_boolean(params[:is_report])
@invoiceItem = @invoiceItem.order(:project_id, :item_type)
render :action => 'invreport', :layout => false
end

Expand All @@ -77,29 +78,41 @@ def invreport
def update
errorMsg = nil
invoiceItem = nil
invItemId = WkInvoiceItem.select(:id).where(:invoice_id => params["invoice_id"].to_i)
arrId = invItemId.map {|i| i.id }
#invItemId = WkInvoiceItem.select(:id).where(:invoice_id => params["invoice_id"].to_i)
#arrId = invItemId.map {|i| i.id }
@invoice = WkInvoice.find(params["invoice_id"].to_i)
arrId = @invoice.invoice_items.pluck(:id)
@invoice.status = params[:field_status]
if @invoice.status_changed?
@invoice.closed_on = Time.now
@invoice.save()
end
totalAmount = 0
tothash = Hash.new
for i in 1..(params[:totalrow].to_i)
if !params["item_id#{i}"].blank?
totalRow = params[:totalrow].to_i
savedRows = 0
deletedRows = 0
#for i in 1..totalRow
while savedRows < totalRow
i = savedRows + deletedRows + 1
if params["item_id#{i}"].blank? && params["project_id#{i}"].blank?
deletedRows = deletedRows + 1
next
end
unless params["item_id#{i}"].blank?
arrId.delete(params["item_id#{i}"].to_i)
invoiceItem = WkInvoiceItem.find(params["item_id#{i}"].to_i)
updatedItem = updateInvoiceItem(invoiceItem, params["project_id#{i}"], params["name#{i}"], params["rate#{i}"].to_f, params["quantity#{i}"].to_f, invoiceItem.currency)
else
else
invoiceItem = @invoice.invoice_items.new
updatedItem = updateInvoiceItem(invoiceItem, params["project_id#{i}"], params["name#{i}"], params["rate#{i}"].to_f, params["quantity#{i}"].to_f, params["currency#{i}"])
end
savedRows = savedRows + 1
tothash[updatedItem.project_id] = [(tothash[updatedItem.project_id].blank? ? 0 : tothash[updatedItem.project_id][0]) + updatedItem.amount, updatedItem.currency]
end

if !arrId.blank?
deleteBilledEntries(arrId)
WkInvoiceItem.delete_all(:id => arrId)
end

Expand All @@ -109,6 +122,13 @@ def update
addTaxes(accountProject[0], val[1], val[0])
end

unless @invoice.id.blank?
totalAmount = @invoice.invoice_items.sum(:amount)
if (totalAmount.round - totalAmount) != 0
addRoundInvItem(totalAmount)
end
end

if errorMsg.nil?
redirect_to :action => 'index' , :tab => 'wkinvoice'
flash[:notice] = l(:notice_successful_update)
Expand All @@ -119,11 +139,16 @@ def update
end

def destroy
WkInvoice.find(params[:invoice_id].to_i).destroy

invoice = WkInvoice.find(params[:invoice_id].to_i)#.destroy
deleteBilledEntries(invoice.invoice_items.pluck(:id))
invoice.destroy
flash[:notice] = l(:notice_successful_delete)
redirect_back_or_default :action => 'index', :tab => params[:tab]
end

def deleteBilledEntries(invItemIdsArr)
CustomField.find(getSettingCfId('wktime_billing_id_cf')).custom_values.where(:value => invItemIdsArr).delete_all unless getSettingCfId('wktime_billing_id_cf').blank? || getSettingCfId('wktime_billing_id_cf') == 0
end

def getAccountProjIds
accArr = ""
Expand Down
64 changes: 55 additions & 9 deletions app/helpers/wkinvoice_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,27 @@ def addInvoice(accountId, projectId, invoiceDate,invoicePeriod)
@invoice.modifier_id = User.current.id
@invoice.account_id = accountId
@invoice.invoice_number = getPluginSetting('wktime_invoice_no_prefix')
if !@invoice.save
errorMsg = generateInvoiceItems(projectId)
unless @invoice.id.blank?
totalAmount = @invoice.invoice_items.sum(:amount)
if (totalAmount.round - totalAmount) != 0
addRoundInvItem(totalAmount)
end
end
errorMsg
end

def saveInvoice
errorMsg = nil
unless @invoice.save
errorMsg = @invoice.errors.full_messages.join("<br>")
else
@invoice.invoice_number = @invoice.invoice_number + @invoice.id.to_s
@invoice.save
errorMsg = generateInvoiceItems(projectId)
end
errorMsg
end

def generateInvoices(accountId, projectId, invoiceDate,invoicePeriod)
errorMsg = nil
account = WkAccount.find(accountId)
Expand All @@ -51,27 +62,33 @@ def generateInvoices(accountId, projectId, invoiceDate,invoicePeriod)
def generateInvoiceItems(projectId)
if projectId.blank? || projectId.to_i == 0
WkAccountProject.where(account_id: @invoice.account_id).find_each do |accProj|
addInvoiceItem(accProj)
errorMsg = addInvoiceItem(accProj)
end
else
accountProject = WkAccountProject.where("account_id = ? and project_id = ?", @invoice.account_id, projectId)
addInvoiceItem(accountProject[0])
errorMsg = addInvoiceItem(accountProject[0])
end
errorMsg = nil
errorMsg
end

def addInvoiceItem(accountProject)
if accountProject.billing_type == 'TM'
# Add invoice items for Time and Materiel cost
saveTAMInvoiceItem(accountProject)
errorMsg = saveTAMInvoiceItem(accountProject)
else
# Add invoice item for fixed cost from the scheduled entries
errorMsg = nil
genInvFrom = Setting.plugin_redmine_wktime['wktime_generate_invoice_from']
genInvFrom = genInvFrom.blank? ? @invoice.start_date : genInvFrom.to_date
scheduledEntries = accountProject.wk_billing_schedules.where(:account_project_id => accountProject.id, :bill_date => genInvFrom .. @invoice.end_date, :invoice_id => nil)
totalAmount = 0
scheduledEntries.each do |entry|
if @invoice.id.blank?
errorMsg = saveInvoice
unless errorMsg.blank?
break
end
end
invItem = saveFCInvoiceItem(entry)
totalAmount = totalAmount + invItem.amount
entry.invoice_id = @invoice.id
Expand All @@ -83,6 +100,7 @@ def addInvoiceItem(accountProject)
addTaxes(accountProject, scheduledEntries[0].currency, totalAmount)
end
end
errorMsg
end

# Add the invoice items for the scheduled entries
Expand All @@ -107,6 +125,7 @@ def saveTAMInvoiceItem(accountProject)
genInvFrom = genInvFrom.blank? ? @invoice.start_date : genInvFrom.to_date
timeEntries = TimeEntry.joins("left outer join custom_values on time_entries.id = custom_values.customized_id and custom_values.customized_type = 'TimeEntry' and custom_values.custom_field_id = #{getSettingCfId('wktime_billing_id_cf')}").where(project_id: accountProject.project_id, spent_on: genInvFrom .. @invoice.end_date).where("custom_values.value is null OR #{getSqlLengthQry("custom_values.value")} = 0 ")

errorMsg = nil
totalAmount = 0
lastUserId = 0
lastIssueId = 0
Expand All @@ -126,6 +145,12 @@ def saveTAMInvoiceItem(accountProject)
updateBilledHours(entry, lasInvItmId)
next
end
if @invoice.id.blank?
errorMsg = saveInvoice
unless errorMsg.blank?
break
end
end
invItem = @invoice.invoice_items.new()
lastUserId = entry.user_id
lastIssueId = entry.issue_id
Expand All @@ -149,6 +174,12 @@ def saveTAMInvoiceItem(accountProject)
next
end
lastIssueId = entry.issue_id
if @invoice.id.blank?
errorMsg = saveInvoice
unless errorMsg.blank?
break
end
end
invItem = @invoice.invoice_items.new()
if accountProject.itemized_bill
description = entry.issue.blank? ? entry.project.name : (accountProject.account.account_billing ? entry.project.name + ' - ' + entry.issue.subject : entry.issue.subject)
Expand All @@ -165,7 +196,8 @@ def saveTAMInvoiceItem(accountProject)
end
if accountProject.apply_tax && totalAmount>0
addTaxes(accountProject, rateHash['currency'], totalAmount)
end
end
errorMsg
end

# Update invoice item by the given invoice item Object
Expand Down Expand Up @@ -222,7 +254,7 @@ def addTaxes(accountProject, currency, totalAmount)
projectTaxes = accountProject.wk_acc_project_taxes
projectTaxes.each do |projtax|
invItem = @invoice.invoice_items.new()
invItem.name = accountProject.project.name + ' - ' + projtax.tax.name
invItem.name = projtax.tax.name
invItem.rate = projtax.tax.rate_pct.blank? ? 0 : projtax.tax.rate_pct
invItem.project_id = accountProject.project_id
invItem.currency = currency
Expand All @@ -234,6 +266,20 @@ def addTaxes(accountProject, currency, totalAmount)
end
end

# Add an invoice item for the round off value
def addRoundInvItem(totalAmount)
invItem = @invoice.invoice_items.new()
invItem.name = l(:label_round_off)
invItem.rate = nil
invItem.project_id = @invoice.invoice_items[0].project_id
invItem.currency = @invoice.invoice_items[0].currency
invItem.quantity = nil
invItem.amount = totalAmount.round - totalAmount
invItem.item_type = 'r'
invItem.modifier_id = User.current.id
invItem.save()
end

# Return the Query string with SQL length function for the given column
def getSqlLengthQry(column)
if ActiveRecord::Base.connection.adapter_name == 'SQLServer'
Expand Down
1 change: 1 addition & 0 deletions app/models/wk_account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class WkAccount < ActiveRecord::Base
has_many :invoice_items, through: :invoices
has_many :projects, through: :wk_account_projects
has_many :contracts, foreign_key: "account_id", class_name: "WkContract", :dependent => :destroy
validates_presence_of :name

# Returns account's contracts for the given project
# or nil if the account do not have contract
Expand Down
2 changes: 2 additions & 0 deletions app/models/wk_address.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class WkAddress < ActiveRecord::Base
unloadable
has_many :wk_accounts, foreign_key: "address_id", class_name: "WkAccount"
validates_presence_of :address1, :work_phone, :fax, :city, :state, :country
validates_numericality_of :pin, :only_integer => true, :greater_than_or_equal_to => 0, :message => :invalid
end
4 changes: 2 additions & 2 deletions app/views/wkaccount/_account_list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<th class="lbl-txt-align"><%= l(:label_account_name) %></th>
<th class="lbl-txt-align"><%= l(:label_account_address) %></th>
<th class="lbl-txt-align"><%= l(:label_work_phone) %></th>
<th class="lbl-txt-align"><%= l(:label_email) %></th>
<!-- <th class="lbl-txt-align"><%= l(:label_email) %></th> -->
<th class="lbl-txt-align"><%= l(:label_country) %></th>
<th class="lbl-txt-align"><%= l(:label_city) %></th>
<th></th>
Expand All @@ -18,7 +18,7 @@
<td class="lbl-txt-align"><%=h entry.name %></td>
<td class="lbl-txt-align"><%=h entry.address.blank? ? "" : entry.address.address1 %></td>
<td class="lbl-txt-align"><%=h entry.address.blank? ? "" : entry.address.work_phone %></td>
<td class="lbl-txt-align"><%=h entry.address.blank? ? "" : entry.address.email %></td>
<!-- <td class="lbl-txt-align"><%=h entry.address.blank? ? "" : entry.address.email %></td> -->
<td class="lbl-txt-align"><%=h entry.address.blank? ? "" : entry.address.country %></td>
<td class="lbl-txt-align"><%=h entry.address.blank? ? "" : entry.address.city %></td>
<td align="center">
Expand Down
Loading

0 comments on commit ca484c0

Please sign in to comment.