|
|
@@ -12,6 +12,7 @@ use App\Models\ProductSKU;
|
|
|
use App\Models\Reclamation;
|
|
|
use App\Models\ReclamationStatus;
|
|
|
use App\Models\User;
|
|
|
+use Illuminate\Database\Eloquent\Collection;
|
|
|
use Illuminate\Http\Request;
|
|
|
use Illuminate\Support\Str;
|
|
|
|
|
|
@@ -134,7 +135,15 @@ class ReportController extends Controller
|
|
|
$this->data['reclamations'][$reclamationStatus] = Reclamation::query()->where('status_id', '=', $reclamationStatusId)->count();
|
|
|
}
|
|
|
$this->data['reclamationMafs'] = $this->data['reclamationDetails'] = [];
|
|
|
- foreach (Reclamation::all() as $reclamation) {
|
|
|
+ $reclamations = Reclamation::query()
|
|
|
+ ->with([
|
|
|
+ 'skus.product',
|
|
|
+ 'details',
|
|
|
+ 'spareParts',
|
|
|
+ ])
|
|
|
+ ->get();
|
|
|
+
|
|
|
+ foreach ($reclamations as $reclamation) {
|
|
|
foreach ($reclamation->skus as $sku) {
|
|
|
$a = $sku->product->article;
|
|
|
if(isset($this->data['reclamationMafs'][$a])){
|
|
|
@@ -154,6 +163,8 @@ class ReportController extends Controller
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ $this->appendReclamationSparePartsToReport($reclamations);
|
|
|
+
|
|
|
|
|
|
// svod
|
|
|
$orderStatuses = OrderStatus::query()->get()->pluck('name', 'id')->toArray();
|
|
|
@@ -263,6 +274,26 @@ class ReportController extends Controller
|
|
|
return view('reports.index', $this->data);
|
|
|
}
|
|
|
|
|
|
+ private function appendReclamationSparePartsToReport(Collection $reclamations): void
|
|
|
+ {
|
|
|
+ foreach ($reclamations as $reclamation) {
|
|
|
+ foreach ($reclamation->spareParts as $sparePart) {
|
|
|
+ $article = trim((string) $sparePart->article);
|
|
|
+ $quantity = (int) ($sparePart->pivot?->quantity ?? 0);
|
|
|
+
|
|
|
+ if ($article === '' || $quantity < 1) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isset($this->data['reclamationDetails'][$article])) {
|
|
|
+ $this->data['reclamationDetails'][$article] += $quantity;
|
|
|
+ } else {
|
|
|
+ $this->data['reclamationDetails'][$article] = $quantity;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private function getOrderCount($districtId, $status = null, $type = null)
|
|
|
{
|
|
|
$q = Order::query()->where('district_id', '=', $districtId);
|