<%@ 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>
<%
    SecUser     loggedInUser    =   SecUser.getTXUser(transaction);
    CompanyUser companyUser     =   loggedInUser.getExtension(CompanyUser.REFERENCE_CompanyUser);
    Company     company         =   companyUser.getCompany();
    Job         job             =   (Job) process.getAttribute("Job");
    String      nextPage        =   WebUtils.getSamePageInRenderMode(request, WebUtils.CREATED_JOB) + "&JobID=" + job.getObjectID() + "&fromJob=true";
    Boolean     ppj             =   (Boolean) process.getAttribute("PPJ");
    String      jobsPage        =   WebUtils.getSamePageInRenderMode(request, "Page");
%>
    <oneit:form name="makePayment"  method="post"   enctype="multipart/form-data">

    <script type="text/javascript">
        $(document).ready(function()
        {
            recalcFunction = setupRecalc ($("makePayment"), {'recalcOnError':true});
        });
    </script> 
    
        <div class="main-created-job card-payment">
            <h1 class="page-title select-payment-optio">
                Enter Payment Details
            </h1>
            <div class="form-page-area billing-content-area">
                
                <oneit:dynInclude   page="/extensions/adminportal/inc/payment_plan.jsp" data="<%= CollectionUtils.EMPTY_MAP%>"  
                                    Company="<%= company %>"    Job="<%= job %>"/>
                
                <div class="form-group row">
                    <div class="col-md-12 col-sm-12 col-xs-12 text-left">
                        <label class="label-20 pay-subsc-txt">Payment</label><br/>               
                        <span id="card-errors" style="color: #eb1c26; font-size: 15px;"></span>
                    </div>
                </div>
        <%
            if(company.getCardID() != null)
            {
        %>
                <oneit:dynInclude   page="/extensions/adminportal/inc/existing_card.jsp" data="<%= CollectionUtils.EMPTY_MAP%>"  
                                    Company="<%= company %>"    IsEdit="<%= false %>"   IsReplace="<%= false %>"/>

        <%
            }
            else
            {
        %>
                <div class="form-group row">
                    <div class="col-md-12 col-sm-12 col-xs-12 text-left">
                        <label class="label-14">Your card details will be saved for future billing</label>            
                    </div>
                </div>   
                <div class="grey-area">
                    <oneit:dynInclude   page="/extensions/adminportal/inc/card_details.jsp" data="<%= CollectionUtils.EMPTY_MAP%>"
                                        Company="<%= company %>"    IsEdit="<%= false %>"   IsReplace="<%= true %>"/>
                </div>
        <%
            }
        %>
                <div class="form-group row" style="padding-top: 30px;">
                    <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6 btn-footer">
                        <oneit:button   value="Cancel and go back to Jobs"   name="gotoPage"  skin="link" cssClass="cancel-and-go-back"
                                        requestAttribs="<%= CollectionUtils.mapEntry("nextPage", jobsPage)
                                                                            .toMap() %>" />
                    </div>
                    <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6 btn-right">
                        <oneit:button   value="Pay and Open Job"   name="savePayment"   cssClass="btn btn-primary large-btn btn-green"
                                        requestAttribs='<%= CollectionUtils.mapEntry("nextPage", nextPage)
                                                                            .mapEntry("Company", company)
                                                                            .mapEntry("PPJ", ppj)
                                                                            .toMap() %>'/>
                    </div>
                </div>
            </div>
        </div>
    </oneit:form>
    <oneit:form name="editJob"  method="post"   enctype="multipart/form-data">
        <div class="row">
            <div class="col-lg-4 col-md-4 col-sm-6">
                <div class="form-group hide">
                    <input type="hidden" name="stripe-token-id" />
                </div>
            </div>
        </div>
        <oneit:button   value="Pay" name="savePayment" cssClass="hide"  id="payNow" 
                                                        requestAttribs='<%= CollectionUtils.mapEntry("nextPage", nextPage)
                                                                                            .mapEntry("Company", company)
                                                                                            .mapEntry("ReplaceCard", Boolean.TRUE)
                                                                                            .mapEntry("PPJ", ppj)
                                                                                            .toMap() %>'/>
    </oneit:form>
    <script src="https://js.stripe.com/v3/"></script>
    <script>
        var stripePubKey = '<%= MakePaymentFP.STRIPE_PUB_KEY %>';
    </script>
    <oneit:script>
        <!-- MUST be included after initializing stripePubKey -->
        <oneit:script src="/scripts/performaStripe.js"/>
    </oneit:script>
</oneit:dynIncluded>