diff --git a/include/controllers/default/cockpit2/api/settlement/index.php b/include/controllers/default/cockpit2/api/settlement/index.php index abfa53556..00bdafcd3 100644 --- a/include/controllers/default/cockpit2/api/settlement/index.php +++ b/include/controllers/default/cockpit2/api/settlement/index.php @@ -127,6 +127,12 @@ class Controller_Api_Settlement extends Crunchbutton_Controller_RestAccount { case 'send-summary': $this->_driverSendSummary(); break; + case 'send-summary': + $this->_driverSendSummary(); + break; + case 'do-err-payments': + $this->_driverDoErrPayments(); + break; default: $this->_error(); break; @@ -519,6 +525,12 @@ class Controller_Api_Settlement extends Crunchbutton_Controller_RestAccount { echo json_encode( $out ); } + private function _driverDoErrPayments(){ + $settlement = new Crunchbutton_Settlement; + $settlement->doDriverErrPayments(); + echo json_encode( [ 'success' => true ] ); + } + private function _driverDoNotPayForOrder(){ $id_order = $this->request()['id_order']; $id_driver = $this->request()['id_driver']; diff --git a/include/library/Crunchbutton/Settlement.php b/include/library/Crunchbutton/Settlement.php index 0a5301385..f6c439650 100644 --- a/include/library/Crunchbutton/Settlement.php +++ b/include/library/Crunchbutton/Settlement.php @@ -757,7 +757,6 @@ class Crunchbutton_Settlement extends Cana_Model { } } - if( $shouldSchedule ){ // schedule it @@ -841,6 +840,17 @@ class Crunchbutton_Settlement extends Cana_Model { return true; } + public function doDriverErrPayments(){ + $schedules = Cockpit_Payment_Schedule::q( 'SELECT * FROM payment_schedule WHERE status = "' . Cockpit_Payment_Schedule::STATUS_ERROR . '"' ); + foreach( $schedules as $_schedule ){ + $id_payment_schedule = $_schedule->id_payment_schedule; + $settlement = new Crunchbutton_Settlement; + Cana::timeout( function() use( $settlement, $id_payment_schedule ) { + $settlement->payDriver( $id_payment_schedule ); + } ); + } + } + public function doDriverPayments( $id_payment_schedule = false ){ if( $id_payment_schedule ){ return $this->payDriver( $id_payment_schedule ); diff --git a/include/views/default/cockpit2/frontend/settlement/settlement-drivers-scheduled.phtml b/include/views/default/cockpit2/frontend/settlement/settlement-drivers-scheduled.phtml index c3e6bbee5..311b4601d 100644 --- a/include/views/default/cockpit2/frontend/settlement/settlement-drivers-scheduled.phtml +++ b/include/views/default/cockpit2/frontend/settlement/settlement-drivers-scheduled.phtml @@ -53,6 +53,12 @@
+ + diff --git a/www/assets/cockpit/js/controllers.settlement.js b/www/assets/cockpit/js/controllers.settlement.js index ea79f5274..6fa5b8cfb 100644 --- a/www/assets/cockpit/js/controllers.settlement.js +++ b/www/assets/cockpit/js/controllers.settlement.js @@ -695,6 +695,12 @@ NGApp.controller( 'SettlementDriversScheduledCtrl', function ( $scope, Settlemen } ); } + $scope.do_err_payments = function(){ + SettlementService.drivers.do_err_payments( function(){ + $scope.update(); + } ); + } + $scope.payment = function( id_payment ){ $scope.navigation.link( '/settlement/drivers/scheduled/' + id_payment ); } diff --git a/www/assets/cockpit/js/service.settlement.js b/www/assets/cockpit/js/service.settlement.js index 4050afa8f..9a28724aa 100644 --- a/www/assets/cockpit/js/service.settlement.js +++ b/www/assets/cockpit/js/service.settlement.js @@ -38,6 +38,7 @@ NGApp.factory( 'SettlementService', function( $resource, $http, $routeParams ) { 'scheduled' : { 'method': 'POST', params : { action: 'scheduled' } }, 'scheduled_payment' : { 'method': 'POST', params : { action: 'scheduled' } }, 'do_payment' : { 'method': 'POST', params : { action: 'do-payment' } }, + 'do_err_payments' : { 'method': 'POST', params : { action: 'do-err-payments' } }, 'send_summary' : { 'method': 'POST', params : { action: 'send-summary' } }, 'schedule_arbitrary_payment' : { 'method': 'POST', params : { action: 'schedule-arbitrary-payment' } }, 'payment' : { 'method': 'POST', params : { action: 'payment' } }, @@ -176,6 +177,12 @@ NGApp.factory( 'SettlementService', function( $resource, $http, $routeParams ) { } ); } + service.drivers.do_err_payments = function( callback ){ + settlement.drivers.do_err_payments( {}, function( json ){ + callback( json ); + } ); + } + service.drivers.schedule_arbitrary_payment = function( id_driver, amount, pay_type, notes, callback ){ settlement.drivers.schedule_arbitrary_payment( { 'id_driver': id_driver, 'amount': amount, 'pay_type': pay_type, 'notes': notes }, function( json ){ callback( json );