Merge branch 'refs/heads/Settlement'
This commit is contained in:
commit
05a7fdc006
@ -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;
|
|
||||||
@ -43,6 +43,12 @@ class Controller_api_settlement extends Crunchbutton_Controller_RestAccount {
|
|||||||
case 'begin':
|
case 'begin':
|
||||||
$this->_restaurantBegin();
|
$this->_restaurantBegin();
|
||||||
break;
|
break;
|
||||||
|
case 'restaurant':
|
||||||
|
$this->_restaurantBegin();
|
||||||
|
break;
|
||||||
|
case 'pay-if-refunded':
|
||||||
|
$this->_restaurantPayIfRefunded();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
$this->_error();
|
$this->_error();
|
||||||
break;
|
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(){
|
private function _restaurantBegin(){
|
||||||
|
|
||||||
$start = $this->request()['start'];
|
$start = $this->request()['start'];
|
||||||
$end = $this->request()['end'];
|
$end = $this->request()['end'];
|
||||||
|
$id_restaurant = $this->request()['id_restaurant'];
|
||||||
$pay_type = ( $this->request()['pay_type'] == 'all' ) ? '' : $this->request()['pay_type'];
|
$pay_type = ( $this->request()['pay_type'] == 'all' ) ? '' : $this->request()['pay_type'];
|
||||||
|
|
||||||
if( !$start || !$end ){
|
if( !$start || !$end ){
|
||||||
$this->_error();
|
$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();
|
$restaurants = $settlement->startRestaurant();
|
||||||
$out = [ 'restaurants' => [] ];
|
$out = [ 'restaurants' => [] ];
|
||||||
$total_restaurants = 0;
|
|
||||||
$total_payments = 0;
|
|
||||||
$total_orders = 0;
|
|
||||||
foreach ( $restaurants as $_restaurant ) {
|
foreach ( $restaurants as $_restaurant ) {
|
||||||
$restaurant = $_restaurant->payment_data;
|
$restaurant = $_restaurant->payment_data;
|
||||||
$lastPayment = $_restaurant->getLastPayment();
|
$lastPayment = $_restaurant->getLastPayment();
|
||||||
@ -92,23 +105,34 @@ class Controller_api_settlement extends Crunchbutton_Controller_RestAccount {
|
|||||||
$_lastPayment[ 'id_payment' ] = $lastPayment->id_payment;
|
$_lastPayment[ 'id_payment' ] = $lastPayment->id_payment;
|
||||||
$restaurant[ 'last_payment' ] = $_lastPayment;
|
$restaurant[ 'last_payment' ] = $_lastPayment;
|
||||||
}
|
}
|
||||||
|
|
||||||
$restaurant[ 'name' ] = $_restaurant->name;
|
$restaurant[ 'name' ] = $_restaurant->name;
|
||||||
$restaurant[ 'id_restaurant' ] = $_restaurant->id_restaurant;
|
$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 = [];
|
$orders = [];
|
||||||
foreach ( $_restaurant->_payableOrders as $_order ) {
|
foreach ( $_restaurant->_payableOrders as $_order ) {
|
||||||
$order = [];
|
$order = [];
|
||||||
$order[ 'id_order' ] = $_order->id_order;
|
$order[ 'id_order' ] = $_order->id_order;
|
||||||
$order[ 'name' ] = $_order->name;
|
$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;
|
$order[ 'total' ] = $_order->final_price_plus_delivery_markup;
|
||||||
$date = $_order->date();
|
$date = $_order->date();
|
||||||
$order[ 'date' ] = $date->format( 'M jS Y g:i:s A' );
|
$order[ 'date' ] = $date->format( 'M jS Y g:i:s A' );
|
||||||
$orders[] = $order;
|
$orders[] = $order;
|
||||||
|
$restaurant[ 'orders_count' ]++;
|
||||||
}
|
}
|
||||||
|
$restaurant[ 'pay' ] = true;
|
||||||
$restaurant[ 'orders' ] = $orders;
|
$restaurant[ 'orders' ] = $orders;
|
||||||
$restaurant[ 'orders_count' ] = count( $orders );
|
|
||||||
if( floatval( $restaurant[ 'total_due' ] ) > 0 ){
|
if( floatval( $restaurant[ 'total_due' ] ) > 0 ){
|
||||||
$out[ 'restaurants' ][] = $restaurant;
|
$out[ 'restaurants' ][] = $restaurant;
|
||||||
$total_restaurants++;
|
$total_restaurants++;
|
||||||
@ -116,16 +140,13 @@ class Controller_api_settlement extends Crunchbutton_Controller_RestAccount {
|
|||||||
$total_payments += $restaurant[ 'total_due' ];
|
$total_payments += $restaurant[ 'total_due' ];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$out[ 'total_restaurants' ] = $total_restaurants;
|
|
||||||
$out[ 'total_payments' ] = $total_payments;
|
|
||||||
$out[ 'total_orders' ] = $total_orders;
|
|
||||||
echo json_encode( $out );
|
echo json_encode( $out );
|
||||||
}
|
}
|
||||||
|
|
||||||
private function _driverBegin(){
|
private function _driverBegin(){
|
||||||
|
|
||||||
$start = "05/10/2014"; //$this->request()['start'];
|
$start = $this->request()['start'];
|
||||||
$end = "05/17/2014"; // $this->request()['end'];
|
$end = $this->request()['end'];
|
||||||
$pay_type = ( $this->request()['pay_type'] == 'all' ) ? '' : $this->request()['pay_type'];
|
$pay_type = ( $this->request()['pay_type'] == 'all' ) ? '' : $this->request()['pay_type'];
|
||||||
|
|
||||||
if( !$start || !$end ){
|
if( !$start || !$end ){
|
||||||
@ -151,7 +172,7 @@ class Controller_api_settlement extends Crunchbutton_Controller_RestAccount {
|
|||||||
$_order[ 'id_order' ] = $order[ 'id_order' ];
|
$_order[ 'id_order' ] = $order[ 'id_order' ];
|
||||||
$_order[ 'name' ] = $order[ 'name' ];
|
$_order[ 'name' ] = $order[ 'name' ];
|
||||||
$_order[ 'restaurant' ] = $order[ 'restaurant' ];
|
$_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[ 'total' ] = $order[ 'final_price_plus_delivery_markup' ];
|
||||||
$_order[ 'date' ] = $order[ 'date' ];
|
$_order[ 'date' ] = $order[ 'date' ];
|
||||||
$driver[ 'orders' ][] = $_order;
|
$driver[ 'orders' ][] = $_order;
|
||||||
@ -169,9 +190,9 @@ class Controller_api_settlement extends Crunchbutton_Controller_RestAccount {
|
|||||||
|
|
||||||
private function _range(){
|
private function _range(){
|
||||||
$now = new DateTime( 'now', new DateTimeZone( c::config()->timezone ) );
|
$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' );
|
$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 );
|
echo json_encode( $range );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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
|
// 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 = []) {
|
public function payableOrders($filters = []) {
|
||||||
|
|
||||||
if (!isset($this->_payableOrders)) {
|
if (!isset($this->_payableOrders)) {
|
||||||
$q = '
|
$q = 'SELECT * FROM `order`
|
||||||
select * from `order`
|
WHERE id_restaurant="'.$this->id_restaurant.'"
|
||||||
where id_restaurant="'.$this->id_restaurant.'"
|
AND DATE(`date`) >= "' . (new DateTime($filters['start']))->format('Y-m-d') . '"
|
||||||
and DATE(`date`) >= "' . (new DateTime($filters['start']))->format('Y-m-d') . '"
|
AND DATE(`date`) <= "' . (new DateTime($filters['end']))->format('Y-m-d') . '"
|
||||||
and DATE(`date`) <= "' . (new DateTime($filters['end']))->format('Y-m-d') . '"
|
AND NAME NOT LIKE "%test%"
|
||||||
and name not like "%test%"
|
ORDER BY `pay_type` ASC, `date` ASC ';
|
||||||
order by `pay_type` asc, `date` asc ';
|
|
||||||
$orders = Order::q($q);
|
$orders = Order::q($q);
|
||||||
$this->_payableOrders = $orders;
|
$this->_payableOrders = $orders;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -46,12 +46,15 @@ class Crunchbutton_Settlement extends Cana_Model {
|
|||||||
FROM restaurant
|
FROM restaurant
|
||||||
LEFT OUTER JOIN ( SELECT id_restaurant, `date` FROM `payment` ) AS p using(id_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
|
INNER JOIN restaurant_payment_type rpt ON rpt.id_restaurant = restaurant.id_restaurant
|
||||||
WHERE active=1';
|
WHERE active=1 ';
|
||||||
if ($filters['payment_method']) {
|
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
|
$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';
|
ORDER BY (CASE WHEN p_id_rest IS NULL THEN 1 ELSE 0 END) ASC';
|
||||||
return Restaurant::q( $q );
|
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 ];
|
$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 ) {;
|
foreach ( $orders as $order ) {;
|
||||||
if( $order ){
|
if( $order ){
|
||||||
|
// Pay if Refunded
|
||||||
|
if( $order[ 'refunded' ] == 1 && $order[ 'pay_if_refunded' ] == 0 ){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$pay[ 'card_subtotal' ] += $this->orderCardSubtotalPayment( $order );
|
$pay[ 'card_subtotal' ] += $this->orderCardSubtotalPayment( $order );
|
||||||
$pay[ 'tax' ] += $this->orderTaxPayment( $order );
|
$pay[ 'tax' ] += $this->orderTaxPayment( $order );
|
||||||
$pay[ 'delivery_fee' ] += $this->orderDeliveryFeePayment( $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[ 'paid_with_cb_card' ] = ( $order->paid_with_cb_card > 0 ) ? 1: 0;
|
||||||
$values[ 'refunded' ] = ( $order->refunded > 0 ) ? 1: 0;
|
$values[ 'refunded' ] = ( $order->refunded > 0 ) ? 1: 0;
|
||||||
$values[ 'pay_if_refunded' ] = ( $order->pay_if_refunded > 0 ) ? 1: 0;
|
$values[ 'pay_if_refunded' ] = ( $order->pay_if_refunded > 0 ) ? 1: 0;
|
||||||
|
$values[ 'reimburse_cash_order' ] = ( $order->reimburse_cash_order > 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
|
// convert all to float -> mysql returns some values as string
|
||||||
foreach( $values as $key => $val ){
|
foreach( $values as $key => $val ){
|
||||||
|
|||||||
@ -23,8 +23,8 @@
|
|||||||
<div class="label">Date end:</div>
|
<div class="label">Date end:</div>
|
||||||
<div class="input"><input type="date" name="rangeEnd" ng-model="range.end" required placeholder=""></div>
|
<div class="input"><input type="date" name="rangeEnd" ng-model="range.end" required placeholder=""></div>
|
||||||
<div class="box-error">
|
<div class="box-error">
|
||||||
<small ng-show="form.rangeend.$error.required">Required.</small>
|
<small ng-show="form.rangeEnd.$error.required">Required.</small>
|
||||||
<small ng-show="form.rangeend.$error.date">Enter a valid end date!</small>
|
<small ng-show="form.rangeEnd.$error.date">Enter a valid end date!</small>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
<?php /*
|
<?php /*
|
||||||
|
|||||||
@ -23,11 +23,11 @@
|
|||||||
<div class="label">Date end:</div>
|
<div class="label">Date end:</div>
|
||||||
<div class="input"><input type="date" name="rangeEnd" ng-model="range.end" required placeholder=""></div>
|
<div class="input"><input type="date" name="rangeEnd" ng-model="range.end" required placeholder=""></div>
|
||||||
<div class="box-error">
|
<div class="box-error">
|
||||||
<small ng-show="form.rangeend.$error.required">Required.</small>
|
<small ng-show="form.rangeEnd.$error.required">Required.</small>
|
||||||
<small ng-show="form.rangeend.$error.date">Enter a valid end date!</small>
|
<small ng-show="form.rangeEnd.$error.date">Enter a valid end date!</small>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
<?php /*
|
|
||||||
<li class="li-input" ng-class="{'error':form.paymentType.$invalid}">
|
<li class="li-input" ng-class="{'error':form.paymentType.$invalid}">
|
||||||
<div class="label">Payment type:</div>
|
<div class="label">Payment type:</div>
|
||||||
<select name="paymentType" required ng-model="pay_type" ng-options="opt.value as opt.name for opt in pay_type_options" class="cart-customize-select"></select>
|
<select name="paymentType" required ng-model="pay_type" ng-options="opt.value as opt.name for opt in pay_type_options" class="cart-customize-select"></select>
|
||||||
@ -35,7 +35,7 @@
|
|||||||
<small ng-show="form.paymentType.$error.required">Required.</small>
|
<small ng-show="form.paymentType.$error.required">Required.</small>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
|
<?php /*
|
||||||
<li class="li-input" ng-class="{'error':form.sort.$invalid}">
|
<li class="li-input" ng-class="{'error':form.sort.$invalid}">
|
||||||
<div class="label">Sort by:</div>
|
<div class="label">Sort by:</div>
|
||||||
<select name="sort" required ng-model="sort" ng-options="opt.value as opt.name for opt in sort_options" class="cart-customize-select"></select>
|
<select name="sort" required ng-model="sort" ng-options="opt.value as opt.name for opt in sort_options" class="cart-customize-select"></select>
|
||||||
@ -58,7 +58,7 @@
|
|||||||
|
|
||||||
<div class="box-content" ng-show="!showForm">
|
<div class="box-content" ng-show="!showForm">
|
||||||
<p>
|
<p>
|
||||||
Listing orders from <strong>{{range.start | date:'MM/dd/yyyy'}}</strong> to <strong>{{range.end | date:'MM/dd/yyyy'}}</strong>.
|
Listing orders from <strong>{{range.start | date:'MM/dd/yyyy'}}</strong> to <strong>{{range.end | date:'MM/dd/yyyy'}}</strong> and payment method <strong>{{pay_type_label}}</strong>.
|
||||||
<br>
|
<br>
|
||||||
<span class="link" ng-click="showForm = true">Show form</span>
|
<span class="link" ng-click="showForm = true">Show form</span>
|
||||||
</p>
|
</p>
|
||||||
@ -75,15 +75,19 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Total Restaurants</td>
|
<td>Total Restaurants</td>
|
||||||
<td>{{result.total_restaurants}}</td>
|
<td>{{total_restaurants}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Total Orders</td>
|
<td>Total Orders</td>
|
||||||
<td>{{result.total_orders}}</td>
|
<td>{{total_orders}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr positive-or-negative-color="{{result.total_payments}}">
|
<tr>
|
||||||
|
<td>Total Orders Refunded (and not included)</td>
|
||||||
|
<td>{{total_not_included}}</td>
|
||||||
|
</tr>
|
||||||
|
<tr positive-or-negative-color="{{total_payments}}">
|
||||||
<td>Total Payments</td>
|
<td>Total Payments</td>
|
||||||
<td>$ {{result.total_payments | formatPrice}}</td>
|
<td>$ {{total_payments | formatPrice}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
@ -93,7 +97,7 @@
|
|||||||
|
|
||||||
<br/><br/><br/>
|
<br/><br/><br/>
|
||||||
|
|
||||||
<h2 class="title">
|
<h2 class="title" ng-class="{ 'excluded': !restaurant.pay }">
|
||||||
<span>{{restaurant.name}}</span>
|
<span>{{restaurant.name}}</span>
|
||||||
</h2>
|
</h2>
|
||||||
<h3 class="title" ng-if="restaurant.last_payment">
|
<h3 class="title" ng-if="restaurant.last_payment">
|
||||||
@ -137,29 +141,55 @@
|
|||||||
<td class="td-medium">Total due</td>
|
<td class="td-medium">Total due</td>
|
||||||
<td class="td-medium">$ {{restaurant.total_due | formatPrice}}</td>
|
<td class="td-medium">$ {{restaurant.total_due | formatPrice}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<td>
|
||||||
|
<span ng-click="restaurant.pay = !restaurant.pay;summary();">
|
||||||
|
<span ng-show="restaurant.pay">
|
||||||
|
<i class="fa fa-check-square-o"></i> <span class="link"><strong>Remove this restaurant from the payment? </strong></span>
|
||||||
|
</span>
|
||||||
|
<span ng-show="!restaurant.pay">
|
||||||
|
<i class="fa fa-square-o"></i> <span class="link"><strong>Include this restaurant at the payment? </strong></span>
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
<td></td>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<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">
|
||||||
<h3 class="title link" ng-if="restaurant.show_orders" ng-click="restaurant.show_orders = false">Hide orders (total {{restaurant.orders_count}} orders )</h3>
|
<span class="link" ng-if="!restaurant.show_orders" ng-click="restaurant.show_orders = true">Show orders</span>
|
||||||
|
<span class="link" ng-if="restaurant.show_orders" ng-click="restaurant.show_orders = false">Hide orders</span> (total {{restaurant.orders_count}} orders <span class="orange" ng-if="restaurant.refunded_count > 0"><strong> + {{restaurant.refunded_count}} </strong> refunded and not included order(s)</span> )
|
||||||
|
</h3>
|
||||||
|
|
||||||
<table class="tb-grid tb-zebra" ng-if="restaurant.show_orders">
|
<table class="tb-grid tb-zebra" ng-if="restaurant.show_orders">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
<td></td>
|
||||||
<td>#</td>
|
<td>#</td>
|
||||||
<td class="td-medium">Name</td>
|
<td class="td-medium">Name</td>
|
||||||
<td>Amount</td>
|
<td>Amount</td>
|
||||||
<td>Payment</td>
|
<td>Payment</td>
|
||||||
|
<td>Refunded</td>
|
||||||
|
<td></td>
|
||||||
<td class="td-medium">Date</td>
|
<td class="td-medium">Date</td>
|
||||||
<td></td>
|
<td></td>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr ng-repeat="order in restaurant.orders">
|
<tr ng-repeat="order in restaurant.orders" ng-class="{ 'excluded': !order.included }">
|
||||||
|
<td></td>
|
||||||
<td>{{order.id_order}}</td>
|
<td>{{order.id_order}}</td>
|
||||||
<td>{{order.name}}</td>
|
<td>{{order.name}}</td>
|
||||||
<td>$ {{order.total | formatPrice}}</td>
|
<td>$ {{order.total | formatPrice}}</td>
|
||||||
<td>{{order.pay_type}}</td>
|
<td>{{order.pay_type}}</td>
|
||||||
|
<td ng-class="{ 'refunded': order.refunded }">
|
||||||
|
<span ng-if="order.refunded">Refunded</span>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<span ng-if="order.refunded" ng-class="{ 'pay-if-refunded': order.pay_if_refunded }" class="pointer">
|
||||||
|
<i ng-click="pay_if_refunded( order.id_order, 0 )" ng-if="order.pay_if_refunded" class="fa fa-check-square-o"></i>
|
||||||
|
<i ng-click="pay_if_refunded( order.id_order, 1 )" ng-if="!order.pay_if_refunded" class="fa fa-square-o"></i>
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
<td>{{order.date}}</td>
|
<td>{{order.date}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
@ -21,6 +21,8 @@ NGApp.controller('SettlementRestaurantsCtrl', function ( $scope, $filter, Settle
|
|||||||
$scope.isSearching = false;
|
$scope.isSearching = false;
|
||||||
$scope.showForm = true;
|
$scope.showForm = true;
|
||||||
|
|
||||||
|
var id_restaurant = false;
|
||||||
|
|
||||||
$scope.pay_type_options = SettlementService.pay_type_options;
|
$scope.pay_type_options = SettlementService.pay_type_options;
|
||||||
$scope.sort_options = SettlementService.sort_options;
|
$scope.sort_options = SettlementService.sort_options;
|
||||||
|
|
||||||
@ -29,6 +31,24 @@ NGApp.controller('SettlementRestaurantsCtrl', function ( $scope, $filter, Settle
|
|||||||
if( json.start && json.end ){
|
if( json.start && json.end ){
|
||||||
$scope.range = { 'start' : new Date( json.start ), 'end' : new Date( json.end ) };
|
$scope.range = { 'start' : new Date( json.start ), 'end' : new Date( json.end ) };
|
||||||
$scope.ready = true;
|
$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;
|
$scope.isSearching = true;
|
||||||
|
|
||||||
var params = { 'start': $filter( 'date' )( $scope.range.start, 'MM/dd/yyyy'),
|
var params = { 'start': $filter( 'date' )( $scope.range.start, 'yyyy-MM-dd' ),
|
||||||
'end': $filter( 'date' )( $scope.range.end, 'MM/dd/yyyy'),
|
'end': $filter( 'date' )( $scope.range.end, 'yyyy-MM-dd' ),
|
||||||
'pay_type': $scope.pay_type };
|
'pay_type': $scope.pay_type };
|
||||||
|
|
||||||
|
if( id_restaurant ){
|
||||||
|
params.id_restaurant = id_restaurant;
|
||||||
|
}
|
||||||
|
|
||||||
SettlementService.restaurants.begin( params, function( json ){
|
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.showForm = false;
|
||||||
$scope.isSearching = 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
|
// Just run if the user is loggedin
|
||||||
if( $scope.account.isLoggedIn() ){
|
if( $scope.account.isLoggedIn() ){
|
||||||
range();
|
range();
|
||||||
|
|||||||
@ -9,11 +9,13 @@ NGApp.factory( 'SettlementService', function( $resource ) {
|
|||||||
settlement.restaurants = $resource( App.service + 'settlement/restaurants/:action/', { action: '@action' }, {
|
settlement.restaurants = $resource( App.service + 'settlement/restaurants/:action/', { action: '@action' }, {
|
||||||
'range' : { 'method': 'GET', params : { action: 'range' } },
|
'range' : { 'method': 'GET', params : { action: 'range' } },
|
||||||
'begin' : { 'method': 'POST', params : { action: 'begin' } },
|
'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' }, {
|
settlement.drivers = $resource( App.service + 'settlement/drivers/:action/', { action: '@action' }, {
|
||||||
'range' : { 'method': 'GET', params : { action: 'range' } },
|
'range' : { 'method': 'GET', params : { action: 'range' } },
|
||||||
'begin' : { 'method': 'POST', params : { action: 'begin' } },
|
'begin' : { 'method': 'POST', params : { action: 'begin' } }
|
||||||
} );
|
} );
|
||||||
|
|
||||||
service.restaurants.begin = function( params, callback ){
|
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 ){
|
service.restaurants.range = function( callback ){
|
||||||
settlement.restaurants.range( function( json ){
|
settlement.restaurants.range( function( json ){
|
||||||
callback( json );
|
callback( json );
|
||||||
|
|||||||
@ -759,6 +759,20 @@ input {
|
|||||||
.tb-zebra tr:nth-child(2n){
|
.tb-zebra tr:nth-child(2n){
|
||||||
background: #F5F5F5;
|
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 {
|
.tb-hack tbody {
|
||||||
width: 100% !important;
|
width: 100% !important;
|
||||||
}
|
}
|
||||||
@ -837,6 +851,12 @@ input {
|
|||||||
.link{
|
.link{
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
text-decoration: underline;
|
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{
|
.tb-grid .schedule-period{
|
||||||
font-weight:bold;
|
font-weight:bold;
|
||||||
@ -1517,3 +1537,6 @@ b, strong{ font-weight: bold; }
|
|||||||
color: #64763d;
|
color: #64763d;
|
||||||
border:1px solid #d6e9c6;
|
border:1px solid #d6e9c6;
|
||||||
}
|
}
|
||||||
|
.orange{
|
||||||
|
color: $orange;
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user