Chore: Variable renaming in JavaScript to camelCase

Feature: Keyboard navigation in Accounts, Employees and Product List.
Chore: Removing unused JavasScript variables in function for JSHint
This commit is contained in:
Amritanshu committed 2014-06-09 13:08:36 +05:30
1 parent 1989c54e92
commit d99fc89e34
26 files changed
+372 -297

No files matched your search

+9 -6
View File
@@ -1,15 +1,17 @@
<h2>Accounts <h2>Accounts
<div class="form-group col-md-9 pull-right"> <div class="form-group col-md-9 pull-right">
<div class="col-md-10"> <div class="col-md-10">
<input type="text" class="form-control" placeholder="Search: n:Name, a:Active, u:Units, g:Group, e:true for extended properties, &quot; or ' for Quotes" ng-model="search"> <input type="text" class="form-control"
placeholder="Search: n:Name, a:Active, u:Units, g:Group, e:true for extended properties, &quot; or ' for Quotes"
ng-model="search">
</div> </div>
<div class="col-md-2"> <div class="col-md-2">
<a href="/Account" class="btn btn-success btn-block">Add <i <a href="/Account" class="btn btn-success btn-block">Add <i
class="glyphicon glyphicon-plus"></i></a> class="glyphicon glyphicon-plus"></i></a>
</div> </div>
</div> </div>
</h2> </h2>
<table class="table table-condensed table-bordered table-striped"> <table class="table table-condensed table-bordered table-striped" keypress="shortcuts">
<thead> <thead>
<tr> <tr>
<th>Name</th> <th>Name</th>
@@ -20,7 +22,8 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr ng-repeat="item in accounts"> <tr id="{{$index}}" ng-repeat="item in accounts" ng-class="{warning:$index==selected}"
ng-click="setSelected($index)">
<td><a href="{{item.Url}}">{{item.Name}}</a></td> <td><a href="{{item.Url}}">{{item.Name}}</a></td>
<td>{{item.Type}}</td> <td>{{item.Type}}</td>
<td>{{item.IsActive}}</td> <td>{{item.IsActive}}</td>
+7 -6
View File
@@ -4,12 +4,12 @@
<input type="text" class="form-control" placeholder="Search" ng-model="search"> <input type="text" class="form-control" placeholder="Search" ng-model="search">
</div> </div>
<div class="col-md-2"> <div class="col-md-2">
<a href="/Employee" class="btn btn-success btn-block">Add <i <a href="/Employee" class="btn btn-success btn-block">Add <i
class="glyphicon glyphicon-plus"></i></a> class="glyphicon glyphicon-plus"></i></a>
</div> </div>
</div> </div>
</h2> </h2>
<table class="table table-condensed table-bordered table-striped"> <table class="table table-condensed table-bordered table-striped" keypress="shortcuts">
<thead> <thead>
<tr> <tr>
<th>Code</th> <th>Code</th>
@@ -22,8 +22,9 @@
<th>Leaving Date</th> <th>Leaving Date</th>
</tr> </tr>
</thead> </thead>
<tbody id="tbodyMain"> <tbody>
<tr ng-repeat="item in employees"> <tr id="{{$index}}" ng-repeat="item in employees" ng-class="{warning:$index==selected}"
ng-click="setSelected($index)">
<td>{{item.Code}}</td> <td>{{item.Code}}</td>
<td><a href="{{item.Url}}">{{item.Name}}</a></td> <td><a href="{{item.Url}}">{{item.Name}}</a></td>
<td>{{item.Designation}}</td> <td>{{item.Designation}}</td>
+5 -5
View File
@@ -51,7 +51,7 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr id="{{$index}}" ng-repeat="item in display.Body" ng-class="{danger:!item.Posted && $index!=selected, warning:$index==selected}" <tr id="{{$index}}" ng-repeat="item in ledger" ng-class="{danger:!item.Posted && $index!=selected, warning:$index==selected}"
ng-click="setSelected($index)"> ng-click="setSelected($index)">
<td class="no-wrap">{{item.Date}}</td> <td class="no-wrap">{{item.Date}}</td>
<td><a href="{{item.Url}}">{{item.Name}}</a></td> <td><a href="{{item.Url}}">{{item.Name}}</a></td>
@@ -64,13 +64,13 @@
</tbody> </tbody>
<tfoot> <tfoot>
<tr> <tr>
<td class="no-wrap">{{display.Footer.Date}}</td> <td class="no-wrap"></td>
<td>Closing Balance</td> <td>Closing Balance</td>
<td>Closing Balance</td> <td>Closing Balance</td>
<td></td> <td></td>
<td class="text-right no-wrap">{{display.Footer.Debit | currency}}</td> <td class="text-right no-wrap">{{footer.Debit | currency}}</td>
<td class="text-right no-wrap">{{display.Footer.Credit | currency}}</td> <td class="text-right no-wrap">{{footer.Credit | currency}}</td>
<td class="text-right no-wrap">{{display.Footer.Running | accounting}}</td> <td class="text-right no-wrap">{{footer.Running | accounting}}</td>
</tr> </tr>
</tfoot> </tfoot>
</table> </table>
+3 -2
View File
@@ -9,7 +9,7 @@
</div> </div>
</div> </div>
</h2> </h2>
<table class="table table-condensed table-bordered table-striped"> <table class="table table-condensed table-bordered table-striped" keypress="shortcuts">
<thead> <thead>
<tr> <tr>
<th class="text-right">Code</th> <th class="text-right">Code</th>
@@ -21,7 +21,8 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr ng-repeat="item in products"> <tr id="{{$index}}" ng-repeat="item in products" ng-class="{warning:$index==selected}"
ng-click="setSelected($index)">
<td class="text-right">{{item.Code}}</td> <td class="text-right">{{item.Code}}</td>
<td><a href="{{item.Url}}">{{item.Name}} ({{showExtended ? item.Fraction + ' ' + item.FractionUnits + ' = 1 ' : ''}}{{item.Units}})</a></td> <td><a href="{{item.Url}}">{{item.Name}} ({{showExtended ? item.Fraction + ' ' + item.FractionUnits + ' = 1 ' : ''}}{{item.Units}})</a></td>
<td class="text-right">{{item.Price | currency}}</td> <td class="text-right">{{item.Price | currency}}</td>
+29 -4
View File
@@ -44,6 +44,31 @@ var AccountListCtrl = ['$scope', '$location', '$routeParams', 'Tokenizer', 'acco
}); });
} }
}, 350); }, 350);
$scope.selected = -1;
$scope.setSelected = function (index) {
$scope.selected = Math.min(Math.max(0, index), $scope.accounts.length - 1);
};
$scope.shortcuts = {
'up': function (e) {
if ($scope.selected > 0) {
$scope.$apply(function () {
$scope.selected = Math.min(Math.max(0, $scope.selected - 1), $scope.accounts.length - 1);
});
$("#" + $scope.selected).scrollintoview();
e.preventDefault();
}
},
'down': function (e) {
if ($scope.selected < $scope.accounts.length - 1) {
$scope.$apply(function () {
$scope.selected = Math.min(Math.max(0, $scope.selected + 1), $scope.accounts.length - 1);
});
$("#" + $scope.selected).scrollintoview();
e.preventDefault();
}
}
};
}]; }];
AccountListCtrl.resolve = { AccountListCtrl.resolve = {
accounts: ['Account', function (Account) { accounts: ['Account', function (Account) {
@@ -58,19 +83,19 @@ var AccountCtrl = ['$scope', '$location', '$modal', 'account', 'accountTypes', '
$scope.costCenters = costCenters; $scope.costCenters = costCenters;
$scope.save = function () { $scope.save = function () {
$scope.account.$save(function (u, putResponseHeaders) { $scope.account.$save(function () {
$scope.toasts.push({Type: 'Success', Message: ''}); $scope.toasts.push({Type: 'Success', Message: ''});
$location.path('/Accounts'); $location.path('/Accounts');
}, function (data, status) { }, function (data) {
$scope.toasts.push({Type: 'Danger', Message: data.data}); $scope.toasts.push({Type: 'Danger', Message: data.data});
}); });
}; };
$scope.delete = function () { $scope.delete = function () {
$scope.account.$delete(function (u, putResponseHeaders) { $scope.account.$delete(function () {
$scope.toasts.push({Type: 'Success', Message: ''}); $scope.toasts.push({Type: 'Success', Message: ''});
$location.path('/Accounts'); $location.path('/Accounts');
}, function (data, status) { }, function (data) {
$scope.toasts.push({Type: 'Danger', Message: data.data}); $scope.toasts.push({Type: 'Danger', Message: data.data});
}); });
}; };
+40 -34
View File
@@ -1,7 +1,7 @@
'use strict'; 'use strict';
var overlord_directive = angular.module('overlord.directive', []); var overlordDirective = angular.module('overlord.directive', []);
overlord_directive.directive('fadey', function () { overlordDirective.directive('fadey', function () {
return { return {
restrict: 'A', restrict: 'A',
link: function (scope, element, attrs) { link: function (scope, element, attrs) {
@@ -22,7 +22,7 @@ overlord_directive.directive('fadey', function () {
}; };
}); });
overlord_directive.directive('ngGrowl', ['growl', '$parse', function (growl, $parse) { overlordDirective.directive('ngGrowl', ['growl', '$parse', function (growl, $parse) {
return { return {
restrict: 'A', restrict: 'A',
link: function (scope, element, attrs) { link: function (scope, element, attrs) {
@@ -34,7 +34,7 @@ overlord_directive.directive('ngGrowl', ['growl', '$parse', function (growl, $pa
}; };
}]); }]);
overlord_directive.directive('aceEditor', ['$parse', function ($parse) { overlordDirective.directive('aceEditor', ['$parse', function ($parse) {
var ACE_EDITOR_CLASS = 'ace-editor'; var ACE_EDITOR_CLASS = 'ace-editor';
function loadAceEditor(element, mode) { function loadAceEditor(element, mode) {
@@ -64,13 +64,15 @@ overlord_directive.directive('aceEditor', ['$parse', function ($parse) {
$(editorElement).css("border", "1px solid #ddd"); $(editorElement).css("border", "1px solid #ddd");
$(editorElement).css("border-radius", "4px"); $(editorElement).css("border-radius", "4px");
if (!ngModel) return; // do nothing if no ngModel if (!ngModel) {
return; // do nothing if no ngModel
}
var getter = $parse(attrs['ngModel']); var getter = $parse(attrs.ngModel);
var setter = getter.assign; var setter = getter.assign;
editor.getSession().setValue(getter(scope)); editor.getSession().setValue(getter(scope));
scope.$watch(attrs['ngModel'], function (newValue) { scope.$watch(attrs.ngModel, function (newValue) {
if (editor.getValue() !== newValue) { if (editor.getValue() !== newValue) {
editor.getSession().setValue(newValue); editor.getSession().setValue(newValue);
} }
@@ -87,16 +89,16 @@ overlord_directive.directive('aceEditor', ['$parse', function ($parse) {
}; };
}]); }]);
overlord_directive.directive('chosen', ['$parse', function ($parse) { overlordDirective.directive('chosen', ['$parse', function ($parse) {
var linker = function (scope, element, attrs) { var linker = function (scope, element, attrs) {
var model = attrs['ngModel'], var model = attrs.ngModel,
list = attrs['chosen'], list = attrs.chosen,
createFunction = attrs['createFunction'], createFunction = attrs.createFunction,
options = {}; options = {};
if (angular.isUndefined(createFunction)) { if (angular.isUndefined(createFunction)) {
options['create_option'] = function (data) { options.create_option = function (data) {
var fn = $parse(attrs['createFunction'] + '("' + data + '")'); var fn = $parse(attrs.createFunction + '("' + data + '")');
scope.$apply(function () { scope.$apply(function () {
fn(scope); fn(scope);
}); });
@@ -120,30 +122,34 @@ overlord_directive.directive('chosen', ['$parse', function ($parse) {
}; };
}]); }]);
overlord_directive.directive('keypress', [function () { overlordDirective.directive('keypress', [function () {
return function (scope, element, attrs) { return function (scope, element, attrs) {
var attribute = scope.$eval(attrs.keypress || '{}'); var keypress = scope.$eval(attrs.keypress || '{}');
for (var k in attribute) { for (var k in keypress) {
(function (k) { if (keypress.hasOwnProperty(k)) {
Mousetrap.bind(k, attribute[k]); (function (k, val) {
})(k); Mousetrap.bind(k, val);
})(k, keypress[k]);
}
} }
element.on('$destroy', function () { element.on('$destroy', function () {
for (var k in attribute) { for (var k in keypress) {
(function (k) { if (keypress.hasOwnProperty(k)) {
Mousetrap.unbind(k); (function (k) {
})(k); Mousetrap.unbind(k);
})(k);
}
} }
}); });
}; };
}]); }]);
overlord_directive.directive('onReturn', ['$parse', function ($parse) { overlordDirective.directive('onReturn', ['$parse', function ($parse) {
return { return {
compile: function ($element, attr) { compile: function ($element, attr) {
var fn = $parse(attr["onReturn"]); var fn = $parse(attr.onReturn);
return function (scope, element, attr) { return function (scope, element) {
element.on("keypress", function (event) { element.on("keypress", function (event) {
if (event.which === 13) { if (event.which === 13) {
scope.$apply(function () { scope.$apply(function () {
@@ -158,7 +164,7 @@ overlord_directive.directive('onReturn', ['$parse', function ($parse) {
}]); }]);
overlord_directive.directive('tanSse', ['$parse', function ($parse) { overlordDirective.directive('tanSse', ['$parse', function ($parse) {
return{ return{
restrict: 'EM', restrict: 'EM',
link: function ($scope, element, attrs) { link: function ($scope, element, attrs) {
@@ -190,7 +196,7 @@ overlord_directive.directive('tanSse', ['$parse', function ($parse) {
}; };
}]); }]);
overlord_directive.directive('tanClick', ['$parse', '$timeout', function ($parse, $timeout) { overlordDirective.directive('tanClick', ['$parse', '$timeout', function ($parse, $timeout) {
return { return {
compile: function ($element, attr) { compile: function ($element, attr) {
var fn = $parse(attr.tanClick); var fn = $parse(attr.tanClick);
@@ -216,7 +222,7 @@ overlord_directive.directive('tanClick', ['$parse', '$timeout', function ($parse
}; };
}]); }]);
overlord_directive.directive('chartDiscreteBar', ['$parse', function ($parse) { overlordDirective.directive('chartDiscreteBar', ['$parse', function ($parse) {
return { return {
restrict: 'A', restrict: 'A',
link: function (scope, element, attrs) { link: function (scope, element, attrs) {
@@ -246,7 +252,7 @@ overlord_directive.directive('chartDiscreteBar', ['$parse', function ($parse) {
}; };
}]); }]);
overlord_directive.directive('chartMultiBar', ['$parse', function ($parse) { overlordDirective.directive('chartMultiBar', ['$parse', function ($parse) {
return { return {
restrict: 'A', restrict: 'A',
link: function (scope, element, attrs) { link: function (scope, element, attrs) {
@@ -267,7 +273,7 @@ overlord_directive.directive('chartMultiBar', ['$parse', function ($parse) {
}; };
}]); }]);
overlord_directive.directive('chartLine', ['$parse', function ($parse) { overlordDirective.directive('chartLine', ['$parse', function ($parse) {
return { return {
restrict: 'A', restrict: 'A',
link: function (scope, element, attrs) { link: function (scope, element, attrs) {
@@ -290,7 +296,7 @@ overlord_directive.directive('chartLine', ['$parse', function ($parse) {
}; };
}]); }]);
overlord_directive.directive('chartPie', ['$parse', function ($parse) { overlordDirective.directive('chartPie', ['$parse', function ($parse) {
return { return {
restrict: 'A', restrict: 'A',
link: function (scope, element, attrs) { link: function (scope, element, attrs) {
@@ -328,7 +334,7 @@ overlord_directive.directive('chartPie', ['$parse', function ($parse) {
}; };
}]); }]);
overlord_directive.directive('chartLinePlusBar', ['$parse', function ($parse) { overlordDirective.directive('chartLinePlusBar', ['$parse', function ($parse) {
return { return {
restrict: 'A', restrict: 'A',
link: function (scope, element, attrs) { link: function (scope, element, attrs) {
@@ -368,7 +374,7 @@ overlord_directive.directive('chartLinePlusBar', ['$parse', function ($parse) {
}; };
}]); }]);
overlord_directive.directive('fileUpload', function () { overlordDirective.directive('fileUpload', function () {
return { return {
scope: true, //create a new scope scope: true, //create a new scope
link: function (scope, el, attrs) { link: function (scope, el, attrs) {
+16 -16
View File
@@ -1,11 +1,11 @@
'use strict'; 'use strict';
var overlord_filter = angular.module('overlord.filter', []); var overlordFilter = angular.module('overlord.filter', []);
overlord_filter.filter('debit', function () { overlordFilter.filter('debit', function () {
return function (input) { return function (input) {
if (input == -1) { if (input === -1) {
return 'Cr'; return 'Cr';
} else if (input == 1) { } else if (input === 1) {
return 'Dr'; return 'Dr';
} else { } else {
return ''; return '';
@@ -13,26 +13,26 @@ overlord_filter.filter('debit', function () {
}; };
}); });
overlord_filter.filter('posted', function () { overlordFilter.filter('posted', function () {
return function (input) { return function (input) {
return input === true ? 'Posted' : 'Post'; return input === true ? 'Posted' : 'Post';
}; };
}); });
overlord_filter.filter('md', function () { overlordFilter.filter('md', function () {
var converter = new Showdown.converter(); var converter = new Showdown.converter();
return function (input) { return function (input) {
return converter.makeHtml(input || ''); return converter.makeHtml(input || '');
}; };
}); });
overlord_filter.filter('save_button', function () { overlordFilter.filter('save_button', function () {
return function (input) { return function (input) {
return (!input) ? 'Save' : 'Update'; return (!input) ? 'Save' : 'Update';
}; };
}); });
overlord_filter.filter('journalDebit', function () { overlordFilter.filter('journalDebit', function () {
return function (input, debit) { return function (input, debit) {
var list = []; var list = [];
if (!angular.isUndefined(input)) { if (!angular.isUndefined(input)) {
@@ -46,7 +46,7 @@ overlord_filter.filter('journalDebit', function () {
}; };
}); });
overlord_filter.filter('localTime', function () { overlordFilter.filter('localTime', function () {
var months = { var months = {
Jan: 1, Jan: 1,
Feb: 2, Feb: 2,
@@ -61,7 +61,7 @@ overlord_filter.filter('localTime', function () {
Nov: 11, Nov: 11,
Dec: 12 Dec: 12
}; };
var months_reverse = { var monthsReverse = {
1: 'Jan', 1: 'Jan',
2: 'Feb', 2: 'Feb',
3: 'Mar', 3: 'Mar',
@@ -92,12 +92,12 @@ overlord_filter.filter('localTime', function () {
} }
var date = new Date(parseInt(d[2]), months[d[1]] - 1, parseInt(d[0]), parseInt(d[3]), parseInt(d[4])).getTime(); var date = new Date(parseInt(d[2]), months[d[1]] - 1, parseInt(d[0]), parseInt(d[3]), parseInt(d[4])).getTime();
date = new Date(date - (new Date().getTimezoneOffset() * 60000)); date = new Date(date - (new Date().getTimezoneOffset() * 60000));
var output = padNumber(date.getDate()) + '-' + months_reverse[date.getMonth() + 1] + '-' + date.getFullYear() + ' ' + padNumber(date.getHours()) + ':' + padNumber(date.getMinutes()); var output = padNumber(date.getDate()) + '-' + monthsReverse[date.getMonth() + 1] + '-' + date.getFullYear() + ' ' + padNumber(date.getHours()) + ':' + padNumber(date.getMinutes());
return output; return output;
}; };
}); });
overlord_filter.filter('percent', ['numberFilter', function (numberFilter) { overlordFilter.filter('percent', ['numberFilter', function (numberFilter) {
return function (input) { return function (input) {
if (!angular.isNumber(input)) { if (!angular.isNumber(input)) {
return input; return input;
@@ -106,13 +106,13 @@ overlord_filter.filter('percent', ['numberFilter', function (numberFilter) {
}; };
}]); }]);
overlord_filter.filter('asDate', ['dateFilter', function (dateFilter) { overlordFilter.filter('asDate', ['dateFilter', function (dateFilter) {
return function (input) { return function (input) {
return angular.isDate(input) ? dateFilter(input, 'dd-MMM-yyyy') : input return angular.isDate(input) ? dateFilter(input, 'dd-MMM-yyyy') : input;
}; };
}]); }]);
overlord_filter.filter('clr', function () { overlordFilter.filter('clr', function () {
return function (input) { return function (input) {
if (input === '\u20B9\u00A00.00' || input === '0.00') { if (input === '\u20B9\u00A00.00' || input === '0.00') {
return ''; return '';
@@ -121,7 +121,7 @@ overlord_filter.filter('clr', function () {
}; };
}); });
overlord_filter.filter('accounting', ['currencyFilter', function (currencyFilter) { overlordFilter.filter('accounting', ['currencyFilter', function (currencyFilter) {
return function (amount) { return function (amount) {
amount = currencyFilter(amount); amount = currencyFilter(amount);
if (amount === '') { if (amount === '') {
+80 -121
View File
@@ -1,12 +1,12 @@
'use strict'; 'use strict';
var overlord_service = angular.module('overlord.service', ['ngResource']); var overlordService = angular.module('overlord.service', ['ngResource']);
overlord_service.factory('IssueGrid', ['$resource', function ($resource) { overlordService.factory('IssueGrid', ['$resource', function ($resource) {
return $resource('/api/Issues/Services/:date'); return $resource('/api/Issues/Services/:date');
}]); }]);
overlord_service.factory('Voucher', ['$resource', function ($resource) { overlordService.factory('Voucher', ['$resource', function ($resource) {
return $resource('/api/Voucher/:id', return $resource('/api/Voucher/:id',
{id: '@VoucherID'}, { {id: '@VoucherID'}, {
post: {method: 'POST', params: {post: true}}, post: {method: 'POST', params: {post: true}},
@@ -50,7 +50,7 @@ overlord_service.factory('Voucher', ['$resource', function ($resource) {
}); });
}]); }]);
overlord_service.factory('Account', ['$resource', function ($resource) { overlordService.factory('Account', ['$resource', function ($resource) {
return $resource('/api/Account/:id', return $resource('/api/Account/:id',
{id: '@LedgerID'}, { {id: '@LedgerID'}, {
query: {method: 'GET', params: {list: true}, isArray: true}, query: {method: 'GET', params: {list: true}, isArray: true},
@@ -58,14 +58,14 @@ overlord_service.factory('Account', ['$resource', function ($resource) {
}); });
}]); }]);
overlord_service.factory('Recipe', ['$resource', function ($resource) { overlordService.factory('Recipe', ['$resource', function ($resource) {
return $resource('/api/Recipe/:id', return $resource('/api/Recipe/:id',
{id: '@RecipeID'}, { {id: '@RecipeID'}, {
query: {method: 'GET', params: {list: true}, isArray: true} query: {method: 'GET', params: {list: true}, isArray: true}
}); });
}]); }]);
overlord_service.factory('Employee', ['$resource', function ($resource) { overlordService.factory('Employee', ['$resource', function ($resource) {
return $resource('/api/Employee/:id', return $resource('/api/Employee/:id',
{id: '@LedgerID'}, { {id: '@LedgerID'}, {
query: {method: 'GET', params: {list: true}, isArray: true}, query: {method: 'GET', params: {list: true}, isArray: true},
@@ -73,30 +73,30 @@ overlord_service.factory('Employee', ['$resource', function ($resource) {
}); });
}]); }]);
overlord_service.factory('Ledger', ['$resource', function ($resource) { overlordService.factory('Ledger', ['$resource', function ($resource) {
return $resource('/api/Ledger/:id'); return $resource('/api/Ledger/:id');
}]); }]);
overlord_service.factory('Reconcile', ['$resource', function ($resource) { overlordService.factory('Reconcile', ['$resource', function ($resource) {
return $resource('/api/Reconcile/:id', {id: '@Account.LedgerID'}); return $resource('/api/Reconcile/:id', {id: '@Account.LedgerID'});
}]); }]);
overlord_service.factory('ProductLedger', ['$resource', function ($resource) { overlordService.factory('ProductLedger', ['$resource', function ($resource) {
return $resource('/api/ProductLedger/:id'); return $resource('/api/ProductLedger/:id');
}]); }]);
overlord_service.factory('CostCenter', ['$resource', function ($resource) { overlordService.factory('CostCenter', ['$resource', function ($resource) {
return $resource('/api/CostCenter/:id', return $resource('/api/CostCenter/:id',
{id: '@CostCenterID'}, { {id: '@CostCenterID'}, {
query: {method: 'GET', params: {list: true}, isArray: true} query: {method: 'GET', params: {list: true}, isArray: true}
}); });
}]); }]);
overlord_service.factory('AccountType', ['$resource', function ($resource) { overlordService.factory('AccountType', ['$resource', function ($resource) {
return $resource('/api/AccountTypes'); return $resource('/api/AccountTypes');
}]); }]);
overlord_service.factory('User', ['$resource', function ($resource) { overlordService.factory('User', ['$resource', function ($resource) {
return $resource('/api/User/:id', return $resource('/api/User/:id',
{id: '@UserID'}, { {id: '@UserID'}, {
query: {method: 'GET', params: {list: true}, isArray: true}, query: {method: 'GET', params: {list: true}, isArray: true},
@@ -104,21 +104,21 @@ overlord_service.factory('User', ['$resource', function ($resource) {
}); });
}]); }]);
overlord_service.factory('Group', ['$resource', function ($resource) { overlordService.factory('Group', ['$resource', function ($resource) {
return $resource('/api/Group/:id', return $resource('/api/Group/:id',
{id: '@GroupID'}, { {id: '@GroupID'}, {
query: {method: 'GET', params: {list: true}, isArray: true} query: {method: 'GET', params: {list: true}, isArray: true}
}); });
}]); }]);
overlord_service.factory('Client', ['$resource', function ($resource) { overlordService.factory('Client', ['$resource', function ($resource) {
return $resource('/api/Client/:id', return $resource('/api/Client/:id',
{id: '@ClientID'}, { {id: '@ClientID'}, {
query: {method: 'GET', params: {list: true}, isArray: true} query: {method: 'GET', params: {list: true}, isArray: true}
}); });
}]); }]);
overlord_service.factory('Product', ['$resource', function ($resource) { overlordService.factory('Product', ['$resource', function ($resource) {
return $resource('/api/Product/:id', return $resource('/api/Product/:id',
{id: '@ProductID'}, { {id: '@ProductID'}, {
query: {method: 'GET', params: {list: true}, isArray: true}, query: {method: 'GET', params: {list: true}, isArray: true},
@@ -126,153 +126,111 @@ overlord_service.factory('Product', ['$resource', function ($resource) {
}); });
}]); }]);
overlord_service.factory('Batch', ['$resource', function ($resource) { overlordService.factory('Batch', ['$resource', function ($resource) {
return $resource('/api/Batch', {}, { return $resource('/api/Batch', {}, {
autocomplete: {method: 'GET', params: {term: ''}, isArray: true} autocomplete: {method: 'GET', params: {term: ''}, isArray: true}
}); });
}]); }]);
overlord_service.factory('ProductGroup', ['$resource', function ($resource) { overlordService.factory('ProductGroup', ['$resource', function ($resource) {
return $resource('/api/ProductGroup/:id', return $resource('/api/ProductGroup/:id',
{id: '@ProductGroupID'}, { {id: '@ProductGroupID'}, {
query: {method: 'GET', params: {list: true}, isArray: true} query: {method: 'GET', params: {list: true}, isArray: true}
}); });
}]); }]);
overlord_service.factory('CostCenter', ['$resource', function ($resource) { overlordService.factory('CostCenter', ['$resource', function ($resource) {
return $resource('/api/CostCenter/:id', return $resource('/api/CostCenter/:id',
{id: '@CostCenterID'}, { {id: '@CostCenterID'}, {
query: {method: 'GET', params: {list: true}, isArray: true} query: {method: 'GET', params: {list: true}, isArray: true}
}); });
}]); }]);
overlord_service.factory('TrialBalance', ['$resource', function ($resource) { overlordService.factory('TrialBalance', ['$resource', function ($resource) {
return $resource('/api/TrialBalance/:date'); return $resource('/api/TrialBalance/:date');
}]); }]);
overlord_service.factory('ClosingStock', ['$resource', function ($resource) { overlordService.factory('ClosingStock', ['$resource', function ($resource) {
return $resource('/api/ClosingStock/:date'); return $resource('/api/ClosingStock/:date');
}]); }]);
overlord_service.factory('CashFlow', ['$resource', function ($resource) { overlordService.factory('CashFlow', ['$resource', function ($resource) {
return $resource('/api/CashFlow/:id'); return $resource('/api/CashFlow/:id');
}]); }]);
overlord_service.factory('Daybook', ['$resource', function ($resource) { overlordService.factory('Daybook', ['$resource', function ($resource) {
return $resource('/api/Daybook'); return $resource('/api/Daybook');
}]); }]);
overlord_service.factory('Unposted', ['$resource', function ($resource) { overlordService.factory('Unposted', ['$resource', function ($resource) {
return $resource('/api/Unposted'); return $resource('/api/Unposted');
}]); }]);
overlord_service.factory('ProfitLoss', ['$resource', function ($resource) { overlordService.factory('ProfitLoss', ['$resource', function ($resource) {
return $resource('/api/ProfitLoss'); return $resource('/api/ProfitLoss');
}]); }]);
overlord_service.factory('StockMovement', ['$resource', function ($resource) { overlordService.factory('StockMovement', ['$resource', function ($resource) {
return $resource('/api/StockMovement'); return $resource('/api/StockMovement');
}]); }]);
overlord_service.factory('BalanceSheet', ['$resource', function ($resource) { overlordService.factory('BalanceSheet', ['$resource', function ($resource) {
return $resource('/api/BalanceSheet/:date'); return $resource('/api/BalanceSheet/:date');
}]); }]);
overlord_service.factory('NetTransactions', ['$resource', function ($resource) { overlordService.factory('NetTransactions', ['$resource', function ($resource) {
return $resource('/api/NetTransactions'); return $resource('/api/NetTransactions');
}]); }]);
overlord_service.factory('Purchases', ['$resource', function ($resource) { overlordService.factory('Purchases', ['$resource', function ($resource) {
return $resource('/api/Purchases'); return $resource('/api/Purchases');
}]); }]);
overlord_service.factory('PurchaseEntries', ['$resource', function ($resource) { overlordService.factory('PurchaseEntries', ['$resource', function ($resource) {
return $resource('/api/PurchaseEntries'); return $resource('/api/PurchaseEntries');
}]); }]);
overlord_service.factory('RawMaterialCost', ['$resource', function ($resource) { overlordService.factory('RawMaterialCost', ['$resource', function ($resource) {
return $resource('/api/RawMaterialCost/:id'); return $resource('/api/RawMaterialCost/:id');
}]); }]);
overlord_service.factory('Auth', ['$resource', function ($resource) { overlordService.factory('Auth', ['$resource', function ($resource) {
return $resource('/api/Auth', {}, { return $resource('/api/Auth', {}, {
login: {method: 'GET', params: {list: true}, isArray: true} login: {method: 'GET', params: {list: true}, isArray: true}
}); });
}]); }]);
overlord_service.factory('Attendance', ['$resource', function ($resource) { overlordService.factory('Attendance', ['$resource', function ($resource) {
return $resource('/api/Attendance/:date', {date: '@Date'}); return $resource('/api/Attendance/:date', {date: '@Date'});
}]); }]);
overlord_service.factory('AttendanceTypes', ['$resource', function ($resource) { overlordService.factory('AttendanceTypes', ['$resource', function ($resource) {
return $resource('/api/AttendanceTypes'); return $resource('/api/AttendanceTypes');
}]); }]);
overlord_service.factory('EmployeeAttendance', ['$resource', function ($resource) { overlordService.factory('EmployeeAttendance', ['$resource', function ($resource) {
return $resource('/api/EmployeeAttendance/:id', {id: '@Employee.LedgerID'}); return $resource('/api/EmployeeAttendance/:id', {id: '@Employee.LedgerID'});
}]); }]);
overlord_service.factory('Account', ['$resource', function ($resource) { overlordService.factory('Account', ['$resource', function ($resource) {
return $resource('/api/Account/:id', return $resource('/api/Account/:id',
{id: '@LedgerID'}, { {id: '@LedgerID'}, {
query: {method: 'GET', params: {list: true}, isArray: true}, query: {method: 'GET', params: {list: true}, isArray: true},
autocomplete: {method: 'GET', params: {term: ''}, isArray: true} autocomplete: {method: 'GET', params: {term: ''}, isArray: true}
}); });
}]); }]);
overlord_service.factory('Message', ['$resource', function ($resource) { overlordService.factory('Message', ['$resource', function ($resource) {
return $resource('/api/Message/:id', return $resource('/api/Message/:id',
{id: '@ThreadID'}, { {id: '@ThreadID'}, {
query: {method: 'GET', params: {list: true}} query: {method: 'GET', params: {list: true}}
}); });
}]); }]);
overlord_service.factory('Tag', ['$resource', function ($resource) { overlordService.factory('Tag', ['$resource', function ($resource) {
return $resource('/api/Tags'); return $resource('/api/Tags');
}]); }]);
overlord_service.service('EventSource', function () { overlordService.factory('Tokenizer', ['$filter', function ($filter) {
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 parseFilterString = function (q, searchInfo) {
// '[^']+'|"[^"]+"|[^ ]+ == Match a space delimited string or quoted string. ms for short // '[^']+'|"[^"]+"|[^ ]+ == Match a space delimited string or quoted string. ms for short
// ((ms\s*:\s*ms)|ms) == Match string : Match string OR Match string // ((ms\s*:\s*ms)|ms) == Match string : Match string OR Match string
@@ -298,15 +256,19 @@ overlord_service.factory('Tokenizer', ['$filter', function ($filter) {
return a >= b; return a >= b;
}, },
'==': function (a, b) { '==': function (a, b) {
return a == b; return a === b;
}, },
'!=': function (a, b) { '!=': function (a, b) {
return a != b; return a !== b;
} }
}, },
comparators = { comparators = {
'text': function (obj, text) { 'text': function (obj, text) {
return obj.toLowerCase().indexOf(text) > -1; if (text.indexOf('!') === 0) {
return obj.toLowerCase().indexOf(text.substr(1)) <= -1;
} else {
return obj.toLowerCase().indexOf(text) > -1;
}
}, },
'boolean': function (obj, text) { 'boolean': function (obj, text) {
return obj === isTrue(text); return obj === isTrue(text);
@@ -319,7 +281,7 @@ overlord_service.factory('Tokenizer', ['$filter', function ($filter) {
return obj.toString().indexOf(text) > -1; return obj.toString().indexOf(text) > -1;
} }
}, },
'true': function (obj, text) { 'true': function () {
return true; return true;
} }
}; };
@@ -339,8 +301,19 @@ overlord_service.factory('Tokenizer', ['$filter', function ($filter) {
return {'Col': comparator.Col, 'Comparator': comparators[comparator.Comparator], 'Value': value}; return {'Col': comparator.Col, 'Comparator': comparators[comparator.Comparator], 'Value': value};
} }
function toArray(matches) { function opLength(operator) {
return _.reduce(matches, function (accumulator, item) { var i,
ops = ['<=', '<', '>=', '>', '==', '!='];
for (i = 0; i < ops.length; i++) {
if (operator.indexOf(ops[i]) === 0) {
return ops[i].length;
}
}
return 0;
}
_(q.match(re))
.reduce(function (accumulator, item) {
var key, var key,
value; value;
if (item.indexOf(':') === -1) { if (item.indexOf(':') === -1) {
@@ -360,36 +333,22 @@ overlord_service.factory('Tokenizer', ['$filter', function ($filter) {
accumulator.push({Key: key, Value: value}); accumulator.push({Key: key, Value: value});
} }
return accumulator; return accumulator;
}, []); }, [])
} .forEach(function (item) {
var key = item.Key,
value = item.Value;
function opLength(operator) { if (key === '' && value.length > 1 && is(value.charAt(0), '+-') && value.substr(1) in sorter) {
var i, sorting.push(value.charAt(0) + sorter[value.substr(1).toLowerCase()]);
ops = ['<=', '<', '>=', '>', '==', '!=']; } else {
for (i = 0; i < ops.length; i++) { key = key || defaultKey;
if (operator.indexOf(ops[i]) == 0) { if (key in comparator) {
return ops[i].length; matches.push(pushObject(comparator[key], value));
} else if (key in flagger) {
flags[key] = value;
}
} }
} });
return 0;
}
_(q.match(re))
_.forEach(toArray(q.match(re)), function (item) {
var key = item.Key,
value = item.Value;
if (key === '' && value.length > 1 && is(value.charAt(0), '+-') && value.substr(1) in sorter) {
sorting.push(value.charAt(0) + sorter[value.substr(1).toLowerCase()]);
} else {
key = key || defaultKey;
if (key in comparator) {
matches.push(pushObject(comparator[key], value));
} else if (key in flagger) {
flags[key] = value;
}
}
});
return {'q': matches, 'o': sorting, 'f': flags}; return {'q': matches, 'o': sorting, 'f': flags};
}; };
var doFilter = _.memoize(function (q, array, matches) { var doFilter = _.memoize(function (q, array, matches) {
@@ -408,7 +367,7 @@ overlord_service.factory('Tokenizer', ['$filter', function ($filter) {
return {parseFilterString: parseFilterString, doFilter: doFilter}; return {parseFilterString: parseFilterString, doFilter: doFilter};
}]); }]);
overlord_service.factory("ReaderPromise", ["$q", function ($q) { overlordService.factory("ReaderPromise", ["$q", function ($q) {
var onLoad = function (reader, deferred) { var onLoad = function (reader, deferred) {
return function () { return function () {
deferred.resolve(reader.result); deferred.resolve(reader.result);
@@ -442,8 +401,8 @@ overlord_service.factory("ReaderPromise", ["$q", function ($q) {
}; };
var readAsDataURL = function (file, scope) { var readAsDataURL = function (file, scope) {
var deferred = $q.defer(); var deferred = $q.defer(),
var reader = getReader(deferred, scope); reader = getReader(deferred, scope);
reader.readAsDataURL(file); reader.readAsDataURL(file);
return deferred.promise; return deferred.promise;
}; };
@@ -453,8 +412,8 @@ overlord_service.factory("ReaderPromise", ["$q", function ($q) {
}; };
}]); }]);
overlord_service.factory("uploadedImageResizer", ["$q", "ReaderPromise", function ($q, ReaderPromise) { overlordService.factory("uploadedImageResizer", ["$q", "ReaderPromise", function ($q, ReaderPromise) {
function ResizeImage(file, MAX_WIDTH, MAX_HEIGHT) { function resizeImage(file, MAX_WIDTH, MAX_HEIGHT) {
var image = file, var image = file,
canvas = document.createElement('canvas'), canvas = document.createElement('canvas'),
ctx = canvas.getContext("2d"), ctx = canvas.getContext("2d"),
@@ -495,8 +454,8 @@ overlord_service.factory("uploadedImageResizer", ["$q", "ReaderPromise", functio
} }
ReaderPromise.readAsDataURL(uploadedFile.file).then(function (result) { ReaderPromise.readAsDataURL(uploadedFile.file).then(function (result) {
file.Original = result; file.Original = result;
file.Thumbnail = ResizeImage(result, 100, 150); file.Thumbnail = resizeImage(result, 100, 150);
file.Resized = ResizeImage(result, 825, 1170); file.Resized = resizeImage(result, 825, 1170);
}); });
oldFiles.push(file); oldFiles.push(file);
}; };
+2 -2
View File
@@ -9,9 +9,9 @@ var AttendanceCtrl = ['$scope', '$location', 'asDateFilter', 'Attendance', 'atte
}; };
$scope.save = function () { $scope.save = function () {
$scope.info.Date = asDate($scope.info.Date); $scope.info.Date = asDate($scope.info.Date);
return $scope.info.$save(function (u, putResponseHeaders) { return $scope.info.$save(function (u) {
$scope.toasts.push({Type: 'Success', Message: u.Code}); $scope.toasts.push({Type: 'Success', Message: u.Code});
}, function (data, status) { }, function (data) {
$scope.toasts.push({Type: 'Danger', Message: data.data}); $scope.toasts.push({Type: 'Danger', Message: data.data});
}); });
}; };
+4 -4
View File
@@ -14,19 +14,19 @@ var ClientCtrl = ['$scope', '$location', '$modal', 'client', function ($scope, $
$scope.client = client; $scope.client = client;
$scope.save = function () { $scope.save = function () {
$scope.client.$save(function (u, putResponseHeaders) { $scope.client.$save(function () {
$scope.toasts.push({Type: 'Success', Message: ''}); $scope.toasts.push({Type: 'Success', Message: ''});
$location.path('/Clients'); $location.path('/Clients');
}, function (data, status) { }, function (data) {
$scope.toasts.push({Type: 'Danger', Message: data.data}); $scope.toasts.push({Type: 'Danger', Message: data.data});
}); });
}; };
$scope.delete = function () { $scope.delete = function () {
$scope.client.$delete(function (u, putResponseHeaders) { $scope.client.$delete(function () {
$scope.toasts.push({Type: 'Success', Message: ''}); $scope.toasts.push({Type: 'Success', Message: ''});
$location.path('/Clients'); $location.path('/Clients');
}, function (data, status) { }, function (data) {
$scope.toasts.push({Type: 'Danger', Message: data.data}); $scope.toasts.push({Type: 'Danger', Message: data.data});
}); });
}; };
+1 -1
View File
@@ -45,7 +45,7 @@ var EmployeeFunctionsCtrl = ['$scope', '$http', 'asDateFilter', function ($scope
transformRequest: angular.identity transformRequest: angular.identity
}).success(function () { }).success(function () {
$scope.toasts.push({Type: 'Success', Message: 'Data uploaded'}); $scope.toasts.push({Type: 'Success', Message: 'Data uploaded'});
}).error(function (data, status, headers, config) { }).error(function (data) {
$scope.toasts.push({Type: 'Danger', Message: data}); $scope.toasts.push({Type: 'Danger', Message: data});
}); });
}; };
+26 -9
View File
@@ -3,14 +3,6 @@
var EmployeeListCtrl = ['$scope', '$location', '$routeParams', 'Tokenizer', 'employees', function ($scope, $location, $routeParams, Tokenizer, employees) { var EmployeeListCtrl = ['$scope', '$location', '$routeParams', 'Tokenizer', 'employees', function ($scope, $location, $routeParams, Tokenizer, employees) {
$scope.search = $routeParams.q || ''; $scope.search = $routeParams.q || '';
$scope.info = employees; $scope.info = employees;
var re = /((([^ ]+):\s*('[^':]+'|"[^":]+"|[^ ]+))|[^ ]+[^: '"]*)/g;
$scope.isTrue = function (value) {
value = value.toLowerCase();
return !_.any(['f', 'fa', 'fal', 'fals', 'false', 'n', 'no', '0'], function (item) {
return item === value;
});
};
$scope.$watch('search', function (newValue, oldValue) { $scope.$watch('search', function (newValue, oldValue) {
$scope.filterEmployees(newValue); $scope.filterEmployees(newValue);
@@ -54,6 +46,31 @@ var EmployeeListCtrl = ['$scope', '$location', '$routeParams', 'Tokenizer', 'emp
}); });
} }
}, 350); }, 350);
$scope.selected = -1;
$scope.setSelected = function (index) {
$scope.selected = Math.min(Math.max(0, index), $scope.employees.length - 1);
};
$scope.shortcuts = {
'up': function (e) {
if ($scope.selected > 0) {
$scope.$apply(function () {
$scope.selected = Math.min(Math.max(0, $scope.selected - 1), $scope.employees.length - 1);
});
$("#" + $scope.selected).scrollintoview();
e.preventDefault();
}
},
'down': function (e) {
if ($scope.selected < $scope.employees.length - 1) {
$scope.$apply(function () {
$scope.selected = Math.min(Math.max(0, $scope.selected + 1), $scope.employees.length - 1);
});
$("#" + $scope.selected).scrollintoview();
e.preventDefault();
}
}
};
}]; }];
EmployeeListCtrl.resolve = { EmployeeListCtrl.resolve = {
@@ -92,7 +109,7 @@ var EmployeeCtrl = ['$scope', '$routeParams', '$location', 'asDateFilter', '$mod
backdrop: true, backdrop: true,
templateUrl: '/template/modal/confirm.html', templateUrl: '/template/modal/confirm.html',
controller: ['$scope', '$modalInstance', function ($scope, $modalInstance) { controller: ['$scope', '$modalInstance', function ($scope, $modalInstance) {
$scope.title = "Delete Account"; $scope.title = "Delete Employee";
$scope.body = "Are you sure? This cannot be undone."; $scope.body = "Are you sure? This cannot be undone.";
$scope.isDelete = true; $scope.isDelete = true;
$scope.ok = function () { $scope.ok = function () {
+1 -1
View File
@@ -1,6 +1,6 @@
'use strict'; 'use strict';
overlord_service.factory('growl', ['$http', '$compile', '$timeout', function ($http, $compile, $timeout) { overlordService.factory('growl', ['$http', '$compile', '$timeout', function ($http, $compile, $timeout) {
var growl = {}; var growl = {};
growl.default_options = { growl.default_options = {
offset: { offset: {
+1 -1
View File
@@ -65,7 +65,7 @@ var JournalCtrl = ['$scope', '$location', 'asDateFilter', '$modal', 'uploadedIma
if (!angular.isArray(journals)) { if (!angular.isArray(journals)) {
return; return;
} }
var amount = journals.reduce(function (previousValue, currentValue, index, array) { var amount = journals.reduce(function (previousValue, currentValue) {
return previousValue + (currentValue.Amount * currentValue.Debit); return previousValue + (currentValue.Amount * currentValue.Debit);
}, 0); }, 0);
$scope.amount = Math.abs(amount); $scope.amount = Math.abs(amount);
+22 -17
View File
@@ -36,13 +36,13 @@ var LedgerCtrl = ['$scope', '$routeParams', '$location', 'asDateFilter', 'ledger
}; };
$scope.$watch('hidden', function () { $scope.$watch('hidden', function () {
$scope.display = $scope.doFilter($scope.info, $scope.hidden); var filtered = $scope.doFilter($scope.hidden, $scope.info.Body);
$scope.ledger = filtered.Body;
$scope.footer = filtered.Footer;
}, true); }, true);
$scope.doFilter = _.memoize(function (input, hidden) { $scope.doFilter = _.memoize(function (hidden, input) {
var ledger = angular.copy(input), var data = angular.copy(input),
data = ledger.Body,
footer = ledger.Footer,
debit = 0, credit = 0, running = 0; debit = 0, credit = 0, running = 0;
if (hidden.length !== 0) { if (hidden.length !== 0) {
@@ -65,11 +65,15 @@ var LedgerCtrl = ['$scope', '$routeParams', '$location', 'asDateFilter', 'ledger
} }
item.Running = running; item.Running = running;
}); });
footer.Debit = debit; return {
footer.Credit = credit; Body: data,
footer.Running = running; Footer: {
return {Body: data, Footer: footer}; Debit: debit,
}, function (input, hidden) { Credit: credit,
Running: running
}
};
}, function (hidden) {
return hidden.sort().join(' '); return hidden.sort().join(' ');
}); });
@@ -77,26 +81,26 @@ var LedgerCtrl = ['$scope', '$routeParams', '$location', 'asDateFilter', 'ledger
'up': function (e) { 'up': function (e) {
if ($scope.selected > 0) { if ($scope.selected > 0) {
$scope.$apply(function () { $scope.$apply(function () {
$scope.selected = $scope.selected -= 1; $scope.selected = Math.min(Math.max(0, $scope.selected - 1), $scope.ledger.length - 1);
}); });
$("#" + $scope.selected).scrollintoview({duration: 'fast'}); $("#" + $scope.selected).scrollintoview();
e.preventDefault(); e.preventDefault();
} }
}, },
'down': function (e) { 'down': function (e) {
if ($scope.selected < $scope.display.Body.length - 1) { if ($scope.selected < $scope.ledger.length - 1) {
$scope.$apply(function () { $scope.$apply(function () {
$scope.selected = $scope.selected += 1; $scope.selected = Math.min(Math.max(0, $scope.selected + 1), $scope.ledger.length - 1);
}); });
$("#" + $scope.selected).scrollintoview({duration: 'fast'}); $("#" + $scope.selected).scrollintoview();
e.preventDefault(); e.preventDefault();
} }
}, },
'alt+r': function (e) { 'alt+r': function (e) {
if ($scope.selected > -1) { if ($scope.selected > -1) {
$scope.$apply(function () { $scope.$apply(function () {
var max = $scope.display.Body.length; var max = $scope.ledger.length;
$scope.hidden.push($scope.display.Body[$scope.selected].ID); $scope.hidden.push($scope.ledger[$scope.selected].ID);
if ($scope.selected === max - 1) { if ($scope.selected === max - 1) {
$scope.selected = max - 2; $scope.selected = max - 2;
} }
@@ -109,6 +113,7 @@ var LedgerCtrl = ['$scope', '$routeParams', '$location', 'asDateFilter', 'ledger
$scope.$apply(function () { $scope.$apply(function () {
$location.path(path).search('StartDate', null).search('FinishDate', null); $location.path(path).search('StartDate', null).search('FinishDate', null);
}); });
e.preventDefault();
}, },
'alt+u': function (e) { 'alt+u': function (e) {
if ($scope.hidden.length !== 0) { if ($scope.hidden.length !== 0) {
+1 -1
View File
@@ -1,6 +1,6 @@
'use strict'; 'use strict';
overlord_service.factory('mdService', ['$http', '$compile', '$timeout', function ($http, $compile, $timeout) { overlordService.factory('mdService', ['$http', '$compile', '$timeout', function ($http, $compile, $timeout) {
var growl = {}; var growl = {};
growl.default_options = { growl.default_options = {
offset: { offset: {
+3 -3
View File
@@ -1,7 +1,7 @@
'use strict'; 'use strict';
var NetTransactionsCtrl = ['$scope', '$location', 'asDateFilter', 'net_transactions', function ($scope, $location, asDate, net_transactions) { var NetTransactionsCtrl = ['$scope', '$location', 'asDateFilter', 'netTransactions', function ($scope, $location, asDate, netTransactions) {
$scope.info = net_transactions; $scope.info = netTransactions;
$scope.show = function () { $scope.show = function () {
var startDate = asDate($scope.info.StartDate), var startDate = asDate($scope.info.StartDate),
finishDate = asDate($scope.info.FinishDate); finishDate = asDate($scope.info.FinishDate);
@@ -11,7 +11,7 @@ var NetTransactionsCtrl = ['$scope', '$location', 'asDateFilter', 'net_transacti
}]; }];
NetTransactionsCtrl.resolve = { NetTransactionsCtrl.resolve = {
net_transactions: ['$route', 'NetTransactions', function ($route, NetTransactions) { netTransactions: ['$route', 'NetTransactions', function ($route, NetTransactions) {
var startDate = $route.current.params.StartDate, var startDate = $route.current.params.StartDate,
finishDate = $route.current.params.FinishDate; finishDate = $route.current.params.FinishDate;
+3 -3
View File
@@ -1,7 +1,7 @@
'use strict'; 'use strict';
var ProductLedgerCtrl = ['$scope', '$routeParams', '$location', 'asDateFilter', 'product_ledger', 'ProductLedger', 'Product', function ($scope, $routeParams, $location, asDate, product_ledger, ProductLedger, Product) { var ProductLedgerCtrl = ['$scope', '$routeParams', '$location', 'asDateFilter', 'productLedger', 'ProductLedger', 'Product', function ($scope, $routeParams, $location, asDate, productLedger, ProductLedger, Product) {
$scope.info = product_ledger; $scope.info = productLedger;
$scope.show = function () { $scope.show = function () {
var id = $scope.info.Product.ProductID, var id = $scope.info.Product.ProductID,
startDate = asDate($scope.info.StartDate), startDate = asDate($scope.info.StartDate),
@@ -28,7 +28,7 @@ var ProductLedgerCtrl = ['$scope', '$routeParams', '$location', 'asDateFilter',
$('#txtProduct').focus(); $('#txtProduct').focus();
}]; }];
ProductLedgerCtrl.resolve = { ProductLedgerCtrl.resolve = {
product_ledger: ['$route', 'ProductLedger', function ($route, ProductLedger) { productLedger: ['$route', 'ProductLedger', function ($route, ProductLedger) {
var id = $route.current.params.id, var id = $route.current.params.id,
startDate = $route.current.params.StartDate, startDate = $route.current.params.StartDate,
finishDate = $route.current.params.FinishDate; finishDate = $route.current.params.FinishDate;
+31 -7
View File
@@ -5,8 +5,8 @@ var ProductListCtrl = ['$scope', '$location', '$routeParams', 'Tokenizer', 'prod
$scope.showExtended = false; $scope.showExtended = false;
$scope.info = products; $scope.info = products;
$scope.$watch('search', function (newValue, oldValue) { $scope.$watch('search', function (value) {
$scope.filterProducts(newValue); $scope.filterProducts(value);
}, true); }, true);
$scope.$on('$destroy', function () { $scope.$on('$destroy', function () {
@@ -37,7 +37,6 @@ var ProductListCtrl = ['$scope', '$location', '$routeParams', 'Tokenizer', 'prod
'e': 'boolean' 'e': 'boolean'
} }
}; };
$scope.filterProducts = _.debounce(function (q) { $scope.filterProducts = _.debounce(function (q) {
if (q !== $scope._search) { if (q !== $scope._search) {
$scope._search = q; $scope._search = q;
@@ -54,6 +53,31 @@ var ProductListCtrl = ['$scope', '$location', '$routeParams', 'Tokenizer', 'prod
}); });
} }
}, 350); }, 350);
$scope.selected = -1;
$scope.setSelected = function (index) {
$scope.selected = Math.min(Math.max(0, index), $scope.products.length - 1);
};
$scope.shortcuts = {
'up': function (e) {
if ($scope.selected > 0) {
$scope.$apply(function () {
$scope.selected = Math.min(Math.max(0, $scope.selected - 1), $scope.products.length - 1);
});
$("#" + $scope.selected).scrollintoview();
e.preventDefault();
}
},
'down': function (e) {
if ($scope.selected < $scope.products.length - 1) {
$scope.$apply(function () {
$scope.selected = Math.min(Math.max(0, $scope.selected + 1), $scope.products.length - 1);
});
$("#" + $scope.selected).scrollintoview();
e.preventDefault();
}
}
};
}]; }];
ProductListCtrl.resolve = { ProductListCtrl.resolve = {
@@ -67,19 +91,19 @@ var ProductCtrl = ['$scope', '$location', '$window', '$modal', 'product', 'produ
$scope.productGroups = productGroups; $scope.productGroups = productGroups;
$scope.save = function () { $scope.save = function () {
$scope.product.$save(function (u, putResponseHeaders) { $scope.product.$save(function (u) {
$scope.toasts.push({Type: 'Success', Message: u.Code}); $scope.toasts.push({Type: 'Success', Message: u.Code});
$window.history.back(); $window.history.back();
}, function (data, status) { }, function (data) {
$scope.toasts.push({Type: 'Danger', Message: data.data}); $scope.toasts.push({Type: 'Danger', Message: data.data});
}); });
}; };
$scope.delete = function () { $scope.delete = function () {
$scope.product.$delete(function (u, putResponseHeaders) { $scope.product.$delete(function () {
$scope.toasts.push({Type: 'Success', Message: ''}); $scope.toasts.push({Type: 'Success', Message: ''});
$window.history.back(); $window.history.back();
}, function (data, status) { }, function (data) {
$scope.toasts.push({Type: 'Danger', Message: data.data}); $scope.toasts.push({Type: 'Danger', Message: data.data});
}); });
}; };
+13 -11
View File
@@ -62,15 +62,17 @@ var PurchaseReturnCtrl = ['$scope', '$location', 'asDateFilter', '$modal', 'uplo
this.voucher.Inventories.splice(index, 1); this.voucher.Inventories.splice(index, 1);
}; };
$scope.$watch('voucher.Inventories', function (inventories, oldValue) { $scope.$watch('voucher.Inventories', function (inventories) {
var amount = 0; var amount = 0,
i,
l;
if (!angular.isUndefined(inventories)) { if (!angular.isUndefined(inventories)) {
for (var i = 0, l = inventories.length; i < l; i++) { for (i = 0, l = inventories.length; i < l; i++) {
amount += Number(inventories[i].Amount); amount += Number(inventories[i].Amount);
} }
} }
if (!angular.isUndefined($scope.voucher.Journals)) { if (!angular.isUndefined($scope.voucher.Journals)) {
for (var i = 0, l = $scope.voucher.Journals.length; i < l; i++) { for (i = 0, l = $scope.voucher.Journals.length; i < l; i++) {
if ($scope.voucher.Journals[i].Debit === 1) { if ($scope.voucher.Journals[i].Debit === 1) {
$scope.voucher.Journals[i].Amount = amount; $scope.voucher.Journals[i].Amount = amount;
break; break;
@@ -86,7 +88,7 @@ var PurchaseReturnCtrl = ['$scope', '$location', 'asDateFilter', '$modal', 'uplo
return !$scope.perms['Purchase Return']; return !$scope.perms['Purchase Return'];
} else if (voucher.Posted && !$scope.perms['Edit Posted Vouchers']) { } else if (voucher.Posted && !$scope.perms['Edit Posted Vouchers']) {
return true; return true;
} else if (voucher.User.UserID != $scope.auth.UserID && !$scope.perms["Edit Other User's Vouchers"]) { } else if (voucher.User.UserID !== $scope.auth.UserID && !$scope.perms["Edit Other User's Vouchers"]) {
return true; return true;
} else { } else {
return false; return false;
@@ -95,27 +97,27 @@ var PurchaseReturnCtrl = ['$scope', '$location', 'asDateFilter', '$modal', 'uplo
$scope.save = function () { $scope.save = function () {
$scope.voucher.Date = asDate($scope.voucher.Date); $scope.voucher.Date = asDate($scope.voucher.Date);
return $scope.voucher.$save({type: 'Purchase Return'}, function (u, putResponseHeaders) { return $scope.voucher.$save({type: 'Purchase Return'}, function (u) {
$scope.toasts.push({Type: 'Success', Message: ''}); $scope.toasts.push({Type: 'Success', Message: ''});
$location.path('/Return/' + u.VoucherID); $location.path('/Return/' + u.VoucherID);
}, function (data, status) { }, function (data) {
$scope.toasts.push({Type: 'Danger', Message: data.data}); $scope.toasts.push({Type: 'Danger', Message: data.data});
}); });
}; };
$scope.delete = function () { $scope.delete = function () {
$scope.voucher.$delete(function (u, putResponseHeaders) { $scope.voucher.$delete(function () {
$scope.toasts.push({Type: 'Success', Message: ''}); $scope.toasts.push({Type: 'Success', Message: ''});
$location.path('/Return').replace(); $location.path('/Return').replace();
}, function (data, status) { }, function (data) {
$scope.toasts.push({Type: 'Danger', Message: data.data}); $scope.toasts.push({Type: 'Danger', Message: data.data});
}); });
}; };
$scope.post = function () { $scope.post = function () {
return $scope.voucher.$post(function (u, putResponseHeaders) { return $scope.voucher.$post(function () {
$scope.toasts.push({Type: 'Success', Message: ''}); $scope.toasts.push({Type: 'Success', Message: ''});
}, function (data, status) { }, function (data) {
$scope.toasts.push({Type: 'Danger', Message: data.data}); $scope.toasts.push({Type: 'Danger', Message: data.data});
}); });
}; };
+3 -3
View File
@@ -77,12 +77,12 @@ var RecipeCtrl = ['$scope', '$location', '$window', '$modal', 'asDateFilter', 'P
this.recipe.RecipeItems.splice(index, 1); this.recipe.RecipeItems.splice(index, 1);
}; };
$scope.$watch('recipe.RecipeItems', function (recipeItems, oldValue) { $scope.$watch('recipe.RecipeItems', function (recipeItems) {
if (!angular.isArray(recipeItems)) { if (!angular.isArray(recipeItems)) {
return; return;
} }
$scope.costPrice = recipeItems.reduce(function (sum, item, index, array) { $scope.costPrice = recipeItems.reduce(function (sum, item) {
var rate = item.Price / (item.Product.Fraction * item.Product.ProductYield) var rate = item.Price / (item.Product.Fraction * item.Product.ProductYield);
return sum + (item.Quantity * rate); return sum + (item.Quantity * rate);
}, 0); }, 0);
}, true); }, true);
+5 -13
View File
@@ -94,36 +94,28 @@ var SalaryDeductionCtrl = ['$scope', '$location', 'asDateFilter', '$modal', 'vou
return !$scope.perms['Salary Deduction']; return !$scope.perms['Salary Deduction'];
} else if (voucher.Posted && !$scope.perms['Edit Posted Vouchers']) { } else if (voucher.Posted && !$scope.perms['Edit Posted Vouchers']) {
return true; return true;
} else if (voucher.User.UserID != $scope.auth.UserID && !$scope.perms["Edit Other User's Vouchers"]) { } else if (voucher.User.UserID !== $scope.auth.UserID && !$scope.perms["Edit Other User's Vouchers"]) {
return true; return true;
} else { } else {
return false; return false;
} }
}; };
$scope.get = function (voucherid) {
$scope.voucher = Voucher.get({VoucherID: voucherid}, function (u, putResponseHeaders) {
$scope.toasts.push({Type: 'Success', Message: ''});
}, function (data, status) {
$scope.toasts.push({Type: 'Danger', Message: data.data});
});
};
$scope.save = function () { $scope.save = function () {
$scope.voucher.Date = asDate($scope.voucher.Date); $scope.voucher.Date = asDate($scope.voucher.Date);
$scope.voucher.$save({type: 'Salary Deduction'}, function (u, putResponseHeaders) { $scope.voucher.$save({type: 'Salary Deduction'}, function (u) {
$scope.toasts.push({Type: 'Success', Message: ''}); $scope.toasts.push({Type: 'Success', Message: ''});
$location.path('/SalaryDeduction/' + u.VoucherID); $location.path('/SalaryDeduction/' + u.VoucherID);
}, function (data, status) { }, function (data) {
$scope.toasts.push({Type: 'Danger', Message: data.data}); $scope.toasts.push({Type: 'Danger', Message: data.data});
}); });
}; };
$scope.delete = function () { $scope.delete = function () {
$scope.voucher.$delete(function (u, putResponseHeaders) { $scope.voucher.$delete(function () {
$scope.toasts.push({Type: 'Success', Message: ''}); $scope.toasts.push({Type: 'Success', Message: ''});
$location.path('/SalaryDeduction').replace(); $location.path('/SalaryDeduction').replace();
}, function (data, status) { }, function (data) {
$scope.toasts.push({Type: 'Danger', Message: data.data}); $scope.toasts.push({Type: 'Danger', Message: data.data});
}); });
}; };
+3 -3
View File
@@ -66,7 +66,7 @@ var SettingsCtrl = ['$scope', '$http', 'asDateFilter', '$modal', 'lockInfo', 'Pr
} }
$scope.rebaseDate = asDate($scope.rebaseDate); $scope.rebaseDate = asDate($scope.rebaseDate);
$http({method: 'POST', url: '/api/Rebase/' + $scope.rebaseDate}). $http({method: 'POST', url: '/api/Rebase/' + $scope.rebaseDate}).
success(function (data) { success(function () {
$scope.toasts.push({Type: 'Success', Message: 'Data rebased!'}); $scope.toasts.push({Type: 'Success', Message: 'Data rebased!'});
}). }).
error(function (errorMessage) { error(function (errorMessage) {
@@ -111,7 +111,7 @@ var SettingsCtrl = ['$scope', '$http', 'asDateFilter', '$modal', 'lockInfo', 'Pr
var stockDate = asDate($scope.stockDate); var stockDate = asDate($scope.stockDate);
var qty = Number($scope.qty); var qty = Number($scope.qty);
$http({method: 'POST', url: '/api/ResetStock/' + $scope.product.ProductID, params: {StockDate: stockDate, ResetDate: resetDate, Quantity: qty}}). $http({method: 'POST', url: '/api/ResetStock/' + $scope.product.ProductID, params: {StockDate: stockDate, ResetDate: resetDate, Quantity: qty}}).
success(function (data) { success(function () {
$scope.toasts.push({Type: 'Success', Message: 'Data rebased!'}); $scope.toasts.push({Type: 'Success', Message: 'Data rebased!'});
}). }).
error(function (errorMessage) { error(function (errorMessage) {
@@ -125,7 +125,7 @@ var SettingsCtrl = ['$scope', '$http', 'asDateFilter', '$modal', 'lockInfo', 'Pr
SettingsCtrl.resolve = { SettingsCtrl.resolve = {
lockInfo: ['$http', function ($http) { lockInfo: ['$http', function ($http) {
return $http.get('/api/LockInfo', {}).then(function (data, status, headers, config) { return $http.get('/api/LockInfo', {}).then(function (data) {
return data; return data;
}); });
}] }]
+4 -4
View File
@@ -14,19 +14,19 @@ var UserCtrl = ['$scope', '$location', 'user', function ($scope, $location, user
$scope.user = user; $scope.user = user;
$scope.save = function () { $scope.save = function () {
$scope.user.$save(function (u, putResponseHeaders) { $scope.user.$save(function () {
$scope.toasts.push({Type: 'Success', Message: ''}); $scope.toasts.push({Type: 'Success', Message: ''});
$location.path('/Users'); $location.path('/Users');
}, function (data, status) { }, function (data) {
$scope.toasts.push({Type: 'Danger', Message: data.data}); $scope.toasts.push({Type: 'Danger', Message: data.data});
}); });
}; };
$scope.delete = function () { $scope.delete = function () {
$scope.user.$delete(function (u, putResponseHeaders) { $scope.user.$delete(function () {
$scope.toasts.push({Type: 'Success', Message: ''}); $scope.toasts.push({Type: 'Success', Message: ''});
$location.path('/Users'); $location.path('/Users');
}, function (data, status) { }, function (data) {
$scope.toasts.push({Type: 'Danger', Message: data.data}); $scope.toasts.push({Type: 'Danger', Message: data.data});
}); });
}; };
+57 -13
View File
@@ -1,15 +1,19 @@
import datetime import datetime
from decimal import Decimal from decimal import Decimal
import uuid import uuid
from pyramid.security import authenticated_userid from pyramid.security import authenticated_userid
from pyramid.view import view_config from pyramid.view import view_config
from sqlalchemy import func, and_ from sqlalchemy import func, and_, distinct
from sqlalchemy.orm import aliased from sqlalchemy.orm import aliased
import transaction import transaction
from brewman.models import DBSession from brewman.models import DBSession
from brewman.models.master import LedgerBase, CostCenter, Product, LedgerType from brewman.models.master import LedgerBase, CostCenter, Ledger, Employee
from brewman.models.validation_exception import TryCatchFunction from brewman.models.validation_exception import TryCatchFunction
from brewman.models.voucher import Journal, Voucher, VoucherType, Batch, Inventory, SalaryDeduction, Fingerprint, Attendance from brewman.models.voucher import Journal, Voucher, VoucherType, Batch, Inventory, SalaryDeduction, Fingerprint, \
Attendance, DbImage
__author__ = 'tanshu' __author__ = 'tanshu'
@@ -20,9 +24,9 @@ def rebase(request):
date = request.matchdict.get('date', None) date = request.matchdict.get('date', None)
date = datetime.datetime.strptime(date, '%d-%b-%Y') date = datetime.datetime.strptime(date, '%d-%b-%Y')
user_id = uuid.UUID(authenticated_userid(request)) user_id = uuid.UUID(authenticated_userid(request))
voucher_l = opening_ledgers(date, user_id) voucher_l, accounts = opening_ledgers(date, user_id)
voucher_b, batches = opening_batches(date, user_id) voucher_b, batches = opening_batches(date, user_id)
delete_data(date, batches) delete_data(date)
DBSession.add(voucher_l) DBSession.add(voucher_l)
for j in voucher_l.journals: for j in voucher_l.journals:
DBSession.add(j) DBSession.add(j)
@@ -31,13 +35,14 @@ def rebase(request):
DBSession.add(j) DBSession.add(j)
for i in voucher_b.inventories: for i in voucher_b.inventories:
DBSession.add(i) DBSession.add(i)
cleanup_lint(date, accounts, batches)
transaction.commit() transaction.commit()
return {} return {}
def opening_ledgers(date, user_id): def opening_ledgers(date, user_id):
running_total = 0 running_total = 0
accounts = []
sum_func = func.sum(Journal.signed_amount) sum_func = func.sum(Journal.signed_amount)
query = DBSession.query(LedgerBase, sum_func) \ query = DBSession.query(LedgerBase, sum_func) \
.join(Journal, Voucher.journals).join(LedgerBase, Journal.ledger) \ .join(Journal, Voucher.journals).join(LedgerBase, Journal.ledger) \
@@ -50,18 +55,17 @@ def opening_ledgers(date, user_id):
type=VoucherType.by_name('Opening Ledgers')) type=VoucherType.by_name('Opening Ledgers'))
for ledger, amount in query: for ledger, amount in query:
amount = round(Decimal(amount), 2) amount = round(Decimal(amount), 2)
if not ledger.type_object().balance_sheet: if ledger.type_object.balance_sheet and ledger.id != LedgerBase.suspense() and amount != 0:
pass
if amount != 0:
running_total += amount running_total += amount
journal = Journal(amount=abs(amount), debit=-1 if amount < 0 else 1, ledger_id=ledger.id, journal = Journal(amount=abs(amount), debit=-1 if amount < 0 else 1, ledger_id=ledger.id,
cost_center_id=ledger.costcenter_id) cost_center_id=ledger.costcenter_id)
voucher.journals.append(journal) voucher.journals.append(journal)
accounts.append(ledger.id)
if running_total != 0: if running_total != 0:
journal = Journal(amount=abs(amount), debit=-1 if amount * -1 < 0 else 1, ledger_id=LedgerBase.suspense(), journal = Journal(amount=abs(amount), debit=-1 if amount * -1 < 0 else 1, ledger_id=LedgerBase.suspense(),
cost_center_id=CostCenter.cost_center_overall()) cost_center_id=CostCenter.cost_center_overall())
voucher.journals.append(journal) voucher.journals.append(journal)
return voucher return voucher, accounts
def opening_batches(date, user_id): def opening_batches(date, user_id):
@@ -93,16 +97,56 @@ def opening_batches(date, user_id):
return voucher, batches return voucher, batches
def delete_data(date, batches): def delete_data(date):
sub_voucher = aliased(Voucher) sub_voucher = aliased(Voucher)
sub_query = DBSession.query(sub_voucher.id).filter(sub_voucher.date < date).subquery() sub_query = DBSession.query(sub_voucher.id).filter(sub_voucher.date < date).subquery()
Inventory.__table__.delete(Inventory.voucher_id.in_(sub_query)).execute() Inventory.__table__.delete(Inventory.voucher_id.in_(sub_query)).execute()
SalaryDeduction.__table__.delete(SalaryDeduction.voucher_id.in_(sub_query)).execute() SalaryDeduction.__table__.delete(SalaryDeduction.voucher_id.in_(sub_query)).execute()
Journal.__table__.delete(Journal.voucher_id.in_(sub_query)).execute() Journal.__table__.delete(Journal.voucher_id.in_(sub_query)).execute()
DbImage.__table__.delete(and_(DbImage.resource_type == 'voucher', DbImage.resource_id.in_(sub_query))).execute()
Voucher.__table__.delete(Voucher.date < date).execute() Voucher.__table__.delete(Voucher.date < date).execute()
Batch.__table__.delete(and_(~Batch.inventories.any(), ~Batch.id.in_(batches))).execute()
def cleanup_lint(date, accounts, batches):
# Insert executes on the end so keep list of batches and journals
Batch.__table__.delete(
and_(
~Batch.id.in_(DBSession.query(distinct(Inventory.batch_id)).subquery()),
~Batch.id.in_(batches)
)
).execute()
Fingerprint.__table__.delete(Fingerprint.date < date).execute() Fingerprint.__table__.delete(Fingerprint.date < date).execute()
Attendance.__table__.delete(Attendance.date < date).execute() Attendance.__table__.delete(Attendance.date < date).execute()
Employee.__table__.delete(
and_(
~Employee.id.in_(DBSession.query(distinct(Journal.ledger_id)).subquery()),
~Employee.id.in_(accounts),
Employee.id.in_(
DBSession.query(LedgerBase.id).filter(
LedgerBase.is_fixture == False
).filter(
LedgerBase.is_active == False
).subquery()),
Employee.leaving_date < date
)
).execute()
LedgerBase.__table__.delete(
and_(
~LedgerBase.id.in_(DBSession.query(Employee.id).subquery()),
LedgerBase.ledger_type == Employee.__mapper_args__['polymorphic_identity']
)
).execute()
Ledger.__table__.delete(
and_(
~Ledger.id.in_(DBSession.query(distinct(Journal.ledger_id)).subquery()),
~Ledger.id.in_(accounts),
Ledger.is_fixture == False,
Ledger.ledger_type == Ledger.__mapper_args__['polymorphic_identity']
)
).execute()
+3 -7
View File
@@ -26,7 +26,7 @@ def html(request):
@view_config(request_method='GET', route_name='api_ledger', renderer='json', permission='Ledger') @view_config(request_method='GET', route_name='api_ledger', renderer='json', permission='Ledger')
def show_blank(request): def show_blank(request):
return {'StartDate': session_period_start(request), return {'StartDate': session_period_start(request),
'FinishDate': session_period_finish(request), 'Ledger': None, 'Body': [], 'Footer': {}} 'FinishDate': session_period_finish(request), 'Ledger': None, 'Body': []}
@view_config(request_method='GET', route_name='api_ledger_id', renderer='json', permission='Ledger') @view_config(request_method='GET', route_name='api_ledger_id', renderer='json', permission='Ledger')
@@ -38,7 +38,7 @@ def show_data(request):
finish_date = request.GET.get('FinishDate', session_period_finish(request)) finish_date = request.GET.get('FinishDate', session_period_finish(request))
info = {'StartDate': start_date, 'FinishDate': finish_date, info = {'StartDate': start_date, 'FinishDate': finish_date,
'Ledger': {'LedgerID': ledger.id, 'Name': ledger.name}, 'Ledger': {'LedgerID': ledger.id, 'Name': ledger.name},
'Body': [], 'Footer': {}} 'Body': []}
build_report(request, info) build_report(request, info)
return info return info
@@ -80,8 +80,6 @@ def build_report(request, info):
'Url': get_edit_url(request, voucher), 'Type': VoucherType.by_id(voucher.type).name, 'Url': get_edit_url(request, voucher), 'Type': VoucherType.by_id(voucher.type).name,
'Narration': voucher.narration, 'Debit': debit, 'Credit': credit, 'Posted': voucher.posted}) 'Narration': voucher.narration, 'Debit': debit, 'Credit': credit, 'Posted': voucher.posted})
info['Footer'] = {'Date': finish_date}
def opening_balance(ledger_id, start_date): def opening_balance(ledger_id, start_date):
opening = DBSession.query(func.sum(Journal.amount * Journal.debit)) \ opening = DBSession.query(func.sum(Journal.amount * Journal.debit)) \
@@ -98,6 +96,4 @@ def opening_balance(ledger_id, start_date):
debit = opening debit = opening
credit = 0 credit = 0
return {'Date': start_date, 'ID': 'OB', 'Name': 'Opening Balance', 'Type': 'Opening Balance', return {'Date': start_date, 'ID': 'OB', 'Name': 'Opening Balance', 'Type': 'Opening Balance',
'Narration': '', 'Debit': debit, 'Credit': credit, 'Posted': True} 'Narration': '', 'Debit': debit, 'Credit': credit, 'Posted': True}