@@ -, +, @@ - Koha::Acquisition::Basket - Koha::Acquisition::Invoice --- Koha/Acquisition/Basket.pm | 47 ++++++++++++++++++++++++++++++++++ Koha/Acquisition/Invoice.pm | 43 +++++++++++++++++++++++++++++++ Koha/Schema/Result/Aqbasket.pm | 4 +++ 3 files changed, 94 insertions(+) --- a/Koha/Acquisition/Basket.pm +++ a/Koha/Acquisition/Basket.pm @@ -71,6 +71,53 @@ sub effective_create_items { return $self->create_items || C4::Context->preference('AcqCreateItem'); } +=head3 to_api + + my $json = $basket->to_api; + +Overloaded method that returns a JSON representation of the Koha::Acquisition::Basket object, +suitable for API output. + +=cut + +sub to_api { + my ( $self ) = @_; + + my $json = $self->SUPER::to_api; + + $json->{closed} = ( $self->closedate ) + ? Mojo::JSON->true + : Mojo::JSON->false; + + return $json; +} + +=head3 to_api_mapping + +This method returns the mapping for representing a Koha::Acquisition::Basket object +on the API. + +=cut + +sub to_api_mapping { + return { + basketno => 'basket_id', + basketname => 'name', + booksellernote => 'vendor_note', + contractnumber => 'contract_id', + creationdate => 'creation_date', + closedate => 'close_date', + booksellerid => 'vendor_id', + authorisedby => 'authorised_by', + booksellerinvoicenumber => undef, + basketgroupid => 'basket_group_id', + deliveryplace => 'delivery_place', + billingplace => 'billing_place', + branch => 'library_id', + is_standing => 'standing' + }; +} + =head2 Internal methods =head3 _type --- a/Koha/Acquisition/Invoice.pm +++ a/Koha/Acquisition/Invoice.pm @@ -27,6 +27,49 @@ Koha::Acquisition::Invoice object class =head1 API + +=head3 to_api + + my $json = $invoice->to_api; + +Overloaded method that returns a JSON representation of the Koha::Acquisition::Invoice object, +suitable for API output. + +=cut + +sub to_api { + my ( $self ) = @_; + + my $json = $self->SUPER::to_api; + + $json->{closed} = ( $self->closedate ) + ? Mojo::JSON->true + : Mojo::JSON->false; + + return $json; +} + +=head3 to_api_mapping + +This method returns the mapping for representing a Koha::Acquisition::Invoice object +on the API. + +=cut + +sub to_api_mapping { + return { + invoiceid => 'invoice_id', + invoicenumber => 'invoice_number', + booksellerid => 'vendor_id', + shipmentdate => 'shipping_date', + billingdate => 'invoice_date', + closedate => 'close_date', + shipmentcost => 'shipping_cost', + shipmentcost_budgetid => 'shipping_cost_budget_id', + message_id => undef + }; +} + =head2 Internal methods =head3 _type --- a/Koha/Schema/Result/Aqbasket.pm +++ a/Koha/Schema/Result/Aqbasket.pm @@ -335,4 +335,8 @@ sub koha_objects_class { 'Koha::Acquisition::Baskets'; } +__PACKAGE__->add_columns( + '+is_standing' => { is_boolean => 1 } +); + 1; --