<div class="content-wrapper">

    <section class="content-header">
        <?=$this->partial('layout/breadcrumb')?>

        <h1 class="pull-right">
            <a href="<?=$this->url('p-order', ['action'=> 'add']);?>" class="btn btn-primary btn-sm"><i class="fa fa-plus"></i> <?=$this->translate('添加采购订单')?></a>
            <?=$this->HelpUrl('pOrderList')?>
        </h1>

    </section>

    <section class="content">
        <?=$this->partial('layout/messages'); ?>

        <div class="row">
            <div class="col-xs-12">
                <div class="box erp-box">

                    <div class="box-body table-responsive no-padding">
                            <table class="table table-hover">
                                <thead>
                                <tr class="erp-bg-thead">
                                    <th width="10%"><?=$this->translate('采购单号')?>-<?=$this->translate('订单数：').$this->orderList->getTotalItemCount()?></th>
                                    <th width="12%"><?=$this->translate('供应商')?></th>
                                    <th width="10%"><?=$this->translate('联系人')?></th>
                                    <th width="10%"><?=$this->translate('联系电话')?></th>
                                    <th width="10%"><?=$this->translate('付款方式')?></th>
                                    <th width="10%"><?=$this->translate('采购金额')?></th>
                                    <th width="6%"><?=$this->translate('状态')?></th>
                                    <th width="6%"><?=$this->translate('退货')?></th>
                                    <th width="15%"><?=$this->translate('操作')?></th>
                                </tr>
                                <?php
                                $sForm = $this->searchForm;
                                $sForm->prepare();
                                $sForm->get('p_order_state')->setEmptyOption('选择');
                                $sForm->get('return_state')->setEmptyOption('选择');
                                ?>
                                <?= $this->form()->openTag($sForm); ?>
                                <tr>
                                    <td>
                                        <?= $this->formElement($sForm->get('p_order_sn')); ?>
                                        <?=$this->formElementErrors($sForm->get('p_order_sn'), ['class'=>'error-message']);?>
                                    </td>
                                    <td>
                                        <?= $this->formElement($sForm->get('supplier_id')); ?>
                                        <?=$this->formElementErrors($sForm->get('supplier_id'), ['class'=>'error-message']);?>
                                    </td>
                                    <td>
                                        <?= $this->formElement($sForm->get('supplier_contacts')); ?>
                                        <?=$this->formElementErrors($sForm->get('supplier_contacts'), ['class'=>'error-message']);?>
                                    </td>
                                    <td>
                                        <?= $this->formElement($sForm->get('supplier_phone')); ?>
                                        <?=$this->formElementErrors($sForm->get('supplier_phone'), ['class'=>'error-message']);?>
                                    </td>
                                    <td>
                                        <?= $this->formElement($sForm->get('payment_code')); ?>
                                        <?=$this->formElementErrors($sForm->get('payment_code'), ['class'=>'error-message']);?>
                                    </td>
                                    <td>
                                        <p>
                                            <?= $this->formElement($sForm->get('start_amount')); ?>
                                        </p>
                                        <div>
                                            <?= $this->formElement($sForm->get('end_amount')); ?>
                                        </div>
                                        <?=$this->formElementErrors($sForm->get('start_amount'), ['class'=>'error-message']);?>
                                        <?=$this->formElementErrors($sForm->get('end_amount'), ['class'=>'error-message']);?>
                                    </td>
                                    <td>
                                        <?= $this->formElement($sForm->get('p_order_state')); ?>
                                        <?=$this->formElementErrors($sForm->get('p_order_state'), ['class'=>'error-message']);?>
                                    </td>
                                    <td>
                                        <?= $this->formElement($sForm->get('return_state')); ?>
                                        <?=$this->formElementErrors($sForm->get('return_state'), ['class'=>'error-message']);?>
                                    </td>
                                    <td>
                                        <button type="submit" class="btn btn-info btn-sm"><i class="fa fa-search"></i></button>
                                        <?php
                                        $formData = $sForm->getData();
                                        if(!empty(array_filter($formData))
                                            || $formData['p_order_state'] != ''
                                            || $formData['return_state'] != '' ) { ?>
                                            <a href="<?=$this->url('p-order');?>" class="btn btn-default btn-sm"><i class="fa fa-reply"></i></a>
                                        <?php } ?>
                                    </td>
                                </tr>
                                <?= $this->form()->closeTag(); ?>
                                </thead>

                                <?php if($this->orderList) foreach ($this->orderList as $order) { ?>
                                    <tr>
                                        <td><?=$this->escapeHtml($order->getPorderSn())?></td>
                                        <td><?=$this->escapeHtml($order->getOneSupplier()->getSupplierName())?></td>
                                        <td><?=$this->escapeHtml($order->getSupplierContacts())?></td>
                                        <td><?=$this->escapeHtml($order->getSupplierPhone())?></td>
                                        <td><?=$this->PurchaseHelper()->orderPayment($order->getPaymentCode())?></td>
                                        <td><?=$this->erpCurrencyFormat($order->getPOrderAmount());?></td>
                                        <td><?=$this->PurchaseHelper()->orderState($order->getPOrderState(), 2)?></td>
                                        <td><?=($order->getReturnState() == 1 ? '<b class="text-danger">'.$this->translate('有').'</b>' : $this->translate('无'))?></td>
                                        <td>
                                            <?php if($order->getPOrderState() == 0) { ?>
                                                <a href="<?= $this->url('p-order',
                                                    ['action'=>'edit', 'id'=>$order->getPOrderId()]); ?>"
                                                   class="btn btn-xs btn-success"><i class="fa fa-pencil"></i> <?=$this->translate('编辑')?>
                                                </a>
                                                <a href="<?= $this->url('p-order', ['action'=>'authPassOrder', 'id'=>$order->getPOrderId()], ['query' => ['qToken' => $this->common()->getCsrfValue()]]); ?>" class="btn btn-xs btn-success"><i class="fa fa-check"></i> <?=$this->translate('审核')?></a>
                                                <a href="javascript:;" onclick="deleteConfirm('<?=$this->translate('您确实要删除该采购单吗？')?>', '<?= $this->url('p-order', ['action'=>'delete', 'id'=>$order->getPOrderId()], ['query' => ['qToken' => $this->common()->getCsrfValue()]]); ?>');" class="btn btn-xs btn-danger">
                                                    <i class="fa fa-trash"></i> <?=$this->translate('删除')?>
                                                </a>
                                            <?php } ?>

                                                <a href="<?= $this->url('p-order',
                                                    ['action'=>'view', 'id'=>$order->getPOrderId()]); ?>"
                                                   class="btn btn-xs btn-info"><i class="fa fa-info-circle"></i> <?=$this->translate('查看')?>
                                                </a>

                                            <?php if($order->getPOrderState() == 1) { ?>
                                                <a href="<?= $this->url('order-return',
                                                    ['action'=>'returnOrder', 'id'=>$order->getPOrderId()]); ?>" class="btn btn-xs btn-primary"><i class="fa fa-share"></i> <?=$this->translate('采购退货')?></a>
                                                <div style="margin-top: 6px;">
                                                <a href="<?= $this->url('warehouse-order', ['action'=>'add', 'id'=>$order->getPOrderId()]); ?>" class="btn btn-xs btn-primary"><i class="fa fa-plus"></i> <?=$this->translate('验货入库')?></a>
                                                <a href="<?= $this->url('p-order', ['action'=>'cancelOrder', 'id'=>$order->getPOrderId()], ['query' => ['qToken' => $this->common()->getCsrfValue()]]); ?>" class="btn btn-xs btn-warning"><i class="fa fa-remove"></i> <?=$this->translate('取消审核')?></a>
                                                </div>
                                            <?php } ?>
                                        </td>
                                    </tr>
                                <?php } ?>
                            </table>
                    </div>
                    <div class="box-footer clearfix">
                        <?=$this->paginationControl($this->orderList, 'Sliding', 'layout/page', ['route' => 'p-order']); ?>
                    </div>
                </div>

            </div>
        </div>

    </section>
</div>