<div class="top-pad"></div>

<div class="content-padding" ng-if="ready">

	<h1 class="title left"><i class="fa fa-bank"></i>
		<span ng-if="payment">Payment #{{result.id_payment}} - {{result.restaurant}}</span>
		<span ng-if="schedule">Payment Schedule #{{result.id_payment_schedule}} - {{result.restaurant}}</span>
	</h1>

	<div class="divider"></div>

	<h2 class="title">#{{result.id_restaurant}} - {{result.restaurant}}</h2>
	<a href="/restaurant/payment-info/{{result.id_restaurant}}">Edit payment info</a>
	<br/><br/>

		<table class="tb-grid tb-zebra">
			<tbody>
				<tr ng-if="result.id_payment">
					<td><strong>Payment id</strong></td>
					<td>
						<span ng-if="payment"># {{result.id_payment}}</span>
						<span ng-if="schedule" class="link orange" ng-click="view_payment( result.id_payment )"># {{result.id_payment}}</span>
					</td>
				</tr>
				<tr ng-if="result.id_payment_schedule">
					<td><strong>Payment schedule id</strong></td>
					<td>
						# {{result.id_payment_schedule}}
					</td>
				</tr>
				<tr>
					<td><strong>Payment Status</strong></td>
					<td ng-class="{ 'orange': result.status != 'done', 'green': result.status == 'done' }">
						{{result.status}}
						<span ng-if="result.status != 'done'" >
							<br/>
							<strong ng-click="do_payment()" class="orange link">Try send payment</strong>
						</span>
					</td>
				</tr>
				<tr ng-if="result.status == 'error' && result.log">
					<td><strong>Error log</strong></td>
					<td class="orange">
						{{result.log}}
						<br />
						<a href="/restaurant/payment-info/{{result.id_restaurant}}/pay">Edit payment method</a>
					</td>
				</tr>
				<tr ng-if="result.status == 'error' && result.status_date">
					<td><strong>Last try</strong></td>
					<td class="orange">{{result.status_date}}</td>
				</tr>
				<tr ng-if="result.payment_date">
					<td><strong>Payment date</strong></td>
					<td>{{result.payment_date}}</td>
				</tr>
				<tr>
					<td><strong>Payment method</strong></td>
					<td>{{result.payment_method}}</td>
				</tr>
				<tr ng-if="result.payment_date">
					<td>
						<strong>Summary sent date</strong>
					</td>
					<td>
						<span ng-if="result.summary_sent_date">{{result.summary_sent_date}}</span>
						<span ng-if="!result.summary_sent_date"><i>Summary not sent</i></span>
					</td>
				</tr>

				<tr ng-if="result.payment_date">
					<td>
						<span class="no-underline link orange" ng-click="view_summary()"><i class="fa fa-eye"></i> View Summary</span>
					</td>
					<td></td>
				</tr>
				<tr ng-if="result.payment_date">
					<td>
						<span class="no-underline link orange" ng-click="send_summary()"><i class="fa fa-send"></i> Send Summary</span>
					</td>
					<td></td>
				</tr>
				<tr ng-if="result.payment_date">
					<td>
						<span class="no-underline link orange" ng-click="download_summary()"><i class="fa fa-download"></i> Download Summary</span>
					</td>
					<td></td>
				</tr>
				<tr class="transparent"><td></td><td></td></tr>
				<tr ng-if="result.balanced_id">
					<td>Balanced Reference</td>
					<td>{{result.balanced_id}}</td>
				</tr>
				<tr ng-if="result.stripe_id">
					<td>Stripe</td>
					<td>
						<a target="_blank" href="https://dashboard.stripe.com/transfers/{{result.stripe_id}}">{{result.stripe_id}}</a>
					</td>
				</tr>
				<tr ng-if="result.check_id">
					<td>Lob (Check)</td>
					<td>
						<a target="_blank" href="https://dashboard.lob.com/#/checks/{{result.check_id}}">{{result.check_id}}</a>
					</td>
				</tr>
				<tr positive-or-negative-color="{{result.calcs.credit_charge}}" ng-if="result.calcs.credit_charge">
					<td>Credit Card Charge</td>
					<td>$ {{result.calcs.credit_charge | formatPrice}}</td>
				</tr>
				<tr positive-or-negative-color="{{result.calcs.tax}}" ng-if="result.calcs.tax">
					<td>Tax</td>
					<td>$ {{result.calcs.tax | formatPrice}}</td>
				</tr>
				<tr positive-or-negative-color="{{result.calcs.delivery_fee}}" ng-if="result.calcs.delivery_fee">
					<td>Delivery Fee</td>
					<td>$ {{result.calcs.delivery_fee | formatPrice}}</td>
				</tr>
				<tr positive-or-negative-color="{{result.calcs.tip}}" ng-if="result.calcs.tip">
					<td>Tip</td>
					<td>$ {{result.calcs.tip | formatPrice}}</td>
				</tr>
				<tr positive-or-negative-color="{{result.calcs.promo_gift_card}}" ng-if="result.calcs.promo_gift_card">
					<td>Promo Gift Card</td>
					<td>$ {{result.calcs.promo_gift_card | formatPrice}}</td>
				</tr>
				<tr positive-or-negative-color="{{result.calcs.apology_gift_card}}" ng-if="result.calcs.apology_gift_card">
					<td>Apology Gift Card</td>
					<td>$ {{result.calcs.apology_gift_card | formatPrice}}</td>
				</tr>
				<tr positive-or-negative-color="{{result.calcs.card_subtotal}}" ng-if="result.calcs.card_subtotal">
					<td>Credit Card Subtotal</td>
					<td>$ {{result.calcs.card_subtotal | formatPrice}}</td>
				</tr>
				<tr positive-or-negative-color="{{result.calcs.cash_reimburse}}" ng-if="result.calcs.cash_reimburse">
					<td>Cash Reimburse</td>
					<td>$ {{result.calcs.cash_reimburse | formatPrice}}</td>
				</tr>
				<tr positive-or-negative-color="{{result.calcs.cash_subtotal}}" ng-if="result.calcs.cash_subtotal">
					<td>Cash Subtotal</td>
					<td>$ {{result.calcs.cash_subtotal | formatPrice}}</td>
				</tr>
				<tr positive-or-negative-color="{{result.adjustment}}" ng-if="result.adjustment">
					<td>Adjustment</td>
					<td>$ {{result.adjustment | formatPrice}}</td>
				</tr>
				<tr class="total-due" positive-or-negative-color="{{result.calcs.total_due}}" ng-if="result.calcs.total_due">
					<td class="td-medium">Total due</td>
					<td class="td-medium">$ {{result.calcs.total_due | formatPrice}}</td>
				</tr>
				<tr class="total-due" positive-or-negative-color="{{result.amount}}">
					<td class="td-medium">Amount</td>
					<td class="td-medium">${{result.amount | formatPrice}}</td>
				</tr>
				<tr ng-if="result.range_date">
					<td><strong>Period</strong></td>
					<td>{{result.range_date}}</td>
				</tr>
				<tr>
					<td>Payment Notes</td>
					<td>{{result.note}}</td>
				</tr>
				<tr ng-if="result.id_payment && !result.check_id">
					<td><strong>Payment Status</strong></td>
					<td ng-class="result.payment_status">
						{{result.payment_status}}
						<span title="Re-check balanced status" class="link no-underline" ng-click="payment_status();"> <i class="fa fa-refresh"></i> </span>
					</td>
				</tr>
				<tr ng-if="result.payment_date_checked">
					<td><strong>Payment Status Checked</strong></td>
					<td ng-class="result.payment_status">
						{{result.payment_date_checked}}
					</td>
				</tr>
				<tr ng-if="result.payment_failure_reason">
					<td><strong>Payment Failure Reason</strong></td>
					<td ng-class="result.payment_status">
						{{result.payment_failure_reason}}
					</td>
				</tr>
			</tbody>
		</table>

		<br/>

		<table class="tb-grid tb-zebra">
			<thead ng-if="result.orders_card">
				<tr>
					<td colspan="5" class="title">Card Orders</td>
				</tr>
			</thead>
			<thead ng-if="!result.orders_card">
				<td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
				</td>
			</thead>
			<thead ng-if="result.orders_card">
				<tr>
					<td>#</td>
					<td class="td-medium">Customer</td>
					<td>Date</td>
					<td>Total</td>
					<td>Tip</td>
				</tr>
			</thead>
			<tbody ng-if="result.orders_card">
				<tr ng-repeat="order in result.orders.card">
					<td>{{order.id_order}}</td>
					<td>{{order.name}}</td>
					<td>{{order.date}}</td>
					<td>$ {{order.total | formatPrice}}</td>
					<td>$ {{order.tip | formatPrice}}</td>
				</tr>
			</tbody>

			<tbody>
				<tr class="transparent" ng-if="result.calcs.order_paymen">
					<td></td>
					<td>Subtotal</td>
					<td>$ {{result.calcs.order_payment | formatPrice}}</td>
					<td></td>
				</tr>
				<tr class="transparent" ng-if="result.calcs.tip">
					<td></td>
					<td>Tips by Card</td>
					<td>$ {{result.calcs.tip | formatPrice}}</td>
					<td></td>
				</tr>
				<tr class="transparent" ng-if="result.calcs.credit_charge">
					<td></td>
					<td>Visa/Mastercard/Amex Charges</td>
					<td>$ {{result.calcs.credit_charge | formatPrice}}</td>
					<td></td>
				</tr>
				<tr class="transparent"><td></td><td></td><td></td><td></td></tr>
			</tbody>

			<thead ng-if="result.orders_cash">
				<tr>
					<td colspan="5" class="title">Cash Orders</td>
				</tr>
			</thead>
			<thead ng-if="!result.orders_cash">
				<td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
				</td>
			</thead>
			<thead ng-if="result.orders_cash">
				<tr>
					<td>#</td>
					<td class="td-medium">Customer</td>
					<td>Date</td>
					<td>Total</td>
					<td></td>
				</tr>
			</thead>
			<tbody ng-if="result.orders_cash">
				<tr ng-repeat="order in result.orders.cash">
					<td>{{order.id_order}}</td>
					<td>{{order.name}}</td>
					<td>{{order.date}}</td>
					<td>$ {{order.total | formatPrice}}</td>
					<td></td>
				</tr>
			</tbody>

			<tbody>
				<tr class="transparent" ng-if="result.calcs.cash_subtotal">
					<td></td>
					<td>Subtotal</td>
					<td>$ {{result.calcs.cash_subtotal | formatPrice}}</td>
					<td></td>
				</tr>
				<tr class="transparent" ng-if="result.calcs.restaurant_fee">
					<td></td>
					<td>Fees</td>
					<td>$ {{result.calcs.restaurant_fee | formatPrice}}</td>
					<td></td>
				</tr>
				<tr class="transparent" ng-if="result.adjustment">
					<td></td>
					<td>Adjustment</td>
					<td>$ {{result.adjustment | formatPrice}}</td>
					<td></td>
				</tr>
				<tr class="transparent" ng-if="result.calcs.total_due">
					<td></td>
					<td><strong>Total Payment (minus fees)</strong></td>
					<td><strong>$ {{result.calcs.total_due | formatPrice}}</strong></td>
					<td></td>
				</tr>
				<tr class="transparent"><td></td><td></td><td></td><td></td></tr>
			</tbody>

			<thead ng-if="result.orders_not_included">
				<tr>
					<td colspan="5" class="title">Not Paid Orders</td>
				</tr>
			</thead>
			<thead ng-if="result.orders_not_included">
				<tr>
					<td>#</td>
					<td class="td-medium">Customer</td>
					<td>Date</td>
					<td>Total</td>
					<td>Tip</td>
				</tr>
			</thead>
			<tbody ng-if="result.orders_not_included">
				<tr ng-repeat="order in result.orders.not_included">
					<td>{{order.id_order}}</td>
					<td>{{order.name}}</td>
					<td>{{order.date}}</td>
					<td>$ {{order.total | formatPrice}}</td>
					<td>$ {{order.tip | formatPrice}}</td>
				</tr>
			</tbody>


		</table>
</div>

<spinner-loading></spinner-loading>
<hack-expand-content></hack-expand-content>
