@extends('layouts.app') @section('content')

تقرير حركة الأصناف

عرض جميع حركات الأصناف في المخازن (وارد - منصرف - تحويل)

@if ($movements && $movements->count() > 0) @php // حساب أرصدة كل صنف بناءً على آخر حركة $itemBalances = []; $balances = []; foreach ($movements as $mov) { $key = $mov->item_name . '_' . ($mov->to_warehouse ?? $mov->from_warehouse ?? 'unknown'); $currentBalance = $balances[$key] ?? 0; if ($mov->document_type === 'receipt') { $currentBalance += floatval($mov->quantity); } elseif ($mov->document_type === 'issue') { $currentBalance -= floatval($mov->quantity); } elseif ($mov->document_type === 'transfer') { $currentBalance += floatval($mov->quantity); } $balances[$key] = $currentBalance; $itemBalances[$mov->item_name] = $currentBalance; } // الرصيد النهائي الكلي $finalBalance = array_sum($itemBalances); @endphp

إجمالي الوارد

{{ number_format($movements->where('document_type', 'receipt')->sum('quantity'), 2) }}

إجمالي المنصرف

{{ number_format($movements->where('document_type', 'issue')->sum('quantity'), 2) }}

إجمالي المحول

{{ number_format($movements->where('document_type', 'transfer')->sum('quantity'), 2) }}

الرصيد النهائي

{{ number_format($finalBalance, 2) }}

@endif
@php // حساب الرصيد الجاري الصحيح لكل حركة $balances = []; foreach ($movements ?? [] as $mov) { // مفتاح فريد لكل صنف + مخزن $key = $mov->item_name . '_' . ($mov->to_warehouse ?? $mov->from_warehouse ?? 'unknown'); // احصل على الرصيد الحالي (أو 0 إذا لم يكن موجوداً) $currentBalance = $balances[$key] ?? 0; // تحديث الرصيد حسب نوع الحركة if ($mov->document_type === 'receipt') { $currentBalance += floatval($mov->quantity); } elseif ($mov->document_type === 'issue') { $currentBalance -= floatval($mov->quantity); } elseif ($mov->document_type === 'transfer') { // التحويل يضيف للمخزن المستقبل $currentBalance += floatval($mov->quantity); } // احفظ الرصيد الجديد $balances[$key] = $currentBalance; // أضف الرصيد للحركة الحالية $mov->running_balance = $currentBalance; } @endphp @forelse($movements ?? [] as $movement) @php $isIn = $movement->movement_type === 'in'; $isOut = $movement->movement_type === 'out'; $isTransfer = $movement->movement_type === 'transfer'; @endphp @empty @endforelse
# التاريخ نوع الحركة الصنف 🟢 وارد 🔴 منصرف 🔵 محول الرصيد الوحدة السعر المجموع المستند
{{ $loop->iteration }} {{ \Carbon\Carbon::parse($movement->document_date)->format('Y-m-d') }} @if ($isIn) وارد @elseif($isOut) منصرف @else تحويل @endif {{ $movement->item_name }} {{ $isIn ? number_format($movement->quantity, 2) : '-' }} {{ $isOut ? number_format($movement->quantity, 2) : '-' }} {{ $isTransfer ? number_format($movement->quantity, 2) : '-' }} {{ number_format($movement->running_balance ?? 0, 2) }} {{ $movement->unit_name ?? '-' }} {{ number_format($movement->unit_price ?? 0, 2) }} {{ number_format($movement->total_cost ?? 0, 2) }} {{ $movement->document_number }}
لا توجد حركات مخزن
@push('scripts') @endpush @endsection