From a5508eb0b4045517248a8fb2e2eb89de2ffedabb Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 25 Jul 2012 10:25:16 +0200 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 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 | 3 + installer/data/mysql/updatedatabase.pl | 9 ++++ .../intranet-tmpl/prog/en/modules/acqui/basket.tt | 6 +++ .../prog/en/modules/acqui/basketgroup.tt | 1 + .../prog/en/modules/acqui/basketheader.tt | 22 ++++++++++ 9 files changed, 119 insertions(+), 40 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index 9678ffc..3f05b24 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -165,7 +165,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 @@ -181,10 +181,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 @@ -195,7 +193,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; } @@ -257,8 +255,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 @@ -307,6 +305,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'} ); @@ -331,6 +330,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 @@ -478,17 +481,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 9b36c14..48b9e5f 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'}, @@ -357,6 +359,15 @@ 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}; + } + $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; @@ -387,6 +398,8 @@ my $total_est_gste; authorisedbyname => $basket->{authorisedbyname}, closedate => $basket->{closedate}, estimateddeliverydate=> $estimateddeliverydate, + deliveryplace => C4::Branch::GetBranchName( $basket->{deliveryplace} ) || C4::Branch::GetBranchName( $basket->{freedeliveryplace} ), + 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 ac0672c..6b7e5bf 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 08b38eb..8f75f40 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 fc9c5f0..03bc390 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -2567,6 +2567,9 @@ 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 + `freedeliveryplace` VARCHAR(10) default NULL, -- basket freedelivery 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 dbceb8d..710f9c0 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -5556,6 +5556,15 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { SetVersion($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;"); + $dbh->do("ALTER TABLE aqbasket ADD freedeliveryplace VARCHAR(10) default NULL AFTER billingplace;"); + print "Upgrade to $DBversion done (Added billingplace, deliveryplace and freedeliveryplaceto 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..0ff9be0 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,13 @@ // YUI Toolbar Functions function yuiToolbar() { new YAHOO.widget.Button("reopenbutton"); + new YAHOO.widget.Button("exportbutton"); } //]]> [% END %] @@ -192,6 +194,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 %] @@ -221,6 +225,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 d02202c..65d3e6e 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() {
  • +
  • + + +
  • +
  • + + +
  •