<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">{{result.title}} #{{result.id_payment}} - {{result.driver}}</span>
		<span ng-if="schedule">{{result.title}} Schedule #{{result.id_payment_schedule}} - {{result.driver}}</span>
	</h1>

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

	<h2 class="title">#{{result.id_driver}} - {{result.driver}}</h2>
	<a href="/staff/{{result.id_driver}}/payinfo">Edit payment info</a> |
	<a href="/drivers/payment/{{result.id_payment_schedule}}">Driver's Summary</a>

	<br/><br/>

		<table class="tb-grid tb-zebra">
			<tbody>
				<tr ng-if="result.id_payment">
					<td><strong>{{result.title}} 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>{{result.title}} schedule id</strong></td>
					<td>
						# {{result.id_payment_schedule}}
					</td>
				</tr>
				<tr ng-if="pay_type_reimbursement">
					<td><strong>Type</strong></td>
					<td>Reimbursement</td>
				</tr>
				<tr ng-if="pay_type_payment">
					<td><strong>Type</strong></td>
					<td>Payment</td>
				</tr>
				<tr>
					<td><strong>Status</strong></td>
					<td ng-class="{ 'orange': result.status != 'done', 'green': result.status == 'done' }">
						{{result.status}}
						<span ng-if="( result.status == 'error' || result.status == 'archived' )" >
							<br/>
							<strong ng-click="do_payment()" class="orange link">Try send payment</strong>
						</span>
						<span ng-if="( result.status == 'scheduled' )" >
							<br/>
							<strong ng-click="force_payment()" class="orange link">Force payment</strong>
						</span>

					</td>
				</tr>
				<tr ng-if="result.log">
					<td><strong>Log</strong></td>
					<td class="orange">{{result.log}}</td>
				</tr>
				<tr ng-if="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>Date</strong></td>
					<td>{{result.payment_date}}</td>
				</tr>
				<tr>
					<td><strong>Method</strong></td>
					<td>{{result.payment_method}}</td>
				</tr>
				<tr>
					<td><strong>Salary Type</strong></td>
					<td>
						<span class="tag tag-blue" ng-if="result.driver_payment_type == 'orders'">Commission</span>
						<span class="tag tag-purple" ng-if="result.driver_payment_type == 'hours'">Hourly with tips</span>
						<span class="tag tag-orange" ng-if="result.driver_payment_type == 'hours_without_tips'">Hourly without tips</span>
						<span class="tag tag-yellow" ng-if="result.driver_payment_type == 'making_whole'">Making whole</span>
						<span class="tag tag-grey" ng-if="!result || !result.driver_payment_type || result.driver_payment_type == '-' ">Payment Type Missing</span>
					</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</td>
					<td>
						<a href="https://dashboard.balancedpayments.com/#/marketplaces/MP2BldrjHz0NLH3st95JbeR0/credits/{{result.balanced_id}}">
							{{result.balanced_id}}
						</a>
					</td>
				</tr>
				<tr>
					<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>
				<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.range_date">
					<td>Period</td>
					<td>{{result.range_date}}</td>
				</tr>
				<tr ng-if="result.hourly" positive-or-negative-color="{{result.shifts_hours_amount}}">
					<td>Worked hours</td>
					<td>${{result.shifts_hours_amount | formatPrice}}</td>
				</tr>

				<tr ng-if="( !result.hourly || result.driver_payment_type == 'making_whole' ) && result.calcs.tax && pay_type_payment" positive-or-negative-color="{{result.calcs.tax}}">
					<td>Tax</td>
					<td>${{result.calcs.tax | formatPrice}}</td>
				</tr>
				<tr ng-if="( !result.hourly || result.driver_payment_type == 'making_whole' ) && result.calcs.delivery_fee && pay_type_payment" positive-or-negative-color="{{result.calcs.delivery_fee}}">
					<td>Delivery Fee</td>
					<td>${{result.calcs.delivery_fee | formatPrice}}</td>
				</tr>
				<tr ng-if="( !result.hourly || result.driver_payment_type == 'making_whole' ) && result.calcs.delivery_fee && pay_type_payment && result.show_delivery_fees" positive-or-negative-color="{{result.calcs.delivery_fee}}">
					<td>Delivery Commission</td>
					<td>${{result.calcs.amount_per_order | formatPrice}}</td>
				</tr>

				<tr ng-if="( !result.hourly || result.show_credit_card_tips && !result.driver_payment_type == 'making_whole' ) && result.calcs.tip && pay_type_payment" positive-or-negative-color="{{result.calcs.tip}}">
					<td>Tip</td>
					<td>${{result.calcs.tip | formatPrice}}</td>
				</tr>

				<tr ng-if="pay_type_payment && result.calcs.total_commissioned" positive-or-negative-color="{{result.calcs.total_commissioned}}">
					<td>Commissioned Orders</td>
					<td>${{result.calcs.total_commissioned | formatPrice}}</td>
				</tr>

				<tr ng-if="pay_type_payment && result.calcs.total_commissioned_tip && ( !result.show_credit_card_tips || result.driver_payment_type == 'making_whole' )" positive-or-negative-color="{{result.calcs.total_commissioned_tip}}">
					<td>Tip</td>
					<td>${{result.calcs.total_commissioned_tip | formatPrice}}</td>
				</tr>

				<tr ng-if="( !result.hourly || result.driver_payment_type == 'making_whole' ) && result.calcs.customer_fee && pay_type_payment" positive-or-negative-color="{{result.calcs.customer_fee}}">
					<td>Customer Fee</td>
					<td>${{result.calcs.customer_fee | formatPrice}}</td>
				</tr>
				<tr ng-if="result.calcs.markup && pay_type_payment" positive-or-negative-color="{{result.calcs.markup}}">
					<td>Crunchbutton’s Markup Already Collected In Cash</td>
					<td>${{result.calcs.markup | formatPrice}}</td>
				</tr>
				<tr ng-if="result.calcs.delivery_fee_collected && pay_type_payment" positive-or-negative-color="{{result.calcs.delivery_fee_collected}}">
					<td>Delivery Fee Collected In Cash</td>
					<td>${{result.calcs.delivery_fee_collected | formatPrice}}</td>
				</tr>
				<tr ng-if="result.calcs.customer_fee_collected && pay_type_payment" positive-or-negative-color="{{result.calcs.customer_fee_collected}}">
					<td>Customer Fee Collected In Cash</td>
					<td>${{result.calcs.customer_fee_collected | formatPrice}}</td>
				</tr>

				<tr ng-if="( !result.hourly || result.driver_payment_type == 'making_whole' ) && result.calcs.credit_charge && pay_type_payment" positive-or-negative-color="{{result.calcs.credit_charge}}">
					<td>Credit Card Charge</td>
					<td>${{result.calcs.credit_charge | formatPrice}}</td>
				</tr>
				<tr ng-if="( !result.hourly || result.driver_payment_type == 'making_whole' ) && result.calcs.gift_card && pay_type_payment" positive-or-negative-color="{{result.calcs.gift_card}}">
					<td>Gift Card</td>
					<td>${{result.calcs.gift_card | formatPrice}}</td>
				</tr>
				<tr positive-or-negative-color="{{result.invites_amount}}" ng-if="result.invites_amount && pay_type_payment">
					<td>New Invited Users</td>
					<td>${{result.invites_amount | formatPrice}}</td>
				</tr>
				<tr ng-if="result.adjustment && result._total_reimburse_ && pay_type_reimbursement" positive-or-negative-color="{{result._total_reimburse_}}">
					<td>Reimbursement</td>
					<td>${{result._total_reimburse_ | formatPrice}}</td>
				</tr>
				<tr ng-if="result.adjustment && result._total_payment_ && pay_type_payment" positive-or-negative-color="{{result._total_payment_}}">
					<td>Payment</td>
					<td>${{result._total_payment_ | formatPrice}}</td>
				</tr>
				<tr ng-if="result.adjustment" positive-or-negative-color="{{result.adjustment}}">
					<td>Adjustments</td>
					<td>${{result.adjustment | formatPrice}}</td>
				</tr>
				<tr class="total-due" positive-or-negative-color="{{result.calcs.total_reimburse}}" ng-if="pay_type_reimbursement">
					<td class="td-medium">Amount</td>
					<td class="td-medium">${{result.calcs.total_reimburse | formatPrice}}</td>
				</tr>
				<tr class="total-due" positive-or-negative-color="{{result.calcs.total_payment}}" ng-if="pay_type_payment">
					<td class="td-medium">Amount</td>
					<td class="td-medium">${{result.calcs.total_payment | formatPrice}}</td>
				</tr>
				<tr ng-if="result.adjustment_note">
					<td>Adjustments Note</td>
					<td>{{result.adjustment_note}}</td>
				</tr>
				<tr>
					<td>{{result.title}} Notes</td>
					<td>{{result.note}}</td>
				</tr>
			</tbody>
		</table>

		<br/>

		<table class="tb-grid tb-zebra" ng-if="result.invites.length">
			<thead>
				<tr>
					<td colspan="3" class="title">New Invited Users</td>
				</tr>
			</thead>
			<thead>
				<tr>
					<td></td>
					<td></td>
					<td></td>
				</tr>
			</thead>
			<thead>
				<tr>
					<td>Customer Name</td>
					<td>First Order At</td>
					<td>Amount</td>
				</tr>
			</thead>
			<tbody>
				<tr ng-repeat="invite in result.invites">
					<td>{{invite.user.name}}</td>
					<td>{{invite.date}}</td>
					<td>${{invite.amount | formatPrice}}</td>
				</tr>
			</tbody>
		</table>


		<br/>

		<table class="tb-grid tb-zebra" ng-if="result.shifts.length">
			<thead>
				<tr>
					<td colspan="4" class="title">Shifts</td>
				</tr>
			</thead>
			<thead>
				<tr>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
				</tr>
			</thead>
			<thead>
				<tr>
					<td>Started at</td>
					<td>Finished at</td>
					<td>Hours</td>
					<td>Amount</td>
				</tr>
			</thead>
			<tbody>
				<tr ng-repeat="shift in result.shifts">
					<td>{{shift.period.start}}</td>
					<td>{{shift.period.end}}</td>
					<td>{{shift.hours}}</td>
					<td>
						<span ng-if="!shift.created_by_driver">${{shift.amount | formatPrice}}</span>
						<span ng-if="shift.created_by_driver">$0.00</span>
					</td>
				</tr>
			</tbody>
			<tbody>
				<tr class="transparent">
					<td></td>
					<td></td>
					<td></td>
					<td></td>
				</tr>
				<tr class="transparent">
					<td></td>
					<td>Total By Hours</td>
					<td>${{result.shifts_hours_amount | formatPrice}}</td>
					<td></td>
				</tr>
			</tbody>
		</table>

		<br/>

		<table class="tb-grid tb-zebra">
			<thead ng-if="result.orders.included.length > 0 || result.orders.not_included.length > 0">
				<tr>
					<td colspan="12" class="title">Orders</td>
				</tr>
			</thead>
			<thead ng-if="!result.orders">
				<tr>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
				</tr>
			</thead>
			<thead ng-if="result.orders.included.length > 0 || result.orders.not_included.length > 0">
				<tr>
					<td>#</td>
					<td>Customer</td>
					<td>Restaurant</td>
					<td>Date</td>
					<td>Type</td>
					<td>
						<span ng-if="pay_type_payment">Tip</span>
					</td>
					<td>
						<span ng-if="pay_type_payment">Delivery<br>Commission</span>
					</td>
					<td>
						<span ng-if="pay_type_payment">Delivery Fee</span>
					</td>
					<td>
						<span ng-if="pay_type_payment">Markup <br>(Collected in Cash)</span>
					</td>
					<td>
						<span ng-if="pay_type_payment">Delivery Fee <br>(Collected in Cash)</span>
					</td>
					<td>
						<span ng-if="pay_type_payment">Customer Fee <br>(Collected in Cash)</span>
					</td>
					<td ng-if="pay_type_reimbursement">Reimbursement</td>
					<td ng-if="pay_type_payment">Payment</td>
				</tr>
			</thead>
			<tbody ng-if="result.orders.included">
				<tr ng-repeat="order in result.orders.included">
					<td>
						<span title="Order delivered during a shift created by driver" ng-if="order.force_to_be_commissioned"><i class="fa fa-money"></i></span>
						{{order.id_order}}
					</td>
					<td>{{order.name}}</td>
					<td>{{order.restaurant}}</td>
					<td>{{order.date}}</td>
					<td>{{order.pay_type}}</td>
					<td><span ng-if="pay_type_payment">${{order.tip | formatPrice}}</span></td>
					<td><span ng-if="pay_type_payment">${{order.amount_per_order | formatPrice}}</span></td>
					<td><span ng-if="pay_type_payment">${{order.delivery_fee | formatPrice}}</span></td>
					<td><span ng-if="pay_type_payment">${{order.markup | formatPrice}}</span></td>
					<td><span ng-if="pay_type_payment">${{order.delivery_fee_collected | formatPrice}}</span></td>
					<td><span ng-if="pay_type_payment">${{order.customer_fee_collected | formatPrice}}</span></td>
					<td ng-if="pay_type_reimbursement">${{order.total_reimburse | formatPrice}}</td>
					<td ng-if="pay_type_payment">${{order.total_payment | formatPrice}}</td>
				</tr>
			</tbody>
			<tbody>
			<?php /* ?>
				<tr class="transparent">
					<td></td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
				</tr>
				<tr class="transparent" ng-if="pay_type_payment && ( !result.hourly || result.driver_payment_type == 'making_whole' ) && result.calcs.delivery_fee">
					<td></td>
					<td></td>
					<td>Total Delivery Fee</td>
					<td>${{result.calcs.delivery_fee | formatPrice}}</td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
				</tr>
				<tr class="transparent" ng-if="pay_type_payment && result.invites_amount">
					<td></td>
					<td></td>
					<td>Total New Invited Users</td>
					<td>${{result.invites_amount | formatPrice}}</td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
				</tr>
				<tr class="transparent" ng-if="pay_type_payment && result.calcs.tip">
					<td></td>
					<td></td>
					<td>Tips by Card</td>
					<td>${{result.calcs.tip | formatPrice}}</td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
				</tr>
				<tr class="transparent" ng-if="result.adjustment && result._total_reimburse_ && pay_type_reimbursement">
					<td></td>
					<td></td>
					<td>Reimbursement</td>
					<td>${{result._total_reimburse_ | formatPrice}}</td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
				</tr>
				<tr class="transparent" ng-if="result.adjustment && result._total_payment_ && pay_type_payment">
					<td></td>
					<td></td>
					<td>Payment</td>
					<td>${{result._total_payment_ | formatPrice}}</td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
				</tr>
				<tr class="transparent" ng-if="result.adjustment">
					<td></td>
					<td></td>
					<td>Adjustment</td>
					<td>${{result.adjustment | formatPrice}}</td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
				</tr>
				<tr class="transparent" ng-if="pay_type_reimbursement">
					<td></td>
					<td></td>
					<td><strong>Total Reimbursed</strong></td>
					<td><strong>${{result.calcs.total_reimburse | formatPrice}}</strong></td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
				</tr>
				<tr class="transparent" ng-if="pay_type_payment && result.calcs.markup">
					<td></td>
					<td></td>
					<td><strong>Markup</strong></td>
					<td><strong>${{result.calcs.markup | formatPrice}}</strong></td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
				</tr>
				<tr class="transparent" ng-if="pay_type_payment">
					<td></td>
					<td></td>
					<td><strong>Total Payment</strong></td>
					<td><strong>${{result.calcs.total_payment | formatPrice}}</strong></td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
				</tr>
				<tr ng-if="result.adjustment_note">
					<td></td>
					<td></td>
					<td>Adjustments Note</td>
					<td>{{result.adjustment_note}}</td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
				</tr>
				<?php */ ?>
				<tr class="transparent"><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
			</tbody>
		</table>
</div>

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