Lines 64-69
BEGIN {
Link Here
|
64 |
&GetParcels &GetParcel |
64 |
&GetParcels &GetParcel |
65 |
&GetContracts &GetContract |
65 |
&GetContracts &GetContract |
66 |
|
66 |
|
|
|
67 |
&GetInvoices |
68 |
&GetInvoice |
69 |
&GetInvoiceDetails |
70 |
&AddInvoice |
71 |
&ModInvoice |
72 |
&CloseInvoice |
73 |
&ReopenInvoice |
74 |
|
67 |
&GetItemnumbersFromOrder |
75 |
&GetItemnumbersFromOrder |
68 |
|
76 |
|
69 |
&AddClaim |
77 |
&AddClaim |
Lines 1224-1238
sub GetCancelledOrders {
Link Here
|
1224 |
=head3 ModReceiveOrder |
1232 |
=head3 ModReceiveOrder |
1225 |
|
1233 |
|
1226 |
&ModReceiveOrder($biblionumber, $ordernumber, $quantityreceived, $user, |
1234 |
&ModReceiveOrder($biblionumber, $ordernumber, $quantityreceived, $user, |
1227 |
$unitprice, $booksellerinvoicenumber, $biblioitemnumber, |
1235 |
$unitprice, $invoiceid, $biblioitemnumber, |
1228 |
$freight, $bookfund, $rrp); |
1236 |
$bookfund, $rrp, \@received_itemnumbers); |
1229 |
|
1237 |
|
1230 |
Updates an order, to reflect the fact that it was received, at least |
1238 |
Updates an order, to reflect the fact that it was received, at least |
1231 |
in part. All arguments not mentioned below update the fields with the |
1239 |
in part. All arguments not mentioned below update the fields with the |
1232 |
same name in the aqorders table of the Koha database. |
1240 |
same name in the aqorders table of the Koha database. |
1233 |
|
1241 |
|
1234 |
If a partial order is received, splits the order into two. The received |
1242 |
If a partial order is received, splits the order into two. |
1235 |
portion must have a booksellerinvoicenumber. |
|
|
1236 |
|
1243 |
|
1237 |
Updates the order with bibilionumber C<$biblionumber> and ordernumber |
1244 |
Updates the order with bibilionumber C<$biblionumber> and ordernumber |
1238 |
C<$ordernumber>. |
1245 |
C<$ordernumber>. |
Lines 1243-1249
C<$ordernumber>.
Link Here
|
1243 |
sub ModReceiveOrder { |
1250 |
sub ModReceiveOrder { |
1244 |
my ( |
1251 |
my ( |
1245 |
$biblionumber, $ordernumber, $quantrec, $user, $cost, |
1252 |
$biblionumber, $ordernumber, $quantrec, $user, $cost, |
1246 |
$invoiceno, $freight, $rrp, $budget_id, $datereceived, $received_items |
1253 |
$invoiceid, $rrp, $budget_id, $datereceived, $received_items |
1247 |
) |
1254 |
) |
1248 |
= @_; |
1255 |
= @_; |
1249 |
my $dbh = C4::Context->dbh; |
1256 |
my $dbh = C4::Context->dbh; |
Lines 1269-1282
sub ModReceiveOrder {
Link Here
|
1269 |
UPDATE aqorders |
1276 |
UPDATE aqorders |
1270 |
SET quantityreceived=? |
1277 |
SET quantityreceived=? |
1271 |
, datereceived=? |
1278 |
, datereceived=? |
1272 |
, booksellerinvoicenumber=? |
1279 |
, invoiceid=? |
1273 |
, unitprice=? |
1280 |
, unitprice=? |
1274 |
, freight=? |
|
|
1275 |
, rrp=? |
1281 |
, rrp=? |
1276 |
, quantity=? |
1282 |
, quantity=? |
1277 |
WHERE biblionumber=? AND ordernumber=?"); |
1283 |
WHERE biblionumber=? AND ordernumber=?"); |
1278 |
|
1284 |
|
1279 |
$sth->execute($quantrec,$datereceived,$invoiceno,$cost,$freight,$rrp,$quantrec,$biblionumber,$ordernumber); |
1285 |
$sth->execute($quantrec,$datereceived,$invoiceid,$cost,$rrp,$quantrec,$biblionumber,$ordernumber); |
1280 |
$sth->finish; |
1286 |
$sth->finish; |
1281 |
|
1287 |
|
1282 |
# create a new order for the remaining items, and set its bookfund. |
1288 |
# create a new order for the remaining items, and set its bookfund. |
Lines 1300-1309
sub ModReceiveOrder {
Link Here
|
1300 |
} |
1306 |
} |
1301 |
} else { |
1307 |
} else { |
1302 |
$sth=$dbh->prepare("update aqorders |
1308 |
$sth=$dbh->prepare("update aqorders |
1303 |
set quantityreceived=?,datereceived=?,booksellerinvoicenumber=?, |
1309 |
set quantityreceived=?,datereceived=?,invoiceid=?, |
1304 |
unitprice=?,freight=?,rrp=? |
1310 |
unitprice=?,rrp=? |
1305 |
where biblionumber=? and ordernumber=?"); |
1311 |
where biblionumber=? and ordernumber=?"); |
1306 |
$sth->execute($quantrec,$datereceived,$invoiceno,$cost,$freight,$rrp,$biblionumber,$ordernumber); |
1312 |
$sth->execute($quantrec,$datereceived,$invoiceid,$cost,$rrp,$biblionumber,$ordernumber); |
1307 |
$sth->finish; |
1313 |
$sth->finish; |
1308 |
} |
1314 |
} |
1309 |
return $datereceived; |
1315 |
return $datereceived; |
Lines 1462-1470
sub GetParcel {
Link Here
|
1462 |
LEFT JOIN aqbasket ON aqbasket.basketno=aqorders.basketno |
1468 |
LEFT JOIN aqbasket ON aqbasket.basketno=aqorders.basketno |
1463 |
LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber |
1469 |
LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber |
1464 |
LEFT JOIN biblio ON aqorders.biblionumber=biblio.biblionumber |
1470 |
LEFT JOIN biblio ON aqorders.biblionumber=biblio.biblionumber |
|
|
1471 |
LEFT JOIN aqinvoices ON aqorders.invoiceid = aqinvoices.invoiceid |
1465 |
WHERE |
1472 |
WHERE |
1466 |
aqbasket.booksellerid = ? |
1473 |
aqbasket.booksellerid = ? |
1467 |
AND aqorders.booksellerinvoicenumber LIKE ? |
1474 |
AND aqinvoices.invoicenumber LIKE ? |
1468 |
AND aqorders.datereceived = ? "; |
1475 |
AND aqorders.datereceived = ? "; |
1469 |
|
1476 |
|
1470 |
my @query_params = ( $supplierid, $code, $datereceived ); |
1477 |
my @query_params = ( $supplierid, $code, $datereceived ); |
Lines 1537-1554
sub GetParcels {
Link Here
|
1537 |
my $dbh = C4::Context->dbh; |
1544 |
my $dbh = C4::Context->dbh; |
1538 |
my @query_params = (); |
1545 |
my @query_params = (); |
1539 |
my $strsth =" |
1546 |
my $strsth =" |
1540 |
SELECT aqorders.booksellerinvoicenumber, |
1547 |
SELECT aqinvoices.invoicenumber, |
1541 |
datereceived,purchaseordernumber, |
1548 |
datereceived,purchaseordernumber, |
1542 |
count(DISTINCT biblionumber) AS biblio, |
1549 |
count(DISTINCT biblionumber) AS biblio, |
1543 |
sum(quantity) AS itemsexpected, |
1550 |
sum(quantity) AS itemsexpected, |
1544 |
sum(quantityreceived) AS itemsreceived |
1551 |
sum(quantityreceived) AS itemsreceived |
1545 |
FROM aqorders LEFT JOIN aqbasket ON aqbasket.basketno = aqorders.basketno |
1552 |
FROM aqorders LEFT JOIN aqbasket ON aqbasket.basketno = aqorders.basketno |
|
|
1553 |
LEFT JOIN aqinvoices ON aqorders.invoiceid = aqinvoices.invoiceid |
1546 |
WHERE aqbasket.booksellerid = ? and datereceived IS NOT NULL |
1554 |
WHERE aqbasket.booksellerid = ? and datereceived IS NOT NULL |
1547 |
"; |
1555 |
"; |
1548 |
push @query_params, $bookseller; |
1556 |
push @query_params, $bookseller; |
1549 |
|
1557 |
|
1550 |
if ( defined $code ) { |
1558 |
if ( defined $code ) { |
1551 |
$strsth .= ' and aqorders.booksellerinvoicenumber like ? '; |
1559 |
$strsth .= ' and aqinvoices.invoicenumber like ? '; |
1552 |
# add a % to the end of the code to allow stemming. |
1560 |
# add a % to the end of the code to allow stemming. |
1553 |
push @query_params, "$code%"; |
1561 |
push @query_params, "$code%"; |
1554 |
} |
1562 |
} |
Lines 1563-1569
sub GetParcels {
Link Here
|
1563 |
push @query_params, $dateto; |
1571 |
push @query_params, $dateto; |
1564 |
} |
1572 |
} |
1565 |
|
1573 |
|
1566 |
$strsth .= "group by aqorders.booksellerinvoicenumber,datereceived "; |
1574 |
$strsth .= "group by aqinvoices.invoicenumber,datereceived "; |
1567 |
|
1575 |
|
1568 |
# can't use a placeholder to place this column name. |
1576 |
# can't use a placeholder to place this column name. |
1569 |
# but, we could probably be checking to make sure it is a column that will be fetched. |
1577 |
# but, we could probably be checking to make sure it is a column that will be fetched. |
Lines 1779-1785
sub GetHistory {
Link Here
|
1779 |
aqorders.quantityreceived, |
1787 |
aqorders.quantityreceived, |
1780 |
aqorders.ecost, |
1788 |
aqorders.ecost, |
1781 |
aqorders.ordernumber, |
1789 |
aqorders.ordernumber, |
1782 |
aqorders.booksellerinvoicenumber as invoicenumber, |
1790 |
aqinvoices.invoicenumber, |
1783 |
aqbooksellers.id as id, |
1791 |
aqbooksellers.id as id, |
1784 |
aqorders.biblionumber |
1792 |
aqorders.biblionumber |
1785 |
FROM aqorders |
1793 |
FROM aqorders |
Lines 1787-1793
sub GetHistory {
Link Here
|
1787 |
LEFT JOIN aqbasketgroups ON aqbasket.basketgroupid=aqbasketgroups.id |
1795 |
LEFT JOIN aqbasketgroups ON aqbasket.basketgroupid=aqbasketgroups.id |
1788 |
LEFT JOIN aqbooksellers ON aqbasket.booksellerid=aqbooksellers.id |
1796 |
LEFT JOIN aqbooksellers ON aqbasket.booksellerid=aqbooksellers.id |
1789 |
LEFT JOIN biblioitems ON biblioitems.biblionumber=aqorders.biblionumber |
1797 |
LEFT JOIN biblioitems ON biblioitems.biblionumber=aqorders.biblionumber |
1790 |
LEFT JOIN biblio ON biblio.biblionumber=aqorders.biblionumber"; |
1798 |
LEFT JOIN biblio ON biblio.biblionumber=aqorders.biblionumber |
|
|
1799 |
LEFT JOIN aqinvoices ON aqorders.invoiceid = aqinvoices.invoiceid"; |
1791 |
|
1800 |
|
1792 |
$query .= " LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber" |
1801 |
$query .= " LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber" |
1793 |
if ( C4::Context->preference("IndependantBranches") ); |
1802 |
if ( C4::Context->preference("IndependantBranches") ); |
Lines 1841-1848
sub GetHistory {
Link Here
|
1841 |
} |
1850 |
} |
1842 |
|
1851 |
|
1843 |
if ($booksellerinvoicenumber) { |
1852 |
if ($booksellerinvoicenumber) { |
1844 |
$query .= " AND (aqorders.booksellerinvoicenumber LIKE ? OR aqbasket.booksellerinvoicenumber LIKE ?)"; |
1853 |
$query .= " AND aqinvoices.invoicenumber LIKE ? "; |
1845 |
push @query_params, "%$booksellerinvoicenumber%", "%$booksellerinvoicenumber%"; |
1854 |
push @query_params, "%$booksellerinvoicenumber%"; |
1846 |
} |
1855 |
} |
1847 |
|
1856 |
|
1848 |
if ( C4::Context->preference("IndependantBranches") ) { |
1857 |
if ( C4::Context->preference("IndependantBranches") ) { |
Lines 1983-1989
sub AddClaim {
Link Here
|
1983 |
"; |
1992 |
"; |
1984 |
my $sth = $dbh->prepare($query); |
1993 |
my $sth = $dbh->prepare($query); |
1985 |
$sth->execute($ordernumber); |
1994 |
$sth->execute($ordernumber); |
|
|
1995 |
} |
1996 |
|
1997 |
=head3 GetInvoices |
1998 |
|
1999 |
my @invoices = GetInvoices( |
2000 |
invoicenumber => $invoicenumber, |
2001 |
suppliername => $suppliername, |
2002 |
shipmentdatefrom => $shipmentdatefrom, # ISO format |
2003 |
shipmentdateto => $shipmentdateto, # ISO format |
2004 |
billingdatefrom => $billingdatefrom, # ISO format |
2005 |
billingdateto => $billingdateto, # ISO format |
2006 |
isbneanissn => $isbn_or_ean_or_issn, |
2007 |
title => $title, |
2008 |
author => $author, |
2009 |
publisher => $publisher, |
2010 |
publicationyear => $publicationyear, |
2011 |
branchcode => $branchcode, |
2012 |
order_by => $order_by |
2013 |
); |
2014 |
|
2015 |
Return a list of invoices that match all given criteria. |
2016 |
|
2017 |
$order_by is "column_name (asc|desc)", where column_name is any of |
2018 |
'invoicenumber', 'booksellerid', 'shipmentdate', 'billingdate', 'closedate', |
2019 |
'shipmentcost', 'shipmentcost_budgetid'. |
2020 |
|
2021 |
asc is the default if omitted |
2022 |
|
2023 |
=cut |
2024 |
|
2025 |
sub GetInvoices { |
2026 |
my %args = @_; |
2027 |
|
2028 |
my @columns = qw(invoicenumber booksellerid shipmentdate billingdate |
2029 |
closedate shipmentcost shipmentcost_budgetid); |
2030 |
|
2031 |
my $dbh = C4::Context->dbh; |
2032 |
my $query = qq{ |
2033 |
SELECT aqinvoices.*, aqbooksellers.name AS suppliername, |
2034 |
COUNT( |
2035 |
DISTINCT IF( |
2036 |
aqorders.datereceived IS NOT NULL, |
2037 |
aqorders.biblionumber, |
2038 |
NULL |
2039 |
) |
2040 |
) AS receivedbiblios, |
2041 |
SUM(aqorders.quantityreceived) AS receiveditems |
2042 |
FROM aqinvoices |
2043 |
LEFT JOIN aqbooksellers ON aqbooksellers.id = aqinvoices.booksellerid |
2044 |
LEFT JOIN aqorders ON aqorders.invoiceid = aqinvoices.invoiceid |
2045 |
LEFT JOIN biblio ON aqorders.biblionumber = biblio.biblionumber |
2046 |
LEFT JOIN biblioitems ON biblio.biblionumber = biblioitems.biblionumber |
2047 |
LEFT JOIN subscription ON biblio.biblionumber = subscription.biblionumber |
2048 |
}; |
2049 |
|
2050 |
my @bind_args; |
2051 |
my @bind_strs; |
2052 |
if($args{supplierid}) { |
2053 |
push @bind_strs, " aqinvoices.booksellerid = ? "; |
2054 |
push @bind_args, $args{supplierid}; |
2055 |
} |
2056 |
if($args{invoicenumber}) { |
2057 |
push @bind_strs, " aqinvoices.invoicenumber LIKE ? "; |
2058 |
push @bind_args, "%$args{invoicenumber}%"; |
2059 |
} |
2060 |
if($args{suppliername}) { |
2061 |
push @bind_strs, " aqbooksellers.name LIKE ? "; |
2062 |
push @bind_args, "%$args{suppliername}%"; |
2063 |
} |
2064 |
if($args{shipmentdatefrom}) { |
2065 |
push @bind_strs, " aqinvoices.shipementdate >= ? "; |
2066 |
push @bind_args, $args{shipementdatefrom}; |
2067 |
} |
2068 |
if($args{shipmentdateto}) { |
2069 |
push @bind_strs, " aqinvoices.shipementdate <= ? "; |
2070 |
push @bind_args, $args{shipementdateto}; |
2071 |
} |
2072 |
if($args{billingdatefrom}) { |
2073 |
push @bind_strs, " aqinvoices.billingdate >= ? "; |
2074 |
push @bind_args, $args{billingdatefrom}; |
2075 |
} |
2076 |
if($args{billingdateto}) { |
2077 |
push @bind_strs, " aqinvoices.billingdate <= ? "; |
2078 |
push @bind_args, $args{billingdateto}; |
2079 |
} |
2080 |
if($args{isbneanissn}) { |
2081 |
push @bind_strs, " (biblioitems.isbn LIKE ? OR biblioitems.ean LIKE ? OR biblioitems.issn LIKE ? ) "; |
2082 |
push @bind_args, $args{isbneanissn}, $args{isbneanissn}, $args{isbneanissn}; |
2083 |
} |
2084 |
if($args{title}) { |
2085 |
push @bind_strs, " biblio.title LIKE ? "; |
2086 |
push @bind_args, $args{title}; |
2087 |
} |
2088 |
if($args{author}) { |
2089 |
push @bind_strs, " biblio.author LIKE ? "; |
2090 |
push @bind_args, $args{author}; |
2091 |
} |
2092 |
if($args{publisher}) { |
2093 |
push @bind_strs, " biblioitems.publishercode LIKE ? "; |
2094 |
push @bind_args, $args{publisher}; |
2095 |
} |
2096 |
if($args{publicationyear}) { |
2097 |
push @bind_strs, " biblioitems.publicationyear = ? "; |
2098 |
push @bind_args, $args{publicationyear}; |
2099 |
} |
2100 |
if($args{branchcode}) { |
2101 |
push @bind_strs, " aqorders.branchcode = ? "; |
2102 |
push @bind_args, $args{branchcode}; |
2103 |
} |
2104 |
|
2105 |
$query .= " WHERE " . join(" AND ", @bind_strs) if @bind_strs; |
2106 |
$query .= " GROUP BY aqinvoices.invoiceid "; |
2107 |
|
2108 |
if($args{order_by}) { |
2109 |
my ($column, $direction) = split / /, $args{order_by}; |
2110 |
if(grep /^$column$/, @columns) { |
2111 |
$direction ||= 'ASC'; |
2112 |
$query .= " ORDER BY $column $direction"; |
2113 |
} |
2114 |
} |
1986 |
|
2115 |
|
|
|
2116 |
my $sth = $dbh->prepare($query); |
2117 |
$sth->execute(@bind_args); |
2118 |
|
2119 |
my $results = $sth->fetchall_arrayref({}); |
2120 |
return @$results; |
2121 |
} |
2122 |
|
2123 |
=head3 GetInvoice |
2124 |
|
2125 |
my $invoice = GetInvoice($invoiceid); |
2126 |
|
2127 |
Get informations about invoice with given $invoiceid |
2128 |
|
2129 |
Return a hash filled with aqinvoices.* fields |
2130 |
|
2131 |
=cut |
2132 |
|
2133 |
sub GetInvoice { |
2134 |
my ($invoiceid) = @_; |
2135 |
my $invoice; |
2136 |
|
2137 |
return unless $invoiceid; |
2138 |
|
2139 |
my $dbh = C4::Context->dbh; |
2140 |
my $query = qq{ |
2141 |
SELECT * |
2142 |
FROM aqinvoices |
2143 |
WHERE invoiceid = ? |
2144 |
}; |
2145 |
my $sth = $dbh->prepare($query); |
2146 |
$sth->execute($invoiceid); |
2147 |
|
2148 |
$invoice = $sth->fetchrow_hashref; |
2149 |
return $invoice; |
2150 |
} |
2151 |
|
2152 |
=head3 GetInvoiceDetails |
2153 |
|
2154 |
my $invoice = GetInvoiceDetails($invoiceid) |
2155 |
|
2156 |
Return informations about an invoice + the list of related order lines |
2157 |
|
2158 |
Orders informations are in $invoice->{orders} (array ref) |
2159 |
|
2160 |
=cut |
2161 |
|
2162 |
sub GetInvoiceDetails { |
2163 |
my ($invoiceid) = @_; |
2164 |
my $invoice; |
2165 |
|
2166 |
return unless $invoiceid; |
2167 |
|
2168 |
my $dbh = C4::Context->dbh; |
2169 |
my $query = qq{ |
2170 |
SELECT aqinvoices.*, aqbooksellers.name AS suppliername |
2171 |
FROM aqinvoices |
2172 |
LEFT JOIN aqbooksellers ON aqinvoices.booksellerid = aqbooksellers.id |
2173 |
WHERE invoiceid = ? |
2174 |
}; |
2175 |
my $sth = $dbh->prepare($query); |
2176 |
$sth->execute($invoiceid); |
2177 |
|
2178 |
$invoice = $sth->fetchrow_hashref; |
2179 |
|
2180 |
$query = qq{ |
2181 |
SELECT aqorders.*, biblio.* |
2182 |
FROM aqorders |
2183 |
LEFT JOIN biblio ON aqorders.biblionumber = biblio.biblionumber |
2184 |
WHERE invoiceid = ? |
2185 |
}; |
2186 |
$sth = $dbh->prepare($query); |
2187 |
$sth->execute($invoiceid); |
2188 |
$invoice->{orders} = $sth->fetchall_arrayref({}); |
2189 |
$invoice->{orders} ||= []; # force an empty arrayref if fetchall_arrayref fails |
2190 |
|
2191 |
return $invoice; |
2192 |
} |
2193 |
|
2194 |
=head3 AddInvoice |
2195 |
|
2196 |
my $invoiceid = AddInvoice( |
2197 |
invoicenumber => $invoicenumber, |
2198 |
booksellerid => $booksellerid, |
2199 |
shipmentdate => $shipmentdate, |
2200 |
billingdate => $billingdate, |
2201 |
closedate => $closedate, |
2202 |
shipmentcost => $shipmentcost, |
2203 |
shipmentcost_budgetid => $shipmentcost_budgetid |
2204 |
); |
2205 |
|
2206 |
Create a new invoice and return its id or undef if it fails. |
2207 |
|
2208 |
=cut |
2209 |
|
2210 |
sub AddInvoice { |
2211 |
my %invoice = @_; |
2212 |
|
2213 |
return unless(%invoice and $invoice{invoicenumber}); |
2214 |
|
2215 |
my @columns = qw(invoicenumber booksellerid shipmentdate billingdate |
2216 |
closedate shipmentcost shipmentcost_budgetid); |
2217 |
|
2218 |
my @set_strs; |
2219 |
my @set_args; |
2220 |
foreach my $key (keys %invoice) { |
2221 |
if(0 < grep(/^$key$/, @columns)) { |
2222 |
push @set_strs, "$key = ?"; |
2223 |
push @set_args, ($invoice{$key} || undef); |
2224 |
} |
2225 |
} |
2226 |
|
2227 |
my $rv; |
2228 |
if(@set_args > 0) { |
2229 |
my $dbh = C4::Context->dbh; |
2230 |
my $query = "INSERT INTO aqinvoices SET "; |
2231 |
$query .= join (",", @set_strs); |
2232 |
my $sth = $dbh->prepare($query); |
2233 |
$rv = $sth->execute(@set_args); |
2234 |
if($rv) { |
2235 |
$rv = $dbh->last_insert_id(undef, undef, 'aqinvoices', undef); |
2236 |
} |
2237 |
} |
2238 |
return $rv; |
2239 |
} |
2240 |
|
2241 |
=head3 ModInvoice |
2242 |
|
2243 |
ModInvoice( |
2244 |
invoiceid => $invoiceid, # Mandatory |
2245 |
invoicenumber => $invoicenumber, |
2246 |
booksellerid => $booksellerid, |
2247 |
shipmentdate => $shipmentdate, |
2248 |
billingdate => $billingdate, |
2249 |
closedate => $closedate, |
2250 |
shipmentcost => $shipmentcost, |
2251 |
shipmentcost_budgetid => $shipmentcost_budgetid |
2252 |
); |
2253 |
|
2254 |
Modify an invoice, invoiceid is mandatory. |
2255 |
|
2256 |
Return undef if it fails. |
2257 |
|
2258 |
=cut |
2259 |
|
2260 |
sub ModInvoice { |
2261 |
my %invoice = @_; |
2262 |
|
2263 |
return unless(%invoice and $invoice{invoiceid}); |
2264 |
|
2265 |
my @columns = qw(invoicenumber booksellerid shipmentdate billingdate |
2266 |
closedate shipmentcost shipmentcost_budgetid); |
2267 |
|
2268 |
my @set_strs; |
2269 |
my @set_args; |
2270 |
foreach my $key (keys %invoice) { |
2271 |
if(0 < grep(/^$key$/, @columns)) { |
2272 |
push @set_strs, "$key = ?"; |
2273 |
push @set_args, ($invoice{$key} || undef); |
2274 |
} |
2275 |
} |
2276 |
|
2277 |
my $dbh = C4::Context->dbh; |
2278 |
my $query = "UPDATE aqinvoices SET "; |
2279 |
$query .= join(",", @set_strs); |
2280 |
$query .= " WHERE invoiceid = ?"; |
2281 |
|
2282 |
my $sth = $dbh->prepare($query); |
2283 |
$sth->execute(@set_args, $invoice{invoiceid}); |
2284 |
} |
2285 |
|
2286 |
=head3 CloseInvoice |
2287 |
|
2288 |
CloseInvoice($invoiceid); |
2289 |
|
2290 |
Close an invoice. |
2291 |
|
2292 |
Equivalent to ModInvoice(invoiceid => $invoiceid, closedate => undef); |
2293 |
|
2294 |
=cut |
2295 |
|
2296 |
sub CloseInvoice { |
2297 |
my ($invoiceid) = @_; |
2298 |
|
2299 |
return unless $invoiceid; |
2300 |
|
2301 |
my $dbh = C4::Context->dbh; |
2302 |
my $query = qq{ |
2303 |
UPDATE aqinvoices |
2304 |
SET closedate = CAST(NOW() AS DATE) |
2305 |
WHERE invoiceid = ? |
2306 |
}; |
2307 |
my $sth = $dbh->prepare($query); |
2308 |
$sth->execute($invoiceid); |
2309 |
} |
2310 |
|
2311 |
=head3 ReopenInvoice |
2312 |
|
2313 |
ReopenInvoice($invoiceid); |
2314 |
|
2315 |
Reopen an invoice |
2316 |
|
2317 |
Equivalent to ModInvoice(invoiceid => $invoiceid, closedate => C4::Dates->new()->output('iso')) |
2318 |
|
2319 |
=cut |
2320 |
|
2321 |
sub ReopenInvoice { |
2322 |
my ($invoiceid) = @_; |
2323 |
|
2324 |
return unless $invoiceid; |
2325 |
|
2326 |
my $dbh = C4::Context->dbh; |
2327 |
my $query = qq{ |
2328 |
UPDATE aqinvoices |
2329 |
SET closedate = NULL |
2330 |
WHERE invoiceid = ? |
2331 |
}; |
2332 |
my $sth = $dbh->prepare($query); |
2333 |
$sth->execute($invoiceid); |
1987 |
} |
2334 |
} |
1988 |
|
2335 |
|
1989 |
1; |
2336 |
1; |