|
|
@@ -207,9 +207,9 @@ class ImportYearDataService
|
|
|
private function clearExistingData(): void
|
|
|
{
|
|
|
// Используем логику из ClearYearDataJob
|
|
|
- $orderIds = Order::withoutGlobalScopes()->withTrashed()->where('year', $this->year)->pluck('id');
|
|
|
- $productIds = Product::withoutGlobalScopes()->withTrashed()->where('year', $this->year)->pluck('id');
|
|
|
- $productSkuIds = ProductSKU::withoutGlobalScopes()->withTrashed()->where('year', $this->year)->pluck('id');
|
|
|
+ $orderIds = Order::withoutGlobalScope(\App\Models\Scopes\YearScope::class)->withTrashed()->where('year', $this->year)->pluck('id');
|
|
|
+ $productIds = Product::withoutGlobalScope(\App\Models\Scopes\YearScope::class)->withTrashed()->where('year', $this->year)->pluck('id');
|
|
|
+ $productSkuIds = ProductSKU::withoutGlobalScope(\App\Models\Scopes\YearScope::class)->withTrashed()->where('year', $this->year)->pluck('id');
|
|
|
$reclamationIds = Reclamation::whereIn('order_id', $orderIds)->pluck('id');
|
|
|
|
|
|
// Собираем файлы до удаления связей
|
|
|
@@ -233,19 +233,19 @@ class ImportYearDataService
|
|
|
Schedule::whereIn('order_id', $orderIds)->delete();
|
|
|
|
|
|
// SKU
|
|
|
- ProductSKU::withoutGlobalScopes()->withTrashed()->where('year', $this->year)->forceDelete();
|
|
|
+ ProductSKU::withoutGlobalScope(\App\Models\Scopes\YearScope::class)->withTrashed()->where('year', $this->year)->forceDelete();
|
|
|
|
|
|
// Заказы
|
|
|
- Order::withoutGlobalScopes()->withTrashed()->where('year', $this->year)->forceDelete();
|
|
|
+ Order::withoutGlobalScope(\App\Models\Scopes\YearScope::class)->withTrashed()->where('year', $this->year)->forceDelete();
|
|
|
|
|
|
// МАФ заказы
|
|
|
- MafOrder::withoutGlobalScopes()->withTrashed()->where('year', $this->year)->forceDelete();
|
|
|
+ MafOrder::withoutGlobalScope(\App\Models\Scopes\YearScope::class)->withTrashed()->where('year', $this->year)->forceDelete();
|
|
|
|
|
|
// Продукты
|
|
|
- Product::withoutGlobalScopes()->withTrashed()
|
|
|
+ Product::withoutGlobalScope(\App\Models\Scopes\YearScope::class)->withTrashed()
|
|
|
->whereIn('id', $productIds)
|
|
|
->update(['certificate_id' => null]);
|
|
|
- Product::withoutGlobalScopes()->withTrashed()->where('year', $this->year)->forceDelete();
|
|
|
+ Product::withoutGlobalScope(\App\Models\Scopes\YearScope::class)->withTrashed()->where('year', $this->year)->forceDelete();
|
|
|
|
|
|
// ТТН
|
|
|
Ttn::where('year', $this->year)->update(['file_id' => null]);
|
|
|
@@ -276,14 +276,14 @@ class ImportYearDataService
|
|
|
$fileIds = $fileIds->merge(DB::table('reclamation_act')->whereIn('reclamation_id', $reclamationIds)->pluck('file_id'));
|
|
|
|
|
|
$fileIds = $fileIds->merge(
|
|
|
- Product::withoutGlobalScopes()->withTrashed()
|
|
|
+ Product::withoutGlobalScope(\App\Models\Scopes\YearScope::class)->withTrashed()
|
|
|
->whereIn('id', $productIds)
|
|
|
->whereNotNull('certificate_id')
|
|
|
->pluck('certificate_id')
|
|
|
);
|
|
|
|
|
|
$fileIds = $fileIds->merge(
|
|
|
- ProductSKU::withoutGlobalScopes()->withTrashed()
|
|
|
+ ProductSKU::withoutGlobalScope(\App\Models\Scopes\YearScope::class)->withTrashed()
|
|
|
->whereIn('id', $productSkuIds)
|
|
|
->whereNotNull('passport_id')
|
|
|
->pluck('passport_id')
|
|
|
@@ -319,6 +319,9 @@ class ImportYearDataService
|
|
|
return $default;
|
|
|
}
|
|
|
$value = $row[$headerMap[$key]] ?? null;
|
|
|
+ if (is_string($value)) {
|
|
|
+ $value = trim($value);
|
|
|
+ }
|
|
|
if ($value === null || $value === '') {
|
|
|
return $default;
|
|
|
}
|
|
|
@@ -373,7 +376,7 @@ class ImportYearDataService
|
|
|
$nomenclatureNumber = $this->getStringValue($row, $headerMap, 'nomenclature_number', '');
|
|
|
|
|
|
// Проверяем существует ли продукт
|
|
|
- $existing = Product::withoutGlobalScopes()
|
|
|
+ $existing = Product::withoutGlobalScope(\App\Models\Scopes\YearScope::class)
|
|
|
->where('year', $this->year)
|
|
|
->where('nomenclature_number', $nomenclatureNumber)
|
|
|
->first();
|
|
|
@@ -417,7 +420,7 @@ class ImportYearDataService
|
|
|
$existing->update($productData);
|
|
|
$this->productIdMapping[$oldId] = $existing->id;
|
|
|
} else {
|
|
|
- $product = Product::withoutGlobalScopes()->create($productData);
|
|
|
+ $product = Product::withoutGlobalScope(\App\Models\Scopes\YearScope::class)->create($productData);
|
|
|
$this->productIdMapping[$oldId] = $product->id;
|
|
|
}
|
|
|
|
|
|
@@ -460,7 +463,7 @@ class ImportYearDataService
|
|
|
// Пробуем найти по номенклатуре
|
|
|
$nomenclature = $this->getValue($row, $headerMap, 'product_nomenclature');
|
|
|
if ($nomenclature) {
|
|
|
- $product = Product::withoutGlobalScopes()
|
|
|
+ $product = Product::withoutGlobalScope(\App\Models\Scopes\YearScope::class)
|
|
|
->where('year', $this->year)
|
|
|
->where('nomenclature_number', $nomenclature)
|
|
|
->first();
|
|
|
@@ -474,7 +477,7 @@ class ImportYearDataService
|
|
|
}
|
|
|
|
|
|
// Проверяем существует ли
|
|
|
- $existing = MafOrder::withoutGlobalScopes()
|
|
|
+ $existing = MafOrder::withoutGlobalScope(\App\Models\Scopes\YearScope::class)
|
|
|
->where('year', $this->year)
|
|
|
->where('product_id', $newProductId)
|
|
|
->where('order_number', $orderNumber)
|
|
|
@@ -498,7 +501,7 @@ class ImportYearDataService
|
|
|
$existing->update($mafOrderData);
|
|
|
$this->mafOrderIdMapping[$oldId] = $existing->id;
|
|
|
} else {
|
|
|
- $mafOrder = MafOrder::withoutGlobalScopes()->create($mafOrderData);
|
|
|
+ $mafOrder = MafOrder::withoutGlobalScope(\App\Models\Scopes\YearScope::class)->create($mafOrderData);
|
|
|
$this->mafOrderIdMapping[$oldId] = $mafOrder->id;
|
|
|
}
|
|
|
|
|
|
@@ -535,7 +538,7 @@ class ImportYearDataService
|
|
|
$objectAddress = $this->getStringValue($row, $headerMap, 'object_address', '');
|
|
|
|
|
|
// Проверяем существует ли
|
|
|
- $existing = Order::withoutGlobalScopes()
|
|
|
+ $existing = Order::withoutGlobalScope(\App\Models\Scopes\YearScope::class)
|
|
|
->where('year', $this->year)
|
|
|
->where('object_address', $objectAddress)
|
|
|
->first();
|
|
|
@@ -582,7 +585,7 @@ class ImportYearDataService
|
|
|
$existing->update($orderData);
|
|
|
$this->orderIdMapping[$oldId] = $existing->id;
|
|
|
} else {
|
|
|
- $order = Order::withoutGlobalScopes()->create($orderData);
|
|
|
+ $order = Order::withoutGlobalScope(\App\Models\Scopes\YearScope::class)->create($orderData);
|
|
|
$this->orderIdMapping[$oldId] = $order->id;
|
|
|
}
|
|
|
|
|
|
@@ -625,7 +628,7 @@ class ImportYearDataService
|
|
|
// Пробуем найти по номенклатуре
|
|
|
$nomenclature = $this->getValue($row, $headerMap, 'product_nomenclature');
|
|
|
if ($nomenclature) {
|
|
|
- $product = Product::withoutGlobalScopes()
|
|
|
+ $product = Product::withoutGlobalScope(\App\Models\Scopes\YearScope::class)
|
|
|
->where('year', $this->year)
|
|
|
->where('nomenclature_number', $nomenclature)
|
|
|
->first();
|
|
|
@@ -646,7 +649,7 @@ class ImportYearDataService
|
|
|
// Пробуем найти по адресу
|
|
|
$orderAddress = $this->getValue($row, $headerMap, 'order_address');
|
|
|
if ($orderAddress) {
|
|
|
- $order = Order::withoutGlobalScopes()
|
|
|
+ $order = Order::withoutGlobalScope(\App\Models\Scopes\YearScope::class)
|
|
|
->where('year', $this->year)
|
|
|
->where('object_address', $orderAddress)
|
|
|
->first();
|
|
|
@@ -669,7 +672,7 @@ class ImportYearDataService
|
|
|
// Пробуем найти по номеру заказа
|
|
|
$mafOrderNumber = $this->getValue($row, $headerMap, 'maf_order_number');
|
|
|
if ($mafOrderNumber) {
|
|
|
- $mafOrder = MafOrder::withoutGlobalScopes()
|
|
|
+ $mafOrder = MafOrder::withoutGlobalScope(\App\Models\Scopes\YearScope::class)
|
|
|
->where('year', $this->year)
|
|
|
->where('product_id', $newProductId)
|
|
|
->where('order_number', $mafOrderNumber)
|
|
|
@@ -702,7 +705,7 @@ class ImportYearDataService
|
|
|
'passport_id' => $passportId,
|
|
|
];
|
|
|
|
|
|
- $sku = ProductSKU::withoutGlobalScopes()->create($skuData);
|
|
|
+ $sku = ProductSKU::withoutGlobalScope(\App\Models\Scopes\YearScope::class)->create($skuData);
|
|
|
$this->productSkuIdMapping[$oldId] = $sku->id;
|
|
|
|
|
|
$count++;
|
|
|
@@ -750,7 +753,7 @@ class ImportYearDataService
|
|
|
// Пробуем найти по адресу
|
|
|
$orderAddress = $this->getValue($row, $headerMap, 'order_address');
|
|
|
if ($orderAddress) {
|
|
|
- $order = Order::withoutGlobalScopes()
|
|
|
+ $order = Order::withoutGlobalScope(\App\Models\Scopes\YearScope::class)
|
|
|
->where('year', $this->year)
|
|
|
->where('object_address', $orderAddress)
|
|
|
->first();
|