acq invoice : price per copy column
authorBill Erickson <berick@esilibrary.com>
Wed, 25 Jul 2012 19:12:55 +0000 (15:12 -0400)
committerBill Erickson <berick@esilibrary.com>
Wed, 25 Jul 2012 19:12:55 +0000 (15:12 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/templates/acq/invoice/view.tt2
Open-ILS/web/js/ui/default/acq/invoice/view.js

index 86b5884..dd6c712 100644 (file)
@@ -17,6 +17,9 @@
                 padding-bottom: 5px;
                 border-bottom: 2px solid #888;
             }
+            #acq-invoice-num-summary-table td[id] {
+                font-weight:bold;
+            }
         </style>
         <table id='acq-invoice-num-summary-table'>
             <tr><td>[% l("Lineitems: " ) %]</td><td id='acq-invoice-summary-count'>0</td></tr>
@@ -25,6 +28,7 @@
                 <td id='acq-invoice-summary-cost'>0.00</td>
             </tr>
         </table>
+        <br/>
     <div>
 
     <div dojoType="dijit.layout.ContentPane" layoutAlign="client">
@@ -68,6 +72,7 @@
                             <th colspan='2'>Title Details</th>
                             <th class='acq-invoice-center-col'>#&nbsp;Invoiced&nbsp;/&nbsp;#&nbsp;Paid</th>
                             <th class='acq-invoice-center-col'>Billed</th>
+                            <th class='acq-invoice-paid-per-copy-col'>Per Copy</th>
                             <th class='acq-invoice-paid-col'>Paid</th>
                             <th class='acq-invoice-center-col hide-complete'>Detach</th>
                         </tr>
@@ -82,6 +87,7 @@
                                 <span name='inv_item_count'></span>&nbsp;/&nbsp;<span name='phys_item_count'></span>
                             </td>
                             <td class='acq-invoice-billed-col'><div name='cost_billed'></div></td>
+                            <td><div name='amount_paid_per_copy'>0.00</div></td>
                             <td class='acq-invoice-paid-col'><div name='amount_paid'></div></td>
                             <td class='acq-invoice-center-col hide-complete'><a href='javascript:void(0);' name='detach'>Detach</a></td>
                         </tr>
                             <th class='acq-invoice-center-col'>Fund</th>
                             <th>Title/Description</th>
                             <th class='acq-invoice-center-col'>Billed</th>
+                            <th/>
                             <th class='acq-invoice-paid-col'>Paid</th>
                             <th class='acq-invoice-center-col hide-complete'>Delete</th>
                         </tr>
                             <td class='acq-invoice-center-col'><div name='fund'></div></td>
                             <td><div name='title'></div></td>
                             <td class='acq-invoice-center-col acq-invoice-billed-col'><div name='cost_billed'></div></td>
+                            <td/>
                             <td class='acq-invoice-paid-col'><div name='amount_paid'></div></td>
                             <td class='acq-invoice-center-col hide-complete'><a href='javascript:void(0);' name='delete'>Delete</a></td>
                         </tr>
                         <tr>
                             <th colspan='3'/>
                             <th class='acq-invoice-center-col acq-invoice-billed-col'>Total</th>
+                            <th/>
                             <th class='acq-invoice-paid-col'>Total</th>
                             <th class='acq-invoice-center-col acq-invoice-balance-col'>Balance</th>
                         </tr>
index 7b5e0be..3e64528 100644 (file)
@@ -70,14 +70,14 @@ function init() {
         openils.Util.hide(dojo.byId('acq-invoice-summary-small'));
     }
 
-    // show summary info by default
-    dojo.byId('acq-invoice-summary-toggle-on').onclick();
-
-
     if(cgi.param('create')) {
         renderInvoice();
 
+        // show summary info by default for new invoices
+        dojo.byId('acq-invoice-summary-toggle-on').onclick();
+
     } else {
+        dojo.byId('acq-invoice-summary-toggle-off').onclick();
         fieldmapper.standardRequest(
             ['open-ils.acq', 'open-ils.acq.invoice.retrieve.authoritative'],
             {
@@ -666,6 +666,7 @@ function updateExpectedCost(li, entry) {
     dojo.byId('acq-invoice-summary-cost').innerHTML = total.toFixed(2);
 }
 
+var invoicEntryWidgets = {};
 function addInvoiceEntry(entry) {
     console.log('Adding new entry for lineitem ' + entry.lineitem());
 
@@ -731,6 +732,7 @@ function addInvoiceEntry(entry) {
                             parentNode : nodeByName(field, row)
                         }),
                         function(w) {    
+
                             if(field == 'phys_item_count') {
                                 dojo.connect(w, 'onChange', 
                                     function() {
@@ -743,8 +745,15 @@ function addInvoiceEntry(entry) {
                                         }
                                     }
                                 )
-                            }
-                        }
+                            } // if
+
+                            if(field == 'inv_item_count' || field == 'cost_billed') {
+                                setPerCopyPrice(row, entry);
+                                // update the per-copy count as invoice count and cost billed change 
+                                dojo.connect(w, 'onChange', function() { setPerCopyPrice(row, entry) } );
+                            } 
+
+                        } // func
                     );
                 }
             );
@@ -784,6 +793,22 @@ function addInvoiceEntry(entry) {
     updateTotalCost();
 }
 
+function setPerCopyPrice(row, entry) {
+    var inv_w = widgetRegistry.acqie[entry.id()].inv_item_count;
+    var bill_w = widgetRegistry.acqie[entry.id()].cost_billed;
+
+    if (inv_w && bill_w) {
+        var invoiced = Number(inv_w.getFormattedValue());
+        var billed = Number(bill_w.getFormattedValue());
+        console.log(invoiced + ' : ' + billed);
+        if (invoiced > 0) {
+            nodeByName('amount_paid_per_copy', row).innerHTML = (billed / invoiced).toFixed(2);
+        } else {
+            nodeByName('amount_paid_per_copy', row).innerHTML = '0.00';
+        }
+    }
+}
+
 function liMarcAttr(lineitem, name) {
     var attr = lineitem.attributes().filter(
         function(attr) {