<section class="panel" style="background-color:#F6F3EE;">
    <header class="panel-heading clearfix panel-theame">
        <i class="fa fa-university"></i> Negative Stock
    </header>
    <div class="panel-body">
        <div class="custom-data-table">
            <table class="table table-hover table-bordered personal-task" id="tbl_inventory_details" style="font-size:13px;">
                <thead>
                    <tr>
                        <th>No</th>
                        <th>Id</th>
                        <th>Part No</th>
                        <th>Description</th>
                        <th>Warehouse</th>
                        <th>Quantity</th>
                    </tr>
                </thead>
                <?php
                $query = 'SELECT * FROM (SELECT product_id,part_number,description,SUM(quantity) AS quantity,isActive,inventory_item_type,warehouse_id 
            FROM view_warehousewise_stock 
            WHERE  inventory_item_type=1
            GROUP BY warehouse_id,product_id
            )A WHERE quantity <0';
            $model = Yii::app()->db->createCommand($query)->queryAll();
            foreach ($model as $i=>$row)
            {
                $MasInventoryWarehouse = MasInventoryWarehouse::model()->findBypK($row['warehouse_id']);
                $warehouse_name = $MasInventoryWarehouse->warehouse_name;
            ?>
            <tr>
                <td><?php echo $i+1;?></td>
                <td><?php echo $row['product_id'];?></td>
                <td><?php echo $row['part_number'];?></td>
                <td><?php echo $row['description'];?></td>
                <td><?php echo $warehouse_name;?></td>
                <td><?php echo $row['quantity'];?></td>
            </tr>
            <?php }    ?>
            </table>
        </div>
    </div>
</section>