1 package OpenILS::Application::Acq::Lineitem;
2 use base qw/OpenILS::Application/;
3 use strict; use warnings;
6 use OpenSRF::Utils::Logger qw(:logger);
7 use OpenILS::Utils::Fieldmapper;
8 use OpenILS::Utils::CStoreEditor q/:funcs/;
9 use OpenILS::Const qw/:const/;
10 use OpenSRF::Utils::SettingsClient;
11 use OpenILS::Application::AppUtils;
12 use OpenILS::Application::Acq::Financials;
13 use OpenILS::Application::Cat::BibCommon;
14 use OpenILS::Application::Cat::AssetCommon;
15 my $U = 'OpenILS::Application::AppUtils';
18 __PACKAGE__->register_method(
19 method => 'create_lineitem',
20 api_name => 'open-ils.acq.lineitem.create',
22 desc => 'Creates a lineitem',
24 {desc => 'Authentication token', type => 'string'},
25 {desc => 'The lineitem object to create', type => 'object'},
27 return => {desc => 'ID of newly created lineitem on success, Event on error'}
32 my($self, $conn, $auth, $li) = @_;
33 my $e = new_editor(xact=>1, authtoken=>$auth);
34 return $e->die_event unless $e->checkauth;
38 my $picklist = $e->retrieve_acq_picklist($li->picklist)
39 or return $e->die_event;
41 if($picklist->owner != $e->requestor->id) {
42 return $e->die_event unless
43 $e->allowed('CREATE_PICKLIST', $picklist->org_unit, $picklist);
46 # indicate the picklist was updated
47 $picklist->edit_time('now');
48 $picklist->editor($e->requestor->id);
49 $e->update_acq_picklist($picklist) or return $e->die_event;
52 if($li->purchase_order) {
53 my $po = $e->retrieve_acq_purchase_order($li->purchase_order)
54 or return $e->die_event;
55 return $e->die_event unless
56 $e->allowed('MANAGE_PROVIDER', $po->ordering_agency, $po);
59 $li->selector($e->requestor->id);
60 $e->create_acq_lineitem($li) or return $e->die_event;
67 __PACKAGE__->register_method(
68 method => 'retrieve_lineitem',
69 api_name => 'open-ils.acq.lineitem.retrieve',
71 desc => 'Retrieves a lineitem',
73 {desc => 'Authentication token', type => 'string'},
74 {desc => 'lineitem ID to retrieve', type => 'number'},
75 {options => q/Hash of options, including
76 "flesh_attrs", which fleshes the attributes;
77 "flesh_li_details", which fleshes the order details objects/, type => 'hash'},
79 return => {desc => 'lineitem object on success, Event on error'}
84 sub retrieve_lineitem {
85 my($self, $conn, $auth, $li_id, $options) = @_;
86 my $e = new_editor(authtoken=>$auth);
87 return $e->die_event unless $e->checkauth;
88 return retrieve_lineitem_impl($e, $li_id, $options);
91 sub retrieve_lineitem_impl {
92 my ($e, $li_id, $options) = @_;
95 # XXX finer grained perms...
98 if($$options{flesh_attrs} or $$options{flesh_notes}) {
99 $flesh = {flesh => 2, flesh_fields => {jub => []}};
100 if($$options{flesh_notes}) {
101 push(@{$flesh->{flesh_fields}->{jub}}, 'lineitem_notes');
102 $flesh->{flesh_fields}->{acqlin} = ['alert_text'];
104 push(@{$flesh->{flesh_fields}->{jub}}, 'attributes') if $$options{flesh_attrs};
107 my $li = $e->retrieve_acq_lineitem([$li_id, $flesh]);
109 if($$options{flesh_li_details}) {
112 flesh_fields => {acqlid => []}
114 push(@{$ops->{flesh_fields}->{acqlid}}, 'fund') if $$options{flesh_fund};
115 push(@{$ops->{flesh_fields}->{acqlid}}, 'fund_debit') if $$options{flesh_fund_debit};
116 my $details = $e->search_acq_lineitem_detail([{lineitem => $li_id}, $ops]);
117 $li->lineitem_details($details);
118 $li->item_count(scalar(@$details));
120 my $details = $e->search_acq_lineitem_detail({lineitem => $li_id}, {idlist=>1});
121 $li->item_count(scalar(@$details));
124 if($li->purchase_order) {
126 $e->retrieve_acq_purchase_order($li->purchase_order)
129 if($purchase_order->owner != $e->requestor->id) {
130 return $e->event unless
131 $e->allowed('VIEW_PURCHASE_ORDER', undef, $purchase_order);
133 } elsif($li->picklist) {
134 my $picklist = $e->retrieve_acq_picklist($li->picklist)
137 if($picklist->owner != $e->requestor->id) {
138 return $e->event unless
139 $e->allowed('VIEW_PICKLIST', undef, $picklist);
143 $li->clear_marc if $$options{clear_marc};
150 __PACKAGE__->register_method(
151 method => 'delete_lineitem',
152 api_name => 'open-ils.acq.lineitem.delete',
154 desc => 'Deletes a lineitem',
156 {desc => 'Authentication token', type => 'string'},
157 {desc => 'lineitem ID to delete', type => 'number'},
159 return => {desc => '1 on success, Event on error'}
163 sub delete_lineitem {
164 my($self, $conn, $auth, $li_id) = @_;
165 my $e = new_editor(xact=>1, authtoken=>$auth);
166 return $e->die_event unless $e->checkauth;
168 my $li = $e->retrieve_acq_lineitem($li_id)
169 or return $e->die_event;
174 my $picklist = $e->retrieve_acq_picklist($li->picklist)
175 or return $e->die_event;
176 return OpenILS::Event->new('BAD_PARAMS')
177 if $picklist->owner != $e->requestor->id;
182 # delete the attached lineitem_details
183 my $lid_ids = $e->search_acq_lineitem_detail(
184 {lineitem => $li_id}, {idlist=>1});
186 for my $lid_id (@$lid_ids) {
187 $e->delete_acq_lineitem_detail(
188 $e->retrieve_acq_lineitem_detail($lid_id))
189 or return $e->die_event;
192 $e->delete_acq_lineitem($li) or return $e->die_event;
198 __PACKAGE__->register_method(
199 method => 'update_lineitem',
200 api_name => 'open-ils.acq.lineitem.update',
202 desc => 'Update a lineitem',
204 {desc => 'Authentication token', type => 'string'},
205 {desc => 'lineitem object update', type => 'object'}
207 return => {desc => '1 on success, Event on error'}
211 sub update_lineitem {
212 my($self, $conn, $auth, $li) = @_;
213 my $e = new_editor(xact=>1, authtoken=>$auth);
214 return $e->die_event unless $e->checkauth;
215 my $evt = update_lineitem_impl($e, $li);
221 sub update_lineitem_impl {
224 my $orig_li = $e->retrieve_acq_lineitem([
226 { flesh => 1, # grab the lineitem with picklist attached
227 flesh_fields => {jub => ['picklist', 'purchase_order']}
229 ]) or return $e->die_event;
231 # the marc may have been cleared on retrieval...
232 $li->marc($e->retrieve_acq_lineitem($li->id)->marc)
235 $li->editor($e->requestor->id);
236 $li->edit_time('now');
237 $e->update_acq_lineitem($li) or return $e->die_event;
241 __PACKAGE__->register_method(
242 method => 'lineitem_search',
243 api_name => 'open-ils.acq.lineitem.search',
246 desc => 'Searches lineitems',
248 {desc => 'Authentication token', type => 'string'},
249 {desc => 'Search definition', type => 'object'},
250 {desc => 'Options hash. idlist=true', type => 'object'},
251 {desc => 'List of lineitems', type => 'object/number'},
256 sub lineitem_search {
257 my($self, $conn, $auth, $search, $options) = @_;
258 my $e = new_editor(authtoken=>$auth, xact=>1);
259 return $e->event unless $e->checkauth;
260 return $e->event unless $e->allowed('CREATE_PICKLIST');
261 # XXX needs permissions consideration
262 my $lis = $e->search_acq_lineitem($search, {idlist=>1});
263 for my $li_id (@$lis) {
264 if($$options{idlist}) {
265 $conn->respond($li_id);
267 my $res = retrieve_lineitem($self, $conn, $auth, $li_id, $options);
268 $conn->respond($res) unless $U->event_code($res);
274 __PACKAGE__->register_method (
275 method => 'lineitems_related_by_bib',
276 api_name => 'open-ils.acq.lineitems_for_bib.by_bib_id',
279 Retrieves lineitems attached to same bib record, subject to the PO ordering agency. This variant takes the bib id.
280 @param authtoken Login session key
281 @param bib_id Id for the pertinent bib record.
282 @param options Object for tweaking the selection criteria and fleshing options.
286 __PACKAGE__->register_method (
287 method => 'lineitems_related_by_bib',
288 api_name => 'open-ils.acq.lineitems_for_bib.by_lineitem_id',
291 Retrieves lineitems attached to same bib record, subject to the PO ordering agency. This variant takes the id for any of the pertinent lineitems.
292 @param authtoken Login session key
293 @param bib_id Id for a pertinent lineitem.
294 @param options Object for tweaking the selection criteria and fleshing options.
298 sub lineitems_related_by_bib {
299 my($self, $conn, $auth, $id_value, $options) = @_;
300 my $e = new_editor(authtoken => $auth);
301 return $e->event unless $e->checkauth;
303 my $perm_orgs = $U->user_has_work_perm_at($e, 'VIEW_PURCHASE_ORDER', {descendants =>1}, $e->requestor->id);
306 if ($self->api_name =~ /by_bib_id/) {
307 $id_field = 'eg_bib_id';
313 "select"=>{"jub"=>["id"]},
314 "from"=>{"jub"=>"acqpo"},
316 $id_field=>$id_value,
323 "order_by"=>[{"class"=>"jub", "field"=>"create_time", "direction"=>"desc"}]
326 if ($options && defined $options->{lineitem_state}) {
327 $query->{'where'}{'jub'}{'state'} = $options->{lineitem_state};
330 if ($options && defined $options->{po_state}) {
331 $query->{'where'}{'+acqpo'}{'state'} = $options->{po_state};
334 if ($options && defined $options->{order_by}) {
335 $query->{'order_by'} = $options->{order_by};
338 my $results = $e->json_query($query);
339 for my $result (@$results) {
340 my $lineitem = $e->retrieve_acq_lineitem([
344 if (! $lineitem) { next; }
346 my $po = OpenILS::Application::Acq::Financials::retrieve_purchase_order_impl->(
348 $lineitem->purchase_order(),
349 {flesh_lineitem_count=>1,flesh_price_summary=>1}
352 if ($e->allowed( ['CREATE_PURCHASE_ORDER','VIEW_PURCHASE_ORDER'], $po->ordering_agency() )) {
353 $lineitem->purchase_order( $po );
354 $conn->respond($lineitem);
362 __PACKAGE__->register_method(
363 method => "lineitem_search_by_attributes",
364 api_name => "open-ils.acq.lineitem.search.by_attributes",
367 desc => "Performs a search against lineitem_attrs",
369 {desc => "Authentication token", type => "string"},
372 attr_value_pairs : list of pairs of (attr definition ID, attr value) where value can be scalar (fuzzy match) or array (exact match)
373 li_states : list of lineitem states
374 po_agencies : list of purchase order ordering agencies (org) ids
376 At least one of these search terms is required.
381 idlist : if set, only return lineitem IDs
382 clear_marc : if set, strip the MARC xml from the lineitem before delivery
383 flesh_attrs : flesh lineitem attributes;
390 __PACKAGE__->register_method(
391 method => "lineitem_search_by_attributes",
392 api_name => "open-ils.acq.lineitem.search.by_attributes.ident",
395 desc => "Performs a search against lineitem_attrs where ident is true.".
396 "See open-ils.acq.lineitem.search.by_attributes for params."
400 sub lineitem_search_by_attributes {
401 my ($self, $conn, $auth, $search, $options) = @_;
403 my $e = new_editor(authtoken => $auth, xact => 1);
404 return $e->die_event unless $e->checkauth;
405 # XXX needs permissions consideration
407 return [] unless $search;
408 my $attr_value_pairs = $search->{attr_value_pairs};
409 my $li_states = $search->{li_states};
410 my $po_agencies = $search->{po_agencies}; # XXX if none, base it on perms
413 "select" => {"acqlia" =>
414 [{"column" => "lineitem", "transform" => "distinct"}]
418 "acqliad" => {"field" => "id", "fkey" => "definition"},
421 "fkey" => "lineitem",
426 "fkey" => "purchase_order"
435 $where->{"+acqliad"} = {"ident" => "t"}
436 if $self->api_name =~ /\.ident/;
438 my $searched_for_something = 0;
440 if (ref $attr_value_pairs eq "ARRAY") {
441 $where->{"-or"} = [];
442 foreach (@$attr_value_pairs) {
444 my ($def, $value) = @$_;
445 push @{$where->{"-or"}}, {
447 "attr_value" => (ref $value) ?
448 $value : {"ilike" => "%" . $value . "%"},
453 $searched_for_something = 1;
456 if ($li_states and @$li_states) {
457 $where->{"+jub"} = {"state" => $li_states};
458 $searched_for_something = 1;
461 if ($po_agencies and @$po_agencies) {
462 $where->{"+acqpo"} = {"ordering_agency" => $po_agencies};
463 $searched_for_something = 1;
466 if (not $searched_for_something) {
468 return new OpenILS::Event(
469 "BAD_PARAMS", note => "You have provided no search terms."
473 $query->{"where"} = $where;
474 my $lis = $e->json_query($query);
476 for my $li_id_obj (@$lis) {
477 my $li_id = $li_id_obj->{"lineitem"};
478 if($options->{"idlist"}) {
479 $conn->respond($li_id);
482 retrieve_lineitem($self, $conn, $auth, $li_id, $options)
490 __PACKAGE__->register_method(
491 method => 'lineitem_search_ident',
492 api_name => 'open-ils.acq.lineitem.search.ident',
495 desc => 'Performs a search against lineitem_attrs where ident is true',
497 {desc => 'Authentication token', type => 'string'},
498 { desc => q/Search definition. Options are:
499 attr_values : list of attribute values (required)
500 li_states : list of lineitem states
501 po_agencies : list of purchase order ordering agencies (org) ids
506 Options hash. Options are:
507 idlist : if set, only return lineitem IDs
508 clear_marc : if set, strip the MARC xml from the lineitem before delivery
509 flesh_attrs : flesh lineitem attributes;
517 my $LI_ATTR_SEARCH = {
518 select => {acqlia => ['lineitem']},
531 fkey => 'purchase_order'
539 sub lineitem_search_ident {
540 my($self, $conn, $auth, $search, $options) = @_;
541 my $e = new_editor(authtoken=>$auth, xact=>1);
542 return $e->event unless $e->checkauth;
543 # XXX needs permissions consideration
545 return [] unless $search;
546 my $attr_values = $search->{attr_values};
547 my $li_states = $search->{li_states};
548 my $po_agencies = $search->{po_agencies}; # XXX if none, base it on perms
553 '+acqliad' => {ident => 't'},
557 push(@{$where_clause->{'-or'}}, {attr_value => {ilike => "%$_%"}}) for @$attr_values;
559 $where_clause->{'+jub'} = {state => {in => $li_states}}
560 if $li_states and @$li_states;
562 $where_clause->{'+acqpo'} = {ordering_agency => $po_agencies}
563 if $po_agencies and @$po_agencies;
565 $LI_ATTR_SEARCH->{where} = $where_clause;
567 my $lis = $e->json_query($LI_ATTR_SEARCH);
569 for my $li_id_obj (@$lis) {
570 my $li_id = $li_id_obj->{lineitem};
571 if($$options{idlist}) {
572 $conn->respond($li_id);
575 if($$options{flesh_attrs}) {
576 $li = $e->retrieve_acq_lineitem([
577 $li_id, {flesh => 1, flesh_fields => {jub => ['attributes']}}])
579 $li = $e->retrieve_acq_lineitem($li_id);
581 $li->clear_marc if $$options{clear_marc};
590 __PACKAGE__->register_method(
591 method => 'lineitem_detail_CUD_batch',
592 api_name => 'open-ils.acq.lineitem_detail.cud.batch',
595 desc => q/Creates a new purchase order line item detail.
596 Additionally creates the associated fund_debit/,
598 {desc => 'Authentication token', type => 'string'},
599 {desc => 'List of lineitem_details to create', type => 'array'},
601 return => {desc => 'Streaming response of current position in the array'}
605 sub lineitem_detail_CUD_batch {
606 my($self, $conn, $auth, $li_details, $options) = @_;
607 my $e = new_editor(xact=>1, authtoken=>$auth);
608 return $e->die_event unless $e->checkauth;
610 my $total = scalar(@$li_details);
611 for my $li_detail (@$li_details) {
615 $logger->info(Dumper($li_detail));
616 $logger->info('lid id ' . $li_detail->id);
617 $logger->info('lineitem ' . $li_detail->lineitem);
619 if($li_detail->isnew) {
620 $res = create_lineitem_detail_impl($self, $conn, $e, $li_detail, $options);
621 } elsif($li_detail->ischanged) {
622 $res = update_lineitem_detail_impl($self, $conn, $e, $li_detail);
623 } elsif($li_detail->isdeleted) {
624 $res = delete_lineitem_detail_impl($self, $conn, $e, $li_detail->id);
626 return $e->event if $e->died;
627 $conn->respond({maximum => $total, progress => $pos++, li => $res});
630 return {complete => 1};
634 sub create_lineitem_detail_impl {
635 my($self, $conn, $e, $li_detail, $options) = @_;
638 my $li = $e->retrieve_acq_lineitem($li_detail->lineitem)
639 or return $e->die_event;
641 my $evt = update_li_edit_time($e, $li);
644 # XXX check lineitem provider perms
646 if($li_detail->fund) {
647 my $fund = $e->retrieve_acq_fund($li_detail->fund) or return $e->die_event;
648 return $e->die_event unless
649 $e->allowed('MANAGE_FUND', $fund->org, $fund);
652 $e->create_acq_lineitem_detail($li_detail) or return $e->die_event;
654 unless($li_detail->barcode) {
655 my $pfx = $U->ou_ancestor_setting_value($li_detail->owning_lib, 'acq.tmp_barcode_prefix') || 'ACQ';
656 $li_detail->barcode($pfx.$li_detail->id);
658 unless($li_detail->cn_label) {
659 my $pfx = $U->ou_ancestor_setting_value($li_detail->owning_lib, 'acq.tmp_callnumber_prefix') || 'ACQ';
660 $li_detail->cn_label($pfx.$li_detail->id);
663 if(my $loc = $U->ou_ancestor_setting_value($li_detail->owning_lib, 'acq.default_copy_location')) {
664 $li_detail->location($loc);
667 $e->update_acq_lineitem_detail($li_detail) or return $e->die_event;
669 return $li_detail if $$options{return_obj};
670 return $li_detail->id
674 sub update_li_edit_time {
676 # some lineitem edits are allowed after approval time...
677 # return OpenILS::Event->new('ACQ_LINEITEM_APPROVED', payload => $li->id)
678 # if $li->state eq 'approved';
679 $li->edit_time('now');
680 $li->editor($e->requestor->id);
681 $e->update_acq_lineitem($li) or return $e->die_event;
686 __PACKAGE__->register_method(
687 method => 'retrieve_lineitem_detail',
688 api_name => 'open-ils.acq.lineitem_detail.retrieve',
690 desc => q/Updates a lineitem detail/,
692 {desc => 'Authentication token', type => 'string'},
693 {desc => 'id of lineitem_detail to retrieve', type => 'number'},
695 return => {desc => 'object on success, Event on failure'}
698 sub retrieve_lineitem_detail {
699 my($self, $conn, $auth, $li_detail_id) = @_;
700 my $e = new_editor(authtoken=>$auth);
701 return $e->event unless $e->checkauth;
703 my $li_detail = $e->retrieve_acq_lineitem_detail($li_detail_id)
706 if($li_detail->fund) {
707 my $fund = $e->retrieve_acq_fund($li_detail->fund) or return $e->event;
708 return $e->event unless
709 $e->allowed('MANAGE_FUND', $fund->org, $fund);
712 # XXX check lineitem perms
718 __PACKAGE__->register_method(
719 method => 'approve_lineitem',
720 api_name => 'open-ils.acq.lineitem.approve',
722 desc => 'Mark a lineitem as approved',
724 {desc => 'Authentication token', type => 'string'},
725 {desc => 'lineitem ID', type => 'number'}
727 return => {desc => '1 on success, Event on error'}
730 sub approve_lineitem {
731 my($self, $conn, $auth, $li_id) = @_;
732 my $e = new_editor(xact=>1, authtoken=>$auth);
733 return $e->die_event unless $e->checkauth;
735 # XXX perm checks for each lineitem detail
737 my $li = $e->retrieve_acq_lineitem($li_id)
738 or return $e->die_event;
740 return OpenILS::Event->new('ACQ_LINEITEM_APPROVED', payload => $li_id)
741 if $li->state eq 'approved';
743 my $details = $e->search_acq_lineitem_detail({lineitem => $li_id});
744 return OpenILS::Event->new('ACQ_LINEITEM_NO_COPIES', payload => $li_id)
745 unless scalar(@$details) > 0;
747 for my $detail (@$details) {
748 return OpenILS::Event->new('ACQ_LINEITEM_DETAIL_NO_FUND', payload => $detail->id)
749 unless $detail->fund;
751 return OpenILS::Event->new('ACQ_LINEITEM_DETAIL_NO_ORG', payload => $detail->id)
752 unless $detail->owning_lib;
755 $li->state('approved');
756 $li->edit_time('now');
757 $e->update_acq_lineitem($li) or return $e->die_event;
765 __PACKAGE__->register_method(
766 method => 'set_lineitem_attr',
767 api_name => 'open-ils.acq.lineitem_usr_attr.set',
769 desc => 'Sets a lineitem_usr_attr value',
771 {desc => 'Authentication token', type => 'string'},
772 {desc => 'Lineitem ID', type => 'number'},
773 {desc => 'Attr name', type => 'string'},
774 {desc => 'Attr value', type => 'string'}
776 return => {desc => '1 on success, Event on error'}
780 __PACKAGE__->register_method(
781 method => 'set_lineitem_attr',
782 api_name => 'open-ils.acq.lineitem_local_attr.set',
784 desc => 'Sets a lineitem_local_attr value',
786 {desc => 'Authentication token', type => 'string'},
787 {desc => 'Lineitem ID', type => 'number'},
788 {desc => 'Attr name', type => 'string'},
789 {desc => 'Attr value', type => 'string'}
791 return => {desc => 'ID of the attr object on success, Event on error'}
796 sub set_lineitem_attr {
797 my($self, $conn, $auth, $li_id, $attr_name, $attr_value) = @_;
798 my $e = new_editor(xact=>1, authtoken=>$auth);
799 return $e->die_event unless $e->checkauth;
803 my $attr_type = $self->api_name =~ /local_attr/ ?
804 'lineitem_local_attr_definition' : 'lineitem_usr_attr_definition';
806 my $attr = $e->search_acq_lineitem_attr({
808 attr_type => $attr_type,
809 attr_name => $attr_name})->[0];
811 my $find = "search_acq_$attr_type";
814 $attr->attr_value($attr_value);
815 $e->update_acq_lineitem_attr($attr) or return $e->die_event;
817 $attr = Fieldmapper::acq::lineitem_attr->new;
818 $attr->lineitem($li_id);
819 $attr->attr_type($attr_type);
820 $attr->attr_name($attr_name);
821 $attr->attr_value($attr_value);
823 my $attr_def_id = $e->$find({code => $attr_name}, {idlist=>1})->[0]
824 or return $e->die_event;
825 $attr->definition($attr_def_id);
826 $e->create_acq_lineitem_attr($attr) or return $e->die_event;
833 __PACKAGE__->register_method(
834 method => 'get_lineitem_attr_defs',
835 api_name => 'open-ils.acq.lineitem_attr_definition.retrieve.all',
837 desc => 'Retrieve lineitem attr definitions',
839 {desc => 'Authentication token', type => 'string'},
841 return => {desc => 'List of attr definitions'}
845 sub get_lineitem_attr_defs {
846 my($self, $conn, $auth) = @_;
847 my $e = new_editor(authtoken=>$auth);
848 return $e->event unless $e->checkauth;
850 for my $type (qw/generated marc local usr provider/) {
851 my $call = "retrieve_all_acq_lineitem_${type}_attr_definition";
852 $results{$type} = $e->$call;
858 __PACKAGE__->register_method(
859 method => 'lineitem_note_CUD_batch',
860 api_name => 'open-ils.acq.lineitem_note.cud.batch',
863 desc => q/Manage lineitem notes/,
865 {desc => 'Authentication token', type => 'string'},
866 {desc => 'List of lineitem_notes to manage', type => 'array'},
868 return => {desc => 'Streaming response of current position in the array'}
872 sub lineitem_note_CUD_batch {
873 my($self, $conn, $auth, $li_notes) = @_;
875 my $e = new_editor(xact=>1, authtoken=>$auth);
876 return $e->die_event unless $e->checkauth;
879 my $total = @$li_notes;
882 for my $note (@$li_notes) {
884 $note->editor($e->requestor->id);
885 $note->edit_time('now');
888 $note->creator($e->requestor->id);
889 $note = $e->create_acq_lineitem_note($note) or return $e->die_event;
891 } elsif($note->isdeleted) {
892 $e->delete_acq_lineitem_note($note) or return $e->die_event;
894 } elsif($note->ischanged) {
895 $e->update_acq_lineitem_note($note) or return $e->die_event;
898 if(!$note->isdeleted) {
899 $note = $e->retrieve_acq_lineitem_note([
901 "flesh" => 1, "flesh_fields" => {"acqlin" => ["alert_text"]}
906 $conn->respond({maximum => $total, progress => ++$count, note => $note});
910 return {complete => 1};
913 __PACKAGE__->register_method(
914 method => 'ranged_line_item_alert_text',
915 api_name => 'open-ils.acq.line_item_alert_text.ranged.retrieve.all');
917 sub ranged_line_item_alert_text {
918 my($self, $conn, $auth, $org_id, $depth) = @_;
919 my $e = new_editor(authtoken => $auth);
920 return $e->event unless $e->checkauth;
921 return $e->event unless $e->allowed('ADMIN_ACQ_LINEITEM_ALERT_TEXT', $org_id);
922 return $e->search_acq_lineitem_alert_text(
923 {owning_lib => $U->get_org_full_path($org_id, $depth)});