Skillnad mellan versioner av "Fakturering"
Klas (diskussion | bidrag) |
|||
Rad 13: | Rad 13: | ||
Vi använder inte cronjobbet Long overdues | Vi använder inte cronjobbet Long overdues | ||
− | Pocessen består av | + | Pocessen består av tre rapporter som körs i denna ordning: |
− | == 1 | + | == 1 Leta-lista == |
Det första vi gör är att ta ut en lista på böcker som inte har blivit återlämnade, fast de är mer än 37 dagar sena, så vi kan leta efter dem i hyllan i fall vi missat att avregistrera dem i återlämningen. | Det första vi gör är att ta ut en lista på böcker som inte har blivit återlämnade, fast de är mer än 37 dagar sena, så vi kan leta efter dem i hyllan i fall vi missat att avregistrera dem i återlämningen. | ||
<pre> | <pre> | ||
Rad 22: | Rad 22: | ||
branches.branchname AS Bibliotek, | branches.branchname AS Bibliotek, | ||
items.ccode AS Samling, | items.ccode AS Samling, | ||
− | + | authorised_values.lib AS Placering, | |
items.itemcallnumber AS Hyllsignum, | items.itemcallnumber AS Hyllsignum, | ||
biblio.author AS Författare, | biblio.author AS Författare, | ||
− | biblio.title AS Titel, | + | CASE |
− | items.barcode AS Streckkod, | + | WHEN biblio.frameworkcode='SER' AND items.enumchron IS NOT NULL |
+ | THEN | ||
+ | CONCAT(biblio.title,'<br>',items.enumchron) | ||
+ | ELSE | ||
+ | biblio.title | ||
+ | END | ||
+ | AS Titel, | ||
+ | items.barcode AS Streckkod, | ||
items.itype AS Exemplartyp | items.itype AS Exemplartyp | ||
Rad 32: | Rad 39: | ||
LEFT JOIN issues ON (borrowers.borrowernumber=issues.borrowernumber) | LEFT JOIN issues ON (borrowers.borrowernumber=issues.borrowernumber) | ||
LEFT JOIN items ON (issues.itemnumber=items.itemnumber) | LEFT JOIN items ON (issues.itemnumber=items.itemnumber) | ||
+ | LEFT JOIN authorised_values ON (items.location=authorised_values.authorised_value) | ||
LEFT JOIN biblio ON (items.biblionumber=biblio.biblionumber) | LEFT JOIN biblio ON (items.biblionumber=biblio.biblionumber) | ||
LEFT JOIN branches ON (items.homebranch=branches.branchcode) | LEFT JOIN branches ON (items.homebranch=branches.branchcode) | ||
− | WHERE (TO_DAYS(curdate())-TO_DAYS(date_due)) > '37' AND items.itemlost !=1 AND items.itemlost !=2 AND items.itemlost !=3 AND items.itemlost !=4 AND issues.branchcode = <<Utlånande bibliotek|branches>> | + | WHERE (TO_DAYS(curdate())-TO_DAYS(date_due)) > '37' AND items.itemlost !=1 AND items.itemlost !=2 AND items.itemlost !=3 AND items.itemlost !=4 AND items.itemlost !=5 AND issues.branchcode = <<Utlånande bibliotek|branches>> |
− | ORDER BY items.homebranch ASC,items.ccode ASC, items.location ASC, items.itemcallnumber ASC, biblio.author ASC,biblio.title ASC | + | ORDER BY items.homebranch ASC,items.ccode ASC, items.location ASC, items.itemcallnumber ASC, biblio.author ASC,biblio.title ASC</pre> |
− | </pre> | ||
− | == 2 | + | == 2 Kontrolllista == |
Nästa steg är att vi manuellt ändrar status till "På räkning" för de böcker som ska faktureras och att vi lägger in en spärr på låntagaren under Begränsningar | Nästa steg är att vi manuellt ändrar status till "På räkning" för de böcker som ska faktureras och att vi lägger in en spärr på låntagaren under Begränsningar | ||
<pre> | <pre> | ||
SELECT | SELECT | ||
− | branches.branchname | + | CONCAT(branches.branchname,'<br>', |
− | items.ccode | + | CASE WHEN items.ccode IS NULL |
− | items.location | + | THEN '--' |
− | items.itemcallnumber AS | + | ELSE items.ccode |
− | biblio.author | + | END,'<br>', |
− | biblio.title | + | CASE WHEN items.location IS NULL |
− | items.barcode | + | THEN '--' |
− | borrowers.cardnumber | + | ELSE |
− | borrowers.surname | + | authorised_values.lib |
− | borrowers.firstname AS | + | END,'<br>', |
+ | items.itemcallnumber) AS Placering, | ||
+ | CONCAT(CASE WHEN biblio.author IS NULL | ||
+ | THEN '' | ||
+ | ELSE biblio.author | ||
+ | END,'<br>', | ||
+ | biblio.title,'<br>', | ||
+ | items.barcode) AS Bok, | ||
+ | CONCAT(borrowers.cardnumber,'<br>', | ||
+ | borrowers.surname,'<br>', | ||
+ | borrowers.firstname) AS 'Låntagare', | ||
issues.date_due AS förfallodatum, | issues.date_due AS förfallodatum, | ||
items.itype AS exemplartyp, | items.itype AS exemplartyp, | ||
CASE | CASE | ||
− | WHEN items.itype | + | WHEN items.itype IN ('BARN TIDSK','TIDSKRIFT') |
+ | THEN '50' | ||
+ | WHEN items.itype IN ('BARN LJUD','BARNBOK','BARNMP3','BARNTAL','BOKCDBARN','BOKDAISYBA','BOKMP3BARN','MUSCDBARN','MUSIKBARN') | ||
THEN '100' | THEN '100' | ||
− | WHEN items.itype = ' | + | WHEN items.itype IN ('BLURAY','TV-SPEL','FILM','Fjarrlan') |
+ | THEN '600' | ||
+ | WHEN items.itype = 'LANGLAN' | ||
+ | THEN '150' | ||
+ | WHEN items.ccode IN ('Vux','Mag','Tillf') | ||
+ | THEN '250' | ||
+ | WHEN items.ccode IN ('Barn','BoU','Skoldepa','Ungdom') | ||
THEN '100' | THEN '100' | ||
− | WHEN items.itype | + | ELSE ' 999' |
− | THEN ' | + | END AS 'Schablonpris', |
− | WHEN items.itype | + | items.price AS 'Inköpspris', |
− | + | CASE | |
− | + | WHEN | |
+ | items.price | ||
+ | / | ||
+ | (CASE | ||
+ | WHEN items.itype IN ('BARN TIDSK','TIDSKRIFT') | ||
+ | THEN '50' | ||
+ | WHEN items.itype IN ('BARN LJUD','BARNBOK','BARNMP3','BARNTAL','BOKCDBARN','BOKDAISYBA','BOKMP3BARN','MUSCDBARN','MUSIKBARN') | ||
THEN '100' | THEN '100' | ||
− | WHEN items.itype | + | WHEN items.itype IN ('BLURAY','TV-SPEL','FILM','Fjarrlan') |
THEN '600' | THEN '600' | ||
− | WHEN items.itype = ' | + | WHEN items.itype = 'LANGLAN' |
+ | THEN '150' | ||
+ | WHEN items.ccode IN ('Vux','Mag','Tillf') | ||
THEN '250' | THEN '250' | ||
− | WHEN items. | + | WHEN items.ccode IN ('Barn','BoU','Skoldepa','Ungdom') |
− | |||
− | |||
THEN '100' | THEN '100' | ||
− | WHEN items.itype | + | ELSE ' 999' |
− | THEN ' | + | END) |
− | + | > '2' | |
+ | THEN | ||
+ | 'Mer än dubbla schablonpriset' | ||
+ | WHEN | ||
+ | items.price | ||
+ | / | ||
+ | (CASE | ||
+ | WHEN items.itype IN ('BARN TIDSK','TIDSKRIFT') | ||
+ | THEN '50' | ||
+ | WHEN items.itype IN ('BARN LJUD','BARNBOK','BARNMP3','BARNTAL','BOKCDBARN','BOKDAISYBA','BOKMP3BARN','MUSCDBARN','MUSIKBARN') | ||
THEN '100' | THEN '100' | ||
− | WHEN items.itype = ' | + | WHEN items.itype IN ('BLURAY','TV-SPEL','FILM','Fjarrlan') |
+ | THEN '600' | ||
+ | WHEN items.itype = 'LANGLAN' | ||
+ | THEN '150' | ||
+ | WHEN items.ccode IN ('Vux','Mag','Tillf') | ||
THEN '250' | THEN '250' | ||
− | WHEN items. | + | WHEN items.ccode IN ('Barn','BoU','Skoldepa','Ungdom') |
THEN '100' | THEN '100' | ||
− | + | ELSE ' 999' | |
− | + | END) | |
− | + | < '0.5' | |
− | + | THEN | |
− | + | 'Mindre än halva schablonpriset' | |
− | + | ELSE '' | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
END | END | ||
− | AS ' | + | AS 'Större avvikelse?' |
− | + | , | |
− | CONCAT('<a href=\"/cgi-bin/koha/ | + | CONCAT('<a href=\"/cgi-bin/koha/cataloguing/additem.pl?op=edititem&biblionumber=', items.biblionumber, '&itemnumber=',items.itemnumber,'\" target="_blank">', |
− | CONCAT('<a href=\"/cgi-bin/koha/ | + | CASE |
− | + | WHEN items.replacementprice IS NULL | |
+ | THEN '--' | ||
+ | ELSE | ||
+ | items.replacementprice | ||
+ | END, '</a>' ) AS 'Annat pris än schablon?', | ||
+ | CONCAT('<a href=\"/cgi-bin/koha/catalogue/moredetail.pl?itemnumber=', items.itemnumber, '&biblionumber=',biblio.biblionumber,'\" target="_blank">', items.barcode, '</a>' ) AS 'Sätt Hopplöst fall på det som inte ska faktureras.', | ||
+ | items.itemnumber | ||
FROM borrowers | FROM borrowers | ||
LEFT JOIN issues ON (borrowers.borrowernumber=issues.borrowernumber) | LEFT JOIN issues ON (borrowers.borrowernumber=issues.borrowernumber) | ||
LEFT JOIN items ON (issues.itemnumber=items.itemnumber) | LEFT JOIN items ON (issues.itemnumber=items.itemnumber) | ||
+ | LEFT JOIN authorised_values ON (items.location=authorised_values.authorised_value) | ||
LEFT JOIN biblio ON (items.biblionumber=biblio.biblionumber) | LEFT JOIN biblio ON (items.biblionumber=biblio.biblionumber) | ||
LEFT JOIN branches ON (items.homebranch=branches.branchcode) | LEFT JOIN branches ON (items.homebranch=branches.branchcode) | ||
− | WHERE (TO_DAYS(curdate())-TO_DAYS(date_due)) > '37' AND items.itemlost !=1 AND items.itemlost !=2 AND items.itemlost !=3 AND items.itemlost !=4 AND issues.branchcode = <<Utlånande bibliotek|branches>> | + | WHERE (TO_DAYS(curdate())-TO_DAYS(date_due)) > '37' AND items.itemlost !=1 AND items.itemlost !=2 AND items.itemlost !=3 AND items.itemlost !=4 AND items.itemlost !=5 AND issues.branchcode = <<Utlånande bibliotek|branches>> |
− | ORDER BY borrowers.cardnumber ASC, items.homebranch ASC,items.ccode ASC, items.location ASC, items.itemcallnumber ASC, biblio.author ASC,biblio.title ASC | + | ORDER BY borrowers.cardnumber ASC, items.homebranch ASC,items.ccode ASC, items.location ASC, items.itemcallnumber ASC, biblio.author ASC,biblio.title ASC</pre> |
− | </pre> | ||
− | == 3 | + | == 3 Fakturautskrift, spärra låntagaren, bevakning == |
Tredje steget är att skapa ett fakturaunderlag. | Tredje steget är att skapa ett fakturaunderlag. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
<pre> | <pre> | ||
SELECT | SELECT | ||
Rad 318: | Rad 168: | ||
lant.surname AS 'Lånad av efternamn', | lant.surname AS 'Lånad av efternamn', | ||
lant.firstname AS 'Lånad av förnamn', | lant.firstname AS 'Lånad av förnamn', | ||
− | + | CASE WHEN SUBSTRING(items.itemlost_on,1,10)=CURDATE() | |
− | + | THEN | |
− | + | CONCAT('<a href=\"/cgi-bin/koha/reports/guided_reports.pl?reports=705&phase=Run+this+report¶m_name=Borrowernumber&sql_params=',lant.borrowernumber,'\" target="_blank">Skriv ut faktura</a>' ) | |
+ | ELSE '' | ||
+ | END | ||
+ | as 'Skriv ut faktura', | ||
+ | CONCAT('<a href=\"/cgi-bin/koha/members/moremember.pl?borrowernumber=', lant.borrowernumber, '#reldebarments','\" target="_blank">', CASE | ||
+ | WHEN borrower_debarments.comment IS NULL | ||
+ | THEN '--' | ||
+ | ELSE (SELECT GROUP_CONCAT( DISTINCT BlocksInnerDets.BlocksDetails SEPARATOR '</br>') | ||
+ | FROM | ||
+ | (SELECT blocksInner.comment | ||
+ | AS BlocksDetails, blocksInner.borrowernumber | ||
+ | FROM borrower_debarments blocksInner | ||
+ | ) BlocksInnerDets | ||
+ | WHERE BlocksInnerDets.borrowernumber = lant.borrowernumber) | ||
+ | END, '</a>' ) AS 'Spärra låntagaren', | ||
CONCAT('<a href=\"/cgi-bin/koha/reserve/request.pl?biblionumber=', items.biblionumber, '&findborrower=', | CONCAT('<a href=\"/cgi-bin/koha/reserve/request.pl?biblionumber=', items.biblionumber, '&findborrower=', | ||
CASE | CASE | ||
Rad 436: | Rad 300: | ||
THEN 'kbrobevakning' | THEN 'kbrobevakning' | ||
WHEN issues.branchcode = 'lkav' | WHEN issues.branchcode = 'lkav' | ||
− | THEN ' | + | THEN 'kbrobevakning' |
ELSE '' | ELSE '' | ||
− | END, '</a>' ) AS 'Reservera för bevakning' | + | END, '</a>' ) AS 'Reservera för bevakning', |
+ | qu.surname AS 'Reserverad av' | ||
FROM items | FROM items | ||
Rad 447: | Rad 312: | ||
LEFT JOIN borrowers lant ON (issues.borrowernumber = lant.borrowernumber) | LEFT JOIN borrowers lant ON (issues.borrowernumber = lant.borrowernumber) | ||
LEFT JOIN borrowers qu ON (reserves.borrowernumber = qu.borrowernumber) | LEFT JOIN borrowers qu ON (reserves.borrowernumber = qu.borrowernumber) | ||
+ | LEFT JOIN borrower_debarments ON (borrower_debarments.borrowernumber=lant.borrowernumber) | ||
WHERE items.itemlost = 1 AND issues.branchcode = <<Utlånande bibliotek|branches>> | WHERE items.itemlost = 1 AND issues.branchcode = <<Utlånande bibliotek|branches>> | ||
− | ORDER BY qu.cardnumber ASC, lant.borrowernumber DESC | + | GROUP BY items.itemnumber |
+ | |||
+ | ORDER BY SUBSTRING(items.itemlost_on,1,10) DESC,qu.cardnumber ASC, lant.borrowernumber DESC</pre> | ||
+ | |||
+ | ==4 Faktura== | ||
+ | <pre> | ||
+ | SELECT | ||
+ | concat(CASE | ||
+ | WHEN adressat.categorycode = 'BARN' | ||
+ | THEN 'målsman för <br>' | ||
+ | WHEN adressat.categorycode = 'ELEVTIDA' | ||
+ | THEN 'målsman för <br>' | ||
+ | ELSE '' | ||
+ | END, | ||
+ | adressat.firstname, ' ', adressat.surname,'<br>', adressat.address,'<br>', | ||
+ | adressat.address2,'<br>', | ||
+ | adressat.zipcode,' ', | ||
+ | adressat.city) AS Adress, | ||
+ | p.attribute AS Personnummer | ||
+ | |||
+ | FROM borrowers adressat | ||
+ | LEFT JOIN issues ON issues.borrowernumber=adressat.borrowernumber | ||
+ | LEFT JOIN items ON items.itemnumber=issues.itemnumber | ||
+ | LEFT JOIN biblio ON (biblio.biblionumber=items.biblionumber) | ||
+ | LEFT JOIN borrower_attributes p ON (adressat.borrowernumber=p.borrowernumber) | ||
+ | WHERE items.itemlost = 1 AND adressat.borrowernumber = <<Borrowernumber>> AND SUBSTRING(items.itemlost_on,1,10) = CURDATE() | ||
+ | |||
+ | UNION | ||
+ | |||
+ | SELECT | ||
+ | CASE | ||
+ | WHEN | ||
+ | COUNT(items.itemnumber) = '1' | ||
+ | THEN | ||
+ | '<b>En försenad bok</b>' | ||
+ | ELSE | ||
+ | CONCAT('<b>',COUNT(items.itemnumber),' försenade böcker</b>') END | ||
+ | AS 'Lån', | ||
+ | '<b>Summa att betala</b>' AS 'Summa att betala' | ||
+ | FROM borrowers fakturerat | ||
+ | LEFT JOIN issues ON issues.borrowernumber=fakturerat.borrowernumber | ||
+ | LEFT JOIN items ON items.itemnumber=issues.itemnumber | ||
+ | LEFT JOIN biblio ON (biblio.biblionumber=items.biblionumber) | ||
+ | WHERE items.itemlost = 1 AND fakturerat.borrowernumber = <<Borrowernumber>> AND SUBSTRING(items.itemlost_on,1,10) = CURDATE() | ||
+ | |||
+ | UNION | ||
+ | |||
+ | SELECT | ||
+ | CASE | ||
+ | WHEN | ||
+ | COUNT(items.itemnumber) > '8' | ||
+ | THEN | ||
+ | CONCAT(SUBSTRING_INDEX(GROUP_CONCAT(DISTINCT biblio.title,' <br>streckkod: ',items.barcode,' <br>återlämningsdatum: ',items.onloan,' <br>pris: ',CASE | ||
+ | WHEN items.replacementprice IS NOT NULL | ||
+ | THEN CONCAT(items.replacementprice,' kronor') | ||
+ | WHEN items.itype IN ('BARN TIDSK','TIDSKRIFT') | ||
+ | THEN '50.00 kronor' | ||
+ | WHEN items.itype IN ('BARN LJUD','BARNBOK','BARNMP3','BARNTAL','BOKCDBARN','BOKDAISYBA','BOKMP3BARN','MUSCDBARN','MUSIKBARN') | ||
+ | THEN '100.00 kronor' | ||
+ | WHEN items.itype IN ('BLURAY','TV-SPEL','FILM','Fjarrlan') | ||
+ | THEN '600.00 kronor' | ||
+ | WHEN items.itype = 'LANGLAN' | ||
+ | THEN '150.00 kronor' | ||
+ | WHEN items.ccode IN ('Vux','Mag','Tillf') | ||
+ | THEN '250.00 kronor' | ||
+ | WHEN items.ccode IN ('Barn','BoU','Skoldepa','Ungdom') | ||
+ | THEN '100.00 kronor' | ||
+ | ELSE ' 999.00 kronor' | ||
+ | END | ||
+ | SEPARATOR '<p>'), '<p>', 8),'<p> och ytterligare ',COUNT(items.itemnumber) -8,' böcker, se ditt konto för fullständiga uppgifter') | ||
+ | ELSE | ||
+ | GROUP_CONCAT(DISTINCT biblio.title,' <br>streckkod: ',items.barcode,' <br>återlämningsdatum: ',items.onloan,' <br>pris: ',CASE | ||
+ | WHEN items.replacementprice IS NOT NULL | ||
+ | THEN CONCAT(items.replacementprice,' kronor') | ||
+ | WHEN items.itype IN ('BARN TIDSK','TIDSKRIFT') | ||
+ | THEN '50.00 kronor' | ||
+ | WHEN items.itype IN ('BARN LJUD','BARNBOK','BARNMP3','BARNTAL','BOKCDBARN','BOKDAISYBA','BOKMP3BARN','MUSCDBARN','MUSIKBARN') | ||
+ | THEN '100.00 kronor' | ||
+ | WHEN items.itype IN ('BLURAY','TV-SPEL','FILM','Fjarrlan') | ||
+ | THEN '600.00 kronor' | ||
+ | WHEN items.itype = 'LANGLAN' | ||
+ | THEN '150.00 kronor' | ||
+ | WHEN items.ccode IN ('Vux','Mag','Tillf') | ||
+ | THEN '250.00 kronor' | ||
+ | WHEN items.ccode IN ('Barn','BoU','Skoldepa','Ungdom') | ||
+ | THEN '100.00 kronor' | ||
+ | ELSE ' 999.00 kronor' | ||
+ | END | ||
+ | SEPARATOR '<p>') | ||
+ | END | ||
+ | , | ||
+ | |||
+ | SUM(CASE | ||
+ | WHEN items.replacementprice IS NOT NULL | ||
+ | THEN items.replacementprice | ||
+ | WHEN items.itype IN ('BARN TIDSK','TIDSKRIFT') | ||
+ | THEN 50.00 | ||
+ | WHEN items.itype IN ('BARN LJUD','BARNBOK','BARNMP3','BARNTAL','BOKCDBARN','BOKDAISYBA','BOKMP3BARN','MUSCDBARN','MUSIKBARN') | ||
+ | THEN 100.00 | ||
+ | WHEN items.itype IN ('BLURAY','TV-SPEL','FILM','Fjarrlan') | ||
+ | THEN 600.00 | ||
+ | WHEN items.itype = 'LANGLAN' | ||
+ | THEN 150.00 | ||
+ | WHEN items.ccode IN ('Vux','Mag','Tillf') | ||
+ | THEN 250.00 | ||
+ | WHEN items.ccode IN ('Barn','BoU','Skoldepa','Ungdom') | ||
+ | THEN 100.00 | ||
+ | ELSE 999.00 | ||
+ | END) | ||
+ | |||
+ | FROM borrowers fakturerat | ||
+ | LEFT JOIN issues ON issues.borrowernumber=fakturerat.borrowernumber | ||
+ | LEFT JOIN items ON items.itemnumber=issues.itemnumber | ||
+ | LEFT JOIN biblio ON (biblio.biblionumber=items.biblionumber) | ||
+ | WHERE items.itemlost = 1 AND fakturerat.borrowernumber = <<Borrowernumber>> AND SUBSTRING(items.itemlost_on,1,10) = CURDATE() | ||
+ | |||
+ | UNION | ||
+ | |||
+ | SELECT '<b>Lämna tillbaks boken/böckerna så fort som möjligt så slipper du betala den här fakturan</b>' AS 'One', | ||
+ | '' AS 'Two' | ||
+ | |||
+ | UNION | ||
+ | |||
+ | SELECT CONCAT(branches.branchname,'<br>',branches.branchphone,'<br>',branches.branchemail), | ||
+ | CASE | ||
+ | WHEN branches.branchcode IN ('GULL','8BYO','8REG','FGBS','HOVA') | ||
+ | THEN '<img src="https://www.skovde.se/globalassets/_2018/kultur--fritid/stadsbiblioteket/bibliotek-mellansjo/gullspang-35px.jpg">' | ||
+ | WHEN branches.branchcode IN ('HJO') | ||
+ | THEN '<img src="https://www.skovde.se/globalassets/_2018/kultur--fritid/stadsbiblioteket/bibliotek-mellansjo/hjo-35px.jpg">' | ||
+ | WHEN branches.branchcode IN ('KABO','8BYL','8BYM','KSTR') | ||
+ | THEN '<img src="https://www.skovde.se/globalassets/_2018/kultur--fritid/stadsbiblioteket/bibliotek-mellansjo/karlsborg-35px.jpg">' | ||
+ | WHEN branches.branchcode IN ('MARI','8BYQ','MKRI','MVAN','VAGY') | ||
+ | THEN '<img src="https://www.skovde.se/globalassets/_2018/kultur--fritid/stadsbiblioteket/bibliotek-mellansjo/mariestad-35px.jpg">' | ||
+ | WHEN branches.branchcode IN ('SKSB','8BXQ','8BXZ','8BYA','8BYB','8BYC','8BYR','KBRO','LKAV','SKGY','SKGZ','SKBO','SKKO','SKPO') | ||
+ | THEN '<img src="https://www.skovde.se/globalassets/_2018/kultur--fritid/stadsbiblioteket/bibliotek-mellansjo/skovde-35px.jpg">' | ||
+ | WHEN branches.branchcode IN ('TIKF','8NYB','TIBOALDRE') | ||
+ | THEN '<img src="https://www.skovde.se/globalassets/_2018/kultur--fritid/stadsbiblioteket/bibliotek-mellansjo/tibro-35px.jpg">' | ||
+ | WHEN branches.branchcode IN ('TIDA','TEKE','TFOR','THOK','TKRI','TVAL') | ||
+ | THEN '<img src="https://www.skovde.se/globalassets/_2018/kultur--fritid/stadsbiblioteket/bibliotek-mellansjo/tidaholm-35px.jpg">' | ||
+ | WHEN branches.branchcode IN ('TORE','8BYI','8BYS') | ||
+ | THEN '<img src="https://www.skovde.se/globalassets/_2018/kultur--fritid/stadsbiblioteket/bibliotek-mellansjo/toreboda-35px.jpg">' | ||
+ | ELSE | ||
+ | '' | ||
+ | END | ||
+ | |||
+ | FROM borrowers adressat | ||
+ | LEFT JOIN issues ON issues.borrowernumber=adressat.borrowernumber | ||
+ | LEFT JOIN items ON items.itemnumber=issues.itemnumber | ||
+ | LEFT JOIN branches ON (branches.branchcode=issues.branchcode) | ||
+ | WHERE items.itemlost = 1 AND adressat.borrowernumber = <<Borrowernumber>> AND SUBSTRING(items.itemlost_on,1,10) = CURDATE() | ||
</pre> | </pre> |
Versionen från 2 december 2020 kl. 13.22
Beskrivning av Bibliotek Mellansjös faktureringsprocess
Bibliotek Mellansjös faktureringsprocess är lite halvmanuell, det är inte ett fullfjädrat faktureringssystem, utan slutresultatet är en pdf som går att ladda upp i kommunens ekonomisystem. Låntagaren ska få faktura från det bibliotek man lånade boken på, oavsett var den egentligen hör hemma.
vi har gjort följande inställningar i systempreferenserna:
DefaultLongOverdueChargeValue är tomt, eftersom vi inte vill att ersättningsbeloppet ksa synas i systemet
DefaultLongOverdueLostValue är tomt, eftersom vi vill ha kontroll över vilka böcker som blir fakturerade
MarkLostItemsAsReturned skulle vi helst vilja ha helt tomt, men tyvärr måste man välja något där, så vi har valt "from the holds to pull list". Vi vill nämligen att böckerna ska finnas kvar på låntagarens konto
Vi använder inte cronjobbet Long overdues
Pocessen består av tre rapporter som körs i denna ordning:
1 Leta-lista
Det första vi gör är att ta ut en lista på böcker som inte har blivit återlämnade, fast de är mer än 37 dagar sena, så vi kan leta efter dem i hyllan i fall vi missat att avregistrera dem i återlämningen.
SELECT branches.branchname AS Bibliotek, items.ccode AS Samling, authorised_values.lib AS Placering, items.itemcallnumber AS Hyllsignum, biblio.author AS Författare, CASE WHEN biblio.frameworkcode='SER' AND items.enumchron IS NOT NULL THEN CONCAT(biblio.title,'<br>',items.enumchron) ELSE biblio.title END AS Titel, items.barcode AS Streckkod, items.itype AS Exemplartyp FROM borrowers LEFT JOIN issues ON (borrowers.borrowernumber=issues.borrowernumber) LEFT JOIN items ON (issues.itemnumber=items.itemnumber) LEFT JOIN authorised_values ON (items.location=authorised_values.authorised_value) LEFT JOIN biblio ON (items.biblionumber=biblio.biblionumber) LEFT JOIN branches ON (items.homebranch=branches.branchcode) WHERE (TO_DAYS(curdate())-TO_DAYS(date_due)) > '37' AND items.itemlost !=1 AND items.itemlost !=2 AND items.itemlost !=3 AND items.itemlost !=4 AND items.itemlost !=5 AND issues.branchcode = <<Utlånande bibliotek|branches>> ORDER BY items.homebranch ASC,items.ccode ASC, items.location ASC, items.itemcallnumber ASC, biblio.author ASC,biblio.title ASC
2 Kontrolllista
Nästa steg är att vi manuellt ändrar status till "På räkning" för de böcker som ska faktureras och att vi lägger in en spärr på låntagaren under Begränsningar
SELECT CONCAT(branches.branchname,'<br>', CASE WHEN items.ccode IS NULL THEN '--' ELSE items.ccode END,'<br>', CASE WHEN items.location IS NULL THEN '--' ELSE authorised_values.lib END,'<br>', items.itemcallnumber) AS Placering, CONCAT(CASE WHEN biblio.author IS NULL THEN '' ELSE biblio.author END,'<br>', biblio.title,'<br>', items.barcode) AS Bok, CONCAT(borrowers.cardnumber,'<br>', borrowers.surname,'<br>', borrowers.firstname) AS 'Låntagare', issues.date_due AS förfallodatum, items.itype AS exemplartyp, CASE WHEN items.itype IN ('BARN TIDSK','TIDSKRIFT') THEN '50' WHEN items.itype IN ('BARN LJUD','BARNBOK','BARNMP3','BARNTAL','BOKCDBARN','BOKDAISYBA','BOKMP3BARN','MUSCDBARN','MUSIKBARN') THEN '100' WHEN items.itype IN ('BLURAY','TV-SPEL','FILM','Fjarrlan') THEN '600' WHEN items.itype = 'LANGLAN' THEN '150' WHEN items.ccode IN ('Vux','Mag','Tillf') THEN '250' WHEN items.ccode IN ('Barn','BoU','Skoldepa','Ungdom') THEN '100' ELSE ' 999' END AS 'Schablonpris', items.price AS 'Inköpspris', CASE WHEN items.price / (CASE WHEN items.itype IN ('BARN TIDSK','TIDSKRIFT') THEN '50' WHEN items.itype IN ('BARN LJUD','BARNBOK','BARNMP3','BARNTAL','BOKCDBARN','BOKDAISYBA','BOKMP3BARN','MUSCDBARN','MUSIKBARN') THEN '100' WHEN items.itype IN ('BLURAY','TV-SPEL','FILM','Fjarrlan') THEN '600' WHEN items.itype = 'LANGLAN' THEN '150' WHEN items.ccode IN ('Vux','Mag','Tillf') THEN '250' WHEN items.ccode IN ('Barn','BoU','Skoldepa','Ungdom') THEN '100' ELSE ' 999' END) > '2' THEN 'Mer än dubbla schablonpriset' WHEN items.price / (CASE WHEN items.itype IN ('BARN TIDSK','TIDSKRIFT') THEN '50' WHEN items.itype IN ('BARN LJUD','BARNBOK','BARNMP3','BARNTAL','BOKCDBARN','BOKDAISYBA','BOKMP3BARN','MUSCDBARN','MUSIKBARN') THEN '100' WHEN items.itype IN ('BLURAY','TV-SPEL','FILM','Fjarrlan') THEN '600' WHEN items.itype = 'LANGLAN' THEN '150' WHEN items.ccode IN ('Vux','Mag','Tillf') THEN '250' WHEN items.ccode IN ('Barn','BoU','Skoldepa','Ungdom') THEN '100' ELSE ' 999' END) < '0.5' THEN 'Mindre än halva schablonpriset' ELSE '' END AS 'Större avvikelse?' , CONCAT('<a href=\"/cgi-bin/koha/cataloguing/additem.pl?op=edititem&biblionumber=', items.biblionumber, '&itemnumber=',items.itemnumber,'\" target="_blank">', CASE WHEN items.replacementprice IS NULL THEN '--' ELSE items.replacementprice END, '</a>' ) AS 'Annat pris än schablon?', CONCAT('<a href=\"/cgi-bin/koha/catalogue/moredetail.pl?itemnumber=', items.itemnumber, '&biblionumber=',biblio.biblionumber,'\" target="_blank">', items.barcode, '</a>' ) AS 'Sätt Hopplöst fall på det som inte ska faktureras.', items.itemnumber FROM borrowers LEFT JOIN issues ON (borrowers.borrowernumber=issues.borrowernumber) LEFT JOIN items ON (issues.itemnumber=items.itemnumber) LEFT JOIN authorised_values ON (items.location=authorised_values.authorised_value) LEFT JOIN biblio ON (items.biblionumber=biblio.biblionumber) LEFT JOIN branches ON (items.homebranch=branches.branchcode) WHERE (TO_DAYS(curdate())-TO_DAYS(date_due)) > '37' AND items.itemlost !=1 AND items.itemlost !=2 AND items.itemlost !=3 AND items.itemlost !=4 AND items.itemlost !=5 AND issues.branchcode = <<Utlånande bibliotek|branches>> ORDER BY borrowers.cardnumber ASC, items.homebranch ASC,items.ccode ASC, items.location ASC, items.itemcallnumber ASC, biblio.author ASC,biblio.title ASC
3 Fakturautskrift, spärra låntagaren, bevakning
Tredje steget är att skapa ett fakturaunderlag.
SELECT biblio.author AS Författare, biblio.title AS Titel, items.barcode AS Streckkod, issues.branchcode AS 'utlånande bibliotek', items.itemlost_on AS 'Fakturerad den', lant.cardnumber AS 'Lånad av streckkod', lant.surname AS 'Lånad av efternamn', lant.firstname AS 'Lånad av förnamn', CASE WHEN SUBSTRING(items.itemlost_on,1,10)=CURDATE() THEN CONCAT('<a href=\"/cgi-bin/koha/reports/guided_reports.pl?reports=705&phase=Run+this+report¶m_name=Borrowernumber&sql_params=',lant.borrowernumber,'\" target="_blank">Skriv ut faktura</a>' ) ELSE '' END as 'Skriv ut faktura', CONCAT('<a href=\"/cgi-bin/koha/members/moremember.pl?borrowernumber=', lant.borrowernumber, '#reldebarments','\" target="_blank">', CASE WHEN borrower_debarments.comment IS NULL THEN '--' ELSE (SELECT GROUP_CONCAT( DISTINCT BlocksInnerDets.BlocksDetails SEPARATOR '</br>') FROM (SELECT blocksInner.comment AS BlocksDetails, blocksInner.borrowernumber FROM borrower_debarments blocksInner ) BlocksInnerDets WHERE BlocksInnerDets.borrowernumber = lant.borrowernumber) END, '</a>' ) AS 'Spärra låntagaren', CONCAT('<a href=\"/cgi-bin/koha/reserve/request.pl?biblionumber=', items.biblionumber, '&findborrower=', CASE WHEN issues.branchcode = '8bxq' THEN 'sksbbevakning' WHEN issues.branchcode = '8bxz' THEN 'sksbbevakning' WHEN issues.branchcode = '8bya' THEN 'sksbbevakning' WHEN issues.branchcode = '8byb' THEN 'sksbbevakning' WHEN issues.branchcode = '8byc' THEN 'sksbbevakning' WHEN issues.branchcode = '8byi' THEN 'torebevakning' WHEN issues.branchcode = '8byl' THEN 'kabobevakning' WHEN issues.branchcode = '8bym' THEN 'kabobevakning' WHEN issues.branchcode = '8byo' THEN 'gullbevakning' WHEN issues.branchcode = '8byq' THEN 'maribevakning' WHEN issues.branchcode = '8byr' THEN 'sksbbevakning' WHEN issues.branchcode = '8bys' THEN 'torebevakning' WHEN issues.branchcode = '8nyb' THEN 'tikfbevakning' WHEN issues.branchcode = '8reg' THEN 'gullbevakning' WHEN issues.branchcode = 'gull' THEN 'gullbevakning' WHEN issues.branchcode = 'hjo' THEN 'hjobevakning' WHEN issues.branchcode = 'hova' THEN 'gullbevakning' WHEN issues.branchcode = 'kabo' THEN 'kabobevakning' WHEN issues.branchcode = 'kstr' THEN 'kabobevakning' WHEN issues.branchcode = 'mari' THEN 'maribevakning' WHEN issues.branchcode = 'sksb' THEN 'sksbbevakning' WHEN issues.branchcode = 'tida' THEN 'tidabevakning' WHEN issues.branchcode = 'tikf' THEN 'tikfbevakning' WHEN issues.branchcode = 'tore' THEN 'torebevakning' WHEN issues.branchcode = 'skgy' THEN 'skgybevakning' WHEN issues.branchcode = 'skgz' THEN 'skgybevakning' WHEN issues.branchcode = 'kbro' THEN 'kbrobevakning' WHEN issues.branchcode = 'lkav' THEN 'kbrobevakning' ELSE '' END,'\" target="_blank">', CASE WHEN issues.branchcode = '8bxq' THEN 'sksbbevakning' WHEN issues.branchcode = '8bxz' THEN 'sksbbevakning' WHEN issues.branchcode = '8bya' THEN 'sksbbevakning' WHEN issues.branchcode = '8byb' THEN 'sksbbevakning' WHEN issues.branchcode = '8byc' THEN 'sksbbevakning' WHEN issues.branchcode = '8byi' THEN 'torebevakning' WHEN issues.branchcode = '8byl' THEN 'kabobevakning' WHEN issues.branchcode = '8bym' THEN 'kabobevakning' WHEN issues.branchcode = '8byo' THEN 'gullbevakning' WHEN issues.branchcode = '8byq' THEN 'maribevakning' WHEN issues.branchcode = '8byr' THEN 'sksbbevakning' WHEN issues.branchcode = '8bys' THEN 'torebevakning' WHEN issues.branchcode = '8nyb' THEN 'tikfbevakning' WHEN issues.branchcode = '8reg' THEN 'gullbevakning' WHEN issues.branchcode = 'gull' THEN 'gullbevakning' WHEN issues.branchcode = 'hjo' THEN 'hjobevakning' WHEN issues.branchcode = 'hova' THEN 'gullbevakning' WHEN issues.branchcode = 'kabo' THEN 'kabobevakning' WHEN issues.branchcode = 'kstr' THEN 'kabobevakning' WHEN issues.branchcode = 'mari' THEN 'maribevakning' WHEN issues.branchcode = 'sksb' THEN 'sksbbevakning' WHEN issues.branchcode = 'tida' THEN 'tidabevakning' WHEN issues.branchcode = 'tikf' THEN 'tikfbevakning' WHEN issues.branchcode = 'tore' THEN 'torebevakning' WHEN issues.branchcode = 'skgy' THEN 'skgybevakning' WHEN issues.branchcode = 'skgz' THEN 'skgzbevakning' WHEN issues.branchcode = 'kbro' THEN 'kbrobevakning' WHEN issues.branchcode = 'lkav' THEN 'kbrobevakning' ELSE '' END, '</a>' ) AS 'Reservera för bevakning', qu.surname AS 'Reserverad av' FROM items LEFT JOIN reserves ON (items.itemnumber = reserves.itemnumber) LEFT JOIN issues ON (items.itemnumber = issues.itemnumber) LEFT JOIN biblio ON (items.biblionumber = biblio.biblionumber) LEFT JOIN borrowers lant ON (issues.borrowernumber = lant.borrowernumber) LEFT JOIN borrowers qu ON (reserves.borrowernumber = qu.borrowernumber) LEFT JOIN borrower_debarments ON (borrower_debarments.borrowernumber=lant.borrowernumber) WHERE items.itemlost = 1 AND issues.branchcode = <<Utlånande bibliotek|branches>> GROUP BY items.itemnumber ORDER BY SUBSTRING(items.itemlost_on,1,10) DESC,qu.cardnumber ASC, lant.borrowernumber DESC
4 Faktura
SELECT concat(CASE WHEN adressat.categorycode = 'BARN' THEN 'målsman för <br>' WHEN adressat.categorycode = 'ELEVTIDA' THEN 'målsman för <br>' ELSE '' END, adressat.firstname, ' ', adressat.surname,'<br>', adressat.address,'<br>', adressat.address2,'<br>', adressat.zipcode,' ', adressat.city) AS Adress, p.attribute AS Personnummer FROM borrowers adressat LEFT JOIN issues ON issues.borrowernumber=adressat.borrowernumber LEFT JOIN items ON items.itemnumber=issues.itemnumber LEFT JOIN biblio ON (biblio.biblionumber=items.biblionumber) LEFT JOIN borrower_attributes p ON (adressat.borrowernumber=p.borrowernumber) WHERE items.itemlost = 1 AND adressat.borrowernumber = <<Borrowernumber>> AND SUBSTRING(items.itemlost_on,1,10) = CURDATE() UNION SELECT CASE WHEN COUNT(items.itemnumber) = '1' THEN '<b>En försenad bok</b>' ELSE CONCAT('<b>',COUNT(items.itemnumber),' försenade böcker</b>') END AS 'Lån', '<b>Summa att betala</b>' AS 'Summa att betala' FROM borrowers fakturerat LEFT JOIN issues ON issues.borrowernumber=fakturerat.borrowernumber LEFT JOIN items ON items.itemnumber=issues.itemnumber LEFT JOIN biblio ON (biblio.biblionumber=items.biblionumber) WHERE items.itemlost = 1 AND fakturerat.borrowernumber = <<Borrowernumber>> AND SUBSTRING(items.itemlost_on,1,10) = CURDATE() UNION SELECT CASE WHEN COUNT(items.itemnumber) > '8' THEN CONCAT(SUBSTRING_INDEX(GROUP_CONCAT(DISTINCT biblio.title,' <br>streckkod: ',items.barcode,' <br>återlämningsdatum: ',items.onloan,' <br>pris: ',CASE WHEN items.replacementprice IS NOT NULL THEN CONCAT(items.replacementprice,' kronor') WHEN items.itype IN ('BARN TIDSK','TIDSKRIFT') THEN '50.00 kronor' WHEN items.itype IN ('BARN LJUD','BARNBOK','BARNMP3','BARNTAL','BOKCDBARN','BOKDAISYBA','BOKMP3BARN','MUSCDBARN','MUSIKBARN') THEN '100.00 kronor' WHEN items.itype IN ('BLURAY','TV-SPEL','FILM','Fjarrlan') THEN '600.00 kronor' WHEN items.itype = 'LANGLAN' THEN '150.00 kronor' WHEN items.ccode IN ('Vux','Mag','Tillf') THEN '250.00 kronor' WHEN items.ccode IN ('Barn','BoU','Skoldepa','Ungdom') THEN '100.00 kronor' ELSE ' 999.00 kronor' END SEPARATOR '<p>'), '<p>', 8),'<p> och ytterligare ',COUNT(items.itemnumber) -8,' böcker, se ditt konto för fullständiga uppgifter') ELSE GROUP_CONCAT(DISTINCT biblio.title,' <br>streckkod: ',items.barcode,' <br>återlämningsdatum: ',items.onloan,' <br>pris: ',CASE WHEN items.replacementprice IS NOT NULL THEN CONCAT(items.replacementprice,' kronor') WHEN items.itype IN ('BARN TIDSK','TIDSKRIFT') THEN '50.00 kronor' WHEN items.itype IN ('BARN LJUD','BARNBOK','BARNMP3','BARNTAL','BOKCDBARN','BOKDAISYBA','BOKMP3BARN','MUSCDBARN','MUSIKBARN') THEN '100.00 kronor' WHEN items.itype IN ('BLURAY','TV-SPEL','FILM','Fjarrlan') THEN '600.00 kronor' WHEN items.itype = 'LANGLAN' THEN '150.00 kronor' WHEN items.ccode IN ('Vux','Mag','Tillf') THEN '250.00 kronor' WHEN items.ccode IN ('Barn','BoU','Skoldepa','Ungdom') THEN '100.00 kronor' ELSE ' 999.00 kronor' END SEPARATOR '<p>') END , SUM(CASE WHEN items.replacementprice IS NOT NULL THEN items.replacementprice WHEN items.itype IN ('BARN TIDSK','TIDSKRIFT') THEN 50.00 WHEN items.itype IN ('BARN LJUD','BARNBOK','BARNMP3','BARNTAL','BOKCDBARN','BOKDAISYBA','BOKMP3BARN','MUSCDBARN','MUSIKBARN') THEN 100.00 WHEN items.itype IN ('BLURAY','TV-SPEL','FILM','Fjarrlan') THEN 600.00 WHEN items.itype = 'LANGLAN' THEN 150.00 WHEN items.ccode IN ('Vux','Mag','Tillf') THEN 250.00 WHEN items.ccode IN ('Barn','BoU','Skoldepa','Ungdom') THEN 100.00 ELSE 999.00 END) FROM borrowers fakturerat LEFT JOIN issues ON issues.borrowernumber=fakturerat.borrowernumber LEFT JOIN items ON items.itemnumber=issues.itemnumber LEFT JOIN biblio ON (biblio.biblionumber=items.biblionumber) WHERE items.itemlost = 1 AND fakturerat.borrowernumber = <<Borrowernumber>> AND SUBSTRING(items.itemlost_on,1,10) = CURDATE() UNION SELECT '<b>Lämna tillbaks boken/böckerna så fort som möjligt så slipper du betala den här fakturan</b>' AS 'One', '' AS 'Two' UNION SELECT CONCAT(branches.branchname,'<br>',branches.branchphone,'<br>',branches.branchemail), CASE WHEN branches.branchcode IN ('GULL','8BYO','8REG','FGBS','HOVA') THEN '<img src="https://www.skovde.se/globalassets/_2018/kultur--fritid/stadsbiblioteket/bibliotek-mellansjo/gullspang-35px.jpg">' WHEN branches.branchcode IN ('HJO') THEN '<img src="https://www.skovde.se/globalassets/_2018/kultur--fritid/stadsbiblioteket/bibliotek-mellansjo/hjo-35px.jpg">' WHEN branches.branchcode IN ('KABO','8BYL','8BYM','KSTR') THEN '<img src="https://www.skovde.se/globalassets/_2018/kultur--fritid/stadsbiblioteket/bibliotek-mellansjo/karlsborg-35px.jpg">' WHEN branches.branchcode IN ('MARI','8BYQ','MKRI','MVAN','VAGY') THEN '<img src="https://www.skovde.se/globalassets/_2018/kultur--fritid/stadsbiblioteket/bibliotek-mellansjo/mariestad-35px.jpg">' WHEN branches.branchcode IN ('SKSB','8BXQ','8BXZ','8BYA','8BYB','8BYC','8BYR','KBRO','LKAV','SKGY','SKGZ','SKBO','SKKO','SKPO') THEN '<img src="https://www.skovde.se/globalassets/_2018/kultur--fritid/stadsbiblioteket/bibliotek-mellansjo/skovde-35px.jpg">' WHEN branches.branchcode IN ('TIKF','8NYB','TIBOALDRE') THEN '<img src="https://www.skovde.se/globalassets/_2018/kultur--fritid/stadsbiblioteket/bibliotek-mellansjo/tibro-35px.jpg">' WHEN branches.branchcode IN ('TIDA','TEKE','TFOR','THOK','TKRI','TVAL') THEN '<img src="https://www.skovde.se/globalassets/_2018/kultur--fritid/stadsbiblioteket/bibliotek-mellansjo/tidaholm-35px.jpg">' WHEN branches.branchcode IN ('TORE','8BYI','8BYS') THEN '<img src="https://www.skovde.se/globalassets/_2018/kultur--fritid/stadsbiblioteket/bibliotek-mellansjo/toreboda-35px.jpg">' ELSE '' END FROM borrowers adressat LEFT JOIN issues ON issues.borrowernumber=adressat.borrowernumber LEFT JOIN items ON items.itemnumber=issues.itemnumber LEFT JOIN branches ON (branches.branchcode=issues.branchcode) WHERE items.itemlost = 1 AND adressat.borrowernumber = <<Borrowernumber>> AND SUBSTRING(items.itemlost_on,1,10) = CURDATE()