Merge branch '540-paperless-warranty' into 'master'
Add script to load warranty serials from motiv's csv #540 Closes #540 See merge request jankstudio/resq!646
This commit is contained in:
commit
b2151b4f84
1 changed files with 50 additions and 0 deletions
50
utils/load_warranty_serial/load_serials.php
Normal file
50
utils/load_warranty_serial/load_serials.php
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
// load csv
|
||||
$csv = fopen($argv[1], 'r');
|
||||
$dsn = $argv[2];
|
||||
$user = $argv[3];
|
||||
$pass = $argv[4];
|
||||
|
||||
// connect to db
|
||||
$db = new PDO($dsn, $user, $pass);
|
||||
|
||||
// prepared statement
|
||||
$sth = $db->prepare('insert into warranty_serial (id, sku, date_create, source) values (:serial, :sku, :date_create, :source)');
|
||||
|
||||
|
||||
// go through rows
|
||||
$counter = 0;
|
||||
$source = 'motiv';
|
||||
while (($row = fgetcsv($csv)) !== false)
|
||||
{
|
||||
// skip first line
|
||||
if ($counter == 0)
|
||||
{
|
||||
$counter++;
|
||||
continue;
|
||||
}
|
||||
|
||||
$serial = trim(strtoupper($row[0]));
|
||||
$sku = trim($row[1]);
|
||||
$date_create = $row[2];
|
||||
$ref_id = $row[3];
|
||||
|
||||
$res = $sth->execute([
|
||||
':serial' => $serial,
|
||||
':sku' => $sku,
|
||||
':date_create' => $date_create,
|
||||
':source' => $source
|
||||
]);
|
||||
|
||||
if (!$res)
|
||||
{
|
||||
$err = $sth->errorInfo();
|
||||
echo "Error ($serial) - " . $err[2] . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
// close file
|
||||
fclose($csv);
|
||||
|
||||
|
||||
Loading…
Reference in a new issue