__PACKAGE__->register_method(
method => 'generate_refundable_payment_receipt',
- api_name => 'open-ils.circ.refundable_payment.receipt.html',
+ api_name => 'open-ils.circ.refundable_payment.receipt.by_xact.html',
signature => {
- desc => q/Generate a printable HTML refundable payment receipt/,
+ desc => q/Generate a printable HTML refundable payment receipt
+ for the latest payment on the given billable transaction ID/,
params => [
{desc => 'Authentication token', type => 'string'},
- {desc => 'Refundable Payment ID', type => 'number'}
+ {desc => 'Billable Transaction ID', type => 'number'}
],
return => {
desc => 'A/T event with fleshed outputs on success, event on error'
);
sub generate_refundable_payment_receipt {
- my ($self, $client, $auth, $mrp_id) = @_;
+ my ($self, $client, $auth, $target_id) = @_;
my $e = new_editor(authtoken => $auth);
return $e->die_event unless $e->checkauth;
- my $mrps= $e->retrieve_money_refundable_payment_summary([
- $mrp_id, {flesh => 1, flesh_fields => {mrps => ['refundable_xact']}}
- ]) or return $e->event;
+ my $mrps;
+ if ($self->api_name =~ /by_xact/) {
+
+ my $mrxs = $e->search_money_refundable_xact_summary([
+ {xact => $target_id},
+ { flesh => 2,
+ flesh_fields => {
+ mrxs => ['refundable_payments'],
+ mrps => ['payment']
+ }
+ }
+ ])->[0] or return $e->event;
+
+ # Print the most recent payment.
+ my @payments = @{$mrxs->refundable_payments};
+ @payments =
+ sort {$a->payment->payment_ts cmp $b->payment->payment_ts} @payments;
+ $mrps = pop(@payments);
+
+ # sync the fleshing for below
+ $mrxs->clear_refundable_payments;
+ $mrps->refundable_xact($mrxs);
+
+ } else {
+
+ $mrps = $e->retrieve_money_refundable_payment_summary([
+ $target_id,
+ {flesh => 1, flesh_fields => {mrps => ['refundable_xact']}}
+ ]) or return $e->event;
+ }
# ->usr may be undef when the transaction in question has been purged.
# Patrons do not need to print receipts for purged transactions.
false
);
+ window.bill_event_listeners.add($('printlostpaid'),
+ 'command',
+ handle_printlostpaid,
+ false
+ );
+
window.bill_event_listeners.add($('payment'),
'change',
function(ev) {
}
}
+
+
/**
* Launch secondary authentication dialog.
* "Skip" option bypasses the secondary authentication step.
$('opac').setAttribute('disabled', g.bill_list_selection.length == 0);
$('copy_details').setAttribute('disabled', g.bill_list_selection.length == 0);
$('printthis').setAttribute('disabled', g.bill_list_selection.length == 0);
+ $('printlostpaid').setAttribute('disabled', g.bill_list_selection.length == 0);
},
'on_click' : function(ev) {
var row = {}; var col = {}; var nobj = {};
g.bill_list.print(params);
}
+function handle_printlostpaid() {
+ var selected = g.bill_list.dump_selected_with_keys(0);
+ var xact_ids = selected.map(function(sel) { return sel.mbts_id });
+
+ for (var i = 0; i < xact_ids.length; i++) {
+ xact_id = xact_ids[0];
+
+ var receipt = g.network.request(
+ 'open-ils.circ',
+ 'open-ils.circ.refundable_payment.receipt.by_xact.html',
+ [ses(), xact_id]
+ );
+
+ if (receipt &&
+ receipt.textcode == 'MONEY_REFUNDABLE_XACT_SUMMARY_NOT_FOUND') {
+ alert('Transaction ' + xact_id + ' has no lost payments');
+ continue;
+ }
+
+ if (!receipt || !receipt.template_output()) {
+ return alert(
+ 'Error creating refundable payment receipt for payment ' + xact_id);
+ }
+
+ var html = receipt.template_output().data();
+ JSAN.use('util.print');
+ var print = new util.print('mail');
+
+ print.simple(html , {
+ no_prompt: false, // always prompt for lost payment receipts
+ content_type: 'text/html'
+ });
+ }
+}
+
function handle_opac() {
try {
var ids = [];
var html = receipt.template_output().data();
JSAN.use('util.print'); var print = new util.print('mail');
print.simple(html , {
- no_prompt: false, /*TODO*/
+ no_prompt: false, // always prompt for lost payment receipts
content_type: 'text/html'
});
}
<command id="add" label="&staff.patron.bill_interface.add_billing.label;" accesskey="&staff.patron.bill_interface.add_billing.accesskey;" disabled="true"/>
<command id="details" label="&staff.patron.bill_interface.full_details.label;" accesskey="&staff.patron.bill_interface.full_details.accesskey;" disabled="true"/>
<command id="printthis" label="&staff.patron.bill_interface.print_selected.label;" accesskey="&staff.patron.bill_interface.full_details.accesskey;" disabled="true"/>
+ <command id="printlostpaid" label="Reprint Lost/Paid Receipt" disabled="true"/>
</commandset>
<popupset>
<menuitem command="add" />
<menuitem command="details" />
<menuitem command="printthis" />
+ <menuitem command="printlostpaid" />
</menupopup>
</popupset>