|
14 | 14 | (active = 't') active,
|
15 | 15 | (deleted = 't') deleted
|
16 | 16 | FROM co.item
|
17 |
| - WHERE deleted = 'f' AND type = 2 |
| 17 | + WHERE type = 2 |
18 | 18 | ON DUPLICATE KEY
|
19 | 19 | UPDATE code = VALUES(code),
|
20 | 20 | name = VALUES(name),
|
|
65 | 65 | $r= $db->query($q) or die("query failed: ". $db->error);
|
66 | 66 | echo "Loaded ", $db->affected_rows, " barcodes.<br>";
|
67 | 67 |
|
| 68 | +# PERSONS |
| 69 | +# |
| 70 | +$q= "INSERT INTO person (id, name, company, address, email, phone, tax_id, |
| 71 | + active, deleted) |
| 72 | + SELECT id, |
| 73 | + (SELECT REPLACE(REPLACE(value, '|', ' '), ' ', ' ') FROM co.metavalue WHERE id_item = item.id AND id_metatype = 2 ORDER BY id DESC LIMIT 1) name, |
| 74 | + (SELECT value FROM co.metavalue WHERE id_item = item.id AND id_metatype = 3 ORDER BY id DESC LIMIT 1) company, |
| 75 | + (SELECT value FROM co.metavalue WHERE id_item = item.id AND id_metatype = 5 ORDER BY id DESC LIMIT 1) address, |
| 76 | + (SELECT value FROM co.metavalue WHERE id_item = item.id AND id_metatype = 9 ORDER BY id DESC LIMIT 1) email, |
| 77 | + (SELECT value FROM co.metavalue WHERE id_item = item.id AND id_metatype = 8 ORDER BY id DESC LIMIT 1) phone, |
| 78 | + (SELECT value FROM co.metavalue WHERE id_item = item.id AND id_metatype = 6 ORDER BY id DESC LIMIT 1) tax_id, |
| 79 | + (active = 't') active, |
| 80 | + (deleted = 't') deleted |
| 81 | + FROM co.item |
| 82 | + WHERE type IN (1,3,6) |
| 83 | + ON DUPLICATE KEY |
| 84 | + UPDATE |
| 85 | + name = VALUES(name), |
| 86 | + company = VALUES(company), |
| 87 | + address = VALUES(address), |
| 88 | + email = VALUES(email), |
| 89 | + phone = VALUES(phone), |
| 90 | + active = VALUES(active), |
| 91 | + deleted = VALUES(deleted)"; |
| 92 | +$r= $db->query($q) or die("query failed: ". $db->error); |
| 93 | +echo "Loaded ", $db->affected_rows, " people.<br>"; |
| 94 | + |
68 | 95 | # TRANSACTIONS
|
69 | 96 | #
|
70 | 97 | $q= "TRUNCATE txn_line";
|
71 | 98 | $r= $db->query($q) or die("query failed: ". $db->error);
|
72 | 99 | echo "Flushed transaction lines.<br>";
|
73 | 100 |
|
74 | 101 | # incomplete transactions
|
75 |
| -$q= "INSERT IGNORE |
76 |
| - INTO txn (id, number, created, type) |
| 102 | +$q= "INSERT |
| 103 | + INTO txn (id, number, created, type, person) |
77 | 104 | SELECT id AS id,
|
78 | 105 | IFNULL(number, 0) AS number,
|
79 | 106 | date AS created,
|
80 | 107 | CASE type
|
81 | 108 | WHEN 1 THEN 'customer'
|
82 | 109 | WHEN 2 THEN 'vendor'
|
83 | 110 | WHEN 3 THEN 'internal'
|
84 |
| - END AS type |
| 111 | + END AS type, |
| 112 | + id_item AS person |
85 | 113 | FROM co.request
|
86 |
| - WHERE id_parent IS NULL"; |
| 114 | + WHERE id_parent IS NULL |
| 115 | + ON DUPLICATE KEY |
| 116 | + UPDATE |
| 117 | + person = VALUES(person)"; |
87 | 118 | $r= $db->query($q) or die("query failed: ". $db->error);
|
88 | 119 | echo "Loaded ", $db->affected_rows, " incomplete transactions.<br>";
|
89 | 120 |
|
90 |
| - |
91 | 121 | # lines from requests (un-received items)
|
92 | 122 | #
|
93 | 123 | # needs the id offset to avoid collisions
|
|
106 | 136 | echo "Loaded ", $db->affected_rows, " transaction lines from incomplete orders.<br>";
|
107 | 137 |
|
108 | 138 | # basics
|
109 |
| -$q= "INSERT IGNORE |
110 |
| - INTO txn (id, number, created, type) |
| 139 | +$q= "INSERT |
| 140 | + INTO txn (id, number, created, type, person) |
111 | 141 | SELECT id_request AS id,
|
112 | 142 | IFNULL(IF(type = 2,
|
113 | 143 | SUBSTRING_INDEX(formatted_request_number, '-', -1),
|
|
118 | 148 | WHEN 1 THEN 'customer'
|
119 | 149 | WHEN 2 THEN 'vendor'
|
120 | 150 | WHEN 3 THEN 'internal'
|
121 |
| - END AS type |
| 151 | + END AS type, |
| 152 | + id_item AS person |
122 | 153 | FROM co.transaction
|
123 |
| - WHERE id_parent IS NULL"; |
| 154 | + WHERE id_parent IS NULL |
| 155 | + ON DUPLICATE KEY |
| 156 | + UPDATE |
| 157 | + person = VALUES(person)"; |
124 | 158 | $r= $db->query($q) or die("query failed: ". $db->error);
|
125 | 159 | echo "Loaded ", $db->affected_rows, " transactions.<br>";
|
126 | 160 |
|
|
0 commit comments