<?php
/**
 * Marketplace - Component Marketplace 
 * ******************************************************************
 *
 * PHP version 7.0
 *
 * @category   Component
 * @package    Joomla
 * @author     WebKul software private limited <support@webkul.com>
 * @copyright  2010 WebKul software private limited
 * @license    http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
 * @version    GIT:5.2
 * @filesource http://store.webkul.com
 * @link       Technical Support:  webkul.uvdesk.com
 * ******************************************************************
 */
// no direct access
defined('_JEXEC') or die('Restricted access');
$sellerid=JFactory::getApplication()->input->get('sellerid');
$remita_form=JFactory::getApplication()->input->get('rrr');
$model=$this->getModel('commisions');
$commision_data=$model->getSellerCommisionInfo($sellerid);
$seller_info=JFactory::getUser($sellerid);
$admin_info=JFactory::getUser();

?>
<style>
    .main-container{
        overflow: hidden;
    }
    .heading{
        font-size: 18px;
        text-align: center;

    }
    .lbl,.fld{
        display: inline-block;
    }
    .seller-info,.sub-container{
        margin:10px;
    }
    .wk_seller_name,.wk_seller_email{
        margin:5px;
    }
    .note{
        text-align: center;
        width:40%;
        background-color: #3BAFDA;
        margin: 10px auto;
    }
    .required{
        color:red;
    }
</style>

<div class="main-container">
    <form action="<?php echo JRoute::_('index.php?option=com_marketplace&view=commisions'); ?>" method="post" name="adminForm" id="adminForm" target="_top">
        <div class="heading">
            <?php echo JText::_('PAY_TO_SELLER');?>
        </div>
        <div class="note"><?php echo JText::_('AMOUNT_NOTE');?></div>
        <div class="seller-info">
            <div class="wk_seller_name">
                <span class="lbl"><?php echo JText::_('CUSTOMER_NAME')?>:</span>
                <span class="fld"><?php echo $seller_info->name ?></span>
            </div>
            <div class="wk_seller_email">
                <span class="lbl"><?php echo JText::_('CUSTOMER_EMAIL')?>:</span> 
                <span class="fld"><?php echo $seller_info->email ?></span>
            </div>
        </div>
        <div class="sub-container">
            <div class="input_field">
                <label for="seller_amount"><?php echo JText::_('AMOUNT');?><span class="required">*</span></label>
                <input type="text" required="true" class="form-field" id="seller_amount" name="seller_amount" value="<?php echo $commision_data->amount_remain;?>" />
                <label for="payer_name"><?php echo JText::_('PAYER_NAME');?><span class="required">*</span></label>
                <input type="text" required="true" class="form-field" id="payer_name" name="payer_name" value="<?php echo $admin_info->name;?>" />
                <label for="payer_email"><?php echo JText::_('PAYER_EMAIL');?><span class="required">*</span></label>
                <input type="text" required="true" class="form-field" id="payer_email" name="payer_email" value="<?php echo $admin_info->email;?>" />
                <label for="payer_phone"><?php echo JText::_('PAYER_PHONE');?></label>
                <input type="text" class="form-field" id="payer_phone" name="payer_phone" value="" />
            </div>
            <div class="pay_button">
                <input type="submit" id="pay_button" value="<?php echo JText::_('PAY')?>" />
            </div>   
        </div>
        <input type="hidden" name="sellerid" value="<?php echo $sellerid;?>" />
        <input type="hidden" name="option" value="com_marketplace" />
          <input type="hidden" name="controller" value="commisions" />
          <input type="hidden" name="view" value="commisions" />
          <input type="hidden" name="task" value="commisions.remitapay" />
        <?php echo JHTML::_('form.token'); ?>
    </form>
</div>

<script type="text/javascript">

    jQuery(document).ready(function(){
        jQuery("#pay_button").on('click',function(e){
            e.preventDefault();
            var amt_regex="^[0-9]+(.[0-9]*)?$";
            var em = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
            var nm =/^[A-Za-z ]{3,40}$/;
            var amount=jQuery("#seller_amount").val();
            
            if (amount.match(amt_regex) == null || amount<=0) {
                
                jQuery('#seller_amount').next('.wk-error').remove();
                jQuery('#seller_amount').after('<p class="wk-error" style="color:red;display:block;">Invalid Amount</p>');
            }
            else{
                jQuery('#seller_amount').next('.wk-error').remove();
            }
            if(em.test(jQuery('#payer_email').val()))
             {
                 
                 jQuery('#payer_email').next(".wk-error").remove();
             }
            else
            {
                jQuery('#payer_email').next('.wk-error').remove();
                jQuery('#payer_email').after('<p class="wk-error" style="color:red;display:block;">Invalid Email</p>');
            }
            if(nm.test(jQuery('#payer_name').val().trim()))
             {
                 
                 jQuery('#payer_name').next(".wk-error").remove();
             }
             else
             {
                 jQuery('#payer_name').next('.wk-error').remove();
                 jQuery('#payer_name').after('<p class="wk-error" style="color:red;display:block;">Accept only Alphabets(minimum 3)</p>');

             }
             if(jQuery('.wk-error').text()){

             }
            else{
                jQuery(this.form).submit();
            }

        });
    });
</script>