<div class="modal-header">
    <button type="button" class="close" ng-click="cancel()">&times;</button>
    <h3 class="modal-title">{[{ product.name}]} Previous Orders</h3>
</div>
<div class="modal-body" style="min-height: 300px;">

	<div ng-if=" ! fixedRelatedType">
		<div class="form-inline">
            <div class="form-group">
    	        <label class="control-label">Type:</label>
                <select name="supplier_id" class="form-control" ng-model="filters.transaction_type">
                	<option ng-selected=" ! filters.transaction_type" value="">All Types </option>
                	<option ng-repeat="type in transaction_types" value="{[{ type.value }]}">{[{type.name}]}</option>
                </select>
            </div>
        </div>
	</div>
	<br>
    <table class="table table-condensed table-striped">
        <thead>
            <th>Date</th>
            <th class="centered">For</th>
            <th ng-if=" ! fixedRelatedType" class="centered">Related To</th>
            <th class="centered">Quantity</th>
            <th>Reason</th>
            <th class="centered">User</th>
        </thead>
        <tbody>
        	<tr ng-if="previousOrders.length ==  0">
        		<td colspan="4">There is no transactions for this item.</td>
        	</tr>
            <tr ng-repeat="transaction in transactions">
                <td>
                    <span tooltip="{[{ ::transaction.created_at }]}">{[{ ::transaction.created_at | fromNow }]}</span>
                </td>
                <td class="centered">{[{ getTransactionType(transaction.related_type) }]}</td>
                <td class="centered" ng-show=" ! fixedRelatedType">
                    <a  ng-if="transaction.related_type == 'purchase_order'"
                        ng-href="#/stock/order-summary/{[{ transaction.related_id }]}">
                            {[{ transaction.related_id }]}
                    </a>
                    <span ng-if="transaction.related_id && transaction.related_type != 'purchase_order'">
                        {[{ transaction.related_type == 'user' ? getUserName(transaction.related_id) : transaction.related_id }]}
                    </span>
                </td>
                <td class="centered">
                    <span class="label" ng-class="{true:'label-success', false:'label-danger'}[transaction.quantity > 0 ]">{[{ transaction.quantity }]}</span>
                </td>
                <td>{[{ transaction.reason }]}</td>
                <td class="centered">{[{ getUserName(transaction.created_by) }]}</td>
            </tr>
        </tbody>
    </table>
    <br><br>
    <div paginator="paginator"></div>
</div>

