diff --git a/include/controllers/default/cockpit/settlement/begin.php b/include/controllers/default/cockpit/settlement/begin.php
index fc305ba2e..1ac081625 100644
--- a/include/controllers/default/cockpit/settlement/begin.php
+++ b/include/controllers/default/cockpit/settlement/begin.php
@@ -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');
diff --git a/include/controllers/default/cockpit/settlement/test.php b/include/controllers/default/cockpit/settlement/test.php
new file mode 100644
index 000000000..c911fa926
--- /dev/null
+++ b/include/controllers/default/cockpit/settlement/test.php
@@ -0,0 +1,45 @@
+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 '
';var_dump( c::view()->pay );exit();
+ }
+ }
+ c::view()->display('settlement/test');
+ }
+}
diff --git a/include/library/Cockpit/Restaurant.php b/include/library/Cockpit/Restaurant.php
index a2bbc84de..b5b53f26e 100644
--- a/include/library/Cockpit/Restaurant.php
+++ b/include/library/Cockpit/Restaurant.php
@@ -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;
}
diff --git a/include/library/Crunchbutton/Settlement.php b/include/library/Crunchbutton/Settlement.php
index d7d1ff51e..2c1c031eb 100644
--- a/include/library/Crunchbutton/Settlement.php
+++ b/include/library/Crunchbutton/Settlement.php
@@ -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;
- }
-
-********************************************/
\ No newline at end of file
diff --git a/include/views/default/cockpit/drivers/hours/index.phtml b/include/views/default/cockpit/drivers/hours/index.phtml
index b1b6554e1..7b31f599d 100644
--- a/include/views/default/cockpit/drivers/hours/index.phtml
+++ b/include/views/default/cockpit/drivers/hours/index.phtml
@@ -27,7 +27,7 @@
- days as $day ) {
+ days as $day ) {
$dark = ( $day->format( 'N' ) == 7 || $day->format( 'N' ) % 2 == 0 ) ? '#F5F5F5' : '';
?>
|
@@ -43,7 +43,7 @@
|
- days as $day ) {
+ days as $day ) {
$dark = ( $day->format( 'N' ) == 7 || $day->format( 'N' ) % 2 == 0 ) ? '#F5F5F5' : '';
?>
|
@@ -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 @@
+ ?>
|
-
+
@@ -177,12 +177,12 @@ workingHours.toggleTimezone = function(){
reps as $rep ) { ?>
- timezone ) ); ?>
+ timezone ) ); ?>
workingHours.admin_tzs[ 'id_admin ?>' ] = 'timezone ?> (format( 'T' ); ?>)';
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( '
' + workingHours.admin_tz + '' );
};
@@ -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 );
}
- } );
+ } );
}
};
diff --git a/include/views/default/cockpit/settlement/begin.phtml b/include/views/default/cockpit/settlement/begin.phtml
index 99a1f2f37..35997cf07 100644
--- a/include/views/default/cockpit/settlement/begin.phtml
+++ b/include/views/default/cockpit/settlement/begin.phtml
@@ -1,4 +1,4 @@
- if (!count($this->settlement->restaurants)) : ?>
+ if (!count($this->restaurants)) : ?>
No restaurants with orders found
else : ?>
@@ -8,7 +8,7 @@
Num Restaurants
- =count($this->settlement->restaurants) ?>
+ =count($this->restaurants) ?>
@@ -17,7 +17,7 @@
- foreach($this->settlement->restaurants as $restaurant) : ?>
+ foreach($this->restaurants as $restaurant) : ?>
if (!$restaurant->payableOrders()->count()) :
continue;
endif ; ?>
diff --git a/include/views/default/cockpit/settlement/test.phtml b/include/views/default/cockpit/settlement/test.phtml
new file mode 100644
index 000000000..69ba1adee
--- /dev/null
+++ b/include/views/default/cockpit/settlement/test.phtml
@@ -0,0 +1,218 @@
+
+ $this->title = 'Settlement';
+ $this->titleicon = 'money';
+ $this->titleLink = '/settlement';
+ $this->title2 = 'Test';
+ $this->title2icon = 'time';
+?>
+
+pay ) {
+ $pay = $this->pay;
+ ?>
+
+
+
+
+
+
+
+
+ | Description |
+ Value |
+ Formatted Value |
+
+
+
+
+ | Credit Card Subtotal |
+
+
+ |
+
+
+ |
+
+
+ | Cash Subtotal |
+
+
+ |
+
+
+ |
+
+
+ | Tax |
+
+
+ |
+
+
+ |
+
+
+ | Delivery Fee |
+
+
+ |
+
+
+ |
+
+
+ | Tip |
+
+
+ |
+
+
+ |
+
+
+ | Customer Fee |
+
+
+ |
+
+
+ |
+
+
+ | Markup |
+
+
+ |
+
+
+ |
+
+
+ | Credit Charge |
+
+
+ |
+
+
+ |
+
+
+ | Restaurant Fee |
+
+
+ |
+
+
+ |
+
+
+ | Promo Gift Card |
+
+
+ |
+
+
+ |
+
+
+ | Apology Gift Card |
+
+
+ |
+
+
+ |
+
+
+ | Total Due |
+
+
+ |
+
+
+ |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ | Order # |
+ Restaurant |
+ Card |
+ Cash |
+ Tax |
+ Delivery Fee |
+ Tip |
+ Credit Card Charge |
+ Restaurant Fee |
+
+
+
+
+ orders as $order ) { ?>
+
+ | id_order; ?> |
+ restaurant()->name; ?> |
+ values[ 'subtotal_card' ]; ?> |
+ values[ 'subtotal_cash' ]; ?> |
+ values[ 'tax' ]; ?> |
+ values[ 'delivery_fee' ]; ?> |
+ values[ 'tip' ]; ?> |
+ values[ 'card_charge' ]; ?> |
+ values[ 'restaurant_fee' ]; ?> |
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/travis/Tests/SettlementTest.php b/travis/Tests/SettlementTest.php
index ed43f85e9..141a23599 100644
--- a/travis/Tests/SettlementTest.php
+++ b/travis/Tests/SettlementTest.php
@@ -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() {}
+
}