diff --git a/db/migrate/000195_payment.sql b/db/migrate/000194_payment.sql similarity index 100% rename from db/migrate/000195_payment.sql rename to db/migrate/000194_payment.sql diff --git a/db/migrate/000194_payment_order.sql b/db/migrate/000194_payment_order.sql deleted file mode 100644 index d6e42649c..000000000 --- a/db/migrate/000194_payment_order.sql +++ /dev/null @@ -1,10 +0,0 @@ -CREATE TABLE `payment_order` ( - `id_payment_order` int(11) unsigned NOT NULL AUTO_INCREMENT, - `id_payment` int(11) unsigned DEFAULT NULL, - `id_order` int(11) unsigned DEFAULT NULL, - PRIMARY KEY (`id_payment_order`), - KEY `id_payment` (`id_payment`), - KEY `id_order` (`id_order`), - CONSTRAINT `payment_order_ibfk_1` FOREIGN KEY (`id_payment`) REFERENCES `payment` (`id_payment`) ON DELETE SET NULL ON UPDATE SET NULL, - CONSTRAINT `payment_order_ibfk_2` FOREIGN KEY (`id_order`) REFERENCES `order` (`id_order`) ON DELETE SET NULL ON UPDATE SET NULL -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; \ No newline at end of file diff --git a/include/controllers/default/cockpit2/api/settlement/index.php b/include/controllers/default/cockpit2/api/settlement/index.php index 0c1561a8c..20691867b 100644 --- a/include/controllers/default/cockpit2/api/settlement/index.php +++ b/include/controllers/default/cockpit2/api/settlement/index.php @@ -43,6 +43,12 @@ class Controller_api_settlement extends Crunchbutton_Controller_RestAccount { case 'begin': $this->_restaurantBegin(); break; + case 'restaurant': + $this->_restaurantBegin(); + break; + case 'pay-if-refunded': + $this->_restaurantPayIfRefunded(); + break; default: $this->_error(); break; @@ -66,22 +72,29 @@ class Controller_api_settlement extends Crunchbutton_Controller_RestAccount { } } + private function _restaurantPayIfRefunded(){ + $id_order = $this->request()['id_order']; + $pay_if_refunded = $this->request()['pay_if_refunded']; + $order = Order::o( $id_order ); + $order->pay_if_refunded = ( intval( $pay_if_refunded ) > 0 ) ? 1 : 0; + $order->save(); + echo json_encode( [ 'id_order' => $order->id_order, 'id_restaurant' => $order->id_restaurant ] ); + } + private function _restaurantBegin(){ $start = $this->request()['start']; $end = $this->request()['end']; + $id_restaurant = $this->request()['id_restaurant']; $pay_type = ( $this->request()['pay_type'] == 'all' ) ? '' : $this->request()['pay_type']; if( !$start || !$end ){ $this->_error(); } - $settlement = new Settlement( [ 'payment_method' => $pay_type, 'start' => $start, 'end' => $end ] ); + $settlement = new Settlement( [ 'payment_method' => $pay_type, 'start' => $start, 'end' => $end, 'id_restaurant' => $id_restaurant ] ); $restaurants = $settlement->startRestaurant(); $out = [ 'restaurants' => [] ]; - $total_restaurants = 0; - $total_payments = 0; - $total_orders = 0; foreach ( $restaurants as $_restaurant ) { $restaurant = $_restaurant->payment_data; $lastPayment = $_restaurant->getLastPayment(); @@ -92,23 +105,34 @@ class Controller_api_settlement extends Crunchbutton_Controller_RestAccount { $_lastPayment[ 'id_payment' ] = $lastPayment->id_payment; $restaurant[ 'last_payment' ] = $_lastPayment; } - $restaurant[ 'name' ] = $_restaurant->name; $restaurant[ 'id_restaurant' ] = $_restaurant->id_restaurant; + $restaurant[ 'not_included' ] = 0; + $restaurant[ 'orders_count' ] = 0; + if( $id_restaurant && $id_restaurant == $restaurant[ 'id_restaurant' ] ){ + $restaurant[ 'show_orders' ] = true; + } $orders = []; foreach ( $_restaurant->_payableOrders as $_order ) { $order = []; $order[ 'id_order' ] = $_order->id_order; $order[ 'name' ] = $_order->name; - $order[ 'pay_type' ] = $_order->pay_type; + $order[ 'refunded' ] = ( $_order->refunded ) ? true : false; + $order[ 'pay_if_refunded' ] = ( $_order->pay_if_refunded ) ? true : false; + $order[ 'pay_type' ] = ucfirst( $_order->pay_type ); + $order[ 'included' ] = ( !$_order->refunded ) ? true : ( $_order->refunded && $_order->pay_if_refunded ) ? true : false; + if( !$order[ 'included' ] ){ + $restaurant[ 'not_included' ]++; + } $order[ 'total' ] = $_order->final_price_plus_delivery_markup; $date = $_order->date(); $order[ 'date' ] = $date->format( 'M jS Y g:i:s A' ); $orders[] = $order; + $restaurant[ 'orders_count' ]++; } + $restaurant[ 'pay' ] = true; $restaurant[ 'orders' ] = $orders; - $restaurant[ 'orders_count' ] = count( $orders ); if( floatval( $restaurant[ 'total_due' ] ) > 0 ){ $out[ 'restaurants' ][] = $restaurant; $total_restaurants++; @@ -116,16 +140,13 @@ class Controller_api_settlement extends Crunchbutton_Controller_RestAccount { $total_payments += $restaurant[ 'total_due' ]; } } - $out[ 'total_restaurants' ] = $total_restaurants; - $out[ 'total_payments' ] = $total_payments; - $out[ 'total_orders' ] = $total_orders; echo json_encode( $out ); } private function _driverBegin(){ - $start = "05/10/2014"; //$this->request()['start']; - $end = "05/17/2014"; // $this->request()['end']; + $start = $this->request()['start']; + $end = $this->request()['end']; $pay_type = ( $this->request()['pay_type'] == 'all' ) ? '' : $this->request()['pay_type']; if( !$start || !$end ){ @@ -151,7 +172,7 @@ class Controller_api_settlement extends Crunchbutton_Controller_RestAccount { $_order[ 'id_order' ] = $order[ 'id_order' ]; $_order[ 'name' ] = $order[ 'name' ]; $_order[ 'restaurant' ] = $order[ 'restaurant' ]; - $_order[ 'pay_type' ] = $order[ 'pay_type' ]; + $_order[ 'pay_type' ] = ucfirst( $order[ 'pay_type' ] ); $_order[ 'total' ] = $order[ 'final_price_plus_delivery_markup' ]; $_order[ 'date' ] = $order[ 'date' ]; $driver[ 'orders' ][] = $_order; @@ -169,9 +190,9 @@ class Controller_api_settlement extends Crunchbutton_Controller_RestAccount { private function _range(){ $now = new DateTime( 'now', new DateTimeZone( c::config()->timezone ) ); - $range = [ 'end' => $now->format( 'Y/m/d' ) ]; + $range = [ 'end' => '2014,05,10' /*$now->format( 'Y,m,d' ) */ ]; $now->modify( '-1 week' ); - $range[ 'start' ] = $now->format( 'Y/m/d' ); + $range[ 'start' ] = '2014,05,04' /*$now->format( 'Y,m,d' )*/; echo json_encode( $range ); } diff --git a/include/library/Cockpit/Restaurant.php b/include/library/Cockpit/Restaurant.php index 93eec68eb..213f31cdc 100644 --- a/include/library/Cockpit/Restaurant.php +++ b/include/library/Cockpit/Restaurant.php @@ -27,14 +27,14 @@ class Cockpit_Restaurant extends Crunchbutton_Restaurant { // get orders that are payable; not test, within our date range, it just return the order, the calc are made at settlement class public function payableOrders($filters = []) { + if (!isset($this->_payableOrders)) { - $q = ' - select * from `order` - where id_restaurant="'.$this->id_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 '; + $q = 'SELECT * FROM `order` + WHERE id_restaurant="'.$this->id_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 '; $orders = Order::q($q); $this->_payableOrders = $orders; } diff --git a/include/library/Crunchbutton/Settlement.php b/include/library/Crunchbutton/Settlement.php index 68fa1453a..aceb9e8be 100644 --- a/include/library/Crunchbutton/Settlement.php +++ b/include/library/Crunchbutton/Settlement.php @@ -46,12 +46,15 @@ class Crunchbutton_Settlement extends Cana_Model { FROM restaurant LEFT OUTER JOIN ( SELECT id_restaurant, `date` FROM `payment` ) AS p using(id_restaurant) INNER JOIN restaurant_payment_type rpt ON rpt.id_restaurant = restaurant.id_restaurant - WHERE active=1'; + WHERE active=1 '; if ($filters['payment_method']) { - $q .= ' AND `rpt.payment_method`="'.$filters['payment_method'].'" '; + $q .= ' AND rpt.payment_method = "'.$filters['payment_method']. '" '; + } + if( $filters[ 'id_restaurant' ] ){ + $q .= ' AND restaurant.id_restaurant = "' . $filters[ 'id_restaurant' ] . '"'; } $q .= ' AND restaurant.id_restaurant - GROUP BY id_restaurant + GROUP BY restaurant.id_restaurant ORDER BY (CASE WHEN p_id_rest IS NULL THEN 1 ELSE 0 END) ASC'; return Restaurant::q( $q ); } @@ -63,6 +66,10 @@ class Crunchbutton_Settlement extends Cana_Model { $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 ) {; if( $order ){ + // Pay if Refunded + if( $order[ 'refunded' ] == 1 && $order[ 'pay_if_refunded' ] == 0 ){ + continue; + } $pay[ 'card_subtotal' ] += $this->orderCardSubtotalPayment( $order ); $pay[ 'tax' ] += $this->orderTaxPayment( $order ); $pay[ 'delivery_fee' ] += $this->orderDeliveryFeePayment( $order ); @@ -326,11 +333,7 @@ class Crunchbutton_Settlement extends Cana_Model { $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; - } + $values[ 'reimburse_cash_order' ] = ( $order->reimburse_cash_order > 0 ) ? 1: 0; // convert all to float -> mysql returns some values as string foreach( $values as $key => $val ){ diff --git a/include/views/default/cockpit2/frontend/settlement-drivers.phtml b/include/views/default/cockpit2/frontend/settlement-drivers.phtml index 294268c0d..f4fd5df5d 100644 --- a/include/views/default/cockpit2/frontend/settlement-drivers.phtml +++ b/include/views/default/cockpit2/frontend/settlement-drivers.phtml @@ -23,8 +23,8 @@
Date end:
- Required. - Enter a valid end date! + Required. + Enter a valid end date!
Date end:
- Required. - Enter a valid end date! + Required. + Enter a valid end date!
-
Payment type:
@@ -35,7 +35,7 @@ Required. - +
Sort by:
@@ -58,7 +58,7 @@

- Listing orders from {{range.start | date:'MM/dd/yyyy'}} to {{range.end | date:'MM/dd/yyyy'}}. + Listing orders from {{range.start | date:'MM/dd/yyyy'}} to {{range.end | date:'MM/dd/yyyy'}} and payment method {{pay_type_label}}.
Show form

@@ -75,15 +75,19 @@ Total Restaurants - {{result.total_restaurants}} + {{total_restaurants}} Total Orders - {{result.total_orders}} + {{total_orders}} - + + Total Orders Refunded (and not included) + {{total_not_included}} + + Total Payments - $ {{result.total_payments | formatPrice}} + $ {{total_payments | formatPrice}} @@ -93,7 +97,7 @@


-

+

{{restaurant.name}}

@@ -137,29 +141,55 @@ Total due $ {{restaurant.total_due | formatPrice}} + + + + Remove this restaurant from the payment? + + + Include this restaurant at the payment? + + + + -

- +

+ Show orders + Hide orders (total {{restaurant.orders_count}} orders + {{restaurant.refunded_count}} refunded and not included order(s) ) +

+ + + - + + + + diff --git a/www/assets/cockpit/js/controllers.settlement.js b/www/assets/cockpit/js/controllers.settlement.js index afb13a490..8484e8c1f 100644 --- a/www/assets/cockpit/js/controllers.settlement.js +++ b/www/assets/cockpit/js/controllers.settlement.js @@ -21,6 +21,8 @@ NGApp.controller('SettlementRestaurantsCtrl', function ( $scope, $filter, Settle $scope.isSearching = false; $scope.showForm = true; + var id_restaurant = false; + $scope.pay_type_options = SettlementService.pay_type_options; $scope.sort_options = SettlementService.sort_options; @@ -29,6 +31,24 @@ NGApp.controller('SettlementRestaurantsCtrl', function ( $scope, $filter, Settle if( json.start && json.end ){ $scope.range = { 'start' : new Date( json.start ), 'end' : new Date( json.end ) }; $scope.ready = true; + // remove this before commit!!! + setTimeout(function() { + $scope.begin(); + }, 100 ); + } + } ); + } + + $scope.pay_if_refunded = function( id_order, pay_if_refunded ){ + $scope.makeBusy(); + var params = { 'id_order': id_order, 'pay_if_refunded' : pay_if_refunded }; + SettlementService.restaurants.pay_if_refunded( params, function( json ){ + id_restaurant = json.id_restaurant; + if( id_restaurant ){ + $scope.begin(); + } else { + App.alert( 'Oops, something bad happened!' ) + $scope.unBusy(); } } ); } @@ -58,17 +78,51 @@ NGApp.controller('SettlementRestaurantsCtrl', function ( $scope, $filter, Settle $scope.isSearching = true; - var params = { 'start': $filter( 'date' )( $scope.range.start, 'MM/dd/yyyy'), - 'end': $filter( 'date' )( $scope.range.end, 'MM/dd/yyyy'), + var params = { 'start': $filter( 'date' )( $scope.range.start, 'yyyy-MM-dd' ), + 'end': $filter( 'date' )( $scope.range.end, 'yyyy-MM-dd' ), 'pay_type': $scope.pay_type }; + if( id_restaurant ){ + params.id_restaurant = id_restaurant; + } + SettlementService.restaurants.begin( params, function( json ){ - $scope.result = json; + if( id_restaurant ){ + for( x in $scope.result.restaurants ){ + if( $scope.result.restaurants[ x ].id_restaurant == id_restaurant ){ + $scope.result.restaurants[ x ] = json.restaurants[ 0 ]; + break; + } + } + $scope.unBusy(); + } else { + $scope.result = json; + } $scope.showForm = false; $scope.isSearching = false; + $scope.summary(); } ); } + $scope.summary = function(){ + var total_restaurants = 0; + var total_payments = 0; + var total_orders = 0; + var total_not_included = 0; + for( x in $scope.result.restaurants ){ + if( $scope.result.restaurants[ x ].pay ){ + total_restaurants++; + total_payments += $scope.result.restaurants[ x ].total_due; + total_orders += $scope.result.restaurants[ x ].orders_count; + total_not_included += $scope.result.restaurants[ x ].not_included; + } + } + $scope.total_restaurants = total_restaurants; + $scope.total_payments = total_payments; + $scope.total_orders = total_orders; + $scope.total_not_included = total_not_included; + } + // Just run if the user is loggedin if( $scope.account.isLoggedIn() ){ range(); diff --git a/www/assets/cockpit/js/service.settlement.js b/www/assets/cockpit/js/service.settlement.js index 042f4e1a6..b35f1a17b 100644 --- a/www/assets/cockpit/js/service.settlement.js +++ b/www/assets/cockpit/js/service.settlement.js @@ -9,11 +9,13 @@ NGApp.factory( 'SettlementService', function( $resource ) { settlement.restaurants = $resource( App.service + 'settlement/restaurants/:action/', { action: '@action' }, { 'range' : { 'method': 'GET', params : { action: 'range' } }, 'begin' : { 'method': 'POST', params : { action: 'begin' } }, + 'restaurant' : { 'method': 'POST', params : { action: 'restaurant' } }, + 'pay_if_refunded' : { 'method': 'POST', params : { action: 'pay-if-refunded' } } } ); settlement.drivers = $resource( App.service + 'settlement/drivers/:action/', { action: '@action' }, { 'range' : { 'method': 'GET', params : { action: 'range' } }, - 'begin' : { 'method': 'POST', params : { action: 'begin' } }, + 'begin' : { 'method': 'POST', params : { action: 'begin' } } } ); service.restaurants.begin = function( params, callback ){ @@ -22,6 +24,12 @@ NGApp.factory( 'SettlementService', function( $resource ) { } ); } + service.restaurants.pay_if_refunded = function( params, callback ){ + settlement.restaurants.pay_if_refunded( params, function( json ){ + callback( json ); + } ); + } + service.restaurants.range = function( callback ){ settlement.restaurants.range( function( json ){ callback( json ); diff --git a/www/assets/cockpit/scss/cockpit.scss b/www/assets/cockpit/scss/cockpit.scss index e6a53f4d6..f726620a0 100644 --- a/www/assets/cockpit/scss/cockpit.scss +++ b/www/assets/cockpit/scss/cockpit.scss @@ -759,6 +759,20 @@ input { .tb-zebra tr:nth-child(2n){ background: #F5F5F5; } + + .tb-zebra .not-included { + color: #CCC; + font-style: italic; + } + .excluded{ + text-decoration: line-through; + } + .tb-zebra .refunded{ + color:$orange; + font-style: normal; + text-decoration: none !important; + } + .tb-hack tbody { width: 100% !important; } @@ -837,6 +851,12 @@ input { .link{ cursor: pointer; text-decoration: underline; + -webkit-touch-callout: none; + -webkit-user-select: none; + -khtml-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; } .tb-grid .schedule-period{ font-weight:bold; @@ -1517,3 +1537,6 @@ b, strong{ font-weight: bold; } color: #64763d; border:1px solid #d6e9c6; } +.orange{ + color: $orange; +}
# Name Amount PaymentRefunded Date
{{order.id_order}} {{order.name}} $ {{order.total | formatPrice}} {{order.pay_type}} + Refunded + + + + + + {{order.date}}