(function (module) { mifosX.controllers = _.extend(module, { ViewClientController: function (scope, routeParams, route, location, resourceFactory, http, $uibModal, API_VERSION, $timeout, $rootScope, Upload) { scope.client = []; scope.identitydocuments = []; scope.buttons = []; scope.clientdocuments = []; scope.staffData = {}; scope.formData = {}; scope.openLoan = true; scope.openSaving = true; scope.openShares = true ; scope.openFixed = true; scope.openRecurring = true; scope.showFixed = false; scope.showRecurring = false; scope.updateDefaultSavings = false; scope.charges = []; scope.legalform = 'm_client'; scope.collaterals = []; // address scope.addresses=[]; scope.view={}; scope.view.data=[]; // scope.families=[]; var entityname="ADDRESS"; formdata={}; resourceFactory.clientTemplateResource.get(function(data) { scope.enableAddress=data.isAddressEnabled; if(scope.enableAddress===true) { resourceFactory.addressFieldConfiguration.get({entity:entityname},function(data){ for(var i=0;i 0 && scope.identitydocuments[j].id == data[0].parentEntityId) { for (var l in data) { var loandocs = {}; loandocs = API_VERSION + '/' + data[l].parentEntityType + '/' + data[l].parentEntityId + '/documents/' + data[l].id + '/attachment?tenantIdentifier=' + $rootScope.tenantIdentifier; data[l].docUrl = loandocs; } scope.identitydocuments[j].documents = data; } } }); } }); }; scope.dataTableChange = function (clientdatatable) { resourceFactory.DataTablesResource.getTableDetails({ datatablename: clientdatatable.registeredTableName, entityId: routeParams.id, genericResultSet: 'true' }, function (data) { scope.datatabledetails = data; scope.datatabledetails.isData = data.data.length > 0 ? true : false; scope.datatabledetails.isMultirow = data.columnHeaders[0].columnName == "id" ? true : false; scope.showDataTableAddButton = !scope.datatabledetails.isData || scope.datatabledetails.isMultirow; scope.showDataTableEditButton = scope.datatabledetails.isData && !scope.datatabledetails.isMultirow; scope.singleRow = []; for (var i in data.columnHeaders) { if (scope.datatabledetails.columnHeaders[i].columnCode) { for (var j in scope.datatabledetails.columnHeaders[i].columnValues) { for (var k in data.data) { if (data.data[k].row[i] == scope.datatabledetails.columnHeaders[i].columnValues[j].id) { data.data[k].row[i] = scope.datatabledetails.columnHeaders[i].columnValues[j].value; } } } } } if (scope.datatabledetails.isData) { for (var i in data.columnHeaders) { if (!scope.datatabledetails.isMultirow) { var row = {}; row.key = data.columnHeaders[i].columnName; row.value = data.data[0].row[i]; scope.singleRow.push(row); } } } }); }; scope.viewstandinginstruction = function () { location.path('/liststandinginstructions/' + scope.client.officeId + '/' + scope.client.id); }; scope.createstandinginstruction = function () { location.path('/createstandinginstruction/' + scope.client.officeId + '/' + scope.client.id + '/fromsavings'); }; scope.deleteAll = function (apptableName, entityId) { resourceFactory.DataTablesResource.delete({datatablename: apptableName, entityId: entityId, genericResultSet: 'true'}, {}, function (data) { route.reload(); }); }; scope.getClientDocuments = function () { resourceFactory.clientDocumentsResource.getAllClientDocuments({clientId: routeParams.id}, function (data) { for (var l in data) { var loandocs = {}; loandocs = API_VERSION + '/' + data[l].parentEntityType + '/' + data[l].parentEntityId + '/documents/' + data[l].id + '/attachment?tenantIdentifier=' + $rootScope.tenantIdentifier; data[l].docUrl = loandocs; if (data[l].fileName) if (data[l].fileName.toLowerCase().indexOf('.jpg') != -1 || data[l].fileName.toLowerCase().indexOf('.jpeg') != -1 || data[l].fileName.toLowerCase().indexOf('.png') != -1) data[l].fileIsImage = true; if (data[l].type) if (data[l].type.toLowerCase().indexOf('image') != -1) data[l].fileIsImage = true; } scope.clientdocuments = data; }); }; scope.deleteDocument = function (documentId, index) { resourceFactory.clientDocumentsResource.delete({clientId: routeParams.id, documentId: documentId}, '', function (data) { scope.clientdocuments.splice(index, 1); }); }; scope.previewDocument = function (url, fileName) { scope.preview = true; scope.fileUrl = scope.hostUrl + url; if(fileName.toLowerCase().indexOf('.png') != -1) scope.fileType = 'image/png'; else if(fileName.toLowerCase().indexOf('.jpg') != -1) scope.fileType = 'image/jpg'; else if(fileName.toLowerCase().indexOf('.jpeg') != -1) scope.fileType = 'image/jpeg'; }; scope.viewDataTable = function (registeredTableName, data) { if (scope.datatabledetails.isMultirow) { location.path("/viewdatatableentry/" + registeredTableName + "/" + scope.client.id + "/" + data.row[0]); } else { location.path("/viewsingledatatableentry/" + registeredTableName + "/" + scope.client.id); } }; scope.downloadDocument = function (documentId) { resourceFactory.clientDocumentsResource.get({clientId: routeParams.id, documentId: documentId}, '', function (data) { scope.clientdocuments.splice(index, 1); }); }; scope.isLoanNotClosed = function (loanaccount) { if (loanaccount.status.code === "loanStatusType.closed.written.off" || loanaccount.status.code === "loanStatusType.closed.obligations.met" || loanaccount.status.code === "loanStatusType.closed.reschedule.outstanding.amount" || loanaccount.status.code === "loanStatusType.withdrawn.by.client" || loanaccount.status.code === "loanStatusType.rejected") { return false; } else { return true; } }; scope.isSavingNotClosed = function (savingaccount) { if (savingaccount.status.code === "savingsAccountStatusType.withdrawn.by.applicant" || savingaccount.status.code === "savingsAccountStatusType.closed" || savingaccount.status.code === "savingsAccountStatusType.pre.mature.closure" || savingaccount.status.code === "savingsAccountStatusType.rejected") { return false; } else { return true; } }; scope.isShareNotClosed = function (shareAccount) { if ( shareAccount.status.code === "shareAccountStatusType.closed" || shareAccount.status.code === "shareAccountStatusType.rejected") { return false; } else { return true; } }; scope.saveNote = function () { resourceFactory.clientResource.save({clientId: routeParams.id, anotherresource: 'notes'}, this.formData, function (data) { var today = new Date(); temp = { id: data.resourceId, note: scope.formData.note, createdByUsername: "test", createdOn: today }; scope.clientNotes.unshift(temp); scope.formData.note = ""; scope.predicate = '-id'; }); } scope.showEditNote = function(clientId, clientNote, index) { $uibModal.open({ templateUrl: 'editNote.html', controller: EditNoteCtrl, resolve: { items: function(){ return { clientId: clientId, clientNote: clientNote, index: index } } }, size: "lg" }); } scope.showDeleteNote = function(clientId, clientNote, index) { $uibModal.open({ templateUrl: 'deleteNote.html', controller: DeleteNoteCtrl, resolve: { items: function(){ return { clientId: clientId, clientNote: clientNote, index: index } } }, size: "lg" }); } var EditNoteCtrl = function ($scope, $uibModalInstance, items) { scope.editData = {}; editData = {}; $scope.editNote = function (clientId, entityId, index, editData) { resourceFactory.clientNotesResource.put({clientId: items.clientId, noteId: items.clientNote}, {note: this.editData.editNote}, function(data) { scope.clientNotes[items.index].note = $scope.editData.editNote; scope.editData.editNote = ""; $uibModalInstance.close(); }); }; $scope.cancel = function (index) { $uibModalInstance.dismiss('cancel'); }; }; var DeleteNoteCtrl = function ($scope, $uibModalInstance, items) { $scope.deleteNote = function (clientId, entityId, index) { resourceFactory.clientNotesResource.delete({clientId: items.clientId, noteId: items.clientNote}, '', function(data) { $uibModalInstance.close(); scope.clientNotes.splice(items.index, 1); }); }; $scope.cancel = function (index) { $uibModalInstance.dismiss('cancel'); }; }; scope.deleteClientIdentifierDocument = function (clientId, entityId, index) { resourceFactory.clientIdenfierResource.delete({clientId: clientId, id: entityId}, '', function (data) { scope.identitydocuments.splice(index, 1); }); }; scope.downloadClientIdentifierDocument = function (identifierId, documentId) { console.log(identifierId, documentId); }; scope.waiveCharge = function(chargeId){ resourceFactory.clientChargesResource.waive({clientId: routeParams.id, resourceType:chargeId}, function (data) { route.reload(); }); } scope.showSignature = function() { $uibModal.open({ templateUrl: 'clientSignature.html', controller: ViewLargerClientSignature, size: "lg" }); }; scope.showWithoutSignature = function() { $uibModal.open({ templateUrl: 'clientWithoutSignature.html', controller: ViewClientWithoutSignature, size: "lg" }); }; scope.showPicture = function () { $uibModal.open({ templateUrl: 'photo-dialog.html', controller: ViewLargerPicCtrl, size: "lg" }); }; var ViewClientWithoutSignature = function($scope,$uibModalInstance){ $scope.cancel = function () { $uibModalInstance.dismiss('cancel'); }; $scope.uploadSig = function () { $uibModalInstance.dismiss('cancel'); scope.uploadSig(); }; }; var ViewLargerClientSignature = function($scope,$uibModalInstance){ var loadSignature = function(){ http({ method: 'GET', url: $rootScope.hostUrl + API_VERSION + '/clients/' + routeParams.id + '/documents' }).then(function (docsData) { $scope.docId = -1; for (var i = 0; i < docsData.data.length; ++i) { if (docsData.data[i].name == 'clientSignature') { $scope.docId = docsData.data[i].id; scope.signature_url = $rootScope.hostUrl + API_VERSION + '/clients/' + routeParams.id + '/documents/' + $scope.docId + '/attachment?tenantIdentifier=' + $rootScope.tenantIdentifier; } } if (scope.signature_url != null) { http({ method: 'GET', url: $rootScope.hostUrl + API_VERSION + '/clients/' + routeParams.id + '/documents/' + $scope.docId + '/attachment?tenantIdentifier=' + $rootScope.tenantIdentifier }).then(function (docsData) { $scope.largeImage = scope.signature_url; }); } }); }; loadSignature(); $scope.deleteSig = function () { $uibModalInstance.dismiss('cancel'); scope.deleteSig(); }; $scope.uploadSig = function () { $uibModalInstance.dismiss('cancel'); scope.uploadSig(); }; $scope.cancel = function () { $uibModalInstance.dismiss('cancel'); }; }; var ViewLargerPicCtrl = function ($scope, $uibModalInstance) { var loadImage = function () { if (scope.client.imagePresent) { http({ method: 'GET', url: $rootScope.hostUrl + API_VERSION + '/clients/' + routeParams.id + '/images?maxWidth=860' }).then(function (imageData) { $scope.largeImage = imageData.data; }); } }; loadImage(); $scope.cancel = function () { $uibModalInstance.dismiss('cancel'); }; }; resourceFactory.creditBureauTemplate.get(function (data) { scope.creditbureaus = data; scope.creditbureauname = scope.creditbureaus.creditBureauName; }); scope.getcreditreport = function(creditBureauId) { scope.creditbureau = creditBureauId; if (creditBureauId == 1) { //id 1 is assigned for ThitsaWorks CreditBureau location.path('/creditreport/thitsaworkCreditbureau/'+scope.creditbureau); } else{ alert("Please Select Respective integrated Credit Bureau"); } }; scope.onFileSelect = function (files) { scope.formData.file = files[0]; }; scope.upload = function () { Upload.upload({ url: $rootScope.hostUrl + API_VERSION + '/creditBureauIntegration/addCreditReport?creditBureauId=1', data: {file: scope.formData.file}, }).then(function (data) { if (!scope.$$phase) { scope.$apply(); } }); }; scope.uploadReport = function (creditBureauId) { scope.creditbureau = creditBureauId; if (creditBureauId == 1) { location.path('/creditreport/thitsaworkUploadCreditbureau/' + routeParams.id +'/'+ scope.creditbureau); } }; scope.downloadCreditReport = function (creditBureauId) { scope.creditbureau = creditBureauId; if (creditBureauId == 1) { //id 1 is assigned for ThitsaWorks CreditBureau location.path('/creditreport/thitsaworkDownloadCreditbureau/' + routeParams.id +'/'+ scope.creditbureau); }else{ alert("Please Select Respective integrated Credit Bureau"); } }; } }); mifosX.ng.application.controller('ViewClientController', ['$scope', '$routeParams', '$route', '$location', 'ResourceFactory', '$http', '$uibModal', 'API_VERSION', '$timeout', '$rootScope', 'Upload', mifosX.controllers.ViewClientController]).run(function ($log) { $log.info("ViewClientController initialized"); }); }(mifosX.controllers || {}));