# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
-# You should have received a copy of the GNU General Public License along with
-# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
-# Suite 330, Boston, MA 02111-1307 USA
+# You should have received a copy of the GNU General Public License along
+# with Koha; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
use strict;
use C4::Dates qw(format_date format_date_in_iso);
use MARC::Record;
use C4::Suggestions;
+use C4::Biblio;
use C4::Debug;
use C4::SQLHelper qw(InsertInTable);
@ISA = qw(Exporter);
@EXPORT = qw(
&GetBasket &NewBasket &CloseBasket &DelBasket &ModBasket
+ &GetBasketAsCSV
&GetBasketsByBookseller &GetBasketsByBasketgroup
-
- &ModBasketHeader
+
+ &ModBasketHeader
&ModBasketgroup &NewBasketgroup &DelBasketgroup &GetBasketgroup &CloseBasketgroup
&GetBasketgroups &ReOpenBasketgroup
&NewOrder &DelOrder &ModOrder &GetPendingOrders &GetOrder &GetOrders
&GetOrderNumber &GetLateOrders &GetOrderFromItemnumber
&SearchOrder &GetHistory &GetRecentAcqui
- &ModReceiveOrder &ModOrderBiblioitemNumber
+ &ModReceiveOrder &ModOrderBiblioitemNumber
&NewOrderItem &ModOrderItem
my $sth = $dbh->prepare($query);
- $sth->trace(3);
+# $sth->trace(3);
$sth->execute($itemnumber);
}
-# Returns the itemnumber(s) associated with the ordernumber given in parameter
+# Returns the itemnumber(s) associated with the ordernumber given in parameter
sub GetItemnumbersFromOrder {
my ($ordernumber) = @_;
my $dbh = C4::Context->dbh;
my @tab;
while (my $order = $sth->fetchrow_hashref) {
- push @tab, $order->{'itemnumber'};
+ push @tab, $order->{'itemnumber'};
}
return @tab;
$basket = &NewBasket( $booksellerid, $authorizedby, $basketname, $basketnote, $basketbooksellernote, $basketcontractnumber );
+=back
+
Create a new basket in aqbasket table
+=over 2
+
=item C<$booksellerid> is a foreign key in the aqbasket table
=item C<$authorizedby> is the username of who created the basket
-The other parameters are optional, see ModBasketHeader for more info on them.
-
=back
+The other parameters are optional, see ModBasketHeader for more info on them.
+
=cut
# FIXME : this function seems to be unused.
#------------------------------------------------------------#
+=head3 GetBasketAsCSV
+
+=over 4
+
+&GetBasketAsCSV($basketno);
+
+Export a basket as CSV
+
+=back
+
+=cut
+sub GetBasketAsCSV {
+ my ($basketno) = @_;
+ my $basket = GetBasket($basketno);
+ my @orders = GetOrders($basketno);
+ my $contract = GetContract($basket->{'contractnumber'});
+ my $csv = Text::CSV->new();
+ my $output;
+
+ # TODO: Translate headers
+ my @headers = qw(contractname ordernumber line entrydate isbn author title publishercode collectiontitle notes quantity rrp);
+
+ $csv->combine(@headers);
+ $output = $csv->string() . "\n";
+
+ my @rows;
+ foreach my $order (@orders) {
+ my @cols;
+ my $bd = GetBiblioData($order->{'biblionumber'});
+ push(@cols,
+ $contract->{'contractname'},
+ $order->{'ordernumber'},
+ $order->{'entrydate'},
+ $order->{'isbn'},
+ $bd->{'author'},
+ $bd->{'title'},
+ $bd->{'publishercode'},
+ $bd->{'collectiontitle'},
+ $order->{'notes'},
+ $order->{'quantity'},
+ $order->{'rrp'},
+ );
+ push (@rows, \@cols);
+ }
+
+ # Sort by publishercode
+ # TODO: Sort by publishercode then by title
+ @rows = sort { @$a[7] cmp @$b[7] } @rows;
+
+ foreach my $row (@rows) {
+ $csv->combine(@$row);
+ $output .= $csv->string() . "\n";
+
+ }
+
+ return $output;
+
+}
+
+
=head3 CloseBasketgroup
=over 4
push(@params, $basketgroupinfo->{'id'});
my $sth = $dbh->prepare($query);
$sth->execute(@params);
-
+
$sth = $dbh->prepare('UPDATE aqbasket SET basketgroupid = NULL WHERE basketgroupid = ?');
$sth->execute($basketgroupinfo->{'id'});
-
+
if($basketgroupinfo->{'basketlist'} && @{$basketgroupinfo->{'basketlist'}}){
$sth = $dbh->prepare("UPDATE aqbasket SET basketgroupid=? WHERE basketno=?");
foreach my $basketno (@{$basketgroupinfo->{'basketlist'}}) {
DelBasketgroup($basketgroupid);
-=over 2
+=back
Deletes a basketgroup in the aqbasketgroups table, and removes the reference to it from the baskets,
-=item C<$basketgroupid> is the 'id' field of the basket in the aqbasketgroup table
+=over 2
-=back
+=item C<$basketgroupid> is the 'id' field of the basket in the aqbasketgroup table
=back
#------------------------------------------------------------#
-=back
=head2 FUNCTIONS ABOUT ORDERS
=cut
+=back
+
=head3 GetBasketgroup
=over 4
#------------------------------------------------------------#
-=back
-
=head2 FUNCTIONS ABOUT ORDERS
-=over 2
-
=cut
#------------------------------------------------------------#
=item $hashref->{'basketno'} is the basketno foreign key in aqorders, it is mandatory
-=item $hashref->{'ordernumber'} is a "minimum order number."
+=item $hashref->{'ordernumber'} is a "minimum order number."
=item $hashref->{'budgetdate'} is effectively ignored.
If it's undef (anything false) or the string 'now', the current day is used.
die "Mandatory parameter $key missing" unless $orderinfo->{$key};
}
- if ( $orderinfo->{'subscription'} eq 'yes' ) {
+ if ( defined $orderinfo->{subscription} && $orderinfo->{'subscription'} eq 'yes' ) {
$orderinfo->{'subscription'} = 1;
} else {
$orderinfo->{'subscription'} = 0;
}
$orderinfo->{'entrydate'} ||= C4::Dates->new()->output("iso");
+ if (!$orderinfo->{quantityreceived}) {
+ $orderinfo->{quantityreceived} = 0;
+ }
my $ordernumber=InsertInTable("aqorders",$orderinfo);
return ( $orderinfo->{'basketno'}, $ordernumber );
$datereceived = C4::Dates->output('iso') unless $datereceived;
my $suggestionid = GetSuggestionFromBiblionumber( $dbh, $biblionumber );
if ($suggestionid) {
- ModStatus( $suggestionid, 'AVAILABLE', '', $biblionumber );
+ ModSuggestion( {suggestionid=>$suggestionid,
+ STATUS=>'AVAILABLE',
+ biblionumber=> $biblionumber}
+ );
}
my $sth=$dbh->prepare("
- SELECT * FROM aqorders
+ SELECT * FROM aqorders
WHERE biblionumber=? AND aqorders.ordernumber=?");
$sth->execute($biblionumber,$ordernumber);
, unitprice=?
, freight=?
, rrp=?
- , quantityreceived=?
+ , quantity=?
WHERE biblionumber=? AND ordernumber=?");
$sth->execute($quantrec,$datereceived,$invoiceno,$cost,$freight,$rrp,$quantrec,$biblionumber,$ordernumber);
foreach my $orderkey ( "linenumber", "allocation" ) {
delete($order->{'$orderkey'});
}
+ $order->{'quantity'} -= $quantrec;
+ $order->{'quantityreceived'} = 0;
my $newOrder = NewOrder($order);
} else {
$sth=$dbh->prepare("update aqorders
LEFT JOIN biblioitems ON biblioitems.biblionumber=biblio.biblionumber
LEFT JOIN aqbasket ON aqorders.basketno = aqbasket.basketno
WHERE (datecancellationprinted is NULL)";
-
+
if($ordernumber){
$query .= " AND (aqorders.ordernumber=?)";
push @args, $ordernumber;
biblioitems.publicationyear,
";
my $from = "
- FROM (((
- (aqorders LEFT JOIN biblio ON biblio.biblionumber = aqorders.biblionumber)
- LEFT JOIN biblioitems ON biblioitems.biblionumber = biblio.biblionumber)
- LEFT JOIN aqbudgets ON aqorders.budget_id = aqbudgets.budget_id),
- (aqbasket LEFT JOIN borrowers ON aqbasket.authorisedby = borrowers.borrowernumber)
- LEFT JOIN aqbooksellers ON aqbasket.booksellerid = aqbooksellers.id
+ FROM
+ aqorders LEFT JOIN biblio ON biblio.biblionumber = aqorders.biblionumber
+ LEFT JOIN biblioitems ON biblioitems.biblionumber = biblio.biblionumber
+ LEFT JOIN aqbudgets ON aqorders.budget_id = aqbudgets.budget_id,
+ aqbasket LEFT JOIN borrowers ON aqbasket.authorisedby = borrowers.borrowernumber
+ LEFT JOIN aqbooksellers ON aqbasket.booksellerid = aqbooksellers.id
WHERE aqorders.basketno = aqbasket.basketno
- AND ( (datereceived = '' OR datereceived IS NULL)
- OR (aqorders.quantityreceived < aqorders.quantity)
+ AND ( datereceived = ''
+ OR datereceived IS NULL
+ OR aqorders.quantityreceived < aqorders.quantity
)
";
my $having = "";
biblio.title,
biblio.author,
aqorders.basketno,
- name,aqbasket.creationdate,
+ aqbasket.basketname,
+ aqbasket.basketgroupid,
+ aqbasketgroups.name as groupname,
+ aqbooksellers.name,
+ aqbasket.creationdate,
aqorders.datereceived,
aqorders.quantity,
aqorders.quantityreceived,
aqorders.biblionumber
FROM aqorders
LEFT JOIN aqbasket ON aqorders.basketno=aqbasket.basketno
+ LEFT JOIN aqbasketgroups ON aqbasket.basketgroupid=aqbasketgroups.id
LEFT JOIN aqbooksellers ON aqbasket.booksellerid=aqbooksellers.id
LEFT JOIN biblio ON biblio.biblionumber=aqorders.biblionumber";
$query .= " LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber"
if ( C4::Context->preference("IndependantBranches") );
-
+
$query .= " WHERE (datecancellationprinted is NULL or datecancellationprinted='0000-00-00') ";
my @query_params = ();
}
if ( defined $name ) {
- $query .= " AND name LIKE ? ";
+ $query .= " AND aqbooksellers.name LIKE ? ";
push @query_params, "%$name%";
}
push @query_params, $userenv->{branch};
}
}
- $query .= " ORDER BY booksellerid";
+ $query .= " ORDER BY id";
+ warn $query;
my $sth = $dbh->prepare($query);
$sth->execute( @query_params );
my $cnt = 1;
$contractlist = &GetContracts($booksellerid, $activeonly);
+=back
+
Looks up the contracts that belong to a bookseller
Returns a list of contracts
+=over 2
+
=item C<$booksellerid> is the "id" field in the "aqbooksellers" table.
=item C<$activeonly> if exists get only contracts that are still active.