partial #2033 - Calculate paying delivery drivers
This commit is contained in:
parent
9cc150b5f7
commit
637a8acbd1
@ -136,6 +136,11 @@ class Controller_home_charts extends Crunchbutton_Controller_Account {
|
|||||||
$info = $chart->getChartInfo( $this->chartId );
|
$info = $chart->getChartInfo( $this->chartId );
|
||||||
if( $info ){ $this->process( $info, $chart ); exit; }
|
if( $info ){ $this->process( $info, $chart ); exit; }
|
||||||
|
|
||||||
|
// Check if it is an Order card chart
|
||||||
|
$chart = new Crunchbutton_Chart_DeliveryFeeTips();
|
||||||
|
$info = $chart->getChartInfo( $this->chartId );
|
||||||
|
if( $info ){ $this->process( $info, $chart ); exit; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function renderPieCommunities( $params, $groups, $description, $title ){
|
private function renderPieCommunities( $params, $groups, $description, $title ){
|
||||||
|
|||||||
91
include/library/Crunchbutton/Chart/DeliveryFeeTips.php
Normal file
91
include/library/Crunchbutton/Chart/DeliveryFeeTips.php
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
<?php
|
||||||
|
class Crunchbutton_Chart_DeliveryFeeTips extends Crunchbutton_Chart {
|
||||||
|
|
||||||
|
public $unit = 'US$';
|
||||||
|
public $description = 'US$';
|
||||||
|
|
||||||
|
public $groups = array(
|
||||||
|
|
||||||
|
'group-delivery-fee-tips-by-community' => array(
|
||||||
|
'title' => 'Delivery fees + Tips',
|
||||||
|
'tags' => array( 'reps' ),
|
||||||
|
'charts' => array(
|
||||||
|
// 'gross-revenue-per-day-by-community' => array( 'title' => 'Day', 'interval' => 'day', 'type' => 'column-community', 'method' => 'byDayByCommunity' ),
|
||||||
|
'delivery-fee-tips-week-by-community' => array( 'title' => 'Week', 'interval' => 'week', 'type' => 'column-community', 'method' => 'byWeekByCommunity' ),
|
||||||
|
// 'gross-revenue-per-month-by-community' => array( 'title' => 'Month', 'interval' => 'month', 'type' => 'column-community', 'method' => 'byMonthByCommunity' ),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function byWeekByCommunity( $render = false ){
|
||||||
|
|
||||||
|
$community = ( $_REQUEST[ 'community' ] ) ? $_REQUEST[ 'community' ] : false;
|
||||||
|
|
||||||
|
|
||||||
|
$orders = Order::q( 'SELECT o.*, YEARWEEK( o.date ) yearweek
|
||||||
|
FROM `order` o
|
||||||
|
LEFT JOIN restaurant r ON r.id_restaurant = o.id_restaurant
|
||||||
|
WHERE o.delivery_type = "' . ORDER::SHIPPING_DELIVERY . '"
|
||||||
|
AND o.pay_type = "' . ORDER::PAY_TYPE_CREDIT_CARD . '"
|
||||||
|
AND YEARWEEK(o.date) >= ' . $this->weekFrom . '
|
||||||
|
AND YEARWEEK(o.date) <= ' . $this->weekTo . '
|
||||||
|
AND REPLACE( r.community, " ", "-" ) = "' . $community . '"
|
||||||
|
AND r.delivery_service = 1' );
|
||||||
|
$delivery_card = array();
|
||||||
|
foreach( $orders as $order ){
|
||||||
|
if( !$delivery_card[ $order->yearweek ] ){
|
||||||
|
$delivery_card[ $order->yearweek ] = 0;
|
||||||
|
}
|
||||||
|
$weeks[ $order->yearweek ] = $order->yearweek;
|
||||||
|
$delivery_card[ $order->yearweek ] += $order->deliveryFee() + $order->tip();
|
||||||
|
}
|
||||||
|
|
||||||
|
$orders = Order::q( 'SELECT o.*, YEARWEEK( o.date ) yearweek
|
||||||
|
FROM `order` o
|
||||||
|
LEFT JOIN restaurant r ON r.id_restaurant = o.id_restaurant
|
||||||
|
WHERE o.delivery_type = "' . ORDER::SHIPPING_DELIVERY . '"
|
||||||
|
AND o.pay_type = "' . ORDER::PAY_TYPE_CASH . '"
|
||||||
|
AND YEARWEEK(o.date) >= ' . $this->weekFrom . '
|
||||||
|
AND YEARWEEK(o.date) <= ' . $this->weekTo . '
|
||||||
|
AND REPLACE( r.community, " ", "-" ) = "' . $community . '"
|
||||||
|
AND r.delivery_service = 1
|
||||||
|
AND r.formal_relationship = 0' );
|
||||||
|
|
||||||
|
$delivery_cash = array();
|
||||||
|
foreach( $orders as $order ){
|
||||||
|
if( !$delivery_cash[ $order->yearweek ] ){
|
||||||
|
$delivery_cash[ $order->yearweek ] = 0;
|
||||||
|
}
|
||||||
|
$delivery_cash[ $order->yearweek ] += $order->fee() + $order->customer_fee();
|
||||||
|
}
|
||||||
|
|
||||||
|
$allWeeks = $this->allWeeks();
|
||||||
|
$weeks = array();
|
||||||
|
|
||||||
|
for( $i = $this->from -1 ; $i < $this->to; $i++ ){
|
||||||
|
$weeks[ $allWeeks[ $i ] ] = $allWeeks[ $i ];
|
||||||
|
}
|
||||||
|
|
||||||
|
$parsedData = array();
|
||||||
|
foreach( $weeks as $week ){
|
||||||
|
$total = 0;
|
||||||
|
if( $delivery_card[ $week ] ){
|
||||||
|
$total = $delivery_card[ $week ];
|
||||||
|
}
|
||||||
|
if( $delivery_cash[ $week ] ){
|
||||||
|
$total -= $delivery_cash[ $week ];
|
||||||
|
}
|
||||||
|
$parsedData[] = (object) array( 'Label' => $this->parseWeek( $week ), 'Total' => $total, 'Type' => $this->unit );
|
||||||
|
}
|
||||||
|
if( $render ){
|
||||||
|
return array( 'data' => $parsedData, 'unit' => $this->unit );
|
||||||
|
}
|
||||||
|
return $parsedData;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -268,7 +268,6 @@ class Crunchbutton_Chart_Revenue extends Crunchbutton_Chart {
|
|||||||
|
|
||||||
$parsedData = $this->parseDataWeeksGroup( $query, $this->description );
|
$parsedData = $this->parseDataWeeksGroup( $query, $this->description );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( $render ){
|
if( $render ){
|
||||||
return array( 'data' => $parsedData, 'unit' => $this->unit );
|
return array( 'data' => $parsedData, 'unit' => $this->unit );
|
||||||
}
|
}
|
||||||
|
|||||||
@ -672,6 +672,18 @@ class Crunchbutton_Order extends Cana_Table {
|
|||||||
return ($this->restaurant()->fee_restaurant) * ($this->price) / 100;
|
return ($this->restaurant()->fee_restaurant) * ($this->price) / 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function customer_fee(){
|
||||||
|
return ($this->restaurant()->fee_customer) * ($this->price) / 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function fee(){
|
||||||
|
if( $this->restaurant()->fee_on_subtotal ){
|
||||||
|
return $this->cbFee();
|
||||||
|
} else {
|
||||||
|
return ($this->restaurant()->fee_restaurant) * ($this->final_price) / 100;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function notify() {
|
public function notify() {
|
||||||
$order = $this;
|
$order = $this;
|
||||||
foreach ($order->restaurant()->notifications() as $n) {
|
foreach ($order->restaurant()->notifications() as $n) {
|
||||||
|
|||||||
@ -46,15 +46,14 @@
|
|||||||
?>
|
?>
|
||||||
<div class="container-<?php echo $_community; ?>" style="display:none;">
|
<div class="container-<?php echo $_community; ?>" style="display:none;">
|
||||||
<center><h3><?php echo $community->community; ?> ( <?php echo $restaurants; ?> restaurants )</h3></center>
|
<center><h3><?php echo $community->community; ?> ( <?php echo $restaurants; ?> restaurants )</h3></center>
|
||||||
|
|
||||||
<div class="row-fluid">
|
<div class="row-fluid">
|
||||||
|
<div type="new-users" class="span6 new-users <?php echo $_community; ?>" id="new-users-<?php echo $_community; ?>" community="<?php echo $_community; ?>"></div>
|
||||||
<div type="new-users" class="span4 new-users <?php echo $_community; ?>" id="new-users-<?php echo $_community; ?>" community="<?php echo $_community; ?>"></div>
|
<div type="repeated-orders" class="span6 repeated-orders <?php echo $_community; ?>" id="repeated-orders-<?php echo $_community; ?>" community="<?php echo $_community; ?>"></div>
|
||||||
<div type="repeated-orders" class="span4 repeated-orders <?php echo $_community; ?>" id="repeated-orders-<?php echo $_community; ?>" community="<?php echo $_community; ?>"></div>
|
</div>
|
||||||
<div type="gross-revenue" class="span4 group-revenue-by <?php echo $_community; ?>" id="group-revenue-by-<?php echo $_community; ?>" community="<?php echo $_community; ?>"></div>
|
<div class="row-fluid">
|
||||||
|
<div type="gross-revenue" class="span6 group-revenue-by <?php echo $_community; ?>" id="group-revenue-by-<?php echo $_community; ?>" community="<?php echo $_community; ?>"></div>
|
||||||
|
<div type="delivery-fee-tips" class="span6 group-delivery-fee-tips <?php echo $_community; ?>" id="group-delivery-fee-tips-by-<?php echo $_community; ?>" community="<?php echo $_community; ?>"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<hr/>
|
<hr/>
|
||||||
</div>
|
</div>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
@ -82,6 +81,9 @@ function loadChartsOfCommunity( community ){
|
|||||||
case 'gross-revenue':
|
case 'gross-revenue':
|
||||||
partial = 'gross-revenue-per-week-by-community/group-revenue-by-community';
|
partial = 'gross-revenue-per-week-by-community/group-revenue-by-community';
|
||||||
break;
|
break;
|
||||||
|
case 'delivery-fee-tips':
|
||||||
|
partial = 'delivery-fee-tips-week-by-community/group-delivery-fee-tips-by-community';
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
var url = '/home/charts/' + partial + '/?activeUserDays=45&=1&community=' + community;
|
var url = '/home/charts/' + partial + '/?activeUserDays=45&=1&community=' + community;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user