From 5fc0502c940072d5b895193d3d451ed994742cce Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 2 Mar 2012 10:39:54 +0100 Subject: [PATCH 1/1] 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 --- C4/Acquisition.pm | 22 ++++-- acqui/basket.pl | 12 +++- acqui/basketheader.pl | 83 ++++++++++++++++++- installer/data/mysql/kohastructure.sql | 3 + installer/data/mysql/updatedatabase.pl | 12 +++ .../intranet-tmpl/prog/en/modules/acqui/basket.tt | 8 ++- .../prog/en/modules/acqui/basketgroup.tt | 1 + .../prog/en/modules/acqui/basketheader.tt | 22 +++++ 8 files changed, 148 insertions(+), 15 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index 0f02639..890ff64 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -184,7 +184,7 @@ The other parameters are optional, see ModBasketHeader for more info on them. # 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 @@ -195,7 +195,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); + ModBasketHeader( $basket, $basketname || '', $basketnote || '', $basketbooksellernote || '', $basketcontractnumber || undef, $deliveryplace || undef, $billingplace || undef ); return $basket; } @@ -460,7 +460,7 @@ sub ModBasket { =head3 ModBasketHeader - &ModBasketHeader($basketno, $basketname, $note, $booksellernote, $contractnumber, $booksellerid); + &ModBasketHeader($basketno, $basketname, $note, $booksellernote, $contractnumber, $booksellerid, $deliveryplace, $billingplace); Modifies a basket's header. @@ -478,18 +478,24 @@ 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 $query = "UPDATE aqbasket SET basketname=?, note=?, booksellernote=?, booksellerid=? WHERE basketno=?"; + my ($basketno, $basketname, $note, $booksellernote, $contractnumber, $booksellerid, $deliveryplace, $billingplace) = @_; + my $query = qq{ + UPDATE aqbasket + SET basketname=?, note=?, booksellernote=?, booksellerid=?, deliveryplace=?, billingplace=? + 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=?"; my $sth2 = $dbh->prepare($query2); diff --git a/acqui/basket.pl b/acqui/basket.pl index 4e676d6..ebe965e 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} || $basket->{freedeliveryplace}, + billingplace => $basket->{billingplace}, active => $bookseller->{'active'}, booksellerid => $bookseller->{'id'}, name => $bookseller->{'name'}, @@ -356,7 +358,13 @@ my $total_est_gste; 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}; + } + $template->param(%$basketgroup); + } my $borrower= GetMember('borrowernumber' => $loggedinuser); my $budgets = GetBudgetHierarchy(q{},$borrower->{branchcode},$borrower->{borrowernumber}); my $has_budgets = 0; @@ -385,6 +393,8 @@ my $total_est_gste; authorisedbyname => $basket->{authorisedbyname}, closedate => $basket->{closedate}, estimateddeliverydate=> $estimateddeliverydate, + deliveryplace => $basket->{deliveryplace} || $basket->{freedeliveryplace}, + billingplace => $basket->{billingplace}, active => $bookseller->{'active'}, booksellerid => $bookseller->{'id'}, name => $bookseller->{'name'}, diff --git a/acqui/basketheader.pl b/acqui/basketheader.pl index 08b38eb..3997811 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'); @@ -109,16 +111,87 @@ 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; + + # In case there's no branch selected + if ($billingplace eq "NO_LIBRARY_SET") { + my %row = ( + value => "", + selected => 1, + branchname => "--", + ); + push @billingplaceloop, \%row; + } + + for ( sort keys %$branches ) { + my $selected = 1 if $_ eq $billingplace; + my %row = ( + value => $_, + selected => $selected, + branchname => $branches->{$_}->{branchname}, + ); + push @billingplaceloop, \%row; + } + $template->param( billingplaceloop => \@billingplaceloop ); + + # Build the combobox to select the delivery place + my @deliveryplaceloop; + + # In case there's no branch selected + if ($deliveryplace eq "NO_LIBRARY_SET") { + my %row = ( + value => "", + selected => 1, + branchname => "--", + ); + push @deliveryplaceloop, \%row; + } + + for ( sort keys %$branches ) { + my $selected = 1 if $_ eq $deliveryplace; + my %row = ( + value => $_, + selected => $selected, + branchname => $branches->{$_}->{branchname}, + ); + push @deliveryplaceloop, \%row; + } + $template->param( deliveryplaceloop => \@deliveryplaceloop ); + #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 54498c3..22528a4 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -2563,6 +2563,9 @@ CREATE TABLE `aqbasket` ( `authorisedby` varchar(10) default NULL, `booksellerinvoicenumber` mediumtext, `basketgroupid` int(11), + deliveryplace varchar(10) default NULL, + billingplace varchar(10) default NULL, + freedeliveryplace VARCHAR(10) default NULL, PRIMARY KEY (`basketno`), KEY `booksellerid` (`booksellerid`), KEY `basketgroupid` (`basketgroupid`), diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 62b4372..1c1621c 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -5343,6 +5343,18 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { SetVersion($DBversion); } + + + +$DBversion = "3.07.00.XXX"; +if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { + $dbh->do("ALTER TABLE aqbasket ADD deliveryplace VARCHAR(10) default NULL;"); + $dbh->do("ALTER TABLE aqbasket ADD billingplace VARCHAR(10) default NULL;"); + $dbh->do("ALTER TABLE aqbasket ADD freedeliveryplace VARCHAR(10) default NULL;"); + print "Upgrade to $DBversion done (Added billingplace and deliveryplace to aqbasket)\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 dcd6ccb..f6bfb96 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt @@ -149,11 +149,14 @@ // YUI Toolbar Functions function yuiToolbar() { new YAHOO.widget.Button("reopenbutton"); + new YAHOO.widget.Button("exportbutton"); } //]]> [% END %] @@ -192,6 +195,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 %] @@ -219,8 +224,9 @@

    - + [% 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 df33b1b..9e23ca7 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basketgroup.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basketgroup.tt @@ -189,6 +189,7 @@ function yuiToolbar() {
  • +
  • + + +
  • +
  • + + +
  •