<div class="xhatch separator-big"></div>

<table width="100%" cellpadding="0" cellspacing="0">
	<tr>
		<td style="border: 0; padding: 5px;">
			<h1>Crunchbutton</h1>
		</td>
		<td style="border: 0; padding: 5px; text-align: right;">
			<span class="order-num">
			<?php if( $summary[ 'pay_type' ] == Cockpit_Payment_Schedule::PAY_TYPE_REIMBURSEMENT ) { ?>
				Reimbursement #
			<?php } else { ?>
				Payment #
			<?php } ?>
			<?php echo $summary[ 'id_payment' ]; ?></span><br />
			<?php echo $summary[ 'driver' ]; ?><br />
			<?php if( $summary[ 'range_date' ] ) {
				echo 'Period ' . $summary[ 'range_date' ];
			}?>
		</td>
	</tr>
</table>

<div class="xhatch separator-small"></div>

<table width="100%" celpadding="0" cellspacing="0">
	<tr>
		<td>
				<table cellpadding="0" cellspacing="0">
					<tr>
					<td style="font-size:22px;" class="text-size-mid"><strong><?php echo $summary[ 'driver' ]; ?></strong></td>
				</tr>
			</table>
		</td>
	</tr>
</table>
<?php if( $summary[ 'note' ] ) { ?>
	<table class="notes" cellpadding="0" cellspacing="0">
		<tr>
			<td valign="top"><img src="<?=$this->helper('ImageBase64')->output(c::config()->dirs->www.'/assets/images/mprinter/note.png')?>" class="icon-note"></td>
			<td style="margin: 0; padding: 22px 0 0 0;" valign="top"><div class="arrow-left"></div></td>
			<td style="width: 100%; padding-right: 0; "><table style="width: 100%"><tr><td class="notes-content"><?=nl2br( $summary[ 'note' ] )?></td></tr></table></td>
		</tr>
	</table>
<?php } ?>

<?php if( $summary[ 'pay_type' ] == Cockpit_Payment_Schedule::PAY_TYPE_PAYMENT ) { ?>
<div class="xhatch separator-small"></div>
	<br>
	<br>
	<table width="100%" celpadding="0" cellspacing="0" class="detail">
		<tbody>
			<tr>
				<td class="topitem"><strong>Total Money Made This Week</strong></td>
				<td class="topitem">$<?php echo number_format( $summary[ 'calcs' ][ 'earnings' ], 2 ); ?></td>
			</tr>
			<tr>
				<td class="topitem"><strong>Amount Already Collected in Cash</strong></td>
				<td class="topitem">$<?php echo number_format( $summary[ 'calcs' ][ 'collected_in_cash' ], 2 ); ?></td>
			</tr>
			<tr>
				<td class="topitem"><strong>Additional Payment Due Through Deposit</strong></td>
				<td class="topitem">$<?php echo number_format( $summary[ 'calcs' ][ 'total_payment' ], 2 ); ?></td>
			</tr>
		</tbody>
	</table>
	<br>
	<br>
<?php } ?>
<div class="xhatch separator-small"></div>

<?php if( $summary[ 'driver_payment_hours' ] ) { ?>
	<table width="100%" celpadding="0" cellspacing="0" class="detail">
		<thead style="font-weight:bold">
			<tr>
				<td colspan="7" class="topitem" style="font-size:18px;">Shifts</td>
			</tr>
		</thead>
		<thead style="font-weight:bold">
			<tr>
				<td class="topitem">Started at</td>
				<td class="topitem">Finished at</td>
				<td class="topitem">Hours</td>
				<td class="topitem">Amount</td>
			</tr>
		</thead>
		<tbody>
		<?php foreach( $summary[ 'shifts' ] as $shift ) { ?>
			<tr>
				<td class="topitem"><?php echo $shift[ 'period' ][ 'start' ]; ?></td>
				<td class="topitem"><?php echo $shift[ 'period' ][ 'end' ]; ?></td>
				<td class="topitem"><?php echo $shift[ 'hours' ]; ?></td>
				<td class="topitem">$<?php echo number_format( $shift[ 'amount' ], 2 ); ?></td>
			</tr>
		<?php } ?>
		</tbody>
	</table>
	<br>
	<br>
<?php } ?>

<?php if( $summary[ 'invites' ] && count( $summary[ 'invites' ] ) >0 ) { ?>
	<table width="100%" celpadding="0" cellspacing="0" class="detail">
		<thead style="font-weight:bold">
			<tr>
				<td colspan="3" class="topitem" style="font-size:18px;">New Invited Users</td>
			</tr>
		</thead>
		<thead style="font-weight:bold">
			<tr>
				<td class="topitem">Customer Name</td>
				<td class="topitem">First Order At</td>
				<td class="topitem">Amount</td>
			</tr>
		</thead>
		<tbody>
		<?php foreach( $summary[ 'invites' ] as $invite ) { ?>
			<tr>
				<td class="topitem"><?php echo $invite[ 'user' ][ 'name' ]; ?></td>
				<td class="topitem"><?php echo $invite[ 'date' ]; ?></td>
				<td class="topitem">$<?php echo number_format( $invite[ 'amount' ], 2 ); ?></td>
			</tr>
		<?php } ?>
		</tbody>
	</table>
	<br>
	<br>
<?php } ?>

<?php
	$coslpan = ( $summary[ 'driver_payment_hours' ] ) ?  3 : 5;
	if( $summary[ 'pay_type' ] == Cockpit_Payment_Schedule::PAY_TYPE_REIMBURSEMENT ) {
		$coslpan = 4;
	} else {
		$coslpan += 3;
		if ( $summary[ 'driver_payment_type' ] == Crunchbutton_Admin_Payment_Type::PAYMENT_TYPE_ORDERS ) {
			$coslpan -= 1;
		}
	}
?>

<table width="100%" celpadding="0" cellspacing="0" class="detail">
	<?php if( count(  $summary[ 'orders' ][ 'included' ] ) > 0 ) { ?>
	<thead style="font-weight:bold">
		<tr>
			<td colspan="<?php echo $coslpan + 4; ?>" class="topitem" style="font-size:18px;">Orders</td>
		</tr>
	</thead>
	<thead style="font-weight:bold">
		<tr>
			<?php if( !$summary[ 'show_credit_card_tips' ] ) { ?><td class="topitem"></td><?php } ?>
			<?php if( !$summary[ 'show_delivery_fees' ] ) { ?><td class="topitem"></td><?php } ?>
			<td style="width:215px;" class="topitem">Customer</td>
			<td style="width:255px;" class="topitem">Restaurant</td>
			<td style="width:215px;" class="topitem">Date</td>
			<?php if( $summary[ 'pay_type' ] == Cockpit_Payment_Schedule::PAY_TYPE_PAYMENT ) { ?>
				<?php if( $summary[ 'show_credit_card_tips' ] ){ ?>
					<td style="width:90px;" class="topitem">
						Tip
					</td>
				<?php } ?>
				<?php if( $summary[ 'show_delivery_fees' ] ) { ?>
					<td style="width:155px;" class="topitem">Delivery Commission</td>
				<?php } ?>
				<td style="width:155px;" class="topitem">Delivery Fee Already Collected in Cash</td>
				<td style="width:155px;" class="topitem">Markup Already Collected in Cash</td>
				<?php if( ( !$summary[ 'driver_payment_hours' ] || $summary[ 'driver_payment_type' ] == Crunchbutton_Admin_Payment_Type::PAYMENT_TYPE_MAKING_WHOLE ) ) { ?>
					<td style="width:155px;" class="topitem">Money Made</td>
				<?php } ?>
			<?php } ?>
			<?php if( $summary[ 'pay_type' ] == Cockpit_Payment_Schedule::PAY_TYPE_REIMBURSEMENT ) { ?>
				<td class="topitem">Reimbursement</td>
			<?php } ?>
		</tr>
	</thead>
	<?php } ?>
	<?php foreach( $summary[ 'orders' ][ 'included' ] as $order ) { ?>
		<tr>
			<?php if( !$summary[ 'show_delivery_fees' ] ) { ?><td class="fooditem"></td><?php } ?>
			<?php if( !$summary[ 'show_credit_card_tips' ] ) { ?><td class="fooditem"></td><?php } ?>
			<td class="fooditem"><?php echo $order[ 'name' ]; ?></td>
			<td class="fooditem"><?php echo $order[ 'restaurant' ]; ?></td>
			<td class="fooditem"><?php echo $order[ 'date' ]; ?></td>
			<?php if( $summary[ 'pay_type' ] == Cockpit_Payment_Schedule::PAY_TYPE_PAYMENT ) { ?>
				<?php if( $summary[ 'show_credit_card_tips' ] ) { ?>
					<td class="fooditem">
						<?php if( $order[ 'tip' ] && $order[ 'pay_type' ] == 'Card' ) { ?>
						$<?php echo number_format( $order[ 'tip' ], 2 ); ?>
						<?php } else { ?>
						-
						<?php } ?>
					</td>
				<?php } ?>

				<?php if( $summary[ 'show_delivery_fees' ] ) { ?>
					<td class="fooditem">$<?php echo number_format( $order[ 'amount_per_order' ], 2 ); ?></td>
				<?php } ?>
				<td class="fooditem">$<?php echo number_format( $order[ 'delivery_fee_collected' ], 2 ); ?></td>
				<td class="fooditem">$<?php echo number_format( $order[ 'markup' ], 2 ); ?></td>
				<?php if( ( !$summary[ 'driver_payment_hours' ] || $summary[ 'driver_payment_type' ] == Crunchbutton_Admin_Payment_Type::PAYMENT_TYPE_MAKING_WHOLE ) ) { ?>
					<td class="fooditem">$<?php echo number_format( $order[ 'total_payment' ], 2 ); ?></td>
				<?php } ?>

			<?php } else { ?>
				<td class="fooditem">$<?php echo number_format( $order[ 'total_reimburse' ], 2 ); ?></td>
			<?php } ?>
		</tr>
	<?php } ?>
		<tr>
			<td colspan="<?php echo $coslpan + 1; ?>">&nbsp;</td>
		</tr>

	<?php if( $summary[ 'pay_type' ] == Cockpit_Payment_Schedule::PAY_TYPE_PAYMENT ) { ?>
		<?php if( $summary[ 'driver_payment_hours' ] ) { ?>
			<tr class="class">
				<td colspan="<?php echo $coslpan; ?>" style="text-align:right">Worked Hours</td>
				<td>$<?php echo number_format( $summary[ 'shifts_hours_amount' ], 2 ); ?></td>
			</tr>
		<?php } ?>
		<?php if( ( !$summary[ 'driver_payment_hours' ] || $summary[ 'driver_payment_type' ] == Crunchbutton_Admin_Payment_Type::PAYMENT_TYPE_MAKING_WHOLE ) && $summary[ 'show_delivery_fees' ] ) { ?>
			<tr class="class">
				<td colspan="<?php echo $coslpan; ?>" style="text-align:right">Total Delivery Commission</td>
				<td>$<?php echo number_format( $summary[ 'calcs' ][ 'delivery_fee' ], 2 ); ?></td>
			</tr>
		<?php } ?>
		<?php if( $summary[ 'show_credit_card_tips' ] ) { ?>
			<tr class="class">
				<td colspan="<?php echo $coslpan; ?>" style="text-align:right">Tip</td>
				<td>$<?php echo number_format( $summary[ 'calcs' ][ 'tip' ], 2 ); ?></td>
			</tr>
		<?php } ?>
			<tr class="class">
				<td colspan="<?php echo $coslpan; ?>" style="text-align:right">Delivery Fee Already Collected in Cash</td>
				<td>$<?php echo number_format( $summary[ 'calcs' ][ 'delivery_fee_collected' ], 2 ); ?></td>
			</tr>
			<tr class="class">
				<td colspan="<?php echo $coslpan; ?>" style="text-align:right">Crunchbutton’s Markup Already Collected In Cash</td>
				<td>$<?php echo number_format( $summary[ 'calcs' ][ 'markup' ], 2 ); ?></td>
			</tr>
				<?php if( $summary[ 'calcs' ][ 'customer_fee_collected' ] ) { ?>
					<tr class="class">
						<td colspan="<?php echo $coslpan; ?>" style="text-align:right">Customer Fee Collected in Cash</td>
						<td>$<?php echo number_format( $summary[ 'calcs' ][ 'customer_fee_collected' ], 2 ); ?></td>
					</tr>
				<?php } ?>
		<?php if( floatval( $summary[ 'invites_amount' ] ) > 0 ) { ?>
		<tr class="class">
			<td colspan="<?php echo $coslpan; ?>" style="text-align:right">Total New Invited Users</td>
			<td>$<?php echo number_format( $summary[ 'invites_amount' ], 2 ); ?></td>
		</tr>
		<?php } ?>
	<?php } ?>

		<?php if( $summary[ 'adjustment' ] ) { ?>
			<?php if( $summary[ 'pay_type' ] == Cockpit_Payment_Schedule::PAY_TYPE_PAYMENT ) { ?>
				<tr class="class">
					<td colspan="<?php echo $coslpan; ?>" style="text-align:right">Payment</td>
					<td>$<?php echo number_format( $summary[ '_total_payment_' ], 2 ); ?></td>
				</tr>
			<?php } else { ?>
				<tr class="class">
					<td colspan="<?php echo $coslpan; ?>" style="text-align:right">Reimbursement</td>
					<td>$<?php echo number_format( $summary[ '_total_reimburse_' ], 2 ); ?></td>
				</tr>
			<?php } ?>
			<tr class="class">
				<td colspan="<?php echo $coslpan; ?>" style="text-align:right">Adjustment</td>
				<td>$<?php echo number_format( $summary[ 'adjustment' ], 2 ); ?></td>
			</tr>
		<?php } ?>
		<tr class="class">
			<td colspan="<?php echo $coslpan; ?>" style="text-align:right"><strong>Amount</strong></td>
			<?php if( $summary[ 'pay_type' ] == Cockpit_Payment_Schedule::PAY_TYPE_PAYMENT ) { ?>
				<td><strong>$<?php echo number_format( $summary[ 'calcs' ][ 'total_payment' ], 2 ); ?></strong></td>
			<?php } else { ?>
				<td><strong>$<?php echo number_format( $summary[ 'calcs' ][ 'total_reimburse' ], 2 ); ?></strong></td>
			<?php } ?>
		</tr>
		<?php if( $summary[ 'adjustment_note' ] ) { ?>
			<tr class="class">
				<td style="text-align:right;padding-right:60px;" colspan="<?php echo ( $coslpan + 1 ); ?>">Adjustment Note:
					<?php echo $summary[ 'adjustment_note' ]; ?>
				</td>
			</tr>
		<?php } ?>
</table>
<br/><br/>
<table cellpadding="0" cellspacing="0" style="width: 100%; margin-top: 20px;">
	<tr>
		<td style="text-align: left;" class="text-size-small">
			<?php if( $summary[ 'payment_method' ] == 'deposit' ) { ?>
				Payment has been deposited into your bank account
			<?php } else { ?>

			<?php } ?>
		</td>
		<td style="text-align: right;" class="text-size-small">Crunchbutton support: call or text <?=c::config()->phone->restaurant?></td>
	</tr>
</table>

<div class="xhatch separator-big" style="text-align:right!important;"></div>
