[open-ils-commits] r16133 - in trunk/Open-ILS/src/perlmods/OpenILS/Application: . Acq (erickson)

svn at svn.open-ils.org svn at svn.open-ils.org
Mon Apr 5 14:58:50 EDT 2010


Author: erickson
Date: 2010-04-05 14:58:45 -0400 (Mon, 05 Apr 2010)
New Revision: 16133

Added:
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Invoice.pm
Modified:
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq.pm
Log:
initial invoice sub-module

Added: trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Invoice.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Invoice.pm	                        (rev 0)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Invoice.pm	2010-04-05 18:58:45 UTC (rev 16133)
@@ -0,0 +1,123 @@
+package OpenILS::Application::Acq::Invoice;
+use base qw/OpenILS::Application/;
+use strict; use warnings;
+
+use OpenSRF::Utils::Logger qw(:logger);
+use OpenILS::Utils::Fieldmapper;
+use OpenILS::Utils::CStoreEditor q/:funcs/;
+use OpenILS::Application::AppUtils;
+use OpenILS::Event;
+my $U = 'OpenILS::Application::AppUtils';
+
+
+__PACKAGE__->register_method(
+	method => 'build_invoice_api',
+	api_name	=> 'open-ils.acq.invoice.create',
+	signature => {
+        desc => q/Creates a new stub invoice/,
+        params => [
+            {desc => 'Authentication token', type => 'string'},
+            {desc => q/Invoice Object/, type => 'object', class => 'acqinv'},
+        ],
+        return => {desc => 'The new invoice w/ entries and items attached', type => 'object', class => 'acqinv'}
+    }
+);
+
+__PACKAGE__->register_method(
+	method => 'build_invoice_api',
+	api_name	=> 'open-ils.acq.invoice.attach',
+	signature => {
+        desc => q/Attach invoice entries and invoice items to an existing invoice/,
+        params => [
+            {desc => 'Authentication token', type => 'string'},
+            {desc => q/Invoice ID/, type => 'number'},
+            {desc => q/Entries/, type => 'array'},
+            {desc => q/Items/, type => 'array'},
+        ],
+        return => {desc => 'The invoice w/ entries and items attached', type => 'object', class => 'acqinv'}
+    }
+);
+
+sub build_invoice_api {
+    my($self, $conn, $auth, $invoice, $entries, $items) = @_;
+
+    my $e = new_editor(xact => 1, authtoken=>$auth);
+    return $e->die_event unless $e->checkauth;
+
+
+    if($self->api_name =~ /create/) {
+        $invoice->receiver($e->requestor->ws_ou) unless $invoice->receiver;
+        $invoice->recv_method('PPR') unless $invoice->recv_method;
+        $invoice->recv_date('now') unless $invoice->recv_date;
+        $e->create_acq_invoice($invoice) or return $e->die_event;
+    } else {
+        $invoice = $e->retrieve_acq_invoice($invoice) or return $e->die_event;
+    }
+
+    return $e->die_event unless $e->allowed('CREATE_INVOICE', $invoice->receiver);
+
+    if($entries) {
+        for my $entry (@$entries) {
+            $entry->invoice($invoice->id);
+            $e->create_acq_invoice_entry($entry) or return $e->die_event;
+        }
+    }
+
+    if($items) {
+        for my $item (@$items) {
+            $item->invoice($invoice->id);
+            $e->create_acq_invoice_item($item) or return $e->die_event;
+        }
+    }
+
+    $invoice = fetch_invice_impl($e, $invoice->id);
+    $e->commit;
+
+    return $invoice;
+}
+
+__PACKAGE__->register_method(
+	method => 'build_invoice_api',
+	api_name	=> 'open-ils.acq.invoice.retrieve',
+	signature => {
+        desc => q/Creates a new stub invoice/,
+        params => [
+            {desc => 'Authentication token', type => 'string'},
+            {desc => q/Invoice Id/, type => 'number'},
+        ],
+        return => {desc => 'The new invoice w/ entries and items attached', type => 'object', class => 'acqinv'}
+    }
+);
+
+
+sub fetch_invice_api {
+    my($self, $conn, $auth, $invoice_id) = @_;
+
+    my $e = new_editor(authtoken=>$auth);
+    return $e->event unless $e->checkauth;
+
+    my $invoice = fetch_invoice_impl($e, $invoice_id) or return $e->event;
+    return $e->event unless $e->allowed(['VIEW_INVOICE', 'CREATE_INVOICE'], $invoice->receiver);
+
+    return $invoice;
+}
+
+sub fetch_invice_impl {
+    my $e = shift;
+    my $invoice_id = shift;
+
+    return $e->retrieve_acq_invoice([
+        $invoice_id,
+        {
+            flesh => 3,
+            flesh_fields => {
+                acqinv => ['entries', 'items'],
+                acqie => ['lineitem', 'purchase_order'],
+                jub => ['attributes']
+            }
+        }
+    ]);
+}
+
+
+1;

Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq.pm	2010-04-05 18:58:44 UTC (rev 16132)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq.pm	2010-04-05 18:58:45 UTC (rev 16133)
@@ -10,5 +10,6 @@
 use OpenILS::Application::Acq::EDI;
 use OpenILS::Application::Acq::Search;
 use OpenILS::Application::Acq::Claims;
+use OpenILS::Application::Acq::Invoice;
 
 1;



More information about the open-ils-commits mailing list