<?php
/**
 * The edit view 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      Gang Liu <liugang@cnezsoft.com>
 * @package     contract
 * @version     $Id$
 * @link        http://www.zdoo.com
 */
?>
<?php include '../../../sys/common/view/header.lite.html.php';?>
<?php include '../../../sys/common/view/editor.html.php';?>
<?php js::set('label', $lang->$moduleType->order);?>
<div class='xuanxuan-card'>
  <form method='post' id='ajaxForm'>
    <div class='panel'>
      <div class='panel-body'>
        <table class='table table-form'>
          <tr>
            <th class='w-80px'><?php echo $lang->$moduleType->name;?></th>
            <td><?php echo html::input('name', $contract->name, "class='form-control'");?></td>
          </tr>
          <tr>
            <th class='w-80px'><?php echo $lang->$moduleType->code;?></th>
            <td><?php echo html::input('code', $contract->code, "class='form-control'");?></td>
          </tr>
          <?php if($moduleType == 'contract'):?>
          <?php foreach($contractOrders as $currentOrder):?>
          <tr>
            <th class='orderTH'><?php echo $lang->$moduleType->order;?></th>
            <td>
              <div class='form-group'>
                <span class='col-xs-6'>
                  <select name='order[]' class='select-order form-control'>
                    <?php foreach($orders as $order):?>
                    <?php if(!$order):?>
                    <option value='' data-real='' data-currency=''></option>
                    <?php else:?>
                    <?php if($order->id == $currentOrder->id or $order->status == 'normal'):?>
                    <?php $selected = $currentOrder->id == $order->id ? "selected='selected'" : '';?>
                    <option value="<?php echo $order->id;?>" <?php echo $selected;?> data-real="<?php echo $order->plan;?>" data-currency="<?php echo $order->currency?>"><?php echo $order->title;?></option>
                    <?php endif;?>
                    <?php endif;?>
                    <?php endforeach;?>
                  </select>
                </span>
                <span class='col-xs-6'>
                  <div class='input-group'>
                    <div class='input-group-addon order-currency'><?php echo zget($currencySign, $currentOrder->currency, '');?></div>
                    <?php echo html::input('real[]', ($currentOrder->real and $currentOrder->real != '0.00') ? $currentOrder->real : $currentOrder->plan, "class='order-real form-control' placeholder='{$this->lang->contract->placeholder->real}'");?>
                    <div class='input-group-btn'>
                      <a href='javascript:;' class='btn plus'><i class='icon-plus'></i></a>
                      <a href='javascript:;' class='btn minus'><i class='icon-remove'></i></a>
                    </div>
                  </div>
                </span>
              </div>
            </td>
          </tr>
          <?php endforeach;?>
          <?php if(!$contractOrders):?>
          <tr>
            <th class='orderTH'><?php echo $lang->$moduleType->order;?></th>
            <td>
              <div class='form-group'>
                <span class='col-xs-6'>
                  <select name='order[]' class='select-order form-control'>
                    <?php foreach($orders as $order):?>
                    <?php if(!$order):?>
                    <option value='' data-real='' data-currency=''></option>
                    <?php else:?>
                    <option value="<?php echo $order->id;?>" data-real="<?php echo $order->plan;?>" data-currency="<?php echo $order->currency?>"><?php echo $order->title;?></option>
                    <?php endif;?>
                    <?php endforeach;?>
                  </select>
                </span>
                <span class='col-xs-6'>
                  <div class='input-group'>
                    <div class='input-group-addon order-currency'><?php echo zget($currencySign, $contract->currency, $contract->currency)?></div>
                    <?php echo html::input('real[]', '', "class='order-real form-control' placeholder='{$this->lang->contract->placeholder->real}'");?>
                    <div class='input-group-btn'>
                      <a href='javascript:;' class='btn plus'><i class='icon-plus'></i></a>
                      <a href='javascript:;' class='btn minus'><i class='icon-remove'></i></a>
                    </div>
                  </div>
                </span>
              </div>
            </td>
          </tr>
          <?php endif;?>
          <tbody id='tmpData' class='hide'></tbody>
          <?php endif;?>
          <tr>
            <th><?php echo $lang->$moduleType->amount;?></th>
            <td>
              <div class='form-group'>
                <span class='col-xs-6'><?php echo html::select('currency', $currencyList, $contract->currency, "class='form-control'");?></span>
                <span class='col-xs-6'><?php echo html::input('amount', $contract->amount, "class='form-control'");?></span>
              </div>
            </td>
          </tr>
          <tr>
            <th><?php echo $lang->$moduleType->items;?></th>
            <td><?php echo html::textarea('items', $contract->items, "class='form-control'");?></td>
          </tr>
          <?php if(commonModel::hasPriv('file', 'upload')):?>
          <tr>
            <th><?php echo $lang->files;?></th>
            <td><?php echo $this->fetch('file', 'buildForm');?></td>
          </tr>
          <?php endif;?>
        </table>
      </div>
    </div>
    <div class='panel'>
      <div class='panel-heading'>
        <strong><?php echo $lang->basicInfo;?></strong>
      </div>
      <div class='panel-body'>
        <table class='table table-form'>
          <tr>
            <th class='w-70px'><?php echo $lang->$moduleType->customer;?></th>
            <td><?php echo html::select('customer', $customers, $contract->customer, "class='form-control' disabled");?></td><td></td>
          </tr>
          <?php if($moduleType == 'contract'):?>
          <tr>
            <th><?php echo $lang->$moduleType->delivery;?></th>
            <td><?php echo html::select('delivery', $lang->$moduleType->deliveryList, $contract->delivery, "class='form-control'");?></td>
          </tr>
          <?php endif;?>
          <tr>
            <th><?php echo $lang->$moduleType->return;?></th>
            <td><?php echo html::select('return', $lang->$moduleType->returnList, $contract->return, "class='form-control'");?></td>
          </tr>
          <tr>
            <th><?php echo $lang->$moduleType->status;?></th>
            <td><?php echo html::select('status', $lang->$moduleType->statusList, $contract->status, "class='form-control'");?></td>
          </tr>
          <tr>
            <th><?php echo $lang->$moduleType->contact;?></th>
            <td><?php echo html::select('contact', $contacts, $contract->contact, "class='form-control chosen'");?></td>
          </tr>
          <?php if($moduleType == 'contract'):?>
          <tr>
            <th><?php echo $lang->$moduleType->address;?></th>
            <td><?php echo html::select('address', $addresses, $contract->address, "class='form-control'");?></td>
          </tr>
          <?php endif;?>
          <tr>
            <th><?php echo $lang->$moduleType->begin;?></th>
            <td><?php echo html::input('begin', formatTime($contract->begin), "class='form-control form-date'");?></td>
          </tr>
          <tr>
            <th><?php echo $lang->$moduleType->end;?></th>
            <td><?php echo html::input('end', formatTime($contract->end), "class='form-control form-date'");?></td>
          </tr>
          <?php if($moduleType == 'contract'):?>
          <tr>
            <th><?php echo $lang->$moduleType->handlers;?></th>
            <td><?php echo html::select('handlers[]', $users, $contract->handlers, "class='form-control chosen' multiple");?></td>
          </tr>
          <?php endif;?>
        </table>
      </div>
    </div>
    <div class='panel'>
      <div class='panel-heading'>
        <strong><?php echo $lang->$moduleType->lifetime;?></strong>
      </div>
      <div class='panel-body'>
        <table class='table table-form table-data' id='contractLife'>
          <tr>
            <th class='w-70px'><?php echo $lang->$moduleType->createdBy;?></th>
            <td><?php echo zget($users, $contract->createdBy);?></td>
          </tr>
          <tr>
            <th><?php echo $lang->$moduleType->signedBy;?></th>
            <td><?php echo html::select('signedBy', $users, $contract->signedBy, "class='form-control chosen'");?></td>
          </tr>
          <tr>
            <th><?php echo $lang->$moduleType->signedDate;?></th>
            <td><?php echo html::input('signedDate', formatTime($contract->signedDate), "class='form-control form-date'");?></td>
          </tr>
          <?php if($moduleType == 'contract'):?>
          <tr>
            <th><?php echo $lang->$moduleType->deliveredBy;?></th>
            <td><?php echo html::select('deliveredBy', $users, $contract->deliveredBy, "class='form-control chosen'");?></td>
          </tr>
          <tr>
            <th><?php echo $lang->$moduleType->deliveredDate;?></th>
            <td><?php echo html::input('deliveredDate', formatTime($contract->deliveredDate), "class='form-control form-date'");?></td>
          </tr>
          <?php endif;?>
          <tr>
            <th><?php echo $lang->$moduleType->returnedBy;?></th>
            <td><?php echo html::select('returnedBy', $users, $contract->returnedBy, "class='form-control chosen'");?></td>
          </tr>
          <tr>
            <th><?php echo $lang->$moduleType->returnedDate;?></th>
            <td><?php echo html::input('returnedDate', formatTime($contract->returnedDate), "class='form-control form-date'");?></td>
          </tr>
          <?php if($contract->finishedBy):?>
          <tr>
            <th><?php echo $lang->$moduleType->finishedBy;?></th>
            <td><?php echo html::select('finishedBy', $users, $contract->finishedBy, "class='form-control chosen'");?></td>
          </tr>
          <tr>
            <th><?php echo $lang->$moduleType->finishedDate;?></th>
            <td><?php echo html::input('finishedDate', formatTime($contract->finishedDate), "class='form-control form-date'");?></td>
          </tr>
          <?php endif;?>
          <?php if($contract->canceledBy):?>
          <tr>
            <th><?php echo $lang->$moduleType->canceledBy;?></th>
            <td><?php echo html::select('canceledBy', $users, $contract->canceledBy, "class='form-control chosen'");?></td>
          </tr>
          <tr>
            <th><?php echo $lang->$moduleType->canceledDate;?></th>
            <td><?php echo html::input('canceledDate', formatTime($contract->canceledDate), "class='form-control form-date'");?></td>
          </tr>
          <?php endif;?>
        </table>
      </div>
    </div>
    <?php echo $this->fetch('action', 'history', "objectType={$moduleType}&objectID={$contract->id}")?>
    <div class='page-actions'><?php echo html::submitButton() . ' ' . html::backButton();?></div>
  </form>
</div>
<?php if($moduleType == 'contract'):?>
<table id='orderGroup' class='hide'>
  <tr>
    <th class='orderTH'></th>
    <td>
      <div class='form-group'>
        <span class='col-xs-6'>
          <select name='order[]' class='select-order form-control'>
            <?php foreach($orders as $order):?>
            <?php if(!$order):?>
            <option value='' data-real='' data-currency=''></option>
            <?php else:?>
            <option value="<?php echo $order->id;?>" data-real="<?php echo $order->plan;?>" data-currency="<?php echo $order->currency?>"><?php echo $order->title;?></option>
            <?php endif;?>
            <?php endforeach;?>
          </select>
        </span>
        <span class='col-xs-6'>
          <div class='input-group'>
            <div class='input-group-addon order-currency'><?php echo zget($currencySign, $contract->currency, $contract->currency)?></div>
            <?php echo html::input('real[]', '', "class='order-real form-control' placeholder='{$this->lang->contract->placeholder->real}'");?>
            <div class='input-group-btn'>
              <a href='javascript:;' class='btn plus'><i class='icon-plus'></i></a>
              <a href='javascript:;' class='btn minus'><i class='icon-remove'></i></a>
            </div>
          </div>
        </span>
      </div>
    </td>
  </tr>
</table>
<?php endif;?>
<?php js::set('currencySign', array('' => '') + $currencySign);?>
<?php include '../../common/view/footer.html.php';?>
