From b914cdc9df674cf5e788529d41449a5438dbfd45 Mon Sep 17 00:00:00 2001 From: Matt Blenkinsop Date: Thu, 19 Sep 2024 14:43:25 +0000 Subject: [PATCH] Bug 38010: Add the form to add a new vendor --- Koha/REST/V1/Acquisitions/Vendors.pm | 25 ++- acqui/booksellers.pl | 1 + .../prog/js/vue/components/Vendors/Main.vue | 9 +- .../vue/components/Vendors/VendorContacts.vue | 205 +++++++++++++++++- .../vue/components/Vendors/VendorDetails.vue | 132 ++++++++++- .../vue/components/Vendors/VendorFormAdd.vue | 154 +++++++++++++ .../components/Vendors/VendorInterfaces.vue | 121 ++++++++++- .../js/vue/components/Vendors/VendorList.vue | 36 ++- .../Vendors/VendorOrderingInformation.vue | 186 +++++++++++++++- .../js/vue/components/Vendors/VendorShow.vue | 7 +- .../js/vue/fetch/acquisition-api-client.js | 3 + .../prog/js/vue/routes/acquisitions.js | 13 ++ 12 files changed, 845 insertions(+), 47 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/VendorFormAdd.vue diff --git a/Koha/REST/V1/Acquisitions/Vendors.pm b/Koha/REST/V1/Acquisitions/Vendors.pm index 2b93fb28751..0747f5bbf43 100644 --- a/Koha/REST/V1/Acquisitions/Vendors.pm +++ b/Koha/REST/V1/Acquisitions/Vendors.pm @@ -87,21 +87,34 @@ Controller function that handles adding a new Koha::Acquisition::Bookseller obje sub add { my $c = shift->openapi->valid_input or return; - my $vendor = Koha::Acquisition::Bookseller->new_from_api( $c->req->json ); + my $vendor = $c->req->json; + my $contacts = delete $vendor->{contacts}; + my $interfaces = delete $vendor->{interfaces}; + my $aliases = delete $vendor->{aliases}; + + my $vendor_to_store = Koha::Acquisition::Bookseller->new_from_api( $c->req->json ); return try { - $vendor->store; - $c->res->headers->location($c->req->url->to_string . '/' . $vendor->id ); + $vendor_to_store->store; + + foreach my $contact (@$contacts) { + $contact->{booksellerid} = $vendor_to_store->id; + Koha::Acquisition::Bookseller::Contact->new($contact)->store; + } + $vendor_to_store->aliases($aliases) if scalar($aliases) > 0; + $vendor_to_store->interfaces($interfaces) if scalar($interfaces) > 0; + + $c->res->headers->location( $c->req->url->to_string . '/' . $vendor_to_store->id ); return $c->render( status => 201, - openapi => $c->objects->to_api($vendor), + openapi => $c->objects->to_api($vendor_to_store), ); - } - catch { + } catch { $c->unhandled_exception($_); }; } + =head3 update Controller function that handles updating a Koha::Acquisition::Bookseller object diff --git a/acqui/booksellers.pl b/acqui/booksellers.pl index 520b977f78f..33b0b042b26 100755 --- a/acqui/booksellers.pl +++ b/acqui/booksellers.pl @@ -62,6 +62,7 @@ use C4::Context; use Koha::Acquisition::Booksellers; use Koha::Patrons; +use Koha::Acquisition::Currencies; my $query = CGI->new; my ( $template, $loggedinuser, $cookie, $userflags ) = get_template_and_user( diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/Main.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/Main.vue index b26ff4e8b44..552be59f6b3 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/Main.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/Main.vue @@ -94,11 +94,18 @@ export default { fetchConfig().then(() => { this.loaded() + this.userPermissions = userPermissions + this.vendorStore.currencies = currencies + this.vendorStore.gstValues = gstValues.map(gv => { + return { + label: `${(gv.option * 100).toFixed(2)}%`, + value: gv.option, + } + }) this.initialized = true }) }, data() { - this.userPermissions = userPermissions return { initialized: false, } diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/VendorContacts.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/VendorContacts.vue index 61a56e3e7d3..d02d2875ba7 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/VendorContacts.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/VendorContacts.vue @@ -1,5 +1,5 @@