<div class="content-wrapper">

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

        <h1 class="pull-right">
            <a href="<?php echo $this->url('sales-order', ['action'=> 'add']);?>" class="btn btn-primary btn-sm"><i class="fa fa-plus"></i> <?php echo $this->translate('添加销售订单'); ?></a>
            <?php echo $this->HelpUrl('salesOrderList'); ?>
        </h1>

    </section>

    <section class="content">
        <?php echo $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%"><?php echo $this->translate('销售单号'); ?>-<?php echo $this->translate('订单数：').$this->orderList->getTotalItemCount(); ?></th>
                                <th width="12%"><?php echo $this->translate('客户'); ?></th>
                                <th width="10%"><?php echo $this->translate('联系人'); ?></th>
                                <th width="10%"><?php echo $this->translate('联系电话'); ?></th>
                                <th width="10%"><?php echo $this->translate('收款方式'); ?></th>
                                <th width="10%"><?php echo $this->translate('收款金额'); ?></th>
                                <th width="6%"><?php echo $this->translate('状态'); ?></th>
                                <th width="5%"><?php echo $this->translate('退货'); ?></th>
                                <th width="10%"><?php echo $this->translate('时间'); ?></th>
                                <th width="15%"><?php echo $this->translate('操作'); ?></th>
                            </tr>
                            <?php
                            $sForm = $this->searchForm;
                            $sForm->prepare();
                            $sForm->get('sales_order_state')->setEmptyOption('选择');
                            $sForm->get('return_state')->setEmptyOption('选择');
                            ?>
                            <?php echo $this->form()->openTag($sForm); ?>
                            <tr>
                                <td>
                                    <?php echo $this->formElement($sForm->get('sales_order_sn')); ?>
                                    <?php echo $this->formElementErrors($sForm->get('sales_order_sn'), ['class'=>'error-message']);?>
                                </td>
                                <td>
                                    <?php echo $this->formElement($sForm->get('customer_id')); ?>
                                    <?php echo $this->formElementErrors($sForm->get('customer_id'), ['class'=>'error-message']);?>
                                </td>
                                <td>
                                    <?php echo $this->formElement($sForm->get('customer_contacts')); ?>
                                    <?php echo $this->formElementErrors($sForm->get('customer_contacts'), ['class'=>'error-message']);?>
                                </td>
                                <td>
                                    <?php echo $this->formElement($sForm->get('customer_phone')); ?>
                                    <?php echo $this->formElementErrors($sForm->get('customer_phone'), ['class'=>'error-message']);?>
                                </td>
                                <td>
                                    <?php echo $this->formElement($sForm->get('receivables_code')); ?>
                                    <?php echo $this->formElementErrors($sForm->get('receivables_code'), ['class'=>'error-message']);?>
                                </td>
                                <td>
                                    <p>
                                        <?php echo $this->formElement($sForm->get('start_amount')); ?>
                                    </p>
                                    <div>
                                        <?php echo $this->formElement($sForm->get('end_amount')); ?>
                                    </div>
                                    <?php echo $this->formElementErrors($sForm->get('start_amount'), ['class'=>'error-message']);?>
                                    <?php echo $this->formElementErrors($sForm->get('end_amount'), ['class'=>'error-message']);?>
                                </td>
                                <td>
                                    <?php echo $this->formElement($sForm->get('sales_order_state')); ?>
                                    <?php echo $this->formElementErrors($sForm->get('sales_order_state'), ['class'=>'error-message']);?>
                                </td>
                                <td>
                                    <?php echo $this->formElement($sForm->get('return_state')); ?>
                                    <?php echo $this->formElementErrors($sForm->get('return_state'), ['class'=>'error-message']);?>
                                </td>
                                <td>
                                    <p>
                                        <?php echo  $this->formElement($sForm->get('start_time')); ?>
                                    </p>
                                    <div>
                                        <?php echo  $this->formElement($sForm->get('end_time')); ?>
                                    </div>
                                    <?php echo $this->formElementErrors($sForm->get('start_time'), ['class'=>'error-message']); ?>
                                    <?php echo $this->formElementErrors($sForm->get('end_time'), ['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['sales_order_state'] != ''
                                        || $formData['return_state'] != '') { ?>
                                        <a href="<?php echo $this->url('sales-order');?>" class="btn btn-default btn-sm"><i class="fa fa-reply"></i></a>
                                    <?php } ?>
                                </td>
                            </tr>
                            <?php echo $this->form()->closeTag(); ?>
                            </thead>

                            <?php if($this->orderList) foreach ($this->orderList as $order) { ?>
                                <tr>
                                    <td><?php echo $this->escapeHtml($order->getSalesOrderSn()); ?></td>
                                    <td><?php echo $this->escapeHtml($order->getOneCustomer()->getCustomerName()); ?></td>
                                    <td><?php echo $this->escapeHtml($order->getCustomerContacts()); ?></td>
                                    <td><?php echo $this->escapeHtml($order->getCustomerPhone()); ?></td>
                                    <td><?php echo $this->escapeHtml($order->getReceivablesCode()); ?>
                                        <?php /*echo $this->salesHelper()->orderReceivables($order->getReceivablesCode()); */?></td>
                                    <td><?php echo $this->erpCurrencyFormat($order->getSalesOrderAmount());?></td>
                                    <td><?php echo $this->salesHelper()->salesOrderState($order->getSalesOrderState(), 2); ?></td>
                                    <td><?php echo ($order->getReturnState() == 1 ? '<b class="text-danger">'.$this->translate('有').'</b>' : $this->translate('无')); ?></td>
                                    <td><?php echo date("Y-m-d H:i", $order->getCreateTime()); ?></td>
                                    <td>
                                        <?php if($order->getSalesOrderState() == 0) { ?>
                                            <a href="<?php echo $this->url('sales-order',
                                                ['action'=>'edit', 'id'=>$order->getSalesOrderId()]); ?>"
                                               class="btn btn-xs btn-success"><i class="fa fa-pencil"></i> <?php echo $this->translate('编辑'); ?>
                                            </a>
                                            <a href="<?php echo $this->url('sales-order', ['action'=>'confirmSalesOrder', 'id'=>$order->getSalesOrderId()], ['query' => ['qToken' => $this->common()->getCsrfValue()]]); ?>" class="btn btn-xs btn-success"><i class="fa fa-check"></i> <?php echo $this->translate('确认'); ?></a>
                                            <a href="javascript:;" onclick="deleteConfirm('<?php echo $this->translate('您确实要删除该销售单吗？'); ?>', '<?php echo $this->url('sales-order', ['action'=>'delete', 'id'=>$order->getSalesOrderId()], ['query' => ['qToken' => $this->common()->getCsrfValue()]]); ?>');" class="btn btn-xs btn-danger">
                                                <i class="fa fa-trash"></i> <?php echo $this->translate('删除'); ?>
                                            </a>
                                        <?php } ?>

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

                                        <?php if($order->getSalesOrderState() == 1) { ?>
                                            <a href="<?php echo $this->url('sales-order',
                                                ['action'=>'sendOrder', 'id'=>$order->getSalesOrderId()]); ?>" class="btn btn-xs btn-primary"><i class="fa fa-truck"></i> <?php echo $this->translate('发货出库'); ?></a>
                                                <a href="<?php echo $this->url('sales-order', ['action'=>'cancelSalesOrder', 'id'=>$order->getSalesOrderId()], ['query' => ['qToken' => $this->common()->getCsrfValue()]]); ?>" class="btn btn-xs btn-warning"><i class="fa fa-remove"></i> <?php echo $this->translate('取消确认'); ?></a>
                                        <?php } ?>
                                    </td>
                                </tr>
                            <?php } ?>
                        </table>
                    </div>
                    <div class="box-footer clearfix">
                        <?php echo $this->paginationControl($this->orderList, 'Sliding', 'layout/page', ['route' => 'sales-order']); ?>
                    </div>
                </div>

            </div>
        </div>

    </section>
</div>
<script type="text/javascript">
    laydate.render({elem: '#start_time'});
    laydate.render({elem: '#end_time'});
</script>