Recently, I developed a mobile application that can scan QR-CODEs containing various information, including a date. However, there have been changes in the format of the date within the QR-CODE between previous and new versions. Previously, the date was formatted as mm/dd, but now it is yy-MM-dd.
Currently, my app can only scan either the old or the new version of the labels, but not both simultaneously. I am exploring the possibility of using an if statement to detect the old format and convert it to the new one. Here is an example of the code that successfully scans the new labels:
(function(){
'use strict';
var app = angular.module('Controllers', []);
var baseUrl = 'https://apps.laticrete.com/LSCWebApiService/lscapi/';
app.controller('BarcodeCtrl', ['$scope', '$state', '$stateParams', '$http', 'alertsManager', '$timeout', 'localStorageService', '$cordovaBarcodeScanner', '$cordovaGeolocation', '$filter',
function($scope, $state, $stateParams, $http, alertsManager, $timeout, localStorageService, $cordovaBarcodeScanner, $cordovaGeolocation, $filter) {
var SessionId = localStorageService.get('SessionId');
// Get GeoLocation
$cordovaGeolocation
.getCurrentPosition()
.then(function(position) {
$scope.lat = position.coords.latitude;
$scope.long = position.coords.longitude;
});
document.addEventListener("deviceready", function() {
$scope.scanMaterial = function() {
$cordovaBarcodeScanner
.scan()
.then(function(result) {
var codeArray = result.text.split(',');
$scope.SKU = codeArray[1].replace("I:", "").trim();
$scope.ControlNumber = codeArray[0].replace("W:", "").trim();
//$scope.ManufactureDate = codeArray[2].replace("MFG:", "").trim();
$scope.ManufactureDate = codeArray[2].replace("MFG:", "20").replace(/(\d{4})(\d{2})(\d{2})/, "$1-$2-$3").trim();
$scope.BatchCode = codeArray[3].replace("B:", "").trim();
var dataObj = {
SessionId: SessionId,
JobId: $stateParams.JobId,
ManufactureDate: $scope.ManufactureDate,
BatchCode: $scope.BatchCode,
SKU: $scope.SKU,
ControlNumber: $scope.ControlNumber,
CreatedClient: new Date(),
Latitude: $scope.lat,
Longitude: $scope.long,
Product: { Id : 1}
};
$http.post(baseUrl + 'Material/PostNewMaterial', dataObj)
.success(function() {
alertsManager.addAlert('Success: You have successfully added material.', 'alert-success');
$state.go('^');
}).error(function(dataObj) {
alertsManager.addAlert('Failure Meesage: ' + JSON.stringify({dataObj:dataObj}), 'alert-danger');
});
$timeout(function(){
alertsManager.clearAlerts();
}, 5000);
}, function(error) {
console.log("An error has happened " + error);
});
};
}, false);
}]);
})();
I specifically need help with the part of the code related to $scope.ManufactureDate.
Thank you for your assistance.