diff --git a/Apollo/api/application/controllers/Branch_Controller.php b/Apollo/api/application/controllers/Branch_Controller.php index fff50bd3..60c6758f 100755 --- a/Apollo/api/application/controllers/Branch_Controller.php +++ b/Apollo/api/application/controllers/Branch_Controller.php @@ -49,17 +49,25 @@ class Branch_Controller extends REST_Controller { public function addBranchDetails_post() { + $details['BranchCode'] = $this->post('branchCode'); $details['BranchName'] = $this->post('branchName'); - $details['LogoPath'] = $this->post('logo'); + // $details['LogoPath'] = $this->post('logo'); $details['MobileNumber'] = $this->post('primaryPhone'); $details['AlternateNumber'] = $this->post('secondaryPhone'); $details['LandlineNumber'] = $this->post('landLine'); $details['Address'] = $this->post('address'); $details['EmailID'] = $this->post('email'); $details['CreatedBy'] = $this->post('createdBy'); - $details['IsActive'] = $this->post('status'); - $branchDetails = $this->branch_model->addBranch($details);// Check if the users data store contains users (in case the database result returns NULL) + $details['IsActive'] = $this->post('status') == true ? 1 : 0; + + $imageStat = $this->post('imageStatus'); + + $imagename = $imageStat == 1 ? $_FILES['logo']['name'] : ''; + $size = $imageStat == 1 ? $_FILES['logo']['size'] : ''; + $imageSource = $imageStat == 1 ? $_FILES['logo']['tmp_name'] : ''; + + $branchDetails = $this->branch_model->addBranch($details, $imageSource);// Check if the users data store contains users (in case the database result returns NULL) if ($branchDetails) { $branchDetails['status'] = REST_Controller::HTTP_OK; @@ -117,10 +125,18 @@ class Branch_Controller extends REST_Controller { $details['LandlineNumber'] = $this->post('landLine'); $details['Address'] = $this->post('address'); $details['EmailID'] = $this->post('email'); - $details['IsActive'] = $this->post('status'); - $details['UpdatedBy'] = $this->post('updatedBy'); - $details['UpdatedOn'] = date("Y-m-d", time()); - $updateDetails = $this->branch_model->updateBranch($details,$branchCode);// Check if the users data store contains users (in case the database result returns NULL) + $details['IsActive'] = $this->post('status') == true ? 1 : 0; + $details['UpdatedBy'] = $this->post('createdBy'); + $date = date('Y-m-d H:i:s'); + $details['UpdatedOn'] = $date; + + $imageStat = $this->post('imageStatus'); + + $imagename = $imageStat == 1 ? $_FILES['logoEdit']['name'] : ''; + $size = $imageStat == 1 ? $_FILES['logoEdit']['size'] : ''; + $imageSource = $imageStat == 1 ? $_FILES['logoEdit']['tmp_name'] : ''; + + $updateDetails = $this->branch_model->updateBranch($details,$branchCode, $imageSource, $imageStat );// Check if the users data store contains users (in case the database result returns NULL) if ($updateDetails) { $updateDetails['status'] = REST_Controller::HTTP_OK; diff --git a/Apollo/api/application/models/Branch_model.php b/Apollo/api/application/models/Branch_model.php index e124c222..97976bc7 100755 --- a/Apollo/api/application/models/Branch_model.php +++ b/Apollo/api/application/models/Branch_model.php @@ -15,9 +15,14 @@ class Branch_model extends CI_Model { * created by kms * */ - public function addBranch($arrayDetails=null) + public function addBranch($arrayDetails=null, $imageSource) { - + + $target = "../images/logo/"; + $getUploadStatus = $this-> upload_image($imageSource, $target); + $imageNameDb = $getUploadStatus['imageName']; + $arrayDetails['LogoPath'] = $getUploadStatus == true ? "logo/".$imageNameDb : ''; +// print_r($arrayDetails['IsActive']);exit(); $this->db->select('BranchCode'); $this->db->where('BranchCode', $arrayDetails['BranchCode']); if($this->db->get(BRANCH)->first_row()){ @@ -80,12 +85,22 @@ class Branch_model extends CI_Model { * created by kms * */ - public function updateBranch($arrayDetails=null,$branchCode=null) + public function updateBranch($arrayDetails=null,$branchCode=null, $imageSource, $imageStat) { + if( $imageStat == 1 ) { + $target = "../images/logo/"; + $getUploadStatus = $this-> upload_image($imageSource, $target); + $imageNameDb = $getUploadStatus['imageName']; + $arrayDetails['LogoPath'] = $getUploadStatus == true ? "logo/".$imageNameDb : null; + } else { + + } + +// print_r($arrayDetails['IsActive']);exit(); + $this->db->where('BranchCode',$branchCode); $upateStatus=$this->db->update(BRANCH, $arrayDetails); if($upateStatus){ - $result['branchStatus'] = true; $result['message'] = "Successfully branch details updated"; } @@ -101,5 +116,21 @@ class Branch_model extends CI_Model { } + // image upload in taget path + public function upload_image( $imageSource, $target ) { + $key2 = substr(str_shuffle('abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'), 0, 12); + $new_regNo = "Dri_" . $key2 . "." . 'jpeg'; + $targetPlace = $target . $new_regNo; + // echo $targetPlace;exit(); + if(!move_uploaded_file($imageSource , $targetPlace)) + { + return $result['status'] = false; + } else { + $result['status'] = true; + $result['imageName'] = $new_regNo; + return $result; + } + } + } \ No newline at end of file diff --git a/Apollo/assets/js/controllers/branchCtrl.js b/Apollo/assets/js/controllers/branchCtrl.js index 597a85a7..2075a734 100755 --- a/Apollo/assets/js/controllers/branchCtrl.js +++ b/Apollo/assets/js/controllers/branchCtrl.js @@ -49,6 +49,51 @@ app.controller('branchCtrl', ["$scope","toaster", "$filter", "ngTableParams", "A $scope.viewId = pid; $scope.editId = -1; };*/ + + + //--------------------------------------------------------------> + // getting for image to show + //--------------------------------------------------------------> + + $scope.stepsModel = []; + $scope.imageUpload = function (event) { + var files = event.target.files; //FileList object + + for (var i = 0; i < files.length; i++) { + var file = files[i]; + var reader = new FileReader(); + reader.onload = $scope.imageIsLoaded; + reader.readAsDataURL(file); + } + } + + $scope.imageIsLoaded = function (e) { + $scope.$apply(function () { + // $scope.stepsModel.push(e.target.result); + $scope.stepsModel[0] = e.target.result; + }); + } + + + //an array of files selected + $scope.files = []; + + //listen for the file selected event + $scope.$on("fileSelected", function (event, args) { + $scope.$apply(function () { + //add the file object to the scope's files collection + $scope.files[0] = args.file; + }); + }); + + + // reset image + $scope.resetImage = function () { + $scope.files.length = 0; + $scope.stepsModel.length = 0; + } + + /* * Submit,update and reset branch details * @params myModel @@ -72,41 +117,70 @@ app.controller('branchCtrl', ["$scope","toaster", "$filter", "ngTableParams", "A angular.element('.ng-invalid[name=' + firstError + ']').focus(); // swal("The form cannot be submitted because it contains validation errors!", "Errors are marked with a red, dashed border!", "error"); } else { - $scope.ldloading1 = {}; + $scope.ldloading1[loading.replace('-', '_')] = true; + + var formData = new FormData(); + var logo = $scope.files[0]; - $scope.ldloading1[loading.replace('-', '_')] = true; + formData.append("branchCode", myModel.branchCode); + formData.append("branchName", myModel.branchName); + formData.append("email", myModel.email); + formData.append("primaryPhone", myModel.primaryPhone); + formData.append("secondaryPhone", myModel.secondaryPhone); + formData.append("landLine", myModel.landLine); + formData.append("address", myModel.address); + formData.append("status", myModel.switchsetting); + var checkImg = logo == undefined ? 0 : 1; + formData.append("imageStatus", checkImg); + + formData.append("createdBy", JSON.parse(localStorage.getItem('localObj')).localUserID); + formData.append('logo', logo); - var addBranch = { - method: 'POST', - url: apiPoint.url + 'addBranchDetails/', - headers: { - 'Content-Type': 'application/json' - }, - data: { - branchCode: myModel.branchCode, - branchName: myModel.branchName, - email: myModel.email, - primaryPhone: myModel.primaryPhone, - secondaryPhone: myModel.secondaryPhone, - landLine: myModel.landLine, - address: myModel.address, - logo: myModel.logo, - status: myModel.switchsetting, - createdBy: JSON.parse(localStorage.getItem('localObj')).localUserID + $http.post(apiPoint.url + 'addBranchDetails/', formData, { + transformRequest: angular.identity, + headers: { 'Content-Type': undefined, 'Process-Data': false }, + }).success(function (data) { + if (data.status==200 && data.branchStatus) { + $scope.ldloading1[loading.replace('-', '_')] = false; + swal("Success!", data.message, "success"); + $state.go($state.current, {}, {reload: true}); + } else { + $scope.ldloading1[loading.replace('-', '_')] = false; + swal("Failed!", data.message, "error"); } - }; - $http(addBranch).then(function (response) { - if (response.data.status==200 && response.data.branchStatus) { - $scope.ldloading1[loading.replace('-', '_')] = false; - swal("Success!", response.data.message, "success"); - $state.go($state.current, {}, {reload: true}); - } else { - $scope.ldloading1[loading.replace('-', '_')] = false; - swal("Failed!", response.data.message, "error"); - } - }); + }); + + // var addBranch = { + // method: 'POST', + // url: apiPoint.url + 'addBranchDetails/', + // headers: { + // 'Content-Type': 'application/json' + // }, + // data: { + // branchCode: myModel.branchCode, + // branchName: myModel.branchName, + // email: myModel.email, + // primaryPhone: myModel.primaryPhone, + // secondaryPhone: myModel.secondaryPhone, + // landLine: myModel.landLine, + // address: myModel.address, + // logo: myModel.logo, + // status: myModel.switchsetting, + // createdBy: JSON.parse(localStorage.getItem('localObj')).localUserID + // } + // }; + // $http(addBranch).then(function (response) { + // if (response.data.status==200 && response.data.branchStatus) { + // $scope.ldloading1[loading.replace('-', '_')] = false; + // swal("Success!", response.data.message, "success"); + // $state.go($state.current, {}, {reload: true}); + // } else { + // $scope.ldloading1[loading.replace('-', '_')] = false; + // swal("Failed!", response.data.message, "error"); + // } + // }); } @@ -130,6 +204,46 @@ app.controller('branchCtrl', ["$scope","toaster", "$filter", "ngTableParams", "A } }; + + + + + $scope.stepsModelEdit = []; + $scope.imageUploadEdit = function (event) { + var files = event.target.files; //FileList object + + for (var i = 0; i < files.length; i++) { + var file = files[i]; + var reader = new FileReader(); + reader.onload = $scope.imageIsLoadedEdit; + reader.readAsDataURL(file); + } + } + + $scope.imageIsLoadedEdit = function (e) { + $scope.$apply(function () { + // $scope.stepsModel.push(e.target.result); + $scope.stepsModelEdit[0] = e.target.result; + }); + } + + //an array of files selected + $scope.filesEdit = []; + //listen for the file selected event + $scope.$on("fileSelectedEdit", function (event, args) { + $scope.$apply(function () { + //add the file object to the scope's files collection + $scope.filesEdit[0] = args.file; + }); + }); + + + // reset image for Edit + $scope.resetImageEdit = function () { + $scope.filesEdit.length = 0; + $scope.stepsModelEdit.length = 0; + } + /* * update the branch details * created by kms @@ -155,39 +269,72 @@ app.controller('branchCtrl', ["$scope","toaster", "$filter", "ngTableParams", "A $scope.ldloading = {}; $scope.ldloading[loading.replace('-', '_')] = true; + + var formData = new FormData(); + var logoEdit = $scope.filesEdit[0]; + formData.append("branchCode", myModel.BranchCode); + formData.append("branchName", myModel.BranchName); + formData.append("email", myModel.EmailID); + formData.append("primaryPhone", myModel.MobileNumber); + formData.append("secondaryPhone", myModel.AlternateNumber); + formData.append("landLine", myModel.LandlineNumber); + formData.append("address", myModel.Address); + formData.append("status", myModel.IsActive); + formData.append("logo", myModel.LogoPath); - var update = { - method: 'POST', - url: apiPoint.url + 'updateBranchDetails/', - headers: { - 'Content-Type': 'application/json' - }, - data: { - branchCode: myModel.BranchCode, - branchName: myModel.BranchName, - email: myModel.EmailID, - primaryPhone: myModel.MobileNumber, - secondaryPhone: myModel.AlternateNumber, - landLine: myModel.LandlineNumber, - address: myModel.Address, - logo: myModel.LogoPath, - status: myModel.IsActive, - createdBy: JSON.parse(localStorage.getItem('localObj')).localUserID - } - }; - $http(update).then(function (response) { - if (response.data.status==200 && response.data.branchStatus) { - $scope.ldloading[loading.replace('-', '_')] = false; - swal("Success!", response.data.message, "success"); - $scope.editId = -1; - $scope.init(); + var checkImg = logoEdit == undefined ? 0 : 1; + formData.append("imageStatus", checkImg); + + formData.append("createdBy", JSON.parse(localStorage.getItem('localObj')).localUserID); + formData.append('logoEdit', logoEdit); - } else { - $scope.ldloading[loading.replace('-', '_')] = false; - swal("Failed!", response.data.message, "error"); - } - }); + $http.post(apiPoint.url + 'updateBranchDetails/', formData, { + transformRequest: angular.identity, + headers: { 'Content-Type': undefined, 'Process-Data': false }, + }).success(function (data) { + if (data.status==200 && data.branchStatus) { + $scope.ldloading[loading.replace('-', '_')] = false; + swal("Success!", data.message, "success"); + $scope.editId = -1; + $scope.init(); + } else { + $scope.ldloading1[loading.replace('-', '_')] = false; + swal("Failed!", data.message, "error"); + } + }); + + // var update = { + // method: 'POST', + // url: apiPoint.url + 'updateBranchDetails/', + // headers: { + // 'Content-Type': 'application/json' + // }, + // data: { + // branchCode: myModel.BranchCode, + // branchName: myModel.BranchName, + // email: myModel.EmailID, + // primaryPhone: myModel.MobileNumber, + // secondaryPhone: myModel.AlternateNumber, + // landLine: myModel.LandlineNumber, + // address: myModel.Address, + // logo: myModel.LogoPath, + // status: myModel.IsActive, + // createdBy: JSON.parse(localStorage.getItem('localObj')).localUserID + // } + // }; + // $http(update).then(function (response) { + // if (response.data.status==200 && response.data.branchStatus) { + // $scope.ldloading[loading.replace('-', '_')] = false; + // swal("Success!", response.data.message, "success"); + // $scope.editId = -1; + // $scope.init(); + + // } else { + // $scope.ldloading[loading.replace('-', '_')] = false; + // swal("Failed!", response.data.message, "error"); + // } + // }); } }; /* @@ -243,3 +390,37 @@ app.controller('branchCtrl', ["$scope","toaster", "$filter", "ngTableParams", "A }; }]); + +// file upload directive +app.directive('fileUpload', function () { + return { + scope: true, //create a new scope + link: function (scope, el, attrs) { + el.bind('change', function (event) { + var files = event.target.files; + //iterate files since 'multiple' may be specified on the element + for (var i = 0; i < files.length; i++) { + //emit event upward + scope.$emit("fileSelected", { file: files[i] }); + } + }); + } + }; +}); + +// file upload directive +app.directive('fileUploadEdit', function () { + return { + scope: true, //create a new scope + link: function (scope, el, attrs) { + el.bind('change', function (event) { + var files = event.target.files; + //iterate files since 'multiple' may be specified on the element + for (var i = 0; i < files.length; i++) { + //emit event upward + scope.$emit("fileSelectedEdit", { file: files[i] }); + } + }); + } + }; +}); diff --git a/Apollo/assets/views/branchDetails.html b/Apollo/assets/views/branchDetails.html index 1c4c5a5e..affc222c 100755 --- a/Apollo/assets/views/branchDetails.html +++ b/Apollo/assets/views/branchDetails.html @@ -4,8 +4,6 @@ border-radius: 60px; box-shadow: 0px 0px 2px #007AFF; padding: 0.5em 0.6em; - - } @@ -30,8 +28,14 @@