updateTotalCost();
+ if(invoice && openils.Util.isTrue(invoice.complete())) {
+
+ dojo.forEach( // hide widgets that should not be visible for a completed invoice
+ dojo.query('.hide-complete'),
+ function(node) { openils.Util.hide(node); }
+ );
+
+ new openils.User().getPermOrgList(
+ 'ACQ_INVOICE_REOPEN',
+ function (orgs) {
+ if(orgs.indexOf(invoice.receiver()) >= 0)
+ openils.Util.show('acq-invoice-reopen-button-wrapper', 'inline');
+ },
+ true,
+ true
+ );
+ }
+
if(invoice) {
dojo.forEach(
invoice.items(),
var totalCost = 0;
for(var id in widgetRegistry.acqii)
if(!widgetRegistry.acqii[id]._object.isdeleted())
- totalCost += widgetRegistry.acqii[id].cost_billed.getFormattedValue();
+ totalCost += Number(widgetRegistry.acqii[id].cost_billed.getFormattedValue());
for(var id in widgetRegistry.acqie)
if(!widgetRegistry.acqie[id]._object.isdeleted())
- totalCost += widgetRegistry.acqie[id].cost_billed.getFormattedValue();
+ totalCost += Number(widgetRegistry.acqie[id].cost_billed.getFormattedValue());
totalInvoicedBox.attr('value', totalCost);
totalPaid = 0;
for(var id in widgetRegistry.acqii)
if(!widgetRegistry.acqii[id]._object.isdeleted())
- totalPaid += widgetRegistry.acqii[id].amount_paid.getFormattedValue();
+ totalPaid += Number(widgetRegistry.acqii[id].amount_paid.getFormattedValue());
for(var id in widgetRegistry.acqie)
if(!widgetRegistry.acqie[id]._object.isdeleted())
- totalPaid += widgetRegistry.acqie[id].amount_paid.getFormattedValue();
+ totalPaid += Number(widgetRegistry.acqie[id].amount_paid.getFormattedValue());
totalPaidBox.attr('value', totalPaid);
var buttonsDisabled = false;
+
if(totalPaid > totalCost || totalPaid < 0) {
openils.Util.addCSSClass(totalPaidBox.domNode, 'acq-invoice-invalid-amount');
invoiceSaveButton.attr('disabled', true);
}
}
+ if(totalPaid == totalCost) { // XXX: too rigid?
+ invoiceCloseButton.attr('disabled', false);
+ } else {
+ invoiceCloseButton.attr('disabled', true);
+ }
+
balanceOwedBox.attr('value', (totalCost - totalPaid));
}
dojo.forEach(
['title', 'author', 'cost_billed', 'amount_paid'],
function(field) {
+
+ var args;
+ if(field == 'title' || field == 'author') {
+ args = {style : 'width:10em'};
+ } else if(field == 'cost_billed' || field == 'amount_paid') {
+ args = {required : true, style : 'width: 6em'};
+ }
registerWidget(
item,
field,
fmClass : 'acqii',
fmObject : item,
fmField : field,
- dijitArgs : (field == 'cost_billed' || field == 'amount_paid') ? {required : true, style : 'width: 6em'} : null,
+ readOnly : invoice && openils.Util.isTrue(invoice.complete()),
+ dijitArgs : args,
parentNode : nodeByName(field, row)
})
)
fmField : 'fund',
labelFormat : fundLabelFormat,
searchFormat : fundSearchFormat,
+ readOnly : invoice && openils.Util.isTrue(invoice.complete()),
parentNode : nodeByName('fund', row)
}
fmObject : item,
fmField : 'inv_item_type',
parentNode : nodeByName('inv_item_type', row),
+ readOnly : invoice && openils.Util.isTrue(invoice.complete()),
dijitArgs : {required : true}
}),
function(w, ww) {
}
function addInvoiceEntry(entry) {
+
+ openils.Util.removeCSSClass(dojo.byId('acq-invoice-entry-header'), 'hidden');
+ openils.Util.removeCSSClass(dojo.byId('acq-invoice-entry-thead'), 'hidden');
+ openils.Util.removeCSSClass(dojo.byId('acq-invoice-entry-tbody'), 'hidden');
+
entryTbody = dojo.byId('acq-invoice-entry-tbody');
if(entryTemplate == null) {
entryTemplate = entryTbody.removeChild(dojo.byId('acq-invoice-entry-template'));
fmClass : 'acqie',
fmField : field,
dijitArgs : dijitArgs,
+ readOnly : invoice && openils.Util.isTrue(invoice.complete()),
parentNode : nodeByName(field, row)
})
);
return (attr) ? attr.attr_value() : '';
}
-function saveChanges(doProrate) {
+function saveChanges(doProrate, doClose, doReopen) {
progressDialog.show(true);
- var updateItems = [];
- for(var id in widgetRegistry.acqii) {
- var reg = widgetRegistry.acqii[id];
- var item = reg._object;
- if(item.ischanged() || item.isnew() || item.isdeleted()) {
- updateItems.push(item);
- if(item.isnew()) item.id(null);
- for(var field in reg) {
- if(field != '_object')
- item[field]( reg[field].getFormattedValue() );
+ if(doReopen) {
+ invoice.complete('f');
+
+ } else {
+
+
+ var updateItems = [];
+ for(var id in widgetRegistry.acqii) {
+ var reg = widgetRegistry.acqii[id];
+ var item = reg._object;
+ if(item.ischanged() || item.isnew() || item.isdeleted()) {
+ updateItems.push(item);
+ if(item.isnew()) item.id(null);
+ for(var field in reg) {
+ if(field != '_object')
+ item[field]( reg[field].getFormattedValue() );
+ }
+
+ // unflesh
+ if(item.purchase_order() != null && typeof item.purchase_order() == 'object')
+ item.purchase_order( item.purchase_order().id() );
}
-
- // unflesh
- if(item.purchase_order() != null && typeof item.purchase_order() == 'object')
- item.purchase_order( item.purchase_order().id() );
}
- }
- var updateEntries = [];
- for(var id in widgetRegistry.acqie) {
- var reg = widgetRegistry.acqie[id];
- var entry = reg._object;
- if(entry.ischanged() || entry.isnew() || entry.isdeleted()) {
- entry.lineitem(entry.lineitem().id());
- entry.purchase_order(entry.purchase_order().id());
- updateEntries.push(entry);
- if(entry.isnew()) entry.id(null);
-
- for(var field in reg) {
- if(field != '_object')
- entry[field]( reg[field].getFormattedValue() );
- }
-
- // unflesh
- dojo.forEach(['purchase_order', 'lineitem'],
- function(field) {
- if(entry[field]() != null && typeof entry[field]() == 'object')
- entry[field]( entry[field]().id() );
+ var updateEntries = [];
+ for(var id in widgetRegistry.acqie) {
+ var reg = widgetRegistry.acqie[id];
+ var entry = reg._object;
+ if(entry.ischanged() || entry.isnew() || entry.isdeleted()) {
+ entry.lineitem(entry.lineitem().id());
+ entry.purchase_order(entry.purchase_order().id());
+ updateEntries.push(entry);
+ if(entry.isnew()) entry.id(null);
+
+ for(var field in reg) {
+ if(field != '_object')
+ entry[field]( reg[field].getFormattedValue() );
}
- );
+
+ // unflesh
+ dojo.forEach(['purchase_order', 'lineitem'],
+ function(field) {
+ if(entry[field]() != null && typeof entry[field]() == 'object')
+ entry[field]( entry[field]().id() );
+ }
+ );
+ }
}
- }
- if(!invoice) {
- invoice = new fieldmapper.acqinv();
- invoice.isnew(true);
- } else {
- invoice.ischanged(true); // for now, just always update
- }
-
- dojo.forEach(invoicePane.fieldList,
- function(field) {
- invoice[field.name]( field.widget.getFormattedValue() );
+ if(!invoice) {
+ invoice = new fieldmapper.acqinv();
+ invoice.isnew(true);
+ } else {
+ invoice.ischanged(true); // for now, just always update
}
- );
+
+ dojo.forEach(invoicePane.fieldList,
+ function(field) {
+ invoice[field.name]( field.widget.getFormattedValue() );
+ }
+ );
+
+ if(doClose)
+ invoice.complete('t');
+ }
fieldmapper.standardRequest(
['open-ils.acq', 'open-ils.acq.invoice.update'],
<div dojoType="dijit.layout.ContentPane" layoutAlign="client">
<table class='oils-acq-invoice-table'>
<thead/>
- <tbody>
+ <tbody id='acq-invoice-entry-header' class='hidden'>
<tr>
<td colspan='0'>
<h3>Bibliographic Items</h3>
</tr>
</tbody>
<!-- acq.invoice_entry -->
- <thead>
- <td colspan='3'>Title Details</td>
- <td># Invoiced / # Received</td>
- <td>Amount Billed</td>
- <td>Amount Paid</td>
- <td>Detach</td>
+ <thead id='acq-invoice-entry-thead' class='hidden'>
+ <tr>
+ <th colspan='2'>Title Details</th>
+ <th class='acq-invoice-center-col'># Invoiced</th>
+ <th class='acq-invoice-center-col'># Received</th>
+ <th class='acq-invoice-center-col'>Billed</th>
+ <th class='acq-invoice-paid-col'>Paid</th>
+ <th class='acq-invoice-center-col hide-complete'>Detach</th>
+ </tr>
</thead>
- <tbody id='acq-invoice-entry-tbody'>
+ <tbody id='acq-invoice-entry-tbody' class='hidden'>
<tr id='acq-invoice-entry-template' class='acq-invoice-row'>
- <td colspan='3'>
+ <td colspan='2'>
<div name='title_details'></div>
<div name='note'></div>
</td>
- <td nowrap='nowrap'>
- <span name='inv_item_count'></span> / <span name='phys_item_count'></span>
+ <td class='acq-invoice-center-col'>
+ <span name='inv_item_count'></span>
</td>
- <td><div name='cost_billed'/></td>
- <td><div name='amount_paid'/></td>
- <td><a href='javascript:void(0);' name='detach'>Detach</a></td>
+ <td class='acq-invoice-center-col'>
+ <span name='phys_item_count'></span>
+ </td>
+ <td class='acq-invoice-billed-col'><div name='cost_billed'/></td>
+ <td class='acq-invoice-paid-col'><div name='amount_paid'/></td>
+ <td class='acq-invoice-center-col hide-complete'><a href='javascript:void(0);' name='detach'>Detach</a></td>
</tr>
</tbody>
<tbody>
</tbody>
<!-- acq.invoice_item -->
<thead>
- <td>Charge Type</td>
- <td>Title / Description (optional)</td>
- <td>Author (optional)</td>
- <td>Fund</td>
- <td>Amount Billed</td>
- <td>Amount Paid</td>
- <td>Delete</td>
+ <tr>
+ <th>Charge Type</th>
+ <th>Title/Description</th>
+ <th>Author</th>
+ <th class='acq-invoice-center-col'>Fund</th>
+ <th class='acq-invoice-center-col'>Billed</th>
+ <th class='acq-invoice-paid-col'>Paid</th>
+ <th class='acq-invoice-center-col hide-complete'>Delete</th>
+ </tr>
</thead>
<tbody id='acq-invoice-item-tbody'>
<tr id='acq-invoice-item-template' class='acq-invoice-row acq-invoice-item-row'>
<td><div name='inv_item_type'/></td>
<td><div name='title'/></td>
<td><div name='author'/></td>
- <td><div name='fund'/></td>
- <td><div name='cost_billed'/></td>
- <td><div name='amount_paid'/></td>
- <td><a href='javascript:void(0);' name='delete'>Delete</a></td>
+ <td class='acq-invoice-center-col'><div name='fund'/></td>
+ <td class='acq-invoice-center-col' class='acq-invoice-billed-col'><div name='cost_billed'/></td>
+ <td class='acq-invoice-paid-col'><div name='amount_paid'/></td>
+ <td class='acq-invoice-center-col' class='hide-complete acq-invoice-balance-col'><a href='javascript:void(0);' name='delete'>Delete</a></td>
</tr>
</tbody>
- <tbody>
+ <tbody class='hide-complete'>
<tr>
<td colspan='0'>
<a href='javascript:void(0);' id='acq-invoice-new-item'>Add Charge...</a>
</tbody>
<thead>
<tr>
- <td colspan='4'/>
- <td>Total Invoiced</td>
- <td>Total Paid</td>
- <td>Balance Owed</td>
+ <th colspan='4'/>
+ <th class='acq-invoice-center-col' class='acq-invoice-billed-col'>Total</th>
+ <th class='acq-invoice-paid-col'>Total</th>
+ <th class='acq-invoice-center-col' class='acq-invoice-balance-col'>Balance</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan='4' style='text-align:right;'>
- <button jsId='invoiceSaveButton'
- dojoType='dijit.form.Button' onclick='saveChanges();'>Save Changes</button>
- <button jsId='invoiceProrateButton'
- dojoType='dijit.form.Button' onclick='saveChanges(true);'>Save & Prorate Charges</button>
+ <button jsId='invoiceSaveButton' class='hide-complete'
+ dojoType='dijit.form.Button' onclick='saveChanges();'>Save</button>
+ <button jsId='invoiceProrateButton' class='hide-complete'
+ dojoType='dijit.form.Button' onclick='saveChanges(true);'>Save & Prorate</button>
+ <button jsId='invoiceCloseButton' class='hide-complete'
+ dojoType='dijit.form.Button' onclick='saveChanges(false, true);'>Save & Close</button>
+ <span class='hidden' id='acq-invoice-reopen-button-wrapper'>
+ <button jsId='invoiceReopenButton'
+ dojoType='dijit.form.Button' onclick='saveChanges(false, false, true);'>Reopen Invoice</button>
+ </span>
</td>
- <td><div jsId='totalInvoicedBox' dojoType='dijit.form.CurrencyTextBox' style='width:6em;'/></td>
- <td><div jsId='totalPaidBox' dojoType='dijit.form.CurrencyTextBox' style='width:6em;'/></td>
- <td><div jsId='balanceOwedBox' dojoType='dijit.form.CurrencyTextBox' style='width:6em;'/></td>
+ <td class='acq-invoice-center-col'><div jsId='totalInvoicedBox' dojoType='dijit.form.CurrencyTextBox' style='width:6em;'/></td>
+ <td class='acq-invoice-paid-col'><div jsId='totalPaidBox' dojoType='dijit.form.CurrencyTextBox' style='width:6em;'/></td>
+ <td class='acq-invoice-center-col'><div jsId='balanceOwedBox' dojoType='dijit.form.CurrencyTextBox' style='width:6em;'/></td>
</tr>
</tbody>
</table>