# flesh li->provider
# flesh lid->fund
sub create_lineitem_detail_debit {
- my ($mgr, $li, $lid, $dry_run) = @_;
+ my ($mgr, $li, $lid, $dry_run, $no_translate) = @_;
my $li_id = ref($li) ? $li->id : $li;
}
my $amount = $li->estimated_unit_price;
- if($li->provider->currency_type ne $lid->fund->currency_type) {
+ if($li->provider->currency_type ne $lid->fund->currency_type and !$no_translate) {
# At Fund debit creation time, translate into the currency of the fund
# TODO: org setting to disable automatic currency conversion at debit create time?
$copy->isnew(1);
$copy->loan_duration(2);
$copy->fine_level(2);
- $copy->status(OILS_COPY_STATUS_ON_ORDER);
+ $copy->status(($lid->recv_time) ? OILS_COPY_STATUS_IN_PROCESS : OILS_COPY_STATUS_ON_ORDER);
$copy->barcode($lid->barcode);
$copy->location($lid->location);
$copy->call_number($volume->id);
params => [
{desc => 'Authentication token', type => 'string'},
{desc => 'List of lineitem_details to create', type => 'array'},
+ {desc => 'Create Debits. Used for creating post-po-asset-creation debits', type => 'bool'},
],
return => {desc => 'Streaming response of current position in the array'}
}
);
sub lineitem_detail_CUD_batch {
- my($self, $conn, $auth, $li_details) = @_;
+ my($self, $conn, $auth, $li_details, $create_debits) = @_;
my $e = new_editor(xact=>1, authtoken=>$auth);
return $e->die_event unless $e->checkauth;
my $mgr = OpenILS::Application::Acq::BatchManager->new(editor => $e, conn => $conn);
- # XXX perms
-
$mgr->total(scalar(@$li_details));
+ my $li;
my %li_cache;
+ my $evt;
for my $lid (@$li_details) {
- my $li = $li_cache{$lid->lineitem} || $e->retrieve_acq_lineitem($lid->lineitem);
+ unless($li = $li_cache{$lid->lineitem}) {
+ ($li, $evt) = fetch_and_check_li($e, $lid->lineitem, 'write');
+ return $evt if $evt;
+ }
if($lid->isnew) {
- create_lineitem_detail($mgr, %{$lid->to_bare_hash}) or return $e->die_event;
+ $lid = create_lineitem_detail($mgr, %{$lid->to_bare_hash}) or return $e->die_event;
+ if($create_debits) {
+ $li->provider($e->retrieve_acq_provider($li->provider)) or return $e->die_event;
+ $lid->fund($e->retrieve_acq_fund($lid->fund)) or return $e->die_event;
+ create_lineitem_detail_debit($mgr, $li, $lid, 0, 1) or return $e->die_event;
+ }
} elsif($lid->ischanged) {
$e->update_acq_lineitem_detail($lid) or return $e->die_event;
return $e->die_event unless $e->checkauth;
my $mgr = OpenILS::Application::Acq::BatchManager->new(editor => $e, conn => $conn);
- my $li = $e->retrieve_acq_lineitem([
- $li_id,
- { flesh => 1,
- flesh_fields => {jub => ['purchase_order', 'picklist']}
- }
- ]) or return $e->die_event;
-
- if($li->purchase_order) {
- return $e->die_event unless
- $e->allowed('CREATE_PURCHASE_ORDER', $li->purchase_order->ordering_agency);
- } else {
- return $e->die_event unless
- $e->allowed('CREATE_PICKLIST', $li->picklist->org_unit);
- }
+ my ($li, $evt) = fetch_and_check_li($e, $li_id, 'write');
+ return $evt if $evt;
$li->estimated_unit_price($price);
update_lineitem($mgr, $li) or return $e->die_event;
$e->commit and $conn->respond_complete or return $e->die_event;
}
+
+# retrieves a lineitem, fleshes its PO and PL, checks perms
+sub fetch_and_check_li {
+ my $e = shift;
+ my $li_id = shift;
+ my $perm_mode = shift || 'read';
+
+ my $li = $e->retrieve_acq_lineitem([
+ $li_id,
+ { flesh => 1,
+ flesh_fields => {jub => ['purchase_order', 'picklist']}
+ }
+ ]) or return $e->die_event;
+
+ if(my $po = $li->purchase_order) {
+ my $perms = ($perm_mode eq 'read') ? 'VIEW_PURCHASE_ORDER' : 'CREATE_PURCHASE_ORDER';
+ return ($li, $e->die_event) unless $e->allowed($perms, $po->ordering_agency);
+
+ } elsif(my $li = $li->picklist) {
+ my $perms = ($perm_mode eq 'read') ? 'VIEW_PICKLIST' : 'CREATE_PICKLIST';
+ return ($li, $e->die_event) unless $e->allowed($perms, $li->picklist->org_unit);
+ }
+
+ return ($li);
+}
+
+
1;
var invoicePane;
var itemTypes;
var virtualId = -1;
+var extraCopies = {};
+var extraCopiesFund;
var widgetRegistry = {acqie : {}, acqii : {}};
function nodeByName(name, context) {
}
);
}
+
+ extraCopiesFund = new openils.widget.AutoFieldWidget({
+ fmField : 'fund',
+ fmClass : 'acqlid',
+ searchFilter : {active : 't'},
+ labelFormat : fundLabelFormat,
+ searchFormat : fundSearchFormat,
+ parentNode : dojo.byId('acq-invoice-extra-copies-fund')
+ });
+ extraCopiesFund.build();
}
function renderInvoice() {
dijitArgs : dijitArgs,
readOnly : invoice && openils.Util.isTrue(invoice.complete()),
parentNode : nodeByName(field, row)
- })
+ }),
+ function(w) {
+ if(field == 'phys_item_count') {
+ dojo.connect(w, 'onChange',
+ function() {
+ // staff entered a higher number in the receive field than was originally ordered
+ if(Number(this.attr('value')) > entry.lineitem().item_count()) {
+ storeExtraCopies(
+ entry.lineitem().id(),
+ Number(this.attr('value')) - entry.lineitem().item_count()
+ );
+ }
+ }
+ )
+ }
+ }
);
}
);
}
function saveChanges(doProrate, doClose, doReopen) {
+ createExtraCopies(
+ function() {
+ saveChangesPartTwo(doProrate, doClose, doReopen);
+ }
+ );
+}
+
+function saveChangesPartTwo(doProrate, doClose, doReopen) {
progressDialog.show(true);
);
}
+function storeExtraCopies(liId, numExtra) {
+
+ dojo.byId('acq-invoice-extra-copies-message').innerHTML =
+ dojo.string.substitute(
+ localeStrings.INVOICE_EXTRA_COPIES, [numExtra]);
+
+ var addCopyHandler;
+ addCopyHandler = dojo.connect(
+ extraCopiesGo,
+ 'onClick',
+ function() {
+ extraCopies[liId] = {
+ numExtra : numExtra,
+ fund : extraCopiesFund.widget.attr('value')
+ }
+ extraItemsDialog.hide();
+ dojo.disconnect(addCopyHandler);
+ }
+ );
+
+ dojo.connect(
+ extraCopiesCancel,
+ 'onClick',
+ function() { extraItemsDialog.hide() }
+ );
+
+ extraItemsDialog.show();
+}
+
+function createExtraCopies(oncomplete) {
+
+ var lids = [];
+ for(var liId in extraCopies) {
+ var data = extraCopies[liId];
+ for(var i = 0; i < data.numExtra; i++) {
+ var lid = new fieldmapper.acqlid();
+ lid.isnew(true);
+ lid.lineitem(liId);
+ lid.fund(data.fund);
+ lid.recv_time('now');
+ lids.push(lid);
+ }
+ }
+
+ if(lids.length == 0)
+ return oncomplete();
+
+ fieldmapper.standardRequest(
+ ['open-ils.acq', 'open-ils.acq.lineitem_detail.cud.batch'],
+ {
+ params : [openils.User.authtoken, lids, true],
+ oncomplete : function(r) {
+ if(openils.Util.readResponse(r))
+ oncomplete();
+ }
+ }
+ );
+
+}
+
openils.Util.addOnLoad(init);