forked from brmlab/brmbar-github
Add import scripts brmbar1 -> brmbar3
This commit is contained in:
parent
8a8d53f8e6
commit
8ae6dfb604
2 changed files with 31 additions and 0 deletions
15
brmbar3/import/import-items.pl
Normal file
15
brmbar3/import/import-items.pl
Normal file
|
@ -0,0 +1,15 @@
|
|||
# stdin in format: 8594002931643;Brmburky - hov.na cibul;-15
|
||||
use v5.12;
|
||||
while (<>) {
|
||||
chomp;
|
||||
say STDERR "--- $_";
|
||||
my ($barcode, $name, $price) = split(/;/);
|
||||
$price = -$price;
|
||||
print <<EOT
|
||||
INSERT INTO currencies (name) VALUES ('$name');
|
||||
INSERT INTO accounts (name, currency, acctype) VALUES ('$name', (SELECT id FROM currencies WHERE name = '$name'), 'inventory');
|
||||
INSERT INTO exchange_rates (target, source, rate, rate_dir) VALUES ((SELECT id FROM currencies WHERE name = '$name'), (SELECT id FROM currencies WHERE name = 'Kč'), $price, 'target_to_source');
|
||||
INSERT INTO exchange_rates (target, source, rate, rate_dir) VALUES ((SELECT id FROM currencies WHERE name = 'Kč'), (SELECT id FROM currencies WHERE name = '$name'), $price, 'source_to_target');
|
||||
INSERT INTO barcodes (barcode, account) VALUES ('$barcode', (SELECT id FROM accounts WHERE name = '$name'));
|
||||
EOT
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue