--- /dev/null
+-- Create call numbers
+SELECT evergreen.populate_call_number(6, 'EQUIPMENT-1', 'IMPORT BOOKING', 1);
+SELECT evergreen.populate_call_number(6, 'EQUIPMENT-2', 'IMPORT BOOKING', 1);
+SELECT evergreen.populate_call_number(6, 'EQUIPMENT-3', 'IMPORT BOOKING', 1);
+SELECT evergreen.populate_call_number(6, 'EQUIPMENT-4', 'IMPORT BOOKING', 1);
+SELECT evergreen.populate_call_number(6, 'EQUIPMENT-5', 'IMPORT BOOKING', 1);
+SELECT evergreen.populate_call_number(9, 'TECH', 'IMPORT BOOKING', 1);
+
+
+-- Create copies
+SELECT evergreen.populate_copy(6, 6, 'EQUIP', 'EQUIPMENT');
+SELECT evergreen.populate_copy(9, 9, 'TECH', 'TECH');
+
--- /dev/null
+\set bib_tag '''IMPORT BOOKING'''
+
+INSERT INTO marcxml_import (tag, marc)
+VALUES (:bib_tag, '<record xmlns="http://www.loc.gov/MARC21/slim"><leader>00434crm a2200133Ki 4500</leader>
+<controlfield tag="005">20180321175835.0</controlfield>
+<controlfield tag="008">150922s2015 xxx1 en d681 50072eng d</controlfield><datafield tag="024" ind1="1" ind2=" "><subfield code="a">681495007240</subfield></datafield><datafield tag="090" ind1=" " ind2=" "><subfield code="a">KOBO EREADER</subfield></datafield><datafield tag="245" ind1="0" ind2="0"><subfield code="a">Kobo Aura ONE ereader.</subfield></datafield><datafield tag="300" ind1=" " ind2=" "><subfield code="a">1 ereader : </subfield><subfield code="b"> electronic texts, digital files ; </subfield><subfield code="c"> 20 x 14 x 1 cm in case, </subfield><subfield code="e"> + power cord.</subfield></datafield><datafield tag="336" ind1=" " ind2=" "><subfield code="a">text </subfield><subfield code="b"> txt </subfield><subfield code="2"> rdacontent</subfield></datafield><datafield tag="338" ind1=" " ind2=" "><subfield code="a">object </subfield><subfield code="2"> rdacarrier</subfield></datafield><datafield tag="655" ind1=" " ind2="0"><subfield code="a">Electronic book readers.</subfield></datafield></record>'),
+(:bib_tag, '<record mlns="http://www.loc.gov/MARC21/slim"><leader>00395crm a2200121Ki 4500</leader>
+<controlfield tag="005">20180321175835.0</controlfield>
+<controlfield tag="008">150922s2015 xxx1 en d681 50072eng d</controlfield><datafield tag="024" ind1="1" ind2=" "><subfield code="a">681495007240</subfield></datafield><datafield tag="090" ind1=" " ind2=" "><subfield code="a">TREETON LAPTOP</subfield></datafield><datafield tag="245" ind1="0" ind2="0"><subfield code="a">VeryPC Treeton Laptop.</subfield></datafield><datafield tag="300" ind1=" " ind2=" "><subfield code="a">1 laptop computer : </subfield><subfield code="b"> electronic texts, digital files ; </subfield><subfield code="c"> 21 x 27 x 7 cm in case, </subfield><subfield code="e"> + power cord.</subfield></datafield><datafield tag="338" ind1=" " ind2=" "><subfield code="a">object </subfield><subfield code="2"> rdacarrier</subfield></datafield><datafield tag="655" ind1=" " ind2="0"><subfield code="a">Laptop computers.</subfield></datafield></record>');
--- /dev/null
+-- Create booking resource types
+INSERT INTO booking.resource_type(id, name, owner, catalog_item, transferable)
+VALUES (555, 'Meeting room', 1, False, True),
+(556, 'Phone charger', 3, False, True);
+
+-- Create booking resource types from MARC
+SELECT evergreen.populate_booking_resource_type(6, 'IMPORT BOOKING');
+
+-- Create booking resources
+INSERT INTO booking.resource(owner, type, barcode)
+VALUES (4, 555, 'ROOM1231'),
+(4, 555, 'ROOM1232'),
+(4, 555, 'ROOM1233' ),
+(7, 555, 'ROOM2341'),
+(7, 555, 'ROOM2342'),
+(7, 555, 'ROOM2343'),
+(7, 555, 'ROOM2344'),
+(7, 555, 'ROOM2345'),
+(7, 555, 'ROOM2346'),
+(6, 556, 'IPHONE-CHARGER-01'),
+(6, 556, 'IPHONE-CHARGER-02'),
+(7, 556, 'ANDROID-CHARGER-01'),
+(7, 556, 'IPHONE-CHARGER-03'),
+(9, 556, 'IPHONE-CHARGER-04'),
+(9, 556, 'IPHONE-CHARGER-05');
+
+-- Create booking resources from item records
+SELECT evergreen.populate_booking_resource('EQUIP');
+/**
+ * Create a booking resource type for all
+ * bib records with a specific last_xact_id
+*/
+CREATE FUNCTION evergreen.populate_booking_resource_type
+ (ownlib INTEGER, bib_tag TEXT)
+RETURNS void AS $$
+ INSERT INTO booking.resource_type(name, owner, catalog_item, transferable, record)
+ SELECT TRIM (' ./' FROM (XPATH(
+ '//marc:datafield[@tag="245"]/marc:subfield[@code="a"]/text()',
+ marc::XML,
+ ARRAY[ARRAY['marc', 'http://www.loc.gov/MARC21/slim']]
+ ))[1]::TEXT),
+ $1, True, True, id
+ FROM biblio.record_entry
+ WHERE id > 0 AND last_xact_id = $2;
+$$ LANGUAGE SQL;
+
+/**
+ * Make all items with barcodes that start
+ * with a certain substring bookable
+*/
+
+CREATE FUNCTION evergreen.populate_booking_resource
+ (barcode_start TEXT)
+RETURNS void AS $$
+ INSERT INTO booking.resource(owner, type, barcode)
+ SELECT circ_lib, resource_type.id, barcode FROM asset.copy
+ INNER JOIN asset.call_number on copy.call_number=call_number.id
+ INNER JOIN booking.resource_type on call_number.record=resource_type.record
+ WHERE barcode LIKE $1 || '%';
+$$ LANGUAGE SQL;
(INTEGER, INTEGER, BIGINT, INTEGER, TEXT, TEXT, TEXT, BOOLEAN);
DROP FUNCTION evergreen.populate_hold
(TEXT, BIGINT, INTEGER, INTEGER, INTEGER, BOOLEAN, TIMESTAMP WITH TIME ZONE, TEXT);
-
+DROP FUNCTION evergreen.populate_booking_resource_type(INTEGER, TEXT);
+DROP FUNCTION evergreen.populate_booking_resource(TEXT);
-- load metarecord bibs
\i bibs_mr.sql
+-- load booking bibs
+\i bibs_booking.sql
+
-- insert all loaded bibs into the biblio.record_entry in insert order
INSERT INTO biblio.record_entry (marc, last_xact_id)
SELECT marc, tag FROM marcxml_import ORDER BY id;
-- load MR copies, etc.
\i assets_mr.sql
+-- load booking assets
+\i assets_booking.sql
+
+-- load booking resource types and resources
+\i booking_resources_types.sql
+
-- load survey data
\i surveys.sql