apollodec/Apollo/assets/js/controllers/daybookadminCtrl.js

546 lines
19 KiB
JavaScript
Executable File

'use strict';
/**
* daybook details capturing
*
*/
app.controller('daybookadminCtrl', ["$scope", "$rootScope", "toaster", "$filter", "ngTableParams", "API_POINTS", "$localStorage", "$http", "$state", 'ipCookie', '$window', function ($scope, $rootScope, toaster, $filter, ngTableParams, apiPoint, $localStorage, $http, $state, ipCookie, $window) {
// get local client details
var localDetail = JSON.parse(localStorage.getItem('localObj'));
var localDetails = ipCookie('cookiechk');
$scope.localTypeViewAdmin = false;
$scope.localTypeViewSuperAdmin = false;
$scope.searchData = {
"date": "",
"dateTo": ""
}
// load functionality when page get loaded
$scope.init = function () {
const LOCALTYPE = localDetail.localType;
if (LOCALTYPE === 'R003') {
$scope.showTheRefValue = 'I001';
$scope.localTypeViewAdmin = true;
$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.getIncomeExpenseType_Status();
$scope.getDayBookList();
} else {
ipCookie.remove('cookiechk');
$window.localStorage.clear();
$state.go('login.signin');
// $scope.localTypeViewSuperAdmin = true;
// $scope.showTheRefValue = 'I001';
// $scope.localTypeViewAdmin = true;
// $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.getIncomeExpenseType_Status();
// $scope.getDayBookList();
}
}
// 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) {
// alert();
$scope.sortKey = keyname; //set the sortKey to the param passed
$scope.reverse = !$scope.reverse; //if true make it false and vice versa
}
// 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 {
}
});
}
$scope.loadingsearch = false;
$scope.noRecordFound = true;
$scope.noRecordFoundSearch = false;
$scope.dataLengthIncome = 0;
$scope.dataLengthExpense = 0;
// day book entry list
$scope.getDayBookList = function () {
$scope.loadingsearch = true;
$scope.noRecordFoundSearch = false;
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.loadingsearch = false;
// $scope.data = response.data.dayBookListDetails;
let datas = response.data.dayBookListDetails;
if (datas.length <= 0) {
$scope.noRecordFoundSearch = true;
} else {
$scope.noRecordFoundSearch = false;
}
let searchResultDetailsBef = datas.filter(val => {
return val.Name == 'I001' ? 1 : 0;
});
$scope.IncomeData = datas.filter(val => {
return val.Name == 'I002' ? 1 : 0;
});
$scope.dataLengthIncome = $scope.IncomeData.length;
const filterAddSelect = searchResultDetailsBef.filter(val => {
val['Selected'] = false;
return val;
});
$scope.searchResultDetails = filterAddSelect;
$scope.dataLengthExpense = $scope.searchResultDetails.length;
// alert(JSON.stringify($scope.searchResultDetails));
$scope.searchResultLength = Object.keys($scope.searchResultDetails).length;
// if ($scope.data.length !== 0) {
// $scope.OpenWindowStatus = false;
// $scope.noRecordFound = false;
// } else {
// $scope.OpenWindowStatus = false;
// $scope.noRecordFound = true;
// }
// alert(JSON.stringify($scope.data));
// $scope.incomeExpenseType = response.data.typeNameList;
} else {
$scope.loadingsearch = false;
}
});
}
// select all or individual functionality
var getAllSelected = function () {
var selectedItems = $scope.searchResultDetails.filter(function (item) {
return item.Selected;
});
return selectedItems.length === $scope.searchResultDetails.length;
}
var setAllSelected = function (value) {
angular.forEach($scope.searchResultDetails, function (item) {
item.Selected = value;
});
}
$scope.allSelected = function (value) {
if (value !== undefined) {
return setAllSelected(value);
} else {
return getAllSelected();
}
}
$scope.myStatusModel = {
'staus': '',
'description': '',
}
// End: select all or individual functionality
$scope.OpenWindowStatus = false;
// open popup window when checkbox get selected / close popup window uncheck the selected items
$scope.openUpdateWind = function () {
var ItemsSelected = $scope.searchResultDetails.filter(function (item) {
if (item.Selected === true) { return true; }
});
// $scope.getStatusList();
// alert(ItemsSelected.length);
if (ItemsSelected.length) {
$scope.myStatusModel = {
'staus': '',
'description': '',
}
$scope.OpenWindowStatus = true;
} else {
$scope.OpenWindowStatus = false;
}
}
// update the status details
$scope.statusUpdate = {
submit: function (form, myStatusModel) {
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 selectedItems = [];
var ItemsSelected = $scope.searchResultDetails.filter(function (item) {
if (item.Selected === true) {
let itemGetID = new getUpdateDetails(item.ID);
selectedItems.push(itemGetID);
return true;
}
});
function getUpdateDetails(id) {
this.dabookListId = id;
this.ListCodeStatus = $scope.myStatusModel.staus;
this.comments = $scope.myStatusModel.description;
}
var updateStudyMaterial = {
method: 'POST',
url: apiPoint.url + 'updateDayBookStatusAdmin/',
headers: {
'Content-Type': 'application/json'
},
data: {
data: selectedItems,
requestDetails: localDetails
}
};
$http(updateStudyMaterial).then(function (response) {
if (response.data.addStatus) {
swal("Success!", response.data.message, "success");
// for success state
$scope.getDayBookList();
$scope.allSelected('undefined');
$scope.OpenWindowStatus = false;
} else {
swal("Failed!", response.data.message, "error");
}
});
}
},
reset: function (form) {
form.$setPristine(true);
$scope.myStatusModel = {
'staus': '',
'description': '',
}
}
}
$scope.statusList = [{
"status_id": 'TS001',
"name": "Pending",
}, {
"status_id": 'TS002',
"name": "Approved",
}, {
"status_id": 'TS003',
"name": "Rejected",
}];
$scope.data = [{
"id": 1,
"date": "20-12-2017",
"incomeExpense": "Income",
"type": "typeIncome1",
"amount": "1000",
"status": "Pending",
"description": "income type income type income type"
}, {
"id": 2,
"date": "20-12-2017",
"incomeExpense": "Expense",
"type": "typeIncome2",
"amount": "2000",
"status": "Pending",
"description": "income type income type income type"
}, {
"id": 3,
"date": "20-12-2017",
"incomeExpense": "Expense",
"type": "typeIncome3",
"amount": "3000",
"status": "Pending",
"description": "income type income type income type"
}];
$scope.incomeExpenseType = [{
"type_id": 1,
"type": "Income",
"name": "fees"
}, {
"type_id": 2,
"type": "Expense",
"name": "food"
}, {
"type_id": 3,
"type": "Expense",
"name": "phone"
}, {
"type_id": 4,
"type": "Expense",
"name": "tea-coffee"
}, {
"type_id": 5,
"type": "Expense",
"name": "Paper"
}];
$scope.getIncomeExpense = function () {
$scope.incomeExpenseName = [{
"type_id": 1,
"type": "TYPE001",
"name": "Income"
}, {
"type_id": 2,
"type": "TYPE002",
"name": "Expense"
}];
}
$scope.getIncomeTypes = $scope.incomeExpenseType.filter(function (val) {
return val.type === 'Income' ? 1 : 0;
});
$scope.getExpenseTypes = $scope.incomeExpenseType.filter(function (val) {
return val.type === 'Expense' ? 1 : 0;
});
$scope.getType = function (type) {
// alert(type);
$scope.myModelAdd.type = '';
$scope.getTypes = type === 'Income' ? $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": ""
}
}
$scope.myModel = {
"id": "",
"date": "",
"incomeExpense": "",
"type": "",
"amount": "",
"status": "",
"description": ""
}
$scope.copyModel = function (p) {
$scope.myModel = {
"id": p.id,
"date": p.date,
"incomeExpense": p.incomeExpense,
"type": p.type,
"amount": p.amount,
"status": p.status,
"description": p.description
}
}
// delete the entry row from the daybook list
$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();
// if( $scope.indexDelete2() === true) {
// $scope.data;
// swal("Deleted!", "Your imaginary file has been deleted.", "success");
// }
});
$scope.indexDelete2 = function () {
let ans = $scope.data.some(function (val, i) {
if (val.id === id) {
$scope.data.splice(i, 1);
swal("Deleted!", "Your record has been deleted.", "success");
return true;
}
}); return ans;
}
}
$scope.myModelAdd = {
"id": "",
"date": "",
"name": "",
"type": "",
"amount": "",
"status": "",
"description": ""
}
// add a new entry to the day book list
$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 {
var formate = "dd-MM-yyyy";
$scope.myModelAdd.date = $filter('date')(new Date($scope.myModelAdd.date), formate);
$scope.myModelAdd.status = 'Pending';
$scope.data.push(myModelAdd);
}
}
}
// update daybook entry data from the list
$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 {
// var studentForUpdate = [];
// let formate = "dd-MM-yyyy";
// $scope.myStatusModel.dateOn = $filter('date')(new Date($scope.myStatusModel.dateOn), formate);
// var ItemsSelected = $scope.searchResultDetails.filter(function (item) {
// if (item.Selected === true) {
// let getStudentID = new getStudentForUpdateDetails(item.StudentID);
// studentForUpdate.push(getStudentID);
// return true;
// }
// });
// function getStudentForUpdateDetails(id) {
// this.StudentID = id;
// this.CourseID = $scope.myStatusModel.semYear;
// this.BranchCode = localDetails.localBranchID;
// this.ListCode = $scope.myStatusModel.staus;
// this.SDate = $scope.myStatusModel.dateOn;
// this.Coursedetail = id;
// this.Comments = $scope.myStatusModel.comment;
// }
// // alert(JSON.stringify($scope.myStatusModel));
// // alert(JSON.stringify(studentForUpdate));
// var updateStudyMaterial = {
// method: 'POST',
// url: apiPoint.url + 'updateStudentMaterialStatus/',
// headers: {
// 'Content-Type': 'application/json'
// },
// data: {
// data: studentForUpdate,
// requestDetails : localDetails
// }
// };
// $http(updateStudyMaterial).then(function (response) {
// if (response.data.addStatus) {
// swal("Success!", response.data.message, "success");
// // for success state
// $scope.allSelected('undefined');
// $scope.OpenWindowStatus = false;
// } else {
// swal("Failed!", response.data.message, "error");
// }
// });
}
},
// reset: function (form) {
// form.$setPristine(true);
// $scope.myStatusModel = {
// 'semYear': '',
// 'staus': '',
// 'dateOn': '',
// 'comment': ''
// }
// }
}
}]);