Store a list of errors associated with each field instead of overwriting the error if multiple occur. Also Adjust the importer to extract the asset tag earlier in the process so all asset related errors are associated with the asset tag rather than some being tied to the name.

This commit is contained in:
Daniel Meltzer 2016-06-22 15:13:01 -04:00
parent dd1241f964
commit 43e64a5f8c
2 changed files with 19 additions and 18 deletions

View file

@ -139,10 +139,13 @@ class ObjectImportCommand extends Command {
$item["notes"] = $this->array_smart_fetch($row, "notes"); $item["notes"] = $this->array_smart_fetch($row, "notes");
$item["quantity"] = $this->array_smart_fetch($row, "quantity"); $item["quantity"] = $this->array_smart_fetch($row, "quantity");
$item["requestable"] = $this->array_smart_fetch($row, "requestable"); $item["requestable"] = $this->array_smart_fetch($row, "requestable");
$item["asset_tag"] = $this->array_smart_fetch($row, "asset tag");
$this->current_assetId = $item["item_name"]; $this->current_assetId = $item["item_name"];
if($item["asset_tag"] != '') {
$this->current_assetId = $item["asset_tag"];
}
$this->log('Category: ' . $item_category); $this->log('Category: ' . $item_category);
$this->log('Location: ' . $item_location); $this->log('Location: ' . $item_location);
$this->log('Purchase Date: ' . $item["purchase_date"]); $this->log('Purchase Date: ' . $item["purchase_date"]);
@ -226,9 +229,9 @@ class ObjectImportCommand extends Command {
public function jsonError($field, $errorString) public function jsonError($field, $errorString)
{ {
$this->errors[$this->current_assetId] = array($field => $errorString); $this->errors[$this->current_assetId][$field] = $errorString;
if($this->option('verbose')) if($this->option('verbose'))
parent::error($errorString); parent::error($field . $errorString);
} }
/** /**
@ -712,7 +715,6 @@ class ObjectImportCommand extends Command {
public function createAssetIfNotExists(array $row, array $item ) public function createAssetIfNotExists(array $row, array $item )
{ {
$asset_serial = $this->array_smart_fetch($row, "serial number"); $asset_serial = $this->array_smart_fetch($row, "serial number");
$asset_tag = $this->array_smart_fetch($row, "asset tag");
$asset_image = $this->array_smart_fetch($row, "image"); $asset_image = $this->array_smart_fetch($row, "image");
$asset_warranty_months = intval($this->array_smart_fetch($row, "warranty months")); $asset_warranty_months = intval($this->array_smart_fetch($row, "warranty months"));
if(empty($asset_warranty_months)) { if(empty($asset_warranty_months)) {
@ -722,17 +724,14 @@ class ObjectImportCommand extends Command {
$asset_model = $this->createOrFetchAssetModel($row, $item["category"], $item["manufacturer"]); $asset_model = $this->createOrFetchAssetModel($row, $item["category"], $item["manufacturer"]);
$supplier = $this->createOrFetchSupplier($row); $supplier = $this->createOrFetchSupplier($row);
$this->current_assetId = $asset_tag;
$this->log('Serial No: '.$asset_serial); $this->log('Serial No: '.$asset_serial);
$this->log('Asset Tag: '.$asset_tag); $this->log('Asset Tag: '.$item['asset_tag']);
$this->log('Notes: '.$item["notes"]); $this->log('Notes: '.$item["notes"]);
$this->log('Warranty Months: ' . $asset_warranty_months); $this->log('Warranty Months: ' . $asset_warranty_months);
foreach ($this->assets as $tempasset) { foreach ($this->assets as $tempasset) {
if (strcasecmp($tempasset->asset_tag, $asset_tag ) == 0 ) { if (strcasecmp($tempasset->asset_tag, $item['asset_tag'] ) == 0 ) {
$this->log('A matching Asset ' . $asset_tag . ' already exists'); $this->log('A matching Asset ' . $item['asset_tag'] . ' already exists');
// $this->comment('A matching Asset ' . $asset_tag . ' already exists');
return; return;
} }
} }
@ -769,7 +768,7 @@ class ObjectImportCommand extends Command {
$asset->purchase_cost = 0.00; $asset->purchase_cost = 0.00;
} }
$asset->serial = $asset_serial; $asset->serial = $asset_serial;
$asset->asset_tag = $asset_tag; $asset->asset_tag = $item['asset_tag'];
$asset->warranty_months = $asset_warranty_months; $asset->warranty_months = $asset_warranty_months;
if($asset_model) if($asset_model)

View file

@ -79,16 +79,18 @@
<th>Errors</th> <th>Errors</th>
</thead> </thead>
<tbody> <tbody>
@foreach (session('import_errors') as $asset => $error) @foreach (session('import_errors') as $asset => $itemErrors)
<tr> <tr>
<td> {{ $asset }}</td> <td> {{ $asset }}</td>
@foreach ($error as $field => $values ) <td>
<td> <span><b>{{ $field }}:</b> @foreach ($itemErrors as $field => $values )
<b>{{ $field }}:</b>
@foreach( $values as $errorString) @foreach( $values as $errorString)
<span>{{$errorString[0]}} </span> <span>{{$errorString[0]}} </span>
@endforeach @endforeach
</td> <br />
@endforeach @endforeach
</td>
</tr> </tr>
@endforeach @endforeach
</tbody> </tbody>