From f04eacaf977b54afa72f35bb5fb5cb2bd451bed8 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 | 21 +- acqui/booksellers.pl | 1 + .../prog/js/vue/components/Vendors/Main.vue | 9 +- .../vue/components/Vendors/VendorContacts.vue | 205 +++++++++++++++++- .../vue/components/Vendors/VendorDetails.vue | 131 ++++++++++- .../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 +- .../prog/js/vue/routes/acquisitions.js | 13 ++ 11 files changed, 839 insertions(+), 45 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 5be398cf1ae..56351fa9252 100644 --- a/Koha/REST/V1/Acquisitions/Vendors.pm +++ b/Koha/REST/V1/Acquisitions/Vendors.pm @@ -85,14 +85,27 @@ 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 { $c->unhandled_exception($_); diff --git a/acqui/booksellers.pl b/acqui/booksellers.pl index bc6b3daed99..12c28a7a38e 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 c26cfead33c..d03006b8e6d 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 28e3b97f865..26f655b95a2 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 @@