return $new_form->id;
}
+__PACKAGE__->register_method(
+ method => 'add_li_to_po',
+ api_name => 'open-ils.acq.purchase_order.add_lineitem',
+ signature => {
+ desc => q/Adds a lineitem to an existing purchase order/,
+ params => [
+ {desc => 'Authentication token', type => 'string'},
+ {desc => 'The purchase order id', type => 'number'},
+ {desc => 'The lineitem ID', type => 'number'},
+ ],
+ return => {desc => 'Streams a total versus completed counts object, event on error'}
+ }
+);
+
+sub add_li_to_po {
+ my($self, $conn, $auth, $po_id, $li_id) = @_;
+
+ my $e = new_editor(authtoken => $auth, xact => 1);
+ return $e->die_event unless $e->checkauth;
+
+ my $mgr = OpenILS::Application::Acq::BatchManager->new(editor => $e, conn => $conn);
+
+ my $po = $e->retrieve_acq_purchase_order($po_id)
+ or return $e->die_event;
+
+ my $li = $e->retrieve_acq_lineitem($li_id)
+ or return $e->die_event;
+
+ return $e->die_event unless
+ $e->allowed('CREATE_PURCHASE_ORDER', $po->ordering_agency);
+
+ unless ($po->state =~ /new|pending/) {
+ $e->rollback;
+ return {success => 0, po => $po, error => 'bad-po-state'};
+ }
+
+ unless ($li->state =~ /new|order-ready|pending-order/) {
+ $e->rollback;
+ return {success => 0, li => $li, error => 'bad-li-state'};
+ }
+
+ $li->purchase_order($po_id);
+ $li->state('pending-order');
+ update_lineitem($mgr, $li) or return $e->die_event;
+
+ $e->commit;
+ return {success => 1};
+}
+
1;
"LOAD_TERMS_FIRST" : "You can't retrieve records until you've loaded a CSV file\nwith bibliographic IDs in the first column.",
"SELECT_SEARCH_FIELD": "Select Search Field",
"LIBRARY_INITIATED": "Library Initiated",
- "DEL_LI_FROM_PO": "That item has already been ordered! Deleting it now will not revoke or modify any order that has been placed with a vendor. Deleting the item may put the system's idea of your purchase order in a state that is inconsistent with reality. Are you sure you mean to do this?"
+ "DEL_LI_FROM_PO": "That item has already been ordered! Deleting it now will not revoke or modify any order that has been placed with a vendor. Deleting the item may put the system's idea of your purchase order in a state that is inconsistent with reality. Are you sure you mean to do this?",
+ "ADD_LI_TO_PO_BAD_PO_STATE" : "The selected PO has already been activated",
+ "ADD_LI_TO_PO_BAD_LI_STATE" : "The selected lineitem is not in a state that can be added to a purchase order"
+
}
dojo.require('openils.BibTemplate');
dojo.require('fieldmapper.OrgUtils');
+dojo.requireLocalization('openils.acq', 'acq');
+var localeStrings = dojo.i18n.getLocalization('openils.acq', 'acq');
+
var liTable;
var identTarget;
var bibRecord;
acqLitSavePlDialog.show();
}
);
+ addToPoButton.onClick = createLi(
+ function() { /* oncomplete */
+ addToPoDialog.show();
+ }
+ );
createPoButton.onClick = createLi(
function() { /* oncomplete */
liTable._loadPOSelect();
prepareButtons();
fetchRelated();
+ dojo.connect(addToPoSave, 'onClick', addToPo)
+ openils.Util.registerEnterHandler(addToPoInput.domNode, addToPo);
+}
+
+var _addToPoHappened = false;
+function addToPo(args) {
+ var poId = addToPoInput.attr('value');
+ if (!poId) return false;
+ if (_addToPoHappened) return false;
+
+ var liId = liTable.getSelected()[0].id();
+ console.log("adding li " + liId + " to PO " + poId);
+
+ // hmm, addToPo is invoked twice for some reason...
+ _addToPoHappened = true;
+
+ fieldmapper.standardRequest(
+ ['open-ils.acq', 'open-ils.acq.purchase_order.add_lineitem'],
+ { async : true,
+ params : [openils.User.authtoken, poId, liId],
+ oncomplete : function(r) {
+ var resp = openils.Util.readResponse(r);
+ if (resp.success) {
+ location.href = oilsBasePath + '/acq/po/view/' + poId;
+ } else {
+ _addToPoHappened = false;
+ if (resp.error == 'bad-po-state') {
+ alert(localeStrings.ADD_LI_TO_PO_BAD_PO_STATE);
+ } else if (resp.error == 'bad-li-state') {
+ alert(localeStrings.ADD_LI_TO_PO_BAD_LI_STATE);
+ }
+ }
+ }
+ }
+ );
+
+ addToPoDialog.hide();
+ return false; // prevent form submission
}
openils.Util.addOnLoad(load);
<button jsId="addToPlButton" dojoType="dijit.form.Button">
Add to Selection List
</button>
+ <button jsId="addToPoButton" dojoType="dijit.form.Button">
+ Add to Purchase Order
+ </button>
<button jsId="createPoButton" dojoType="dijit.form.Button">
Create Purchase Order
</button>
</div>
+ <div class="hidden">
+ <div dojoType="dijit.Dialog" jsId='addToPoDialog'>
+ <table class='dijitTooltipTable'>
+ <tr>
+ <td><label>Enter the PO #: </label></td>
+ <td><input jsId='addToPoInput' dojoType="dijit.form.TextBox" /></td>
+ </tr>
+ <tr>
+ <td colspan='2' align='center'>
+ <button dojoType='dijit.form.Button' jsId='addToPoSave' type="submit">Save</button>
+ </td>
+ </tr>
+ </table>
+ </div>
+ </div>
+
</div>
[% INCLUDE "default/acq/common/info.tt2" which = "Related" %]
[% INCLUDE "default/acq/common/li_table.tt2" %]