<?php
        $product_id = Yii::app()->request->getParam('id');
        $modelStore = Store::model()->findByPK($product_id);
        $model_temp = ProductLocation::model()->find(array(
                        'select' => 'SUM(quantity) AS quantity' ,  'condition' => 'stock_id = '.$product_id
                    ));
        $indirect_model= new InventoryIndirectTransferItem();
        $available_qty= $indirect_model->with('parent','unitdetails')->find(array('select'=>'(SUM(transfer_qty-damaged_qty-transferred_qty)) * unitdetails.factor AS available_qty','condition'=>'parent.is_complete!="Y" AND t.item_id="'.$product_id.'"','group'=>'t.item_id'))->available_qty;
        $damaged_qty1= $indirect_model->with('parent','unitdetails')->find(array('select'=>'(SUM(t.damaged_qty)) * unitdetails.factor AS damaged_qty','condition'=>'t.item_id="'.$product_id.'" AND t.damaged_qty !="0"','group'=>'t.item_id'))->damaged_qty;
        $creditnote_model= new CreditnoteItem();
        $damaged_qty2= $creditnote_model->with('parent','orderunit')->find(array('select'=>'(SUM(t.returned_quantity)) * orderunit.factor AS returned_quantity','condition'=>'parent.sales_return="DA" AND t.product_id="'.$product_id.'" AND t.returned_quantity !="0"','group'=>'t.product_id'))->returned_quantity;
        $damaged_qty  = $damaged_qty1+$damaged_qty2;

        $quantity  =  number_format(($model_temp->quantity+$damaged_qty+$available_qty), 2); 
        $stockHelper = '<table class="table table-stripped table-bordered">';
        $stockHelper .= '<tr><th colspan="2">ITEM ' . ($modelStore->part_number) . '             <i title="click to close" class="icon-off"></i></th></tr>';
        $stockHelper .= '<tr><td class="cell-left" style="width:120px;">Current stock</td><td style="width:60px;">' . preg_replace('/\s\d+\.00/', '', floatval($quantity)) . '</td></tr>';
        $stockHelper .= '<tr><td class="cell-left">Cost rate  </td><td class="cell-right">' . Yii::app()->numberFormatter->formatCurrency($modelStore->rate, "") . '</td></tr>';
        $stockHelper .= '<tr><td class="cell-left">Stock Value  </td><td class="cell-right">' . Yii::app()->numberFormatter->formatCurrency($modelStore->rate * $quantity, "") . '</td></tr>';
        $model_location = ProductLocation::model()->findAll(array('condition'=>'stock_id="'.$product_id.'"'));
        $stockHelper .= '<tr><td class="cell-left" colpsan="2"><strong>Locations<strong></td></tr>';
        foreach ($model_location as $key => $value) {
            $stockHelper .= '<tr><td class="cell-left" colpsan="2">' .$value->warehouse->warehouse_name. '</td>';
            $stockHelper .= '<td class="cell-left" colpsan="2">'.$value->quantity.'</td></tr>';
        }
        $stockHelper .= '</table>';
        echo $stockHelper;
?>
<span class="sh-close" onclick="$('#stockhelper').hide();"><i class="fa fa-times"></i></span>