partial #2250 - settlement - calcs and tests

This commit is contained in:
Daniel Camargo 2014-06-10 17:45:04 -03:00
parent 71bb429057
commit 84da4e5cda
8 changed files with 450 additions and 114 deletions

View File

@ -9,11 +9,8 @@ class Controller_settlement_begin extends Crunchbutton_Controller_Account {
$dates = explode(',',trim($_REQUEST['dates']));
c::view()->settlement = new Settlement([
'payment_method' => $_REQUEST['payment_method'],
'start' => $_REQUEST['start'],
'end' => $_REQUEST['end'],
]);
$settlement = new Settlement( [ 'payment_method' => $_REQUEST['payment_method'], 'start' => $_REQUEST['start'], 'end' => $_REQUEST['end'] ] );
c::view()->restaurants = $settlement->start();
c::view()->layout('layout/ajax');
c::view()->display('settlement/begin');

View File

@ -0,0 +1,45 @@
<?php
class Controller_settlement_test extends Crunchbutton_Controller_Account {
public function init() {
if (!c::admin()->permission()->check(['global','settlement'])) {
return;
}
$id_orders = c::getPagePiece( 2 );
if( $id_orders ){
$settlement = new Settlement;
$id_orders = explode( ',', $id_orders );
$orders = [];
$orders_values = [];
foreach( $id_orders as $key => $val ){
$id_order = trim( $val );
if( is_numeric( $id_order ) )
$order = Order::o( $id_order );
if( $order->id_order ){
$orders[] = $order;
}
}
if( count( $orders ) > 0 ){
foreach ( $orders as $order ) {
$values = $settlement->orderExtractVariables( $order );
$orders_values[] = $values;
$order->values = [ 'subtotal_card' => $settlement->orderCardSubtotalPayment( $values ),
'subtotal_cash' => $settlement->orderCashSubtotalPayment( $values ),
'tax' => $settlement->orderTaxPayment( $values ),
'delivery_fee' => $settlement->orderDeliveryFeePayment( $values ),
'tip' => $settlement->orderTipPayment( $values ),
'tip' => $settlement->orderTipPayment( $values ),
'card_charge' => $settlement->orderCreditChargePayment( $values ),
'restaurant_fee' => $settlement->orderRestaurantFeePayment( $values )
];
}
c::view()->pay = $settlement->processOrders( $orders_values );
c::view()->orders = $orders;
// echo '<pre>';var_dump( c::view()->pay );exit();
}
}
c::view()->display('settlement/test');
}
}

View File

@ -29,8 +29,7 @@ class Cockpit_Restaurant extends Crunchbutton_Restaurant {
and DATE(`date`) >= "' . (new DateTime($filters['start']))->format('Y-m-d') . '"
and DATE(`date`) <= "' . (new DateTime($filters['end']))->format('Y-m-d') . '"
and name not like "%test%"
order by `pay_type` asc, `date` asc
';
order by `pay_type` asc, `date` asc ';
$orders = Order::q($q);
$this->_payableOrders = $orders;
}

View File

@ -10,13 +10,23 @@
class Crunchbutton_Settlement extends Cana_Model {
public function __construct( $filters = [] ) {
$this->filters = $filters;
}
$this->restaurants = self::restaurants($filters);
public function start(){
foreach ($this->restaurants as $restaurant) {
$restaurant->_payableOrders = $restaurant->payableOrders( $filters );
$restaurant->payment_data = $this->processOrders( $restaurant->_payableOrders );
$this->restaurants = self::restaurants( $this->filters );
foreach ( $this->restaurants as $restaurant ) {
$restaurant->_payableOrders = $restaurant->payableOrders( $this->filters );
$payableOrders = $restaurant->_payableOrders;
$orders = [];
foreach( $payableOrders as $order ){
$orders[] = $this->orderExtractVariables( $order );
}
$restaurant->payment_data = $this->processOrders( $orders );
}
return $this->restaurants;
}
// get restaurants that we need to pay
@ -31,9 +41,8 @@ class Crunchbutton_Settlement extends Cana_Model {
}
$q .= ' AND restaurant.id_restaurant
GROUP BY id_restaurant
ORDER BY id_restaurant ASC';
// ORDER BY (CASE WHEN p_id_rest IS NULL THEN 1 ELSE 0 END) ASC,
return Restaurant::q($q);
ORDER BY (CASE WHEN p_id_rest IS NULL THEN 1 ELSE 0 END) ASC';
return Restaurant::q( $q );
}
@ -42,25 +51,29 @@ class Crunchbutton_Settlement extends Cana_Model {
// start all with 0
$pay = [ 'card_subtotal' => 0, 'tax' => 0, 'delivery_fee' => 0, 'tip' => 0, 'customer_fee' => 0, 'markup' => 0, 'credit_charge' => 0, 'restaurant_fee' => 0, 'promo_gift_card' => 0, 'apology_gift_card' => 0, 'order_payment' => 0, 'cash_subtotal' => 0 ];
foreach ( $orders as $order ) {
$arr = $this->orderExtractVariables( $order );
$pay[ 'card_subtotal' ] += $this->orderCardSubtotalPayment( $arr );
$pay[ 'tax' ] += $this->orderTaxPayment( $arr );
$pay[ 'delivery_fee' ] += $this->orderDeliveryFeePayment( $arr );
$pay[ 'tip' ] += $this->orderTipPayment( $arr );
$pay[ 'customer_fee' ] += $this->orderCustomerFeePayment( $arr );
$pay[ 'markup' ] += $this->orderMarkupPayment( $arr );
$pay[ 'credit_charge' ] += $this->orderCreditChargePayment( $arr );
$pay[ 'restaurant_fee' ] += $this->orderRestaurantFeePayment( $arr );
$pay[ 'promo_gift_card' ] += $this->orderPromoGiftCardPayment( $arr );
$pay[ 'apology_gift_card' ] += $this->orderApologyGiftCardPayment( $arr );
$pay[ 'order_payment' ] += $this->orderRestaurantOrderPayment( $arr );
$pay[ 'cash_subtotal' ] += $this->orderCashSubtotalPayment( $arr );
$formal_relationship = $arr[ 'formal_relationship' ];
foreach ( $orders as $order ) {;
if( $order ){
$pay[ 'card_subtotal' ] += $this->orderCardSubtotalPayment( $order );
$pay[ 'tax' ] += $this->orderTaxPayment( $order );
$pay[ 'delivery_fee' ] += $this->orderDeliveryFeePayment( $order );
$pay[ 'tip' ] += $this->orderTipPayment( $order );
$pay[ 'customer_fee' ] += $this->orderCustomerFeePayment( $order );
$pay[ 'markup' ] += $this->orderMarkupPayment( $order );
$pay[ 'credit_charge' ] += $this->orderCreditChargePayment( $order );
$pay[ 'restaurant_fee' ] += $this->orderRestaurantFeePayment( $order );
$pay[ 'promo_gift_card' ] += $this->orderPromoGiftCardPayment( $order );
$pay[ 'apology_gift_card' ] += $this->orderApologyGiftCardPayment( $order );
$pay[ 'order_payment' ] += $this->orderRestaurantOrderPayment( $order );
$pay[ 'cash_subtotal' ] += $this->orderCashSubtotalPayment( $order );
$pay[ 'formal_relationship' ] = $order[ 'formal_relationship' ];
}
}
// sum
$pay[ 'total_due' ] = $this->orderCalculateTotalDue( $pay );
return $pay;
}
public function orderCalculateTotalDue( $pay ){
$total_due = $pay[ 'card_subtotal' ] +
$pay[ 'tax' ] +
$pay[ 'delivery_fee' ] +
@ -71,8 +84,7 @@ class Crunchbutton_Settlement extends Cana_Model {
$pay[ 'restaurant_fee' ] +
$pay[ 'promo_gift_card' ] +
$pay[ 'apology_gift_card' ];
$pay[ 'total_due' ] = ( max( $total_due, 0 ) ) * $formal_relationship;
return $pay;
return ( max( $total_due, 0 ) ) * $pay[ 'formal_relationship' ];
}
// This method calculates the "base" charge for credit orders using the formula
@ -252,6 +264,13 @@ class Crunchbutton_Settlement extends Cana_Model {
$values[ 'delivery_service' ] = ( $order->delivery_service > 0 ) ? 1: 0;
$values[ 'formal_relationship' ] = ( $order->restaurant()->formal_relationship > 0 ) ? 1: 0;
$values[ 'paid_with_cb_card' ] = ( $order->paid_with_cb_card > 0 ) ? 1: 0;
$values[ 'refunded' ] = ( $order->refunded > 0 ) ? 1: 0;
$values[ 'pay_if_refunded' ] = ( $order->pay_if_refunded > 0 ) ? 1: 0;
// Pay if Refunded
if( $values[ 'refunded' ] == 1 && $values[ 'pay_if_refunded' ] == 0 ){
return false;
}
// convert all to float -> mysql returns some values as string
foreach( $values as $key => $val ){
@ -260,48 +279,3 @@ class Crunchbutton_Settlement extends Cana_Model {
return $values;
}
}
/*******************************************
// this method receives the restaurant orders and run the math
public function payableOrders( $orders ){
foreach ($orders as $order) {
// @note: i dont know what this is at all or why its a fixed 85% -devin
if ( Crunchbutton_Credit::creditByOrderPaidBy( $order->id_order, Crunchbutton_Credit::PAID_BY_PROMOTIONAL ) ) {
$order->_display_price *= 0.85;
$order->_display_final_price *= 0.85;
} else {
$order->_display_price = $order->price;
$order->_display_final_price = $order->final_price;
}
if ($restaurant->charge_credit_fee == '0') {
$order->_cc_fee = 0;
} else {
$order->_cc_fee = $order->pay_type == 'card' ? .3 + .029 * $order->_display_final_price : 0;
}
$order->_cb_fee = $order->cbFee(); // return ($this->restaurant()->fee_restaurant) * ($this->price) / 100;
if ($order->pay_type == 'card') {
$order->restaurant()->_settlement_card += $order->_display_final_price;
} else {
$order->restaurant()->_settlement_cash += $order->_display_final_price;
}
$order->restaurant()->_settlement_cc_fees += $order->_cc_fee;
$order->restaurant()->_settlement_cb_fees += $order->_cb_fee;
// @todo: determine if a driver picked this up and add them to a payment list
}
return $orders;
}
********************************************/

View File

@ -27,7 +27,7 @@
<div class="box-content">
<table width="100%">
<tr>
<?php foreach( $this->days as $day ) {
<?php foreach( $this->days as $day ) {
$dark = ( $day->format( 'N' ) == 7 || $day->format( 'N' ) % 2 == 0 ) ? '#F5F5F5' : '';
?>
<th width="14%" style="background:<?php echo $dark; ?>">
@ -43,7 +43,7 @@
<?php } ?>
</tr>
<tr>
<?php foreach( $this->days as $day ) {
<?php foreach( $this->days as $day ) {
$dark = ( $day->format( 'N' ) == 7 || $day->format( 'N' ) % 2 == 0 ) ? '#F5F5F5' : '';
?>
<td width="14%" style="background:<?php echo $dark; ?>" valign="top">
@ -65,15 +65,15 @@
foreach ( $groups as $group ) {
$pos = strrpos( $group->name, Crunchbutton_Group::DRIVER_GROUPS_PREFIX );
if( $pos !== false ){
$adminCommunities[ $group->name ] = Group::getRestaurantCommunityName( $group->name );
$adminCommunities[ $group->name ] = Group::getRestaurantCommunityName( $group->name );
}
}
if( count( $adminCommunities ) > 0 && $adminCommunities != '' ){
$join = '';
foreach( $adminCommunities as $communitie ) {
foreach( $adminCommunities as $communitie ) {
$communities .= $join . $communitie;
$join = ', ';
}
}
} else {
$communities = 'None';
}
@ -103,7 +103,7 @@
<?php
}
}
?>
?>
<?php if( $hasEditPermission ) { ?>
<div>
<button class="btn btn-default modal-hours-open" href="/drivers/hours/add/<?php echo $day->format( 'Y/m/d' ); ?>/<?php echo $this->week; ?>" style="width:80%;" title="Add hours to <?php echo $day->format( 'M' ); ?> <?php echo $day->format( 'd' ); ?> (<?php echo $day->format( 'D' ); ?>)">
@ -116,7 +116,7 @@
<?php } ?>
</tr>
</table>
<br/>
<div class="padded" style="font-size:16px;">
<?php if( $hasEditPermission ) { ?>
@ -177,12 +177,12 @@ workingHours.toggleTimezone = function(){
<?php foreach( $this->reps as $rep ) { ?>
<?php $now = new DateTime( 'now', new DateTimeZone( $rep->timezone ) ); ?>
<?php $now = new DateTime( 'now', new DateTimeZone( $rep->timezone ) ); ?>
workingHours.admin_tzs[ '<?php echo $rep->id_admin ?>' ] = '<?php echo $rep->timezone ?> (<?php echo $now->format( 'T' ); ?>)';
<?php } ?>
workingHours.admin_tz = '';
workingHours.setTimezone = function( id_admin ){
workingHours.admin_tz = ( workingHours.admin_tzs[ id_admin ] ) ? workingHours.admin_tzs[ id_admin ] : 'America/Los_Angeles';
workingHours.admin_tz = ( workingHours.admin_tzs[ id_admin ] ) ? workingHours.admin_tzs[ id_admin ] : 'America/Los_Angeles';
$( '#form-timezone' ).html( '<strong>' + workingHours.admin_tz + '</strong>' );
};
@ -199,7 +199,7 @@ workingHours.copyAll = function(){
} else {
alert( 'Ops, error! ' + data.error );
}
} );
} );
}
};
@ -223,14 +223,14 @@ workingHours.add = function(){
if( !workingHours.validateHours( hours ) ){
alert( 'Unable to figure out what this time means!' );
$( '#form-hours' ).focus();
return;
return;
}
var weekdays = [];
$( '[name="form-weekdays"]' ).each( function(){
var checkbox = $( this );
if( checkbox.is( ':checked' ) ){
weekdays.push( checkbox.val() );
weekdays.push( checkbox.val() );
}
} );
@ -248,8 +248,8 @@ workingHours.add = function(){
} );
};
workingHours.edit = function(){
workingHours.edit = function(){
var hours = $.trim( $( '#form-hours' ).val() );
if( hours == '' ){
@ -261,7 +261,7 @@ workingHours.edit = function(){
if( !workingHours.validateHours( hours ) ){
alert( 'Unable to figure out what this time means!' );
$( '#form-hours' ).focus();
return;
return;
}
$.ajax( {
@ -291,7 +291,7 @@ workingHours.copy = function(){
} else {
alert( 'Ops, error! ' + data.error );
}
} );
} );
}
};

View File

@ -1,4 +1,4 @@
<? if (!count($this->settlement->restaurants)) : ?>
<? if (!count($this->restaurants)) : ?>
No restaurants with orders found
<? else : ?>
<div class='box'>
@ -8,7 +8,7 @@
<div style='padding:5px; border-bottom:1px solid #ccc;' >
<span style='display:inline-block;min-width:100px;'>Num Restaurants</span>&nbsp;&nbsp;
<span id='num_restaurants'>
<strong><?=count($this->settlement->restaurants) ?></strong>
<strong><?=count($this->restaurants) ?></strong>
</span>
</div>
<div style='padding:5px; border-bottom:1px solid #ccc;' >
@ -17,7 +17,7 @@
</div>
</div>
<? foreach($this->settlement->restaurants as $restaurant) : ?>
<? foreach($this->restaurants as $restaurant) : ?>
<? if (!$restaurant->payableOrders()->count()) :
continue;
endif ; ?>

View File

@ -0,0 +1,218 @@
<?
$this->title = 'Settlement';
$this->titleicon = 'money';
$this->titleLink = '/settlement';
$this->title2 = 'Test';
$this->title2icon = 'time';
?>
<div class="container-fluid padded">
<div class="row-fluid">
<div class="box">
<div class="box-header">
<span class="title">Math test</span>
</div>
<div class="box-content">
<ul class="box-list">
<li>
<label for="id_order"><strong>Order(s) #</strong></label>
<input type="text" name="id_order" value="24515, 24505, 24497, 24420, 24407" placeholder="24515, 24505, 24497, 24420, 24407" id="id_order" />
</li>
<li>
<button class="calc btn btn-blue"><i class="icon-cogs"></i>&nbsp;Calculate</button>
</li>
</ul>
</div>
</div>
</div>
</div>
<?php if( $this->pay ) {
$pay = $this->pay;
?>
<div class="container-fluid padded">
<div class="row-fluid">
<div class="box">
<div class="box-header">
<span class="title">Total Due</span>
</div>
<div class="box-content">
<table class="table table-normal">
<thead>
<tr>
<td>Description</td>
<td>Value</td>
<td>Formatted Value</td>
</tr>
</thead>
<tbody>
<tr>
<td>Credit Card Subtotal</td>
<td>
<?php echo $pay['card_subtotal']; ?>
</td>
<td>
<strong><?php echo Util::format_price( $pay['card_subtotal'] ); ?></strong>
</td>
</tr>
<tr>
<td>Cash Subtotal</td>
<td>
<?php echo $pay['cash_subtotal']; ?>
</td>
<td>
<strong><?php echo Util::format_price( $pay['cash_subtotal'] ); ?></strong>
</td>
</tr>
<tr>
<td>Tax</td>
<td>
<?php echo $pay['tax']; ?>
</td>
<td>
<strong><?php echo Util::format_price( $pay['tax'] ); ?></strong>
</td>
</tr>
<tr>
<td>Delivery Fee</td>
<td>
<?php echo $pay['delivery_fee']; ?>
</td>
<td>
<strong><?php echo Util::format_price( $pay['delivery_fee'] ); ?></strong>
</td>
</tr>
<tr>
<td>Tip</td>
<td>
<?php echo $pay['tip']; ?>
</td>
<td>
<strong><?php echo Util::format_price( $pay['tip'] ); ?></strong>
</td>
</tr>
<tr>
<td>Customer Fee</td>
<td>
<?php echo $pay['customer_fee']; ?>
</td>
<td>
<strong><?php echo Util::format_price( $pay['customer_fee'] ); ?></strong>
</td>
</tr>
<tr>
<td>Markup</td>
<td>
<?php echo $pay['markup']; ?>
</td>
<td>
<strong><?php echo Util::format_price( $pay['markup'] ); ?></strong>
</td>
</tr>
<tr>
<td>Credit Charge</td>
<td>
<?php echo $pay['credit_charge']; ?>
</td>
<td>
<strong><?php echo Util::format_price( $pay['credit_charge'] ); ?></strong>
</td>
</tr>
<tr>
<td>Restaurant Fee</td>
<td>
<?php echo $pay['restaurant_fee']; ?>
</td>
<td>
<strong><?php echo Util::format_price( $pay['restaurant_fee'] ); ?></strong>
</td>
</tr>
<tr>
<td>Promo Gift Card</td>
<td>
<?php echo $pay['promo_gift_card']; ?>
</td>
<td>
<strong><?php echo Util::format_price( $pay['promo_gift_card'] ); ?></strong>
</td>
</tr>
<tr>
<td>Apology Gift Card</td>
<td>
<?php echo $pay['apology_gift_card']; ?>
</td>
<td>
<strong><?php echo Util::format_price( $pay['apology_gift_card'] ); ?></strong>
</td>
</tr>
<tr style="background:#b3dc63;">
<td>Total Due</td>
<td>
<?php echo $pay['total_due']; ?>
</td>
<td>
<strong><?php echo Util::format_price( $pay['total_due'] ); ?></strong>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="container-fluid padded">
<div class="row-fluid">
<div class="box">
<div class="box-header">
<span class="title">Orders</span>
</div>
<div class="box-content">
<table class="table table-normal">
<thead>
<tr>
<td>Order #</td>
<td>Restaurant</td>
<td>Card</td>
<td>Cash</td>
<td>Tax</td>
<td>Delivery Fee</td>
<td>Tip</td>
<td>Credit Card Charge</td>
<td>Restaurant Fee</td>
</tr>
</thead>
<tbody>
<?php foreach( $this->orders as $order ) { ?>
<tr>
<td><?php echo $order->id_order; ?></td>
<td><?php echo $order->restaurant()->name; ?></td>
<td><?php echo $order->values[ 'subtotal_card' ]; ?></td>
<td><?php echo $order->values[ 'subtotal_cash' ]; ?></td>
<td><?php echo $order->values[ 'tax' ]; ?></td>
<td><?php echo $order->values[ 'delivery_fee' ]; ?></td>
<td><?php echo $order->values[ 'tip' ]; ?></td>
<td><?php echo $order->values[ 'card_charge' ]; ?></td>
<td><?php echo $order->values[ 'restaurant_fee' ]; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<?php } ?>
<script type="text/javascript">
$(document).ready( function(){
$( '.calc' ).on( 'click', function(){
if( $( '#id_order' ).val() ){
window.location.href = '/settlement/test/' + $( '#id_order' ).val();
} else {
alert( 'You need to type the id_order!' );
$( '#id_order' ).focus();
}
} );
} );
</script>

View File

@ -3,28 +3,131 @@
class SettlementTest extends PHPUnit_Framework_TestCase {
public function setUp() {
$this->orders_formal_relationship = [];
$this->orders_no_formal_relationship = [];
// values of id_order: 24515
$this->orders_formal_relationship[] = ['subtotal' => 12.48, 'tax' => 0.79, 'tip' => 2.25, 'delivery_fee' => 0, 'service_fee' => 0, 'customer_fee' => 0, 'customer_fee_percent' => 0, 'restaurant_fee_percent' => 10, 'delivery_service_markup' => 0, 'delivery_service_markup_value' => 0, 'id_admin' => 0, 'gift_card_total' => 0, 'gift_card_paid_by_crunchbutton' => 0, 'gift_card_paid_by_restaurant' => 0, 'gift_card_paid_by_promotional' => 0, 'gift_card_paid_by_other_restaurant' => 0, 'total_charged' => 15.52, 'promotion_maximum' => 2, 'max_apology_credit' => 5, 'credit' => 1, 'cash' => 0, 'charge_credit_fee' => 1, 'pay_credit_charge' => 1, 'pay_promotion' => 1, 'just_fee_on_subtotal' => 0, 'delivery_service' => 0, 'formal_relationship' => 1, 'paid_with_cb_card' => 0, 'refunded' => 0, 'pay_if_refunded' => 0];
// values of id_order: 24505
$this->orders_formal_relationship[] = ['subtotal' => 9.34, 'tax' => 0.59, 'tip' => 2, 'delivery_fee' => 0, 'service_fee' => 0, 'customer_fee' => 0, 'customer_fee_percent' => 0, 'restaurant_fee_percent' => 10, 'delivery_service_markup' => 0, 'delivery_service_markup_value' => 0, 'id_admin' => 0, 'gift_card_total' => 0, 'gift_card_paid_by_crunchbutton' => 0, 'gift_card_paid_by_restaurant' => 0, 'gift_card_paid_by_promotional' => 0, 'gift_card_paid_by_other_restaurant' => 0, 'total_charged' => 11.93, 'promotion_maximum' => 2, 'max_apology_credit' => 5, 'credit' => 1, 'cash' => 0, 'charge_credit_fee' => 1, 'pay_credit_charge' => 1, 'pay_promotion' => 1, 'just_fee_on_subtotal' => 0, 'delivery_service' => 0, 'formal_relationship' => 1, 'paid_with_cb_card' => 0, 'refunded' => 0, 'pay_if_refunded' => 0];
// values of id_order: 24497
$this->orders_formal_relationship[] = ['subtotal' => 8.99, 'tax' => 0.57, 'tip' => 0, 'delivery_fee' => 0, 'service_fee' => 0, 'customer_fee' => 0, 'customer_fee_percent' => 0, 'restaurant_fee_percent' => 10, 'delivery_service_markup' => 0, 'delivery_service_markup_value' => 0, 'id_admin' => 0, 'gift_card_total' => 0, 'gift_card_paid_by_crunchbutton' => 0, 'gift_card_paid_by_restaurant' => 0, 'gift_card_paid_by_promotional' => 0, 'gift_card_paid_by_other_restaurant' => 0, 'total_charged' => 9.56, 'promotion_maximum' => 2, 'max_apology_credit' => 5, 'credit' => 0, 'cash' => 1, 'charge_credit_fee' => 1, 'pay_credit_charge' => 1, 'pay_promotion' => 1, 'just_fee_on_subtotal' => 0, 'delivery_service' => 0, 'formal_relationship' => 1, 'paid_with_cb_card' => 0, 'refunded' => 0, 'pay_if_refunded' => 0];
// values of id_order: 24420
$this->orders_formal_relationship[] = ['subtotal' => 10.98, 'tax' => 0.7, 'tip' => 1.1, 'delivery_fee' => 0, 'service_fee' => 0, 'customer_fee' => 0, 'customer_fee_percent' => 0, 'restaurant_fee_percent' => 10, 'delivery_service_markup' => 0, 'delivery_service_markup_value' => 0, 'id_admin' => 0, 'gift_card_total' => 0, 'gift_card_paid_by_crunchbutton' => 0, 'gift_card_paid_by_restaurant' => 0, 'gift_card_paid_by_promotional' => 0, 'gift_card_paid_by_other_restaurant' => 0, 'total_charged' => 12.78, 'promotion_maximum' => 2, 'max_apology_credit' => 5, 'credit' => 1, 'cash' => 0, 'charge_credit_fee' => 1, 'pay_credit_charge' => 1, 'pay_promotion' => 1, 'just_fee_on_subtotal' => 0, 'delivery_service' => 0, 'formal_relationship' => 1, 'paid_with_cb_card' => 0, 'refunded' => 0, 'pay_if_refunded' => 0];
// values of id_order: 24407
$this->orders_formal_relationship[] = ['subtotal' => 8.99, 'tax' => 0.57, 'tip' => 1.35, 'delivery_fee' => 0, 'service_fee' => 0, 'customer_fee' => 0, 'customer_fee_percent' => 0, 'restaurant_fee_percent' => 10, 'delivery_service_markup' => 0, 'delivery_service_markup_value' => 0, 'id_admin' => 0, 'gift_card_total' => 0, 'gift_card_paid_by_crunchbutton' => 0, 'gift_card_paid_by_restaurant' => 0, 'gift_card_paid_by_promotional' => 0, 'gift_card_paid_by_other_restaurant' => 0, 'total_charged' => 10.91, 'promotion_maximum' => 2, 'max_apology_credit' => 5, 'credit' => 1, 'cash' => 0, 'charge_credit_fee' => 1, 'pay_credit_charge' => 1, 'pay_promotion' => 1, 'just_fee_on_subtotal' => 0, 'delivery_service' => 0, 'formal_relationship' => 1, 'paid_with_cb_card' => 0, 'refunded' => 0, 'pay_if_refunded' => 0];
// values of id_order: 24482
$this->orders_no_formal_relationship[] = ['subtotal' => 2.59, 'tax' => 0.23, 'tip' => 1.25, 'delivery_fee' => 3, 'service_fee' => 0, 'customer_fee' => 0, 'customer_fee_percent' => 0, 'restaurant_fee_percent' => 0, 'delivery_service_markup' => 20, 'delivery_service_markup_value' => 0.52, 'id_admin' => 205, 'gift_card_total' => 0, 'gift_card_paid_by_crunchbutton' => 0, 'gift_card_paid_by_restaurant' => 0, 'gift_card_paid_by_promotional' => 0, 'gift_card_paid_by_other_restaurant' => 0, 'total_charged' => 7.59, 'promotion_maximum' => 2, 'max_apology_credit' => 0, 'credit' => 1, 'cash' => 0, 'charge_credit_fee' => 1, 'pay_credit_charge' => 1, 'pay_promotion' => 1, 'just_fee_on_subtotal' => 0, 'delivery_service' => 1, 'formal_relationship' => 0, 'paid_with_cb_card' => 0, 'refunded' => 0, 'pay_if_refunded' => 0];
// values of id_order: 24459
$this->orders_no_formal_relationship[] = ['subtotal' => 11.46, 'tax' => 1.03, 'tip' => 2.5, 'delivery_fee' => 3, 'service_fee' => 0, 'customer_fee' => 0, 'customer_fee_percent' => 0, 'restaurant_fee_percent' => 0, 'delivery_service_markup' => 20, 'delivery_service_markup_value' => 2.3, 'id_admin' => 72, 'gift_card_total' => 0, 'gift_card_paid_by_crunchbutton' => 0, 'gift_card_paid_by_restaurant' => 0, 'gift_card_paid_by_promotional' => 0, 'gift_card_paid_by_other_restaurant' => 0, 'total_charged' => 20.29, 'promotion_maximum' => 2, 'max_apology_credit' => 0, 'credit' => 1, 'cash' => 0, 'charge_credit_fee' => 1, 'pay_credit_charge' => 1, 'pay_promotion' => 1, 'just_fee_on_subtotal' => 0, 'delivery_service' => 1, 'formal_relationship' => 0, 'paid_with_cb_card' => 0, 'refunded' => 0, 'pay_if_refunded' => 0];
$this->settlement = new Crunchbutton_Settlement;
// at first test the calcs using one order
$this->first_order = Order::o( 22763 );
$this->first_order_variables = $this->settlement->processOrder( $this->order );
}
public function testFirstOrder() {
// $this->first_order
// $this->order_variables
// orderSubtotalPayment
// $this->order_variables
$this->assertTrue(true);
public function testIndividualMathsCashOrderFormalRelationship() {
$order = $this->orders_formal_relationship[ 2 ];
$this->assertEquals( $this->settlement->orderCardSubtotalPayment( $order ), 0 );
$this->assertEquals( $this->settlement->orderTaxPayment( $order ), 0 );
$this->assertEquals( $this->settlement->orderDeliveryFeePayment( $order ), 0 );
$this->assertEquals( $this->settlement->orderTipPayment( $order ), 0 );
$this->assertEquals( $this->settlement->orderCustomerFeePayment( $order ), 0 );
$this->assertEquals( $this->settlement->orderMarkupPayment( $order ), 0 );
$this->assertEquals( $this->settlement->orderCreditChargePayment( $order ), 0 );
$this->assertEquals( $this->settlement->orderRestaurantFeePayment( $order ), -0.899 );
$this->assertEquals( $this->settlement->orderPromoGiftCardPayment( $order ), 0 );
$this->assertEquals( $this->settlement->orderApologyGiftCardPayment( $order ), 0 );
$this->assertEquals( $this->settlement->orderRestaurantOrderPayment( $order ), 0 );
$this->assertEquals( $this->settlement->orderCashSubtotalPayment( $order ), 9.56 );
}
public function tearDown() {
// neet to implement
public function testIndividualMathsCreditOrderFormalRelationship() {
$order = $this->orders_formal_relationship[ 0 ];
$this->assertEquals( $this->settlement->orderCardSubtotalPayment( $order ), 12.48 );
$this->assertEquals( $this->settlement->orderTaxPayment( $order ), 0.79 );
$this->assertEquals( $this->settlement->orderDeliveryFeePayment( $order ), 0 );
$this->assertEquals( $this->settlement->orderTipPayment( $order ), 2.25 );
$this->assertEquals( $this->settlement->orderCustomerFeePayment( $order ), 0 );
$this->assertEquals( $this->settlement->orderMarkupPayment( $order ), 0 );
$this->assertEquals( $this->settlement->orderCreditChargePayment( $order ), -0.75008 );
$this->assertEquals( $this->settlement->orderRestaurantFeePayment( $order ), -1.473 );
$this->assertEquals( $this->settlement->orderPromoGiftCardPayment( $order ), 0 );
$this->assertEquals( $this->settlement->orderApologyGiftCardPayment( $order ), 0 );
$this->assertEquals( $this->settlement->orderRestaurantOrderPayment( $order ), 15.52 );
$this->assertEquals( $this->settlement->orderCashSubtotalPayment( $order ), 0 );
}
public function testDueToPayFormalRelationship(){
$pay = $this->settlement->processOrders( $this->orders_formal_relationship );
$this->assertEquals( $pay[ 'card_subtotal' ], 41.79 );
$this->assertEquals( $pay[ 'tax' ], 2.65 );
$this->assertEquals( $pay[ 'delivery_fee' ], 0 );
$this->assertEquals( $pay[ 'tip' ], 6.7 );
$this->assertEquals( $pay[ 'customer_fee' ], 0 );
$this->assertEquals( $pay[ 'markup' ], 0 );
$this->assertEquals( $pay[ 'credit_charge' ], -2.68306 );
$this->assertEquals( $pay[ 'restaurant_fee' ], -5.748 );
$this->assertEquals( $pay[ 'promo_gift_card' ], 0 );
$this->assertEquals( $pay[ 'apology_gift_card' ], 0 );
$this->assertEquals( $pay[ 'order_payment' ], 51.14 );
$this->assertEquals( $pay[ 'cash_subtotal' ], 9.56 );
$this->assertEquals( $pay[ 'formal_relationship' ], 1 );
$this->assertEquals( $pay[ 'total_due' ], 42.70894 );
}
public function testIndividualMathsCashOrderNoFormalRelationship() {
// values of id_order: 24419
$order = ['subtotal' => 11.1, 'tax' => 0.83, 'tip' => 0, 'delivery_fee' => 2, 'service_fee' => 0, 'customer_fee' => 0, 'customer_fee_percent' => 0, 'restaurant_fee_percent' => 0, 'delivery_service_markup' => 20, 'delivery_service_markup_value' => 2.22, 'id_admin' => 209, 'gift_card_total' => 0, 'gift_card_paid_by_crunchbutton' => 0, 'gift_card_paid_by_restaurant' => 0, 'gift_card_paid_by_promotional' => 0, 'gift_card_paid_by_other_restaurant' => 0, 'total_charged' => 16.15, 'promotion_maximum' => 2, 'max_apology_credit' => 0, 'credit' => 0, 'cash' => 1, 'charge_credit_fee' => 1, 'pay_credit_charge' => 1, 'pay_promotion' => 1, 'just_fee_on_subtotal' => 0, 'delivery_service' => 1, 'formal_relationship' => 0, 'paid_with_cb_card' => 0, 'refunded' => 0, 'pay_if_refunded' => 0];
$this->assertEquals( $this->settlement->orderCardSubtotalPayment( $order ), 0 );
$this->assertEquals( $this->settlement->orderTaxPayment( $order ), 0 );
$this->assertEquals( $this->settlement->orderDeliveryFeePayment( $order ), 0 );
$this->assertEquals( $this->settlement->orderTipPayment( $order ), 0 );
$this->assertEquals( $this->settlement->orderCustomerFeePayment( $order ), 0 );
$this->assertEquals( $this->settlement->orderMarkupPayment( $order ), 0 );
$this->assertEquals( $this->settlement->orderCreditChargePayment( $order ), 0 );
$this->assertEquals( $this->settlement->orderRestaurantFeePayment( $order ), 0 );
$this->assertEquals( $this->settlement->orderPromoGiftCardPayment( $order ), 0 );
$this->assertEquals( $this->settlement->orderApologyGiftCardPayment( $order ), 0 );
$this->assertEquals( $this->settlement->orderRestaurantOrderPayment( $order ), 0 );
$this->assertEquals( $this->settlement->orderCashSubtotalPayment( $order ), 11.93 );
}
public function testIndividualMathsCreditOrderNoFormalRelationship() {
$order = $this->orders_no_formal_relationship[ 0 ];
$this->assertEquals( $this->settlement->orderCardSubtotalPayment( $order ), 2.59 );
$this->assertEquals( $this->settlement->orderTaxPayment( $order ), 0.23 );
$this->assertEquals( $this->settlement->orderDeliveryFeePayment( $order ), 0 );
$this->assertEquals( $this->settlement->orderTipPayment( $order ), 0 );
$this->assertEquals( $this->settlement->orderCustomerFeePayment( $order ), 0 );
$this->assertEquals( $this->settlement->orderMarkupPayment( $order ), 0 );
$this->assertEquals( $this->settlement->orderCreditChargePayment( $order ), -0.52011 );
$this->assertEquals( $this->settlement->orderRestaurantFeePayment( $order ), 0 );
$this->assertEquals( $this->settlement->orderPromoGiftCardPayment( $order ), 0 );
$this->assertEquals( $this->settlement->orderApologyGiftCardPayment( $order ), 0 );
$this->assertEquals( $this->settlement->orderRestaurantOrderPayment( $order ), 2.82 );
$this->assertEquals( $this->settlement->orderCashSubtotalPayment( $order ), 0 );
}
public function testDueToPayNoFormalRelationship(){
$pay = $this->settlement->processOrders( $this->orders_no_formal_relationship );
$this->assertEquals( $pay[ 'card_subtotal' ], 14.05 );
$this->assertEquals( $pay[ 'tax' ], 1.26 );
$this->assertEquals( $pay[ 'delivery_fee' ], 0 );
$this->assertEquals( $pay[ 'tip' ], 0 );
$this->assertEquals( $pay[ 'customer_fee' ], 0 );
$this->assertEquals( $pay[ 'markup' ], 0 );
$this->assertEquals( $pay[ 'credit_charge' ], -1.40852 );
$this->assertEquals( $pay[ 'restaurant_fee' ], 0 );
$this->assertEquals( $pay[ 'promo_gift_card' ], 0 );
$this->assertEquals( $pay[ 'apology_gift_card' ], 0 );
$this->assertEquals( $pay[ 'order_payment' ], 15.31 );
$this->assertEquals( $pay[ 'cash_subtotal' ], 0 );
$this->assertEquals( $pay[ 'formal_relationship' ], 0 );
$this->assertEquals( $pay[ 'total_due' ], 0 );
}
public function tearDown() {}
}