<?php
/**
 * The create view file of trade 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      Xiying Guan <guanxiying@xirangit.com>
 * @package     trade
 * @version     $Id$
 * @link        http://www.zdoo.com
 */
?>
<?php include '../../common/view/header.html.php';?>
<?php include '../../../sys/common/view/datepicker.html.php';?>
<?php js::set('modeType', $type);?>
<?php js::set('mainCurrency', $config->setting->mainCurrency);?>
<div class='panel'>
  <div class='panel-heading'>
    <strong><?php echo $lang->trade->{$type};?></strong>
  </div>
  <div class='panel-body'>
    <form method='post' id='ajaxForm'>
      <table class='table table-form w-p60'>
        <tr>
          <th class='w-100px'><?php echo $lang->trade->depositor;?></th>
          <td><?php echo html::select('depositor', $depositorList, '', "class='form-control chosen'");?></td>
        </tr>
        <?php if(count($productCategories) >= 2):?>
        <tr>
          <th><?php echo $lang->product->category;?></th>
          <td><?php echo html::select('productCategory', $productCategories, '', "class='form-control chosen'");?></td>
        </tr>
        <?php endif;?>
        <tr>
          <th><?php echo $lang->trade->product;?></th>
          <td><?php echo html::select('product', array('') + $productList, '', "class='form-control chosen'");?></td>
        </tr>

        <?php if($type == 'in'):?>
        <tr class='income'>
          <th><?php echo $lang->trade->category;?></th>
          <td>
            <div class='input-group categoryBox'>
              <?php echo html::select('category', array('') + (array) $categories, '', "class='form-control chosen'");?>
              <div class='input-group-btn'>
                <?php echo html::a($this->createLink('tree', 'browse', "type=$type"), "<i class='icon icon-config'></i>", "class='btn' title={$lang->trade->manageCategory} target='_blank'");?>
              </div>
              <div class='input-group-btn'>
                <?php echo html::commonButton('<i class="icon icon-refresh"></i>', 'btn', "title={$lang->refresh} onclick='ajaxGetCategories()'");?>
              </div>
            </div>
          </td>
        </tr>
        <?php endif;?>

        <?php if($type == 'out'):?>
        <tr class='expense'>
          <th><?php echo $lang->trade->category;?></th>
          <td>
            <div class='input-group categoryBox'>
              <?php echo html::select('category', array('') + (array) $categories, '', "class='form-control chosen'");?>
              <div class='input-group-btn'>
                <?php echo html::a($this->createLink('tree', 'browse', "type=$type"), "<i class='icon icon-config'></i>", "class='btn' title={$lang->trade->manageCategory} target='_blank'");?>
              </div>
              <div class='input-group-btn'>
                <?php echo html::commonButton('<i class="icon icon-refresh"></i>', 'btn', "title={$lang->refresh} onclick='ajaxGetCategories()'");?>
              </div>
            </div>
          </td>
        </tr>
        <tr>
          <th><?php echo $lang->trade->outType;?></th>
          <td><?php echo html::checkbox('objectType', $lang->trade->objectTypeList);?></td>
        </tr>
        <tr class='customerTR hide'>
          <th><?php echo $lang->trade->traderList['in'];?></th>
          <td>
          <?php echo html::select('customer', $customerList, '', "class='form-control chosen' onchange='getOrder(this.value)' data-no_results_text='" . $lang->searchMore . "'");?>
          </td>
        </tr>
        <tr class='allCustomerTR hide'>
          <th><?php echo $lang->trade->traderList['in'];?></th>
          <td>
          <?php echo html::select('allCustomer', ($traderList + $customerList), '', "class='form-control chosen' onchange='getContract(this.value)' data-no_results_text='" . $lang->searchMore . "'");?>
          </td>
        </tr>
        <tr class='traderTR'>
          <th><?php echo $lang->trade->traderList['out'];?></th>
          <td>
            <?php if(count($traderList) > 1):?>
            <div class='input-group'>
              <?php  echo html::select('trader', $traderList, '', "class='form-control chosen' data-no_results_text='" . $lang->searchMore . "'");?>
              <?php  echo html::input('traderName', '', "class='form-control' style='display:none'");?>
              <div class='input-group-addon'><?php echo html::checkbox('createTrader', array( 1 => $lang->trade->newTrader));?></div>
            </div>
            <?php else:?>
            <?php echo html::input('traderName', '', "class='form-control'") . html::hidden('createTrader', '1');?>
            <?php endif;?>
          </td>
        </tr>
        <tr class='customer-depositor hide'>
          <th><?php echo $lang->customer->depositor;?></th>
          <td><?php echo html::input('customerDepositor', '', "class='form-control' disabled='disabled'");?></td>
        </tr>
        <tr class='hide'>
          <th><?php echo $lang->trade->order;?></th>
          <td class='orderTD'><select name='order' id='order' class='form-control'></select></td>
        </tr>
        <tr class='hide'>
          <th><?php echo $lang->trade->contract;?></th>
          <td class='contractTD'><select name='contract' id='contract' class='form-control'></select></td>
        </tr>
        <?php endif;?>

        <?php if($type == 'in'):?>
        <tr>
          <th><?php echo $lang->trade->traderList['in'];?></th>
          <td>
          <?php echo html::select('trader', $customerList, '', "class='form-control chosen' onchange='getContract(this.value)' data-no_results_text='" . $lang->searchMore . "'");?>
          </td>
        </tr>
        <tr class='customer-depositor hide'>
          <th><?php echo $lang->customer->depositor;?></th>
          <td><?php echo html::input('customerDepositor', '', "class='form-control' disabled='disabled'");?></td>
        </tr>
        <tr>
          <th><?php echo $lang->trade->contract;?></th>
          <td class='contractTD'><select name='contract' id='contract' class='form-control'></select></td>
        </tr>
        <?php endif;?>

        <tr>
          <th><?php echo $lang->trade->money;?></th>
          <td>
            <div class='input-group'>
              <?php echo html::input('money', '', "class='form-control'");?>
              <span class='input-group-addon '><?php echo $lang->trade->currency;?></span>
              <?php echo html::select('currencyLabel', $lang->currencyList, '', "class='form-control' disabled");?>
              <?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>
          </td>
        </tr>
        <tr>
          <th><?php echo $lang->trade->dept;?></th>
          <td><?php echo html::select('dept', $deptList, '', "class='form-control chosen'");?></td>
        </tr>
        <tr>
          <th><?php echo $lang->trade->handlers;?></th>
          <td><?php echo html::select('handlers[]', $users, '', "class='form-control chosen' multiple");?></td>
        </tr>
        <tr>
          <th><?php echo $lang->trade->date;?></th>
          <td><?php echo html::input('date', date('Y-m-d'), "class='form-control form-date'");?></td>
        </tr>
        <tr>
          <th><?php echo $lang->trade->desc;?></th>
          <td><?php echo html::textarea('desc','', "class='form-control' rows='3'");?></td>
        </tr>
        <?php if(commonModel::hasPriv('file', 'upload')):?>
        <tr>
          <th><?php echo $lang->trade->uploadFile;?></th>
          <td><?php echo $this->fetch('file', 'buildForm');?></td>
        </tr>
        <?php endif;?>
        <tr>
          <th></th>
          <td class='form-actions'><?php echo html::submitButton() . html::backButton();?></td>
        </tr>
      </table>
    </form>
  </div>
</div>
<script>
<?php helper::import('../js/searchcustomer.js');?>
</script>
<?php include '../../common/view/footer.html.php';?>
