<?php 
/**
 * The view file for the method of view of refund 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     refund 
 * @version     $Id$
 * @link        http://www.zdoo.com
 */
?>
<?php include '../../common/view/header.html.php'; ?>
<?php include '../../../sys/common/view/confirmer.html.php';?>
<?php js::set('mode', $mode == 'review' ? $status : $mode);?>
<?php js::set('status', $refund->status);?>
<?php js::set('createTradeTip', $lang->refund->createTradeTip);?>
<div id='mainTitle' class='clearfix'>
  <div class='btn-toolbar pull-left'>
    <?php if(!isonlybody()):?>
    <?php echo html::a('javascript:history.go(-1);', '<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 $refund->id?></span>
      <span class="text" title='<?php echo $refund->name; ?>'><?php echo $refund->name; ?></span>
    </div>
  </div>
</div>
<div class='main-row'>
  <div class='main-col col-8'>
    <div class='panel panel-block table-row'>
      <div class='panel-heading'><strong><?php echo $lang->refund->desc?></strong></div>
      <div class='panel-body'>
        <p><?php echo sprintf($lang->refund->descTip, zget($users, $refund->createdBy), zget($currencySign, $refund->currency) . $refund->money)?></p>
        <?php if(!empty($refund->reason)):?>
        <p><?php echo "{$lang->refund->statusList[$refund->status]}{$lang->refund->reason}:{$refund->reason}"?></p>
        <?php endif;?>
        <p><?php echo $refund->desc?></p>
      </div>
    </div> 
    <?php if(!empty($refund->files)):?>
    <div class='panel panel-block table-row'>
      <div class='panel-heading'><strong><?php echo $lang->refund->files?></strong></div>
      <div class='panel-body'>
        <div><?php echo $this->fetch('file', 'printFiles', array('files' => $refund->files, 'fieldset' => 'false'))?></div>
      </div>
    </div>
    <?php endif;?>
    <?php if(!empty($refund->detail)):?>
    <div class='panel panel-block main-table table-row'>
      <div class='panel-heading'><strong><?php echo $lang->refund->detail?></strong></div>
      <table class='table table-borderless'>
        <thead>
          <tr class="text-center">
            <th class='w-50px'><?php echo $lang->refund->id;?></th>
            <th class='w-90px'><?php echo $lang->refund->money;?></th>
            <th class='w-90px'><?php echo $lang->refund->invoice;?></th>
            <th class='w-90px'><?php echo $lang->refund->date;?></th>
            <th class='w-140px text-left'><?php echo $lang->refund->category;?></th>
            <th class='w-100px'><?php echo $lang->refund->related;?></th>
            <th class='w-80px'><?php echo $lang->refund->status;?></th>
            <th class='text-left'><?php echo $lang->refund->desc;?></th>
          </tr>
        </thead>
        <tbody>
          <?php foreach($refund->detail as $d):?>
          <tr class='text-center'>
            <td><?php echo $d->id;?></td>
            <td><?php echo zget($currencySign, $d->currency) . $d->money;?></td>
            <td><?php echo zget($currencySign, $d->currency) . $d->invoice;?></td>
            <td><?php echo formatTime($d->date, DT_DATE1);?></td>
            <td class='text-left' title='<?php echo zget($categories, $d->category, '');?>'><?php echo zget($categories, $d->category, '');?></td>
            <?php $related = ''; foreach(explode(',', trim($d->related, ',')) as $account) $related .= ' ' . zget($users, $account);?>
            <td title='<?php echo $related;?>'><?php echo $related;?></td>
            <td><span data-toggle='tooltip' data-original-title="<?php echo $d->reason;?>"><?php echo zget($lang->refund->statusList, $d->status);?></span></td>
            <td class='text-left c-name' title='<?php echo $d->desc;?>'><?php echo $d->desc;?></td>
          </tr>
          <?php endforeach;?>
        </tbody>
      </table>
    </div> 
    <?php endif;?>
    <?php echo $this->fetch('action', 'history', "objectType=refund&objectID={$refund->id}");?>
    <div class='main-actions'>
      <div class='btn-toolbar'>
        <?php
        $canEdit      = $this->refund->isClickable($refund, 'edit');
        $canDelete    = $this->refund->isClickable($refund, 'delete');
        $canSwitch    = $this->refund->isClickable($refund, 'switchStatus');
        $canReview    = $this->refund->isClickable($refund, 'review');
        $canReimburse = $this->refund->isClickable($refund, 'reimburse');

        $browseLink = $this->session->refundList ? $this->session->refundList : inlink('personal');
        commonModel::printBack($browseLink);

        if($canSwitch or $canEdit or $canDelete)
        {
            echo "<div class='divider'></div>";
            if($canSwitch)
            {
                $switchLabel = $refund->status == 'wait' ? $lang->refund->cancel : $lang->refund->submit;
                echo html::a(inlink('switchStatus', "id=$refund->id"), $switchLabel, "class='btn switchStatus'");
            }
            if($canEdit) echo html::a(inlink('edit', "refundID={$refund->id}"), $lang->edit, "class='btn btn-default'");
            if($canDelete) echo html::a(inlink('delete', "refundID={$refund->id}&referer={$referer}"), $lang->delete, "class='btn btn-default deleter'");
        }
        if($canReview or $canReimburse)
        {
            echo "<div class='divider'></div>";
            if($canReview) echo html::a(inlink('review', "refundID={$refund->id}"), $lang->refund->review, "class='btn btn-default' data-toggle='modal' data-width='800'");
            if($canReimburse && $refund->status == 'pass') echo html::a(inlink('reimburse', "type=single&refundID={$refund->id}"), $lang->refund->common, "class='btn btn-default' data-toggle='modal' data-width='540'");
            if($canReimburse && $refund->status == 'fail') echo html::a(inlink('reimburse', "type=single&refundID={$refund->id}&currency=&money=&status=fail"), $lang->refund->common, "class='btn btn-default confirmer' data-confirmTitle='{$lang->refund->reimburseConfirmTitle}' data-confirmDetail='{$lang->refund->reimburseConfirmDetail}' data-confirmButton='{$lang->confirm}' data-confirming='{$lang->loading}'");
        }

        commonModel::printRPN($preAndNext);
        ?>
      </div>
    </div>
  </div>
  <div class='side-col col-4'>
    <div class='panel panel-block'>
      <div class='panel-heading'><strong><i class='icon-file-text-alt'></i> <?php echo $lang->refund->baseInfo;?></strong></div>
      <div class='panel-body'>
        <table class='table table-data'>
          <tr>
            <th class='w-90px'><?php echo $lang->refund->dept;?></th>
            <td><?php echo zget($deptList, $refund->dept, '')?></td>
          </tr>
          <tr>
            <th><?php echo $lang->refund->category;?></th>
            <td><?php echo zget($categories, $refund->category, '')?></td>
          </tr>
          <?php if($customer):?>
          <tr>
            <th><?php echo $lang->refund->customer;?></th>
            <td><?php if(!commonModel::printLink('crm.customer', 'view', "customer=$refund->customer", $customer->name, "class='openEntry'")) echo $customer->name;?></td>
          </tr>
          <?php endif;?>
          <?php if($order):?>
          <tr>
            <th><?php echo $lang->refund->order;?></th>
            <td><?php if(!commonModel::printLink('crm.order', 'view', "order=$refund->order", $order->name, "class='openEntry'")) echo $order->title;?></td>
          </tr>
          <?php endif;?>
          <?php if($contract):?>
          <tr>
            <th><?php echo $lang->refund->contract;?></th>
            <td><?php if(!commonModel::printLink('crm.contract', 'view', "contract=$refund->contract", $contract->name, "class='openEntry'")) echo $contract->name;?></td>
          </tr>
          <?php endif;?>
          <?php if($project):?>
          <tr>
            <th><?php echo $lang->refund->project;?></th>
            <td><?php if(!commonModel::printLink('proj.project', 'view', "project=$refund->project", $project->name, "data-toggle='modal'")) echo $project->name;?></td>
          </tr>
          <?php endif;?>
          <?php if($trip):?>
          <tr>
            <th><?php echo $lang->refund->trip;?></th>
            <td><?php if(!commonModel::printLink('oa.trip', 'view', "tripID=$refund->trip", $trip->name, "data-toggle='modal'")) echo $tirp->name;?></td>
          </tr>
          <?php endif;?>
          <tr>
            <th><?php echo $lang->refund->money;?></th>
            <td><?php echo zget($currencySign, $refund->currency) . $refund->money?></td>
          </tr>
          <tr>
            <th><?php echo $lang->refund->invoice;?></th>
            <td><?php echo zget($currencySign, $refund->currency) . $refund->invoice?></td>
          </tr>
          <tr>
            <th><?php echo $lang->refund->status;?></th>
            <td><?php echo zget($lang->refund->statusList, $refund->status)?></td>
          </tr>
          <tr>
            <th><?php echo $lang->refund->date;?></th>
            <td><?php echo formatTime($refund->date, DT_DATE1);?></td>
          </tr>
          <tr>
            <th><?php echo $lang->refund->related;?></th>
            <?php
            $related = '';
            if(!empty($refund->detail))
            {
                $relatedList = array();
                foreach($refund->detail  as $detail)
                {
                    foreach(explode(',', trim($detail->related, ',')) as $account)
                    {
                        if(!$account) continue;
                        $relatedList[$account] = zget($users, $account);
                    }
                }
                $related = implode(' ', $relatedList);
            }
            else
            {
                foreach(explode(',', trim($refund->related, ',')) as $account)
                {
                    $related .= ' ' . zget($users, $account);
                }
            }
            ?>
            <td><?php echo $related;?></td>
          </tr>
          <tr>
            <th><?php echo $lang->refund->payee;?></th>
            <td><?php echo zget($users, $refund->payee);?></td>
          </tr>
          <tr>
            <th><?php echo $lang->refund->createdBy;?></th>
            <td><?php echo zget($users, $refund->createdBy) . $lang->at . formatTime($refund->createdDate, DT_DATETIME1);?></td>
          </tr>
          <tr>
            <th><?php echo $lang->refund->editedBy;?></th>
            <td><?php if($refund->editedBy) echo zget($users, $refund->editedBy) . $lang->at . formatTime($refund->editedDate, DT_DATETIME1);?></td>
          </tr>
          <tr id='firstReviewer'>
            <th><?php echo $lang->refund->firstReviewer;?></th>
            <td><?php echo $refund->firstReviewerLabel;?></td>
          </tr>
          <tr id='secondReviewer'>
            <th><?php echo $lang->refund->secondReviewer;?></th>
            <td><?php echo $refund->secondReviewerLabel;?></td>
          </tr>
          <tr>
            <th><?php echo $lang->refund->refundBy;?></th>
            <td><?php if($refund->refundBy) echo zget($users, $refund->refundBy) . $lang->at . formatTime($refund->refundDate, DT_DATETIME1);?></td>
          </tr>
        </table>
      </div>
    </div>
  </div>
</div>
<?php include '../../common/view/footer.html.php';?>
