Skip to content

Commit

Permalink
Merge branch 'qa'
Browse files Browse the repository at this point in the history
  • Loading branch information
smeeks committed Mar 13, 2023
2 parents edd3ec5 + 81b89df commit fcf34a7
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 28 deletions.
21 changes: 16 additions & 5 deletions app/controllers/draft_budget_allocations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,20 @@ def new
def create
@draft_budget_allocation = DraftBudgetAllocation.new
respond_to do |format|
if @draft_budget_allocation.update(form_params)
format.html { redirect_to draft_project_phase_path(@draft_budget_allocation.draft_project_phase)}
if form_params[:amount].to_i > DraftFundingRequest.find(form_params[:draft_funding_request_id]).draft_project_phase.remaining
error_message = "Allocation amount can not exceed remaining project phase cost.
Please enter an amount no larger than $#{DraftFundingRequest.find(form_params[:draft_funding_request_id]).draft_project_phase.remaining}."
elsif form_params[:amount].to_i < 0
error_message = "Allocation amount must be a positive integer."
else
format.html
if @draft_budget_allocation.update(form_params)
format.html { redirect_to draft_project_phase_path(@draft_budget_allocation.draft_project_phase)}
else
format.html
end
end
flash.alert = error_message
format.html { redirect_back(fallback_location: root_path) }
end
end

Expand All @@ -66,13 +75,15 @@ def destroy

def lock_me
allocation_to_loc = DraftBudgetAllocation.find_by(object_key: params[:allocation_id])
total_request_amount = allocation_to_loc.amount.to_f / allocation_to_loc.effective_pct.to_f
total_request_amount = ((params[:amount] || allocation_to_loc.amount).to_f / allocation_to_loc.effective_pct.to_f).round()
funding_request = allocation_to_loc.draft_funding_request
accumulated = 0.0
funding_request.ordered_allocations.each do |alloc|
calc_amount = (alloc.effective_pct.to_f * total_request_amount.to_f).floor()
if(alloc.required_pct == 1.0)
alloc.amount = total_request_amount - accumulated
elsif(alloc.object_key == params[:allocation_id])
alloc.amount = params[:amount]
else
alloc.amount = calc_amount
end
Expand All @@ -81,7 +92,7 @@ def lock_me
end

respond_to do |format|
format.html { redirect_to draft_project_phase_path(allocation_to_loc.draft_project_phase) }
format.json {}
end
end

Expand Down
6 changes: 5 additions & 1 deletion app/mailers/cpt_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ def transition(emails, subject, scenario)
@app_title = ENV["APPLICATION_TITLE"] ? ENV["APPLICATION_TITLE"] : 'TransAM Application'
@scenario = scenario
@subject = subject
mail(to: emails, subject: subject)
if Rails.env == 'production'
mail(to: emails, subject: subject)
else
mail(to: '[email protected]', subject: subject, body: emails.join("\n"))
end
end

end
7 changes: 4 additions & 3 deletions app/models/scenario.rb
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,9 @@ def past_tense transition
return "rejected"
when "submit"
return "submitted"
end
when "reopen"
return "reopened"
end
end

def state_title
Expand Down Expand Up @@ -459,8 +461,7 @@ def send_transition_email transition
if users.blank? #No managers here, send to all users at this org
users = User.where(organization: state_owner)
end
#emails = users.pluck(:email)
emails = ["[email protected]"] #TODO Leave this here. Remove only when going to QA.
emails = users.pluck(:email)

CptMailer.transition(emails, subject, self).deliver! unless emails.blank?
end
Expand Down
58 changes: 49 additions & 9 deletions app/views/draft_project_phases/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@
="Funding Request #{count+=1}"
=render partial: "shared/draft_funding_request_partial", locals: {funding_request: funding_request, budgets: @draft_budgets}

// Funding
%div.row
.col-md-12.text-center
%h4
="Funding Request"
=link_to draft_funding_requests_url(draft_project_phase_id: @draft_project_phase.object_key), method: :post, class: "btn btn-info btn-xs" do
%i.fa.fa-plus

// Milestones
%div.row
.col-md-12
Expand Down Expand Up @@ -143,10 +151,11 @@
success: function(data) {
console.log("updated allocation");

let total = sum_a($(root).find(".unedit"));
let allocationTotal = sum_a($(root).find(".unedit"));
let grandTotal = parseFloat(sum_a($(".unedit")));

$(".unedit").each(function(alloc) {
let actual = (100*(parseFloat($(this).text().replace(/[^\d\.\-eE+]/g, ""))/parseFloat('#{@draft_project_phase.cost}')));
$(root).find(".unedit").each(function(alloc) {
let actual = (100*(parseFloat($(this).text().replace(/[^\d\.\-eE+]/g, ""))/parseFloat(sum_a($(root).find(".unedit")))));
// update actual %
$(this).parent().siblings(".alloc_actual").html((actual.toFixed(3) || 0) + "%");
});
Expand All @@ -157,14 +166,14 @@
// $(x.target).parent().siblings(".alloc_actual").html(actual.toFixed(3) + "%");

// update totals
$(root).find(".fr_total").html('$' + total.toLocaleString());
$(root).find(".fr_total").html('$' + allocationTotal.toLocaleString());
let allocatedHtmlArr = $(".allocated").html().split("\n");
let remainingHtmlArr = $(".remaining").html().split("\n");
allocatedHtmlArr[4] = '$' + total.toLocaleString();
allocatedHtmlArr[4] = '$' + grandTotal.toLocaleString();
remainingHtmlArr[4] = '$' + remaining_allocation.toLocaleString();
$(".allocated").html(allocatedHtmlArr.join("\n"));
$(".remaining").html(remainingHtmlArr.join("\n"));
let percentFunded = Math.round(100*(total/parseFloat('#{@draft_project_phase.cost}')));
let percentFunded = Math.round(100*(grandTotal/parseFloat('#{@draft_project_phase.cost}')));
if (percentFunded == 100 && remaining_allocation > 0) {
percentFunded = 99;
}
Expand Down Expand Up @@ -234,7 +243,38 @@
};



// lock allocation
$(document).on("click", ".alloc_lock", (x)=>{

let root = $(x.target).closest(".allocation_row");
let old_total = parseFloat($(root).closest(".dfrp").find(".unedit_total").text().replace(/[^\d\.\-eE+]/g, ""));
let amount = Math.floor(parseFloat($(root).find("input.edit").val()) || 0).toString();
let effectivePct = parseFloat($(root).find("div")[2].innerText) / 100;
let id = $(x.target).data("allocationId");
let objectKey = $(x.target).data("objectKey");

if (parseFloat(amount) < 0) {
alert("Allocated value can not be a negative number.");
} else if (Math.round(parseFloat(amount)/effectivePct) > Math.round(old_total + remaining_allocation)) {
alert("Locking the entered allocation would result in a total of $" + Math.round(parseFloat(amount)/effectivePct) +
" being applied to this funding request, which exceeds the remaining project cost. " +
"Please enter a value no higher than " + Math.floor((old_total + remaining_allocation) * effectivePct) + " for this allocation.");
} else {
// Make Call to Update the Total
$.ajax({
url: "/draft_budget_allocations/"+id+"/lock_me",
data: {"amount":amount,"allocation_id":objectKey},
method: 'PATCH',
dataType: 'json',
success: function(data) {
location.reload();
},
error: function(e) {
console.log(e);
}
});
}
});



Expand All @@ -246,7 +286,7 @@
if (updated_total < 0) {
alert("Total allocation can not be a negative number.");
$(x.target).prop("checked", true);
} else if (updated_total > #{@draft_project_phase.cost}) {
} else if (updated_total > remaining_allocation + parseFloat($(x.target).siblings(".unedit_total").text().replace(/[^\d\.\-eE+]/g, "") || "0")) {
alert("Total allocation can not exceed project phase cost.");
$(x.target).prop("checked", true);
} else {
Expand Down Expand Up @@ -281,7 +321,7 @@
let root = $(x.target).closest(".dfrp");
let total = $(root).find("input.edit.edit_total").val();

if (parseFloat(total) >= 0 && parseFloat(total) <= #{@draft_project_phase.cost}) {
if (parseFloat(total) >= 0 && parseFloat(total) <= remaining_allocation + parseFloat($(root).find(".unedit_total").text().replace(/[^\d\.\-eE+]/g, ""))) {
var cancel_id = x.target.id;
var fs_id = cancel_id.split("_")[1];
var edit_id = "#edit_" + fs_id;
Expand Down
46 changes: 37 additions & 9 deletions app/views/shared/_draft_funding_request_partial.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@



.dfrp
.dfrp{id: "#{funding_request.object_key}RequestContainer"}
-funding_request.violations.each do |violation|
%h5
%i.fa.fa-exclamation-triangle
Expand Down Expand Up @@ -64,7 +64,7 @@
="#{(100*effective_pct).round(3)}%"
-remaining_pct = remaining_pct*(1-(allocation.required_pct))
.col-md-1.alloc_actual
-cost = @draft_project_phase.cost
-cost = funding_request.total
="#{allocation.amount > 0 && cost > 0 ? (100*(allocation.amount.to_f/cost.to_f)).round(3) : 0}%"
.col-md-3.text-right
%input.edit{type:'number',value:"#{allocation.amount}", style:"display:none"}
Expand All @@ -75,12 +75,16 @@
%i.fa.fa-edit.trigger_toggle_edit
%i.fa.fa-check.trigger_toggle_edit.confirm_edit{style:"display:none"}
%i.fa.fa-times.cancel_edit{style:"display:none"}
-# =link_to lock_me_draft_budget_allocation_path(allocation_id:allocation), method: :patch do
-# %i.fa.fa-lock.alloc_lock
-# =link_to draft_budget_allocation_path(allocation), method: :delete do
-# %i.fa.fa-trash
%i.fa.fa-lock.alloc_lock{data:{allocation_id: allocation.id, object_key: allocation.object_key}}
=link_to draft_budget_allocation_path(allocation), method: :delete do
%i.fa.fa-trash

.row
.row.add-allocation
.col-md-3.text-center
=link_to new_draft_budget_allocation_url(draft_funding_request_id: funding_request.object_key) do
%i.fa.fa-plus

.row
.row
.col-md-9
.col-md-2
Expand Down Expand Up @@ -110,10 +114,11 @@
$(document).on("click", "##{funding_request.object_key} .lock_total", (x)=>{

let root = $(x.target).closest(".dfrp");
let old_value = parseFloat($(root).find(".unedit_total").text().replace(/[^\d\.\-eE+]/g, ""));
let total = Math.floor(parseFloat($(root).find("input.edit.edit_total").val()) || 0).toString();
let id = "#{funding_request.object_key}";

if (parseFloat(total) >= 0 && parseFloat(total) <= #{@draft_project_phase.cost}) {
if (parseFloat(total) >= 0 && parseFloat(total) <= remaining_allocation + old_value) {
// Make Call to Update the Total
$.ajax({
url: "/draft_funding_requests/"+id+"/lock_total",
Expand All @@ -128,4 +133,27 @@
}
});
}
});
});

.row
.col-md-11
%hr

:javascript
$(document).ready(function() {
let allocationCount = $("##{funding_request.object_key}RequestContainer .allocation_row").length;
if (allocationCount >= 3) {
$("##{funding_request.object_key}RequestContainer .add-allocation").hide();
} else {
$("##{funding_request.object_key}RequestContainer .add-allocation").show();
}
if (allocationCount <= 1) {
$("##{funding_request.object_key}RequestContainer a[data-method='delete']").hide();
} else {
$("##{funding_request.object_key}RequestContainer a[data-method='delete']").show();
}
});

// $(".cancel_edit[data-method='delete']").on("click", ()=>{
//
// });
2 changes: 1 addition & 1 deletion lib/transam_cpt/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module TransamCpt
VERSION = "2.27.0"
VERSION = "2.28.0"
end

0 comments on commit fcf34a7

Please sign in to comment.