From ddfe6c831b1930e027665cd43bcbeefaffac6873 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 | 68 +++++++++------- acqui/basket.pl | 12 +++- acqui/basketheader.pl | 86 ++++++++++++++++++-- installer/data/mysql/kohastructure.sql | 3 + installer/data/mysql/updatedatabase.pl | 10 +++ .../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, 170 insertions(+), 40 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index 15a68ea..68c6aeb 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -42,7 +42,7 @@ BEGIN { @ISA = qw(Exporter); @EXPORT = qw( &GetBasket &NewBasket &CloseBasket &DelBasket &ModBasket - &GetBasketAsCSV + &GetBasketAsCSV &GetBasketsByBookseller &GetBasketsByBasketgroup &ModBasketHeader @@ -181,7 +181,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 @@ -192,7 +192,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; } @@ -239,38 +239,38 @@ sub GetBasketAsCSV { # TODO: Translate headers my @headers = qw(contractname ordernumber entrydate isbn author title publishercode collectiontitle notes quantity rrp); - $csv->combine(@headers); - $output = $csv->string() . "\n"; + $csv->combine(@headers); + $output = $csv->string() . "\n"; my @rows; foreach my $order (@orders) { - my @cols; - # newlines are not valid characters for Text::CSV combine() + my @cols; + # newlines are not valid characters for Text::CSV combine() $order->{'notes'} =~ s/[\r\n]+//g; - push(@cols, - $contract->{'contractname'}, - $order->{'ordernumber'}, - $order->{'entrydate'}, - $order->{'isbn'}, - $order->{'author'}, - $order->{'title'}, - $order->{'publishercode'}, - $order->{'collectiontitle'}, - $order->{'notes'}, - $order->{'quantity'}, - $order->{'rrp'}, - ); - push (@rows, \@cols); + push(@cols, + $contract->{'contractname'}, + $order->{'ordernumber'}, + $order->{'entrydate'}, + $order->{'isbn'}, + $order->{'author'}, + $order->{'title'}, + $order->{'publishercode'}, + $order->{'collectiontitle'}, + $order->{'notes'}, + $order->{'quantity'}, + $order->{'rrp'}, + $basket->{'deliveryplace'}, + $basket->{'billingplace'}, + ); + push (@rows, \@cols); } foreach my $row (@rows) { - $csv->combine(@$row); - $output .= $csv->string() . "\n"; - + $csv->combine(@$row); + $output .= $csv->string() . "\n"; } - - return $output; + return $output; } @@ -384,7 +384,7 @@ sub ModBasket { =head3 ModBasketHeader - &ModBasketHeader($basketno, $basketname, $note, $booksellernote, $contractnumber); + &ModBasketHeader($basketno, $basketname, $note, $booksellernote, $contractnumber, $deliveryplace, $billingplace); Modifies a basket's header. @@ -400,16 +400,24 @@ Modifies a basket's header. =item C<$contractnumber> is the "contractnumber" (foreign) key in the "aqbasket" table. +=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) = @_; - my $query = "UPDATE aqbasket SET basketname=?, note=?, booksellernote=? WHERE basketno=?"; + my ($basketno, $basketname, $note, $booksellernote, $contractnumber, $deliveryplace, $billingplace) = @_; + my $query = qq{ + UPDATE aqbasket + SET basketname=?, note=?, booksellernote=?, deliveryplace=?, billingplace=? + WHERE basketno=? + }; my $dbh = C4::Context->dbh; my $sth = $dbh->prepare($query); - $sth->execute($basketname,$note,$booksellernote,$basketno); + $sth->execute($basketname, $note, $booksellernote, $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 7864fee..ddca25c 100755 --- a/acqui/basket.pl +++ b/acqui/basket.pl @@ -129,6 +129,8 @@ if ( $op eq 'delete_confirm' ) { creationdate => format_date( $basket->{creationdate} ), authorisedby => $basket->{authorisedby}, authorisedbyname => $basket->{authorisedbyname}, + deliveryplace => $basket->{deliveryplace} || $basket->{freedeliveryplace}, + billingplace => $basket->{billingplace}, closedate => format_date( $basket->{closedate} ), active => $bookseller->{'active'}, booksellerid => $bookseller->{'id'}, @@ -340,7 +342,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; @@ -367,6 +375,8 @@ my $total_est_gste; creationdate => C4::Dates->new($basket->{creationdate},'iso')->output, authorisedby => $basket->{authorisedby}, authorisedbyname => $basket->{authorisedbyname}, + deliveryplace => $basket->{deliveryplace} || $basket->{freedeliveryplace}, + billingplace => $basket->{billingplace}, closedate => C4::Dates->new($basket->{closedate},'iso')->output, active => $bookseller->{'active'}, booksellerid => $bookseller->{'id'}, diff --git a/acqui/basketheader.pl b/acqui/basketheader.pl index b33e4ef..aa3ed6e 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/; @@ -68,9 +69,9 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( ); #parameters: -my $booksellerid; -$booksellerid = $input->param('booksellerid'); +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'); @@ -107,17 +108,86 @@ if ( $op eq 'add_form' ) { basketbooksellernote => $basket->{'booksellernote'}, booksellername => $bookseller->{'name'}, booksellerid => $booksellerid, - basketno => $basketno - ); + basketno => $basketno, + 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')); + ModBasketHeader( + $basketno, + $input->param('basketname'), + $input->param('basketnote'), + $input->param('basketbooksellernote'), + $input->param('basketcontractnumber'), + $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'), + $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 e0ce034..f660a5a 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -2525,6 +2525,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 a2335af..3be112f 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -4960,6 +4960,16 @@ 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 DropAllForeignKeys($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 bad45e0..7f7236d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt @@ -134,11 +134,14 @@ // YUI Toolbar Functions function yuiToolbar() { new YAHOO.widget.Button("reopenbutton"); + new YAHOO.widget.Button("exportbutton"); } //]]> [% END %] @@ -177,6 +180,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 %]
  • [% END %] [% IF ( closedate ) %]
  • Closed on: [% closedate %]
  • [% END %] @@ -203,8 +208,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 c651e00..0e5d99f 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() {
  • +
  • + + +
  • +
  • + + +
  •   -- 1.7.7.3