Fix load serials script to save everything. #549

This commit is contained in:
Korina Cordero 2021-04-19 06:16:13 +00:00
parent 699c135f33
commit 9e1d855433
2 changed files with 45 additions and 5 deletions

View file

@ -46,9 +46,16 @@ class WarrantySerial
*/
protected $source;
// other information
/**
* @ORM\Column(type="json")
*/
protected $meta_info;
public function __construct()
{
$this->date_create = new DateTime();
$this->meta_info = [];
}
public function setID($id)
@ -99,4 +106,19 @@ class WarrantySerial
{
return $this->source;
}
public function addMetaInfo($id, $value)
{
$this->meta_info[$id] = $value;
return $this;
}
public function getMetaInfo($id)
{
// return null if we don't have it
if (!isset($this->meta_info[$id]))
return null;
return $this->meta_info[$id];
}
}

View file

@ -10,7 +10,7 @@ $pass = $argv[4];
$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)');
$sth = $db->prepare('insert into warranty_serial (id, sku, date_create, source, meta_info) values (:serial, :sku, :date_create, :source, :meta_info)');
// go through rows
@ -32,16 +32,34 @@ while (($row = fgetcsv($csv)) !== false)
$ref_id = $row[3]; */
// sample of line in output file:
// MG3101407704,N/A,Dispatch,In,2021-04-12T00:39:47.1870000+08:00
$serial = trim(strtoupper($row[0]);
// serial number, sku, dispatch status, created date, inventory status, category id, category name
// CH2000012071,WCHD23BL-CPN00-LX,0,2020-08-11 04:05:27.090,0,4,CHAMPION MF
$serial = trim(strtoupper($row[0]));
$sku = trim($row[1]);
$date_create = $row[4]);
$dispatch_status = trim($row[2]);
$date_create = $row[3];
$inventory_status = trim($row[4]);
$cat_id = trim($row[5]);
$cat_name = trim($row[6]);
$meta_info = [
'dispatch_status' => $dispatch_status,
'inventory_status' => $inventory_status,
'category_id' => $cat_id,
'category_name' => $cat_name,
];
$info = json_encode($meta_info);
if ($sku == 'N/A')
$sku = null;
$res = $sth->execute([
':serial' => $serial,
':sku' => $sku,
':date_create' => $date_create,
':source' => $source
':source' => $source,
':meta_info' => $info,
]);
if (!$res)