From f95f05d0fe36df3ba71c8dbbfe768cb277925704 Mon Sep 17 00:00:00 2001
From: Daniel Camargo
Date: Wed, 11 Jun 2014 18:19:48 -0300
Subject: [PATCH] Settlement: implement additional payment math in
Settlement.php #2250 - cockpit 3
---
.../default/cockpit2/api/settlement/index.php | 31 ++++-
include/library/Crunchbutton/Payment.php | 9 +-
.../cockpit2/frontend/settlement.phtml | 120 +++++++++++++++++-
.../cockpit/js/controllers.settlement.js | 19 ++-
www/assets/cockpit/js/service.settlement.js | 2 +-
5 files changed, 167 insertions(+), 14 deletions(-)
diff --git a/include/controllers/default/cockpit2/api/settlement/index.php b/include/controllers/default/cockpit2/api/settlement/index.php
index 66b6a3125..1f06c06c6 100644
--- a/include/controllers/default/cockpit2/api/settlement/index.php
+++ b/include/controllers/default/cockpit2/api/settlement/index.php
@@ -44,11 +44,24 @@ class Controller_api_settlement extends Crunchbutton_Controller_RestAccount {
$settlement = new Settlement( [ 'payment_method' => $pay_type, 'start' => $start, 'end' => $end ] );
$restaurants = $settlement->start();
- $out = [];
+ $out = [ 'restaurants' => [] ];
+ $total_restaurants = 0;
+ $total_payments = 0;
+ $total_orders = 0;
foreach ( $restaurants as $_restaurant ) {
- $restaurant = [];
+ $restaurant = $_restaurant->payment_data;
+ $lastPayment = $_restaurant->getLastPayment();
+ if( $lastPayment->id_payment ){
+ $_lastPayment = [];
+ $_lastPayment[ 'amount' ] = $lastPayment->amount;
+ $_lastPayment[ 'date' ] = $lastPayment->date()->format( 'M jS Y g:i:s A' );
+ $_lastPayment[ 'id_payment' ] = $lastPayment->id_payment;
+ $restaurant[ 'last_payment' ] = $_lastPayment;
+ }
+
$restaurant[ 'name' ] = $_restaurant->name;
- $restaurant[ 'pay_info' ] = $_restaurant->payment_data;
+ $restaurant[ 'id_restaurant' ] = $_restaurant->id_restaurant;
+
$orders = [];
foreach ( $_restaurant->_payableOrders as $_order ) {
$order = [];
@@ -56,13 +69,21 @@ class Controller_api_settlement extends Crunchbutton_Controller_RestAccount {
$order[ 'name' ] = $_order->name;
$order[ 'total' ] = $_order->final_price_plus_delivery_markup;
$date = $_order->date();
- $order[ 'date' ] = $date->format( 'm/d/Y' );
+ $order[ 'date' ] = $date->format( 'M jS Y g:i:s A' );
$orders[] = $order;
}
$restaurant[ 'orders' ] = $orders;
$restaurant[ 'orders_count' ] = count( $orders );
- $out[] = $restaurant;
+ if( floatval( $restaurant[ 'total_due' ] ) > 0 ){
+ $out[ 'restaurants' ][] = $restaurant;
+ $total_restaurants++;
+ $total_orders += count( $orders );
+ $total_payments += $restaurant[ 'total_due' ];
+ }
}
+ $out[ 'total_restaurants' ] = $total_restaurants;
+ $out[ 'total_payments' ] = $total_payments;
+ $out[ 'total_orders' ] = $total_orders;
echo json_encode( $out );
}
diff --git a/include/library/Crunchbutton/Payment.php b/include/library/Crunchbutton/Payment.php
index f01729594..5fc221e07 100644
--- a/include/library/Crunchbutton/Payment.php
+++ b/include/library/Crunchbutton/Payment.php
@@ -44,7 +44,7 @@ class Crunchbutton_Payment extends Cana_Table {
}
}
-
+
public function infoLink(){
if( $this->type() == 'stripe' ){
return '' . $this->stripe_id . '';
@@ -58,6 +58,13 @@ class Crunchbutton_Payment extends Cana_Table {
return Restaurant::o($this->id_restaurant);
}
+ public function date() {
+ if (!isset($this->_date)) {
+ $this->_date = new DateTime( $this->date, new DateTimeZone( c::config()->timezone ) );
+ }
+ return $this->_date;
+ }
+
public function type(){
if( $this->stripe_id ){
return 'stripe';
diff --git a/include/views/default/cockpit2/frontend/settlement.phtml b/include/views/default/cockpit2/frontend/settlement.phtml
index 78fca74bf..5364aba3a 100644
--- a/include/views/default/cockpit2/frontend/settlement.phtml
+++ b/include/views/default/cockpit2/frontend/settlement.phtml
@@ -70,8 +70,126 @@
+
+
+
+ {{restaurant.name}}
+
+
+ Last payment #{{restaurant.last_payment.id_payment}}: $ {{restaurant.last_payment.amount | formatPrice}} on {{restaurant.last_payment.date}}
+
+
+
+
+ |
+ Tax
+ |
+
+ $ {{restaurant.tax | formatPrice}}
+ |
+
+
+ |
+ Delivery Fee
+ |
+
+ $ {{restaurant.delivery_fee | formatPrice}}
+ |
+
+
+ |
+ Tip
+ |
+
+ $ {{restaurant.tip | formatPrice}}
+ |
+
+
+ |
+ Promo Gift Card
+ |
+
+ $ {{restaurant.promo_gift_card | formatPrice}}
+ |
+
+
+ |
+ Apology Gift Card
+ |
+
+ $ {{restaurant.apology_gift_card | formatPrice}}
+ |
+
+
+ |
+ Credit Card Subtotal
+ |
+
+ $ {{restaurant.card_subtotal | formatPrice}}
+ |
+
+
+ |
+ Cash Subtotal
+ |
+
+ $ {{restaurant.cash_subtotal | formatPrice}}
+ |
+
+
+ |
+ Credit Card Charge
+ |
+
+ $ {{restaurant.credit_charge | formatPrice}}
+ |
+
+
+ |
+ Total due
+ |
+
+ $ {{restaurant.total_due | formatPrice}}
+ |
+
+
+
-
+
Show orders (total {{restaurant.orders_count}} orders )
+
Hide orders (total {{restaurant.orders_count}} orders )
+
+
+
+
+ | # |
+ Name |
+ Total |
+ Date |
+ |
+
+
+
+
+ |
+ {{order.id_order}}
+ |
+
+ {{order.name}}
+ |
+
+ $ {{order.total | formatPrice}}
+ |
+
+ {{order.date}}
+ |
+
+
+
+
+
+
+
+
diff --git a/www/assets/cockpit/js/controllers.settlement.js b/www/assets/cockpit/js/controllers.settlement.js
index da4ad3846..f30869702 100644
--- a/www/assets/cockpit/js/controllers.settlement.js
+++ b/www/assets/cockpit/js/controllers.settlement.js
@@ -1,4 +1,4 @@
-NGApp.controller('SettlementCtrl', function ( $scope, SettlementService ) {
+NGApp.controller('SettlementCtrl', function ( $scope, $filter, SettlementService ) {
$scope.ready = false;
$scope.pay_type = 'all';
@@ -21,12 +21,13 @@ NGApp.controller('SettlementCtrl', function ( $scope, SettlementService ) {
$scope.begin = function(){
+ $scope.results = false;
+
if( $scope.form.$invalid ){
$scope.submitted = true;
return;
}
-
for( x in $scope.pay_type_options ){
if( $scope.pay_type_options[ x ].value == $scope.pay_type ){
$scope.pay_type_label = $scope.pay_type_options[ x ].name;
@@ -42,10 +43,16 @@ NGApp.controller('SettlementCtrl', function ( $scope, SettlementService ) {
}
$scope.isSearching = true;
- $scope.showForm = false;
-// $filter('date')(date, format)
- $scope.start = $scope.range.start.formatted();
- $scope.end = $scope.range.end.formatted();
+
+ var params = { 'start': $filter( 'date' )( $scope.range.start, 'MM/dd/yyyy'),
+ 'end': $filter( 'date' )( $scope.range.end, 'MM/dd/yyyy'),
+ 'pay_type': $scope.pay_type };
+
+ SettlementService.begin( params, function( json ){
+ $scope.result = json;
+ console.log('$scope.result',$scope.result);
+ $scope.showForm = false;
+ } );
$scope.isSearching = false;
diff --git a/www/assets/cockpit/js/service.settlement.js b/www/assets/cockpit/js/service.settlement.js
index c85254acd..45aba808c 100644
--- a/www/assets/cockpit/js/service.settlement.js
+++ b/www/assets/cockpit/js/service.settlement.js
@@ -8,7 +8,7 @@ NGApp.factory( 'SettlementService', function( $rootScope, $resource ) {
} );
service.begin = function( params, callback ){
- drivers.begin( params, function( json ){
+ settlement.begin( params, function( json ){
callback( json );
} );
}