Minor budget edit/view cosmetic improvements

This commit is contained in:
Yingtong Li 2019-06-19 17:03:52 +10:00
parent ff29819ca1
commit 2ca59c0684
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
3 changed files with 36 additions and 35 deletions

View File

@ -32,7 +32,7 @@
<label class="three wide column">Name</label>
<input class="eleven wide column" type="text" name="name" value="{{ revision.name }}">
</div>
<div class="ui inline grid field">
<div class="ui required inline grid field">
<label class="three wide column">Due date</label>
<div class="eleven wide column">
<div class="ui calendar" id="cal_date">
@ -139,11 +139,11 @@
},
onSuccess: function(event, fields) {
var revenue_data = [];
$('#revenue_grid .jsgrid-grid-body tr:not(.totalrow)').each(function(i, el) {
$('#revenue_grid .jsgrid-grid-body tr:not(.totalrow):not(.jsgrid-nodata-row)').each(function(i, el) {
var row = $(el).data('JSGridItem');
revenue_data.push({
'Description': row['Description'],
'Unit cost': row['Unit cost'],
'Unit price': row['Unit price'],
'Units': row['Units'],
'IWT': row['IWT'],
});
@ -151,11 +151,11 @@
$('#revenue_input').val(JSON.stringify(revenue_data));
var expense_data = [];
$('#expense_grid .jsgrid-grid-body tr:not(.totalrow)').each(function(i, el) {
$('#expense_grid .jsgrid-grid-body tr:not(.totalrow):not(.jsgrid-nodata-row)').each(function(i, el) {
var row = $(el).data('JSGridItem');
expense_data.push({
'Description': row['Description'],
'Unit cost': row['Unit cost'],
'Unit price': row['Unit price'],
'Units': row['Units'],
});
});
@ -166,7 +166,7 @@
// Interferes with jsGrid
$('.ui.form').on('keyup keypress', function(e) {
var keyCode = e.keyCode || e.which;
if (keyCode === 13) {
if (keyCode === 13) {
e.preventDefault();
return false;
}
@ -177,9 +177,9 @@
var total = 0;
var totalIWT = 0;
for (var row of args.grid.data) {
total += row['Unit cost'] * row['Units'];
if (row['Unit cost'] > 0 && row['IWT']) {
totalIWT += (row['Unit cost'] - (row['Unit cost'] - 0.8) / 1.019) * row['Units'];
total += row['Unit price'] * row['Units'];
if (row['Unit price'] > 0 && row['IWT']) {
totalIWT += (row['Unit price'] - (row['Unit price'] - 0.8) / 1.019) * row['Units'];
}
}
@ -203,7 +203,7 @@
function recalcExpTotal(args) {
var total = 0;
for (var row of args.grid.data) {
total += row['Unit cost'] * row['Units'];
total += row['Unit price'] * row['Units'];
}
$(args.grid._body).find('.totalrow').remove();
@ -244,15 +244,15 @@
height: '20em',
inserting: true,
editing: true,
noDataContent: 'No entries',
noDataContent: 'No entries. Click the green plus icon at the top right to add a new row.',
data: revenue_data,
fields: [
{ name: 'Description', type: 'text', width: '55%', validate: 'required' },
{ name: 'Unit cost', type: 'float', width: '10%', validate: 'required', itemTemplate: function(value, item) { return '$' + value.toFixed(2); } },
{ name: 'Units', type: 'float', width: '10%', validate: 'required' },
{ name: 'IWT', type: 'checkbox', width: '5%' },
{ name: 'Total', align: 'right', width: '10%', itemTemplate: function(value, item) { return '$' + (item['Unit cost'] * item['Units']).toFixed(2); } },
{ type: 'control', width: '10%' },
{ name: 'Description', type: 'text', width: '50%', validate: 'required' },
{ name: 'Unit price', type: 'float', width: '12.5%', validate: 'required', itemTemplate: function(value, item) { return '$' + value.toFixed(2); } },
{ name: 'Units', type: 'float', width: '12.5%', validate: 'required' },
{ name: 'IWT', type: 'checkbox', width: '5%', insertTemplate: function() { var result = jsGrid.fields.checkbox.prototype.insertTemplate.call(this); result.prop('checked', true); return result; } },
{ name: 'Total', align: 'right', width: '10%', itemTemplate: function(value, item) { return '$' + (item['Unit price'] * item['Units']).toFixed(2); } },
{ type: 'control', width: '10%', modeSwitchButton: false },
],
onItemUpdated: recalcRevTotal,
onRefreshed: recalcRevTotal,
@ -264,14 +264,14 @@
height: '20em',
inserting: true,
editing: true,
noDataContent: 'No entries',
noDataContent: 'No entries. Click the green plus icon at the top right to add a new row.',
data: expense_data,
fields: [
{ name: 'Description', type: 'text', width: '55%', validate: 'required' },
{ name: 'Unit cost', type: 'float', width: '10%', validate: 'required', itemTemplate: function(value, item) { return '$' + value.toFixed(2); } },
{ name: 'Units', type: 'float', width: '10%', validate: 'required' },
{ name: 'Total', align: 'right', width: '10%', itemTemplate: function(value, item) { return '$' + (item['Unit cost'] * item['Units']).toFixed(2); } },
{ type: 'control', width: '10%' },
{ name: 'Description', type: 'text', width: '50%', validate: 'required' },
{ name: 'Unit price', type: 'float', width: '12.5%', validate: 'required', itemTemplate: function(value, item) { return '$' + value.toFixed(2); } },
{ name: 'Units', type: 'float', width: '12.5%', validate: 'required' },
{ name: 'Total', align: 'right', width: '10%', itemTemplate: function(value, item) { return '$' + (item['Unit price'] * item['Units']).toFixed(2); } },
{ type: 'control', width: '10%', modeSwitchButton: false },
],
onItemUpdated: recalcExpTotal,
onRefreshed: recalcExpTotal,
@ -293,5 +293,7 @@
return el.classList.contains('totalrow');
}
});
//$('.jsgrid-insert-mode-button').click();
</script>
{% endblock %}

View File

@ -25,7 +25,7 @@
{% if is_latest %}
<div>
<span class="ui header">Status: {{ import('sstreasury.models').BudgetState(revision.state).description }}</span>
<span class="ui header">Status: {{ revision.get_state_display() }}</span>
<a class="ui mini labeled right floated icon button" href="{{ url('budget_edit', kwargs={'id': revision.budget.id}) }}"><i class="edit icon"></i> Edit</a>
</div>
{% else %}
@ -198,9 +198,9 @@
var total = 0;
var totalIWT = 0;
for (var row of args.grid.data) {
total += row['Unit cost'] * row['Units'];
if (row['Unit cost'] > 0 && row['IWT']) {
totalIWT += (row['Unit cost'] - (row['Unit cost'] - 0.8) / 1.019) * row['Units'];
total += row['Unit price'] * row['Units'];
if (row['Unit price'] > 0 && row['IWT']) {
totalIWT += (row['Unit price'] - (row['Unit price'] - 0.8) / 1.019) * row['Units'];
}
}
@ -222,7 +222,7 @@
function recalcExpTotal(args) {
var total = 0;
for (var row of args.grid.data) {
total += row['Unit cost'] * row['Units'];
total += row['Unit price'] * row['Units'];
}
$(args.grid._body).find('.totalrow').remove();
@ -263,10 +263,10 @@
data: revenue_data,
fields: [
{ name: 'Description', type: 'text', width: '55%', validate: 'required' },
{ name: 'Unit cost', type: 'float', width: '10%', validate: 'required', itemTemplate: function(value, item) { return '$' + value.toFixed(2); } },
{ name: 'Unit price', type: 'float', width: '10%', validate: 'required', itemTemplate: function(value, item) { return '$' + value.toFixed(2); } },
{ name: 'Units', type: 'float', width: '10%', validate: 'required' },
{ name: 'IWT', type: 'checkbox', width: '5%' },
{ name: 'Total', align: 'right', width: '10%', itemTemplate: function(value, item) { return '$' + (item['Unit cost'] * item['Units']).toFixed(2); } },
{ name: 'Total', align: 'right', width: '10%', itemTemplate: function(value, item) { return '$' + (item['Unit price'] * item['Units']).toFixed(2); } },
],
onRefreshed: recalcRevTotal,
});
@ -279,9 +279,9 @@
data: expense_data,
fields: [
{ name: 'Description', type: 'text', width: '55%', validate: 'required' },
{ name: 'Unit cost', type: 'float', width: '10%', validate: 'required', itemTemplate: function(value, item) { return '$' + value.toFixed(2); } },
{ name: 'Unit price', type: 'float', width: '10%', validate: 'required', itemTemplate: function(value, item) { return '$' + value.toFixed(2); } },
{ name: 'Units', type: 'float', width: '10%', validate: 'required' },
{ name: 'Total', align: 'right', width: '10%', itemTemplate: function(value, item) { return '$' + (item['Unit cost'] * item['Units']).toFixed(2); } },
{ name: 'Total', align: 'right', width: '10%', itemTemplate: function(value, item) { return '$' + (item['Unit price'] * item['Units']).toFixed(2); } },
],
onRefreshed: recalcExpTotal,
});

View File

@ -50,15 +50,14 @@ class BudgetState(Enum):
class BudgetRevision(models.Model):
budget = models.ForeignKey(Budget, on_delete=models.CASCADE)
name = models.CharField(max_length=100)
date = models.DateField(null=True)
date = models.DateField()
contributors = models.ManyToManyField(User, related_name='+')
comments = models.TextField()
author = models.ForeignKey(User, on_delete=models.PROTECT, related_name='+')
time = models.DateTimeField()
#state = models.IntegerField(choices=[(v.value, v.description) for v in BudgetState])
state = models.IntegerField()
state = models.IntegerField(choices=[(v.value, v.description) for v in BudgetState])
revenue = JSONField(default=[])
revenue_comments = models.TextField()