Settlement: implement additional payment math in Settlement.php #2250 - cockpit 3
This commit is contained in:
parent
b90ef3c9d1
commit
f95f05d0fe
@ -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 );
|
||||
}
|
||||
|
||||
|
||||
@ -44,7 +44,7 @@ class Crunchbutton_Payment extends Cana_Table {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function infoLink(){
|
||||
if( $this->type() == 'stripe' ){
|
||||
return '<a href="https://manage.stripe.com/transfers/' . $this->stripe_id . '">' . $this->stripe_id . '</a>';
|
||||
@ -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';
|
||||
|
||||
@ -70,8 +70,126 @@
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div ng-if="result">
|
||||
<div ng-repeat="restaurant in result.restaurants">
|
||||
<h2 class="title">
|
||||
<span>{{restaurant.name}}</span>
|
||||
</h2>
|
||||
<h3 class="title" ng-if="restaurant.last_payment">
|
||||
Last payment #{{restaurant.last_payment.id_payment}}: <strong>$ {{restaurant.last_payment.amount | formatPrice}}</strong> on <strong>{{restaurant.last_payment.date}}</strong>
|
||||
</h3>
|
||||
<table class="tb-grid">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<strong>Tax</strong>
|
||||
</td>
|
||||
<td>
|
||||
<span>$ {{restaurant.tax | formatPrice}}</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<strong>Delivery Fee</strong>
|
||||
</td>
|
||||
<td>
|
||||
<span>$ {{restaurant.delivery_fee | formatPrice}}</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<strong>Tip</strong>
|
||||
</td>
|
||||
<td>
|
||||
<span>$ {{restaurant.tip | formatPrice}}</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<strong>Promo Gift Card</strong>
|
||||
</td>
|
||||
<td>
|
||||
<span>$ {{restaurant.promo_gift_card | formatPrice}}</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<strong>Apology Gift Card</strong>
|
||||
</td>
|
||||
<td>
|
||||
<span>$ {{restaurant.apology_gift_card | formatPrice}}</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<strong>Credit Card Subtotal</strong>
|
||||
</td>
|
||||
<td>
|
||||
<span>$ {{restaurant.card_subtotal | formatPrice}}</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<strong>Cash Subtotal</strong>
|
||||
</td>
|
||||
<td>
|
||||
<span>$ {{restaurant.cash_subtotal | formatPrice}}</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<strong>Credit Card Charge</strong>
|
||||
</td>
|
||||
<td>
|
||||
<span>$ {{restaurant.credit_charge | formatPrice}}</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="td-medium">
|
||||
<strong>Total due</strong>
|
||||
</td>
|
||||
<td class="td-medium">
|
||||
<span>$ {{restaurant.total_due | formatPrice}}</span>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div>
|
||||
<h3 class="title link" ng-if="!restaurant.show_orders" ng-click="restaurant.show_orders = true">Show orders (total {{restaurant.orders_count}} orders )</h3>
|
||||
<h3 class="title link" ng-if="restaurant.show_orders" ng-click="restaurant.show_orders = false">Hide orders (total {{restaurant.orders_count}} orders )</h3>
|
||||
|
||||
<table class="tb-grid" ng-if="restaurant.show_orders">
|
||||
<thead>
|
||||
<tr>
|
||||
<td>#</td>
|
||||
<td class="td-medium">Name</td>
|
||||
<td class="td-medium">Total</td>
|
||||
<td class="td-medium">Date</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr ng-repeat="order in restaurant.orders">
|
||||
<td>
|
||||
{{order.id_order}}
|
||||
</td>
|
||||
<td>
|
||||
{{order.name}}
|
||||
</td>
|
||||
<td>
|
||||
$ {{order.total | formatPrice}}
|
||||
</td>
|
||||
<td>
|
||||
{{order.date}}
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
|
||||
<hr/>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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 );
|
||||
} );
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user