|
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 1245-1259
sub GetCancelledOrders {
Link Here
|
| 1245 |
=head3 ModReceiveOrder |
1253 |
=head3 ModReceiveOrder |
| 1246 |
|
1254 |
|
| 1247 |
&ModReceiveOrder($biblionumber, $ordernumber, $quantityreceived, $user, |
1255 |
&ModReceiveOrder($biblionumber, $ordernumber, $quantityreceived, $user, |
| 1248 |
$unitprice, $booksellerinvoicenumber, $biblioitemnumber, |
1256 |
$unitprice, $invoiceid, $biblioitemnumber, |
| 1249 |
$freight, $bookfund, $rrp); |
1257 |
$bookfund, $rrp, \@received_itemnumbers); |
| 1250 |
|
1258 |
|
| 1251 |
Updates an order, to reflect the fact that it was received, at least |
1259 |
Updates an order, to reflect the fact that it was received, at least |
| 1252 |
in part. All arguments not mentioned below update the fields with the |
1260 |
in part. All arguments not mentioned below update the fields with the |
| 1253 |
same name in the aqorders table of the Koha database. |
1261 |
same name in the aqorders table of the Koha database. |
| 1254 |
|
1262 |
|
| 1255 |
If a partial order is received, splits the order into two. The received |
1263 |
If a partial order is received, splits the order into two. |
| 1256 |
portion must have a booksellerinvoicenumber. |
|
|
| 1257 |
|
1264 |
|
| 1258 |
Updates the order with bibilionumber C<$biblionumber> and ordernumber |
1265 |
Updates the order with bibilionumber C<$biblionumber> and ordernumber |
| 1259 |
C<$ordernumber>. |
1266 |
C<$ordernumber>. |
|
Lines 1264-1270
C<$ordernumber>.
Link Here
|
| 1264 |
sub ModReceiveOrder { |
1271 |
sub ModReceiveOrder { |
| 1265 |
my ( |
1272 |
my ( |
| 1266 |
$biblionumber, $ordernumber, $quantrec, $user, $cost, |
1273 |
$biblionumber, $ordernumber, $quantrec, $user, $cost, |
| 1267 |
$invoiceno, $freight, $rrp, $budget_id, $datereceived, $received_items |
1274 |
$invoiceid, $rrp, $budget_id, $datereceived, $received_items |
| 1268 |
) |
1275 |
) |
| 1269 |
= @_; |
1276 |
= @_; |
| 1270 |
|
1277 |
|
|
Lines 1305-1313
sub ModReceiveOrder {
Link Here
|
| 1305 |
$order->{'quantity'} = $quantrec; |
1312 |
$order->{'quantity'} = $quantrec; |
| 1306 |
$order->{'quantityreceived'} = $quantrec; |
1313 |
$order->{'quantityreceived'} = $quantrec; |
| 1307 |
$order->{'datereceived'} = $datereceived; |
1314 |
$order->{'datereceived'} = $datereceived; |
| 1308 |
$order->{'booksellerinvoicenumber'} = $invoiceno; |
1315 |
$order->{'invoiceid'} = $invoiceid; |
| 1309 |
$order->{'unitprice'} = $cost; |
1316 |
$order->{'unitprice'} = $cost; |
| 1310 |
$order->{'freight'} = $freight; |
|
|
| 1311 |
$order->{'rrp'} = $rrp; |
1317 |
$order->{'rrp'} = $rrp; |
| 1312 |
$order->{'orderstatus'} = 3; # totally received |
1318 |
$order->{'orderstatus'} = 3; # totally received |
| 1313 |
$new_ordernumber = NewOrder($order); |
1319 |
$new_ordernumber = NewOrder($order); |
|
Lines 1319-1328
sub ModReceiveOrder {
Link Here
|
| 1319 |
} |
1325 |
} |
| 1320 |
} else { |
1326 |
} else { |
| 1321 |
$sth=$dbh->prepare("update aqorders |
1327 |
$sth=$dbh->prepare("update aqorders |
| 1322 |
set quantityreceived=?,datereceived=?,booksellerinvoicenumber=?, |
1328 |
set quantityreceived=?,datereceived=?,invoiceid=?, |
| 1323 |
unitprice=?,freight=?,rrp=? |
1329 |
unitprice=?,rrp=? |
| 1324 |
where biblionumber=? and ordernumber=?"); |
1330 |
where biblionumber=? and ordernumber=?"); |
| 1325 |
$sth->execute($quantrec,$datereceived,$invoiceno,$cost,$freight,$rrp,$biblionumber,$ordernumber); |
1331 |
$sth->execute($quantrec,$datereceived,$invoiceid,$cost,$rrp,$biblionumber,$ordernumber); |
| 1326 |
$sth->finish; |
1332 |
$sth->finish; |
| 1327 |
} |
1333 |
} |
| 1328 |
return ($datereceived, $new_ordernumber); |
1334 |
return ($datereceived, $new_ordernumber); |
|
Lines 1370-1376
sub CancelReceipt {
Link Here
|
| 1370 |
UPDATE aqorders |
1376 |
UPDATE aqorders |
| 1371 |
SET quantityreceived = ?, |
1377 |
SET quantityreceived = ?, |
| 1372 |
datereceived = ?, |
1378 |
datereceived = ?, |
| 1373 |
booksellerinvoicenumber = ? |
1379 |
invoiceid = ? |
| 1374 |
WHERE ordernumber = ? |
1380 |
WHERE ordernumber = ? |
| 1375 |
}; |
1381 |
}; |
| 1376 |
$sth = $dbh->prepare($query); |
1382 |
$sth = $dbh->prepare($query); |
|
Lines 1597-1605
sub GetParcel {
Link Here
|
| 1597 |
LEFT JOIN aqbasket ON aqbasket.basketno=aqorders.basketno |
1603 |
LEFT JOIN aqbasket ON aqbasket.basketno=aqorders.basketno |
| 1598 |
LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber |
1604 |
LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber |
| 1599 |
LEFT JOIN biblio ON aqorders.biblionumber=biblio.biblionumber |
1605 |
LEFT JOIN biblio ON aqorders.biblionumber=biblio.biblionumber |
|
|
1606 |
LEFT JOIN aqinvoices ON aqorders.invoiceid = aqinvoices.invoiceid |
| 1600 |
WHERE |
1607 |
WHERE |
| 1601 |
aqbasket.booksellerid = ? |
1608 |
aqbasket.booksellerid = ? |
| 1602 |
AND aqorders.booksellerinvoicenumber LIKE ? |
1609 |
AND aqinvoices.invoicenumber LIKE ? |
| 1603 |
AND aqorders.datereceived = ? "; |
1610 |
AND aqorders.datereceived = ? "; |
| 1604 |
|
1611 |
|
| 1605 |
my @query_params = ( $supplierid, $code, $datereceived ); |
1612 |
my @query_params = ( $supplierid, $code, $datereceived ); |
|
Lines 1672-1689
sub GetParcels {
Link Here
|
| 1672 |
my $dbh = C4::Context->dbh; |
1679 |
my $dbh = C4::Context->dbh; |
| 1673 |
my @query_params = (); |
1680 |
my @query_params = (); |
| 1674 |
my $strsth =" |
1681 |
my $strsth =" |
| 1675 |
SELECT aqorders.booksellerinvoicenumber, |
1682 |
SELECT aqinvoices.invoicenumber, |
| 1676 |
datereceived,purchaseordernumber, |
1683 |
datereceived,purchaseordernumber, |
| 1677 |
count(DISTINCT biblionumber) AS biblio, |
1684 |
count(DISTINCT biblionumber) AS biblio, |
| 1678 |
sum(quantity) AS itemsexpected, |
1685 |
sum(quantity) AS itemsexpected, |
| 1679 |
sum(quantityreceived) AS itemsreceived |
1686 |
sum(quantityreceived) AS itemsreceived |
| 1680 |
FROM aqorders LEFT JOIN aqbasket ON aqbasket.basketno = aqorders.basketno |
1687 |
FROM aqorders LEFT JOIN aqbasket ON aqbasket.basketno = aqorders.basketno |
|
|
1688 |
LEFT JOIN aqinvoices ON aqorders.invoiceid = aqinvoices.invoiceid |
| 1681 |
WHERE aqbasket.booksellerid = ? and datereceived IS NOT NULL |
1689 |
WHERE aqbasket.booksellerid = ? and datereceived IS NOT NULL |
| 1682 |
"; |
1690 |
"; |
| 1683 |
push @query_params, $bookseller; |
1691 |
push @query_params, $bookseller; |
| 1684 |
|
1692 |
|
| 1685 |
if ( defined $code ) { |
1693 |
if ( defined $code ) { |
| 1686 |
$strsth .= ' and aqorders.booksellerinvoicenumber like ? '; |
1694 |
$strsth .= ' and aqinvoices.invoicenumber like ? '; |
| 1687 |
# add a % to the end of the code to allow stemming. |
1695 |
# add a % to the end of the code to allow stemming. |
| 1688 |
push @query_params, "$code%"; |
1696 |
push @query_params, "$code%"; |
| 1689 |
} |
1697 |
} |
|
Lines 1698-1704
sub GetParcels {
Link Here
|
| 1698 |
push @query_params, $dateto; |
1706 |
push @query_params, $dateto; |
| 1699 |
} |
1707 |
} |
| 1700 |
|
1708 |
|
| 1701 |
$strsth .= "group by aqorders.booksellerinvoicenumber,datereceived "; |
1709 |
$strsth .= "group by aqinvoices.invoicenumber,datereceived "; |
| 1702 |
|
1710 |
|
| 1703 |
# can't use a placeholder to place this column name. |
1711 |
# can't use a placeholder to place this column name. |
| 1704 |
# but, we could probably be checking to make sure it is a column that will be fetched. |
1712 |
# but, we could probably be checking to make sure it is a column that will be fetched. |
|
Lines 1915-1921
sub GetHistory {
Link Here
|
| 1915 |
aqorders.quantityreceived, |
1923 |
aqorders.quantityreceived, |
| 1916 |
aqorders.ecost, |
1924 |
aqorders.ecost, |
| 1917 |
aqorders.ordernumber, |
1925 |
aqorders.ordernumber, |
| 1918 |
aqorders.booksellerinvoicenumber as invoicenumber, |
1926 |
aqinvoices.invoicenumber, |
| 1919 |
aqbooksellers.id as id, |
1927 |
aqbooksellers.id as id, |
| 1920 |
aqorders.biblionumber |
1928 |
aqorders.biblionumber |
| 1921 |
FROM aqorders |
1929 |
FROM aqorders |
|
Lines 1923-1929
sub GetHistory {
Link Here
|
| 1923 |
LEFT JOIN aqbasketgroups ON aqbasket.basketgroupid=aqbasketgroups.id |
1931 |
LEFT JOIN aqbasketgroups ON aqbasket.basketgroupid=aqbasketgroups.id |
| 1924 |
LEFT JOIN aqbooksellers ON aqbasket.booksellerid=aqbooksellers.id |
1932 |
LEFT JOIN aqbooksellers ON aqbasket.booksellerid=aqbooksellers.id |
| 1925 |
LEFT JOIN biblioitems ON biblioitems.biblionumber=aqorders.biblionumber |
1933 |
LEFT JOIN biblioitems ON biblioitems.biblionumber=aqorders.biblionumber |
| 1926 |
LEFT JOIN biblio ON biblio.biblionumber=aqorders.biblionumber"; |
1934 |
LEFT JOIN biblio ON biblio.biblionumber=aqorders.biblionumber |
|
|
1935 |
LEFT JOIN aqinvoices ON aqorders.invoiceid = aqinvoices.invoiceid"; |
| 1927 |
|
1936 |
|
| 1928 |
$query .= " LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber" |
1937 |
$query .= " LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber" |
| 1929 |
if ( C4::Context->preference("IndependantBranches") ); |
1938 |
if ( C4::Context->preference("IndependantBranches") ); |
|
Lines 1977-1984
sub GetHistory {
Link Here
|
| 1977 |
} |
1986 |
} |
| 1978 |
|
1987 |
|
| 1979 |
if ($booksellerinvoicenumber) { |
1988 |
if ($booksellerinvoicenumber) { |
| 1980 |
$query .= " AND (aqorders.booksellerinvoicenumber LIKE ? OR aqbasket.booksellerinvoicenumber LIKE ?)"; |
1989 |
$query .= " AND aqinvoices.invoicenumber LIKE ? "; |
| 1981 |
push @query_params, "%$booksellerinvoicenumber%", "%$booksellerinvoicenumber%"; |
1990 |
push @query_params, "%$booksellerinvoicenumber%"; |
| 1982 |
} |
1991 |
} |
| 1983 |
|
1992 |
|
| 1984 |
if ($basketgroupname) { |
1993 |
if ($basketgroupname) { |
|
Lines 2124-2130
sub AddClaim {
Link Here
|
| 2124 |
"; |
2133 |
"; |
| 2125 |
my $sth = $dbh->prepare($query); |
2134 |
my $sth = $dbh->prepare($query); |
| 2126 |
$sth->execute($ordernumber); |
2135 |
$sth->execute($ordernumber); |
|
|
2136 |
} |
| 2137 |
|
| 2138 |
=head3 GetInvoices |
| 2139 |
|
| 2140 |
my @invoices = GetInvoices( |
| 2141 |
invoicenumber => $invoicenumber, |
| 2142 |
suppliername => $suppliername, |
| 2143 |
shipmentdatefrom => $shipmentdatefrom, # ISO format |
| 2144 |
shipmentdateto => $shipmentdateto, # ISO format |
| 2145 |
billingdatefrom => $billingdatefrom, # ISO format |
| 2146 |
billingdateto => $billingdateto, # ISO format |
| 2147 |
isbneanissn => $isbn_or_ean_or_issn, |
| 2148 |
title => $title, |
| 2149 |
author => $author, |
| 2150 |
publisher => $publisher, |
| 2151 |
publicationyear => $publicationyear, |
| 2152 |
branchcode => $branchcode, |
| 2153 |
order_by => $order_by |
| 2154 |
); |
| 2155 |
|
| 2156 |
Return a list of invoices that match all given criteria. |
| 2157 |
|
| 2158 |
$order_by is "column_name (asc|desc)", where column_name is any of |
| 2159 |
'invoicenumber', 'booksellerid', 'shipmentdate', 'billingdate', 'closedate', |
| 2160 |
'shipmentcost', 'shipmentcost_budgetid'. |
| 2161 |
|
| 2162 |
asc is the default if omitted |
| 2163 |
|
| 2164 |
=cut |
| 2165 |
|
| 2166 |
sub GetInvoices { |
| 2167 |
my %args = @_; |
| 2168 |
|
| 2169 |
my @columns = qw(invoicenumber booksellerid shipmentdate billingdate |
| 2170 |
closedate shipmentcost shipmentcost_budgetid); |
| 2171 |
|
| 2172 |
my $dbh = C4::Context->dbh; |
| 2173 |
my $query = qq{ |
| 2174 |
SELECT aqinvoices.*, aqbooksellers.name AS suppliername, |
| 2175 |
COUNT( |
| 2176 |
DISTINCT IF( |
| 2177 |
aqorders.datereceived IS NOT NULL, |
| 2178 |
aqorders.biblionumber, |
| 2179 |
NULL |
| 2180 |
) |
| 2181 |
) AS receivedbiblios, |
| 2182 |
SUM(aqorders.quantityreceived) AS receiveditems |
| 2183 |
FROM aqinvoices |
| 2184 |
LEFT JOIN aqbooksellers ON aqbooksellers.id = aqinvoices.booksellerid |
| 2185 |
LEFT JOIN aqorders ON aqorders.invoiceid = aqinvoices.invoiceid |
| 2186 |
LEFT JOIN biblio ON aqorders.biblionumber = biblio.biblionumber |
| 2187 |
LEFT JOIN biblioitems ON biblio.biblionumber = biblioitems.biblionumber |
| 2188 |
LEFT JOIN subscription ON biblio.biblionumber = subscription.biblionumber |
| 2189 |
}; |
| 2190 |
|
| 2191 |
my @bind_args; |
| 2192 |
my @bind_strs; |
| 2193 |
if($args{supplierid}) { |
| 2194 |
push @bind_strs, " aqinvoices.booksellerid = ? "; |
| 2195 |
push @bind_args, $args{supplierid}; |
| 2196 |
} |
| 2197 |
if($args{invoicenumber}) { |
| 2198 |
push @bind_strs, " aqinvoices.invoicenumber LIKE ? "; |
| 2199 |
push @bind_args, "%$args{invoicenumber}%"; |
| 2200 |
} |
| 2201 |
if($args{suppliername}) { |
| 2202 |
push @bind_strs, " aqbooksellers.name LIKE ? "; |
| 2203 |
push @bind_args, "%$args{suppliername}%"; |
| 2204 |
} |
| 2205 |
if($args{shipmentdatefrom}) { |
| 2206 |
push @bind_strs, " aqinvoices.shipementdate >= ? "; |
| 2207 |
push @bind_args, $args{shipementdatefrom}; |
| 2208 |
} |
| 2209 |
if($args{shipmentdateto}) { |
| 2210 |
push @bind_strs, " aqinvoices.shipementdate <= ? "; |
| 2211 |
push @bind_args, $args{shipementdateto}; |
| 2212 |
} |
| 2213 |
if($args{billingdatefrom}) { |
| 2214 |
push @bind_strs, " aqinvoices.billingdate >= ? "; |
| 2215 |
push @bind_args, $args{billingdatefrom}; |
| 2216 |
} |
| 2217 |
if($args{billingdateto}) { |
| 2218 |
push @bind_strs, " aqinvoices.billingdate <= ? "; |
| 2219 |
push @bind_args, $args{billingdateto}; |
| 2220 |
} |
| 2221 |
if($args{isbneanissn}) { |
| 2222 |
push @bind_strs, " (biblioitems.isbn LIKE ? OR biblioitems.ean LIKE ? OR biblioitems.issn LIKE ? ) "; |
| 2223 |
push @bind_args, $args{isbneanissn}, $args{isbneanissn}, $args{isbneanissn}; |
| 2224 |
} |
| 2225 |
if($args{title}) { |
| 2226 |
push @bind_strs, " biblio.title LIKE ? "; |
| 2227 |
push @bind_args, $args{title}; |
| 2228 |
} |
| 2229 |
if($args{author}) { |
| 2230 |
push @bind_strs, " biblio.author LIKE ? "; |
| 2231 |
push @bind_args, $args{author}; |
| 2232 |
} |
| 2233 |
if($args{publisher}) { |
| 2234 |
push @bind_strs, " biblioitems.publishercode LIKE ? "; |
| 2235 |
push @bind_args, $args{publisher}; |
| 2236 |
} |
| 2237 |
if($args{publicationyear}) { |
| 2238 |
push @bind_strs, " biblioitems.publicationyear = ? "; |
| 2239 |
push @bind_args, $args{publicationyear}; |
| 2240 |
} |
| 2241 |
if($args{branchcode}) { |
| 2242 |
push @bind_strs, " aqorders.branchcode = ? "; |
| 2243 |
push @bind_args, $args{branchcode}; |
| 2244 |
} |
| 2245 |
|
| 2246 |
$query .= " WHERE " . join(" AND ", @bind_strs) if @bind_strs; |
| 2247 |
$query .= " GROUP BY aqinvoices.invoiceid "; |
| 2248 |
|
| 2249 |
if($args{order_by}) { |
| 2250 |
my ($column, $direction) = split / /, $args{order_by}; |
| 2251 |
if(grep /^$column$/, @columns) { |
| 2252 |
$direction ||= 'ASC'; |
| 2253 |
$query .= " ORDER BY $column $direction"; |
| 2254 |
} |
| 2255 |
} |
| 2127 |
|
2256 |
|
|
|
2257 |
my $sth = $dbh->prepare($query); |
| 2258 |
$sth->execute(@bind_args); |
| 2259 |
|
| 2260 |
my $results = $sth->fetchall_arrayref({}); |
| 2261 |
return @$results; |
| 2262 |
} |
| 2263 |
|
| 2264 |
=head3 GetInvoice |
| 2265 |
|
| 2266 |
my $invoice = GetInvoice($invoiceid); |
| 2267 |
|
| 2268 |
Get informations about invoice with given $invoiceid |
| 2269 |
|
| 2270 |
Return a hash filled with aqinvoices.* fields |
| 2271 |
|
| 2272 |
=cut |
| 2273 |
|
| 2274 |
sub GetInvoice { |
| 2275 |
my ($invoiceid) = @_; |
| 2276 |
my $invoice; |
| 2277 |
|
| 2278 |
return unless $invoiceid; |
| 2279 |
|
| 2280 |
my $dbh = C4::Context->dbh; |
| 2281 |
my $query = qq{ |
| 2282 |
SELECT * |
| 2283 |
FROM aqinvoices |
| 2284 |
WHERE invoiceid = ? |
| 2285 |
}; |
| 2286 |
my $sth = $dbh->prepare($query); |
| 2287 |
$sth->execute($invoiceid); |
| 2288 |
|
| 2289 |
$invoice = $sth->fetchrow_hashref; |
| 2290 |
return $invoice; |
| 2291 |
} |
| 2292 |
|
| 2293 |
=head3 GetInvoiceDetails |
| 2294 |
|
| 2295 |
my $invoice = GetInvoiceDetails($invoiceid) |
| 2296 |
|
| 2297 |
Return informations about an invoice + the list of related order lines |
| 2298 |
|
| 2299 |
Orders informations are in $invoice->{orders} (array ref) |
| 2300 |
|
| 2301 |
=cut |
| 2302 |
|
| 2303 |
sub GetInvoiceDetails { |
| 2304 |
my ($invoiceid) = @_; |
| 2305 |
my $invoice; |
| 2306 |
|
| 2307 |
return unless $invoiceid; |
| 2308 |
|
| 2309 |
my $dbh = C4::Context->dbh; |
| 2310 |
my $query = qq{ |
| 2311 |
SELECT aqinvoices.*, aqbooksellers.name AS suppliername |
| 2312 |
FROM aqinvoices |
| 2313 |
LEFT JOIN aqbooksellers ON aqinvoices.booksellerid = aqbooksellers.id |
| 2314 |
WHERE invoiceid = ? |
| 2315 |
}; |
| 2316 |
my $sth = $dbh->prepare($query); |
| 2317 |
$sth->execute($invoiceid); |
| 2318 |
|
| 2319 |
$invoice = $sth->fetchrow_hashref; |
| 2320 |
|
| 2321 |
$query = qq{ |
| 2322 |
SELECT aqorders.*, biblio.* |
| 2323 |
FROM aqorders |
| 2324 |
LEFT JOIN biblio ON aqorders.biblionumber = biblio.biblionumber |
| 2325 |
WHERE invoiceid = ? |
| 2326 |
}; |
| 2327 |
$sth = $dbh->prepare($query); |
| 2328 |
$sth->execute($invoiceid); |
| 2329 |
$invoice->{orders} = $sth->fetchall_arrayref({}); |
| 2330 |
$invoice->{orders} ||= []; # force an empty arrayref if fetchall_arrayref fails |
| 2331 |
|
| 2332 |
return $invoice; |
| 2333 |
} |
| 2334 |
|
| 2335 |
=head3 AddInvoice |
| 2336 |
|
| 2337 |
my $invoiceid = AddInvoice( |
| 2338 |
invoicenumber => $invoicenumber, |
| 2339 |
booksellerid => $booksellerid, |
| 2340 |
shipmentdate => $shipmentdate, |
| 2341 |
billingdate => $billingdate, |
| 2342 |
closedate => $closedate, |
| 2343 |
shipmentcost => $shipmentcost, |
| 2344 |
shipmentcost_budgetid => $shipmentcost_budgetid |
| 2345 |
); |
| 2346 |
|
| 2347 |
Create a new invoice and return its id or undef if it fails. |
| 2348 |
|
| 2349 |
=cut |
| 2350 |
|
| 2351 |
sub AddInvoice { |
| 2352 |
my %invoice = @_; |
| 2353 |
|
| 2354 |
return unless(%invoice and $invoice{invoicenumber}); |
| 2355 |
|
| 2356 |
my @columns = qw(invoicenumber booksellerid shipmentdate billingdate |
| 2357 |
closedate shipmentcost shipmentcost_budgetid); |
| 2358 |
|
| 2359 |
my @set_strs; |
| 2360 |
my @set_args; |
| 2361 |
foreach my $key (keys %invoice) { |
| 2362 |
if(0 < grep(/^$key$/, @columns)) { |
| 2363 |
push @set_strs, "$key = ?"; |
| 2364 |
push @set_args, ($invoice{$key} || undef); |
| 2365 |
} |
| 2366 |
} |
| 2367 |
|
| 2368 |
my $rv; |
| 2369 |
if(@set_args > 0) { |
| 2370 |
my $dbh = C4::Context->dbh; |
| 2371 |
my $query = "INSERT INTO aqinvoices SET "; |
| 2372 |
$query .= join (",", @set_strs); |
| 2373 |
my $sth = $dbh->prepare($query); |
| 2374 |
$rv = $sth->execute(@set_args); |
| 2375 |
if($rv) { |
| 2376 |
$rv = $dbh->last_insert_id(undef, undef, 'aqinvoices', undef); |
| 2377 |
} |
| 2378 |
} |
| 2379 |
return $rv; |
| 2380 |
} |
| 2381 |
|
| 2382 |
=head3 ModInvoice |
| 2383 |
|
| 2384 |
ModInvoice( |
| 2385 |
invoiceid => $invoiceid, # Mandatory |
| 2386 |
invoicenumber => $invoicenumber, |
| 2387 |
booksellerid => $booksellerid, |
| 2388 |
shipmentdate => $shipmentdate, |
| 2389 |
billingdate => $billingdate, |
| 2390 |
closedate => $closedate, |
| 2391 |
shipmentcost => $shipmentcost, |
| 2392 |
shipmentcost_budgetid => $shipmentcost_budgetid |
| 2393 |
); |
| 2394 |
|
| 2395 |
Modify an invoice, invoiceid is mandatory. |
| 2396 |
|
| 2397 |
Return undef if it fails. |
| 2398 |
|
| 2399 |
=cut |
| 2400 |
|
| 2401 |
sub ModInvoice { |
| 2402 |
my %invoice = @_; |
| 2403 |
|
| 2404 |
return unless(%invoice and $invoice{invoiceid}); |
| 2405 |
|
| 2406 |
my @columns = qw(invoicenumber booksellerid shipmentdate billingdate |
| 2407 |
closedate shipmentcost shipmentcost_budgetid); |
| 2408 |
|
| 2409 |
my @set_strs; |
| 2410 |
my @set_args; |
| 2411 |
foreach my $key (keys %invoice) { |
| 2412 |
if(0 < grep(/^$key$/, @columns)) { |
| 2413 |
push @set_strs, "$key = ?"; |
| 2414 |
push @set_args, ($invoice{$key} || undef); |
| 2415 |
} |
| 2416 |
} |
| 2417 |
|
| 2418 |
my $dbh = C4::Context->dbh; |
| 2419 |
my $query = "UPDATE aqinvoices SET "; |
| 2420 |
$query .= join(",", @set_strs); |
| 2421 |
$query .= " WHERE invoiceid = ?"; |
| 2422 |
|
| 2423 |
my $sth = $dbh->prepare($query); |
| 2424 |
$sth->execute(@set_args, $invoice{invoiceid}); |
| 2425 |
} |
| 2426 |
|
| 2427 |
=head3 CloseInvoice |
| 2428 |
|
| 2429 |
CloseInvoice($invoiceid); |
| 2430 |
|
| 2431 |
Close an invoice. |
| 2432 |
|
| 2433 |
Equivalent to ModInvoice(invoiceid => $invoiceid, closedate => undef); |
| 2434 |
|
| 2435 |
=cut |
| 2436 |
|
| 2437 |
sub CloseInvoice { |
| 2438 |
my ($invoiceid) = @_; |
| 2439 |
|
| 2440 |
return unless $invoiceid; |
| 2441 |
|
| 2442 |
my $dbh = C4::Context->dbh; |
| 2443 |
my $query = qq{ |
| 2444 |
UPDATE aqinvoices |
| 2445 |
SET closedate = CAST(NOW() AS DATE) |
| 2446 |
WHERE invoiceid = ? |
| 2447 |
}; |
| 2448 |
my $sth = $dbh->prepare($query); |
| 2449 |
$sth->execute($invoiceid); |
| 2450 |
} |
| 2451 |
|
| 2452 |
=head3 ReopenInvoice |
| 2453 |
|
| 2454 |
ReopenInvoice($invoiceid); |
| 2455 |
|
| 2456 |
Reopen an invoice |
| 2457 |
|
| 2458 |
Equivalent to ModInvoice(invoiceid => $invoiceid, closedate => C4::Dates->new()->output('iso')) |
| 2459 |
|
| 2460 |
=cut |
| 2461 |
|
| 2462 |
sub ReopenInvoice { |
| 2463 |
my ($invoiceid) = @_; |
| 2464 |
|
| 2465 |
return unless $invoiceid; |
| 2466 |
|
| 2467 |
my $dbh = C4::Context->dbh; |
| 2468 |
my $query = qq{ |
| 2469 |
UPDATE aqinvoices |
| 2470 |
SET closedate = NULL |
| 2471 |
WHERE invoiceid = ? |
| 2472 |
}; |
| 2473 |
my $sth = $dbh->prepare($query); |
| 2474 |
$sth->execute($invoiceid); |
| 2128 |
} |
2475 |
} |
| 2129 |
|
2476 |
|
| 2130 |
1; |
2477 |
1; |