'use strict'; /** * controllers for ng-table * Simple table with sorting and filtering on AngularJS */ app.controller('staffCtrl', ["$scope", "toaster", "$filter", "ngTableParams", "$http",'fileUpload', "API_POINTS", "$state", '$rootScope', '$cookies', 'md5', 'ipCookie', '$timeout', '$window', "flowFactory", function ($scope, toaster, $filter, ngTableParams, $http, fileUpload, apiPoint, $state, $rootScope, $cookies, md5, ipCookie, $timeout, $window, flowFactory) { // $scope.removeImage = function () { // $scope.noImage = true; // }; // $scope.obj = new Flow(); // if ($scope.userInfo.avatar == '') { // $scope.noImage = true; // } /** * staff details capture * by : kdk */ $scope.myModel = { 'employeeId': '', 'firstname': '', 'lastname': '', 'fathername': '', 'mothername': '', 'emailId': '', 'primaryPhone': '', 'secondaryPhone': '', 'dateofbirth': '', 'gender': '', 'qualificaion': '', 'aadharNumber': '', 'otherId': '', 'otherIdDetails': '', 'address1': '', 'address2': '', 'homeBranch': '', 'dateofjoining': '', 'dateofjoining': '', 'role': '', 'switchsetting': true, }; var data = ''; $scope.roleDetails = ''; $scope.branchDetails = ''; $scope.employeeDetails = ''; $scope.loader = false; $scope.emptyData; // 2017-11-23T00:00:00+0530 // sorting function for table params $scope.sort = function (keyname) { $scope.sortKey = keyname; //set the sortKey to the param passed $scope.reverse = !$scope.reverse; //if true make it false and vice versa } // get local cliend details var localDetail = JSON.parse(localStorage.getItem('localObj')); var localDetails = ipCookie('cookiechk'); // load when html page load $scope.init = function () { if (localDetail != null) { $scope.currentDate = new Date(); // $scope.currentPage = 1; $scope.getEmployeeList(); $scope.getRoleList(); $scope.getBranchDetails(); } else { } } $scope.getEmployeeList = function () { $scope.loader = true; var empListreq = { method: 'POST', url: apiPoint.url + 'getEmployeeList/', headers: { 'Content-Type': 'application/json' }, data: { data: localDetails } }; $http(empListreq).then(function (response) { if (response.data.employeeList) { $scope.loader = false; $scope.emptyData = true; $scope.data = response.data.employees_details; // data = response.data.employees_details; // $scope.$watch('result', function () { // $scope.tableParams.settings().$scope = $scope; // $scope.tableParams.reload(); // }); // if( data.length <= 2) { // $scope.currentPage = $scope.currentPage; // } else { // $scope.currentPage = $scope.currentPage-1; // } // $scope.intial = response.data.employees_details; // $scope.search = { StaffID: '' }; // $scope.tableParams = new ngTableParams({ // page: 1, // count: 10, // filter: $scope.search // }, { // // total: data.length, // getData: function ($defer, params) { // $scope.currentPage = params.page() // data; // params.total(data.length) // var orderedData = params.sorting() ? $filter('orderBy')(data, params.orderBy()) : data; // orderedData = params.filter() ? $filter('filter')(orderedData, params.filter().StaffID) : orderedData; // $defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count())); // } // }); } else { $scope.loader = false; $scope.emptyData = false; } }); } $scope.editId = -1; $scope.editBranchId = -1; $scope.setEditId = function (id) { $scope.editId = id; $scope.editBranchId = -1; } $scope.setEditBranchId = function (id) { $scope.getEmpBranchDetails(id); $scope.editBranchId = id; $scope.editId = -1; $scope.branchEditLoading = true; } $scope.cancel = function () { $scope.getEmployeeList(); $scope.editId = -1; $scope.editBranchId = -1; } $scope.empBranchDetails = ''; $scope.empRoleDetail = ''; $scope.getEmpBranchDetails = function (id) { // alert(id); var req = { method: 'POST', url: apiPoint.url + 'getEmpBranchDetails/', headers: { 'Content-Type': 'application/json' }, data: { staffID: id } }; $http(req).then(function (response) { if (response.data.empBranchDetails) { // $scope.editBranchId = id; $scope.branchEditLoading = false; $scope.empBranchs = response.data.branch_details; $scope.branchArr = []; angular.forEach($scope.empBranchs, function (item, index) { // alert(item.BranchName); $scope.branchArr.push(item.BranchName); }); $scope.empBranchDetails = { arr: $scope.branchArr, } $scope.empRoleDetail = response.data.role_details[0]; } else { } }); } $scope.getRoleList = function () { var req = { method: 'POST', url: apiPoint.url + 'getRoleDetails/', headers: { 'Content-Type': 'application/json' }, data: { reqRoleID: localDetails.localType } }; $http(req).then(function (response) { if (response.data.RoleDetailStatus) { $scope.roleDetails = response.data.role_details; } else { } }); } $scope.getBranchDetails = function () { var req = { method: 'POST', url: apiPoint.url + 'getMasterBranchDetails/', headers: { 'Content-Type': 'application/json' }, data: { reqRoleID: localDetails.localType, reqUserID: localDetails.localUserID, } }; $http(req).then(function (response) { if (response.data.MeasterBranchDetailStatus == true) { $scope.branchDetails = response.data.branch_details; $scope.branchDetailsName = []; angular.forEach($scope.branchDetails, function (item, index) { // alert(item.BranchName); $scope.branchDetailsName.push(item.BranchName); }); } else { } }); } // check employee Id existing $scope.checkEmpIdExist = function () { var checkReq = { method: 'POST', url: apiPoint.url + 'chkEmpExistDetail/', headers: { 'Content-Type': 'application/json' }, data: { data: $scope.myModel.employeeId, check: 'employeeId' } }; $http(checkReq).then(function (response) { if (response.data.existEmpId == true) { swal("Warning!", response.data.message, "warning"); $scope.myModel.employeeId = ''; } else { } }); } // check mobile number existing $scope.checkMobileExist = function () { var checkReq = { method: 'POST', url: apiPoint.url + 'chkEmpExistDetail/', headers: { 'Content-Type': 'application/json' }, data: { data: $scope.myModel.primaryPhone, check: 'mobileNumber' } }; $http(checkReq).then(function (response) { if (response.data.existMobile == true) { swal("Warning!", response.data.message, "warning"); $scope.myModel.primaryPhone = ''; } else { } }); } // check emailId existing $scope.checkEmailExist = function () { var checkReq = { method: 'POST', url: apiPoint.url + 'chkEmpExistDetail/', headers: { 'Content-Type': 'application/json' }, data: { data: $scope.myModel.emailId, check: 'emailId' } }; $http(checkReq).then(function (response) { if (response.data.existEmailId == true) { swal("Warning!", response.data.message, "warning"); $scope.myModel.emailId = ''; } else { } }); } // add empolyee $scope.employeeForm = { submit: function (form, myModel) { // var formate = "yyyy-MM-dd'T'HH:mm:ssZ"; // var date = $filter('date')(new Date($scope.myModel.dateofbirth), formate); // alert(date); var firstError = null; if (form.$invalid) { var field = null, firstError = null; for (field in form) { if (field[0] != '$') { if (firstError === null && !form[field].$valid) { firstError = form[field].$name; } if (form[field].$pristine) { form[field].$dirty = true; } } } 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 { // alert($scope.myModel.dateofbirth); var formate = "dd-MM-yyyy"; // var date = $filter('date')(new Date($scope.myModel.dateofbirth), formate); $scope.myModel.switchsetting = $scope.myModel.switchsetting === true ? 1 : 0; $scope.myModel.dateofbirth = $filter('date')(new Date($scope.myModel.dateofbirth), formate); $scope.myModel.dateofjoining = $filter('date')(new Date($scope.myModel.dateofjoining), formate); // alert($scope.myModel.dateofbirth) var req = { method: 'POST', url: apiPoint.url + 'insertEmployee/', headers: { 'Content-Type': 'application/json' }, data: { data: $scope.myModel, createdBy: localDetails.localUserID, } }; $http(req).then(function (response) { if (response.data.addEmpStatus == true) { swal("Success!", response.data.message, "success"); $state.go($state.current, {}, { reload: true }); } else { // $scope.ldloading1[loading.replace('-', '_')] = false; swal("Failed!", response.data.message, "error"); } }); } }, reset: function (form) { // $scope.myModel = angular.copy($scope.master); form.$setPristine(true); $scope.myModel = { 'employeeId': '', 'firstname': '', 'lastname': '', 'fathername': '', 'mothername': '', 'emailId': '', 'primaryPhone': '', 'secondaryPhone': '', 'dateofbirth': '', 'gender': '', 'qualificaion': '', 'aadharNumber': '', 'otherId': '', 'otherIdDetails': '', 'address1': '', 'address2': '', 'homeBranch': '', 'dateofjoining': '', 'dateofjoining': '', 'role': '', 'switchsetting': true, }; } } // update check mobile exist $scope.updateCheckMobileExist = function (p) { var checkReq = { method: 'POST', url: apiPoint.url + 'chkUpdateEmpExistDetail/', headers: { 'Content-Type': 'application/json' }, data: { exceptId: p.StaffID, datas: p.MobileNumber, check: 'mobileNumber' } }; $http(checkReq).then(function (response) { if (response.data.existMobile == true) { swal("Warning!", response.data.message, "warning"); p.MobileNumber = response.data.resetValue.MobileNumber; } else { } }); } $scope.updateCheckEmailExist = function (p) { var checkReq = { method: 'POST', url: apiPoint.url + 'chkUpdateEmpExistDetail/', headers: { 'Content-Type': 'application/json' }, data: { exceptId: p.StaffID, datas: p.EmailID, check: 'emailId' } }; $http(checkReq).then(function (response) { if (response.data.existEmailId == true) { swal("Warning!", response.data.message, "warning"); p.EmailID = response.data.resetValue.EmailID; } else { } }); } $scope.hidden_DOB= ''; $scope.hidden_DOJ= ''; $scope.updateEmpDetails = function (form, p, hide_dob, hide_doj) { var firstError = null; if (form.$invalid) { var field = null, firstError = null; for (field in form) { if (field[0] != '$') { if (firstError === null && !form[field].$valid) { firstError = form[field].$name; } if (form[field].$pristine) { form[field].$dirty = true; } } } 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 { var formate = "dd-MM-yyyy"; // var checkDOB = $filter('date')(new Date(p.DOB), formate); // var checkDOJ = $filter('date')(new Date(p.DOJ), formate); // alert(checkDOB); // alert(checkDOJ); p.IsActive = p.IsActive === true ? 1 : 0; p.DOB = p.DOB == hide_dob ? p.DOB : $filter('date')(new Date(p.DOB), formate); p.DOJ = p.DOJ == hide_doj ? p.DOJ : $filter('date')(new Date(p.DOJ), formate); var req = { method: 'POST', url: apiPoint.url + 'updateEmpExistDetail/', headers: { 'Content-Type': 'application/json' }, data: { data: p, updatedBy: localDetails.localUserID, } }; $http(req).then(function (response) { if (response.data.updateEmpStatus = true) { swal("Success!", response.data.message, "success"); $scope.getEmployeeList(); $scope.editId = -1; } else { // $scope.ldloading1[loading.replace('-', '_')] = false; swal("Failed!", response.data.message, "error"); } }); } } $scope.updateEmpBranchDetails = function (form, empRole, empBranchs, p) { // alert(empBranchs.arr.length); if (empBranchs.arr.length >= 1) { var firstError = null; if (form.$invalid) { var field = null, firstError = null; for (field in form) { if (field[0] != '$') { if (firstError === null && !form[field].$valid) { firstError = form[field].$name; } if (form[field].$pristine) { form[field].$dirty = true; } } } 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 { // alert(JSON.stringify(p)); // alert(JSON.stringify(empRole)); // alert(JSON.stringify(empBranchs)); $scope.sendBranchData = { 'empFor': p.StaffID, 'updateRole': empRole.ListCode, 'updateBranch': empBranchs.arr, 'updateBy': localDetails.localUserID } // p.IsActive = p.IsActive === true ? 1 : 0; var req = { method: 'POST', url: apiPoint.url + 'updateEmpBranchDetail/', headers: { 'Content-Type': 'application/json' }, data: $scope.sendBranchData }; $http(req).then(function (response) { if (response.data.updateEmpbranchStatus = true) { swal("Success!", response.data.message, "success"); $scope.getEmployeeList(); $scope.editBranchId = -1; } else { // $scope.ldloading1[loading.replace('-', '_')] = false; swal("Failed!", response.data.message, "error"); } }); } } else { swal("Warning!", "should select atleast branch!!", "warning"); } } $scope.uploadFile = function () { alert(); // var customer_name = $scope.customer_name; // console.log(customer_name); // var userId = $scope.userId; // console.log(userId); // var cafNo = $scope.cafNo; // console.log(cafNo); // var primaryEmail = $scope.primaryEmail; // console.log(primaryEmail); // var primaryPhone = $scope.primaryPhone; // console.log(primaryPhone); // var presentAddress = $scope.presentAddress; // console.log(presentAddress); // var createdBy = localStorage.getItem('id'); // // console.log('Id is '); // console.log(createdBy); // var idProof = $scope.idProof; // console.log('Id Proof is '); // console.dir(idProof); // var addressProof = $scope.addressProof; // console.log('address Proof is '); // console.dir(addressProof); // var cafForm = $scope.cafForm; // console.log('caf Form is '); // console.dir(cafForm); var uploadUrl = apiPoint.url + "addschoolimage.php"; fileUpload.uploadFileToUrl(customer_name, userId, cafNo, primaryEmail, primaryPhone, presentAddress, createdBy, idProof, addressProof, cafForm, uploadUrl); }; }]); 'use strict'; /** * controllers used for the dashboard */ app.directive('fileModel', ['$parse', function ($parse) { return { restrict: 'A', link: function (scope, element, attrs) { var model = $parse(attrs.fileModel); var modelSetter = model.assign; element.bind('change', function () { scope.$apply(function () { modelSetter(scope, element[0].files[0]); }); }); } }; }]); // We can write our own fileUpload service to reuse it in the controller app.service('fileUpload', ['$http', '$state', function ($http, $state) { this.uploadFileToUrl = function (customer_name, userId, cafNo, primaryEmail, primaryPhone, presentAddress, createdBy, idProof, addressProof, cafForm, uploadUrl) { var fd = new FormData(); fd.append('customer_name', customer_name); fd.append('userId', userId); fd.append('cafNo', cafNo); fd.append('primaryEmail', primaryEmail); fd.append('primaryPhone', primaryPhone); fd.append('presentAddress', presentAddress); fd.append('createdBy', createdBy); fd.append('idProof', idProof); fd.append('addressProof', addressProof); fd.append('cafForm', cafForm); $http.post(uploadUrl, fd, { transformRequest: angular.identity, headers: {'Content-Type': undefined, 'Process-Data': false}, }) .success(function (data) { if (data.status == true) { console.log("Success"); swal("Success!", "Profile image is updated successfully!", "success"); $state.go($state.current, {}, {reload: true}); }else if(data.status_1 == true){ swal("Success!", "school logo is updated successfully!", "success"); $state.go($state.current, {}, {reload: true}); }else if(data.status_2 == false){ swal("Failed!", "Select Image for uploading!", "error"); }else if(data.status_3 == false){ swal("Failed!", "Image Size Should Be Less Than 5 Mb!", "error"); } else if(data.status_4 == false){ swal("Failed!", "Image Size Should Be More Than 50 Kb!", "error"); }else{ swal("Failed!", "Image uploading has failed!", "error"); } }); } }]); app.controller('tarrifimage', ['$scope', '$state', '$http', 'fileUpload', 'API_POINTS', 'ngTableParams', '$filter', function ($scope, $state, $http, fileUpload, apiPoint, ngTableParams, $filter) { $scope.idProof_check = false; $scope.customerID = ''; $scope.customerCafNo = ''; $scope.new_id_form = ''; $scope.address_check = false; $scope.custID = ''; $scope.cusCafNo = ''; $scope.checked_check = false; $scope.cafFormId = ''; $scope.cafFormNo = ''; $scope.customerId = ''; $scope.new_caf_form = ''; //$scope.uploadFile = function () { // // // var idProof = $scope.idProof; // console.log('Id Proof is '); // console.dir(idProof); // // // // // var uploadUrl = apiPoint.url + "addimage.php"; // // fileUpload.uploadFileToUrl( idProof, uploadUrl); //}; $scope.uploadFile_1 = function () { //alert(idProof); var customer_name = $scope.customer_name; console.log(customer_name); var userId = $scope.userId; console.log(userId); var cafNo = $scope.cafNo; console.log(cafNo); var primaryEmail = $scope.primaryEmail; console.log(primaryEmail); var primaryPhone = $scope.primaryPhone; console.log(primaryPhone); var presentAddress = $scope.presentAddress; console.log(presentAddress); var createdBy = localStorage.getItem('id'); // console.log('Id is '); console.log(createdBy); var idProof = $scope.idProof; console.log('Id Proof is '); console.dir(idProof); var addressProof = $scope.addressProof; console.log('address Proof is '); console.dir(addressProof); var cafForm = $scope.cafForm; console.log('caf Form is '); console.dir(cafForm); var uploadUrl = apiPoint.url + "addschoolimage.php"; fileUpload.uploadFileToUrl(customer_name, userId, cafNo, primaryEmail, primaryPhone, presentAddress, createdBy, idProof, addressProof, cafForm, uploadUrl); }; $scope.uploadFile = function () { //alert(idProof); var customer_name = $scope.customer_name; console.log(customer_name); var userId = $scope.userId; console.log(userId); var cafNo = $scope.cafNo; console.log(cafNo); var primaryEmail = $scope.primaryEmail; console.log(primaryEmail); var primaryPhone = $scope.primaryPhone; console.log(primaryPhone); var presentAddress = $scope.presentAddress; console.log(presentAddress); var createdBy = localStorage.getItem('id'); // console.log('Id is '); console.log(createdBy); var idProof = $scope.idProof; console.log('Id Proof is '); console.dir(idProof); var addressProof = $scope.addressProof; console.log('address Proof is '); console.dir(addressProof); var cafForm = $scope.cafForm; console.log('caf Form is '); console.dir(cafForm); var uploadUrl = apiPoint.url + "addprofileimage.php"; fileUpload.uploadFileToUrl(customer_name, userId, cafNo, primaryEmail, primaryPhone, presentAddress, createdBy, idProof, addressProof, cafForm, uploadUrl); }; $scope.viewId = -1; $scope.viewMore = function (pid) { $scope.viewId = pid; $scope.editId = -1; }; $scope.editId = -1; $scope.setEditId = function (pid) { $scope.editId = pid; }; }]); /** * Created by ws040 on 10/1/17. */