Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 22 |
| CommodityImport | |
0.00% |
0 / 1 |
|
0.00% |
0 / 2 |
110.00 | |
0.00% |
0 / 22 |
| __construct | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 3 |
|||
| collection | |
0.00% |
0 / 1 |
72.00 | |
0.00% |
0 / 19 |
|||
| <?php | |
| namespace App\Imports; | |
| use App\Commodity; | |
| use Illuminate\Support\Collection; | |
| use Maatwebsite\Excel\Concerns\ToCollection; | |
| use Maatwebsite\Excel\Concerns\WithHeadingRow; | |
| class CommodityImport implements ToCollection, WithHeadingRow | |
| { | |
| protected $isOverride=false; | |
| public function __construct($isOverride) | |
| { | |
| if($isOverride=='1') | |
| $this->isOverride=true; | |
| } | |
| /** | |
| * @param Collection $collections | |
| */ | |
| public function collection(Collection $collections) | |
| { | |
| foreach ($collections as $row) | |
| { | |
| $barcode = $row['barcode'] ?? $row['BARCODE'] ?? $row['Barcode']; | |
| if(!$barcode)continue; | |
| $name = $row['name'] ?? $row['NAME'] ?? $row['Name'] ?? ''; | |
| $sku = $row['sku'] ?? $row['SKU'] ?? $row['Sku'] ?? ''; | |
| $owner = $row['owner'] ?? $row['owner_name'] ?? $row['OWNER'] ?? $row['Owner'] ?? ''; | |
| $commodity=Commodity::where('barcode',$row['barcode'])->first(); | |
| if($commodity){ | |
| if($this->isOverride){ | |
| $name?$commodity['name']= $name:false; | |
| $sku?$commodity['sku']= $sku:false; | |
| $owner?$commodity['owner_name']= $owner:false; | |
| $commodity->update(); | |
| } | |
| }else{ | |
| Commodity::create([ | |
| 'name' => $name, | |
| 'sku' => $sku, | |
| 'owner_name' => $owner, | |
| 'barcode' => $barcode, | |
| ]); | |
| } | |
| } | |
| } | |
| } |