Driver Settlement - #3232
This commit is contained in:
parent
4a72fa7521
commit
90f49a44b9
@ -2,4 +2,9 @@ ALTER TABLE `payment_schedule` ADD `pay_type` enum('payment','reimbursement') D
|
||||
|
||||
ALTER TABLE `payment` ADD `pay_type` enum('payment','reimbursement') DEFAULT 'payment';
|
||||
|
||||
ALTER TABLE `payment` ADD `id_driver` int(11) unsigned DEFAULT NULL;
|
||||
ALTER TABLE `payment` ADD KEY `payment_ibfk_3` (`id_driver`);
|
||||
ALTER TABLE `payment` ADD CONSTRAINT `payment_ibfk_3` FOREIGN KEY (`id_driver`) REFERENCES `admin` (`id_admin`) ON DELETE SET NULL ON UPDATE SET NULL;
|
||||
|
||||
|
||||
ALTER TABLE `order_transaction` CHANGE `type` `type` enum('debit','credit','paid-to-restaurant','paid-to-driver','reimbursed-driver') DEFAULT NULL;
|
||||
15
db/migrate/000199_admin_payment_type.sql
Normal file
15
db/migrate/000199_admin_payment_type.sql
Normal file
@ -0,0 +1,15 @@
|
||||
CREATE TABLE `admin_payment_type` (
|
||||
`id_admin_payment_type` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`id_admin` int(11) unsigned DEFAULT NULL,
|
||||
`payment_method` enum('deposit') NOT NULL DEFAULT 'deposit',
|
||||
`payment_type` enum('orders','hours') NOT NULL DEFAULT 'orders',
|
||||
`summary_email` varchar(255) DEFAULT NULL,
|
||||
`legal_name_payment` varchar(255) DEFAULT NULL,
|
||||
`stripe_id` varchar(255) DEFAULT NULL,
|
||||
`stripe_account_id` varchar(255) DEFAULT NULL,
|
||||
`balanced_id` varchar(255) DEFAULT NULL,
|
||||
`balanced_bank` varchar(255) DEFAULT NULL,
|
||||
PRIMARY KEY (`id_admin_payment_type`),
|
||||
KEY `admin_payment_type_ibfk1` (`id_admin`),
|
||||
CONSTRAINT `admin_payment_type_ibfk1` FOREIGN KEY (`id_admin`) REFERENCES `admin` (`id_admin`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
|
||||
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
class Controller_api_driver extends Crunchbutton_Controller_RestAccount {
|
||||
|
||||
public function init() {
|
||||
|
||||
// list of drivers that were already paid
|
||||
$drivers = Crunchbutton_Admin::q( 'SELECT DISTINCT(a.id_admin) AS id_admin, a.name FROM admin a
|
||||
INNER JOIN payment p ON p.id_driver = a.id_admin
|
||||
ORDER BY a.name ASC' );
|
||||
$export = [];
|
||||
$export[] = array( 'id_driver' => 0, 'name' => 'All' );
|
||||
foreach( $drivers as $driver ){
|
||||
$export[] = array( 'id_driver' => $driver->id_admin, 'name' => $driver->name );
|
||||
}
|
||||
echo json_encode( $export );
|
||||
|
||||
}
|
||||
}
|
||||
@ -4,6 +4,14 @@ class Controller_Api_Settlement extends Crunchbutton_Controller_RestAccount {
|
||||
|
||||
public function init() {
|
||||
|
||||
$this->resultsPerPage = 20;
|
||||
|
||||
// $this->_driverPayments();
|
||||
// exit;
|
||||
|
||||
// $this->_driverDoPayment();
|
||||
// exit;
|
||||
|
||||
// $this->_driverBegin();
|
||||
// exit;
|
||||
|
||||
@ -104,9 +112,21 @@ class Controller_Api_Settlement extends Crunchbutton_Controller_RestAccount {
|
||||
case 'transfer-driver':
|
||||
$this->_driverTransferDeliveryDriver();
|
||||
break;
|
||||
case 'do-payment':
|
||||
$this->_driverDoPayment();
|
||||
break;
|
||||
case 'schedule':
|
||||
$this->_driverSchedule();
|
||||
break;
|
||||
case 'scheduled':
|
||||
$this->_driverScheduled();
|
||||
break;
|
||||
case 'payments':
|
||||
$this->_driverPayments();
|
||||
break;
|
||||
case 'payment':
|
||||
$this->_driverPayment();
|
||||
break;
|
||||
default:
|
||||
$this->_error();
|
||||
break;
|
||||
@ -283,14 +303,14 @@ class Controller_Api_Settlement extends Crunchbutton_Controller_RestAccount {
|
||||
|
||||
private function _restaurantPayments(){
|
||||
|
||||
$resultsPerPage = 20;
|
||||
$resultsPerPage = $this->resultsPerPage;
|
||||
|
||||
$page = max( $this->request()['page'], 1 );
|
||||
$id_restaurant = max( $this->request()['id_restaurant'], 0 );
|
||||
$start = ( ( $page - 1 ) * $resultsPerPage );
|
||||
|
||||
$payments = Crunchbutton_Payment::listPayments( [ 'limit' => $start . ',' . $resultsPerPage, 'id_restaurant' => $id_restaurant ] );
|
||||
$payments_total = Crunchbutton_Payment::listPayments( [ 'id_restaurant' => $id_restaurant ] );
|
||||
$payments = Crunchbutton_Payment::listPayments( [ 'limit' => $start . ',' . $resultsPerPage, 'id_restaurant' => $id_restaurant, 'type' => 'restaurant' ] );
|
||||
$payments_total = Crunchbutton_Payment::listPayments( [ 'id_restaurant' => $id_restaurant, 'type' => 'restaurant' ] );
|
||||
$payments_total = $payments_total->count();
|
||||
|
||||
$list = [];
|
||||
@ -384,7 +404,7 @@ class Controller_Api_Settlement extends Crunchbutton_Controller_RestAccount {
|
||||
$id_driver = $this->request()['id_driver'];
|
||||
|
||||
if( !$start || !$end ){
|
||||
// $this->_error();
|
||||
$this->_error();
|
||||
}
|
||||
|
||||
$settlement = new Settlement( [ 'start' => $start, 'end' => $end ] );
|
||||
@ -472,6 +492,114 @@ class Controller_Api_Settlement extends Crunchbutton_Controller_RestAccount {
|
||||
echo json_encode( [ 'success' => true ] );
|
||||
}
|
||||
|
||||
private function _driverScheduled(){
|
||||
if( c::getPagePiece( 4 ) ){
|
||||
$settlement = new Settlement;
|
||||
$id_payment_schedule = c::getPagePiece( 4 );
|
||||
$summary = $settlement->driverSummary( $id_payment_schedule );
|
||||
if( $summary ){
|
||||
echo json_encode( $summary );
|
||||
} else {
|
||||
$this->_error();
|
||||
}
|
||||
} else {
|
||||
$schedule = new Cockpit_Payment_Schedule;
|
||||
$schedules = $schedule->driverNotCompletedSchedules();
|
||||
$out = [ 'drivers' => '', 'scheduled' => 0, 'processing' => 0, 'done' => 0, 'error' => 0, 'total_payments' => 0, 'total_reimbursements' => 0 ];
|
||||
foreach( $schedules as $_schedule ){
|
||||
$data = $_schedule->exports();
|
||||
if( !$data[ 'amount' ] ){
|
||||
$data[ 'amount' ] = 0;
|
||||
}
|
||||
$data[ 'date' ] = $_schedule->date()->format( 'M jS Y g:i:s A' );
|
||||
$out[ 'drivers' ][] = $data;
|
||||
$out[ $_schedule->status ]++;
|
||||
if( $_schedule->pay_type == Cockpit_Payment_Schedule::PAY_TYPE_REIMBURSEMENT ){
|
||||
$out[ 'total_reimbursements' ]++;
|
||||
} else {
|
||||
$out[ 'total_payments' ]++;
|
||||
}
|
||||
|
||||
}
|
||||
$now = new DateTime( 'now', new DateTimeZone( c::config()->timezone ) );
|
||||
$out[ 'updated_at' ] = $now->format( 'M jS Y g:i:s A' );
|
||||
echo json_encode( $out );
|
||||
}
|
||||
}
|
||||
|
||||
private function _driverPayments(){
|
||||
|
||||
$resultsPerPage = $this->resultsPerPage;
|
||||
|
||||
$page = max( $this->request()['page'], 1 );
|
||||
$id_driver = max( $this->request()['id_driver'], 0 );
|
||||
$pay_type = max( $this->request()['pay_type'], 0 );
|
||||
$start = ( ( $page - 1 ) * $resultsPerPage );
|
||||
|
||||
$payments = Crunchbutton_Payment::listPayments( [ 'limit' => $start . ',' . $resultsPerPage, 'id_driver' => $id_driver, 'type' => 'driver', 'pay_type' => $pay_type ] );
|
||||
$payments_total = Crunchbutton_Payment::listPayments( [ 'id_driver' => $id_driver, 'type' => 'driver', 'pay_type' => $pay_type ] );
|
||||
$payments_total = $payments_total->count();
|
||||
|
||||
$list = [];
|
||||
foreach( $payments as $payment ){
|
||||
$data = $payment->exports();
|
||||
$data[ 'date' ] = $payment->date()->format( 'M jS Y g:i:s A' );
|
||||
unset( $data[ 'id_restaurant' ] );
|
||||
unset( $data[ 'check_id' ] );
|
||||
unset( $data[ 'note' ] );
|
||||
unset( $data[ 'notes' ] );
|
||||
unset( $data[ 'type' ] );
|
||||
unset( $data[ 'id' ] );
|
||||
$list[] = $data;
|
||||
}
|
||||
|
||||
$pages = ceil( $payments_total / $resultsPerPage );
|
||||
|
||||
$data = [];
|
||||
$data[ 'count' ] = $payments_total;
|
||||
$data[ 'pages' ] = $pages;
|
||||
$data[ 'prev' ] = ( $page > 1 ) ? $page - 1 : null;
|
||||
$data[ 'page' ] = intval( $page );
|
||||
$data[ 'next' ] = ( $page < $pages ) ? $page + 1 : null;
|
||||
$data[ 'results' ] = $list;
|
||||
|
||||
echo json_encode( $data );
|
||||
}
|
||||
|
||||
private function _driverPayment(){
|
||||
$settlement = new Settlement;
|
||||
$id_payment = c::getPagePiece( 4 );
|
||||
$summary = $settlement->driverSummaryByIdPayment( $id_payment );
|
||||
if( $summary ){
|
||||
echo json_encode( $summary );
|
||||
} else {
|
||||
$this->_error();
|
||||
}
|
||||
}
|
||||
|
||||
private function _driverDoPayment(){
|
||||
$id_payment_schedule = c::getPagePiece( 4 );
|
||||
$schedule = Cockpit_Payment_Schedule::o( $id_payment_schedule );
|
||||
if( $schedule->id_payment_schedule ){
|
||||
if( $schedule->status == Cockpit_Payment_Schedule::STATUS_DONE ){
|
||||
echo json_encode( [ 'error' => 'Payment already done!' ] );
|
||||
exit;
|
||||
}
|
||||
if( $schedule->status == Cockpit_Payment_Schedule::STATUS_PROCESSING ){
|
||||
echo json_encode( [ 'error' => 'Payment already in process!' ] );
|
||||
exit;
|
||||
}
|
||||
$settlement = new Settlement;
|
||||
if( $settlement->doDriverPayments( $id_payment_schedule ) ){
|
||||
echo json_encode( [ 'success' => true ] );
|
||||
} else {
|
||||
echo json_encode( [ 'error' => 'Problem finishing the payment!' ] );
|
||||
}
|
||||
} else {
|
||||
echo json_encode( [ 'error' => 'Payment schedule not found!' ] );
|
||||
}
|
||||
}
|
||||
|
||||
private function _range(){
|
||||
$now = new DateTime( 'now', new DateTimeZone( c::config()->timezone ) );
|
||||
$range = [ 'end' => $now->format( 'Y,m,d' ) ];
|
||||
|
||||
@ -24,4 +24,8 @@ class Cockpit_Admin extends Crunchbutton_Admin {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function payment_type(){
|
||||
return Crunchbutton_Admin_Payment_Type::byAdmin( $this->id_admin );
|
||||
}
|
||||
|
||||
}
|
||||
@ -44,6 +44,10 @@ class Cockpit_Payment_Schedule extends Cana_Table {
|
||||
return Admin::o( $this->id_admin );
|
||||
}
|
||||
|
||||
public function driver() {
|
||||
return Admin::o( $this->id_driver );
|
||||
}
|
||||
|
||||
public function restaurant() {
|
||||
return Restaurant::o( $this->id_restaurant );
|
||||
}
|
||||
@ -51,7 +55,11 @@ class Cockpit_Payment_Schedule extends Cana_Table {
|
||||
public function date() {
|
||||
if (!isset($this->_date)) {
|
||||
$this->_date = new DateTime($this->date, new DateTimeZone(c::config()->timezone));
|
||||
$this->_date->setTimezone(new DateTimeZone($this->restaurant()->timezone));
|
||||
if( $this->id_restaurant ){
|
||||
$this->_date->setTimezone(new DateTimeZone($this->restaurant()->timezone));
|
||||
} else if( $this->id_driver ){
|
||||
$this->_date->setTimezone(new DateTimeZone($this->driver()->timezone));
|
||||
}
|
||||
}
|
||||
return $this->_date;
|
||||
}
|
||||
@ -59,7 +67,11 @@ class Cockpit_Payment_Schedule extends Cana_Table {
|
||||
public function status_date() {
|
||||
if (!isset($this->_status_date)) {
|
||||
$this->_status_date = new DateTime($this->status_date, new DateTimeZone(c::config()->timezone));
|
||||
$this->_status_date->setTimezone(new DateTimeZone($this->restaurant()->timezone));
|
||||
if( $this->id_restaurant ){
|
||||
$this->_status_date->setTimezone(new DateTimeZone($this->restaurant()->timezone));
|
||||
} else if( $this->id_driver ){
|
||||
$this->_status_date->setTimezone(new DateTimeZone($this->driver()->timezone));
|
||||
}
|
||||
}
|
||||
return $this->_status_date;
|
||||
}
|
||||
@ -78,6 +90,13 @@ class Cockpit_Payment_Schedule extends Cana_Table {
|
||||
return Cockpit_Payment_Schedule::q( $query );
|
||||
}
|
||||
|
||||
public function driverNotCompletedSchedules(){
|
||||
$query = 'SELECT ps.*, a.name AS driver FROM payment_schedule ps
|
||||
INNER JOIN admin a ON a.id_admin = ps.id_driver
|
||||
WHERE ps.status != "' . Cockpit_Payment_Schedule::STATUS_DONE . '" AND amount > 0 ORDER BY ps.id_payment_schedule DESC';
|
||||
return Cockpit_Payment_Schedule::q( $query );
|
||||
}
|
||||
|
||||
public function orders(){
|
||||
return Cockpit_Payment_Schedule_Order::q( 'SELECT * FROM payment_schedule_order WHERE id_payment_schedule = "' . $this->id_payment_schedule . '" ORDER BY id_order DESC' );
|
||||
}
|
||||
|
||||
24
include/library/Crunchbutton/Admin/Payment/Type.php
Normal file
24
include/library/Crunchbutton/Admin/Payment/Type.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
class Crunchbutton_Admin_Payment_Type extends Cana_Table {
|
||||
|
||||
const PAYMENT_METHOD_DEPOSIT = 'deposit';
|
||||
|
||||
public function __construct($id = null) {
|
||||
parent::__construct();
|
||||
$this
|
||||
->table('admin_payment_type')
|
||||
->idVar('id_admin_payment_type')
|
||||
->load($id);
|
||||
}
|
||||
|
||||
function byAdmin( $id_admin ){
|
||||
if( $id_admin ){
|
||||
$payment = Crunchbutton_Admin_Payment_Type::q( 'SELECT * FROM admin_payment_type WHERE id_admin = ' . $id_admin . ' ORDER BY id_admin_payment_type DESC LIMIT 1' );
|
||||
if( $payment->id_admin_payment_type ){
|
||||
return Crunchbutton_Admin_Payment_Type::o( $payment->id_admin_payment_type );
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -45,6 +45,38 @@ class Crunchbutton_Payment extends Cana_Table {
|
||||
}
|
||||
}
|
||||
$payment->env = c::getEnv(false);
|
||||
$payment->id_admin = c::user()->id_admin;
|
||||
$payment->save();
|
||||
|
||||
if( $payment->balanced_id || $payment->stripe_id ){
|
||||
return $payment->id_payment;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static function credit_driver($params = null) {
|
||||
|
||||
$payment = new Payment((object)$params);
|
||||
$payment->date = date('Y-m-d H:i:s');
|
||||
$payment_type = Crunchbutton_Admin_Payment_Type::byAdmin( $payment->id_driver );
|
||||
|
||||
// if( $payment->type == 'balanced' ){
|
||||
// try {
|
||||
// $credit = Crunchbutton_Balanced_Credit::credit( $payment_type, $payment->amount, $payment->note);
|
||||
// } catch ( Exception $e ) {
|
||||
// throw new Exception( $e->getMessage() );
|
||||
// exit;
|
||||
// }
|
||||
// if( $credit && $credit->id ){
|
||||
// $payment->balanced_id = $credit->id;
|
||||
// }
|
||||
// }
|
||||
|
||||
$payment->env = c::getEnv(false);
|
||||
$payment->id_admin = c::user()->id_admin;
|
||||
$payment->balanced_id = 123;
|
||||
$payment->save();
|
||||
|
||||
if( $payment->balanced_id || $payment->stripe_id ){
|
||||
@ -69,17 +101,43 @@ class Crunchbutton_Payment extends Cana_Table {
|
||||
}
|
||||
|
||||
public function listPayments( $search = [] ){
|
||||
$query = '';
|
||||
$where = ' WHERE 1=1 ';
|
||||
if( $search[ 'id_restaurant' ] ){
|
||||
$where .= ' AND p.id_restaurant = ' . $search[ 'id_restaurant' ];
|
||||
}
|
||||
$limit = ( $search[ 'limit' ] ) ? ' LIMIT ' . $search[ 'limit' ] : '';
|
||||
$query = 'SELECT p.*, r.name AS restaurant, ps.id_payment_schedule FROM payment p
|
||||
if( $search[ 'type' ] ){
|
||||
if( $search[ 'type' ] == 'restaurant' ){
|
||||
|
||||
if( $search[ 'id_restaurant' ] ){
|
||||
$where .= ' AND p.id_restaurant = ' . $search[ 'id_restaurant' ];
|
||||
}
|
||||
|
||||
$query = 'SELECT p.*, r.name AS restaurant, ps.id_payment_schedule FROM payment p
|
||||
LEFT OUTER JOIN payment_schedule ps ON ps.id_payment = p.id_payment
|
||||
INNER JOIN restaurant r ON r.id_restaurant = p.id_restaurant
|
||||
' . $where . '
|
||||
ORDER BY p.id_payment DESC ' . $limit;
|
||||
return Crunchbutton_Payment::q( $query );
|
||||
|
||||
}
|
||||
if( $search[ 'type' ] == 'driver' ){
|
||||
|
||||
if( $search[ 'id_driver' ] ){
|
||||
$where .= ' AND p.id_driver = ' . $search[ 'id_driver' ];
|
||||
}
|
||||
|
||||
if( $search[ 'pay_type' ] ){
|
||||
$where .= ' AND p.pay_type = "' . $search[ 'pay_type' ] . '"';
|
||||
}
|
||||
|
||||
$query = 'SELECT p.*, a.name AS driver, ps.id_payment_schedule FROM payment p
|
||||
LEFT OUTER JOIN payment_schedule ps ON ps.id_payment = p.id_payment
|
||||
INNER JOIN admin a ON a.id_admin = p.id_driver
|
||||
' . $where . '
|
||||
ORDER BY p.id_payment DESC ' . $limit;
|
||||
}
|
||||
}
|
||||
$limit = ( $search[ 'limit' ] ) ? ' LIMIT ' . $search[ 'limit' ] : '';
|
||||
if( $query != '' ){
|
||||
return Crunchbutton_Payment::q( $query );
|
||||
}
|
||||
}
|
||||
|
||||
public function date() {
|
||||
|
||||
@ -27,7 +27,7 @@ class Crunchbutton_Restaurant_Payment_Type extends Cana_Table {
|
||||
|
||||
function byRestaurant( $id_restaurant ){
|
||||
if( $id_restaurant ){
|
||||
$payment = Crunchbutton_User_Payment_Type::q( 'SELECT * FROM restaurant_payment_type WHERE id_restaurant = ' . $id_restaurant . ' LIMIT 1' );
|
||||
$payment = Crunchbutton_Restaurant_Payment_Type::q( 'SELECT * FROM restaurant_payment_type WHERE id_restaurant = ' . $id_restaurant . ' LIMIT 1' );
|
||||
if( $payment->id_restaurant_payment_type ){
|
||||
return Crunchbutton_Restaurant_Payment_Type::o( $payment->id_restaurant_payment_type );
|
||||
} else{
|
||||
|
||||
@ -123,7 +123,7 @@ class Crunchbutton_Settlement extends Cana_Model {
|
||||
}
|
||||
|
||||
// this method receives the restaurant orders and run the math
|
||||
public function driversProcessOrders( $orders ){
|
||||
public function driversProcessOrders( $orders, $recalculatePaidOrders = false ){
|
||||
$pay = [];
|
||||
foreach ( $orders as $order ) {
|
||||
|
||||
@ -153,10 +153,10 @@ class Crunchbutton_Settlement extends Cana_Model {
|
||||
$order[ 'pay_info' ][ 'total_reimburse' ] = $this->orderReimburseDriver( $order );
|
||||
$order[ 'pay_info' ][ 'total_payment' ] = $this->orderCalculateTotalDueDriver( $order[ 'pay_info' ] );
|
||||
|
||||
if( $order[ 'driver_reimbursed' ] ){
|
||||
if( $order[ 'driver_reimbursed' ] && !$recalculatePaidOrders ){
|
||||
$order[ 'pay_info' ][ 'total_reimburse' ] = 0;
|
||||
}
|
||||
if( $order[ 'driver_paid' ] ){
|
||||
if( $order[ 'driver_paid' ] && !$recalculatePaidOrders ){
|
||||
$order[ 'pay_info' ][ 'total_payment' ] = 0;
|
||||
}
|
||||
|
||||
@ -581,12 +581,25 @@ class Crunchbutton_Settlement extends Cana_Model {
|
||||
$this->log( 'scheduleDriverPayment', $schedule->properties() );
|
||||
}
|
||||
}
|
||||
// $settlement = new Crunchbutton_Settlement;
|
||||
$settlement = new Crunchbutton_Settlement;
|
||||
// Cana::timeout(function() use( $settlement ) {
|
||||
// $settlement->dodriverPayments();
|
||||
$settlement->doDriverPayments();
|
||||
// } );
|
||||
}
|
||||
|
||||
public function doDriverPayments( $id_payment_schedule = false ){
|
||||
if( $id_payment_schedule ){
|
||||
return $this->payDriver( $id_payment_schedule );
|
||||
} else {
|
||||
// $schedule = new Cockpit_Payment_Schedule;
|
||||
// $lastDate = $schedule->lastRestaurantStatusDate();
|
||||
// $schedules = $schedule->restaurantSchedulesFromDate( $lastDate );
|
||||
// foreach( $schedules as $_schedule ){
|
||||
// $this->payRestaurant( $_schedule->id_payment_schedule );
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
public function doRestaurantPayments( $id_payment_schedule = false ){
|
||||
if( $id_payment_schedule ){
|
||||
return $this->payRestaurant( $id_payment_schedule );
|
||||
@ -618,7 +631,6 @@ class Crunchbutton_Settlement extends Cana_Model {
|
||||
$summary[ 'summary_method' ] = $schedule->restaurant()->payment_type()->summary_method;
|
||||
$summary[ 'summary_email' ] = $schedule->restaurant()->payment_type()->summary_email;
|
||||
$summary[ 'summary_fax' ] = $schedule->restaurant()->payment_type()->summary_fax;
|
||||
$summary[ 'restaurant' ] = $schedule->restaurant()->name;
|
||||
$summary[ 'payment_method' ] = $schedule->restaurant()->payment_type()->payment_method;
|
||||
$payment = $schedule->payment();
|
||||
if( $payment->id_payment ){
|
||||
@ -883,6 +895,193 @@ class Crunchbutton_Settlement extends Cana_Model {
|
||||
}
|
||||
}
|
||||
|
||||
public function payDriver( $id_payment_schedule ){
|
||||
|
||||
$env = c::getEnv();
|
||||
|
||||
$schedule = Cockpit_Payment_Schedule::o( $id_payment_schedule );
|
||||
$this->log( 'payDriver', $schedule->properties() );
|
||||
if( $schedule->id_payment_schedule ){
|
||||
|
||||
if( $schedule->status == Cockpit_Payment_Schedule::STATUS_SCHEDULED ||
|
||||
$schedule->status == Cockpit_Payment_Schedule::STATUS_ERROR ){
|
||||
|
||||
// Save the processing date
|
||||
$schedule->status = Cockpit_Payment_Schedule::STATUS_PROCESSING;
|
||||
$schedule->status_date = date( 'Y-m-d H:i:s' );
|
||||
$schedule->save();
|
||||
|
||||
$amount = floatval( $schedule->amount );
|
||||
|
||||
$payment_method = $schedule->driver()->payment_type()->payment_method;
|
||||
|
||||
// Deposit payment method
|
||||
if( $payment_method == Crunchbutton_Admin_Payment_Type::PAYMENT_METHOD_DEPOSIT ){
|
||||
try {
|
||||
$p = Payment::credit_driver( [ 'id_driver' => $schedule->id_driver,
|
||||
'amount' => $amount,
|
||||
'note' => $schedule->note,
|
||||
'pay_type' => $schedule->pay_type,
|
||||
'type' => 'balanced' ] );
|
||||
} catch ( Exception $e ) {
|
||||
$schedule->log = $e->getMessage();
|
||||
$schedule->status = Cockpit_Payment_Schedule::STATUS_ERROR;
|
||||
$schedule->status_date = date( 'Y-m-d H:i:s' );
|
||||
$schedule->save();
|
||||
$this->log( 'payDriver: Error', $schedule->properties() );
|
||||
return false;
|
||||
}
|
||||
if( $p ){
|
||||
|
||||
$payment = Crunchbutton_Payment::o( $p );
|
||||
|
||||
// save the adjustment
|
||||
if( floatval( $schedule->adjustment ) != 0 ){
|
||||
$payment->adjustment = $schedule->adjustment;
|
||||
$payment->save();
|
||||
}
|
||||
|
||||
$schedule->id_payment = $payment->id_payment;
|
||||
$schedule->status = Cockpit_Payment_Schedule::STATUS_DONE;
|
||||
$schedule->log = 'Payment finished';
|
||||
$schedule->status_date = date( 'Y-m-d H:i:s' );
|
||||
$schedule->save();
|
||||
$this->log( 'payDriver: Success', $schedule->properties() );
|
||||
$orders = $schedule->orders();
|
||||
|
||||
if( $schedule->pay_type == Cockpit_Payment_Schedule::PAY_TYPE_PAYMENT ){
|
||||
$order_transaction_type = Crunchbutton_Order_Transaction::TYPE_PAID_TO_DRIVER;
|
||||
} else {
|
||||
$order_transaction_type = Crunchbutton_Order_Transaction::TYPE_REIMBURSED_TO_DRIVER;
|
||||
}
|
||||
|
||||
foreach ( $orders as $order ) {
|
||||
|
||||
$order_transaction = new Crunchbutton_Order_Transaction;
|
||||
$order_transaction->id_order = $order->id_order;
|
||||
$order_transaction->amt = $order->amount;
|
||||
$order_transaction->date = date( 'Y-m-d H:i:s' );
|
||||
$order_transaction->type = $order_transaction_type;
|
||||
$order_transaction->source = Crunchbutton_Order_Transaction::SOURCE_CRUNCHBUTTON;
|
||||
$order_transaction->id_admin = $payment->id_admin;
|
||||
$order_transaction->save();
|
||||
|
||||
$payment_order_transaction = new Cockpit_Payment_Order_Transaction;
|
||||
$payment_order_transaction->id_payment = $payment->id_payment;
|
||||
$payment_order_transaction->id_order_transaction = $order_transaction->id_order_transaction;
|
||||
$payment_order_transaction->save();
|
||||
}
|
||||
|
||||
// $this->sendDriverPaymentNotification( $payment->id_payment );
|
||||
return true;
|
||||
} else {
|
||||
$message = 'Driver Payment error! Driver: ' . $schedule->driver()->name;
|
||||
$message .= "\n". 'id_payment_schedule: ' . $schedule->id_payment_schedule;
|
||||
$message .= "\n". 'amount: ' . $schedule->amount;
|
||||
$message .= "\n". $schedule->log;
|
||||
$schedule->status = Cockpit_Payment_Schedule::STATUS_ERROR;
|
||||
$schedule->status_date = date( 'Y-m-d H:i:s' );
|
||||
$schedule->save();
|
||||
Crunchbutton_Support::createNewWarning( [ 'body' => $message ] );
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
$schedule->log = 'Driver doesn\'t have a payment method.';
|
||||
$message = 'Driver Payment error! Driver: ' . $schedule->driver()->name;
|
||||
$message .= "\n". 'id_payment_schedule: ' . $schedule->id_payment_schedule;
|
||||
$message .= "\n". 'amount: ' . $schedule->amount;
|
||||
$message .= "\n". $schedule->log;
|
||||
$schedule->status = Cockpit_Payment_Schedule::STATUS_ERROR;
|
||||
$schedule->status_date = date( 'Y-m-d H:i:s' );
|
||||
$schedule->save();
|
||||
$this->log( 'payDriver: Error', $schedule->properties() );
|
||||
Crunchbutton_Support::createNewWarning( [ 'body' => $message ] );
|
||||
}
|
||||
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function driverSummaryByIdPayment( $id_payment ){
|
||||
$schedule = Cockpit_Payment_Schedule::q( 'SELECT * FROM payment_schedule WHERE id_payment = "' . $id_payment . '"' );
|
||||
if( $schedule->id_payment_schedule ){
|
||||
return $this->driverSummary( $schedule->id_payment_schedule );
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function driverSummary( $id_payment_schedule ){
|
||||
|
||||
$schedule = Cockpit_Payment_Schedule::o( $id_payment_schedule );
|
||||
if( $schedule->id_payment_schedule && $schedule->type == Cockpit_Payment_Schedule::TYPE_DRIVER ){
|
||||
$settlement = new Settlement;
|
||||
$summary = $schedule->exports();
|
||||
$summary[ 'driver' ] = $schedule->driver()->name;
|
||||
$summary[ 'summary_method' ] = $schedule->driver()->payment_type()->summary_method;
|
||||
$summary[ 'summary_email' ] = $schedule->driver()->payment_type()->summary_email;
|
||||
$summary[ 'summary_fax' ] = $schedule->driver()->payment_type()->summary_fax;
|
||||
$summary[ 'driver' ] = $schedule->driver()->name;
|
||||
$summary[ 'payment_method' ] = $schedule->driver()->payment_type()->payment_method;
|
||||
$payment = $schedule->payment();
|
||||
if( $payment->id_payment ){
|
||||
$summary[ 'balanced_id' ] = $payment->balanced_id;
|
||||
$summary[ 'stripe_id' ] = $payment->stripe_id;
|
||||
$summary[ 'check_id' ] = $payment->check_id;
|
||||
$summary[ 'summary_sent_date' ] = $payment->summary_sent_date()->format( 'M jS Y g:i:s A T' );
|
||||
$summary[ 'payment_date' ] = $payment->date()->format( 'M jS Y g:i:s A T' );
|
||||
}
|
||||
if( $schedule->status_date ){
|
||||
$summary[ 'status_date' ] = $schedule->status_date()->format( 'M jS Y g:i:s A T' );
|
||||
}
|
||||
$orders = $schedule->orders();
|
||||
$_orders = [];
|
||||
$summary[ 'orders_count' ] = 0;
|
||||
$summary[ 'orders_not_included' ] = 0;
|
||||
$summary[ 'orders' ] = [ 'included' => [], 'not_included' => [] ];
|
||||
foreach( $orders as $order ){
|
||||
$_order = $order->order();
|
||||
if( $_order->id_order ){
|
||||
$variables = $settlement->orderExtractVariables( $_order );
|
||||
$pay_info = $settlement->driversProcessOrders( [ $variables ], true );
|
||||
$type = $variables[ 'cash' ] ? 'Cash' : 'Card';
|
||||
$summary[ 'orders_count' ]++;
|
||||
$summary[ 'orders' ][ 'included' ][] = [ 'id_order' => $variables[ 'id_order' ],
|
||||
'name' => $variables[ 'name' ],
|
||||
'total' => $variables[ 'final_price_plus_delivery_markup' ],
|
||||
'date' => $variables[ 'short_date' ],
|
||||
'tip' => $variables[ 'tip' ],
|
||||
'pay_type' => $type,
|
||||
'total_reimburse' => $pay_info[ 0 ][ 'total_reimburse' ],
|
||||
'total_payment' => $pay_info[ 0 ][ 'total_payment' ]
|
||||
];
|
||||
$_orders[] = $variables;
|
||||
}
|
||||
}
|
||||
$calcs = $settlement->driversProcessOrders( $_orders, true );
|
||||
$summary[ 'calcs' ] = [ 'total_reimburse' => $calcs[ 0 ][ 'total_reimburse' ],
|
||||
'total_payment' => $calcs[ 0 ][ 'total_payment' ],
|
||||
'tax' => $calcs[ 0 ][ 'tax' ],
|
||||
'delivery_fee' => $calcs[ 0 ][ 'delivery_fee' ],
|
||||
'tip' => $calcs[ 0 ][ 'tip' ],
|
||||
'customer_fee' => $calcs[ 0 ][ 'customer_fee' ],
|
||||
'markup' => $calcs[ 0 ][ 'markup' ],
|
||||
'credit_charge' => $calcs[ 0 ][ 'credit_charge' ],
|
||||
'restaurant_fee' => $calcs[ 0 ][ 'restaurant_fee' ],
|
||||
'gift_card' => $calcs[ 0 ][ 'gift_card' ],
|
||||
'subtotal' => $calcs[ 0 ][ 'subtotal' ],
|
||||
];
|
||||
$summary[ 'admin' ] = [ 'id_admin' => $schedule->id_admin, 'name' => $schedule->admin()->name ];
|
||||
return $summary;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function sendRestaurantPaymentNotification( $id_payment ){
|
||||
|
||||
$summary = $this->restaurantSummaryByIdPayment( $id_payment );
|
||||
|
||||
@ -0,0 +1,244 @@
|
||||
<div class="top-pad"></div>
|
||||
|
||||
<div class="content-padding" ng-if="ready">
|
||||
|
||||
<h1 class="title left"><i class="fa fa-bank"></i>
|
||||
<span ng-if="payment">Payment #{{result.id_payment}} - {{result.driver}}</span>
|
||||
<span ng-if="schedule">Payment Schedule #{{result.id_payment_schedule}} - {{result.driver}}</span>
|
||||
</h1>
|
||||
|
||||
<div class="divider"></div>
|
||||
|
||||
<h2 class="title">{{result.driver}}</h2>
|
||||
|
||||
<table class="tb-grid tb-zebra">
|
||||
<tbody>
|
||||
<tr ng-if="result.id_payment">
|
||||
<td><strong>Payment ID</strong></td>
|
||||
<td>
|
||||
<span ng-if="payment"># {{result.id_payment}}</span>
|
||||
<span ng-if="schedule" class="link orange" ng-click="view_payment( result.id_payment )"># {{result.id_payment}}</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr ng-if="result.id_payment_schedule">
|
||||
<td><strong>Payment Schecule ID</strong></td>
|
||||
<td>
|
||||
# {{result.id_payment_schedule}}
|
||||
</td>
|
||||
</tr>
|
||||
<tr ng-if="pay_type_reimbursement">
|
||||
<td><strong>Type</strong></td>
|
||||
<td>Reimbursement</td>
|
||||
</tr>
|
||||
<tr ng-if="pay_type_payment">
|
||||
<td><strong>Type</strong></td>
|
||||
<td>Payment</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>Payment Status</strong></td>
|
||||
<td ng-class="{ 'orange': result.status != 'done', 'green': result.status == 'done' }">
|
||||
{{result.status}}
|
||||
<span ng-if="result.status != 'done'" >
|
||||
<br/>
|
||||
<strong ng-click="do_payment()" class="orange link">Try send payment</strong>
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr ng-if="result.status == 'error' && result.log">
|
||||
<td><strong>Error log</strong></td>
|
||||
<td class="orange">{{result.log}}</td>
|
||||
</tr>
|
||||
<tr ng-if="result.status == 'error' && result.status_date">
|
||||
<td><strong>Last try</strong></td>
|
||||
<td class="orange">{{result.status_date}}</td>
|
||||
</tr>
|
||||
<tr ng-if="result.payment_date">
|
||||
<td><strong>Payment Date</strong></td>
|
||||
<td>{{result.payment_date}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>Payment method</strong></td>
|
||||
<td>{{result.payment_method}}</td>
|
||||
</tr>
|
||||
<tr ng-if="result.payment_date">
|
||||
<td>
|
||||
<strong>Summary sent date</strong>
|
||||
</td>
|
||||
<td>
|
||||
<span ng-if="result.summary_sent_date">{{result.summary_sent_date}}</span>
|
||||
<span ng-if="!result.summary_sent_date"><i>Summary not sent</i></span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr ng-if="result.payment_date && payment">
|
||||
<td><span class="link orange" ng-click="view_summary()">View Summary</span></td>
|
||||
<td><span class="link orange" ng-click="send_summary()">Send Summary</span></td>
|
||||
</tr>
|
||||
<tr class="transparent"><td></td><td></td></tr>
|
||||
<tr ng-if="result.balanced_id">
|
||||
<td>Balanced</td>
|
||||
<td>{{result.balanced_id}}</td>
|
||||
</tr>
|
||||
<tr ng-if="result.stripe_id">
|
||||
<td>Stripe</td>
|
||||
<td>{{result.stripe_id}}</td>
|
||||
</tr>
|
||||
<tr positive-or-negative-color="{{result.calcs.tax}}">
|
||||
<td>Tax</td>
|
||||
<td>$ {{result.calcs.tax | formatPrice}}</td>
|
||||
</tr>
|
||||
<tr positive-or-negative-color="{{result.calcs.delivery_fee}}">
|
||||
<td>Delivery Fee</td>
|
||||
<td>$ {{result.calcs.delivery_fee | formatPrice}}</td>
|
||||
</tr>
|
||||
<tr positive-or-negative-color="{{result.calcs.tip}}">
|
||||
<td>Tip</td>
|
||||
<td>$ {{result.calcs.tip | formatPrice}}</td>
|
||||
</tr>
|
||||
<tr positive-or-negative-color="{{result.calcs.customer_fee}}">
|
||||
<td>Customer Fee</td>
|
||||
<td>$ {{result.calcs.customer_fee | formatPrice}}</td>
|
||||
</tr>
|
||||
<tr positive-or-negative-color="{{result.calcs.markup}}">
|
||||
<td>Markup</td>
|
||||
<td>$ {{result.calcs.markup | formatPrice}}</td>
|
||||
</tr>
|
||||
<tr positive-or-negative-color="{{result.calcs.credit_charge}}">
|
||||
<td>Credit Card Charge</td>
|
||||
<td>$ {{result.calcs.credit_charge | formatPrice}}</td>
|
||||
</tr>
|
||||
<tr positive-or-negative-color="{{result.calcs.gift_card}}">
|
||||
<td>Gift Card</td>
|
||||
<td>$ {{result.calcs.gift_card | formatPrice}}</td>
|
||||
</tr>
|
||||
<tr positive-or-negative-color="{{result.adjustment}}">
|
||||
<td>Adjustments</td>
|
||||
<td>$ {{result.adjustment | formatPrice}}</td>
|
||||
</tr>
|
||||
<tr class="total-due" positive-or-negative-color="{{result.calcs.total_reimburse}}" ng-if="pay_type_reimbursement">
|
||||
<td class="td-medium">Reimbursement</td>
|
||||
<td class="td-medium">$ {{result.calcs.total_reimburse | formatPrice}}</td>
|
||||
</tr>
|
||||
<tr class="total-due" positive-or-negative-color="{{result.calcs.total_payment}}" ng-if="pay_type_payment">
|
||||
<td class="td-medium">Payment</td>
|
||||
<td class="td-medium">$ {{result.calcs.total_payment | formatPrice}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Payment Notes</td>
|
||||
<td>{{result.note}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<br/>
|
||||
|
||||
<table class="tb-grid tb-zebra">
|
||||
<thead>
|
||||
<tr>
|
||||
<td colspan="7" class="title">Orders</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<thead ng-if="!result.orders">
|
||||
<td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</td>
|
||||
</thead>
|
||||
<thead ng-if="result.orders">
|
||||
<tr>
|
||||
<td>#</td>
|
||||
<td class="td-medium">Curstomer name</td>
|
||||
<td>Date</td>
|
||||
<td>Total</td>
|
||||
<td>Tip</td>
|
||||
<td>Type</td>
|
||||
<td ng-if="pay_type_reimbursement">Reimbursement</td>
|
||||
<td ng-if="pay_type_payment">Payment</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody ng-if="result.orders.included">
|
||||
<tr ng-repeat="order in result.orders.included">
|
||||
<td>{{order.id_order}}</td>
|
||||
<td>{{order.name}}</td>
|
||||
<td>{{order.date}}</td>
|
||||
<td>$ {{order.tip | formatPrice}}</td>
|
||||
<td>$ {{order.total | formatPrice}}</td>
|
||||
<td>{{order.pay_type}}</td>
|
||||
<td ng-if="pay_type_reimbursement">$ {{order.total_reimburse | formatPrice}}</td>
|
||||
<td ng-if="pay_type_payment">$ {{order.total_payment | formatPrice}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
<tbody>
|
||||
<tr class="transparent">
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr class="transparent">
|
||||
<td></td>
|
||||
<td>Tips by Card</td>
|
||||
<td>$ {{result.calcs.tip | formatPrice}}</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr class="transparent">
|
||||
<td></td>
|
||||
<td>Visa/Mastercard/Amex Charges</td>
|
||||
<td>$ {{result.calcs.credit_charge | formatPrice}}</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr class="transparent" ng-if="result.adjustment">
|
||||
<td></td>
|
||||
<td>Adjustment</td>
|
||||
<td>$ {{result.adjustment | formatPrice}}</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr class="transparent" ng-if="pay_type_reimbursement">
|
||||
<td></td>
|
||||
<td><strong>Total Reimburse</strong></td>
|
||||
<td><strong>$ {{result.calcs.total_reimburse | formatPrice}}</strong></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr class="transparent" ng-if="pay_type_payment">
|
||||
<td></td>
|
||||
<td><strong>Total Payment</strong></td>
|
||||
<td><strong>$ {{result.calcs.total_payment | formatPrice}}</strong></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr class="transparent">
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<spinner-loading></spinner-loading>
|
||||
<hack-expand-content></hack-expand-content>
|
||||
@ -0,0 +1,77 @@
|
||||
<div class="top-pad"></div>
|
||||
|
||||
<div class="content-padding" ng-show="ready">
|
||||
|
||||
<h1 class="title left"><i class="fa fa-bank"></i><span>Payments - Drivers</span></h1>
|
||||
|
||||
<div class="divider"></div>
|
||||
|
||||
<h2 class="title">
|
||||
<span>Payments</span>
|
||||
</h2>
|
||||
|
||||
<ul class="ul-inputs box-content">
|
||||
<li class="li-input">
|
||||
<div class="label">Driver:</div>
|
||||
<select ng-model="id_driver" ng-options="opt.id_driver as opt.name for opt in drivers" class="cart-customize-select"></select>
|
||||
</li>
|
||||
<li class="li-input">
|
||||
<div class="label">Type:</div>
|
||||
<select ng-model="pay_type" ng-options="opt.type as opt.label for opt in pay_types" class="cart-customize-select"></select>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div ng-if="count">
|
||||
|
||||
<div class="box-content" ng-show="!showForm">
|
||||
<p>
|
||||
Total of <strong>{{count}}</strong> payments found.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<table class="tb-grid tb-zebra">
|
||||
<thead>
|
||||
<tr>
|
||||
<td>#</td>
|
||||
<td class="td-medium">Driver</td>
|
||||
<td>Type</td>
|
||||
<td>Amount</td>
|
||||
<td>Date</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr ng-repeat="payment in payments">
|
||||
<td>
|
||||
<span ng-show="payment.id_payment_schedule" class="orange link" ng-click="open(payment.id_payment)">
|
||||
{{payment.id_payment}}
|
||||
</span>
|
||||
<span ng-show="!payment.id_payment_schedule">
|
||||
{{payment.id_payment}}
|
||||
</span>
|
||||
</td>
|
||||
<td>{{payment.driver}}</td>
|
||||
<td>{{payment.pay_type}}</td>
|
||||
<td>$ {{payment.amount | formatPrice}}</td>
|
||||
<td>{{payment.date}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<table class="tb-pagination" ng-show="pages > 1">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td class="td-prev"><button class="button orange" ng-show="prev" ng-click="prevPage()">prev</button></td>
|
||||
<td class="td-info">Page {{page}} of {{pages}}</td>
|
||||
<td class="td-next"><button class="button orange" ng-show="next" ng-click="nextPage()">next</button></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div ng-if="!count">
|
||||
No payments
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<spinner-loading></spinner-loading>
|
||||
<hack-expand-content></hack-expand-content>
|
||||
@ -0,0 +1,85 @@
|
||||
<div class="top-pad"></div>
|
||||
|
||||
<div class="content-padding" ng-show="ready">
|
||||
|
||||
<h1 class="title left"><i class="fa fa-bank"></i><span>Scheduled Payments - Drivers</span></h1>
|
||||
|
||||
<div class="divider"></div>
|
||||
|
||||
<div ng-if="result">
|
||||
|
||||
<h2 class="title">
|
||||
<span>Summary</span>
|
||||
</h2>
|
||||
<h3 class="title">
|
||||
Summary updated at {{result.updated_at}} <span class="orange link" ng-click="update()">Update now</span>
|
||||
</h3>
|
||||
|
||||
<table class="tb-grid tb-zebra summary">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>Total of Payments</td>
|
||||
<td>{{result.total_payments}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Total of Reimbursements</td>
|
||||
<td>{{result.total_reimbursements}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Scheduled</td>
|
||||
<td>{{result.scheduled}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Processing</td>
|
||||
<td>{{result.processing}}</td>
|
||||
</tr>
|
||||
<tr ng-class="{'orange' : result.error > 0 }">
|
||||
<td>Error</td>
|
||||
<td>{{result.error}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div ng-show="result.drivers">
|
||||
|
||||
<h2 class="title">
|
||||
<span>Scheduled Payments</span>
|
||||
</h2>
|
||||
|
||||
<div class="box-filter">
|
||||
<button class="button green" ng-class="{ 'inactive' : filter }" ng-click="filter = false">All</button>
|
||||
<button class="button button-big green" ng-class="{ 'inactive' : filter != 'reimbursement' }" ng-click="filter = 'reimbursement'">Reimbursement</button>
|
||||
<button class="button button-big green" ng-class="{ 'inactive' : filter != 'payment' }" ng-click="filter = 'payment'">Payments</button>
|
||||
<div class="divider"></div>
|
||||
</div>
|
||||
|
||||
<table class="tb-grid tb-zebra">
|
||||
<thead>
|
||||
<tr>
|
||||
<td>#</td>
|
||||
<td class="td-medium">Driver</td>
|
||||
<td>Scheduled at</td>
|
||||
<td>Type</td>
|
||||
<td>Amount</td>
|
||||
<td>Status</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr ng-repeat="driver in result.drivers" ng-show="!filter || filter == driver.pay_type">
|
||||
<td>{{driver.id_payment_schedule}}</td>
|
||||
<td>{{driver.driver}}</td>
|
||||
<td>{{driver.date}}</td>
|
||||
<td>{{driver.pay_type}}</td>
|
||||
<td>$ {{driver.amount | formatPrice}}</td>
|
||||
<td>
|
||||
<span class="link orange" ng-click="payment( driver.id_payment_schedule )">{{driver.status}}</span>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<spinner-loading></spinner-loading>
|
||||
<hack-expand-content></hack-expand-content>
|
||||
@ -62,11 +62,9 @@
|
||||
</div>
|
||||
|
||||
<div ng-if="result">
|
||||
|
||||
<h2 class="title">
|
||||
<span>Summary</span>
|
||||
</h2>
|
||||
|
||||
<div>
|
||||
<table class="tb-grid tb-zebra summary">
|
||||
<tbody>
|
||||
@ -92,9 +90,7 @@
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
</div>
|
||||
|
||||
<table class="tb-grid tb-zebra">
|
||||
<thead>
|
||||
<tr>
|
||||
@ -175,7 +171,6 @@
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
|
||||
<ul class="ul-inputs box-content">
|
||||
<li class="li-input">
|
||||
<button class="button button-big save" ng-click="schedule_payment();">Pay Drivers</button>
|
||||
@ -271,10 +266,6 @@
|
||||
<td>Credit Card Charge</td>
|
||||
<td>$ {{driver.credit_charge | formatPrice}}</td>
|
||||
</tr>
|
||||
<tr positive-or-negative-color="{{driver.restaurant_fee}}">
|
||||
<td>Crunchbutton Fees</td>
|
||||
<td>$ {{driver.restaurant_fee | formatPrice}}</td>
|
||||
</tr>
|
||||
<tr positive-or-negative-color="{{driver.gift_card}}">
|
||||
<td>Gift Card</td>
|
||||
<td>$ {{driver.gift_card | formatPrice}}</td>
|
||||
|
||||
@ -3,8 +3,8 @@
|
||||
<div class="content-padding" ng-if="ready">
|
||||
|
||||
<h1 class="title left"><i class="fa fa-bank"></i>
|
||||
<span ng-show="payment">Payment #{{result.id_payment}} - {{result.restaurant}}</span>
|
||||
<span ng-show="schedule">Payment Schedule #{{result.id_payment_schedule}} - {{result.restaurant}}</span>
|
||||
<span ng-if="payment">Payment #{{result.id_payment}} - {{result.restaurant}}</span>
|
||||
<span ng-if="schedule">Payment Schedule #{{result.id_payment_schedule}} - {{result.restaurant}}</span>
|
||||
</h1>
|
||||
|
||||
<div class="divider"></div>
|
||||
@ -13,14 +13,14 @@
|
||||
|
||||
<table class="tb-grid tb-zebra">
|
||||
<tbody>
|
||||
<tr ng-show="result.id_payment">
|
||||
<tr ng-if="result.id_payment">
|
||||
<td><strong>Payment ID</strong></td>
|
||||
<td>
|
||||
<span ng-show="payment"># {{result.id_payment}}</span>
|
||||
<span ng-show="schedule" class="link orange" ng-click="view_payment( result.id_payment )"># {{result.id_payment}}</span>
|
||||
<span ng-if="payment"># {{result.id_payment}}</span>
|
||||
<span ng-if="schedule" class="link orange" ng-click="view_payment( result.id_payment )"># {{result.id_payment}}</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr ng-show="result.id_payment_schedule">
|
||||
<tr ng-if="result.id_payment_schedule">
|
||||
<td><strong>Payment Schecule ID</strong></td>
|
||||
<td>
|
||||
# {{result.id_payment_schedule}}
|
||||
@ -30,21 +30,21 @@
|
||||
<td><strong>Payment Status</strong></td>
|
||||
<td ng-class="{ 'orange': result.status != 'done', 'green': result.status == 'done' }">
|
||||
{{result.status}}
|
||||
<span ng-show="result.status != 'done'" >
|
||||
<span ng-if="result.status != 'done'" >
|
||||
<br/>
|
||||
<strong ng-click="do_payment()" class="orange link">Try send payment</strong>
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr ng-show="result.status == 'error' && result.log">
|
||||
<tr ng-if="result.status == 'error' && result.log">
|
||||
<td><strong>Error log</strong></td>
|
||||
<td class="orange">{{result.log}}</td>
|
||||
</tr>
|
||||
<tr ng-show="result.status == 'error' && result.status_date">
|
||||
<tr ng-if="result.status == 'error' && result.status_date">
|
||||
<td><strong>Last try</strong></td>
|
||||
<td class="orange">{{result.status_date}}</td>
|
||||
</tr>
|
||||
<tr ng-show="result.payment_date">
|
||||
<tr ng-if="result.payment_date">
|
||||
<td><strong>Payment Date</strong></td>
|
||||
<td>{{result.payment_date}}</td>
|
||||
</tr>
|
||||
@ -52,29 +52,29 @@
|
||||
<td><strong>Payment method</strong></td>
|
||||
<td>{{result.payment_method}}</td>
|
||||
</tr>
|
||||
<tr ng-show="result.payment_date">
|
||||
<tr ng-if="result.payment_date">
|
||||
<td>
|
||||
<strong>Summary sent date</strong>
|
||||
</td>
|
||||
<td>
|
||||
<span ng-show="result.summary_sent_date">{{result.summary_sent_date}}</span>
|
||||
<span ng-show="!result.summary_sent_date"><i>Summary not sent</i></span>
|
||||
<span ng-if="result.summary_sent_date">{{result.summary_sent_date}}</span>
|
||||
<span ng-if="!result.summary_sent_date"><i>Summary not sent</i></span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr ng-show="result.payment_date && payment">
|
||||
<tr ng-if="result.payment_date && payment">
|
||||
<td><span class="link orange" ng-click="view_summary()">View Summary</span></td>
|
||||
<td><span class="link orange" ng-click="send_summary()">Send Summary</span></td>
|
||||
</tr>
|
||||
<tr class="transparent"><td></td><td></td></tr>
|
||||
<tr ng-show="result.balanced_id">
|
||||
<tr ng-if="result.balanced_id">
|
||||
<td>Balanced</td>
|
||||
<td>{{result.balanced_id}}</td>
|
||||
</tr>
|
||||
<tr ng-show="result.stripe_id">
|
||||
<tr ng-if="result.stripe_id">
|
||||
<td>Stripe</td>
|
||||
<td>{{result.stripe_id}}</td>
|
||||
</tr>
|
||||
<tr ng-show="result.check_id">
|
||||
<tr ng-if="result.check_id">
|
||||
<td>Lob (Check)</td>
|
||||
<td>{{result.check_id}}</td>
|
||||
</tr>
|
||||
@ -233,7 +233,7 @@
|
||||
<td>$ {{result.calcs.restaurant_fee | formatPrice}}</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr class="transparent" ng-show="result.adjustment">
|
||||
<tr class="transparent" ng-if="result.adjustment">
|
||||
<td></td>
|
||||
<td>Adjustment</td>
|
||||
<td>$ {{result.adjustment | formatPrice}}</td>
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
<div class="content-padding" ng-show="ready">
|
||||
|
||||
<h1 class="title left"><i class="fa fa-bank"></i><span>Payments - Scheduled</span></h1>
|
||||
<h1 class="title left"><i class="fa fa-bank"></i><span>Scheduled Payments - Restaurants</span></h1>
|
||||
|
||||
<div class="divider"></div>
|
||||
|
||||
@ -36,32 +36,35 @@
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<h2 class="title">
|
||||
<span>Scheduled Payments</span>
|
||||
</h2>
|
||||
<div ng-if="result.restaurants">
|
||||
|
||||
<table class="tb-grid tb-zebra">
|
||||
<thead>
|
||||
<tr>
|
||||
<td>#</td>
|
||||
<td class="td-medium">Restaurant</td>
|
||||
<td>Scheduled at</td>
|
||||
<td>Amount</td>
|
||||
<td>Status</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr ng-repeat="restaurant in result.restaurants">
|
||||
<td>{{restaurant.id_payment_schedule}}</td>
|
||||
<td>{{restaurant.restaurant}}</td>
|
||||
<td>{{restaurant.date}}</td>
|
||||
<td>$ {{restaurant.amount | formatPrice}}</td>
|
||||
<td>
|
||||
<span class="link orange" ng-click="payment( restaurant.id_payment_schedule )">{{restaurant.status}}</span>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<h2 class="title">
|
||||
<span>Scheduled Payments</span>
|
||||
</h2>
|
||||
|
||||
<table class="tb-grid tb-zebra">
|
||||
<thead>
|
||||
<tr>
|
||||
<td>#</td>
|
||||
<td class="td-medium">Restaurant</td>
|
||||
<td>Scheduled at</td>
|
||||
<td>Amount</td>
|
||||
<td>Status</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr ng-repeat="restaurant in result.restaurants">
|
||||
<td>{{restaurant.id_payment_schedule}}</td>
|
||||
<td>{{restaurant.restaurant}}</td>
|
||||
<td>{{restaurant.date}}</td>
|
||||
<td>$ {{restaurant.amount | formatPrice}}</td>
|
||||
<td>
|
||||
<span class="link orange" ng-click="payment( restaurant.id_payment_schedule )">{{restaurant.status}}</span>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@ -13,6 +13,8 @@
|
||||
<hr/>
|
||||
<h2 class="title">Drivers</h2>
|
||||
<h3 class="title link" ng-click="drivers()">New Payment</h3>
|
||||
<h3 class="title link" ng-click="drivers_payments()">Payments list</h3>
|
||||
<h3 class="title link" ng-click="drivers_scheduled_payments()">Scheduled Payments (not finished or error)</h3>
|
||||
|
||||
<div class="divider"></div>
|
||||
|
||||
|
||||
@ -140,6 +140,27 @@ NGApp.config(['$routeProvider', '$locationProvider', function($routeProvider, $l
|
||||
controller: 'SettlementDriversScheduledCtrl',
|
||||
templateUrl: 'assets/view/settlement-drivers-scheduled.html'
|
||||
})
|
||||
.when('/settlement/drivers/scheduled/:id', {
|
||||
action: 'settlement',
|
||||
controller: 'SettlementDriversScheduledViewCtrl',
|
||||
templateUrl: 'assets/view/settlement-drivers-payment.html'
|
||||
})
|
||||
.when('/settlement/drivers/payments', {
|
||||
action: 'settlement',
|
||||
controller: 'SettlementDriversPaymentsCtrl',
|
||||
templateUrl: 'assets/view/settlement-drivers-payments.html'
|
||||
})
|
||||
.when('/settlement/drivers/payment/:id', {
|
||||
action: 'settlement',
|
||||
controller: 'SettlementDriversPaymentCtrl',
|
||||
templateUrl: 'assets/view/settlement-drivers-payment.html'
|
||||
})
|
||||
.when('/settlement/drivers/summary/:id', {
|
||||
action: 'settlement',
|
||||
controller: 'SettlementDriversSummaryCtrl',
|
||||
templateUrl: 'assets/view/settlement-drivers-summary.html'
|
||||
})
|
||||
/* Driver shifts */
|
||||
.when('/drivers/orders', {
|
||||
action: 'drivers-orders',
|
||||
controller: 'DriversOrdersCtrl',
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
NGApp.controller('SettlementCtrl', function ( $scope ) {
|
||||
NGApp.controller( 'SettlementCtrl', function ( $scope ) {
|
||||
|
||||
$scope.ready = true;
|
||||
|
||||
@ -18,9 +18,17 @@ NGApp.controller('SettlementCtrl', function ( $scope ) {
|
||||
$scope.navigation.link( '/settlement/drivers' );
|
||||
}
|
||||
|
||||
$scope.drivers_payments = function(){
|
||||
$scope.navigation.link( '/settlement/drivers/payments' );
|
||||
}
|
||||
|
||||
$scope.drivers_scheduled_payments = function(){
|
||||
$scope.navigation.link( '/settlement/drivers/scheduled' );
|
||||
}
|
||||
|
||||
} );
|
||||
|
||||
NGApp.controller('SettlementRestaurantsCtrl', function ( $scope, $filter, SettlementService ) {
|
||||
NGApp.controller( 'SettlementRestaurantsCtrl', function ( $scope, $filter, SettlementService ) {
|
||||
|
||||
$scope.ready = false;
|
||||
$scope.pay_type = 'all';
|
||||
@ -197,7 +205,7 @@ NGApp.controller('SettlementRestaurantsCtrl', function ( $scope, $filter, Settle
|
||||
$scope.total_reimburse_cash_orders = total_reimburse_cash_orders;
|
||||
$scope.total_refunded = total_refunded;
|
||||
$scope.sum = sum;
|
||||
console.log('$scope.sum',$scope.sum);
|
||||
console.log( '$scope.sum',$scope.sum);
|
||||
}
|
||||
|
||||
$scope.show_details = function( restaurant ){
|
||||
@ -225,7 +233,7 @@ NGApp.controller('SettlementRestaurantsCtrl', function ( $scope, $filter, Settle
|
||||
|
||||
});
|
||||
|
||||
NGApp.controller('SettlementRestaurantsScheduledCtrl', function ( $scope, SettlementService ) {
|
||||
NGApp.controller( 'SettlementRestaurantsScheduledCtrl', function ( $scope, SettlementService ) {
|
||||
|
||||
$scope.ready = false;
|
||||
|
||||
@ -247,7 +255,7 @@ NGApp.controller('SettlementRestaurantsScheduledCtrl', function ( $scope, Settle
|
||||
|
||||
});
|
||||
|
||||
NGApp.controller('SettlementRestaurantsSummaryCtrl', function ( $scope, $routeParams, SettlementService ) {
|
||||
NGApp.controller( 'SettlementRestaurantsSummaryCtrl', function ( $scope, $routeParams, SettlementService ) {
|
||||
|
||||
$scope.ready = false;
|
||||
|
||||
@ -269,7 +277,7 @@ NGApp.controller('SettlementRestaurantsSummaryCtrl', function ( $scope, $routePa
|
||||
|
||||
});
|
||||
|
||||
NGApp.controller('SettlementRestaurantsPaymentsCtrl', function ( $scope, $rootScope, SettlementService, RestaurantService ) {
|
||||
NGApp.controller( 'SettlementRestaurantsPaymentsCtrl', function ( $scope, $rootScope, SettlementService, RestaurantService ) {
|
||||
|
||||
$scope.ready = false;
|
||||
$scope.id_restaurant = 0;
|
||||
@ -319,7 +327,7 @@ NGApp.controller('SettlementRestaurantsPaymentsCtrl', function ( $scope, $rootSc
|
||||
|
||||
});
|
||||
|
||||
NGApp.controller('SettlementRestaurantsScheduledViewCtrl', function ( $scope, $routeParams, SettlementService ) {
|
||||
NGApp.controller( 'SettlementRestaurantsScheduledViewCtrl', function ( $scope, $routeParams, SettlementService ) {
|
||||
|
||||
$scope.ready = false;
|
||||
$scope.schedule = true;
|
||||
@ -356,7 +364,7 @@ NGApp.controller('SettlementRestaurantsScheduledViewCtrl', function ( $scope, $r
|
||||
|
||||
});
|
||||
|
||||
NGApp.controller('SettlementRestaurantsPaymentCtrl', function ( $scope, $routeParams, SettlementService ) {
|
||||
NGApp.controller( 'SettlementRestaurantsPaymentCtrl', function ( $scope, $routeParams, SettlementService ) {
|
||||
|
||||
$scope.ready = false;
|
||||
|
||||
@ -393,7 +401,7 @@ NGApp.controller('SettlementRestaurantsPaymentCtrl', function ( $scope, $routePa
|
||||
|
||||
});
|
||||
|
||||
NGApp.controller('SettlementDriversCtrl', function ( $scope, $filter, SettlementService, DriverService ) {
|
||||
NGApp.controller( 'SettlementDriversCtrl', function ( $scope, $filter, SettlementService, DriverService ) {
|
||||
|
||||
$scope.ready = false;
|
||||
|
||||
@ -538,11 +546,11 @@ NGApp.controller('SettlementDriversCtrl', function ( $scope, $filter, Settlement
|
||||
}
|
||||
|
||||
$scope.schedule_reimbursement = function(){
|
||||
schedule( $scope.result.reimbursement );
|
||||
schedule( SettlementService.PAY_TYPE_REIMBURSEMENT );
|
||||
}
|
||||
|
||||
$scope.schedule_payment = function(){
|
||||
schedule( $scope.result.payment );
|
||||
schedule( SettlementService.PAY_TYPE_PAYMENT );
|
||||
}
|
||||
|
||||
var schedule = function( pay_type ){
|
||||
@ -569,7 +577,6 @@ NGApp.controller('SettlementDriversCtrl', function ( $scope, $filter, Settlement
|
||||
} );
|
||||
}
|
||||
|
||||
|
||||
$scope.show_details = function( driver ){
|
||||
if( !driver.show_details ){
|
||||
$scope.showing_details = true;
|
||||
@ -595,4 +602,168 @@ NGApp.controller('SettlementDriversCtrl', function ( $scope, $filter, Settlement
|
||||
DriverService.listSimple( function( json ){ $scope.drivers = json; } )
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
NGApp.controller( 'SettlementDriversScheduledCtrl', function ( $scope, SettlementService ) {
|
||||
|
||||
$scope.ready = false;
|
||||
$scope.filter = false;
|
||||
|
||||
$scope.update = function(){
|
||||
SettlementService.drivers.scheduled( function( json ){
|
||||
$scope.result = json;
|
||||
$scope.ready = true;
|
||||
} );
|
||||
}
|
||||
|
||||
$scope.payment = function( id_payment ){
|
||||
$scope.navigation.link( '/settlement/drivers/scheduled/' + id_payment );
|
||||
}
|
||||
|
||||
// Just run if the user is loggedin
|
||||
if( $scope.account.isLoggedIn() ){
|
||||
$scope.update();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
NGApp.controller( 'SettlementDriversScheduledViewCtrl', function ( $scope, $routeParams, SettlementService ) {
|
||||
|
||||
$scope.ready = false;
|
||||
$scope.schedule = true;
|
||||
|
||||
load = function(){
|
||||
SettlementService.drivers.scheduled_payment( function( json ){
|
||||
$scope.result = json;
|
||||
if( json.pay_type == SettlementService.PAY_TYPE_REIMBURSEMENT ){
|
||||
$scope.pay_type_reimbursement = true;
|
||||
} else {
|
||||
$scope.pay_type_payment = true;
|
||||
}
|
||||
$scope.ready = true;
|
||||
$scope.unBusy();
|
||||
} );
|
||||
}
|
||||
|
||||
$scope.do_payment = function(){
|
||||
$scope.makeBusy();
|
||||
SettlementService.drivers.do_payment( $routeParams.id, function( json ){
|
||||
if( json.error ){
|
||||
App.alert( 'Oops, something bad happened: ' + json.error );
|
||||
load();
|
||||
$scope.unBusy();
|
||||
} else {
|
||||
load();
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
$scope.view_payment = function( id_payment ){
|
||||
$scope.navigation.link( '/settlement/drivers/payment/' + id_payment );
|
||||
}
|
||||
|
||||
// Just run if the user is loggedin
|
||||
if( $scope.account.isLoggedIn() ){
|
||||
load();
|
||||
}
|
||||
});
|
||||
|
||||
NGApp.controller( 'SettlementDriversPaymentsCtrl', function ( $scope, $rootScope, SettlementService, DriverService) {
|
||||
|
||||
$scope.ready = false;
|
||||
$scope.id_driver = 0;
|
||||
$scope.page = 1;
|
||||
|
||||
var list = function(){
|
||||
SettlementService.drivers.payments( { 'page': $scope.page, 'id_driver': $scope.id_driver, 'pay_type': $scope.pay_type }, function( data ){
|
||||
$scope.pages = data.pages;
|
||||
$scope.next = data.next;
|
||||
$scope.prev = data.prev;
|
||||
$scope.payments = data.results;
|
||||
$scope.count = data.count;
|
||||
$scope.ready = true;
|
||||
} );
|
||||
}
|
||||
|
||||
var drivers = function(){
|
||||
DriverService.paid( function( data ){
|
||||
$scope.drivers = data;
|
||||
} );
|
||||
}
|
||||
|
||||
$scope.open = function( id_payment ){
|
||||
$scope.navigation.link( '/settlement/drivers/payment/' + id_payment );
|
||||
}
|
||||
|
||||
$scope.$watch( 'id_driver', function( newValue, oldValue, scope ) {
|
||||
$scope.page = 1;
|
||||
list();
|
||||
} );
|
||||
|
||||
$scope.$watch( 'pay_type', function( newValue, oldValue, scope ) {
|
||||
$scope.page = 1;
|
||||
list();
|
||||
} );
|
||||
|
||||
|
||||
$scope.nextPage = function(){
|
||||
$scope.page = $scope.next;
|
||||
list();
|
||||
}
|
||||
|
||||
$scope.prevPage = function(){
|
||||
$scope.page = $scope.prev;
|
||||
list();
|
||||
}
|
||||
|
||||
// Just run if the user is loggedin
|
||||
if( $scope.account.isLoggedIn() ){
|
||||
$scope.pay_type = 0;
|
||||
$scope.pay_types = SettlementService.pay_types();
|
||||
drivers();
|
||||
list();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
NGApp.controller( 'SettlementDriversPaymentCtrl', function ( $scope, $routeParams, SettlementService ) {
|
||||
|
||||
$scope.ready = false;
|
||||
|
||||
$scope.payment = true;
|
||||
|
||||
load = function(){
|
||||
SettlementService.drivers.payment( function( json ){
|
||||
$scope.result = json;
|
||||
if( json.pay_type == SettlementService.PAY_TYPE_REIMBURSEMENT ){
|
||||
$scope.pay_type_reimbursement = true;
|
||||
} else {
|
||||
$scope.pay_type_payment = true;
|
||||
}
|
||||
$scope.ready = true;
|
||||
$scope.unBusy();
|
||||
} );
|
||||
}
|
||||
|
||||
$scope.view_summary = function(){
|
||||
$scope.navigation.link( '/settlement/drivers/summary/' + $routeParams.id );
|
||||
}
|
||||
|
||||
$scope.send_summary = function(){
|
||||
$scope.makeBusy();
|
||||
SettlementService.drivers.send_summary( function( json ){
|
||||
if( json.success ){
|
||||
load();
|
||||
} else {
|
||||
$scope.unBusy();
|
||||
App.alert( 'Oops, something bad happened!' );
|
||||
}
|
||||
} )
|
||||
}
|
||||
|
||||
// Just run if the user is loggedin
|
||||
if( $scope.account.isLoggedIn() ){
|
||||
load();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@ -6,9 +6,16 @@ NGApp.factory( 'DriverService', function( $rootScope, $resource, $routeParams )
|
||||
var drivers = $resource( App.service + 'driver/:action', { action: '@action' }, {
|
||||
// list methods
|
||||
'listSimple' : { 'method': 'GET', params : { 'action' : 'all' }, isArray: true },
|
||||
'paid' : { 'method': 'GET', params : { 'action' : 'paid' }, isArray: true },
|
||||
}
|
||||
);
|
||||
|
||||
service.paid = function( callback ){
|
||||
drivers.paid( function( data ){
|
||||
callback( data );
|
||||
} );
|
||||
}
|
||||
|
||||
service.listSimple = function( callback ){
|
||||
drivers.listSimple( function( data ){
|
||||
callback( data );
|
||||
|
||||
@ -3,6 +3,10 @@ NGApp.factory( 'SettlementService', function( $resource, $http, $routeParams ) {
|
||||
var service = { restaurants : {}, drivers : {} };
|
||||
var settlement = { restaurants : {}, drivers : {} };
|
||||
|
||||
// constants
|
||||
service.PAY_TYPE_PAYMENT = 'payment';
|
||||
service.PAY_TYPE_REIMBURSEMENT = 'reimbursement';
|
||||
|
||||
service.pay_type_options = [ { 'name': 'All', 'value' : 'all' }, { 'name': 'Check', 'value' : 'check' }, { 'name': 'Deposit', 'value' : 'deposit' } ];
|
||||
service.sort_options = [ { 'name': 'Last Payment', 'value' : 'last_payment' }, { 'name': 'Alphabetical', 'value' : 'alphabetical' } ];
|
||||
|
||||
@ -22,11 +26,16 @@ NGApp.factory( 'SettlementService', function( $resource, $http, $routeParams ) {
|
||||
'scheduled' : { 'method': 'POST', params : { action: 'scheduled' } }
|
||||
} );
|
||||
|
||||
settlement.drivers = $resource( App.service + 'settlement/drivers/:action/', { action: '@action' }, {
|
||||
settlement.drivers = $resource( App.service + 'settlement/drivers/:action/:id_payment_schedule/', { action: '@action', id_payment_schedule: '@id_payment_schedule' }, {
|
||||
'range' : { 'method': 'GET', params : { action: 'range' } },
|
||||
'do_not_pay_driver' : { 'method': 'POST', params : { action: 'do-not-pay-driver' } },
|
||||
'transfer_driver' : { 'method': 'POST', params : { action: 'transfer-driver' } },
|
||||
'schedule' : { 'method': 'POST', params : { action: 'schedule' } },
|
||||
'scheduled' : { 'method': 'POST', params : { action: 'scheduled' } },
|
||||
'scheduled_payment' : { 'method': 'POST', params : { action: 'scheduled' } },
|
||||
'do_payment' : { 'method': 'POST', params : { action: 'do-payment' } },
|
||||
'payment' : { 'method': 'POST', params : { action: 'payment' } },
|
||||
'payments' : { 'method': 'POST', params : { action: 'payments' } },
|
||||
'begin' : { 'method': 'POST', params : { action: 'begin' } }
|
||||
} );
|
||||
|
||||
@ -143,6 +152,44 @@ NGApp.factory( 'SettlementService', function( $resource, $http, $routeParams ) {
|
||||
} );
|
||||
}
|
||||
|
||||
service.drivers.scheduled = function( params, callback ){
|
||||
settlement.drivers.scheduled( params, function( json ){
|
||||
callback( json );
|
||||
} );
|
||||
}
|
||||
|
||||
service.drivers.do_payment = function( id_payment_schedule, callback ){
|
||||
settlement.drivers.do_payment( { 'id_payment_schedule' : id_payment_schedule }, function( json ){
|
||||
callback( json );
|
||||
} );
|
||||
}
|
||||
|
||||
service.drivers.scheduled_payment = function( callback ){
|
||||
settlement.drivers.scheduled_payment( { 'id_payment_schedule' : $routeParams.id }, function( json ){
|
||||
callback( json );
|
||||
} );
|
||||
}
|
||||
|
||||
service.drivers.payments = function( params, callback ){
|
||||
settlement.drivers.payments( { 'page' : params.page, 'id_driver' : params.id_driver, 'pay_type': params.pay_type }, function( json ){
|
||||
callback( json );
|
||||
} );
|
||||
}
|
||||
|
||||
service.drivers.payment = function( callback ){
|
||||
settlement.drivers.payment( { 'id_payment_schedule' : $routeParams.id }, function( json ){
|
||||
callback( json );
|
||||
} );
|
||||
}
|
||||
|
||||
service.pay_types = function(){
|
||||
var tips = [];
|
||||
tips.push( { type: 0, label: 'All' } );
|
||||
tips.push( { type: service.PAY_TYPE_PAYMENT, label: 'Payment' } );
|
||||
tips.push( { type: service.PAY_TYPE_REIMBURSEMENT, label: 'Reimbursement' } );
|
||||
return tips;
|
||||
}
|
||||
|
||||
service.drivers.range = function( callback ){
|
||||
settlement.drivers.range( function( json ){
|
||||
callback( json );
|
||||
|
||||
@ -1136,6 +1136,9 @@ h3.title{
|
||||
border: 2px solid $green;
|
||||
color: $green;
|
||||
}
|
||||
.box-filter .button-big{
|
||||
width: 12em;
|
||||
}
|
||||
|
||||
.box-filter .search {
|
||||
width:15em;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user