<?php
/**
 * The receive payments file of contract module of ZDOO.
 *
 * @copyright   Copyright 2009-2018 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
 * @license     ZPL (http://zpl.pub/page/zplv12.html)
 * @author      Tingting Dai <daitingting@xirangit.com>
 * @package     contract
 * @version     $Id$
 * @link        http://www.zdoo.com
 */
?>
<?php include '../../../sys/common/view/header.modal.html.php';?>
<?php include '../../../sys/common/view/editor.html.php';?>
<?php js::set('mainCurrency', $config->setting->mainCurrency);?>
<?php $methodName = $this->config->contract->receiveType[$contract->type];?>
<form method='post' id='receiveForm' class='form-table' action='<?php echo inlink($methodName, "contractID={$contract->id}")?>'>
  <table class='table table-form'>
    <tr>
      <th class='w-100px'><?php echo $lang->$moduleType->all;?></th>
      <td class='w-p60'><?php echo zget($currencySign, $contract->currency, $contract->currency) . $contract->amount;?></td>
      <td></td>
    </tr>
    <tr>
      <th><?php echo $lang->$moduleType->thisAmount;?></th>
      <td>
        <div class='input-group'>
          <?php echo html::input('amount', '', "class='form-control'");?>
          <div class='input-group-addon'>
            <label class='checkbox-inline'><input type='checkbox' id='finish' name='finish' value='1'> <?php echo $lang->$moduleType->completeReturn;?></label>
            <label class='checkbox-inline'><input type='checkbox' id='createTrade' name='createTrade' value='1' checked='checked'> <?php echo $lang->trade->create;?></label>
          </div>
        </div>
      </td>
      <td></td>
    </tr>
    <tr class='tradeTR'>
      <th><?php echo $lang->trade->depositor;?></th>
      <td>
        <select name='depositor' id='depositor' class='form-control chosen'>
          <?php
          $options = array();
          foreach($depositorList as $depositor) $options[$depositor->id] = $depositor->abbr;
          $convertedPinYin = class_exists('commonModel') ? commonModel::convert2Pinyin($options) : array();

          echo "<option value='0' data-currency='' data-keys=''></option>";
          foreach($depositorList as $depositor)
          {
              $optionPinyin = zget($convertedPinYin, $depositor->abbr, '');

              echo "<option value='{$depositor->id}' data-currency='{$depositor->currency}' data-keys='{$optionPinyin}'>{$depositor->abbr}</option>";
          }
          ?>
        </select>
      </td>
      <td>
        <?php unset($depositorList[0]);?>
        <?php unset($depositorList['']);?>
        <?php if(!$depositorList) commonModel::printLink('cash.depositor', 'browse', '', $lang->depositor->create, "class='btn createDepositor'");?>
      </td>
    </tr>
    <tr class='currencyTR'>
      <th><?php echo $lang->trade->currency;?></th>
      <td>
        <div class='input-group'>
          <?php echo html::select('currencyLabel', $lang->currencyList, $config->setting->mainCurrency, "class='form-control' readonly");?>
          <?php echo html::hidden('currency');?>
          <span class='input-group-addon  exchangeRate'><?php echo $lang->trade->exchangeRate;?></span>
          <?php echo html::input('exchangeRate', '', "class='form-control exchangeRate'");?>
          <div class="required required-wrapper"></div>
        </div>
      </td>
      <td></td>
    </tr>
    <tr class='tradeTR'>
      <th><?php echo $lang->trade->category;?></th>
      <td><?php echo html::select('category', $categories, '', "class='form-control chosen'");?></td>
      <td></td>
    </tr>
    <tr class='tradeTR'>
      <th><?php echo $lang->trade->dept;?></th>
      <td><?php echo html::select('dept', $deptList, !empty($creator->dept) ? $creator->dept : '', "class='form-control chosen'");?></td>
      <td></td>
    </tr>
    <?php if($moduleType == 'contract'):?>
    <tr class='tradeTR'>
      <th><?php echo $lang->trade->product;?></th>
      <td><?php echo html::select('product', $productList, $product, "class='form-control chosen'");?></td>
      <td></td>
    </tr>
    <?php endif;?>
    <tr>
      <th><?php echo $lang->$moduleType->returnedBy;?></th>
      <td><?php echo html::select('returnedBy', $users, $this->app->user->account, "class='form-control chosen'");?></td>
      <td></td>
    </tr>
    <tr>
      <th><?php echo $lang->$moduleType->returnedDate;?></th>
      <td><?php echo html::input('returnedDate', helper::today(), "class='form-control form-date'");?></td>
      <td></td>
    </tr>
    <tr>
      <th><?php echo $lang->contract->handlers;?></th>
      <td colspan='2'><?php echo html::select('handlers[]', $users, $contract->handlers . ',' . $this->app->user->account, "class='form-control chosen' multiple");?></td>
    </tr>
    <tr>
      <th><?php echo $lang->comment;?></th>
      <td colspan='2'><?php echo html::textarea('comment', '', "rows='2'");?></td>
    </tr>
    <?php echo $this->printExtendFields($contract, 'table');?>
    <tr>
      <th></th>
      <td colspan='2' class='form-actions'>
        <div id='duplicateError' class='alert alert-danger duplicate hide'></div>
        <?php echo html::submitButton();?>
        <?php echo html::commonButton($lang->contract->updateTrade, 'btn btn-primary duplicate hide', "id='updateTrade'");?>
        <?php echo html::commonButton($lang->continueSave, 'btn btn-danger duplicate hide', "id='continueSubmit'");?>
      </td>
    </tr>
  </table>
</form>
<?php if(!empty($contract->returnList)):?>
<div class='panel panel-block'>
  <div class='panel-heading'><strong><?php echo $lang->$moduleType->returnRecords;?></strong></div>
  <div class='panel-body'>
    <?php foreach($contract->returnList as $return):?>
    <?php printf($lang->$moduleType->returnInfo, formatTime($return->returnedDate, DT_DATE1), zget($users, $return->returnedBy, $return->returnedBy), zget($currencySign, $return->currency, '') . $return->amount);?>
    <?php endforeach;?>
  </div>
</div>
<?php endif;?>
<?php include '../../../sys/common/view/footer.modal.html.php';?>
