Commit abaac246 by Nilu

Bug: When hiring team is on a plan, then a coupon applied and tried to upgrade,…

Bug: When hiring team is on a plan, then a coupon applied and tried to upgrade, price differences are not calculated correctly. Critical as upgrading charge is done via our system,  not automatically handled by stripe
parent 276a7b5e
......@@ -33,6 +33,7 @@
<column name="has_cap" type="Boolean" nullable="true"/>
<column name="max_cap" type="Long" nullable="true"/>
<column name="coupon_expiry_date" type="Date" nullable="true"/>
<column name="last_plan_amount" type="Double" nullable="true"/>
<column name="company_id" type="Long" length="11" nullable="false"/>
<column name="billing_team_id" type="Long" length="11" nullable="true"/>
<column name="added_by_user_id" type="Long" length="11" nullable="false"/>
......
......@@ -33,6 +33,7 @@ CREATE TABLE tl_hiring_team (
has_cap char(1) NULL,
max_cap numeric(12) NULL,
coupon_expiry_date datetime NULL,
last_plan_amount numeric(20,5) NULL,
company_id numeric(12) NOT NULL,
billing_team_id numeric(12) NULL,
added_by_user_id numeric(12) NOT NULL,
......
......@@ -34,6 +34,7 @@ CREATE TABLE tl_hiring_team (
has_cap char(1) NULL,
max_cap number(12) NULL,
coupon_expiry_date date NULL,
last_plan_amount number(20,5) NULL,
company_id number(12) NOT NULL,
billing_team_id number(12) NULL,
added_by_user_id number(12) NOT NULL,
......
......@@ -34,6 +34,7 @@ CREATE TABLE tl_hiring_team (
has_cap char(1) NULL,
max_cap numeric(12) NULL,
coupon_expiry_date timestamp NULL,
last_plan_amount numeric(20,5) NULL,
company_id numeric(12) NOT NULL,
billing_team_id numeric(12) NULL,
added_by_user_id numeric(12) NOT NULL,
......
......@@ -87,20 +87,23 @@ public class SaveCompanyFP extends SaveFP
if(currentPlan != null && currentPlan.getActiveJobCount() < paymentPlan.getActiveJobCount())
{
boolean hasValidCoupon = hiringTeam.hasValidCouponOn(new Date(subscription.getCurrentPeriodEnd() * 1000));
double currentPlanCost = hiringTeam.getLastPlanAmount() != null ? hiringTeam.getLastPlanAmount() : currentPlan.getAmount();
double newPlanCost = hasValidCoupon ? paymentPlan.getAmount() * (1 - (hiringTeam.getCoupon().getPercentageOff() * 0.01)) : paymentPlan.getAmount();
double costDiff = newPlanCost - currentPlanCost;
StripeUtils.chargeUpgradePlanDifference(hiringTeam, costDiff);
}
double discountPercentage = 0d;
if(subscription.getDiscount() != null && subscription.getDiscount().getCoupon() != null && subscription.getDiscount().getCoupon().getPercentOff() != null)
{
discountPercentage = subscription.getDiscount().getCoupon().getPercentOff().doubleValue();
discountPercentage = 1 - (subscription.getDiscount().getCoupon().getPercentOff().doubleValue() * 0.01 );
}
boolean hasValidCoupon = hiringTeam.hasValidCouponOn(new Date(subscription.getCurrentPeriodEnd() * 1000));
double currentPlanCost = discountPercentage > 0 ? currentPlan.getAmount() * discountPercentage * 0.01 : currentPlan.getAmount();
double newPlanCost = hasValidCoupon ? paymentPlan.getAmount() * hiringTeam.getCoupon().getPercentageOff() * 0.01 : paymentPlan.getAmount();
double costDiff = newPlanCost - currentPlanCost;
StripeUtils.chargeUpgradePlanDifference(hiringTeam, costDiff);
hiringTeam.setLastPlanAmount(discountPercentage > 0 ? paymentPlan.getAmount() * discountPercentage : paymentPlan.getAmount());
}
if(currentPlan == null || currentPlan.getActiveJobCount() < paymentPlan.getActiveJobCount())
{
......
......@@ -44,6 +44,7 @@
<ATTRIB name="HasCap" type="Boolean" dbcol="has_cap" defaultValue="Boolean.FALSE"/>
<ATTRIB name="MaxCap" type="Integer" dbcol="max_cap" />
<ATTRIB name="CouponExpiryDate" type="Date" dbcol="coupon_expiry_date" />
<ATTRIB name="LastPlanAmount" type="Double" dbcol="last_plan_amount" />
<SINGLEREFERENCE name="Company" type="Company" dbcol="company_id" mandatory="true" backreferenceName="HiringTeams" />
<SINGLEREFERENCE name="BilledByTeam" type="HiringTeam" dbcol="billing_team_id" mandatory="false" backreferenceName="BillingTeams" />
......
......@@ -35,6 +35,8 @@
{
subscription = StripeUtils.retrieveSubscription(hiringTeam.getStripeSubscription());
}
System.out.println(subscription);
%>
<script type="text/javascript">
var Popup = null;
......@@ -283,14 +285,19 @@
</h3>
<div class="upgrade-info">
<%
boolean validCoupon = hiringTeam.hasValidCouponOn(new Date(subscription.getCurrentPeriodEnd() * 1000));
double currentPlanCost = hiringTeam.getLastPlanAmount() != null ? hiringTeam.getLastPlanAmount() : currentPlan.getAmount();
double newPlanCost = validCoupon ? paymentPlan.getAmount() * (1 - (hiringTeam.getCoupon().getPercentageOff() * 0.01)) : paymentPlan.getAmount();
double costDiff = newPlanCost - currentPlanCost;
if(isUpgrade)
{
%>
Upgrading your plan to <%= paymentPlan.getActiveJobCount() %> Jobs per month will incur an additional cost of
<%= FormatUtils.stringify(paymentPlan.getAmount() - currentPlan.getAmount(), "CurrencyDollarsOnly", "") %> be billed immediately.
<%= FormatUtils.stringify(costDiff, "CurrencyDollarsOnly", "") %> be billed immediately.
<span>
This cost is to cover the difference between your current active <%= currentPlan.getActiveJobCount() %> job plan (<%= FormatUtils.stringify(currentPlan.getAmount(), "Currency", "") %>)
and the new <%= paymentPlan.getActiveJobCount() %> job plan (<%= FormatUtils.stringify(paymentPlan.getAmount(), "CurrencyDollarsOnly", "") %>).
This cost is to cover the difference between your current active <%= currentPlan.getActiveJobCount() %> job plan (<%= FormatUtils.stringify(currentPlanCost, "CurrencyDollarsOnly", "") %>)
and the new <%= paymentPlan.getActiveJobCount() %> job plan (<%= FormatUtils.stringify(newPlanCost, "CurrencyDollarsOnly", "") %>).
</span>
<%
}
......@@ -316,7 +323,7 @@
</div>
<div class="list-item">
<span class="item-title">Date of next billing period</span>
<span class="item-value"><%= FormatUtils.stringify(paymentPlan.getAmount(), "CurrencyDollarsOnly", "") %> on <oneit:toString value="<%= new Date(subscription.getCurrentPeriodEnd() * 1000) %>" mode="LongDate"/></span>
<span class="item-value"><%= FormatUtils.stringify(newPlanCost, "CurrencyDollarsOnly", "") %> on <oneit:toString value="<%= new Date(subscription.getCurrentPeriodEnd() * 1000) %>" mode="LongDate"/></span>
</div>
</div>
<div class="upgrade-info">
......
<?xml version="1.0" encoding="UTF-8"?>
<!-- @AutoRun -->
<OBJECTS name="" xmlns:oneit="http://www.1iT.com.au">
<NODE name="Script" factory="Vector">
<NODE name="DDL" factory="Participant" class="oneit.sql.transfer.RedefineTableOperation">
<tableName factory="String">tl_hiring_team</tableName>
<column name="last_plan_amount" type="Double" nullable="true"/>
</NODE>
</NODE>
</OBJECTS>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment