Commit 3ecd2258 by Nilu

set up payment plan modifications

parent ee7fc713
......@@ -35,6 +35,7 @@
<column name="coupon_expiry_date" type="Date" nullable="true"/>
<column name="last_plan_amount" type="Double" nullable="true"/>
<column name="google_address_text" type="String" nullable="true" length="300"/>
<column name="plan_cancelled" type="Boolean" 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"/>
......
......@@ -35,6 +35,7 @@ CREATE TABLE tl_hiring_team (
coupon_expiry_date datetime NULL,
last_plan_amount numeric(20,5) NULL,
google_address_text varchar(300) NULL,
plan_cancelled char(1) NULL,
company_id numeric(12) NOT NULL,
billing_team_id numeric(12) NULL,
added_by_user_id numeric(12) NOT NULL,
......
......@@ -36,6 +36,7 @@ CREATE TABLE tl_hiring_team (
coupon_expiry_date date NULL,
last_plan_amount number(20,5) NULL,
google_address_text varchar2(300) NULL,
plan_cancelled char(1) NULL,
company_id number(12) NOT NULL,
billing_team_id number(12) NULL,
added_by_user_id number(12) NOT NULL,
......
......@@ -36,6 +36,7 @@ CREATE TABLE tl_hiring_team (
coupon_expiry_date timestamp NULL,
last_plan_amount numeric(20,5) NULL,
google_address_text varchar(300) NULL,
plan_cancelled char(1) NULL,
company_id numeric(12) NOT NULL,
billing_team_id numeric(12) NULL,
added_by_user_id numeric(12) NOT NULL,
......
package performa.form;
import com.stripe.model.Subscription;
import java.util.Date;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import oneit.logging.LogLevel;
......@@ -16,7 +15,6 @@ import oneit.utils.BusinessException;
import oneit.utils.CollectionUtils;
import oneit.utils.MultiException;
import performa.orm.HiringTeam;
import performa.orm.PaymentPlan;
import performa.utils.StripeUtils;
......@@ -28,7 +26,6 @@ public class SaveCompanyFP extends SaveFP
HttpServletRequest request = submission.getRequest();
HiringTeam hiringTeam = (HiringTeam) process.getAttribute("HiringTeam");
Boolean isPayment = (Boolean) request.getAttribute("IsPayment");
PaymentPlan paymentPlan = (PaymentPlan) request.getAttribute("PaymentPlan");
Subscription subscription = StripeUtils.retrieveSubscription(hiringTeam.getStripeSubscription());
if(CollectionUtils.equals(hiringTeam.getIsLogoDeleted(), Boolean.TRUE))
......@@ -65,90 +62,6 @@ public class SaveCompanyFP extends SaveFP
}
}
if(subscription != null)
{
if(hiringTeam.getIsPPJ())
{
StripeUtils.cancelSubscription(subscription, true);
LogMgr.log(HiringTeam.LOG, LogLevel.PROCESSING1,"In SaveCompanyFP cancelling a subscription in Stripe since moving to PPJ : ", subscription );
}
else
{
if(hiringTeam.getPaymentPlan() != null)
{
StripeUtils.cancelSubscription(subscription, false);
LogMgr.log(HiringTeam.LOG, LogLevel.PROCESSING1,"In SaveCompanyFP reactivating a subscription (as subscription is not cancelled yet) in Stripe since moving to Subscription from PPJ : ", subscription );
}
}
}
if(CollectionUtils.equals(isPayment, Boolean.TRUE))
{
LogMgr.log(HiringTeam.LOG, LogLevel.PROCESSING1,"Hiring Team payment plan updated.", hiringTeam, " payment plan: ", hiringTeam.getPaymentPlan());
if(hiringTeam.getCardID() == null)
{
throw new BusinessException("Please enter billing details before selecting a payment plan");
}
// cannot subscribe a user to a plan without card details
Subscription updatedSubscription = StripeUtils.updatePlan(hiringTeam, subscription, paymentPlan);
if(updatedSubscription == null)
{
throw new BusinessException("Problem with changing your plan. Please contact adminstrator for more info.");
}
PaymentPlan currentPlan = hiringTeam.getPaymentPlan();
if(subscription != null && 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 != null && subscription.getDiscount() != null && subscription.getDiscount().getCoupon() != null && subscription.getDiscount().getCoupon().getPercentOff() != null)
{
discountPercentage = 1 - (subscription.getDiscount().getCoupon().getPercentOff().doubleValue() * 0.01 );
}
hiringTeam.setLastPlanAmount(discountPercentage > 0 ? paymentPlan.getAmount() * discountPercentage : paymentPlan.getAmount());
if(currentPlan == null || currentPlan.getActiveJobCount() < paymentPlan.getActiveJobCount())
{
hiringTeam.setAvailableCredits(paymentPlan.getActiveJobCount());
}
hiringTeam.setPaymentPlan(paymentPlan);
LogMgr.log(HiringTeam.LOG, LogLevel.PROCESSING1,"Stripe subscription updated.", hiringTeam, hiringTeam.getStripeSubscription());
}
if(!hiringTeam.isTrue(hiringTeam.getHasCap()))
{
hiringTeam.setMaxCap(null);
}
if(hiringTeam.isTrue(hiringTeam.getHasCap()) && hiringTeam.getPaymentPlan() != null)
{
if(hiringTeam.getMaxCap() == null)
{
hiringTeam.setMaxCap(hiringTeam.getPaymentPlan().getActiveJobCount());
}
else if(hiringTeam.getMaxCap() < hiringTeam.getPaymentPlan().getActiveJobCount())
{
throw new BusinessException("Cap should be greater than the number of jobs of the selected plan");
}
}
// // Update company in intercom
// IntercomUtils.updateCompany(company);
......
package performa.form;
import com.stripe.model.Subscription;
import java.util.Date;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import oneit.logging.LogLevel;
import oneit.logging.LogMgr;
import oneit.objstore.StorageException;
import oneit.objstore.parser.BusinessObjectParser;
import oneit.servlets.forms.SubmissionDetails;
import oneit.servlets.forms.SuccessfulResult;
import oneit.servlets.process.ORMProcessState;
import oneit.servlets.process.SaveFP;
import oneit.utils.BusinessException;
import oneit.utils.CollectionUtils;
import oneit.utils.MultiException;
import performa.orm.HiringTeam;
import performa.orm.PaymentPlan;
import performa.utils.StripeUtils;
public class SavePaymentPlanFP extends SaveFP
{
@Override
public SuccessfulResult processForm(ORMProcessState process, SubmissionDetails submission, Map params) throws BusinessException, StorageException
{
HttpServletRequest request = submission.getRequest();
HiringTeam hiringTeam = (HiringTeam) process.getAttribute("HiringTeam");
PaymentPlan paymentPlan = request.getAttribute("PaymentPlan") != null ? (PaymentPlan) request.getAttribute("PaymentPlan") : hiringTeam.getPaymentPlan();
Boolean firstTime = request.getAttribute("firstTime") != null ? (Boolean) request.getAttribute("firstTime") : Boolean.FALSE;
Boolean savePlan = request.getAttribute("savePlan") != null ? (Boolean) request.getAttribute("savePlan") : Boolean.FALSE;
Boolean savePPJ = request.getAttribute("savePPJ") != null ? (Boolean) request.getAttribute("savePPJ") : Boolean.FALSE;
Boolean saveCap = request.getAttribute("saveCap") != null ? (Boolean) request.getAttribute("saveCap") : Boolean.FALSE;
// Billing needs to be setup first. Cannot subscribe a user to a plan without card details
if(hiringTeam.getCardID() == null)
{
throw new BusinessException("Please enter billing details before selecting a payment plan");
}
Subscription subscription = StripeUtils.retrieveSubscription(hiringTeam.getStripeSubscription());
if(subscription != null && savePPJ)
{
if(CollectionUtils.equals(hiringTeam.getIsPPJ(), Boolean.TRUE))
{
StripeUtils.cancelSubscription(subscription, true);
hiringTeam.setHasCap(false);
hiringTeam.setMaxCap(null);
hiringTeam.setPlanCancelled(true);
LogMgr.log(HiringTeam.LOG, LogLevel.PROCESSING1,"In SaveCompanyFP cancelling a subscription in Stripe since moving to PPJ : ", subscription );
}
else
{
if(hiringTeam.getPaymentPlan() != null && hiringTeam.isTrue(hiringTeam.getPlanCancelled()))
{
StripeUtils.cancelSubscription(subscription, false);
hiringTeam.setPlanCancelled(false);
LogMgr.log(HiringTeam.LOG, LogLevel.PROCESSING1,"In SaveCompanyFP reactivating a subscription (as subscription is not cancelled yet) in Stripe since moving to Subscription from PPJ : ", subscription );
}
}
}
// When Subscribe and Save selected
if(CollectionUtils.equals(hiringTeam.getIsPPJ(), Boolean.FALSE) && (firstTime || savePlan))
{
LogMgr.log(HiringTeam.LOG, LogLevel.PROCESSING1,"Hiring Team payment plan updated.", hiringTeam, " payment plan: ", hiringTeam.getPaymentPlan());
Subscription updatedSubscription = StripeUtils.updatePlan(hiringTeam, subscription, paymentPlan);
if(updatedSubscription == null)
{
throw new BusinessException("Problem with changing your plan. Please contact adminstrator for more info.");
}
if(firstTime)
{
hiringTeam.setAvailableCredits(paymentPlan.getActiveJobCount());
}
else
{
PaymentPlan currentPlan = hiringTeam.getPaymentPlan();
if(subscription != null && 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);
hiringTeam.setAvailableCredits(paymentPlan.getActiveJobCount());
}
hiringTeam.setPaymentPlan(paymentPlan);
}
double discountPercentage = 0d;
if(subscription != null && subscription.getDiscount() != null && subscription.getDiscount().getCoupon() != null && subscription.getDiscount().getCoupon().getPercentOff() != null)
{
discountPercentage = 1 - (subscription.getDiscount().getCoupon().getPercentOff().doubleValue() * 0.01 );
}
hiringTeam.setLastPlanAmount(discountPercentage > 0 ? paymentPlan.getAmount() * discountPercentage : paymentPlan.getAmount());
LogMgr.log(HiringTeam.LOG, LogLevel.PROCESSING1,"Stripe subscription updated.", hiringTeam, hiringTeam.getStripeSubscription());
}
if(!hiringTeam.isTrue(hiringTeam.getHasCap()))
{
hiringTeam.setMaxCap(null);
}
if((firstTime || saveCap) && (hiringTeam.isTrue(hiringTeam.getHasCap()) && hiringTeam.getPaymentPlan() != null))
{
if(hiringTeam.getMaxCap() == null)
{
hiringTeam.setMaxCap(hiringTeam.getPaymentPlan().getActiveJobCount());
}
else if(hiringTeam.getMaxCap() < hiringTeam.getPaymentPlan().getActiveJobCount())
{
throw new BusinessException("Cap should be greater than the number of jobs of the selected plan");
}
}
return super.processForm(process, submission, params);
}
@Override
public void validate(ORMProcessState process, SubmissionDetails submission, MultiException exceptions, Map params) throws StorageException
{
HttpServletRequest request = submission.getRequest();
HiringTeam hiringTeam = (HiringTeam) process.getAttribute("HiringTeam");
PaymentPlan paymentPlan = request.getAttribute("PaymentPlan") != null ? (PaymentPlan) request.getAttribute("PaymentPlan") : hiringTeam.getPaymentPlan();
Boolean firstTime = request.getAttribute("firstTime") != null ? (Boolean) request.getAttribute("firstTime") : Boolean.FALSE;
Boolean savePlan = request.getAttribute("savePlan") != null ? (Boolean) request.getAttribute("savePlan") : Boolean.FALSE;
if(CollectionUtils.equals(hiringTeam.getIsPPJ(), Boolean.FALSE) && (firstTime || savePlan))
{
BusinessObjectParser.assertFieldCondition(paymentPlan != null, hiringTeam , HiringTeam.SINGLEREFERENCE_PaymentPlan, "mandatory", exceptions, true, request);
}
super.validate(process, submission, exceptions, params);
}
}
\ No newline at end of file
......@@ -261,4 +261,9 @@ public class HiringTeam extends BaseHiringTeam
return addUser;
}
public boolean isPlanActive(PaymentPlan paymentPlan)
{
return CollectionUtils.equals(getPaymentPlan(), paymentPlan);
}
}
\ No newline at end of file
......@@ -45,6 +45,7 @@
<ATTRIB name="CouponExpiryDate" type="Date" dbcol="coupon_expiry_date" />
<ATTRIB name="LastPlanAmount" type="Double" dbcol="last_plan_amount" />
<ATTRIB name="GoogleAddressText" type="String" dbcol="google_address_text" length="300" />
<ATTRIB name="PlanCancelled" type="Boolean" dbcol="plan_cancelled" defaultValue="Boolean.FALSE"/>
<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" />
......
......@@ -6592,14 +6592,15 @@ span.tab-number {
margin: 0
}
.setmax button {
.setmax a {
height: 50px;
width: 100px;
border-radius: 0 2px 2px 0;
background-color: #4E5258;
color: #FFFFFF;
font-size: 11px;
margin: 0
margin: 0;
padding-top: 15px;
}
#change-plan .jBox-content {padding: 0;}
......@@ -7630,3 +7631,7 @@ input{
font-weight: 500;
color: #ffffff !important;
}
.container-fluid.repeat{
margin-top: 50px;
}
\ No newline at end of file
......@@ -54,6 +54,7 @@
<FORM name="*.saveClient" factory="Participant" class="performa.form.SaveClientFP"/>
<FORM name="*.applyCoupon" factory="Participant" class="performa.form.ApplyCouponFP"/>
<FORM name="*.saveCompany" factory="Participant" class="performa.form.SaveCompanyFP"/>
<FORM name="*.savePlan" factory="Participant" class="performa.form.SavePaymentPlanFP"/>
<FORM name="*.processCulture" factory="Participant" class="performa.form.ProcessCultureFP"/>
<FORM name="*.savePayment" factory="Participant" class="performa.form.MakePaymentFP"/>
<FORM name="*.managePlans" factory="Participant" class="performa.form.ManagePlansFP"/>
......
......@@ -322,7 +322,7 @@
</div>
</div>
<div class="form-group row">
<div class="col-md-4">
<div class="col-md-6">
<div class="styled_checkboxes">
<div class="checkbox checkbox-primary">
<oneit:ormInput obj="<%= template %>" id="is-remote" attributeName="Remote" type="checkbox"/>
......@@ -579,7 +579,7 @@
</div>
</div>
<div class="container-fluid">
<div class="container-fluid repeat">
<div class="main-tab-template">
<span class="tab-number">2</span>
<span class="job-details">Requirements</span>
......
......@@ -43,6 +43,7 @@
<script>
dataLayer = [{
'userId': '<%= clientUser != null ? clientUser.getUserName() : "" %>',
'stripeId': '<%= selectedTeam != null ? selectedTeam.getStripeReference() : "" %>',
}];
</script>
<script>
......
......@@ -338,7 +338,7 @@
</div>
</div>
<div class="form-group row">
<div class="col-md-4">
<div class="col-md-6">
<div class="styled_checkboxes">
<div class="checkbox checkbox-primary">
<oneit:ormInput obj="<%= job %>" id="is-remote" attributeName="Remote" type="checkbox"/>
......
......@@ -322,7 +322,7 @@
requestAttribs='<%= CollectionUtils.mapEntry ("nextPage", nextPage)
.mapEntry("cancelProcess", true)
.toMap() %>'/>
<oneit:button value="Save Updates" name="saveCompany" cssClass="btn btn-primary largeBtn" disabled="<%= readOnly ? "true" : "false" %>"
<oneit:button value="Save Team" name="saveCompany" cssClass="btn btn-primary largeBtn" disabled="<%= readOnly ? "true" : "false" %>"
requestAttribs="<%= CollectionUtils.mapEntry("nextPage", nextPage)
.mapEntry("procParams", CollectionUtils.mapEntry("HiringTeam", hiringTeam).toMap())
.mapEntry("Company", company)
......
......@@ -86,7 +86,7 @@
right: 0;
bottom: 0;
background-color: rgba(0,0,0,0.5);
z-index: 2;
z-index: 99999;
cursor: pointer;
}
.welcome-pop-top {
......
<?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="plan_cancelled" type="Boolean" 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