community-app/app/scripts/controllers/main/AdHocQuerySearchController.js
2014-03-02 04:09:27 -08:00

139 lines
6.8 KiB
JavaScript

(function (module) {
mifosX.controllers = _.extend(module, {
AdHocQuerySearchController: function (scope, routeParams, dateFilter, resourceFactory) {
scope.formData = {};
scope.showResults = false;
resourceFactory.globalSearchTemplateResource.get(function (data) {
scope.searchTemplate = data;
scope.formData.loanfromdate = new Date();
scope.formData.loantodate = new Date();
scope.formData.loandatetype = "approvalDate";
scope.showDateFields = true;
scope.formData.loans = "loans";
scope.formData.includeOutStandingAmountPercentage = true;
scope.formData.outStandingAmountPercentageCondition = 'between';
scope.formData.includeOutstandingAmount = true;
scope.formData.outstandingAmountCondition = 'between';
});
scope.updatePercentageType = function () {
if (scope.formData.percentagetype == 'between') {
scope.formData.percentage = undefined;
} else {
scope.formData.minpercentage = undefined;
scope.formData.maxpercentage = undefined;
}
};
scope.updateOutstandingType = function () {
if (scope.formData.outstandingType == 'between') {
scope.formData.outstandingamt = undefined;
} else {
scope.formData.minoutstandingamt = undefined;
scope.formData.maxoutstandingamt = undefined;
}
};
scope.updateLoanDateType = function () {
if (scope.formData.loandatetype == "approvalDate" || scope.formData.loandatetype == "createdDate" || scope.formData.loandatetype == "disbursalDate") {
scope.showDateFields = true;
} else {
scope.showDateFields = false;
}
};
scope.submit = function () {
var adHocQuery = { "locale": scope.optlang.code, "dateFormat": "yyyy-MM-dd"};
if (scope.formData.loans) {
adHocQuery.entities = adHocQuery.entities || [];
adHocQuery.entities.push(scope.formData.loans);
}
;
if (scope.formData.allloans) {
adHocQuery.loanStatus = adHocQuery.loanStatus || [];
adHocQuery.loanStatus.push(scope.formData.allloans);
}
;
if (scope.formData.activeloans) {
adHocQuery.loanStatus = adHocQuery.loanStatus || [];
adHocQuery.loanStatus.push(scope.formData.activeloans);
}
;
if (scope.formData.overpaidloans) {
adHocQuery.loanStatus = adHocQuery.loanStatus || [];
adHocQuery.loanStatus.push(scope.formData.overpaidloans);
}
;
if (scope.formData.arrearloans) {
adHocQuery.loanStatus = adHocQuery.loanStatus || [];
adHocQuery.loanStatus.push(scope.formData.arrearloans);
}
;
if (scope.formData.closedloans) {
adHocQuery.loanStatus = adHocQuery.loanStatus || [];
adHocQuery.loanStatus.push(scope.formData.closedloans);
}
;
if (scope.formData.writeoffloans) {
adHocQuery.loanStatus = adHocQuery.loanStatus || [];
adHocQuery.loanStatus.push(scope.formData.writeoffloans);
}
;
if (scope.formData.loanProducts) {
adHocQuery.loanProducts = scope.formData.loanProducts;
}
;
if (scope.formData.offices) {
adHocQuery.offices = scope.formData.offices;
}
;
if (scope.formData.loandatetype) {
adHocQuery.loanDateOption = scope.formData.loandatetype;
adHocQuery.loanFromDate = dateFilter(scope.formData.loanfromdate, adHocQuery.dateFormat);
adHocQuery.loanToDate = dateFilter(scope.formData.loantodate, adHocQuery.dateFormat);
}
;
if (scope.formData.includeOutStandingAmountPercentage) {
adHocQuery.includeOutStandingAmountPercentage = scope.formData.includeOutStandingAmountPercentage;
if (scope.formData.outStandingAmountPercentageCondition) {
adHocQuery.outStandingAmountPercentageCondition = scope.formData.outStandingAmountPercentageCondition;
if (adHocQuery.outStandingAmountPercentageCondition == 'between') {
adHocQuery.minOutStandingAmountPercentage = scope.formData.minOutStandingAmountPercentage;
adHocQuery.maxOutStandingAmountPercentage = scope.formData.maxOutStandingAmountPercentage;
} else {
adHocQuery.outStandingAmountPercentage = scope.formData.outStandingAmountPercentage;
}
;
}
;
}
;
if (scope.formData.includeOutstandingAmount) {
adHocQuery.includeOutstandingAmount = scope.formData.includeOutstandingAmount;
if (scope.formData.outstandingAmountCondition) {
adHocQuery.outstandingAmountCondition = scope.formData.outstandingAmountCondition;
if (adHocQuery.outstandingAmountCondition == 'between') {
adHocQuery.minOutstandingAmount = scope.formData.minOutstandingAmount;
adHocQuery.maxOutstandingAmount = scope.formData.maxOutstandingAmount;
} else {
adHocQuery.outstandingAmount = scope.formData.outstandingAmount;
}
;
}
;
}
;
resourceFactory.globalAdHocSearchResource.search(adHocQuery, function (data) {
scope.searchResults = data;
scope.showResults = true;
});
};
}
});
mifosX.ng.application.controller('AdHocQuerySearchController', ['$scope', '$routeParams', 'dateFilter', 'ResourceFactory', mifosX.controllers.AdHocQuerySearchController]).run(function ($log) {
$log.info("AdHocQuerySearchController initialized");
});
}(mifosX.controllers || {}));