<div class="content-wrapper">
    <?php
    $form = $this->form;
    $form->prepare();
    ?>
    <?= $this->form()->openTag($form); ?>
    <section class="content-header">
        <?=$this->partial('layout/breadcrumb')?>

        <h1 class="pull-right">
            <a href="<?=$this->url('sales-order');?>" class="btn btn-default btn-sm"><i class="fa fa-arrow-left"></i> <?=$this->translate('返回销售订单列表')?></a>
            <button type="submit" class="btn btn-primary btn-sm"><i class="fa fa-check"></i> <?=$this->translate('点击发货出库')?></button>
            <?=$this->HelpUrl('salesSendOrder')?>
        </h1>
    </section>

    <section class="content">

        <div class="row">
            <div class="col-md-12">
                <div class="box box-primary">
                    <div class="box-header with-border">
                        <h3 class="box-title"><?=$this->translate('订单发货出库');?></h3>
                    </div>

                    <div class="box-body">
                        <?=$this->formElementErrors($form->get('dberp_csrf'), ['class'=>'error-message']); ?>
                        <div class="row">
                            <div class="col-xs-4 form-group">
                                <div class="col-sm-12">
                                    <b><?=$this->translate('销售单号')?>：</b><?=$this->escapeHtml($this->orderInfo->getSalesOrderSn());?>
                                </div>
                            </div>

                            <div class="col-xs-4 form-group">
                                <div class="col-sm-12">
                                    <b><?=$this->translate('订单状态')?>：</b><?=$this->salesHelper()->salesOrderState($this->orderInfo->getSalesOrderState(), 2);?>
                                </div>
                            </div>

                            <div class="col-xs-4 form-group">
                                <div class="col-sm-12">
                                    <b><?=$this->translate('付款方式')?>：</b><?=$this->salesHelper()->orderReceivables($this->orderInfo->getReceivablesCode());?>
                                </div>
                            </div>

                        </div>

                        <div class="row">
                            <div class="col-xs-4 form-group">
                                <div class="col-sm-12">
                                    <b><?=$this->translate('客户')?>：</b><?=$this->escapeHtml($this->orderInfo->getOneCustomer()->getCustomerName());?>
                                </div>
                            </div>
                            <div class="col-xs-4 form-group">
                                <div class="col-sm-12">
                                    <b><?=$this->translate('客户联系人')?>：</b><?=$this->escapeHtml($this->orderInfo->getCustomerContacts());?>
                                </div>
                            </div>

                            <div class="col-xs-4 form-group">
                                <div class="col-sm-12">
                                    <b><?=$this->translate('客户手机')?>：</b><?=$this->escapeHtml($this->orderInfo->getCustomerPhone());?>
                                </div>
                            </div>

                        </div>

                        <div class="row">
                            <div class="col-xs-4 form-group">
                                <div class="col-sm-12">
                                    <b><?=$this->translate('客户座机')?>：</b><?=$this->escapeHtml($this->orderInfo->getCustomerTelephone());?>
                                </div>
                            </div>
                            <div class="col-xs-4 form-group">
                                <div class="col-sm-12">
                                    <b><?=$this->translate('收货地址')?>：</b><?=$this->escapeHtml($this->orderInfo->getCustomerAddress());?>
                                </div>
                            </div>
                            <div class="col-xs-4 form-group">
                                <div class="col-sm-12">
                                    <b><?=$this->translate('备注')?>：</b><?=$this->escapeHtml($this->orderInfo->getSalesOrderInfo());?>
                                </div>
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-xs-4 form-group">
                                <div class="col-sm-12">
                                    <?=$this->translate('发货单号')?><span class="must_add_value">*</span>
                                    <?= $this->formElement($form->get('sendOrderSn')); ?>
                                    <?= $this->formElementErrors($form->get('sendOrderSn'), ['class'=>'error-message']); ?>
                                </div>
                            </div>
                        </div>
                        <div class="box-header">
                            <h4 class="box-title"><?=$this->translate('发货商品')?></h4>
                            <?= $this->formElementErrors($form->get('sendWarehouse'), ['class'=>'error-message']); ?>
                        </div>
                        <div class="box-body table-responsive no-padding">
                            <table class="table">
                                <tr>
                                    <th width="15%"><?=$this->translate('商品编号')?></th>
                                    <th width="20%"><?=$this->translate('商品名称')?></th>
                                    <th><?=$this->translate('商品规格')?></th>
                                    <th><?=$this->translate('单位')?></th>
                                    <th><?=$this->translate('销售单价')?></th>
                                    <th><?=$this->translate('销售数量')?></th>
                                    <th><?=$this->translate('税金')?></th>
                                    <th width="10%"><?=$this->translate('销售总价')?></th>
                                </tr>

                                <?php
                                foreach ($this->orderGoods as $goodsValue) {
                                    ?>
                                    <tr>
                                        <td><?=$this->escapeHtml($goodsValue->getGoodsNumber());?></td>
                                        <td><?=$this->escapeHtml($goodsValue->getGoodsName());?></td>
                                        <td><?=$this->escapeHtml($goodsValue->getGoodsSpec());?></td>
                                        <td><?=$this->escapeHtml($goodsValue->getGoodsUnit());?></td>
                                        <td><?=$this->erpCurrencyFormat($goodsValue->getSalesGoodsPrice());?></td>
                                        <td><?=$this->escapeHtml($goodsValue->getSalesGoodsSellNum());?></td>
                                        <td><?=$this->erpCurrencyFormat($goodsValue->getSalesGoodsTax());?></td>
                                        <td><?=$this->erpCurrencyFormat($goodsValue->getSalesGoodsAmount());?></td>
                                    </tr>
                                    <?php if($this->warehouse[$goodsValue->getGoodsId()]) { ?>
                                    <tr>
                                        <td colspan="8">
                                            <label><?=$this->translate('选择发货仓库')?>：</label>
                                            <?php foreach ($this->warehouse[$goodsValue->getGoodsId()] as $warehouseValue) { if($warehouseValue->getWarehouseGoodsStock() > 0) { ?>
                                                <input type="checkbox" title="<?=$this->translate('请选择仓库')?>" required minlength="1" name="sendWarehouse[<?=$goodsValue->getGoodsId();?>][]" value="<?=$warehouseValue->getWarehouseId();?>"> <?=$warehouseValue->getOneWarehouse()->getWarehouseName()?>(<strong><?=$this->translate('库存：').$warehouseValue->getWarehouseGoodsStock()?></strong>)
                                            <?php } } ?>
                                        </td>
                                    </tr>
                                    <?php } else { ?>
                                    <tr>
                                        <td colspan="8">
                                            <label><?=$this->translate('选择发货仓库')?>：</label>
                                            <label class="text-danger"><?=$this->translate('仓库无库存')?></label>
                                        </td>
                                    </tr>
                                    <?php } ?>
                                <?php } ?>

                                <tr id="tr-end">
                                    <td colspan="6"></td>
                                    <td colspan="2" class="text-right"><b><?=$this->translate('销售金额合计')?>：</b><span id="order-amount"><?=(isset($orderInfo) ? $this->erpCurrencyFormat($orderInfo->getSalesOrderAmount()) : 0)?></span></td>
                                </tr>
                            </table>
                        </div>

                    </div>
                    <div class="box-footer">
                        <?=$this->formElement($form->get('dberp_csrf')); ?>
                        <button type="submit" class="btn btn-primary col-md-offset-5"><i class="fa fa-check"></i> <?=$this->translate('点击发货出库')?></button>
                    </div>
                </div>


            </div>
        </div>

    </section>
    <?= $this->form()->closeTag(); ?>
</div>
<script>
    $(document).ready(function() {
        $("#<?=$form->getName()?>").validate();
    });
</script>