Daybook done.

Unposted Entries done.
This commit is contained in:
Tanshu 2012-10-17 01:32:01 +05:30
parent d221a4f4e9
commit 83a87c799d
14 changed files with 181 additions and 238 deletions

View File

@ -94,9 +94,6 @@ def main(global_config, **settings):
config.add_route('issue', '/Issue')
config.add_route('issues_grid', '/Issues/Services/{date}')
config.add_route('day_book', '/Reports/DayBook')
config.add_route('unposted', '/Reports/Unposted')
config.add_route('ledger_id', '/Ledger/{id}')
config.add_route('ledger', '/Ledger')
@ -109,6 +106,9 @@ def main(global_config, **settings):
config.add_route('cash_flow_id', '/CashFlow/{id}')
config.add_route('cash_flow', '/CashFlow')
config.add_route('daybook', '/Daybook')
config.add_route('unposted', '/Unposted')
config.add_route('profit_loss', '/Reports/ProfitLoss')
config.add_route('group_roles_id', '/Admin/GroupRoles/{id}')

View File

@ -0,0 +1,42 @@
<form method="post" autocomplete="off" class="horizontal-form" ng-controller="DaybookCtrl">
<legend>Daybook</legend>
<div class="control-group">
<label for="txtStartDate" class="control-label">Date</label>
<div class="controls">
<datepicker id="txtStartDate" model="info" prop="StartDate" ng-model="info.StartDate"></datepicker>
<datepicker id="txtFinishDate" model="info" prop="FinishDate" ng-model="info.FinishDate"></datepicker>
<button ng-click="show()">Show</button>
</div>
</div>
<div class="control-group">
<label for="gvGrid" class="control-label"></label>
<div class="controls">
<table id="gvGrid" class="clean-table">
<thead>
<tr>
<th>Date</th>
<th>Type</th>
<th>Narration</th>
<th>Debit</th>
<th class="right">Amount</th>
<th>Credit</th>
<th class="right">Amount</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in info.Body" ng-class="{true:'', false:'unposted'}[item.Posted]">
<td><a href="{{item.Url}}">{{item.Date}}</a></td>
<td>{{item.Type}}</td>
<td>{{item.Narration}}</td>
<td class="right">{{item.DebitN}}</td>
<td class="right">{{item.DebitA}}</td>
<td class="right">{{item.CreditN}}</td>
<td class="right">{{item.CreditA}}</td>
</tr>
</tbody>
</table>
</div>
</div>
</form>

View File

@ -0,0 +1,35 @@
<form method="post" autocomplete="off" class="horizontal-form" ng-controller="UnpostedCtrl">
<legend>Unposted Entries</legend>
<div class="control-group">
<label for="gvGrid" class="control-label"></label>
<div class="controls">
<table id="gvGrid" class="clean-table">
<thead>
<tr>
<th>Select</th>
<th>Date</th>
<th>Type</th>
<th>Narration</th>
<th>Debit</th>
<th class="right">Amount</th>
<th>Credit</th>
<th class="right">Amount</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in info">
<td></td>
<td><a href="{{item.Url}}">{{item.Date}}</a></td>
<td>{{item.Type}}</td>
<td>{{item.Narration}}</td>
<td class="right">{{item.DebitN}}</td>
<td class="right">{{item.DebitA}}</td>
<td class="right">{{item.CreditN}}</td>
<td class="right">{{item.CreditA}}</td>
</tr>
</tbody>
</table>
</div>
</div>
</form>

View File

@ -92,6 +92,16 @@ overlord_service.factory('CashFlow', ['$resource', function ($resource) {
return $resource('/CashFlow/:id');
}]);
// TODO: Replace hardcoded url with route_url
overlord_service.factory('Daybook', ['$resource', function ($resource) {
return $resource('/Daybook');
}]);
// TODO: Replace hardcoded url with route_url
overlord_service.factory('Unposted', ['$resource', function ($resource) {
return $resource('/Unposted');
}]);
// TODO: Replace hardcoded url with route_url
overlord_service.factory('LedgerService', ['$resource', function ($resource) {
return $resource('/Services/Accounts/:type');

View File

@ -1,27 +1,15 @@
function Populate(response) {
if (response != null) {
var stateObj = { 'StartDate': response.start_date, 'FinishDate': response.finish_date };
history.pushState(stateObj, 'Display', response.url);
var $table = $('#tbodyMain')
$table.html(response.body);
function DaybookCtrl($scope, $routeParams, $location, Daybook) {
if (typeof $routeParams.StartDate === 'undefined') {
$scope.info = Daybook.get({});
} else if (typeof $routeParams.id === 'undefined') {
$scope.info = Daybook.get({StartDate:$routeParams.StartDate, FinishDate:$routeParams.FinishDate});
}
$scope.show = function () {
$scope.info = Daybook.get({StartDate:$scope.info.StartDate, FinishDate:$scope.info.FinishDate}, function (u, putResponseHeaders) {
$location.path('/Daybook').search({StartDate:u.StartDate, FinishDate:u.FinishDate});
}, function (data, status) {
$scope.toasts.push({Type:'Error', Message:data.data});
});
};
$('#txtStartDate').focus();
}
function Show(startDate, finishDate) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: show_url,
data: JSON.stringify({ startDate: startDate, finishDate: finishDate }),
dataType: "json",
success: function(response) {
Populate(response);
},
error: function(jqXHR, textStatus) {
$("#ctl00_statusDiv").removeClass().addClass("error");
var msg = $.parseJSON(jqXHR.responseText).Message;
$("#ctl00_statusDiv").html(msg);
}
});
return false;
}

View File

@ -32,6 +32,9 @@ var overlord = angular.module('overlord', ['overlord.directive', 'overlord.filte
// when('/Ledger', {templateUrl:'/partial/ledger.html', controller:LedgerCtrl, resolve: LedgerCtrl.resolve}).
// when('/Ledger/:id', {templateUrl:'/partial/ledger.html', controller:LedgerCtrl, resolve: LedgerCtrl.resolve}).
when('/Daybook', {templateUrl:'/partial/daybook.html', controller:DaybookCtrl}).
when('/Unposted', {templateUrl:'/partial/unposted.html', controller:UnpostedCtrl}).
when('/TrialBalance', {templateUrl:'/partial/trial-balance.html', controller:TrialBalanceCtrl}).
when('/TrialBalance/:date', {templateUrl:'/partial/trial-balance.html', controller:TrialBalanceCtrl}).

View File

@ -0,0 +1,3 @@
function UnpostedCtrl($scope, Unposted) {
$scope.info = Unposted.query();
}

View File

@ -42,6 +42,8 @@
${h.ScriptLink(request, 'product-ledger.js')}
${h.ScriptLink(request, 'trial-balance.js')}
${h.ScriptLink(request, 'cash-flow.js')}
${h.ScriptLink(request, 'daybook.js')}
${h.ScriptLink(request, 'unposted.js')}
${h.ScriptLink(request, 'account.js')}
${h.ScriptLink(request, 'user.js')}

View File

@ -5,7 +5,7 @@
<li><a href="${request.route_url('product_ledger')}">Product Ledger</a></li>
## <li><a href="/AccountsTesting/Reports/RawMaterialCost.aspx">Raw Material Cost</a></li>
<li><a href="${request.route_url('cash_flow')}">Cash Flow</a></li>
<li><a href="${request.route_url('day_book')}">Day Book</a></li>
<li><a href="${request.route_url('daybook')}">Day Book</a></li>
<li><a href="">Purchases</a>
<ul>
<li><a href="/AccountsTesting/Reports/PurchaseEntry.aspx">Purchase Entry</a></li>

View File

@ -1,69 +0,0 @@
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal"
metal:use-macro="base">
<tal:block metal:fill-slot="content">
${h.JsLink(request, 'daybook.js')}
<script type="text/javascript">
$(document).ready(function() {
AutoComplete('#txtLedger', '${request.route_url('services_account_list')}');
$('#txtStartDate').datepicker({ dateFormat: 'dd-M-yy' });
${startDate}
$('#txtFinishDate').datepicker({ dateFormat: 'dd-M-yy'});
${finishDate}
show_url = '${request.route_url('day_book')}';
$("#btnSubmit").click(function() { return Show($('#txtStartDate').val(), $('#txtFinishDate').val()); });
window.onpopstate = function(event) {
var state = event.state;
if (state != null) {
$('#txtStartDate').val(state.StartDate);
$('#txtFinishDate').val(state.FinishDate);
Show(state.StartDate, state.FinishDate);
}
};
});
</script>
<article tal:attributes="class pagecontentclass">
<section>
<h2 class="ribbon-header">Display Ledger</h2>
<form method="post" autocomplete="off">
${h.CsrfToken(request.session)}
<p>
${h.Label('Start Date:', 'txtStartDate')}
${h.TextInput('txtStartDate', css_class = 'non-search-box', autocomplete='off')}
</p>
<p>
${h.Label('Finish Date:', 'txtFinishDate')}
${h.TextInput('txtFinishDate', css_class = 'non-search-box', autocomplete='off')}
</p>
<p>
${h.SubmitButton('btnSubmit', 'Submit')}
</p>
<p>
<table id="gvGrid" class="clean-table">
<thead>
<tr>
<th class="Date">Date</th>
<th class="VoucherType">Type</th>
<th class="NameDebit">Debit</th>
<th class="Debit right">Amount</th>
<th class="NameCredit">Credit</th>
<th class="Credit right">Amount</th>
<th class="Narration">Narration</th>
</tr>
</thead>
<tbody id="tbodyMain">
${body}
</tbody>
<tfoot id="tfootMain">
</tfoot>
</table>
</p>
${h.EndForm()}
</section>
</article>
</tal:block>
</html>

View File

@ -1,40 +0,0 @@
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal"
metal:use-macro="base">
<tal:block metal:fill-slot="content">
<script type="text/javascript">
$(document).ready(function() {
$(document).ready(function() {
$('#gvGrid').dataTable({
"bInfo": false,
"bPaginate": false
});
} );
});
</script>
<article tal:attributes="class pagecontentclass">
<section>
<h2 class="ribbon-header">Unposted Entries</h2>
<table id="gvGrid" class="clean-table">
<thead>
<tr>
<th class="Date">Date</th>
<th class="VoucherType">Type</th>
<th class="NameDebit">Debit</th>
<th class="Debit right">Amount</th>
<th class="NameCredit">Credit</th>
<th class="Credit right">Amount</th>
<th class="Narration">Narration</th>
</tr>
</thead>
<tbody id="tbodyMain">
${body}
</tbody>
<tfoot id="tfootMain">
</tfoot>
</table>
</section>
</article>
</tal:block>
</html>

View File

@ -1,81 +0,0 @@
import datetime
from sqlalchemy.orm import joinedload_all
from pyramid.view import view_config
from brewman.helpers import Literal
from brewman.models.voucher import Voucher, Journal, VoucherType
@view_config(request_method='GET', route_name='day_book', permission='DayBook', renderer='brewman:templates/reports/day_book.pt')
def day_book_get(request):
startDate = request.GET.get('startDate', None)
finishDate = request.GET.get('finishDate', None)
should_build_report = False if startDate is None else True
if not should_build_report:
body = ""
else:
report = build_report(request, startDate, finishDate)
body = Literal(report['body'])
if startDate == None:
startDate = Literal(
"StartDate('#txtStartDate', '{0}');".format(request.route_url('services_session_period_start')))
finishDate = Literal(
"FinishDate('#txtFinishDate', '{0}');".format(request.route_url('services_session_period_finish')))
else:
startDate = Literal("$('#txtStartDate').val('{0}');".format(startDate))
finishDate = Literal("$('#txtFinishDate').val('{0}');".format(finishDate))
return {'title': 'Day Book - Hops n Grains',
'pageclass': "page-blogpost page-sidebar-right",
'pagecontentclass': "page-content grid_12",
'page_header': '',
'body': body,
'startDate': startDate,
'finishDate': finishDate}
@view_config(request_method='POST', route_name='day_book', permission='DayBook', renderer='json', xhr=True)
def day_book_post(request):
startDate = request.json_body['startDate']
finishDate = request.json_body['finishDate']
return build_report(request, startDate, finishDate)
def build_report(request, startDate, finishDate):
editUrl = ''
body = ''
query = Voucher.query().options(joinedload_all(Voucher.journals, Journal.ledger, innerjoin=True))\
.filter(Voucher.date >= datetime.datetime.strptime(startDate, '%d-%b-%Y'))\
.filter(Voucher.date <= datetime.datetime.strptime(finishDate, '%d-%b-%Y'))\
.filter(Voucher.type != VoucherType.by_name('Issue').id)\
.order_by(Voucher.date).order_by(Voucher.last_edit_date).all()
for voucher in query:
debit = 0
credit = 0
nameDebit = ""
nameCredit = ""
for journal in voucher.journals:
if journal.debit == 1:
debit += journal.amount
nameDebit += "{0} / ".format(journal.ledger.name)
else:
credit += journal.amount
nameCredit += "{0} / ".format(journal.ledger.name)
nameDebit = nameDebit[:-3]
nameCredit = nameCredit[:-3]
nameDebit = '<a href="' + get_edit_url(request, voucher) + '">' + nameDebit + '</a>'
nameCredit = '<a href="' + get_edit_url(request, voucher) + '">' + nameCredit + '</a>'
body += '<tr class="Voucher{0}" id="{1}"><td class="Date">{2}</td><td class="VoucherType">{3}</td>' \
'<td class="NameDebit">{4}</td><td class="Debit right">\u20B9 {5:.2f}</td><td class="NameCredit">{6}' \
'</td><td class="Credit right">\u20B9 {7:.2f}</td><td class="Narration">{8}</td></tr>'.format(
('' if voucher.posted else ' unposted'), str(voucher.id),
voucher.date.strftime('%d-%b-%Y'), VoucherType.by_id(voucher.type).name, nameDebit, debit,
nameCredit, credit, voucher.narration)
return {'body': body, 'start_date': startDate, 'finish_date': finishDate,
'url': request.route_url('day_book', _query={'startDate': startDate, 'finishDate': finishDate})}

View File

@ -0,0 +1,56 @@
import datetime
from sqlalchemy.orm import joinedload_all
from pyramid.view import view_config
from brewman.models.voucher import Voucher, Journal, VoucherType
from brewman.views.services.session import services_session_period_finish, services_session_period_start
from brewman.views.transactions import get_edit_url
@view_config(request_method='GET', route_name='daybook', renderer='brewman:templates/angular_base.mako',
xhr=False)
def daybook_get(request):
return {}
@view_config(request_method='GET', route_name='daybook', renderer='json', xhr=True)
def daybook_report(request):
start_date = request.GET.get('StartDate', None)
finish_date = request.GET.get('FinishDate', None)
if start_date and finish_date:
return build_report(request, start_date, finish_date)
else:
return {'StartDate': services_session_period_start(request),
'FinishDate': services_session_period_finish(request), 'Body': []}
def build_report(request, start_date, finish_date):
report = {'StartDate': start_date, 'FinishDate': finish_date, 'Body': []}
query = Voucher.query().options(joinedload_all(Voucher.journals, Journal.ledger, innerjoin=True))\
.filter(Voucher.date >= datetime.datetime.strptime(start_date, '%d-%b-%Y'))\
.filter(Voucher.date <= datetime.datetime.strptime(finish_date, '%d-%b-%Y'))\
.filter(Voucher.type != VoucherType.by_name('Issue').id)\
.order_by(Voucher.date).order_by(Voucher.last_edit_date).all()
for voucher in query:
debit = 0
credit = 0
nameDebit = ""
nameCredit = ""
for journal in voucher.journals:
if journal.debit == 1:
debit += journal.amount
nameDebit += "{0} / ".format(journal.ledger.name)
else:
credit += journal.amount
nameCredit += "{0} / ".format(journal.ledger.name)
nameDebit = nameDebit[:-3]
nameCredit = nameCredit[:-3]
report['Body'].append({'Date': voucher.date.strftime('%d-%b-%Y'), 'Url': get_edit_url(request, voucher),
'Type': VoucherType.by_id(voucher.type).name,
'Narration': voucher.narration, 'Posted': voucher.posted,
'DebitN': nameDebit, 'DebitA': "\u20B9\u00A0{0:.2f}".format(debit),
'CreditN': nameCredit,'CreditA': "\u20B9\u00A0{0:.2f}".format(credit)})
return report

View File

@ -1,26 +1,22 @@
import datetime
from sqlalchemy.orm import joinedload_all
from pyramid.view import view_config
from brewman.helpers import Literal
from brewman.models.voucher import Voucher, Journal, VoucherType
from brewman.views.transactions import get_edit_url
@view_config(request_method='GET', route_name='unposted', renderer='brewman:templates/reports/unposted.pt')
def unposted(request):
body = Literal(build_report(request))
@view_config(request_method='GET', route_name='unposted', renderer='brewman:templates/angular_base.mako',
xhr=False)
def unposted_get(request):
return {}
return {'title': 'Day Book - Hops n Grains',
'pageclass': "page-blogpost page-sidebar-right",
'pagecontentclass': "page-content grid_12",
'page_header': '',
'body': body}
@view_config(request_method='GET', route_name='unposted', renderer='json', xhr=True)
def unposted_report(request):
return build_report(request)
def build_report(request):
editUrl = ''
body = ''
body = []
query = Voucher.query().options(joinedload_all(Voucher.journals, Journal.ledger, innerjoin=True))\
.filter(Voucher.posted == False)\
@ -42,12 +38,10 @@ def build_report(request):
nameDebit = nameDebit[:-3]
nameCredit = nameCredit[:-3]
nameDebit = '<a href="' + get_edit_url(request, voucher) + '">' + nameDebit + '</a>'
nameCredit = '<a href="' + get_edit_url(request, voucher) + '">' + nameCredit + '</a>'
body.append({'Date': voucher.date.strftime('%d-%b-%Y'), 'Url': get_edit_url(request, voucher),
'Type': VoucherType.by_id(voucher.type).name,
'Narration': voucher.narration, 'Posted': voucher.posted,
'DebitN': nameDebit, 'DebitA': "\u20B9 {0:.2f}".format(debit),
'CreditN': nameCredit,'CreditA': "\u20B9 {0:.2f}".format(credit)})
body += '<tr class="Voucher" id="{0}"><td class="Date">{1}</td><td class="VoucherType">{2}</td>'\
'<td class="NameDebit">{3}</td><td class="Debit right">\u20B9 {4:.2f}</td><td class="NameCredit">{5}'\
'</td><td class="Credit right">\u20B9 {6:.2f}</td><td class="Narration">{7}</td></tr>'.format(
str(voucher.id), voucher.date.strftime('%d-%b-%Y'), VoucherType.by_id(voucher.type).name, nameDebit, debit,
nameCredit, credit, voucher.narration)
return body