diff --git a/db/migrate/000249_admin_payment_type_trackchange.sql b/db/migrate/000249_admin_payment_type_trackchange.sql
new file mode 100644
index 000000000..75859a776
--- /dev/null
+++ b/db/migrate/000249_admin_payment_type_trackchange.sql
@@ -0,0 +1,22 @@
+CREATE TABLE `admin_payment_type_change_set` (
+ `id_admin_payment_type_change_set` int(11) unsigned NOT NULL AUTO_INCREMENT,
+ `id_admin_payment_type` int(11) unsigned DEFAULT NULL,
+ `timestamp` timestamp NULL DEFAULT NULL,
+ `id_admin` int(11) unsigned DEFAULT NULL,
+ PRIMARY KEY (`id_admin_payment_type_change_set`),
+ KEY `id_admin_payment_type` (`id_admin_payment_type`),
+ KEY `id_admin` (`id_admin`),
+ CONSTRAINT `admin_payment_type_change_set_ibfk_1` FOREIGN KEY (`id_admin_payment_type`) REFERENCES `admin_payment_type` (`id_admin_payment_type`) ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT `admin_payment_type_change_set_ibfk_2` FOREIGN KEY (`id_admin`) REFERENCES `admin` (`id_admin`) ON DELETE SET NULL ON UPDATE CASCADE
+) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
+
+CREATE TABLE `admin_payment_type_change` (
+ `id_admin_payment_type_change` int(11) unsigned NOT NULL AUTO_INCREMENT,
+ `id_admin_payment_type_change_set` int(11) unsigned DEFAULT NULL,
+ `field` varchar(255) DEFAULT NULL,
+ `old_value` varchar(255) DEFAULT NULL,
+ `new_value` varchar(255) DEFAULT NULL,
+ PRIMARY KEY (`id_admin_payment_type_change`),
+ KEY `id_admin_payment_type_change_set` (`id_admin_payment_type_change_set`),
+ CONSTRAINT `admin_payment_type_change_ibfk_1` FOREIGN KEY (`id_admin_payment_type_change_set`) REFERENCES `admin_payment_type_change_set` (`id_admin_payment_type_change_set`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
\ No newline at end of file
diff --git a/db/migrate/000250_admin_pexcard_trackchange.sql b/db/migrate/000250_admin_pexcard_trackchange.sql
new file mode 100644
index 000000000..321e647f4
--- /dev/null
+++ b/db/migrate/000250_admin_pexcard_trackchange.sql
@@ -0,0 +1,22 @@
+CREATE TABLE `admin_pexcard_change_set` (
+ `id_admin_pexcard_change_set` int(11) unsigned NOT NULL AUTO_INCREMENT,
+ `id_admin_pexcard` int(11) unsigned DEFAULT NULL,
+ `timestamp` timestamp NULL DEFAULT NULL,
+ `id_admin` int(11) unsigned DEFAULT NULL,
+ PRIMARY KEY (`id_admin_pexcard_change_set`),
+ KEY `id_admin_pexcard` (`id_admin_pexcard`),
+ KEY `id_admin` (`id_admin`),
+ CONSTRAINT `admin_pexcard_change_set_ibfk_1` FOREIGN KEY (`id_admin_pexcard`) REFERENCES `admin_pexcard` (`id_admin_pexcard`) ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT `admin_pexcard_change_set_ibfk_2` FOREIGN KEY (`id_admin`) REFERENCES `admin` (`id_admin`) ON DELETE SET NULL ON UPDATE CASCADE
+) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
+
+CREATE TABLE `admin_pexcard_change` (
+ `id_admin_pexcard_change` int(11) unsigned NOT NULL AUTO_INCREMENT,
+ `id_admin_pexcard_change_set` int(11) unsigned DEFAULT NULL,
+ `field` varchar(255) DEFAULT NULL,
+ `old_value` varchar(255) DEFAULT NULL,
+ `new_value` varchar(255) DEFAULT NULL,
+ PRIMARY KEY (`id_admin_pexcard_change`),
+ KEY `id_admin_pexcard_change_set` (`id_admin_pexcard_change_set`),
+ CONSTRAINT `admin_pexcard_change_ibfk_1` FOREIGN KEY (`id_admin_pexcard_change_set`) REFERENCES `admin_pexcard_change_set` (`id_admin_pexcard_change_set`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
\ No newline at end of file
diff --git a/include/controllers/default/cockpit2/api/pexcard/CardLog.php b/include/controllers/default/cockpit2/api/pexcard/CardLog.php
new file mode 100644
index 000000000..34e33e890
--- /dev/null
+++ b/include/controllers/default/cockpit2/api/pexcard/CardLog.php
@@ -0,0 +1,110 @@
+permission()->check( ['global', 'settlement', 'support-all', 'support-crud' ] ) ){
+ $this->_error();
+ }
+
+ $limit = $this->request()['limit'] ? c::db()->escape($this->request()['limit']) : 20;
+ $search = $this->request()['search'] ? c::db()->escape($this->request()['search']) : '';
+ $type = $this->request()['type'] ? c::db()->escape($this->request()['type']) : 'all';
+ $status = $this->request()['status'] ? c::db()->escape($this->request()['status']) : 'all';
+ $page = $this->request()['page'] ? c::db()->escape($this->request()['page']) : 1;
+
+ if ($page == 1) {
+ $offset = '0';
+ } else {
+ $offset = ($page-1) * $limit;
+ }
+
+ $q = '
+ SELECT -WILD-
+ FROM
+ (SELECT
+ s.name AS `staff_name`,
+ a.name AS `admin_name`,
+ aptcs.timestamp,
+ NULL AS `card_serial`,
+ new_value AS `value`,
+ "using_pex" AS `type`
+ FROM admin_payment_type_change_set aptcs
+ INNER JOIN admin_payment_type_change aptc ON aptcs.id_admin_payment_type_change_set = aptc.id_admin_payment_type_change_set
+ AND aptc.field = "using_pex"
+ INNER JOIN admin_payment_type apt ON apt.id_admin_payment_type = aptcs.id_admin_payment_type
+ INNER JOIN admin s ON s.id_admin = apt.id_admin
+ INNER JOIN admin a ON a.id_admin = aptcs.id_admin
+
+ UNION
+
+ SELECT
+ s.name AS `staff_name`,
+ a.name AS `admin_name`,
+ apcs.timestamp,
+ ap.card_serial,
+ new_value AS `value`,
+ "card_assign" AS `type`
+ FROM admin_pexcard_change_set apcs
+ INNER JOIN admin_pexcard_change apc ON apcs.id_admin_pexcard_change_set = apc.id_admin_pexcard_change_set
+ AND apc.field = "id_admin"
+ INNER JOIN admin_pexcard ap ON ap.id_admin_pexcard = apcs.id_admin_pexcard
+ INNER JOIN admin s ON s.id_admin = apc.new_value
+ INNER JOIN admin a ON a.id_admin = apcs.id_admin ) log WHERE 1 = 1
+ ';
+
+ if ($type != 'all') {
+ $q .= '
+ AND log.type = "' . $type . '"
+ ';
+ }
+
+ if ($search) {
+ $q .= Crunchbutton_Query::search([
+ 'search' => stripslashes($search),
+ 'fields' => [
+ 'log.staff_name' => 'like',
+ 'log.admin_name' => 'like',
+ 'log.card_serial' => 'like'
+ ]
+ ]);
+ }
+
+
+ // get the count
+ $r = c::db()->get(str_replace('-WILD-','COUNT(*) c', $q));
+ $count = intval( $r->_items[0]->c );
+
+ $q .= '
+ ORDER BY log.timestamp DESC
+ LIMIT '.$offset.', '.$limit . '
+ ';
+
+ // do the query
+ $d = [];
+ $r = c::db()->query(str_replace('-WILD-','*', $q));
+
+ while ($o = $r->fetch()) {
+ $date = new DateTime($o->timestamp, new DateTimeZone(c::config()->timezone));;
+ $o->date = $date->format( 'M jS Y g:i:s A T' );
+ unset( $o->timestamp );
+ $d[] = $o;
+ }
+
+ echo json_encode([
+ 'count' => intval($count),
+ 'pages' => ceil($count / $limit),
+ 'page' => $page,
+ 'results' => $d
+ ]);
+
+ exit;
+ }
+
+ private function _error( $error = 'invalid request' ){
+ echo json_encode( [ 'error' => $error ] );
+ exit();
+ }
+
+}
\ No newline at end of file
diff --git a/include/controllers/default/cockpit2/api/pexcard/log.php b/include/controllers/default/cockpit2/api/pexcard/log.php
index 0904baae7..0baa68291 100644
--- a/include/controllers/default/cockpit2/api/pexcard/log.php
+++ b/include/controllers/default/cockpit2/api/pexcard/log.php
@@ -87,11 +87,8 @@ class Controller_api_PexCard_Log extends Crunchbutton_Controller_RestAccount {
// get the count
- $count = 0;
- $r = c::db()->query(str_replace('-WILD-','COUNT(*) c', $q));
- while ($c = $r->fetch()) {
- $count++;
- }
+ $r = c::db()->get(str_replace('-WILD-','COUNT(*) c', $q));
+ $count = intval( $r->_items[0]->c );
$q .= '
ORDER BY pa.id_pexcard_action DESC
@@ -102,6 +99,7 @@ class Controller_api_PexCard_Log extends Crunchbutton_Controller_RestAccount {
$d = [];
$r = c::db()->query(str_replace('-WILD-','
pa.id_pexcard_action,
+ pa.date,
pa.status,
a.name AS `driver`,
a.login,
@@ -119,6 +117,8 @@ class Controller_api_PexCard_Log extends Crunchbutton_Controller_RestAccount {
', $q));
while ($o = $r->fetch()) {
+ $date = new DateTime($o->date, new DateTimeZone(c::config()->timezone));;
+ $o->date = $date->format( 'M jS Y g:i:s A T' );
$d[] = $o;
}
diff --git a/include/controllers/default/cockpit2/api/staff/payinfo.php b/include/controllers/default/cockpit2/api/staff/payinfo.php
index 3d8c4c044..37ea230a4 100644
--- a/include/controllers/default/cockpit2/api/staff/payinfo.php
+++ b/include/controllers/default/cockpit2/api/staff/payinfo.php
@@ -67,7 +67,6 @@ class Controller_api_staff_payinfo extends Crunchbutton_Controller_RestAccount {
$payment_type->using_pex = ( intval( $this->request()[ 'using_pex' ] ) ? intval( $this->request()[ 'using_pex' ] ) : 0 );
-
if( $this->request()[ 'using_pex_date_formatted' ] ){
$payment_type->using_pex_date = ( new DateTime( $this->request()[ 'using_pex_date_formatted' ] ) )->format( 'Y-m-d H:i:s' );
} else {
diff --git a/include/library/Cockpit/Admin/Pexcard.php b/include/library/Cockpit/Admin/Pexcard.php
index 846292745..9b8e30854 100644
--- a/include/library/Cockpit/Admin/Pexcard.php
+++ b/include/library/Cockpit/Admin/Pexcard.php
@@ -1,6 +1,6 @@
{$this->idVar()}) {
+ $this->_changeSet = new Cockpit_Admin_Pexcard_Trackchange(Cana_Changeset::save($this));
+ }
+ parent::save();
+ }
+
+ public function changeSet() {
+ if (!isset($this->_changeSet)) {
+ $sets = $this->changeSets();
+ $this->_changeSet = array_pop($sets);
+ }
+ return $this->_changeSet;
+ }
+}
\ No newline at end of file
diff --git a/include/library/Crunchbutton/Admin/Payment/Type.php b/include/library/Crunchbutton/Admin/Payment/Type.php
index 441fc5f8e..bdf7e0d48 100644
--- a/include/library/Crunchbutton/Admin/Payment/Type.php
+++ b/include/library/Crunchbutton/Admin/Payment/Type.php
@@ -1,6 +1,6 @@
{$this->idVar()}) {
+ $this->_changeSet = new Crunchbutton_Admin_Payment_Type_Trackchange(Cana_Changeset::save($this));
+ }
+ parent::save();
+ }
+
+ public function changeSet() {
+ if (!isset($this->_changeSet)) {
+ $sets = $this->changeSets();
+ $this->_changeSet = array_pop($sets);
+ }
+ return $this->_changeSet;
+ }
+}
\ No newline at end of file
diff --git a/include/library/Crunchbutton/Pexcard/Action.php b/include/library/Crunchbutton/Pexcard/Action.php
index 5f2b6019f..62ff942a2 100644
--- a/include/library/Crunchbutton/Pexcard/Action.php
+++ b/include/library/Crunchbutton/Pexcard/Action.php
@@ -13,7 +13,7 @@ class Crunchbutton_Pexcard_Action extends Cana_Table {
const STATUS_DONE = 'done';
const STATUS_ERROR = 'error';
- const MAX_TRIES = 1;
+ const MAX_TRIES = 3;
const TYPE_CREDIT = 'credit';
const TYPE_DEBIT = 'debit';
diff --git a/include/views/default/cockpit/orders/content.phtml b/include/views/default/cockpit/orders/content.phtml
index 3c94484a4..c0eb093c5 100644
--- a/include/views/default/cockpit/orders/content.phtml
+++ b/include/views/default/cockpit/orders/content.phtml
@@ -115,8 +115,6 @@ $permissionSupportView = c::admin()->permission()->check(['global','support-all'
Balanced transaction
-
-
setTimeZone( new DateTimeZone( c::config()->timezone ) ); ?>
diff --git a/include/views/default/cockpit2/frontend/listview/listview-pexcard-card-log.phtml b/include/views/default/cockpit2/frontend/listview/listview-pexcard-card-log.phtml
new file mode 100644
index 000000000..e89bc6b0e
--- /dev/null
+++ b/include/views/default/cockpit2/frontend/listview/listview-pexcard-card-log.phtml
@@ -0,0 +1,29 @@
+
+
+
+ | Changed by |
+ Staff |
+ Using pex |
+ Card Serial |
+ Type |
+ Date |
+
+
+ | {{l.admin_name}} |
+ {{l.staff_name}} |
+
+
+ Yes
+ No
+
+ -
+ |
+
+ {{l.card_serial}}
+ -
+ |
+ {{l.type}} |
+ {{l.date}} |
+
+
+
\ No newline at end of file
diff --git a/include/views/default/cockpit2/frontend/listview/listview-pexcard-log.phtml b/include/views/default/cockpit2/frontend/listview/listview-pexcard-log.phtml
index da7e68a3b..e02affa6f 100644
--- a/include/views/default/cockpit2/frontend/listview/listview-pexcard-log.phtml
+++ b/include/views/default/cockpit2/frontend/listview/listview-pexcard-log.phtml
@@ -4,6 +4,7 @@
| # |
Driver |
Card Serial / Last Four |
+ Date |
Type |
Amount |
Order |
@@ -16,6 +17,7 @@
{{l.id_pexcard_action}} |
{{l.driver}} |
{{l.card_serial}} / {{l.last_four}} |
+ {{l.date}} |
{{l.type}} |
${{l.amount | formatPrice}} |
|
diff --git a/include/views/default/cockpit2/frontend/pexcard/pexcard-card-log.phtml b/include/views/default/cockpit2/frontend/pexcard/pexcard-card-log.phtml
new file mode 100644
index 000000000..a7126ce61
--- /dev/null
+++ b/include/views/default/cockpit2/frontend/pexcard/pexcard-card-log.phtml
@@ -0,0 +1,26 @@
+
+
+
+
Pex Card: Card Activations Log
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/include/views/default/cockpit2/frontend/pexcard/pexcard.phtml b/include/views/default/cockpit2/frontend/pexcard/pexcard.phtml
index 8adeaa591..db29ddc57 100644
--- a/include/views/default/cockpit2/frontend/pexcard/pexcard.phtml
+++ b/include/views/default/cockpit2/frontend/pexcard/pexcard.phtml
@@ -7,6 +7,7 @@
| Assign Pex Card to Driver |
| Transactions log |
| Pex Card Report |
+ | Card Activations Log |
diff --git a/www/assets/cockpit/js/cockpit.js b/www/assets/cockpit/js/cockpit.js
index 87533c344..570f497d8 100644
--- a/www/assets/cockpit/js/cockpit.js
+++ b/www/assets/cockpit/js/cockpit.js
@@ -202,6 +202,11 @@ NGApp.config(['$routeProvider', '$locationProvider', function($routeProvider, $l
controller: 'PexCardLogCtrl',
templateUrl: 'assets/view/pexcard-log.html'
})
+ .when('/pexcard/card/log', {
+ action: 'pexcard',
+ controller: 'PexCardCardLogCtrl',
+ templateUrl: 'assets/view/pexcard-card-log.html'
+ })
.when('/pexcard/log/:id', {
action: 'pexcard',
controller: 'PexCardLogViewCtrl',
diff --git a/www/assets/cockpit/js/controllers.pexcard.js b/www/assets/cockpit/js/controllers.pexcard.js
index 63c884e7e..175e9cfea 100644
--- a/www/assets/cockpit/js/controllers.pexcard.js
+++ b/www/assets/cockpit/js/controllers.pexcard.js
@@ -177,7 +177,6 @@ NGApp.controller('PexCardLogCtrl', function ($scope, PexCardService, ViewListSer
scope: $scope,
watch: {
search: '',
- type: 'all',
status: 'all',
type: 'all',
_action: 'all'
@@ -190,3 +189,22 @@ NGApp.controller('PexCardLogCtrl', function ($scope, PexCardService, ViewListSer
}
});
});
+
+NGApp.controller('PexCardCardLogCtrl', function ($scope, PexCardService, ViewListService) {
+
+ angular.extend( $scope, ViewListService );
+
+ $scope.view({
+ scope: $scope,
+ watch: {
+ search: '',
+ type: 'all',
+ },
+ update: function() {
+ PexCardService.cardlog($scope.query, function(d) {
+ $scope.logs = d.results;
+ $scope.complete(d);
+ });
+ }
+ });
+});
diff --git a/www/assets/cockpit/js/controllers.staff.js b/www/assets/cockpit/js/controllers.staff.js
index 1914874ee..ed88e8dac 100644
--- a/www/assets/cockpit/js/controllers.staff.js
+++ b/www/assets/cockpit/js/controllers.staff.js
@@ -247,10 +247,11 @@ NGApp.controller('StaffPayInfoCtrl', function( $scope, $filter, StaffPayInfoServ
$scope.$watch( 'payInfo.using_pex', function( newValue, oldValue, scope ) {
if( parseInt( $scope.payInfo.using_pex ) == 0 ){
using_pex_date = $scope.payInfo.using_pex_date;
- $scope.payInfo.using_pex_date = new Date( '0000,00,00' );
+ //
+ $scope.payInfo.using_pex_date = '';
} else {
- if( using_pex_date ){
- $scope.payInfo.using_pex_date = using_pex_date;
+ if( !$scope.payInfo.using_pex_date ){
+ $scope.payInfo.using_pex_date = new Date();
}
}
@@ -262,7 +263,7 @@ NGApp.controller('StaffPayInfoCtrl', function( $scope, $filter, StaffPayInfoServ
$scope.submitted = true;
return;
}
- if( !isNaN( $scope.payInfo.using_pex_date.getTime() ) ){
+ if( $scope.payInfo.using_pex_date && !isNaN( $scope.payInfo.using_pex_date.getTime() ) ){
$scope.payInfo.using_pex_date_formatted = $filter( 'date' )( $scope.payInfo.using_pex_date, 'yyyy-MM-dd' )
} else {
$scope.payInfo.using_pex_date_formatted = null;
diff --git a/www/assets/cockpit/js/service.pexcard.js b/www/assets/cockpit/js/service.pexcard.js
index d5a5b5918..a93f94676 100644
--- a/www/assets/cockpit/js/service.pexcard.js
+++ b/www/assets/cockpit/js/service.pexcard.js
@@ -12,6 +12,7 @@ NGApp.factory( 'PexCardService', function( $resource, $http, $routeParams ) {
'pex_change_card_status' : { 'method': 'POST', params : { action: 'pexcard-change-card-status' } },
'report' : { 'method': 'POST', params : { action: 'report' } },
'logs' : { 'method': 'GET', params : { action: 'log' } },
+ 'cardlog' : { 'method': 'GET', params : { action: 'cardlog' } },
'action' : { 'method': 'GET', params : { action: 'log' } }
} );
@@ -27,8 +28,6 @@ NGApp.factory( 'PexCardService', function( $resource, $http, $routeParams ) {
} );
}
-
-
service.driver_search = function( params, callback ){
pexcard.driver_search( params, function( data ){
callback( data );
@@ -71,6 +70,12 @@ NGApp.factory( 'PexCardService', function( $resource, $http, $routeParams ) {
} );
}
+ service.cardlog = function(params, callback) {
+ pexcard.cardlog(params).$promise.then(function success(data, responseHeaders) {
+ callback(data);
+ });
+ }
+
service.logs = function(params, callback) {
pexcard.logs(params).$promise.then(function success(data, responseHeaders) {
callback(data);