community-app/app/scripts/controllers/accounting/JournalEntryController.js
2013-09-13 10:49:03 +05:30

78 lines
3.6 KiB
JavaScript

(function(module) {
mifosX.controllers = _.extend(module, {
JournalEntryController: function(scope, resourceFactory, location) {
scope.formData = {};
scope.formData.crAccounts = [];
scope.formData.dbAccounts = [];
resourceFactory.accountCoaResource.getAllAccountCoas({manualEntriesAllowed:true, usage:1, disabled:false}, function(data){
scope.glAccounts = data;
});
resourceFactory.officeResource.getAllOffices(function(data){
scope.offices = data;
});
//events for credits
scope.addCrAccount = function () {
if(scope.formData.crAmountTemplate != undefined){
scope.formData.crAccounts.push({crGlAccountId: scope.formData.creditAccountTemplate.id, crGlcode: scope.formData.creditAccountTemplate.glCode, crGlName : scope.formData.creditAccountTemplate.name , crAmount : scope.formData.crAmountTemplate});
scope.formData.crAmountTemplate = undefined;
}
}
scope.removeCrAccount = function(index) {
scope.formData.crAccounts.splice(index,1);
}
//events for debits
scope.addDebitAccount = function () {
if(scope.formData.debitAmountTemplate != undefined){
scope.formData.dbAccounts.push({debitGlAccountId: scope.formData.debitAccountTemplate.id, debitGlcode: scope.formData.debitAccountTemplate.glCode, debitGlName : scope.formData.debitAccountTemplate.name , debitAmount : scope.formData.debitAmountTemplate});
scope.formData.debitAmountTemplate = undefined;
}
}
scope.removeDebitAccount = function(index) {
scope.formData.dbAccounts.splice(index,1);
}
scope.submit = function() {
var jeTransaction = new Object();
jeTransaction.locale = 'en';
jeTransaction.dateFormat = 'dd MMMM yyyy';
jeTransaction.officeId=this.formData.officeId;
jeTransaction.transactionDate = this.formData.transactionDate;
jeTransaction.referenceNumber = this.formData.referenceNumber;
jeTransaction.comments = this.formData.comments;
//Construct credits array
jeTransaction.credits = [];
for (var i = 0; i < this.formData.crAccounts.length; i++) {
var temp = new Object();
temp.glAccountId = this.formData.crAccounts[i].crGlAccountId;
temp.amount = this.formData.crAccounts[i].crAmount;
jeTransaction.credits.push(temp);
}
//construct debits array
jeTransaction.debits = [];
for (var i = 0; i < this.formData.dbAccounts.length; i++) {
var temp = new Object();
temp.glAccountId = this.formData.dbAccounts[i].debitGlAccountId;
temp.amount = this.formData.dbAccounts[i].debitAmount;
jeTransaction.debits.push(temp);
}
resourceFactory.journalEntriesResource.save(jeTransaction,function(data){
location.path('/viewtransactions/'+data.transactionId);
});
}
}
});
mifosX.ng.application.controller('JournalEntryController', ['$scope', 'ResourceFactory', '$location', mifosX.controllers.JournalEntryController]).run(function($log) {
$log.info("JournalEntryController initialized");
});
}(mifosX.controllers || {}));