308 lines
11 KiB
JavaScript
308 lines
11 KiB
JavaScript
'use strict';
|
|
|
|
var overlord_service = angular.module('overlord.service', ['ngResource']);
|
|
|
|
overlord_service.factory('IssueGrid', ['$resource', function ($resource) {
|
|
return $resource('/api/Issues/Services/:date');
|
|
}]);
|
|
|
|
overlord_service.factory('Voucher', ['$resource', function ($resource) {
|
|
return $resource('/api/Voucher/:id',
|
|
{id: '@VoucherID'}, {
|
|
post: {method: 'POST', params: {post: true}}
|
|
});
|
|
}]);
|
|
|
|
overlord_service.factory('Account', ['$resource', function ($resource) {
|
|
return $resource('/api/Account/:id',
|
|
{id: '@LedgerID'}, {
|
|
query: {method: 'GET', params: {list: true}, isArray: true},
|
|
autocomplete: {method: 'GET', params: {term: ''}, isArray: true}
|
|
});
|
|
}]);
|
|
|
|
overlord_service.factory('Recipe', ['$resource', function ($resource) {
|
|
return $resource('/api/Recipe/:id',
|
|
{id: '@RecipeID'}, {
|
|
query: {method: 'GET', params: {list: true}, isArray: true}
|
|
});
|
|
}]);
|
|
|
|
overlord_service.factory('Employee', ['$resource', function ($resource) {
|
|
return $resource('/api/Employee/:id',
|
|
{id: '@LedgerID'}, {
|
|
query: {method: 'GET', params: {list: true}, isArray: true},
|
|
autocomplete: {method: 'GET', params: {term: ''}, isArray: true}
|
|
});
|
|
}]);
|
|
|
|
overlord_service.factory('Ledger', ['$resource', function ($resource) {
|
|
return $resource('/api/Ledger/:id');
|
|
}]);
|
|
|
|
overlord_service.factory('Reconcile', ['$resource', function ($resource) {
|
|
return $resource('/api/Reconcile/:id', {id: '@Account.LedgerID'});
|
|
}]);
|
|
|
|
overlord_service.factory('ProductLedger', ['$resource', function ($resource) {
|
|
return $resource('/api/ProductLedger/:id');
|
|
}]);
|
|
|
|
overlord_service.factory('CostCenter', ['$resource', function ($resource) {
|
|
return $resource('/api/CostCenter/:id',
|
|
{id: '@CostCenterID'}, {
|
|
query: {method: 'GET', params: {list: true}, isArray: true}
|
|
});
|
|
}]);
|
|
|
|
overlord_service.factory('AccountType', ['$resource', function ($resource) {
|
|
return $resource('/api/AccountTypes');
|
|
}]);
|
|
|
|
overlord_service.factory('User', ['$resource', function ($resource) {
|
|
return $resource('/api/User/:id',
|
|
{id: '@UserID'}, {
|
|
query: {method: 'GET', params: {list: true}, isArray: true},
|
|
names: {method: 'GET', params: {names: true}, isArray: true}
|
|
});
|
|
}]);
|
|
|
|
overlord_service.factory('Group', ['$resource', function ($resource) {
|
|
return $resource('/api/Group/:id',
|
|
{id: '@GroupID'}, {
|
|
query: {method: 'GET', params: {list: true}, isArray: true}
|
|
});
|
|
}]);
|
|
|
|
overlord_service.factory('Client', ['$resource', function ($resource) {
|
|
return $resource('/api/Client/:id',
|
|
{id: '@ClientID'}, {
|
|
query: {method: 'GET', params: {list: true}, isArray: true}
|
|
});
|
|
}]);
|
|
|
|
overlord_service.factory('Product', ['$resource', function ($resource) {
|
|
return $resource('/api/Product/:id',
|
|
{id: '@ProductID'}, {
|
|
query: {method: 'GET', params: {list: true}, isArray: true},
|
|
autocomplete: {method: 'GET', params: {term: ''}, isArray: true}
|
|
});
|
|
}]);
|
|
|
|
overlord_service.factory('Batch', ['$resource', function ($resource) {
|
|
return $resource('/api/Batch', {}, {
|
|
autocomplete: {method: 'GET', params: {term: ''}, isArray: true}
|
|
});
|
|
}]);
|
|
|
|
overlord_service.factory('ProductGroup', ['$resource', function ($resource) {
|
|
return $resource('/api/ProductGroup/:id',
|
|
{id: '@ProductGroupID'}, {
|
|
query: {method: 'GET', params: {list: true}, isArray: true}
|
|
});
|
|
}]);
|
|
|
|
overlord_service.factory('CostCenter', ['$resource', function ($resource) {
|
|
return $resource('/api/CostCenter/:id',
|
|
{id: '@CostCenterID'}, {
|
|
query: {method: 'GET', params: {list: true}, isArray: true}
|
|
});
|
|
}]);
|
|
|
|
overlord_service.factory('TrialBalance', ['$resource', function ($resource) {
|
|
return $resource('/api/TrialBalance/:date');
|
|
}]);
|
|
|
|
overlord_service.factory('ClosingStock', ['$resource', function ($resource) {
|
|
return $resource('/api/ClosingStock/:date');
|
|
}]);
|
|
|
|
overlord_service.factory('CashFlow', ['$resource', function ($resource) {
|
|
return $resource('/api/CashFlow/:id');
|
|
}]);
|
|
|
|
overlord_service.factory('Daybook', ['$resource', function ($resource) {
|
|
return $resource('/api/Daybook');
|
|
}]);
|
|
|
|
overlord_service.factory('Unposted', ['$resource', function ($resource) {
|
|
return $resource('/api/Unposted');
|
|
}]);
|
|
|
|
overlord_service.factory('ProfitLoss', ['$resource', function ($resource) {
|
|
return $resource('/api/ProfitLoss');
|
|
}]);
|
|
|
|
overlord_service.factory('StockMovement', ['$resource', function ($resource) {
|
|
return $resource('/api/StockMovement');
|
|
}]);
|
|
|
|
overlord_service.factory('BalanceSheet', ['$resource', function ($resource) {
|
|
return $resource('/api/BalanceSheet/:date');
|
|
}]);
|
|
|
|
overlord_service.factory('NetTransactions', ['$resource', function ($resource) {
|
|
return $resource('/api/NetTransactions');
|
|
}]);
|
|
|
|
overlord_service.factory('Purchases', ['$resource', function ($resource) {
|
|
return $resource('/api/Purchases');
|
|
}]);
|
|
|
|
overlord_service.factory('PurchaseEntries', ['$resource', function ($resource) {
|
|
return $resource('/api/PurchaseEntries');
|
|
}]);
|
|
|
|
overlord_service.factory('RawMaterialCost', ['$resource', function ($resource) {
|
|
return $resource('/api/RawMaterialCost/:id');
|
|
}]);
|
|
|
|
overlord_service.factory('Auth', ['$resource', function ($resource) {
|
|
return $resource('/api/Auth', {}, {
|
|
login: {method: 'GET', params: {list: true}, isArray: true}
|
|
});
|
|
}]);
|
|
|
|
overlord_service.factory('Attendance', ['$resource', function ($resource) {
|
|
return $resource('/api/Attendance/:date', {date: '@Date'});
|
|
}]);
|
|
|
|
overlord_service.factory('AttendanceTypes', ['$resource', function ($resource) {
|
|
return $resource('/api/AttendanceTypes');
|
|
}]);
|
|
|
|
overlord_service.factory('EmployeeAttendance', ['$resource', function ($resource) {
|
|
return $resource('/api/EmployeeAttendance/:id', {id: '@Employee.LedgerID'});
|
|
}]);
|
|
|
|
overlord_service.factory('Account', ['$resource', function ($resource) {
|
|
return $resource('/api/Account/:id',
|
|
{id: '@LedgerID'}, {
|
|
query: {method: 'GET', params: {list: true}, isArray: true},
|
|
autocomplete: {method: 'GET', params: {term: ''}, isArray: true}
|
|
});
|
|
}]);
|
|
overlord_service.factory('Message', ['$resource', function ($resource) {
|
|
return $resource('/api/Message/:id',
|
|
{id: '@ThreadID'}, {
|
|
query: {method: 'GET', params: {list: true}}
|
|
});
|
|
}]);
|
|
|
|
overlord_service.factory('Tag', ['$resource', function ($resource) {
|
|
return $resource('/api/Tags');
|
|
}]);
|
|
|
|
overlord_service.service('EventSource', function () {
|
|
this.status = 'Disconnected';
|
|
this.Open = function (url) {
|
|
if (url) {
|
|
this.url = url;
|
|
}
|
|
if (this.url) {
|
|
this.source = new EventSource(url);
|
|
if (this.status !== 'Open') {
|
|
this.source.addEventListener('open', function (e) {
|
|
this.status = 'Open';
|
|
}, false);
|
|
}
|
|
}
|
|
};
|
|
this.DataCallback = function (callback) {
|
|
this.source.addEventListener('message', function (e) {
|
|
var data = JSON.parse(e.data);
|
|
callback(e);
|
|
}, false);
|
|
};
|
|
this.source.addEventListener('error', function (e) {
|
|
if (e.readyState == EventSource.CLOSED) {
|
|
this.status = 'Error';
|
|
}
|
|
}, false);
|
|
this.ErrorCallback = function (callback) {
|
|
this.source.addEventListener('error', callback, false);
|
|
}
|
|
|
|
this.EventCallback = function (event, callback) {
|
|
this.source.addEventListener(event, callback, false);
|
|
}
|
|
|
|
this.Close = function () {
|
|
if (this.status === 'Open') {
|
|
this.source.close();
|
|
this.status = 'Closed'
|
|
}
|
|
}
|
|
});
|
|
|
|
overlord_service.factory('Tokenizer', ['$filter', function ($filter) {
|
|
var parseFilterString = function (q, searchInfo) {
|
|
var re = /((([^ ]+):\s*('[^':]+'|"[^":]+"|[^ ]+))|[^ ]+[^: '"]*)/g,
|
|
comparator = searchInfo.comparator,
|
|
sorter = searchInfo.sorter,
|
|
defaultKey = comparator[comparator.def],
|
|
matches = [],
|
|
sorting = [],
|
|
flags = {};
|
|
|
|
|
|
function isTrue(value) {
|
|
return !_.any(['f', 'fa', 'fal', 'fals', 'false', 'n', 'no', '0'], function (item) {
|
|
return item === value;
|
|
});
|
|
}
|
|
|
|
function pushObject(comparator, value) {
|
|
return {'Col': comparator.Col, 'Comparator': comparators[comparator.Comparator], 'Value': value};
|
|
}
|
|
|
|
var comparators = {
|
|
'text': function (obj, text) {
|
|
return obj.toLowerCase().indexOf(text) > -1;
|
|
},
|
|
'boolean': function (obj, text) {
|
|
return obj === isTrue(text);
|
|
},
|
|
'true': function (obj, text) {
|
|
return true;
|
|
}
|
|
};
|
|
var m = q.match(re);
|
|
_.forEach(m, function (item) {
|
|
item = item.trim();
|
|
if (item.indexOf(':') === -1) {
|
|
if ((item.length > 1) && (item.charAt(0) === '+' || item.charAt(0) === '-') && (item.substr(1) in sorter)) {
|
|
sorting.push(item.charAt(0) + sorter[item.substr(1).toLowerCase()]);
|
|
} else if (item.length >= 1 && item.charAt(0) !== '+' && item.charAt(0) !== '-') {
|
|
matches.push(pushObject(defaultKey, item));
|
|
}
|
|
} else {
|
|
var key = item.substr(0, item.indexOf(':')).toLowerCase();
|
|
var value = item.substr(item.indexOf(':') + 1, item.length).trim().toLowerCase();
|
|
if (value.indexOf("'") !== -1 || value.indexOf('"') !== -1) {
|
|
value = value.substring(1, value.length - 1).trim();
|
|
}
|
|
if (key !== '' && value !== '' && key in comparator) {
|
|
matches.push(pushObject(comparator[key], value));
|
|
} else if (key !== '' && key in searchInfo.flags) {
|
|
flags[key] = value;
|
|
}
|
|
}
|
|
});
|
|
return {'q': matches, 'o': sorting, 'f': flags};
|
|
};
|
|
var doFilter = _.memoize(function (q, array, matches) {
|
|
var filterExpressions = matches.q,
|
|
sortPredicates = matches.o,
|
|
filterCount = filterExpressions.length;
|
|
var arrayCopy = filterCount === 0 ? array : _.filter(array, function (item) {
|
|
return _.every(filterExpressions, function (expression) {
|
|
return expression.Comparator(item[expression.Col], expression.Value);
|
|
});
|
|
});
|
|
arrayCopy = sortPredicates.length === 0 ? arrayCopy : $filter('orderBy')(arrayCopy, sortPredicates);
|
|
return arrayCopy;
|
|
});
|
|
|
|
return {'parseFilterString': parseFilterString, 'doFilter': doFilter };
|
|
}]); |