Commit 924d0d1d by Nilu

reporting usage when on overage plan

parent 2472b185
......@@ -18,12 +18,9 @@ import com.stripe.model.Card;
import com.stripe.model.Charge;
import java.util.Calendar;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import oneit.logging.LoggingArea;
import oneit.security.SecUser;
import oneit.utils.DateDiff;
import performa.intercom.utils.IntercomUtils;
import performa.orm.Company;
import performa.orm.CompanyUser;
import performa.orm.HiringTeam;
......@@ -65,7 +62,7 @@ public class MakePaymentFP extends SaveFP
ReplaceCardFP.replaceCardDetails(process, submission);
}
if(company.getCardID() != null && ppj)
if(hiringTeam.getCardID() != null && hiringTeam.isTrue(hiringTeam.getIsPPJ()))
{
try
{
......@@ -73,7 +70,7 @@ public class MakePaymentFP extends SaveFP
chargeParams.put("amount", NullArith.intVal(NullArith.multiply(job.getAssessmentType() == AssessmentType.COMPREHENSIVE ? 499.0 : 399.0, 100, 0d)));
chargeParams.put("currency", "aud");
chargeParams.put("description", "Charges of creating job");
chargeParams.put("customer", company.getStripeReference());
chargeParams.put("customer", hiringTeam.getStripeReference());
Charge.create(chargeParams);
}
......@@ -85,7 +82,7 @@ public class MakePaymentFP extends SaveFP
}
}
if(company.getCardID() == null)
if(hiringTeam.getCardID() == null)
{
Card card = StripeUtils.retrieveCard(hiringTeam);
......@@ -98,7 +95,7 @@ public class MakePaymentFP extends SaveFP
job.setOpenDate(new Date());
job.setJobStatus(JobStatus.OPEN);
job.setLastEdited(new Date());
job.setIsPPJ(ppj);
job.setIsPPJ(hiringTeam.getIsPPJ());
if(job.getShortenedURL() == null)
{
......@@ -116,20 +113,20 @@ public class MakePaymentFP extends SaveFP
// restarting process as custom attributes needs to be updated to intercom
Set<String> attribsToRestore = new HashSet<>();
attribsToRestore.add("Job");
attribsToRestore.add("Company");
completeProcessRestartAndRestoreAttribs(process, attribsToRestore);
secUser = SecUser.getTXUser(process.getTransaction());
companyUser = secUser.getExtension(CompanyUser.REFERENCE_CompanyUser);
// Update company in intercom
if(companyUser.getCompany() != null)
{
IntercomUtils.updateCompany(companyUser.getCompany());
}
// Set<String> attribsToRestore = new HashSet<>();
// attribsToRestore.add("Job");
// attribsToRestore.add("Company");
//
// completeProcessRestartAndRestoreAttribs(process, attribsToRestore);
//
// secUser = SecUser.getTXUser(process.getTransaction());
// companyUser = secUser.getExtension(CompanyUser.REFERENCE_CompanyUser);
//
// // Update company in intercom
// if(companyUser.getCompany() != null)
// {
// IntercomUtils.updateCompany(companyUser.getCompany());
// }
return super.processForm(process, submission, p);
}
......
......@@ -116,6 +116,18 @@ public class SaveCompanyFP extends SaveFP
{
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);
......
......@@ -20,6 +20,7 @@ import oneit.utils.math.NullArith;
import performa.intercom.utils.IntercomUtils;
import performa.orm.*;
import performa.orm.types.*;
import performa.utils.StripeUtils;
public class SaveJobFP extends SaveFP
......@@ -34,6 +35,7 @@ public class SaveJobFP extends SaveFP
SecUser secUser = SecUser.getTXUser(process.getTransaction());
CompanyUser companyUser = secUser.getExtension(CompanyUser.REFERENCE_CompanyUser);
Company company = companyUser.getCompany();
HiringTeam hiringTeam = job.getHiringTeam();
LogMgr.log(Job.LOG, LogLevel.PROCESSING1,"In SaveJobFP saving job : ", job );
......@@ -51,17 +53,27 @@ public class SaveJobFP extends SaveFP
job.setApplyBy(DateDiff.add(DateDiff.getToday(), Calendar.DATE, 30));
job.setOpenDate(new Date());
company.setUsedCredits(NullArith.add(company.getUsedCredits(), 1).intValue());
if(status == JobStatus.OPEN)
{
if(company.getSelectedPaymentPlan() != null)
if (!hiringTeam.canCreateJob())
{
company.setPaymentPlan(company.getSelectedPaymentPlan());
throw new BusinessException("Please change payment plan settings to open this job");
}
hiringTeam.setUsedCredits(NullArith.add(hiringTeam.getUsedCredits(), 1).intValue());
LogMgr.log(Company.LOG, LogLevel.PROCESSING1,"Company payment plan updated.", job, company, company.getPaymentPlan());
if(hiringTeam.getUsedCredits() > hiringTeam.getAvailableCredits())
{
StripeUtils.recordUsage(hiringTeam);
}
if(status == JobStatus.OPEN)
{
// if(hiringTeam.getSelectedPaymentPlan() != null)
// {
// company.setPaymentPlan(company.getSelectedPaymentPlan());
//
// LogMgr.log(Company.LOG, LogLevel.PROCESSING1,"Company payment plan updated.", job, company, company.getPaymentPlan());
// }
job.setJobStatus(status);
LogMgr.log(Job.LOG, LogLevel.PROCESSING1,"Job status changed as Open. ", job );
......@@ -115,6 +127,7 @@ public class SaveJobFP extends SaveFP
SecUser loggedInUser = SecUser.getTXUser(process.getTransaction());
CompanyUser companyUser = loggedInUser.getExtension(CompanyUser.REFERENCE_CompanyUser);
Company company = companyUser.getCompany();
HiringTeam hiringTeam = job.getHiringTeam();
if(job.getJobStatus() != JobStatus.DRAFT || openJob == Boolean.TRUE)
{
......@@ -129,19 +142,19 @@ public class SaveJobFP extends SaveFP
//to select payment plan when job open
if(status != null && status == JobStatus.OPEN)
{
BusinessObjectParser.assertFieldCondition(company.getSelectedPaymentPlan() != null || company.getPaymentPlan() != null, company, Company.SINGLEREFERENCE_PaymentPlan, "mandatory", exceptions, true, request);
// BusinessObjectParser.assertFieldCondition(company.getSelectedPaymentPlan() != null || company.getPaymentPlan() != null, company, Company.SINGLEREFERENCE_PaymentPlan, "mandatory", exceptions, true, request);
if(company.getSelectedPaymentPlan() != null)
{
BusinessObjectParser.assertFieldCondition(company.getSelectedPaymentPlan().getActiveJobCount() > company.getUsedCredits() , job, Job.FIELD_JobStatus, "insufficientCredit", exceptions, true, request);
}
// if(company.getSelectedPaymentPlan() != null)
// {
BusinessObjectParser.assertFieldCondition(hiringTeam.canCreateJob() , job, Job.FIELD_JobStatus, "insufficientCredit", exceptions, true, request);
// }
}
if(job.getJobStatus() == JobStatus.OPEN)
{
BusinessObjectParser.assertFieldCondition(company.getCardID() != null , company, Company.FIELD_CardID, "mandatoryCardDetails", exceptions, true, request);
BusinessObjectParser.assertFieldCondition(hiringTeam.getCardID() != null , hiringTeam, HiringTeam.FIELD_CardID, "mandatoryCardDetails", exceptions, true, request);
BusinessObjectParser.assertFieldCondition(company.canCreateJob() , job, Job.FIELD_JobStatus, "insufficientCredit", exceptions, true, request);
BusinessObjectParser.assertFieldCondition(hiringTeam.canCreateJob() , job, Job.FIELD_JobStatus, "insufficientCredit", exceptions, true, request);
}
super.validate(process, submission, exceptions, params);
......
......@@ -144,4 +144,9 @@ public class HiringTeam extends BaseHiringTeam
return false;
}
public boolean canCreateJob()
{
return getAvailableCredits() > getUsedCredits() || !getHasCap() || (getHasCap() && getMaxCap() > getUsedCredits());
}
}
\ No newline at end of file
......@@ -38,6 +38,7 @@ public class WebUtils
public static final String CLIENTS = "Clients";
public static final String EDIT_CLIENT = "EditClient";
public static final String MANAGE_USERS = "ManageUsers";
public static final String MANAGE_PLAN = "ManagePlan";
public static final String MY_COMPANY = "MyCompany";
public static final String BILLING = "Billing";
public static final String VIEW_APPLICANTS = "ViewApplicants";
......
......@@ -14,6 +14,11 @@
String fifthPage = WebUtils.getSamePageInRenderMode(request, WebUtils.JOB_REVIEW);
String jobsPage = WebUtils.getSamePageInRenderMode(request, "Page");
Article companyArticle = WebUtils.getArticleByShortCut(transaction, WebUtils.MY_COMPANY);
String billingPage = companyArticle.getLink(request, CollectionUtils.mapEntry("cms.rm", WebUtils.BILLING).toMap());
String planPage = companyArticle.getLink(request, CollectionUtils.mapEntry("cms.rm", WebUtils.MANAGE_PLAN).toMap());
String sharingPage = WebUtils.getSamePageInRenderMode(request, WebUtils.CREATED_JOB) + "&fromJob=true";
if(job == null && request.getParameter("JobID")!= null)
{
job = Job.getJobByID(transaction, Long.parseLong(request.getParameter("JobID")));
......@@ -25,6 +30,10 @@
Company company = companyUser.getCompany();
Debug.assertion(job != null, "Job is null in admin portal create job");
HiringTeam hiringTeam = job.getHiringTeam();
process.setAttribute("HiringTeam", hiringTeam);
%>
<oneit:form name="editJob" method="post" enctype="multipart/form-data">
......@@ -35,10 +44,10 @@
<h1 class="page-title">Review Job
<%
if(company.getPaymentPlan()!=null)
if(hiringTeam.getPaymentPlan() != null)
{
Integer activeCount = company.getOpenJobsCount();
Integer totCount = company.getPaymentPlan().getActiveJobCount();
Integer activeCount = hiringTeam.getUsedCredits();
Integer totCount = hiringTeam.getAvailableCredits();
Integer remCount = (totCount - activeCount) > 0 ? (totCount - activeCount) : 0;
%>
<div style="float:right;">
......@@ -336,39 +345,48 @@
.mapEntry ("restartProcess", Boolean.TRUE)
.mapEntry ("attribNamesToRestore", Collections.singleton("Job"))
.toMap() %>" />
<%
if(company.canCreateJob())
{
if(company.getCardID() != null)
<%
if(hiringTeam.getCardID() == null)
{
String createJobPage = WebUtils.getSamePageInRenderMode(request, WebUtils.CREATED_JOB) + "&fromJob=true";
%>
<oneit:button value="Confirm and Create Job" name="saveJob" cssClass="btn btn-primary btn-green top-margin-25 largeBtn"
requestAttribs="<%= CollectionUtils.mapEntry("nextPage", createJobPage)
.mapEntry ("fromPage", fifthPage)
.mapEntry("JobStatus", JobStatus.OPEN)
<oneit:button value="Open this Job" name="saveJob" cssClass="btn btn-primary btn-green top-margin-25 largeBtn"
requestAttribs="<%= CollectionUtils.mapEntry("nextPage", billingPage)
.mapEntry("JobStatus", JobStatus.DRAFT)
.mapEntry ("restartProcess", Boolean.TRUE)
.mapEntry ("attribNamesToRestore", Collections.singleton("Job"))
.mapEntry ("attribNamesToRestore", new HashSet<String> (Arrays.asList(new String[] {"Job", "HiringTeam"})))
.mapEntry(NotificationUtils.DISPLAY_NOTIFICATION_PARAM, false)
.toMap() %>" />
<%
}
else
else if(hiringTeam.isTrue(hiringTeam.getIsPPJ()))
{
String createJobPage = WebUtils.getSamePageInRenderMode(request, WebUtils.CARD_PAYMENT);
%>
<oneit:button value="Confirm and Create Job" name="gotoPage" cssClass="btn btn-primary btn-green top-margin-25 largeBtn"
requestAttribs="<%= CollectionUtils.mapEntry("nextPage", createJobPage).toMap() %>" />
<oneit:button value="Open this Job" name="savePayment" cssClass="btn btn-primary btn-green top-margin-25 largeBtn"
requestAttribs="<%= CollectionUtils.mapEntry("nextPage", sharingPage).toMap() %>" />
<%
}
else if(hiringTeam.canCreateJob())
{
%>
<oneit:button value="Open this Job" name="saveJob" cssClass="btn btn-primary btn-green top-margin-25 largeBtn"
requestAttribs="<%= CollectionUtils.mapEntry("nextPage", sharingPage)
.mapEntry("JobStatus", JobStatus.OPEN)
.mapEntry ("restartProcess", Boolean.TRUE)
.mapEntry ("attribNamesToRestore", Collections.singleton("Job"))
.toMap() %>" />
<%
}
else
{
%>
<oneit:button value="Confirm and make payment" name="gotoPage" cssClass="btn btn-primary btn-green top-margin-25 largeBtn"
requestAttribs="<%= CollectionUtils.mapEntry("nextPage", nextPage).toMap() %>" />
<oneit:button value="Open this Job" name="saveJob" cssClass="btn btn-primary btn-green top-margin-25 largeBtn"
requestAttribs="<%= CollectionUtils.mapEntry("nextPage", planPage)
.mapEntry("JobStatus", JobStatus.DRAFT)
.mapEntry ("restartProcess", Boolean.TRUE)
.mapEntry ("attribNamesToRestore", new HashSet<String> (Arrays.asList(new String[] {"Job", "HiringTeam"})))
.mapEntry(NotificationUtils.DISPLAY_NOTIFICATION_PARAM, false)
.toMap() %>" />
<%
}
%>
......
......@@ -372,7 +372,7 @@ System.out.println(subscription);
<span> No, leave it open</span>
<label class="switch">
<oneit:recalcClass htmlTag="span" classScript="hiringTeam.isTrue(hiringTeam.getHasCap()) ? 'checkbox checked': 'checkbox unchecked'" hiringTeam="<%= hiringTeam %>">
<oneit:ormInput obj="<%= hiringTeam %>" attributeName="HasCap" type="checkbox"/>
<oneit:ormInput obj="<%= hiringTeam %>" attributeName="HasCap" type="checkbox" onChange="paymentPlanChanged()"/>
</oneit:recalcClass>
<div class="slider round"></div>
</label>
......@@ -385,6 +385,8 @@ System.out.println(subscription);
<oneit:button value="Set Max" name="saveCompany" cssClass="btn btn-primary"
requestAttribs="<%= CollectionUtils.mapEntry("nextPage", nextPage)
.mapEntry ("restartProcess", Boolean.TRUE)
.mapEntry ("attribNamesToRestore", Collections.singleton("HiringTeam"))
.toMap() %>" />
</oneit:recalcClass>
</div>
......
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