From 1b4b78a136c769075f6ce796cbd763de7feb95c6 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 25 Jul 2012 10:25:16 +0200 Subject: [PATCH] Bug 5356: delivery place and billing place centralised in basket management - adding 2 select option in basdketheader.tmpl (delivery and billing place) - adding 2 more fields in basket csv export Signed-off-by: Katrin Fischer Tested together with patches for bug 7302. --- C4/Acquisition.pm | 31 ++++++++----- acqui/basket.pl | 13 ++++++ acqui/basketgroup.pl | 29 +++--------- acqui/basketheader.pl | 45 ++++++++++++++++--- installer/data/mysql/kohastructure.sql | 2 + installer/data/mysql/updatedatabase.pl | 8 ++++ .../prog/en/modules/acqui/basket.tt | 6 +++ .../prog/en/modules/acqui/basketgroup.tt | 1 + .../prog/en/modules/acqui/basketheader.tt | 22 +++++++++ 9 files changed, 117 insertions(+), 40 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index 05cae14b3a..42b52ba625 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -173,7 +173,7 @@ sub GetBasket { =head3 NewBasket $basket = &NewBasket( $booksellerid, $authorizedby, $basketname, - $basketnote, $basketbooksellernote, $basketcontractnumber ); + $basketnote, $basketbooksellernote, $basketcontractnumber, $deliveryplace, $billingplace ); Create a new basket in aqbasket table @@ -189,10 +189,8 @@ The other parameters are optional, see ModBasketHeader for more info on them. =cut -# FIXME : this function seems to be unused. - sub NewBasket { - my ( $booksellerid, $authorisedby, $basketname, $basketnote, $basketbooksellernote, $basketcontractnumber ) = @_; + my ( $booksellerid, $authorisedby, $basketname, $basketnote, $basketbooksellernote, $basketcontractnumber, $deliveryplace, $billingplace ) = @_; my $dbh = C4::Context->dbh; my $query = " INSERT INTO aqbasket @@ -203,7 +201,7 @@ sub NewBasket { $dbh->do($query); #find & return basketno MYSQL dependant, but $dbh->last_insert_id always returns null :-( my $basket = $dbh->{'mysql_insertid'}; - ModBasketHeader($basket, $basketname || '', $basketnote || '', $basketbooksellernote || '', $basketcontractnumber || undef, $booksellerid); + ModBasketHeader($basket, $basketname || '', $basketnote || '', $basketbooksellernote || '', $basketcontractnumber || undef, $booksellerid, $deliveryplace || undef, $billingplace || undef ); return $basket; } @@ -265,8 +263,8 @@ sub GetBasketAsCSV { notes => $order->{'notes'}, quantity => $order->{'quantity'}, rrp => $order->{'rrp'}, - deliveryplace => $basket->{'deliveryplace'}, - billingplace => $basket->{'billingplace'} + deliveryplace => C4::Branch::GetBranchName( $basket->{'deliveryplace'} ), + billingplace => C4::Branch::GetBranchName( $basket->{'billingplace'} ), }; foreach(qw( contractname author title publishercode collectiontitle notes @@ -315,6 +313,7 @@ sub GetBasketGroupAsCSV { my @orders = GetOrders( $$basket{basketno} ); my $contract = GetContract( $$basket{contractnumber} ); my $bookseller = GetBookSellerFromId( $$basket{booksellerid} ); + my $basketgroup = GetBasketgroup( $$basket{basketgroupid} ); foreach my $order (@orders) { my $bd = GetBiblioData( $order->{'biblionumber'} ); @@ -339,6 +338,10 @@ sub GetBasketGroupAsCSV { booksellerpostal => $bookseller->{postal}, contractnumber => $contract->{contractnumber}, contractname => $contract->{contractname}, + basketgroupdeliveryplace => C4::Branch::GetBranchName( $basketgroup->{deliveryplace} ) || C4::Branch::GetBranchName( $basketgroup->{freedeliveryplace} ), + basketgroupbillingplace => C4::Branch::GetBranchName( $basketgroup->{billingplace} ), + basketdeliveryplace => C4::Branch::GetBranchName( $basket->{deliveryplace} ), + basketbillingplace => C4::Branch::GetBranchName( $basket->{billingplace} ), }; foreach(qw( basketname author title publishercode collectiontitle notes @@ -486,17 +489,25 @@ Modifies a basket's header. =item C<$booksellerid> is the id (foreign) key in the "aqbooksellers" table for the vendor. +=item C<$deliveryplace> is the "deliveryplace" field in the aqbasket table. + +=item C<$billingplace> is the "billingplace" field in the aqbasket table. + =back =cut sub ModBasketHeader { - my ($basketno, $basketname, $note, $booksellernote, $contractnumber, $booksellerid) = @_; + my ($basketno, $basketname, $note, $booksellernote, $contractnumber, $booksellerid, $deliveryplace, $billingplace) = @_; + my $query = qq{ + UPDATE aqbasket + SET basketname=?, note=?, booksellernote=?, booksellerid=?, deliveryplace=?, billingplace=? + WHERE basketno=? + }; - my $query = "UPDATE aqbasket SET basketname=?, note=?, booksellernote=?, booksellerid=? WHERE basketno=?"; my $dbh = C4::Context->dbh; my $sth = $dbh->prepare($query); - $sth->execute($basketname,$note,$booksellernote,$booksellerid,$basketno); + $sth->execute($basketname, $note, $booksellernote, $booksellerid, $deliveryplace, $billingplace, $basketno); if ( $contractnumber ) { my $query2 ="UPDATE aqbasket SET contractnumber=? WHERE basketno=?"; diff --git a/acqui/basket.pl b/acqui/basket.pl index 4b7566b934..ace6b63a06 100755 --- a/acqui/basket.pl +++ b/acqui/basket.pl @@ -130,6 +130,8 @@ if ( $op eq 'delete_confirm' ) { authorisedby => $basket->{authorisedby}, authorisedbyname => $basket->{authorisedbyname}, closedate => $basket->{closedate}, + deliveryplace => $basket->{deliveryplace}, + billingplace => $basket->{billingplace}, active => $bookseller->{'active'}, booksellerid => $bookseller->{'id'}, name => $bookseller->{'name'}, @@ -283,6 +285,15 @@ if ( $op eq 'delete_confirm' ) { my $contract = &GetContract($basket->{contractnumber}); my @orders = GetOrders($basketno); + if ($basket->{basketgroupid}){ + my $basketgroup = GetBasketgroup($basket->{basketgroupid}); + for my $key (keys %$basketgroup ){ + $basketgroup->{"basketgroup$key"} = delete $basketgroup->{$key}; + } + $basketgroup->{basketgroupdeliveryplace} = C4::Branch::GetBranchName( $basketgroup->{basketgroupdeliveryplace} ); + $basketgroup->{basketgroupbillingplace} = C4::Branch::GetBranchName( $basketgroup->{basketgroupbillingplace} ); + $template->param(%$basketgroup); + } my $borrower= GetMember('borrowernumber' => $loggedinuser); my $budgets = GetBudgetHierarchy; my $has_budgets = 0; @@ -313,6 +324,8 @@ if ( $op eq 'delete_confirm' ) { authorisedbyname => $basket->{authorisedbyname}, closedate => $basket->{closedate}, estimateddeliverydate=> $estimateddeliverydate, + deliveryplace => C4::Branch::GetBranchName( $basket->{deliveryplace} ), + billingplace => C4::Branch::GetBranchName( $basket->{billingplace} ), active => $bookseller->{'active'}, booksellerid => $bookseller->{'id'}, name => $bookseller->{'name'}, diff --git a/acqui/basketgroup.pl b/acqui/basketgroup.pl index ac0672c69f..6b7e5bf192 100755 --- a/acqui/basketgroup.pl +++ b/acqui/basketgroup.pl @@ -328,30 +328,11 @@ if ( $op eq "add" ) { my $borrower = GetMember( ( 'borrowernumber' => $loggedinuser ) ); $billingplace = $billingplace || $borrower->{'branchcode'}; $deliveryplace = $deliveryplace || $borrower->{'branchcode'}; - - my $branches = GetBranches; - - # Build the combobox to select the billing place - my @billingplaceloop; - for (sort keys %$branches) { - push @billingplaceloop, { - value => $_, - selected => $_ eq $billingplace, - branchname => $branches->{$_}->{branchname}, - }; - } - $template->param( billingplaceloop => \@billingplaceloop ); - - # Build the combobox to select the delivery place - my @deliveryplaceloop; - for (sort keys %$branches) { - push @deliveryplaceloop, { - value => $_, - selected => $_ eq $deliveryplace, - branchname => $branches->{$_}->{branchname}, - }; - } - $template->param( deliveryplaceloop => \@deliveryplaceloop ); + + my $branches = C4::Branch::GetBranchesLoop( $billingplace ); + $template->param( billingplaceloop => $branches ); + $branches = C4::Branch::GetBranchesLoop( $deliveryplace ); + $template->param( deliveryplaceloop => $branches ); $template->param( booksellerid => $booksellerid ); } diff --git a/acqui/basketheader.pl b/acqui/basketheader.pl index 08b38eb6f2..8f75f4097f 100755 --- a/acqui/basketheader.pl +++ b/acqui/basketheader.pl @@ -50,6 +50,7 @@ use warnings; use CGI; use C4::Context; use C4::Auth; +use C4::Branch; use C4::Output; use C4::Acquisition qw/GetBasket NewBasket GetContracts ModBasketHeader/; use C4::Bookseller qw/GetBookSellerFromId GetBookSeller/; @@ -70,6 +71,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( #parameters: my $booksellerid = $input->param('booksellerid'); my $basketno = $input->param('basketno'); +my $branches = GetBranches; my $basket; my $op = $input ->param('op'); my $is_an_edit= $input ->param('is_an_edit'); @@ -100,7 +102,7 @@ if ( $op eq 'add_form' ) { $template->param(contractloop => \@contractloop, basketcontractnumber => $basket->{'contractnumber'}); } - my @booksellers = GetBookSeller(); + my @booksellers = C4::Bookseller::GetBookSeller(); $template->param( add_form => 1, basketname => $basket->{'basketname'}, basketnote => $basket->{'note'}, @@ -109,16 +111,47 @@ if ( $op eq 'add_form' ) { booksellerid => $booksellerid, basketno => $basketno, booksellers => \@booksellers, - ); + deliveryplace => $basket->{deliveryplace}, + billingplace => $basket->{billingplace}, + ); + + my $billingplace = $basket->{'billingplace'} || C4::Context->userenv->{"branch"}; + my $deliveryplace = $basket->{'deliveryplace'} || C4::Context->userenv->{"branch"}; + + # Build the combobox to select the billing place + my @billingplaceloop; + + my $branches = C4::Branch::GetBranchesLoop( $billingplace ); + $template->param( billingplaceloop => $branches ); + $branches = C4::Branch::GetBranchesLoop( $deliveryplace ); + $template->param( deliveryplaceloop => $branches ); + #End Edit } elsif ( $op eq 'add_validate' ) { #we are confirming the changes, save the basket - my $basketno; if ( $is_an_edit ) { - $basketno = $input->param('basketno'); - ModBasketHeader( $input->param('basketno'), $input->param('basketname'), $input->param('basketnote'), $input->param('basketbooksellernote'), $input->param('basketcontractnumber') || undef, $input->param('basketbooksellerid') ); + ModBasketHeader( + $basketno, + $input->param('basketname'), + $input->param('basketnote'), + $input->param('basketbooksellernote'), + $input->param('basketcontractnumber') || undef, + $input->param('basketbooksellerid'), + $input->param('deliveryplace'), + $input->param('billingplace'), + ); } else { #New basket - $basketno = NewBasket($booksellerid, $loggedinuser, $input->param('basketname'), $input->param('basketnote'), $input->param('basketbooksellernote'), $input->param('basketcontractnumber')); + $basketno = NewBasket( + $booksellerid, + $loggedinuser, + $input->param('basketname'), + $input->param('basketnote'), + $input->param('basketbooksellernote'), + $input->param('basketcontractnumber') || undef, + undef, + $input->param('deliveryplace'), + $input->param('billingplace'), + ); } print $input->redirect('basket.pl?basketno='.$basketno); exit 0; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 4f7058776a..39857b7969 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -2594,6 +2594,8 @@ CREATE TABLE `aqbasket` ( -- stores data about baskets in acquisitions `authorisedby` varchar(10) default NULL, -- the borrowernumber of the person who created the basket `booksellerinvoicenumber` mediumtext, -- appears to always be NULL `basketgroupid` int(11), -- links this basket to its group (aqbasketgroups.id) + `deliveryplace` varchar(10) default NULL, -- basket delivery place + `billingplace` varchar(10) default NULL, -- basket billing place PRIMARY KEY (`basketno`), KEY `booksellerid` (`booksellerid`), KEY `basketgroupid` (`basketgroupid`), diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 4d47a5929e..9444577f34 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -5974,6 +5974,14 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { } +$DBversion = "3.09.00.XXX"; +if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { + $dbh->do("ALTER TABLE aqbasket ADD deliveryplace VARCHAR(10) default NULL AFTER basketgroupid;"); + $dbh->do("ALTER TABLE aqbasket ADD billingplace VARCHAR(10) default NULL AFTER deliveryplace;"); + print "Upgrade to $DBversion done (Added billingplace, deliveryplace to the aqbasket table)\n"; + SetVersion($DBversion); +} + =head1 FUNCTIONS =head2 TableExists($table) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt index ca92fac672..bd9d145af4 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt @@ -175,11 +175,13 @@ // YUI Toolbar Functions function yuiToolbar() { new YAHOO.widget.Button("reopenbutton"); + new YAHOO.widget.Button("exportbutton"); } //]]> [% END %] @@ -218,6 +220,8 @@ [% IF ( basketcontractno ) %]
  • Contract name: [% basketcontractname %]
  • [% END %] + [% IF ( deliveryplace ) %]
  • Delivery place: [% deliveryplace %]
  • [% END %] + [% IF ( billingplace ) %]
  • Billing place: [% billingplace %]
  • [% END %] [% IF ( authorisedbyname ) %]
  • Managed by: [% authorisedbyname %]
  • [% END %] [% IF ( creationdate ) %]
  • Opened on: [% creationdate | $KohaDates %]
  • [% END %] [% IF ( closedate ) %]
  • Closed on: [% closedate | $KohaDates %]
  • [% END %] @@ -247,6 +251,8 @@

    + [% IF ( basketgroupdeliveryplace ) %]

    Basketgroup Delivery place: [% basketgroupdeliveryplace %]

    [% END %] + [% IF ( basketgroupbillingplace ) %]

    Basketgroup Billing place: [% basketgroupbillingplace %]

    [% END %] [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basketgroup.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basketgroup.tt index d02202cfeb..65d3e6e086 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basketgroup.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basketgroup.tt @@ -203,6 +203,7 @@ function yuiToolbar() {
  • +
  • +
  • + + +
  • +
  • + +
  •   -- 2.39.5