<?php 
/**
 * The view file for the method of view of invoice module of ZDOO.
 *
 * @copyright   Copyright 2009-2016 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
 * @license     商业软件，非开源软件
 * @author      Tingting Dai <daitingting@xirangit.com>
 * @package     invoice 
 * @version     $Id$
 * @link        http://www.zdoo.com
 */
?>
<?php include $app->getAppRoot() . 'common/view/header.html.php';?>
<?php $browseLink = $this->session->invoiceList ? $this->session->invoiceList : inlink('browse');?>
<div id='mainTitle' class='clearfix'>
  <div class='btn-toolbar pull-left'>
    <?php if(!isonlybody()):?>
    <?php echo html::a($browseLink, '<i class="icon icon-back icon-sm"></i> ' . $lang->goback, "class='btn btn-back'");?>
    <div class="divider"></div>
    <?php endif;?>
    <div class="page-title">
      <span class="label label-id"><?php echo $invoice->id?></span>
      <span class='text' title='<?php echo $invoice->invoiceTitle;?>'><?php echo $invoice->invoiceTitle;?></span>
      <span class="text" title='<?php echo $invoice->sn;?>'><?php echo $invoice->sn;?></span>
    </div>
  </div>
</div>
<div class='main-row'>
  <div class='main-col col-8'>
    <div class='panel panel-block'>
      <div class='panel-heading'><strong><?php echo $lang->invoice->view;?></strong></div>
      <div class='panel-body'>
        <table class='table table-data'>
          <tbody>
            <tr>
              <th class='w-70px text-right'><?php echo $lang->invoice->type;?></th>
              <td><?php echo zget($lang->invoice->saleTypeList, $invoice->saleType) . ' - ' . zget($lang->invoice->typeList, $invoice->type);?></td>
            </tr>
            <tr>
              <th><?php echo $lang->invoice->money;?></th>
              <td><?php echo $invoice->money;?></td>
            </tr>
            <tr>
              <th><?php echo $lang->invoice->taxRate;?></th>
              <td><?php echo $invoice->taxRate . '%';?></td>
            </tr>
            <tr>
              <th><?php echo $lang->invoice->status;?></th>
              <td><span class='<?php echo zget($config->invoice->colorList, $invoice->status);?>'><?php echo zget($lang->invoice->statusList, $invoice->status);?></span></td>
            </tr>
            <?php if($invoice->sn):?>
            <tr>
              <th><?php echo $lang->invoice->sn;?></th>
              <td><?php echo $invoice->sn;?></td>
            </tr>
            <?php endif;?>
            <tr>
              <th><?php echo $lang->invoice->invoiceTitle;?></th>
              <td><?php echo $invoice->invoiceTitle;?></td>
            </tr>
            <tr>
              <th><?php echo $lang->invoice->taxNumber;?></th>
              <td><?php echo $invoice->taxNumber;?></td>
            </tr>
            <?php if($invoice->registedAddress):?>
            <tr>
              <th><?php echo $lang->invoice->registedAddress;?></th>
              <td><?php echo $invoice->registedAddress;?></td>
            </tr>
            <?php endif;?>
            <?php if($invoice->phone):?>
            <tr>
              <th><?php echo $lang->invoice->phone;?></th>
              <td><?php echo $invoice->phone;?></td>
            </tr>
            <?php endif;?>
            <?php if($invoice->bankName):?>
            <tr>
              <th><?php echo $lang->invoice->bankName;?></th>
              <td><?php echo $invoice->bankName;?></td>
            </tr>
            <?php endif;?>
            <?php if($invoice->bankAccount):?>
            <tr>
              <th><?php echo $lang->invoice->bankAccount;?></th>
              <td><?php echo $invoice->bankAccount;?></td>
            </tr>
            <?php endif;?>
            <?php if(!empty($invoice->desc)):?>
            <tr>
              <th><?php echo $lang->invoice->desc;?></th>
              <td><?php echo $invoice->desc;?></td>
            </tr>
            <?php endif;?>
            <?php if(!empty($invoice->files)):?>
            <tr>
              <th></th>
              <td><?php echo $this->fetch('file', 'printFiles', array('files' => $invoice->files, 'fieldset' => 'false'))?></td>
            </tr>
            <?php endif;?>
          </tbody>
        </table>
      </div>
    </div> 
    <?php if(!empty($invoice->details)):?>
    <div class='panel panel-block'>
      <div class='panel-heading'><strong><?php echo $lang->invoice->detail?></strong></div>
      <div class='panel-body'>
        <table class='table table-bordered table-fixed table-hover'>
          <tr class='text-center'>
            <th class='w-50px'><?php echo $lang->invoice->id;?></th>
            <th class='text-left'><?php echo $lang->invoice->item;?></th>
            <th class='w-100px'><?php echo $lang->invoice->model;?></th>
            <th class='w-100px'><?php echo $lang->invoice->unit;?></th>
            <th class='w-100px text-right'><?php echo $lang->invoice->amount;?></th>
            <th class='w-100px text-right'><?php echo $lang->invoice->price;?></th>
            <th class='w-100px text-right'><?php echo $lang->invoice->money;?></th>
            <th class='w-100px text-right'><?php echo $lang->invoice->taxMoney;?></th>
          </tr>
          <?php foreach($invoice->details as $detail):?>
          <tr>
            <td class='text-center'><?php echo $detail->id;?></td>
            <td><?php echo $detail->item;?></td>
            <td><?php echo $detail->model;?></td>
            <td class='text-center'><?php echo $detail->unit;?></td>
            <td class='text-right'><?php echo $detail->amount;?></td>
            <td class='text-right'><?php echo $detail->price;?></span></td>
            <td class='text-right'><?php echo $detail->money;?></td>
            <td class='text-right'><?php echo $detail->taxMoney;?></td>
          </tr>
          <?php endforeach;?>
        </table>
      </div> 
    </div> 
    <?php endif;?>
    <?php echo $this->fetch('action', 'history', "objectType=invoice&objectID={$invoice->id}");?>
    <div class='main-actions'>
      <div class='btn-toolbar'>
        <?php 
        commonModel::printBack($browseLink);

        if($invoice->status == 'wait')
        {
            commonModel::printLink('invoice', 'drawn', "invoiceID=$invoice->id", $lang->invoice->drawn, "class='btn' data-toggle='modal'");
        }
        else
        {
            echo html::a('javascript:;', $lang->invoice->drawn, "class='btn disabled'");
        }
        $expressLabel = $invoice->type != 'companyDigitalOrdinary' ? $lang->invoice->express : $lang->invoice->send;
        if($invoice->status == 'normal')
        {
            if($invoice->expressedBy)
            {
                echo html::a('javascript:;', $expressLabel, "class='btn disabled'");
            }
            else
            {
                commonModel::printLink('invoice', 'express', "invoiceID=$invoice->id", $expressLabel, "class='btn' data-toggle='modal'");
            }
            commonModel::printLink('invoice', 'taxRefund', "invoiceID=$invoice->id&status=canceled", $lang->invoice->cancel, "class='btn' data-toggle='modal'");
            commonModel::printLink('invoice', 'taxRefund', "invoiceID=$invoice->id&status=red", $lang->invoice->red, "class='btn' data-toggle='modal'");
            echo "<div class='divider'></div>";
        }
        else
        {
            echo html::a('javascript:;', $expressLabel, "class='btn disabled'");
            echo html::a('javascript:;', $lang->invoice->cancel, "class='btn disabled'");
            echo html::a('javascript:;', $lang->invoice->red, "class='btn disabled'");
            echo "<div class='divider'></div>";
        }
        ?>
        <?php
        commonModel::printLink('invoice', 'edit', "invoiceID=$invoice->id", $lang->edit, "class='btn btn-default'");
        commonModel::printLink('invoice', 'delete', "invoiceID=$invoice->id", $lang->delete, "class='btn btn-default deleter'");
        echo "<div class='divider'></div>";

        commonModel::printRPN($preAndNext);
        ?>
      </div>
    </div>
  </div>
  <div class='side-col col-4'>
    <div class='panel panel-block'>
      <div class='panel-heading'><strong><?php echo $lang->invoice->baseInfo;?></strong></div>
      <div class='panel-body'>
        <table class='table table-data'>
          <tr>
            <th class='w-70px'><?php echo $lang->invoice->company;?></th>
            <td><?php echo zget($companies, $invoice->company, '');?></td>
          </tr>
          <tr>
            <?php $customer = isset($customer->name) ? $customer->name : $invoice->customer;?>
            <th class='w-70px'><?php echo $lang->invoice->customer;?></th>
            <td>
              <?php if($invoice->customer):?>
              <?php if(!commonModel::printLink('crm.customer', 'view', "customerID=$invoice->customer", $customer)) echo $customer;?>
              <?php endif;?>
            </td>
          </tr>
          <tr>
            <?php $contract = isset($contract->name) ? $contract->name : $invoice->contract;?>
            <th><?php echo $lang->invoice->contract;?></th>
            <td>
              <?php if($invoice->contract):?>
              <?php if(!commonModel::printLink('crm.contract', 'view', "contractID=$invoice->contract", $contract)) echo $contract;?>
              <?php endif;?>
            </td>
          </tr>
          <tr>
            <?php $contact = isset($contact->realname) ? $contact->realname : $invoice->contact;?>
            <th><?php echo $lang->invoice->contact;?></th>
            <td>
              <?php if($invoice->contact):?>
              <?php if(!commonModel::printLink('crm.contact', 'view', "contactID=$invoice->contact", $contact)) echo $contact;?>
              <?php endif;?>
            </td>
          </tr>
          <?php if($invoice->type != 'companyDigitalOrdinary'):?>
          <tr>
            <th><?php echo $lang->invoice->express;?></th>
            <td><?php echo $invoice->express;?></td>
          </tr>
          <tr>
            <th><?php echo $lang->invoice->waybill;?></th>
            <td><?php echo $invoice->waybill;?></td>
          </tr>
          <tr>
            <th><?php echo $lang->invoice->address;?></th>
            <td><?php echo isset($address->location) ? $address->location : '';?></td>
          </tr>
          <?php elseif($invoice->type == 'companyDigitalOrdinary'):?>
          <tr>
            <th><?php echo $lang->invoice->sendway;?></th>
            <td><?php echo zget($lang->invoice->sendwayList, $invoice->sendway);?></td>
          </tr>
          <tr>
            <th><?php echo $lang->invoice->sendAccount;?></th>
            <td><?php echo $invoice->sendAccount;?></td>
          </tr>
          <?php endif;?>
        </table>
      </div>
    </div>
    <div class='panel panel-block'>
      <div class='panel-heading'><strong><?php echo $lang->invoice->lifetime;?></strong></div>
      <div class='panel-body'>
        <table class='table table-data'>
          <tr>
            <th class='w-70px'><?php echo $lang->invoice->createdBy;?></th>
            <td><?php echo zget($users, $invoice->createdBy) . $lang->at . $invoice->createdDate;?></td>
          </tr>
          <?php if($invoice->editedBy):?>
          <tr>
            <th><?php echo $lang->invoice->editedBy;?></th>
            <td><?php echo zget($users, $invoice->editedBy) . $lang->at . $invoice->editedDate;?></td>
          </tr>
          <?php endif;?>
          <?php if($invoice->receivedBy):?>
          <tr>
            <th><?php echo $lang->invoice->receivedBy;?></th>
            <td><?php echo zget($users, $invoice->receivedBy) . $lang->at . $invoice->receivedDate;?></td>
          </tr>
          <?php endif;?>
          <?php if($invoice->checkedBy):?>
          <tr>
            <th><?php echo $lang->invoice->checkedBy;?></th>
            <td><?php echo zget($users, $invoice->checkedBy) . $lang->at . $invoice->checkedDate;?></td>
          </tr>
          <?php endif;?>
          <?php if($invoice->drawnBy):?>
          <tr>
            <th><?php echo $lang->invoice->drawnBy;?></th>
            <td><?php echo zget($users, $invoice->drawnBy) . $lang->at . $invoice->drawnDate;?></td>
          </tr>
          <?php endif;?>
          <?php if($invoice->expressedBy):?>
          <tr>
            <th><?php echo $lang->invoice->expressedBy;?></th>
            <td><?php echo zget($users, $invoice->expressedBy) . $lang->at . $invoice->expressedDate;?></td>
          </tr>
          <?php endif;?>
          <?php if($invoice->taxRefundedBy):?>
          <tr>
            <th>
              <?php if($invoice->status == 'canceled') echo $lang->invoice->canceledBy;?>
              <?php if($invoice->status == 'red') echo $lang->invoice->redBy;?>
              <?php if($invoice->status != 'canceled' && $invoice->status != 'red') echo $lang->invoice->taxRefundedBy;?>
            </th>
            <td><?php echo zget($users, $invoice->taxRefundedBy) . $lang->at . $invoice->taxRefundedDate;?></td>
          </tr>
          <?php endif;?>
        </table>
      </div>
    </div>
  </div>
</div>
<?php include $app->getAppRoot() . 'common/view/footer.html.php';?>
