<ol class="breadcrumb">
	<li><a href="#/">Dashboard</a></li>
	<li class="active">Invoices</li>
</ol>

<div class="container-fluid">
	<div class="row">
		<div class="col-md-12">
			<div class="panel panel-midnightblue">
				<div class="panel-heading">
					<h2>Invoices</h2>
					<div class="panel-ctrls">
						<a class="button-icon" ng-click="vm._downloadCSV()" title="Download CSV"><i class="ti ti-save"></i></a>
						<a class="button-icon" ng-click="vm._checkPaymentsFromQuickbooks()" title="Check Payments From Quickbooks"><i class="ti ti-check-box"></i></a>
						<a class="button-icon" ng-click="vm._reload()" title="Reload"><i class="ti ti-reload"></i></a>
						<a href="#/invoices/new" class="button-icon" title="New Invoice"><i class="ti ti-plus"></i></a>
					</div>
				</div>
				<div class="panel-body">
					<div class="row" style="margin-bottom: 15px;">
						<div class="col-sm-6">
							<div class="input-group">
								<span class="input-group-addon">
									<i class="ti ti-calendar"></i>
								</span>
								<input type="text" ng-focus="vm._openCalendar($event, 'date_from')" class="form-control datepicker" is-open="vm.calendar_opened['date_from']" datepicker-popup="MM/dd/yyyy" close-text="Close" name="date_from" id="date_from" ng-model="vm.date_from" placeholder="From">
								<span class="input-group-addon">
									<i class="ti ti-calendar"></i>
								</span>
								<input type="text" ng-focus="vm._openCalendar($event, 'date_to')" class="form-control datepicker" is-open="vm.calendar_opened['date_to']" datepicker-popup="MM/dd/yyyy" close-text="Close" name="date_to" id="date_to" ng-model="vm.date_to" placeholder="To">
								<span class="input-group-btn">
									<a ng-disabled="!vm.date_from && !vm.date_to" ng-click="vm._filterByDate()" class="btn btn-primary">Search</a>
								</span>
							</div>
						</div>
						<div class="col-sm-3">
							<select class="form-control" ng-model="vm.status_filter">
								<option value="">-- Status --</option>
								<option value="Billed">Billed</option>
								<option value="Canceled">Canceled</option>
								<option value="Paid">Paid</option>
								<option value="-1">All</option>
							</select>
						</div>
						<div class="col-md-3">
							<select class="form-control" ng-model="vm.quickbooks_filter">
								<option value="">-- Quickbooks --</option>
								<option value="Yes">Yes</option>
								<option value="No">No</option>
								<option value="-1">All</option>
							</select>
						</div>
					</div>
					<div class="row" style="margin-bottom: 15px;">
						<div class="col-sm-12">
							<input type="text" class="form-control" style="width: 100%;" ng-model="searchInput" placeholder="Search here...">
						</div>
					</div>
					<table class="table table-striped">
						<thead>
							<tr>
								<th>ID</th>
								<th>Date</th>
								<th class="hidden-xs">Due Date</th>
								<th class="hidden-xs">Customer</th>
								<th class="hidden-xs">Work Order</th>
								<th class="hidden-xs">Send By</th>
								<th>Amount</th>
								<th>Status</th>
								<th class="hidden-xs">Quickbooks</th>
								<th width="15%">Actions</th>
							</tr>
						</thead>
						<tbody>
							<tr dir-paginate="invoice in vm._filteredInvoices = (vm.invoices | filter: searchInput | filter: vm._filterByStatus | filter: vm._filterByQuickbooks) | itemsPerPage: 10">
								<td>
									<a href="#/invoices/{{invoice.id}}">
										{{invoice.number}}
									</a>
								</td>
								<td>{{invoice.date_formatted}}</td>
								<td class="hidden-xs">{{invoice.date_due_formatted}}</td>
								<td class="hidden-xs">
									<a href="#/customers/{{invoice.customer.id}}">
										{{invoice.customer.name}}
									</a>
								</td>
								<td class="hidden-xs">
									<a href="#/work-orders/{{invoice.work_order_id}}">
										{{invoice.work_order.number}}
									</a>
								</td>
								<td class="hidden-xs">
									<span class="label label-info" style="margin-right: 5px;" ng-repeat="option in invoice.send_by">
										{{option}}
									</span>
								</td>
								<td>{{invoice.amount | currency: "$"}}</td>
								<td>
									<span class="badge" ng-class="{'badge-danger': invoice.status_formatted == 'Billed', 'badge-info': invoice.status_formatted == 'Canceled', 'badge-success': invoice.status_formatted == 'Paid'}">{{invoice.status_formatted}}</span>
								</td>
								<td class="hidden-xs">
									<span ng-if="invoice.quickbooks_id">Yes</span>
									<span ng-if="!invoice.quickbooks_id">No</span>
								</td>
								<td>
									<div class="btn-group" ng-if="invoice.status_formatted != 'Paid' || vm._checkSendToQuickbooks(invoice)">
										<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
											<i class="ti ti-settings"></i>&nbsp;&nbsp;<span class="caret"></span>
										</button>
										<ul class="dropdown-menu" role="menu">
											<li ng-if="invoice.status_formatted == 'Canceled'"><a ng-click="vm._destroy(invoice.id)">Delete</a></li>
											<li class="divider"></li>
											<li><a ng-click="vm._resend(invoice.id)">ReSend</a></li>
											<li class="divider" ng-if="invoice.status_formatted == 'Billed'"></li>
											<li ng-if="invoice.status_formatted == 'Billed'"><a ng-click="vm._cancel(invoice.id)">Cancel Invoice</a></li>
											<li ng-if="invoice.status_formatted == 'Billed'"><a ng-click="vm._confirm(invoice.id)">Confirm Payment</a></li>
											<li class="divider" ng-if="vm._checkSendToQuickbooks(invoice)"></li>
											<li ng-if="vm._checkSendToQuickbooks(invoice)">
												<a ng-click="vm._sendToQuickbooks(invoice.id)">
													<span>Add To Quickbooks</span>
												</a>
											</li>
										</ul>
									</div>
								</td>
							</tr>
						</tbody>
					</table>
					<p class="text-center" ng-show="vm.invoices.length == 0">No records found</p>
					<div class="row">
						<div class="col-sm-12 text-center">
							<dir-pagination-controls></dir-pagination-controls>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
