more import dances
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 7 Aug 2006 17:05:20 +0000 (17:05 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 7 Aug 2006 17:05:20 +0000 (17:05 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@5334 dcc99617-32d9-48b4-a31d-7c20da2025e4

Evergreen/src/extras/import/import_legacy_closings.pl [new file with mode: 0755]
Evergreen/src/extras/import/import_legacy_hoo.pl [new file with mode: 0755]

diff --git a/Evergreen/src/extras/import/import_legacy_closings.pl b/Evergreen/src/extras/import/import_legacy_closings.pl
new file mode 100755 (executable)
index 0000000..a0957d2
--- /dev/null
@@ -0,0 +1,37 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+print "CREATE TEMP TABLE legacy_closing (lib text, cstart int, cend int, reason text);\n";
+print "COPY legacy_closing (lib,cstart,cend,reason) FROM STDIN;\n";
+
+while (<>) {
+       my ($lib,$s,$e) = split '\|';
+       my @start = split ' ', $s;
+       my @end = split ' ', $e;
+
+       for (my $x = 0; $x < @start; $x++) {
+               print "$lib\t$start[$x]\t$end[$x]\tLegacy Closing\n";
+       }
+}
+
+print "\\.\n";
+
+print <<SQL;
+
+DELETE FROM actor.org_unit_closed;
+
+CREATE TEMP VIEW legacy_closing_view AS
+       SELECT  au.id AS org_unit,
+               ('epoch'::TIMESTAMPTZ + (l.cstart || ' seconds')::INTERVAL)::DATE AS close_start,
+               ('epoch'::TIMESTAMPTZ + (l.cend || ' seconds')::INTERVAL + '1 day'::INTERVAL)::DATE - '1 second'::INTERVAL AS close_end,
+               l.reason AS reason
+         FROM  legacy_closing l
+               JOIN actor.org_unit au ON (au.shortname = l.lib);
+
+INSERT INTO actor.org_unit_closed (org_unit, close_start, close_end, reason)
+       SELECT * from legacy_closing_view;
+
+SQL
+
diff --git a/Evergreen/src/extras/import/import_legacy_hoo.pl b/Evergreen/src/extras/import/import_legacy_hoo.pl
new file mode 100755 (executable)
index 0000000..70c0a19
--- /dev/null
@@ -0,0 +1,39 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+print "CREATE TEMP TABLE legacy_hoo (lib text, d0o time, d0c time, d1o time, d1c time, d2o time, d2c time, d3o time, d3c time, d4o time, d4c time, d5o time, d5c time, d6o time, d6c time);\n";
+print "COPY legacy_hoo (lib,d0o,d0c,d1o,d1c,d2o,d2c,d3o,d3c,d4o,d4c,d5o,d5c,d6o,d6c) FROM STDIN;\n";
+
+while (<>) {
+       my ($lib,@dow) = split '\|';
+       @dow = @dow[1,2,3,4,5,6,0];
+       
+       print "$lib";
+       for my $c (@dow) {
+               if ($c == 1) {
+                       print "\t00:00:00\t00:00:00";
+               } else {
+                       print "\t09:00:00\t17:00:00";
+               }
+       }
+       print "\n";
+}
+
+print "\\.\n";
+
+print <<SQL;
+
+DELETE FROM actor.hours_of_operation;
+
+CREATE TEMP VIEW legacy_hoo_view AS
+       SELECT  au.id AS id, l.d0o, l.d0c, l.d1o, l.d1c, l.d2o, l.d2c, l.d3o, l.d3c, l.d4o, l.d4c, l.d5o, l.d5c, l.d6o, l.d6c
+         FROM  legacy_hoo l
+               JOIN actor.org_unit au ON (au.shortname = l.lib);
+
+INSERT INTO actor.hours_of_operation (id, dow_0_open, dow_0_close, dow_1_open, dow_1_close, dow_2_open, dow_2_close, dow_3_open, dow_3_close, dow_4_open, dow_4_close, dow_5_open, dow_5_close, dow_6_open, dow_6_close)
+       SELECT * from legacy_hoo_view;
+
+SQL
+