<?php 
/**
 * @author      Magetop Developer (Kien)
 * @package     Magento Multi Vendor Marketplace
 * @copyright   Copyright (c) Magetop (https://www.magetop.com)
 * @terms       https://www.magetop.com/terms
 * @license     https://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 **/
$transaction = $block->getMkDetailTransactionForPay($block->getTranId()); 
$paymentDetail = $block->getPaymentMethodById($transaction['payment_id']);
$_transactionDetail = $block->getDetailPartnerForPay($transaction['seller_id']);
?>
<div class="main-col-inner">
    <div id="messages"></div>
    <div class="content-header" style="float: left; width: 100%">
        <h3 class="icon-head head-adminhtml-vendor-withdrawal" style="float: left;"><?php echo __('Withdrawal Information') ?></h3>    
        <?php if ($transaction->getPaidStatus() == 1) {?>
            <p class="form-buttons" style="float: right;">
                <button style="" onclick="rejectWithdrawal()" class="scalable delete" type="button" title="<?php echo __('Reject') ?>" id="">
                    <span><span><span><?php echo __('Reject') ?></span></span></span>
                </button>
                <button style="" onclick="completeWithdrawal();" class="scalable save" type="button" title="<?php echo __('Complete Withdrawal') ?>" id="">
                    <span><span><span><?php echo __('Complete Withdrawal') ?></span></span></span>
                </button>
            </p>
        <?php } ?>
    </div>
    <div class="entry-edit">
        <form enctype="multipart/form-data" method="post" action="<?php echo $this->getUrl('marketplace/index/pay') ?>" id="cancel_form">
            <input type="hidden" name="form_key" value="<?php echo \Magento\Framework\App\ObjectManager::getInstance()->get('Magento\Framework\Data\Form\FormKey')->getFormKey() ?>" />
            <input type="hidden" name="tran_id" value="<?php echo $block->getTranId() ?>" />
            <input type="hidden" name="seller_id" value="<?php echo $transaction['seller_id'] ?>" />
            <input type="hidden" name="type" value="cancel" />
            <input type="hidden" class="old_url" name="old_url" value="" />
            <?php if ($transaction->getPaidStatus() == 1) {?>
                <input type="hidden" name="note" id="cancel_note" value="" />
            <?php } ?>
        </form>
        <form enctype="multipart/form-data" method="post" action="<?php echo $this->getUrl('marketplace/index/pay') ?>" id="complete_form">
            <input type="hidden" name="form_key" value="<?php echo \Magento\Framework\App\ObjectManager::getInstance()->get('Magento\Framework\Data\Form\FormKey')->getFormKey() ?>" />                        
            <input type="hidden" name="tran_id" value="<?php echo $block->getTranId() ?>" />
            <input type="hidden" name="seller_id" value="<?php echo $transaction['seller_id'] ?>" />
            <input type="hidden" name="type" value="complete" />
            <input type="hidden" class="old_url" name="old_url" value="" />
            <div style="font-size: 12px" id="withdrawal_tabs_main_section_content">
                <div class="entry-edit">
                    <div class="entry-edit-head">
                        <h4 class="icon-head head-edit-form fieldset-legend"><?php echo __('Seller Information') ?></h4>
                        <div class="form-buttons"></div>
                    </div>
                    <div id="vendorinfo_form" class="fieldset ">
                        <div class="hor-scroll">
                            <table cellspacing="0" class="form-list">
                                <tbody>
                                    <tr>
                                        <td class="label"><label for="credit"><?php echo __('Seller Name') ?></label></td>
                                        <td class="value">
                                            <span style="color: #996515;font-weight: bold;">
                                                <?php echo $block->getSellerDetailById($transaction['seller_id']) ?>
                                            </span>           
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="label"><label for="credit"><?php echo __('Credit Balance') ?></label></td>
                                        <td class="value">
                                            <span style="color: #996515;font-weight: bold;">
                                                <?php echo $block->getPrice($_transactionDetail['amountremain']) ?>
                                            </span>           
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <br />
                    <div class="entry-edit-head">
                        <h4 class="icon-head head-edit-form fieldset-legend"><?php echo __('Withdrawal information') ?></h4>
                        <div class="form-buttons"></div>
                    </div>
                    <div id="withdrawal_form" class="fieldset ">
                        <div class="hor-scroll">
                            <table cellspacing="0" class="form-list">
                                <tbody>
                                    <tr>
                                        <td class="label"><label for="method"><?php echo __('Payment Method') ?></label></td>
                                        <td class="value">
                                            <?php echo $transaction['transaction_id_online']?__('Marketplace Paypal Adaptive'):$paymentDetail['name'] ?>             
                                        </td>
                                    </tr>
                                    <?php if($transaction['payment_email']){ ?>
                                        <tr>
                                            <td class="label">
                                                <label for="payment_account"><?php echo $transaction['transaction_id_online']?__('Paypal'):$paymentDetail['name'] ?>  <?php echo __('Email Account') ?></label>
                                            </td>
                                            <td class="value">
                                                <?php echo $transaction['payment_email'] ?>             
                                            </td>
                                        </tr>
                                    <?php } ?>
                                    <tr>
                                        <td class="label"><label for="amount"><?php echo __('Amount') ?></label></td>
                                        <td class="value">
                                            <span style="color: #996515;font-weight: bold;">
                                                <?php echo $block->getPrice($transaction['transaction_amount']) ?>    
                                            </span>            
                                        </td>
                                    </tr>
                                        <tr>
                                        <td class="label"><label for="fee"><?php echo __('Fee Amount') ?></label></td>
                                        <td class="value">
                                            <span style="color: #996515;font-weight: bold;">
                                                <?php echo $block->getPrice($transaction['amount_fee']) ?>   
                                            </span>            
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="label"><label for="net_amount"><?php echo __('Net Amount') ?></label></td>
                                        <td class="value">
                                            <span style="color: #996515;font-weight: bold;">
                                                <?php echo $block->getPrice($transaction['amount_paid']) ?>    
                                            </span>            
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="label"><label for="status"><?php echo __('Status') ?></label></td>
                                        <td class="value">
                                            <?php if ($transaction->getPaidStatus() == 1) echo '<span class="status_yellow">'.__('Pending').'</span>' ?>
                                            <?php if ($transaction->getPaidStatus() == 2) echo '<span class="status_green">'.__('Completed').'</span>' ?>
                                            <?php if ($transaction->getPaidStatus() == 3) echo '<span class="status_gray">'.__('Canceled').'</span>' ?>              
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="label"><label for="created_at"><?php echo __('Created At') ?></label></td>
                                        <td class="value">
                                            <?php echo $transaction->getCreatedAt() ?>               
                                        </td>
                                    </tr>
                                    <?php if($transaction['payment_additional']){ ?> 
                                        <tr>
                                            <td colspan="2">
                                                <div style="border: 1px solid #d3d3d3; padding: 10px;margin: 10px 0;border-radius: 5px; -moz-border-radius: 5px; -webkit-border-radius: 5px;background: #fffeed;">
                                                    <h3>Additional Info</h3>
                                                    <?php echo $transaction['payment_additional'] ?> 
                                                    <br/>
                                                </div>
                                            </td>
                                        </tr>
                                    <?php } ?>  
                                    <tr></tr>
                                    <?php if ($transaction->getPaidStatus() == 1) {?>
                                        <tr>
                                            <td class="label"><label for="note"><?php echo __('Note') ?></label></td>
                                            <td class="value">
                                                <textarea class="textarea" cols="50" rows="5" name="note" id="complete_note"></textarea>            
                                            </td>
                                        </tr>
                                    <?php } ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <script type="text/javascript">
        function rejectWithdrawal(){
            if(confirm('<?php echo __('Are you sure you want to do this?') ?>')){
                $('cancel_form').submit();
            }
        }
        function completeWithdrawal(){
            if(confirm('<?php echo __('Are you sure you want to do this?') ?>')){
                $('complete_form').submit();
            }
        }

        require([
            'jquery'
        ], function ($) {
            $('#complete_note').keyup(function(){
                $('#cancel_note').val($(this).val());
            });
        });
    </script>
</div>
<style>
    .hor-scroll {
        margin-bottom: -4px;
        overflow: auto;
        padding-bottom: 4px;
        width: 100%;
    }
    .form-list td.label {
        padding: 5px 0px 0px 30px;
        width: 500px;
    }
    .form-list td.value {
        padding-right: 5px !important;
        width: 400px;
    }
</style>