{include file="header.tpl"}

<div class="main-content">
  <div class="page-content">
    <div class="row">
      <div class="col-xl-12">
        <div class="card">
          <div class="card-body">
            <h4 class="card-title">Ask for withdrawal</h4>
            <br>

            {if $say eq 'processed'}
              {if $batch eq ''}Withdrawal request has been successfully saved.
              {else} Withdrawal has been processed. Batch id: {$batch}
              {/if}
              <br><br>
            {/if}

            {if $fatals}
              {if $fatals.times_limit}
                You can withdraw {$settings.limit_withdraw_period_times} per {$settings.limit_withdraw_period_date} only.
              {/if}
            {else}

            {* --- Error Messages --- *}
            {if $say eq 'ec_forbidden' || $errors.ec_forbidden}
              <div class="alert alert-warning">Withdraw for this processor is temporarily forbidden.</div>
            {/if}
            {if $say eq 'on_hold' || $errors.on_hold}
              <div class="alert alert-warning">This amount is currently on hold.</div>
            {/if}
            {if $say eq 'zero' || $errors.zero}
              <div class="alert alert-warning">Withdrawal amount must be greater than {$currency_sign}0.00.</div>
            {/if}
            {if $say eq 'less_min' || $errors.less_min}
              <div class="alert alert-warning">Minimum withdrawal is {$currency_sign}{$fees.amount_min}.</div>
            {/if}
            {if $say eq 'greater_max' || $errors.greater_max}
              <div class="alert alert-warning">Maximum withdrawal is {$currency_sign}{$fees.amount_max}.</div>
            {/if}
            {if $say eq 'daily_limit' || $errors.daily_limit}
              <div class="alert alert-warning">You have exceeded your daily withdrawal limit.</div>
            {/if}
            {if $say eq 'not_enought' || $errors.not_enought}
              <div class="alert alert-warning">Requested amount exceeds your available balance.</div>
            {/if}
            {if $say eq 'invalid_transaction_code' || $errors.invalid_transaction_code}
              <div class="alert alert-danger">Invalid transaction code.</div>
            {/if}
            {if $say eq 'invalid_tfa_code' || $errors.invalid_tfa_code}
              <div class="alert alert-danger">Invalid 2FA code.</div>
            {/if}
            {if $say eq 'no_deposits' || $errors.no_deposits}
              <div class="alert alert-warning">Withdrawal is only available after making a deposit.</div>
            {/if}
            {if $say eq 'no_active_deposits' || $errors.no_active_deposits}
              <div class="alert alert-warning">You must have an active deposit to withdraw.</div>
            {/if}
            {if $errors.turing_image}
              <div class="alert alert-danger">Invalid CAPTCHA.</div>
            {/if}

            {* --- Preview Step --- *}
            {if $preview}

              <form method="post">
                <input type="hidden" name="a" value="withdraw">
                <input type="hidden" name="action" value="withdraw">
                <input type="hidden" name="amount" value="{$amount}">
                <input type="hidden" name="ec" value="{$ec}">
                <input type="hidden" name="comment" value="{$comment|escape:html}">

                <table class="table table-sm">
                  <tr><th>Payment System:</th><td>{$currency}</td></tr>
                  <tr><th>Account:</th><td>{$account}</td></tr>
                  <tr><th>Debit Amount:</th><td>{$currency_sign}{$amount}</td></tr>
                  <tr>
                    <th>Withdrawal Fee:</th>
                    <td>
                      {if $fees.fee > 0}
                        {$fees.percent}% + {$currency_sign}{$fees.add_amount}
                        (min. {$currency_sign}{$fees.fee_min}, max. 
                        {if $fees.fee_max}{$currency_sign}{$fees.fee_max}{else}no{/if})
                      {else}
                        No fee
                      {/if}
                    </td>
                  </tr>

                  {if $converted}
                  <tr><th>Credit Amount:</th><td>{$currency_sign}{$converted.amount}</td></tr>
                  <tr><th>{$converted.fiat} Amount:</th><td>{$to_withdraw}</td></tr>
                  {else}
                  <tr><th>Credit Amount:</th><td>{$currency_sign}{$to_withdraw}</td></tr>
                  {/if}

                  {if $comment}
                  <tr><th>Note:</th><td>{$comment|escape:html}</td></tr>
                  {/if}

                  {if $settings.use_transaction_code && $userinfo.transaction_code}
                  <tr>
                    <th>Transaction Code:</th>
                    <td><input type="password" name="transaction_code" class="form-control form-control-sm" size="15"></td>
                  </tr>
                  {/if}

                  {if $userinfo.tfa_settings.withdraw}
                  <tr>
                    <th>2FA Code:</th>
                    <td>
                      <input type="text" name="tfa_code" class="form-control form-control-sm" size="15">
                      <input type="hidden" name="tfa_time" id="tfa_time">
                    </td>
                  </tr>
                  {literal}
                  <script>
                    document.getElementById('tfa_time').value = (new Date()).getTime();
                  </script>
                  {/literal}
                  {/if}

                  <tr>
                    <td colspan="2">
                      <input type="submit" value="Confirm" class="btn btn-sm btn-primary">
                    </td>
                  </tr>
                </table>
              </form>

            {* --- Withdraw Form --- *}
            {else}
              <form method="post">
                <input type="hidden" name="a" value="withdraw">
                <input type="hidden" name="action" value="preview">
                <input type="hidden" name="say" value="">

                <table class="table table-sm">
                  <tr>
                    <td>Account Balance:</td>
                    <td>{$currency_sign}<b>{$ab_formated.total}</b></td>
                  </tr>
                  <tr>
                    <td>Pending Withdrawals:</td>
                    <td>{$currency_sign}<b>{if $ab_formated.withdraw_pending != 0}{$ab_formated.withdraw_pending|amount_format}{else}0.00{/if}</b></td>
                  </tr>
                </table>

                <table class="table table-sm">
                  <tr>
                    <th></th>
                    <th>Processing</th>
                    <th>Available</th>
                    <th>Pending</th>
                    <th>Account</th>
                  </tr>
                  {foreach from=$ps item=p}
                  <tr>
                    <td>
                      {if $p.available > 0 && ($p.status > 0 || $p.available > 0)}
                        <input type="radio" name="ec" value="{$p.id}" {if $frm.ec == $p.id}checked{/if}>
                      {/if}
                    </td>
                    <td><img src="images/{$p.id}.gif" width="44" height="17" class="align-middle"> {$p.name|escape:html}</td>
                    <td><b class="text-success">{$currency_sign}{$p.available}</b></td>
                    <td><b class="text-danger">{$currency_sign}{$p.pending}</b></td>
                    <td>
                      {if $p.account != ''}
                        {$p.account|escape:html}
                      {else}
                        <a href="{"?a=edit_account"|encurl}"><i>not set</i></a>
                      {/if}
                    </td>
                  </tr>
                  {/foreach}
                </table>

                {if $have_available}
                <table class="table table-sm w-50">
                  <tr>
                    <td>Withdrawal ({$currency_sign}):</td>
                    <td><input type="text" name="amount" value="{$frm.amount|amount_format|default:"10.00"}" class="form-control form-control-sm"></td>
                  </tr>
                  <tr>
                    <td colspan="2">
                      <textarea name="comment" class="form-control form-control-sm" rows="4">Your comment</textarea>
                    </td>
                  </tr>

                  {if $ti.check.withdrawal}
                  <tr>
                    <td><img src="{"?a=show_validation_image&`$ti.session.name`=`$ti.session.id`&rand=`$ti.session.rand`"|encurl}"></td>
                    <td><input type="text" name="validation_number" class="form-control form-control-sm" size="15"></td>
                  </tr>
                  {/if}

                  <tr>
                    <td colspan="2"><input type="submit" value="Request" class="btn btn-sm btn-primary"></td>
                  </tr>
                </table>
                {else}
                  <br><br><div class="alert alert-info">You have no funds to withdraw.</div>
                {/if}
              </form>
            {/if}
            {/if}

          </div>
        </div>
      </div>
    </div>
  </div>
</div>

{include file="footer.tpl"}
