<?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/kindeditor.html.php';?>
<?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'>
    <div 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'>
      <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'>
      <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, $contract->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'>
      <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->fetch('action', 'history', "objectType=customer&objectID={$customer->id}")?>
    <div class='main-actions'>
      <div class='btn-toolbar'>
        <?php
        commonModel::printBack($browseLink);
        echo "<div class='divider'></div>";

        commonModel::printLink('crm.order', 'create', "customer=$customer->id", $lang->order->common, "class='btn'");
        commonModel::printLink('crm.contract', 'create', "customer=$customer->id", $lang->contract->common, "class='btn'");
        echo "<div class='divider'></div>";
        commonModel::printLink('action', 'createRecord', "objectType=customer&objectID={$customer->id}&customer={$customer->id}&history=", $lang->customer->record, "class='btn' data-toggle='modal' data-width='800'");
        commonModel::printLink('customer', 'assign', "customerID=$customer->id", $lang->customer->assign, "class='btn' data-toggle='modal'");
        commonModel::printLink('customer', 'contact', "customerID=$customer->id", $lang->customer->contact,  "class='btn' data-toggle='modal' data-width='950'");
        commonModel::printLink('address',  'browse', "objectType=customer&objectID=$customer->id", $lang->customer->address, "class='btn' data-toggle='modal'");
        echo "<div class='divider'></div>";
        commonModel::printLink('customer', 'edit', "customerID=$customer->id", $lang->edit, "class='btn'");
        commonModel::printLink('customer', 'delete', "customerID=$customer->id", $lang->delete, "class='deleter btn'");
        echo html::a('#commentBox', $this->lang->comment, "class='btn btn-default' onclick=setComment()");
        echo "<div class='divider'></div>";

        commonModel::printRPN($preAndNext);
        ?>
      </div>
    </div>
    <div id='commentBox' class='hide panel panel-block'>
      <div class='panel-heading'><strong><?php echo $lang->comment;?></strong></div>
      <div class='panel-body'>
        <form id='ajaxForm' method='post' action='<?php echo inlink('edit', "customerID={$customer->id}&comment=true")?>'>
          <div class='form-group'><?php echo html::textarea('comment', '',"rows='5' class='w-p100'");?></div>
          <div class='form-actions'><?php echo html::submitButton() . html::commonButton($lang->cancel, 'btn btn-back', "onclick=setComment()");?></div>
        </form>
      </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>
            <th class='w-60px'><?php echo $lang->customer->source;?></th>
            <td><?php echo zget($lang->customer->sourceList, $customer->source);?></td>
          </tr>
          <tr>
            <th><?php echo $lang->customer->sourceNote;?></th>
            <td><?php echo $customer->sourceNote;?></td>
          </tr>
          <tr>
            <th><?php echo $lang->customer->level;?></th>
            <td><?php if($customer->level) echo $lang->customer->levelNameList[$customer->level];?></td>
          </tr>
          <tr>
            <th><?php echo $lang->customer->status;?></th>
            <td><?php if($customer->status) echo $lang->customer->statusList[$customer->status];?></td>
          </tr>
          <tr>
            <th><?php echo $lang->customer->assignedTo;?></th>
            <td><?php echo zget($users, $customer->assignedTo);?></td>
          </tr>
          <tr>
            <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 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 echo html::a("$customer->site", $customer->site, "target='_blank'");?></td>
          </tr>
          <tr>
            <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'>
      <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'>
      <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'>
      <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>
  </div>
</div>
<?php include $app->getAppRoot() . 'common/view/footer.html.php';?>
