<div class="task-group-inner">
	<div class="clearfix">
        <div class="form-group">
            <label class="col-sm-4 control-label">Show discontinued stock: </label>
            <div class="col-sm-3">
                <label class="radio-inline">
                    <input type="checkbox" ng-true-value="1" ng-false-value="0" ng-model="disco">
                </label>
            </div>
        </div>
		<input class="form-control" discontinued="disco" type="text" placeholder="Search and add parts" ng-model="part_search" search-clear="true" search-callback="addPart(ev, data)" autocomplete="off" product-search>
	</div>
	<small ng-hide="parts.length > 0">No parts assigned.</small>
	<table class="table table-condensed" ng-show="parts.length > 0">
		<thead>
			<th></th>
			<th>Name</th>
			<th class="centered">Price</th>
			<th class="centered">Cost</th>
			<th class="centered">Quantity</th>
            <th class="centered">On Order</th>
			<th class="centered">VAT</th>
			<th class="centered">Total</th>
			<th></th>
		</thead>
		<tbody>
			<tr ng-repeat="part in parts">
                <td><span class="text-warning" ng-show="part.quantity_on_order > 0" tooltip="On order"><i class="fa fa-clock-o"></i></span></td>
				<td>{[{ part.stock ? part.stock.name : 'Loading...' }]}</td>
				<td class="centered"><span editable-text="part.price" e-class="input-tiny" onaftersave="updatePart(part)">{[{ part.price | currency:"£" }]}</span></td>
				<td class="centered">{[{ part.stock && part.stock.cost != 'NA' ? (part.stock.cost | currency:"£") : 'NA'}]}</td>
				<td class="centered"><span editable-number="part.quantity" onbeforesave="updatePartProperty(part, 'quantity', $data)">{[{ part.quantity }]}</span></td>
                <td class="centered"><span ng-class="{'label label-danger' : part.quantity_on_order > 0 && part.stock && part.stock.quantity >= part.quantity_on_order}" >{[{ part.quantity_on_order }]}</span></td>
				<td class="centered">{[{ part.price * part.vat * part.quantity / 100 | currency:"£" }]}</td>
				<td class="centered"><span editable-text="part.total_price" e-class="input-tiny" onaftersave="updateTotalPrice(part)">{[{ part.total_price | currency:"£" }]}</span></td>
				<td><span class="btn btn-mini" ng-if="part.stock && part.stock.composite == '1'" tooltip="Update items" ng-click="updateCompositeItems(part)"><i class="fa fa-cog"></i></span></td>
				<td><a href="#" ng-click="removePart(part)" data-eat-click><span class="text-danger">Remove</span></a></td>
			</tr>
		</tbody>
	</table>
	<div class="text-right parts-row" ng-show="parts.length > 0">
		<div>Subtotal: {[{ subtotal() | currency:"£" }]}</div>
		<div>Tax: {[{ tax() | currency:"£" }]}</div>
		<div>Cost: {[{ cost() ? (cost| currency:"£") : 'NA' }]}</div>
		<div><strong>Total Price: {[{ total() | currency:"£" }]}</strong></div>
	</div>
	<hr>
	<div class="row">
		<div class="col-sm-6">
			<div request-existing-part="parts" related="related" related-type="task"></div>
		</div>
		<div class="col-sm-6 text-right">
			<div request-non-existing-part="parts" related="related" related-type="task"></div>
		</div>
	</div>
</div>

<script type="text/ng-template" id="modals/request-existing-part.html">
	@include('bookings::templates.modals.request-existing-part')
</script>
<script type="text/ng-template" id="modals/request-non-existing-part.html">
	@include('bookings::templates.modals.request-non-existing-part')
</script>
<script type="text/ng-template" id="bookings/modals/part-composite-items.html">
	@include('bookings::templates.modals.part-composite-items')
</script>