<div class="task-group-inner">
	<span ng-init="vat = {!! Config::get('settings.vat') !!}">
	<div class="clearfix">
		<input class="form-control" type="text" placeholder="Search and add build" ng-model="build_search" search-clear="true" search-callback="addBuild(ev, data)" autocomplete="off" search-composite="true" product-search>
	</div>
	<small ng-hide="builds.length > 0">No build assigned.</small>
	<table class="table table-condensed" ng-show="builds.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">VAT</th>
			<th class="centered">Total</th>
			<th></th>
		</thead>
		<tbody>
			<tr ng-repeat="build in builds">
                <td><span class="text-warning" ng-show="build.ordered_components.length > 0" uib-tooltip="On order"><i class="fa fa-clock-o"></i></span></td>
				<td><span editable-text="build.name" onbeforesave="updateBuildProperty(build, 'name', $data)">{[{ build.name }]}</span></td>
				<td class="centered">
					<span ng-if="build.status == 'planning'" editable-text="build.price" e-class="input-tiny" onaftersave="updateBuildProperty(build, 'price', $data)">{[{ build.price | currency:"£" }]}</span>
					<span ng-if="build.status != 'planning'">{[{ build.stock.price_excluding_vat | currency:"£" }]}</span>
				</td>
				<td class="centered">{[{ build.cost != 'NA' ? ( build.cost | currency:"£") : build.cost }]}</td>
				<td class="centered"><span editable-number="build.quantity" onbeforesave="updateBuildProperty(build, 'quantity', $data)">{[{ build.quantity }]}</span></td>
				<td class="centered">
					{[{ (build.status == 'planning' ? build.price : build.stock.price_excluding_vat) * vat * build.quantity / 100 | currency:"£" }]}
				</td>
				<td class="centered">
					<span ng-if="build.status == 'planning'" editable-text="build.total_price" e-class="input-tiny" onaftersave="updateTotalPrice($data, build)">	{[{ build.total_price | currency:"£" }]}</span>
					<span ng-if="build.status != 'planning'">	{[{ build.stock.price_excluding_vat * build.quantity * ( 1 + vat/100) | currency:"£" }]}</span>
				</td>
				<td>
					<div class="pull-right">
						<span class="btn btn-mini" uib-tooltip="Update items" ng-click="showBuildComponents(build)"><i class="fa fa-cog"></i></span>
						<span class="btn btn-mini btn-success" ng-if="build.status == 'planning' " uib-tooltip="Confirm Plan" ng-click="updateBuildProperty(build, 'status', 'in_progress')"><i class="fa fa-thumbs-o-up"></i></span>
						<span class="btn btn-mini btn-success" ng-if="build.status == 'in_progress' " uib-tooltip="Mark as completed" ng-click="completeBuild(build)"><i class="fa fa-cube"></i></span>
						<span class="btn btn-mini btn-success" ng-if="build.status == 'in_progress' " uib-tooltip="Mark as completed and add as a part" ng-click="completeBuild(build, true)"><i class="fa fa-puzzle-piece"></i></span>
						<span ng-if="build.status != 'completed'" class="btn btn-mini btn-danger" uib-tooltip="Remove build" ng-click="removeBuild(build)"><i class="fa fa-trash"></i></span>
					</div>
				</td>
			</tr>
		</tbody>
	</table>
	<hr>
	<div class="text-right builds-row" ng-show="builds.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-12">
			<div class="pull-right" create-non-exiting-build builds="builds" related="related" related-type="task"></div>
		</div>
	</div>
</div>
<script type="text/ng-template" id="stock/stock-form.html">
	@include('stock::forms.stock')
</script>
<script type="text/ng-template" id="modals/create-non-existing-build.html">
 	@include('bookings::templates.modals.create-non-existing-build')
</script>
<script type="text/ng-template" id="bookings/modals/build-composite-items.html">
    @include('bookings::templates.modals.build-composite-items')
</script>

