<link href="/css/tabs.css" rel="stylesheet" type="text/css">
<script type="text/javascript" language="javascript" src="/js/jquery-1.8.3.js"></script>
<script type="text/javascript" language="javascript" src="/js/ajax.js"></script>
<script type="text/javascript" language="javascript" src="/js/func.js"></script>
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" class="table">
    <tr>
        <td height="22" class="td_bg">
            <TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
                <TBODY>
                <TR>
                    <TD height="30" align="center" class=tab-on id=navcell onclick=switchCell(1) name="navcell">出库列表
                    </TD>
                    <TD height="30" align="center" class=tab-off id=navcell onclick=switchCell(2) name="navcell">出库记录
                    </TD>
                    <TD height="30" class=tab-none>&nbsp;</TD>
                </TR>
                </TBODY>
            </TABLE>
        </td>
    </tr>
    <tr>
        <td height="22" colspan="2" class="td_bg">
            <table width="100%" align="center" height="120" border="0" cellpadding="0" cellspacing="0" id="mainTable">
                <tr>
                    <td height="120" valign="top" class="td_bg">
                        <TABLE id=tb cellSpacing=1 cellPadding=0 width="100%" border=0 name="tb">
                            <TR>
                                <TD valign="top">
                                    <table width="98%" border="0" align="center" cellpadding="3" cellspacing="1"
                                           class="table" style="table-layout: fixed;">
                                        <form id="searchForm">
                                            <tr>
                                                <td class="td_bg">
                                                    车牌号:<input name="car_no" type="text" value="">
                                                    <input type="button" class="act_btn" id="search-btn"
                                                           name="search-btn"
                                                           value="搜索">
                                                </td>
                                            </tr>
                                        </form>
                                    </table>
                                    <table width="98%" border="0" align="center" cellpadding="2" cellspacing="1"
                                           class="table" style="table-layout: fixed;">
                                        <tr>
                                            <td width="50" align="center" align="center" class="bg_tr" nowrap
                                                width="5%">排序
                                            </td>
                                            <td align="center" align="center" class="bg_tr" nowrap width="5%">车牌号</td>
                                            <td align="center" align="center" class="bg_tr" nowrap>品牌</td>
                                            <td align="center" align="center" class="bg_tr" nowrap width="10%">车型</td>
                                            <td align="center" align="center" class="bg_tr" nowrap>排量</td>
                                            <td align="center" align="center" class="bg_tr" nowrap>年款</td>
                                            <td align="center" align="center" class="bg_tr" nowrap>维修人</td>
                                            <td align="center" align="center" class="bg_tr" nowrap>配件名称</td>
                                            <td align="center" align="center" class="bg_tr" nowrap>库存</td>
                                            <td align="center" align="center" class="bg_tr" nowrap>数量</td>
                                            <td align="center" align="center" class="bg_tr" nowrap>单价</td>
                                            <td align="center" align="center" class="bg_tr" nowrap width="10%">下单时间</td>
                                            <td align="center" align="center" class="bg_tr" nowrap>状态</td>
                                            <td align="center" class="bg_tr" nowrap width="10%">操作</td>
                                        </tr>
                                        <?php if (isset($fix_items)): ?>
                                            <?php foreach ($fix_items as $key => $fix_item): ?>
                                                <tr class="item-tr">
                                                    <td align="center" class="td_bg" nowrap><?= $key + 1 ?></td>
                                                    <td align="center" class="td_bg" nowrap><?= $fix_item->fix->car_no ?></td>
                                                    <td align="left" class="td_bg" nowrap><?= $fix_item->brand->name ?></td>
                                                    <td align="left" class="td_bg" nowrap><?= $fix_item->series->name ?></td>
                                                    <td align="left" class="td_bg" nowrap><?= $fix_item->displacement->name ?></td>
                                                    <td align="left" class="td_bg" nowrap><?= $fix_item->car_year ?></td>
                                                    <td align="center" class="td_bg" nowrap><?= !is_null($fix_item->get_user) ? $fix_item->getUser->name: '暂无' ?></td>
                                                    <td align="left" class="td_bg" nowrap><?= $fix_item->name ?></td>
                                                    <td align="left" class="td_bg" nowrap>
                                                        <?php if(($num = \common\models\StoreRoom::findOne($fix_item->item->fk_id)->number) < 1): ?>
                                                            <span style="color: red">库存为0</span>
                                                        <?php else: ?>
                                                            <span style="color: green"><?= $num ?></span>
                                                        <?php endif; ?>
                                                    </td>
                                                    <td align="left" class="td_bg" nowrap><?= $fix_item->number ?></td>
                                                    <td align="left" class="td_bg" nowrap><?= $fix_item->price ?></td>
                                                    <td align="left" class="td_bg" nowrap><?= $fix_item->created_at ?></td>
                                                    <td align="center" class="td_bg item-status" nowrap>
                                                        <?php if(1 === $fix_item->status): ?>
                                                            <span style="color:red;">待领取</span>
                                                        <?php elseif(2 === $fix_item->status): ?>
                                                            <span style="color:green;">已出库</span>
                                                        <?php elseif(3 === $fix_item->status): ?>
                                                            <span style="color:red;">待采购</span>
                                                        <?php endif; ?>
                                                    </td>
                                                    <td align="center" class="td_bg" nowrap>
                                                        <?php if('0000-00-00 00:00:00' === $fix_item->get_at && $num >= 1): ?>
                                                            <a href="javascript:void(0);"
                                                                onclick="putOutStore(<?= $fix_item->item->fk_id ?>,<?= $fix_item->number ?>,<?= $fix_item->item_id ?>,$(this),<?= $fix_item->id ?>)">[出库并打印]</a>
                                                        <?php else: ?>
                                                            <a href="javascript:void(0);" style="color:grey;">[出库并打印]</a>
                                                        <?php endif; ?>
                                                        <?php if($num < 1): ?>
                                                        <a href="javascript:void(0);"
                                                            onclick="purchaseItem(<?= $fix_item->id ?>,$(this))">[缺货]</a>
                                                        <?php else: ?>
                                                            <a href="javascript:void(0);" style="color: grey">[缺货]</a>
                                                        <?php endif; ?>
                                                    </td>
                                                </tr>
                                            <?php endforeach; ?>
                                        <?php endif; ?>
                                        <!--    <tr>-->
                                        <!--        <td height="25" colspan="12" align="center" class="td_bg">分页位置</td>-->
                                        <!--    </tr>-->
                                    </table>
                                </TD>
                            </TR>
                        </TABLE>
                        <TABLE id=tb cellSpacing=1 cellPadding=0 width="100%" border=0 name="tb" class="hide-table">
                            <TR>
                                <TD>
                                    <table width="98%" border="0" align="center" cellpadding="2" cellspacing="1"
                                           class="table" style="table-layout: fixed;">
                                        <tr>
                                            <td align="center" class="bg_tr" nowrap width="5%">排序</td>
                                            <td align="center" align="center" class="bg_tr" nowrap>品牌</td>
                                            <td align="center" align="center" class="bg_tr" nowrap>车型</td>
                                            <td align="center" align="center" class="bg_tr" nowrap>排量</td>
                                            <td align="center" align="center" class="bg_tr" nowrap>年份</td>
                                            <td align="center" align="center" class="bg_tr" nowrap>配件名字</td>
                                            <td align="center" align="center" class="bg_tr" nowrap>领料人</td>
                                            <td align="center" align="center" class="bg_tr" nowrap>领取数量</td>
                                            <td align="center" align="center" class="bg_tr" nowrap>操作人</td>
                                            <td align="center" align="center" class="bg_tr" nowrap>操作时间</td>
                                        </tr>
                                        <?php if (isset($store_logs)): ?>
                                            <?php foreach ($store_logs as $key => $store_log): ?>
                                                <tr>
                                                    <td align="center" class="td_bg" nowrap><?= $key + 1 ?></td>
                                                    <td align="center" class="td_bg" nowrap><?= $store_log->brand->name ?></td>
                                                    <td align="center" class="td_bg" nowrap><?= $store_log->series->name ?></td>
                                                    <td align="center" class="td_bg" nowrap><?= $store_log->displacement->name ?></td>
                                                    <td align="center" class="td_bg" nowrap><?= $store_log->year->name ?></td>
                                                    <td align="center" class="td_bg" nowrap><?= $store_log->name ?></td>
                                                    <td align="center" class="td_bg" nowrap><?= $store_log->get_man ?></td>
                                                    <td align="center" class="td_bg" nowrap><?= $store_log->number ?></td>
                                                    <td align="center" class="td_bg" nowrap><?= $store_log->op_man ?></td>
                                                    <td align="center" class="td_bg" nowrap><?= $store_log->op_time ?></td>
                                                </tr>
                                            <?php endforeach; ?>
                                        <?php endif; ?>
                                        <!--    <tr>-->
                                        <!--        <td height="25" colspan="12" align="center" class="td_bg">分页位置</td>-->
                                        <!--    </tr>-->
                                    </table>
                                </TD>
                            </TR>
                        </TABLE>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>
<script type="text/javascript" language="javascript">
    function putOutStore(id,number,item_id,obj,record_id) {
        var getMan = prompt('请输入领料人?', '');
        if (!getMan) {
            alert('领料人不可为空!');
            return false;
        }

        if(number < 1 || id < 1 || item_id < 1){
            alert('出库失败!');
            return false;
        }
        $.post('/store-room/operation-out-store', {id: id,get_man:getMan,number:number,item_id:item_id,record_id:record_id}, function (msg) {
            alert(msg.msg);
            if(msg.success){
                obj.parents('.item-tr').remove();
//                location.href = '/print/op-send-print';
            }
        }, 'json');
    }
    //采购
    function purchaseItem(id,obj){
        if(id < 1) return false;
        $.post('/purchase/out-of-stock-list-create',{id:id},function(data){
            alert(data.msg);
            if(data.success){
                location.reload();
            }
        },'json');
    }
</script>