434 lines
15 KiB
JavaScript
434 lines
15 KiB
JavaScript
'use strict';
|
|
/**
|
|
* daybook details capturing
|
|
*
|
|
*/
|
|
app.controller('daybookCtrl', ["$scope", "$rootScope", "toaster", "$filter", "ngTableParams", "API_POINTS", "$localStorage", "$http", "$state", 'ipCookie', '$window','SweetAlert', function ($scope, $rootScope, toaster, $filter, ngTableParams, apiPoint, $localStorage, $http, $state, ipCookie, $window, SweetAlert) {
|
|
|
|
// get local client details
|
|
var localDetail = JSON.parse(localStorage.getItem('localObj'));
|
|
var localDetails = ipCookie('cookiechk');
|
|
$scope.disableAddButton = false;
|
|
$scope.disableEditButton = false;
|
|
|
|
$scope.searchData = {
|
|
"date": "",
|
|
"dateTo": ""
|
|
}
|
|
|
|
// get the data while page loading functions goes here
|
|
$scope.init = function () {
|
|
$scope.todayDate = new Date();
|
|
const LOCALTYPE = localDetail.localType;
|
|
if(LOCALTYPE === 'R002') {
|
|
$scope.currentDate = new Date();
|
|
var d = new Date();
|
|
$scope.oneMonthBefore = d.setMonth(d.getMonth()-1);
|
|
// alert($scope.oneMonthBefore);
|
|
var formate = "dd-MM-yyyy";
|
|
$scope.searchData.date = $filter('date')(new Date($scope.oneMonthBefore), formate);
|
|
$scope.searchData.dateTo = $filter('date')(new Date($scope.currentDate), formate);
|
|
$scope.getDayBookList();
|
|
$scope.getIncomeExpenseType_Status();
|
|
|
|
}else {
|
|
ipCookie.remove('cookiechk');
|
|
$window.localStorage.clear();
|
|
$state.go('login.signin');
|
|
}
|
|
}
|
|
|
|
$scope.dayBookApprovalAccess = '';
|
|
// Finance module access control
|
|
function getFinanceModuleAccess() {
|
|
var getFinacnceModuleAcccessCtrl = {
|
|
method: 'POST',
|
|
url: apiPoint.url + 'empDayBookModuleAccessChk/',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
data: {
|
|
localReqDetails: localDetails
|
|
}
|
|
};
|
|
$http(getFinacnceModuleAcccessCtrl).then(function (response) {
|
|
if (response.data.dayBkAccessChkStatus) {
|
|
$scope.dayBookApprovalAccess = response.data.dayBkAccessChk_Value;
|
|
$scope.currentDate = new Date();
|
|
var formate = "dd-MM-yyyy";
|
|
$scope.searchData.date = $filter('date')(new Date($scope.currentDate), formate);
|
|
$scope.searchData.dateTo = $filter('date')(new Date($scope.currentDate), formate);
|
|
$scope.getDayBookList();
|
|
$scope.getIncomeExpenseType_Status();
|
|
return true;
|
|
} else {
|
|
return true;
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
// $scope.getApproveLoad = function() {
|
|
// alert();
|
|
// }
|
|
|
|
// change from date, update and call search functionality
|
|
$scope.changeDate = function () {
|
|
if($scope.searchData.date !== undefined) {
|
|
var formate = "dd-MM-yyyy";
|
|
$scope.searchData.date = $filter('date')(new Date($scope.searchData.date), formate);
|
|
$scope.getDayBookList();
|
|
} else {
|
|
$scope.searchData.date = '';
|
|
$scope.getDayBookList();
|
|
}
|
|
}
|
|
|
|
// change to date, update and call search functionality
|
|
$scope.changeToDate = function () {
|
|
if($scope.searchData.dateTo !== undefined) {
|
|
var formate = "dd-MM-yyyy";
|
|
$scope.searchData.dateTo = $filter('date')(new Date($scope.searchData.dateTo), formate);
|
|
$scope.getDayBookList();
|
|
} else {
|
|
$scope.searchData.dateTo = '';
|
|
$scope.getDayBookList();
|
|
}
|
|
}
|
|
|
|
// 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
|
|
}
|
|
|
|
$scope.noRecordFound = true;
|
|
$scope.dataLength = 0;
|
|
// get day book type name list
|
|
$scope.getDayBookList = function () {
|
|
var getDatBookListDetails = {
|
|
method: 'POST',
|
|
url: apiPoint.url + 'getDayBookDetails/',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
data: {
|
|
data: $scope.searchData,
|
|
localReqDetails: localDetails,
|
|
}
|
|
};
|
|
$http(getDatBookListDetails).then(function (response) {
|
|
if (response.data.dayBookListStatus) {
|
|
|
|
$scope.data = response.data.dayBookListDetails;
|
|
$scope.dataLength = $scope.data.length;
|
|
if ($scope.data.length !== 0) {
|
|
$scope.noRecordFound = false;
|
|
} else {
|
|
$scope.noRecordFound = true;
|
|
}
|
|
// alert(JSON.stringify($scope.data));
|
|
// $scope.incomeExpenseType = response.data.typeNameList;
|
|
} else {
|
|
|
|
}
|
|
});
|
|
}
|
|
|
|
// income expense type status list
|
|
$scope.getIncomeExpenseType_Status = function () {
|
|
var getIncomeExpenseType = {
|
|
method: 'POST',
|
|
url: apiPoint.url + 'getIncomeExpenseTypeState/',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
data: {
|
|
localReqDetails: localDetails
|
|
}
|
|
};
|
|
$http(getIncomeExpenseType).then(function (response) {
|
|
if (response.data.typeNameStatus) {
|
|
$scope.incomeExpenseName = response.data.typeList;
|
|
$scope.incomeExpenseType = response.data.typeNameList;
|
|
} else {
|
|
}
|
|
});
|
|
}
|
|
|
|
// parse the income and expense type from the list
|
|
$scope.getType = function (type) {
|
|
$scope.getIncomeTypes = $scope.incomeExpenseType.filter(function (val) {
|
|
return val.TypeID === 'I002' ? 1 : 0;
|
|
});
|
|
$scope.getExpenseTypes = $scope.incomeExpenseType.filter(function (val) {
|
|
return val.TypeID === 'I001' ? 1 : 0;
|
|
});
|
|
$scope.myModelAdd.type = '';
|
|
$scope.getTypes = type === 'I002' ? $scope.getIncomeTypes : $scope.getExpenseTypes;
|
|
};
|
|
|
|
$scope.editId = -1;
|
|
$scope.setEditId = function (P) {
|
|
// alert(id);
|
|
$scope.editId = P;
|
|
}
|
|
|
|
$scope.editClose = function () {
|
|
$scope.editId = -1;
|
|
$scope.myModel = {
|
|
"id": "",
|
|
"date": "",
|
|
"incomeExpense": "",
|
|
"type": "",
|
|
"amount": "",
|
|
"status": "",
|
|
"description": "",
|
|
"paidTo": "",
|
|
"description_paid": "",
|
|
"voucherNumber": "",
|
|
"branch":"",
|
|
"name":""
|
|
}
|
|
}
|
|
|
|
$scope.myModel = {
|
|
"id": "",
|
|
"date": "",
|
|
"incomeExpense": "",
|
|
"type": "",
|
|
"amount": "",
|
|
"status": "",
|
|
"description": "",
|
|
"paidTo": "",
|
|
"description_paid": "",
|
|
"voucherNumber": "",
|
|
"branch": "",
|
|
"name":""
|
|
}
|
|
|
|
$scope.copyModel = function (p) {
|
|
console.log(p);
|
|
$scope.myModel = {
|
|
"id": p.ID,
|
|
"date": p.Date,
|
|
"incomeExpense": p.Name,
|
|
"type": p.Type,
|
|
"amount": p.Amount,
|
|
"status": p.Status,
|
|
"description": p.Description,
|
|
"paidTo": p.PaidTo,
|
|
"description_paid": p.PaidDescription,
|
|
"voucherNumber": p.VoucherNumber,
|
|
"branch":p.BranchCode,
|
|
"name": p.Name
|
|
}
|
|
// alert(JSON.stringify($scope.myModel));
|
|
}
|
|
|
|
|
|
//delete the income entry From the fees payable
|
|
$scope.deleteFeePayableEntry = function (id) {
|
|
// alert(id);
|
|
SweetAlert.swal({
|
|
title: "Warning!",
|
|
text: "Do you want to Delete this Entry ?",
|
|
type: "warning",
|
|
showCancelButton: true,
|
|
confirmButtonColor: "#007aff",
|
|
confirmButtonText: "Yes!"
|
|
}, function (res) {
|
|
if (res === true) {
|
|
// alert(id);
|
|
// alert(stuId);
|
|
var deleteFeePayableDetails = {
|
|
method: 'POST',
|
|
url: apiPoint.url + 'deleteDayBookFeePayableDetails/',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
data: {
|
|
data: id,
|
|
requestDetails: localDetails
|
|
}
|
|
};
|
|
$http(deleteFeePayableDetails).then(function (response) {
|
|
if (response.data.deletedStatus) {
|
|
swal(" ", "Deleted Successfully.", "success");
|
|
$scope.getDayBookList();
|
|
} else {
|
|
swal(" ", response.data.message, "error");
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
// delete the income/expense list row
|
|
$scope.deleEditEntry = function (id) {
|
|
swal({
|
|
title: "Are you sure?",
|
|
text: "Your will not be able to recover this record!",
|
|
type: "warning",
|
|
showCancelButton: true,
|
|
confirmButtonClass: "btn-danger",
|
|
confirmButtonText: "Yes, delete it!",
|
|
closeOnConfirm: false
|
|
},
|
|
function () {
|
|
$scope.indexDelete2(id);
|
|
});
|
|
$scope.indexDelete2 = function (id) {
|
|
var deleteDetails = {
|
|
method: 'POST',
|
|
url: apiPoint.url + 'deleteDayBookDetails/',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
data: {
|
|
data: id,
|
|
requestDetails: localDetails
|
|
}
|
|
};
|
|
$http(deleteDetails).then(function (response) {
|
|
if (response.data.deletedStatus) {
|
|
swal(" ", "Deleted Successfully.", "success");
|
|
$scope.getDayBookList();
|
|
} else {
|
|
swal(" ", response.data.message, "error");
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
$scope.myModelAdd = {
|
|
"id": "",
|
|
"date": "",
|
|
"name": "",
|
|
"type": "",
|
|
"amount": "",
|
|
"status": "",
|
|
"description": "",
|
|
"paidTo": "",
|
|
"description_paid": "",
|
|
"voucherNumber": ""
|
|
}
|
|
|
|
// add a new daybook entry
|
|
$scope.daybookAdd = {
|
|
submit: function (form, myModelAdd) {
|
|
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 {
|
|
$scope.disableAddButton = true;
|
|
var formate = "dd-MM-yyyy";
|
|
$scope.myModelAdd.date = $filter('date')(new Date($scope.myModelAdd.date), formate);
|
|
$scope.myModelAdd.status = $scope.myModelAdd.name == 'I001' ? 'Pending' : 'Approved';
|
|
// $scope.data.push(myModelAdd);
|
|
|
|
var addDayBookDetails = {
|
|
method: 'POST',
|
|
url: apiPoint.url + 'addDayBook/',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
data: {
|
|
data: myModelAdd,
|
|
localReqDetails: localDetails
|
|
}
|
|
};
|
|
$http(addDayBookDetails).then(function (response) {
|
|
if (response.data.addDayBookStatus) {
|
|
swal(" ", "Income/Expense added successfully.", "success");
|
|
$state.go($state.current, {}, { reload: true });
|
|
$scope.disableAddButton = false;
|
|
} else {
|
|
swal(" ", response.data.message, "error");
|
|
$scope.disableAddButton = false;
|
|
}
|
|
});
|
|
}
|
|
},
|
|
reset: function (form) {
|
|
form.$setPristine(true);
|
|
$scope.myModelAdd = {
|
|
"id": "",
|
|
"date": "",
|
|
"name": "",
|
|
"type": "",
|
|
"amount": "",
|
|
"status": "",
|
|
"description": "",
|
|
"paidTo": "",
|
|
"description_paid": "",
|
|
"voucherNumber": ""
|
|
}
|
|
}
|
|
}
|
|
|
|
// update a daybook entry details
|
|
$scope.daybookeditUpdate = {
|
|
submit: function (form, myModel) {
|
|
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($scope.myModel));exit();
|
|
$scope.disableEditButton = true;
|
|
var updateDayBookDetails = {
|
|
method: 'POST',
|
|
url: apiPoint.url + 'updateDayBookDetails/',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
data: {
|
|
data: $scope.myModel,
|
|
requestDetails: localDetails
|
|
}
|
|
};
|
|
$http(updateDayBookDetails).then(function (response) {
|
|
if (response.data.updateDetailsStatus) {
|
|
swal(" ","Updated successfully.", "success");
|
|
// for success state
|
|
$scope.editId = -1;
|
|
$scope.getDayBookList();
|
|
$scope.disableEditButton = false;
|
|
} else {
|
|
swal(" ", response.data.message, "error");
|
|
$scope.disableEditButton = false;
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
}]);
|
|
|
|
|