diff --git a/README.rdoc b/README.rdoc
index 827f6a57b..2a589ecd1 100644
--- a/README.rdoc
+++ b/README.rdoc
@@ -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
diff --git a/app/controllers/wkaccount_controller.rb b/app/controllers/wkaccount_controller.rb
index 073f7113a..86df37ac9 100644
--- a/app/controllers/wkaccount_controller.rb
+++ b/app/controllers/wkaccount_controller.rb
@@ -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
@@ -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("
")
+ 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("
") : wkaccount.errors.full_messages.join("
") + "
" + 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("
")
+ flash[:error] = errorMsg #wkaccount.errors.full_messages.join("
")
+ redirect_to :controller => 'wkaccount',:action => 'edit', :account_id => wkaccount.id
end
end
diff --git a/app/controllers/wkinvoice_controller.rb b/app/controllers/wkinvoice_controller.rb
index 56fb2d0ab..c5ca56c09 100644
--- a/app/controllers/wkinvoice_controller.rb
+++ b/app/controllers/wkinvoice_controller.rb
@@ -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
@@ -77,9 +78,10 @@ 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
@@ -87,19 +89,30 @@ def update
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
@@ -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)
@@ -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 = ""
diff --git a/app/helpers/wkinvoice_helper.rb b/app/helpers/wkinvoice_helper.rb
index d82a6b2b1..486e40bbb 100644
--- a/app/helpers/wkinvoice_helper.rb
+++ b/app/helpers/wkinvoice_helper.rb
@@ -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("
")
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)
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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)
@@ -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
@@ -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
@@ -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'
diff --git a/app/models/wk_account.rb b/app/models/wk_account.rb
index 290e04d57..ecd7a8e39 100644
--- a/app/models/wk_account.rb
+++ b/app/models/wk_account.rb
@@ -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
diff --git a/app/models/wk_address.rb b/app/models/wk_address.rb
index f3323514f..29958e84d 100644
--- a/app/models/wk_address.rb
+++ b/app/models/wk_address.rb
@@ -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
diff --git a/app/views/wkaccount/_account_list.html.erb b/app/views/wkaccount/_account_list.html.erb
index f2b282355..6ec04535f 100644
--- a/app/views/wkaccount/_account_list.html.erb
+++ b/app/views/wkaccount/_account_list.html.erb
@@ -6,7 +6,7 @@
<%= l(:label_account_name) %> |
<%= l(:label_account_address) %> |
<%= l(:label_work_phone) %> |
- <%= l(:label_email) %> |
+
<%= l(:label_country) %> |
<%= l(:label_city) %> |
|
@@ -18,7 +18,7 @@
<%=h entry.name %> |
<%=h entry.address.blank? ? "" : entry.address.address1 %> |
<%=h entry.address.blank? ? "" : entry.address.work_phone %> |
- <%=h entry.address.blank? ? "" : entry.address.email %> |
+
<%=h entry.address.blank? ? "" : entry.address.country %> |
<%=h entry.address.blank? ? "" : entry.address.city %> |
diff --git a/app/views/wkaccount/edit.html.erb b/app/views/wkaccount/edit.html.erb
index be81e539a..9c98886bf 100644
--- a/app/views/wkaccount/edit.html.erb
+++ b/app/views/wkaccount/edit.html.erb
@@ -2,14 +2,14 @@
<%=@accountEntry.blank? ? l(:label_new_account) : l(:label_edit_account) %>
|