<?php
$part_number="";
$purchase_helper = PurchasingOrderStockItem::model()->with('purchaseorder')->together()->findAll(
        array(
            'condition' => 't.stock_item_id=' . $id . ' AND purchaseorder.vendor_id <> ' . $company_id,
            'order' => 'purchaseorder.order_date DESC', 'limit' => 3
));
  if ($purchase_helper != null) {
    $table1 = "<table class='table table-stripped table-bordered'>
        <tr>
            <td>File No.</td>
            <td>Date</td>
            <td>Vendor</td>
            <td>Quantity</td>
            <td>Rate</td>
            <td>Status</td>
            </tr>";
    foreach ($purchase_helper as $eachItem) {
        $part_number=$eachItem->product->part_number;
        $table1.='<tr><td>' . $eachItem->purchaseorder->id . '</td>
            <td>' . date('Y-m-d', strtotime($eachItem->purchaseorder->order_date)) . '</td>
            <td class="cell-left">' . $eachItem->purchaseorder->vendor_details->vendor_name . '</td>
            <td class="cell-center">' . Yii::app()->numberFormatter->formatDecimal($eachItem->stock_item_quantity) . '</td>
            <td class="cell-right">' . Yii::app()->numberFormatter->formatCurrency($eachItem->stock_item_rate, "") . '</td>
            <td class="cell-center">' . $eachItem->purchaseorder->file->status . '</td>
                </tr>';
    }
        $table1 .= "</table>";
  }
/* quote helper related to same company */
    $purchase_helper_1 = PurchasingOrderStockItem::model()->with('purchaseorder')->together()->findAll(
            array(
                'condition' => 't.stock_item_id=' . $id . ' AND purchaseorder.vendor_id = ' . $company_id,
                'order' => 'purchaseorder.order_date DESC', 'limit' => 3
    ));

    if ($purchase_helper_1 != null) {
        $table2 = "<table class='table table-stripped table-bordered'>
            <tr>
                <td>File No.</td>
                <td>Date</td>
                <td>Vendor</td>
                <td>Quantity</td>
                <td>Rate</td>
                <td>Status</td>
                </tr>";
        foreach ($purchase_helper_1 as $eachItem) {
            $part_number=$eachItem->product->part_number;
            $table2.='<tr><td>' . $eachItem->purchaseorder->id . '</td>
                <td>' . date('Y-m-d', strtotime($eachItem->purchaseorder->order_date)) . '</td>
                <td class="cell-left">' . $eachItem->purchaseorder->vendor_details->vendor_name . '</td>
                <td class="cell-center">' . Yii::app()->numberFormatter->formatDecimal($eachItem->stock_item_quantity) . '</td>
                <td class="cell-right">' . Yii::app()->numberFormatter->formatCurrency($eachItem->stock_item_rate, "") . '</td>
                <td class="cell-center">' . $eachItem->purchaseorder->file->status . '</td>
                    </tr>';
        }
        $table2 .= "</table>";
    }
        if (empty($table1) && empty($table2))
            echo "No results found!";
        else {
            $out_put = '<table class="table table-stripped table-bordered "><tr><th colspan=2>ITEM : ' . $part_number . '             <i title="click to close" class="icon-off"></i></th></tr><tr>';
            $out_put.=!empty($table1) ? '<td class="text-center">FROM OTHER VENDORS ' . $table1 . '</td>' : '';
            echo '<br/>';
            $out_put.=!empty($table2) ? '<td class="text-center">FROM SAME VENDOR ' . $table2 . '</td>' : '';
            $out_put.='</tr></table>';
            echo $out_put;
        }
?>
<span class="sh-close" onclick="$('#stockhelper').hide();"><i class="fa fa-times"></i></span>
