<?php 
/**
 * The info file of customer 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     customer 
 * @version     $Id$
 * @link        http://www.zdoo.com
 */
?>
<?php include $app->getModuleRoot() . 'common/view/header.html.php';?>
<?php include '../../common/view/editor.html.php';?>
<?php js::set('stage', $customer->stage);?>
<?php js::set('customerID', $customer->id);?>
<?php js::set('copySuccess', $lang->customer->copySuccess);?>
<?php js::set('activeStage', $activeStage);?>
<?php $browseLink = $this->session->customerList ? $this->session->customerList : 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 $customer->id?></span>
      <span class="text" title='<?php echo $customer->name;?>'><?php echo $customer->name;?></span>
      <?php if($customer->deleted):?>
      <span class='label label-danger'><?php echo $lang->deleted;?></span>
      <?php endif;?>
    </div>
  </div>
</div>
<div class='main-row'>
  <div class='main-col col-8 main-left'>
    <div id='customerDesc' class='panel panel-block'>
      <div class='panel-heading'><strong><?php echo $lang->customer->desc;?></strong></div>
      <div class='panel-body'><?php echo $customer->desc;?></div>
    </div>
    <?php if($customer->intension):?>
    <div class='panel panel-block universal'>
      <div class='panel-heading'><strong><?php echo $lang->customer->intension;?></strong></div>
      <div class='panel-body'><?php echo $customer->intension;?></div>
    </div>
    <?php endif;?>
    <?php if($customer->depositor):?>
    <div class='panel panel-block'>
      <div class='panel-heading'><strong><?php echo $lang->customer->depositor;?></strong></div>
      <div class='panel-body'><?php echo $customer->depositor;?></div>
    </div>
    <?php endif;?>
    <?php if(!empty($returnList)):?>
    <div class='panel panel-block panel-sm table-row universal'>
      <div class='panel-heading'><strong><?php echo $lang->contract->returnRecords;?></strong></div>
      <div class='panel-body'>
        <table class='table table-bordered table-fixed'>
          <thead>
            <tr class='text-center'>
              <th><?php echo $lang->contract->common;?></th>
              <th class='w-100px'><?php echo $lang->contract->returnedDate;?></th>
              <th class='w-100px'><?php echo $lang->contract->returnedBy;?></th> 
              <th class='w-120px text-right'><?php echo $lang->contract->amount;?></th> 
              <th class='w-160px'><?php echo $lang->trade->depositor;?></th>
            </tr>
          </thead>
          <?php foreach($returnList as $return):?>
          <?php $contract = $contracts[$return->contract];?>
          <tr class='text-center'>
            <td class='c-name'><?php echo $contract->name;?></td>
            <td><?php echo formatTime($return->returnedDate, DT_DATE1);?></td>
            <td><?php echo zget($users, $return->returnedBy, $return->returnedBy);?></td>
            <td class='text-right'><?php echo zget($currencySign, $return->currency, '') . formatMoney($return->amount);?></td>
            <td><?php echo $return->depositor;?></td>
          </tr>
          <?php endforeach;?>
        </table>
      </div>
    </div>
    <?php endif;?>

    <div class='panel panel-block panel-sm universal'>
      <div class='panel-heading'><strong><?php echo $lang->file->common;?></strong></div>
      <div class='panel-body'>
        <?php echo $this->fetch('file', 'printFiles', array('files' => $files, 'fieldset' => 'false'))?>
      </div>
    </div>
    <?php echo $this->printExtendFields($customer, 'div', "position=left&inCell=1&inForm=0");?>
    <?php echo $this->fetch('action', 'history', "objectType=customer&objectID={$customer->id}")?>
    <div class='main-actions'>
      <div class='btn-toolbar'>
        <?php commonModel::printBack($browseLink);?>
        <div class='divider'></div>
        <?php echo $this->customer->buildOperateMenu($customer, 'view')?>
        <div class='divider'></div>
        <?php 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->customer->basicInfo;?></strong></div>
      <div class='panel-body'>
        <table class='table table-data'>
          <tr class='universal'>
            <th class='w-100px'><?php echo $lang->customer->public;?></th>
            <td><?php echo zget($lang->customer->publicList, $customer->public);?></td>
          </tr>
          <tr class='universal'>
            <th><?php echo $lang->customer->sourceType;?></th>
            <td><?php echo zget($lang->customer->sourceTypeList, $customer->sourceType);?></td>
          </tr>
          <tr class='universal'>
            <th class='w-100px'><?php echo $lang->customer->source;?></th>
            <td><?php echo zget($lang->customer->sourceList, $customer->source);?></td>
          </tr>
          <tr class='universal'>
            <th><?php echo $lang->customer->sourceNote;?></th>
            <td><?php echo $customer->sourceNote;?></td>
          </tr>
          <tr class='universal'>
            <th><?php echo $lang->customer->level;?></th>
            <td><?php if($customer->level) echo $lang->customer->levelNameList[$customer->level];?></td>
          </tr>
          <tr class='universal'>
            <th><?php echo $lang->customer->status;?></th>
            <td><?php if($customer->status) echo $lang->customer->statusList[$customer->status];?></td>
          </tr>
          <tr class='universal'>
            <th><?php echo $lang->customer->recommendationRate;?></th>
            <td><?php echo $customer->recommendationRate;?></td>
          </tr>
          <tr class='universal'>
            <th><?php echo $lang->customer->assignedTo;?></th>
            <td><?php echo zget($users, $customer->assignedTo);?></td>
          </tr>
          <tr class='universal'>
            <th><?php echo $lang->customer->CSM;?></th>
            <td><?php echo zget($users, $customer->CSM);?></td>
          </tr>
          <tr class='w-100px'>
            <th><?php echo $lang->customer->size;?></th>
            <td><?php echo $lang->customer->sizeNameList[$customer->size];?></td>
          </tr>
          <tr>
            <th><?php echo $lang->customer->type;?></th>
            <td><?php echo $lang->customer->typeList[$customer->type];?></td>
          </tr>
          <tr>
            <th><?php echo $lang->customer->industry;?></th>
            <td><?php if($customer->industry) echo $industryList[$customer->industry];?></td>
          </tr>
          <tr>
            <th><?php echo $lang->customer->area;?></th>
            <td><?php if($customer->area) echo $areaList[$customer->area];?></td>
          </tr>
          <tr>
            <th><?php echo $lang->customer->weibo;?></th>
            <td><?php if(!empty($customer->weibo) && $customer->weibo != 'http://weibo.com/') echo html::a("$customer->weibo", $customer->weibo, "target='_blank'");?></td>
          </tr>
          <tr>
            <th><?php echo $lang->customer->weixin;?></th>
            <td><?php echo $customer->weixin;?></td>
          </tr>
          <tr>
            <th><?php echo $lang->customer->site;?></th>
            <td><?php if(!empty($customer->site) && $customer->site != 'http://') echo html::a("$customer->site", $customer->site, "target='_blank'");?></td>
          </tr>
          <tr class='universal'>
            <th><?php echo $lang->customer->nextDate;?></th>
            <td><?php echo formatTime($customer->nextDate, DT_DATE1);?></td>
          </tr>
        </table>
      </div>
    </div>
    <?php echo $this->fetch('contact', 'block', "customer={$customer->id}", 'crm')?>
    <?php if(!empty($contracts)):?>
    <div class='panel panel-block universal'>
      <div class='panel-body no-padding-top'>
        <table class='table table-data table-form table-fixed'>
          <thead>
            <tr class='text-center'>      
              <th class='text-left'><?php echo $lang->customer->contract;?></th>
              <th class='w-120px'><?php echo $lang->order->amount;?></th> 
              <th class='w-60px'><?php echo $lang->order->status;?></th> 
            </tr>
          </thead>
          <?php foreach($contracts as $contract):?>
          <tr data-url='<?php echo $this->createLink('crm.contract', 'view', "contractID=$contract->id"); ?>' class='text-center'>
            <td class='c-name'><?php echo $contract->name;?></td>
            <td><?php echo zget($currencySign, $contract->currency, '') . $contract->amount;?></td>
            <td class='<?php echo "contract-{$contract->status}";?>'><?php echo $lang->contract->statusList[$contract->status];?></td>
          </tr>
          <?php endforeach;?>
        </table>
      </div>
    </div>
    <?php endif;?>

    <?php if(!empty($orders)):?>
    <div class='panel panel-block universal'>
      <div class='panel-body no-padding-top'>
        <table class='table table-data table-form table-fixed'>
          <thead>
            <tr class='text-center'>      
              <th class='text-left'><?php echo $lang->customer->order;?></th>
              <th class='w-100px'><?php echo $lang->order->plan;?></th>
              <th class='w-100px'><?php echo $lang->order->real;?></th>
              <th class='w-60px'><?php echo $lang->order->status;?></th>
            </tr>
          </thead>
          <?php foreach($orders as $order):?>
          <tr data-url='<?php echo $this->createLink('crm.order', 'view', "orderID=$order->id"); ?>' class='text-center'>
            <td class='text-left'><?php foreach($order->products as $product) echo $product . ' ';?></td>
            <td><?php echo $order->plan;?></td>
            <td><?php echo zget($currencySign, $order->currency, '') . $order->real;?></td>
            <td class='<?php echo "order-{$order->status}";?>'><?php echo $lang->order->statusList[$order->status];?></td>
          </tr>
          <?php endforeach;?>
        </table>
      </div>
    </div>
    <?php endif;?>

    <?php if(!empty($productList)):?>
    <div class='panel panel-block'>
      <div class='panel-body no-padding-top'>
        <table class='table table-data table-form table-fixed'>
          <thead>
            <tr class='text-center'>      
              <th class='text-left'><?php echo $lang->customer->purchasedProducts;?></th>
              <th class='w-100px'><?php echo $lang->product->category;?></th>
              <th class='w-60px'><?php echo $lang->product->type;?></th>
              <th class='w-60px'><?php echo $lang->product->status;?></th>
            </tr>
          </thead>
          <?php foreach($productList as $product):?>
          <tr class='text-center' data-url='<?php echo $this->createLink('crm.product', 'view', "productID=$product->id"); ?>'>
            <td class='c-name'><?php echo $product->name;?></td>
            <td><?php echo zget($productCategories, $product->category, '');?></td>
            <td><?php echo zget($lang->product->typeList, $product->type);?></td>
            <td><?php echo zget($lang->product->statusList, $product->status);?></td>
          </tr>
          <?php endforeach;?>
        </table>
      </div>
    </div>
    <?php endif;?>

    <div class='panel panel-block universal'>
      <div class='panel-heading'><strong><?php echo $lang->customer->address;?></strong></div>
      <div class='panel-body'>
        <table class='table table-data'>
          <?php foreach($addresses as $address):?>
          <tr>
            <td><?php echo $address->title . $lang->colon . $address->fullLocation;?></td>
          </tr>
          <?php endforeach;?>
        </table>
      </div>
    </div>
    <?php echo $this->printExtendFields($customer, 'div', "position=right&inCell=1&inForm=0");?>
  </div>
</div>
<?php include $app->getAppRoot() . 'common/view/footer.html.php';?>
