<%@ page extends="oneit.servlets.jsp.JSPInclude" %>

<%@ include file="/inc/stdimports50.jsp" %><%-- This is in cougar --%>
<%@ include file="/inc/stdcms.jsp" %><%-- This is in cougar --%>
<%@ include file="/extensions/performa/inc/stdimports.jsp" %>

<oneit:dynIncluded>
<%
    String          hiringTeamList  =   WebUtils.getSamePageInRenderMode(request, "Page");
    String          nextPage        =   WebUtils.getSamePageInRenderMode(request, "ManagePlan");
    SecUser         loggedInUser    =   SecUser.getTXUser(transaction);
    CompanyUser     companyUser     =   loggedInUser.getExtension(CompanyUser.REFERENCE_CompanyUser);
    Company         company         =   companyUser.getCompany();
    HiringTeam      hiringTeam      =   (HiringTeam) process.getAttribute("HiringTeam");

    Debug.assertion(company != null , "Invalid company in admin portal my company");
    
    Debug.assertion(hiringTeam != null , "Invalid Hiring Team in admin portal manage plan");
    
    PaymentPlan[]   paymentPlans    =   PaymentPlan.SearchByAll()
                                                    .andDisabled(new EqualsFilter<>(Boolean.FALSE))
                                                    .andUsageType(new EqualsFilter<>(UsageType.LICENSED))
                                                    .andActiveJobCount(new GreaterThanFilter<>(0))
                                                    .search(transaction);
        
    List<PaymentPlan>   sortedPlans =   ObjstoreUtils.sort(Arrays.asList(paymentPlans), 
                                                        new ObjectTransform[]{PaymentPlan.pipesPaymentPlan().toActiveJobCount()}, 
                                                        new Comparator[]{CollectionUtils.DEFAULT_COMPARATOR_NULLS_FIRST});
%>
    <script type="text/javascript">
        var Popup = null;
        $(document).ready(function()
        {
            recalcFunction = setupRecalc ($("form#editCompany"), {'recalcOnError':true});
       
          Popup = new jBox('Modal', {
                id : "change-plan",
                overlay : true, 
                width : 600, height : 640
                });
         
         var isinvliadCoupon = getParameterByName("invalidcoupon");
         
         if (isinvliadCoupon==='true'){
            PopupCoupon = new jBox('Modal', {
                id : "change-plan",
                overlay : true, content :  $("#invalid-coupon-popup") ,
               width : 500, height : 400
                });       
               PopupCoupon.open();
           }
                          
           $(".invalid-coupon-close-button").on("click",function(){             
               PopupCoupon.close();
           });               
                          
           $(".select-btn").on("click",function(){             
               Popup.setContent($("#" + $(this).data('popupid')  ));
               Popup.open();
               
           });               
        });                                                
    </script> 
    
    <div class="container-fluid">
        <div class="row content">
            <div class="main-content-area">
                <oneit:form name="editCompany"  method="post"    enctype="multipart/form-data">
                    
                    <h1 class="page-title page-title-with-arrow">
                        <oneit:button cssClass="arrow-btn-blue"  name="gotoPage" value=" " skin="link"
                                    requestAttribs="<%= CollectionUtils.mapEntry("nextPage", hiringTeamList).toMap() %>" >
                        <img src="images/arrow-left-prev_blue.svg" />
                    </oneit:button>
                        <%= hiringTeam.getHiringTeamName() %>
                    </h1>
                    <div class="my-company-area">
                        
                        <div style="padding-left: 15px; padding-right: 15px;">
                            <oneit:dynInclude   page="/extensions/applicantportal/inc/multifieldtext.jsp"   data="<%= CollectionUtils.EMPTY_MAP%>"/>
                        </div>

                        <oneit:dynInclude   page="/extensions/adminportal/inc/my_company_tabs.jsp"    TabNumber="2"    data="<%= CollectionUtils.EMPTY_MAP%>"/>

                        <div class="company-content-area">
                            <!-- Tab panes -->
                            <div class="tab-content">
                                <div class="tab-pane active" id="company-detail">
                                    <div>  
                                        <div class="tabpage-title manage-plan">
                                            <label class="label-20">Manage Plan</label>                
                                        </div>
                                        <div class="apply-coupon">
                                            <oneit:ormInput obj="<%= hiringTeam %>"    type="text" attributeName="CouponCode"   placeholder="Coupon Code"  cssClass="form-control" />      
                                            <oneit:button   value="APPLY"     name="applyCoupon"    cssClass="btn btn-input-inside"
                                                                        requestAttribs="<%= CollectionUtils.mapEntry("nextPage", nextPage)
                                                                                                            .mapEntry("HiringTeam", hiringTeam)
                                                                                                            .toMap() %>" />
                                        </div>
                                    </div>
                                    <div class="coupon-applied-alert">
                                        coupon applied 
                                        <span class="coupon_code">
                                            <oneit:toString value="ABCD123" mode="EscapeHTML"/> - save
                                            <oneit:toString value="10%" mode="EscapeHTML"/>
                                        </span>
                                        <span class="expire">
                                            Expires
                                            <oneit:toString value="18 Sep 2018" mode="EscapeHTML"/>
                                        </span>
                                    </div>
                                    <div class="form-group row">
                                        <div class="col-md-12 oneit-radio coupon-applied">
                                            <div class="rectangle-5">
                                                <div class="manage-plan-row">
                                                    <div class="radio">
                                                        <label>
                                                            <oneit:ormInput obj="<%= hiringTeam %>" type="radio" attributeName="IsPPJ" value="true"/>
                                                        </label>
                                                     </div>
                                                    <div class="manage-plan-title">
                                                        <h3>Pay Per Job</h3>                                                        
                                                        <span>
                                                            You'll be charged each time you add a new job
                                                        </span>
                                                    </div>
                                                    <div class="manage-plan-payplan">
                                                        <div class="per-job-amount">
                                                            <oneit:toString value="<%= PaymentPlan.PER_PER_JOB_AMOUNT %>" mode="Currency"/>/ Job
                                                        </div>
                                                        <div class="per-job-amount-past">
                                                            was <oneit:toString value="<%= PaymentPlan.PER_PER_JOB_AMOUNT %>" mode="Currency"/> per job
                                                        </div>
                                                    </div>
                                                    <div class="clearboth"></div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group row">
                                        <div class="col-md-12 oneit-radio coupon-applied">                                             
                                            <div class="rectangle-5">
                                                <div class="manage-plan-row">
                                                    <div class="radio">
                                                        <label>
                                                            <oneit:ormInput obj="<%= hiringTeam %>" type="radio" attributeName="IsPPJ" value="false"/>
                                                        </label>
                                                    </div>
                                                    <div class="manage-plan-title">
                                                        <h3>Subscribe & Save</h3>                                                        
                                                        <span>
                                                            Intend to post multiple jobs this month?<br>
                                                            Find a plan to suit your hiring needs, and save today.
                                                        </span>
                                                    </div>
                                                    <div class="manage-plan-payplan">
                                                        <div class="per-job-amount">
                                                        </div>
                                                        <div class="per-job-amount-past">
                                                        </div>
                                                    </div>
                                                    <div class="clearboth"></div>
                                                </div>
                                                <div class="manage-plan-hidden-info">   
                                                    <div class="subscription-billed">
                                                        <img src="images/icon-calendar.png"> Your subscription is billed and resets on the   <oneit:toString value="12th" mode="EscapeHTML"/> of every month
                                                    </div>
                                                    <div class="choose-plan-row">    
                                                        <div class="choose-your-plan-title">
                                                            Choose Your Plan
                                                        </div>
                                                        <div class="choose-plan-headings">  
                                                            <div class="jobs-per-month">Jobe Per Month</div>
                                                            <div class="cost-per-job">Cost Per Job</div>
                                                            <div class="monthly-fee">Monthly Fee</div>
                                                        </div>
                                                    <%
                                                        Subscription    subscription    =  null;
                                                        PaymentPlan     currentPlan     =   hiringTeam.getPaymentPlan();

                                                        if(!hiringTeam.isPPJ() && currentPlan != null)
                                                        {
                                                            subscription    =   StripeUtils.retrieveSubscription(hiringTeam.getStripeSubscription());
                                                        }

                                                        for (PaymentPlan paymentPlan : sortedPlans)
                                                        {
                                                            boolean     isSelectedPlan  =   CollectionUtils.equals(paymentPlan, currentPlan);
                                                    %>
                                                            <div class="choose-plan-item <%= isSelectedPlan ? "active" : ""%>">
                                                                <div class="jobs">
                                                                    <%= paymentPlan.getActiveJobCount() %> Jobs 
                                                                </div>
                                                                <div class="cost">
                                                                    <oneit:toString value="<%= paymentPlan.getAmount() / paymentPlan.getActiveJobCount() %>"  mode="Currency"/>
                                                                    <span class="past-val">
                                                                        was <oneit:toString value="<%= 270.00 %>" mode="Currency"/>
                                                                    </span>
                                                                </div>
                                                                <div class="fee">
                                                                    <oneit:toString value="<%= paymentPlan.getAmount() %>" mode="Currency"/><span class="month"> / month </span>
                                                                    <span class="past-val">
                                                                        was <oneit:toString value="<%= 2700.00 %>" mode="Currency"/>
                                                                    </span>
                                                                </div>
                                                                <div class="select-button">
                                                                    <%
                                                                        if(isSelectedPlan)
                                                                        {
                                                                    %>
                                                                            <span class="btn active-btn">Active</span>
                                                                    <%
                                                                        }
                                                                        else if(currentPlan != null)
                                                                        {
                                                                            boolean isUpgrade   =   paymentPlan.getActiveJobCount() > currentPlan.getActiveJobCount();
                                                                    %>
                                                                            <a href="#" class="btn select-btn" data-popupid ="change-plan-popup-<%=paymentPlan.getID()%>" >Select</a>
                                                                            
                                                                            <div id="change-plan-popup-<%=paymentPlan.getID()%>" style="display:none" >
                                                                                <div class="change-plan-content">
                                                                                    <h3>
                                                                                        <%= isUpgrade ? "Upgrade" : "Change" %> to <%= paymentPlan.getActiveJobCount() %> Jobs per month?
                                                                                    </h3>
                                                                                    <div class="upgrade-info">
                                                                                        <%
                                                                                            if(isUpgrade)
                                                                                            {
                                                                                        %>
                                                                                                Upgrading your plan to <%= paymentPlan.getActiveJobCount() %> Jobs per month will incur an additional cost of 
                                                                                                <%= FormatUtils.stringify(paymentPlan.getAmount() - currentPlan.getAmount(), "Currency", "") %> 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(), "Currency", "") %>).
                                                                                                </span>
                                                                                        <%
                                                                                            }
                                                                                            else
                                                                                            {
                                                                                        %>
                                                                                                Changing your plan down to 5 Jobs per month will not incur any additional costs, and will begin on 1 September, 2018.
                                                                                                <span>
                                                                                                    Because your plan has already been billed, your new plan will commence at the beginning of the next billing period.                               
                                                                                                </span>
                                                                                        <%
                                                                                            }
                                                                                        %>
                                                                                    </div>
                                                                                    <div class="change-plan-list">
                                                                                        <div class="list-item">
                                                                                            <span class="item-title">Jobs remaining this month</span>
                                                                                            <span class="item-value">10 Job Remaining</span>
                                                                                        </div>
                                                                                        <div class="list-item">
                                                                                            <span class="item-title">Date your plan will reset</span>
                                                                                            <span class="item-value">12 September, 2018</span>
                                                                                        </div>
                                                                                        <div class="list-item">
                                                                                            <span class="item-title">Date of next billing period</span>
                                                                                            <span class="item-value">$4,700 on 12 September, 2018</span>
                                                                                        </div>
                                                                                    </div>
                                                                                    <div class="upgrade-info">
                                                                                        <span>
                                                                                            Would you like to proceed with <%= isUpgrade ? "upgrading your account?" : "this change?" %>
                                                                                        </span>
                                                                                    </div>
                                                                                </div>
                                                                                <div class="change-plan-button">
                                                                                    <a class="change-plan-no-button popup-no-button">No</a>
                                                                                    <oneit:button   skin="link" value="Yes"     name="saveCompany"      cssClass="change-plan-yes-button"
                                                                                                    requestAttribs="<%= CollectionUtils.mapEntry("nextPage", nextPage)
                                                                                                                                .toMap() %>" />

                                                                                </div>
                                                                            </div> 
                                                                    <%
                                                                        }
                                                                        else
                                                                        {
                                                                    %>
                                                                            <oneit:button   skin="link" value="Select"     name="saveCompany"      cssClass="btn select-btn"
                                                                                        requestAttribs="<%= CollectionUtils.mapEntry("nextPage", nextPage)
                                                                                                                            .mapEntry ("IsPayment", Boolean.TRUE)
                                                                                                                            .mapEntry ("PaymentPlan", paymentPlan)
                                                                                                                            .toMap() %>" />
                                                                    <%
                                                                        }
                                                                    %>
                                                                </div>
                                                            </div>
                                                    <%
                                                        }
                                                    %>                                                                    
                                                        <div class="additional-jobs-over">
                                                            <span class="blue-alert">
                                                                Additional jobs over plan allowance are billed at the Cost Per Job for the subscription level
                                                            </span>
                                                            <span>
                                                                Would you like to set a maximum limit on the total jobs able to be posted
                                                            </span>
                                                        </div>
                                                        <div class="set-a-cap-option">
                                                            <div >
                                                                <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:recalcClass>
                                                                    <div class="slider round"></div>
                                                                </label>
                                                                <span>yes, set a cap</span>
                                                            </div>
                                                        </div>
                                                        <div class="setmax">
                                                            <div>
                                                                <oneit:ormInput obj="<%= hiringTeam %>"    type="text" attributeName="MaxCap"    cssClass="form-control" />      

                                                                <oneit:button   value="Set Max"     name="saveCompany"      cssClass="btn btn-primary"
                                                                                requestAttribs="<%= CollectionUtils.mapEntry("nextPage", nextPage)
                                                                                                                    .toMap() %>" />
                                                            </div>
                                                        </div>

                                                        <div class="form-group row">
                                                            <oneit:button   value="Update Subscription" name="saveCompany"      cssClass="btn btn-primary largeBtn btn-green save-btn" style="display:inline;"
                                                                            requestAttribs="<%= CollectionUtils.mapEntry("nextPage", nextPage)
                                                                                                            .mapEntry ("restartProcess", Boolean.TRUE)
                                                                                                            .mapEntry ("Company", company)
                                                                                                            .mapEntry ("IsPayment", Boolean.TRUE)
                                                                                                            .mapEntry ("PaymentPlan", null)
                                                                                                            .mapEntry ("attribNamesToRestore", Collections.singleton("HiringTeam"))
                                                                                                            .toMap() %>" />
                                                        </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    <div class="text-center footer-note">
                                        Looking to cancel your account? Please <a href="http://www.talentology.com/">contact us.</a>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </oneit:form>
            </div>
        </div>
    </div>
                                                        
    
     <div id="invalid-coupon-popup" style="display:none" >
                 <div class="change-plan-content">
                    <h3>Oops!</h3>
                    <div class="upgrade-info">
                        <span>We're having some difficulty validating your coupon. <br> Please check the code supplied and try again</span>
                        <span>For further assitance, please <a href='#'>contact us</a></span>
                    </div>
                </div>
                <div class="change-plan-button">
                    <a class="invalid-coupon-close-button popup-no-button">Close & Try</a>
                </div>        
     </div>           
      
                                                         
</oneit:dynIncluded>
