Yakıt Fişlerinin Mal Sorumlusuna iletilmemesi sorunu giderildi.
This commit is contained in:
@@ -1234,6 +1234,9 @@ END;
|
||||
- `status`: pending, approved, rejected
|
||||
- `date_from`: Başlangıç tarihi
|
||||
- `date_to`: Bitiş tarihi
|
||||
- `manager_id`: Mal sorumlusu ID'sine göre filtreleme
|
||||
- `fuel_manager_id`: Yakıt sorumlusu ID'sine göre filtreleme
|
||||
- `unit_id`: Birlik bazlı filtreleme (mal sorumlularının bağlı olduğu birlik için önerilir)
|
||||
|
||||
**Response** (200 OK):
|
||||
```json
|
||||
@@ -1734,4 +1737,4 @@ echo "Recovery completed. Services restarting..."
|
||||
|
||||
**Bu dokümantasyon Yakıt Takip Uygulaması projesinin kapsamlı süreçlerini ve teknik detaylarını içermektedir. Güncel kalmak için düzenli olarak gözden geçirilmeli ve güncellenmelidir.**
|
||||
|
||||
*Son güncelleme: 2024-11-05*
|
||||
*Son güncelleme: 2024-11-05*
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<script>
|
||||
import { onMount, onDestroy } from 'svelte';
|
||||
import { io } from 'socket.io-client';
|
||||
import { getSocketUrl } from '$lib/utils/socket';
|
||||
|
||||
export let user = null;
|
||||
|
||||
@@ -17,6 +18,13 @@
|
||||
let approvalNotes = '';
|
||||
let rejectionNotes = '';
|
||||
|
||||
function eventBelongsToCurrentUser(data) {
|
||||
if (!data || !user) return false;
|
||||
const matchesManager = data.goods_manager_id && user.id && parseInt(data.goods_manager_id) === parseInt(user.id);
|
||||
const matchesUnit = data.unit_id && user.unit_id && parseInt(data.unit_id) === parseInt(user.unit_id);
|
||||
return matchesManager || matchesUnit;
|
||||
}
|
||||
|
||||
onMount(async () => {
|
||||
console.log('🟢 GoodsManagerContent mounted, user:', user);
|
||||
|
||||
@@ -29,27 +37,27 @@
|
||||
|
||||
console.log('🔌 Connecting to Socket.IO...');
|
||||
// Socket.IO bağlantısı
|
||||
socket = io('http://localhost:3000');
|
||||
socket = io(getSocketUrl());
|
||||
|
||||
console.log('👤 Goods Manager ID:', user.id);
|
||||
|
||||
// Yeni fiş atandığında bildirim
|
||||
socket.on('fuel-slip-assigned', (data) => {
|
||||
console.log('Socket event received: fuel-slip-assigned', data);
|
||||
if (data.goods_manager_id === user.id) {
|
||||
if (eventBelongsToCurrentUser(data)) {
|
||||
console.log('✅ Slip assigned to this manager, reloading...');
|
||||
loadAssignedSlips();
|
||||
successMessage = 'Yeni yakıt fişi atandı!';
|
||||
setTimeout(() => successMessage = '', 3000);
|
||||
} else {
|
||||
console.log('ℹ️ Slip assigned to different manager:', data.goods_manager_id, 'vs', user.id);
|
||||
console.log('ℹ️ Slip assigned to different context:', data);
|
||||
}
|
||||
});
|
||||
|
||||
// Fiş durumu güncellendiğinde listeyi yenile
|
||||
socket.on('fuel-slip-updated', (data) => {
|
||||
console.log('Socket event received: fuel-slip-updated', data);
|
||||
if (data.goods_manager_id === user.id) {
|
||||
if (eventBelongsToCurrentUser(data)) {
|
||||
console.log('✅ Slip updated for this manager, reloading...');
|
||||
loadAssignedSlips();
|
||||
}
|
||||
@@ -72,10 +80,22 @@
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`📥 Loading slips for goods_manager_id: ${user.id}`);
|
||||
const params = new URLSearchParams({ status: 'pending' });
|
||||
if (user.unit_id) {
|
||||
params.set('unit_id', user.unit_id);
|
||||
console.log(`📥 Loading slips for unit_id: ${user.unit_id}`);
|
||||
} else if (user.id) {
|
||||
params.set('manager_id', user.id);
|
||||
console.log(`📥 Loading slips for goods_manager_id: ${user.id}`);
|
||||
} else {
|
||||
console.error('❌ Kullanıcı bilgileri eksik (id/unit_id)');
|
||||
error = 'Kullanıcı bilgileri eksik.';
|
||||
loading = false;
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const url = `/api/fuel-slips?manager_id=${user.id}&status=pending`;
|
||||
const url = `/api/fuel-slips?${params.toString()}`;
|
||||
console.log('🌐 Fetching from:', url);
|
||||
|
||||
const response = await fetch(url);
|
||||
@@ -788,4 +808,4 @@
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
@@ -47,7 +47,15 @@
|
||||
error = '';
|
||||
|
||||
try {
|
||||
const url = `/api/fuel-slips?manager_id=${user.id}&status=approved`;
|
||||
const params = new URLSearchParams({ status: 'approved' });
|
||||
if (user.unit_id) {
|
||||
params.set('unit_id', user.unit_id);
|
||||
} else if (user.id) {
|
||||
params.set('manager_id', user.id);
|
||||
} else {
|
||||
throw new Error('Kullanıcı bilgilerinde eksik alan var.');
|
||||
}
|
||||
const url = `/api/fuel-slips?${params.toString()}`;
|
||||
const response = await fetch(url);
|
||||
|
||||
if (response.ok) {
|
||||
@@ -599,4 +607,4 @@
|
||||
max-height: 2000px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import { io } from 'socket.io-client';
|
||||
|
||||
const SOCKET_URL = process.env.SOCKET_URL || process.env.VITE_SOCKET_URL || 'http://localhost:3000';
|
||||
|
||||
let socket = null;
|
||||
|
||||
export function getSocketClient() {
|
||||
if (!socket) {
|
||||
socket = io('http://localhost:3000', {
|
||||
socket = io(SOCKET_URL, {
|
||||
transports: ['websocket', 'polling']
|
||||
});
|
||||
|
||||
@@ -41,4 +43,4 @@ export function emitSocketEvent(event, data) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
24
src/lib/utils/socket.js
Normal file
24
src/lib/utils/socket.js
Normal file
@@ -0,0 +1,24 @@
|
||||
import { browser } from '$app/environment';
|
||||
|
||||
const DEFAULT_SOCKET_PORT = import.meta.env?.VITE_SOCKET_PORT || '3000';
|
||||
const CONFIGURED_SOCKET_URL = import.meta.env?.VITE_SOCKET_URL;
|
||||
|
||||
export function getSocketUrl() {
|
||||
if (CONFIGURED_SOCKET_URL) {
|
||||
return CONFIGURED_SOCKET_URL;
|
||||
}
|
||||
|
||||
if (browser && typeof window !== 'undefined') {
|
||||
const { protocol, hostname, port } = window.location;
|
||||
|
||||
// Geliştirme ortamında frontend genellikle farklı portta (ör. 5173) çalışır.
|
||||
// Bu durumda backend (socket sunucusu) portunu zorla.
|
||||
const isDevServer = import.meta.env?.DEV;
|
||||
const targetPort = isDevServer ? DEFAULT_SOCKET_PORT : port || DEFAULT_SOCKET_PORT;
|
||||
|
||||
return `${protocol}//${hostname}${targetPort ? `:${targetPort}` : ''}`;
|
||||
}
|
||||
|
||||
// SSR veya fallback durumları için
|
||||
return `http://localhost:${DEFAULT_SOCKET_PORT}`;
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
import { onMount, onDestroy, tick } from "svelte";
|
||||
import { goto } from "$app/navigation";
|
||||
import { io } from "socket.io-client";
|
||||
import { getSocketUrl } from "$lib/utils/socket";
|
||||
import VehiclesContent from "$lib/components/VehiclesContent.svelte";
|
||||
import UnitsContent from "$lib/components/UnitsContent.svelte";
|
||||
import PersonnelContent from "$lib/components/PersonnelContent.svelte";
|
||||
@@ -96,7 +97,7 @@
|
||||
await loadFuelData();
|
||||
|
||||
// Socket.IO bağlantısı
|
||||
socket = io("http://localhost:3000");
|
||||
socket = io(getSocketUrl());
|
||||
|
||||
// Fiş durumu güncellendiğinde listeyi yenile
|
||||
socket.on("fuel-slip-updated", (data) => {
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
import { onMount, onDestroy, tick } from 'svelte';
|
||||
import { goto } from '$app/navigation';
|
||||
import { io } from 'socket.io-client';
|
||||
import { getSocketUrl } from '$lib/utils/socket';
|
||||
|
||||
let user = null;
|
||||
let vehicles = [];
|
||||
@@ -60,7 +61,7 @@ let filteredVehicles = [];
|
||||
user = JSON.parse(userData);
|
||||
|
||||
// Socket.IO bağlantısı
|
||||
socket = io('http://localhost:3000');
|
||||
socket = io(getSocketUrl());
|
||||
|
||||
// Fiş durumu güncellendiğinde listeyi yenile
|
||||
socket.on('fuel-slip-updated', (data) => {
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
import { onMount, onDestroy } from 'svelte';
|
||||
import { goto } from '$app/navigation';
|
||||
import { io } from 'socket.io-client';
|
||||
import { getSocketUrl } from '$lib/utils/socket';
|
||||
|
||||
let user = null;
|
||||
let assignedSlips = [];
|
||||
@@ -25,17 +26,24 @@
|
||||
let approvalNotes = '';
|
||||
let rejectionNotes = '';
|
||||
|
||||
function eventBelongsToCurrentUser(data) {
|
||||
if (!data || !user) return false;
|
||||
const matchesManager = data.goods_manager_id && user.id && parseInt(data.goods_manager_id) === parseInt(user.id);
|
||||
const matchesUnit = data.unit_id && user.unit_id && parseInt(data.unit_id) === parseInt(user.unit_id);
|
||||
return matchesManager || matchesUnit;
|
||||
}
|
||||
|
||||
onMount(async () => {
|
||||
// Artık mal sorumlu işlemleri dashboard içinde SPA olarak çalışıyor
|
||||
goto('/dashboard');
|
||||
return;
|
||||
|
||||
// Socket.IO bağlantısı
|
||||
socket = io('http://localhost:3000');
|
||||
socket = io(getSocketUrl());
|
||||
|
||||
// Yeni fiş atandığında bildirim
|
||||
socket.on('fuel-slip-assigned', (data) => {
|
||||
if (data.goods_manager_id === user.id) {
|
||||
if (eventBelongsToCurrentUser(data)) {
|
||||
loadAssignedSlips();
|
||||
successMessage = 'Yeni yakıt fişi atandı!';
|
||||
setTimeout(() => successMessage = '', 3000);
|
||||
@@ -44,7 +52,7 @@
|
||||
|
||||
// Fiş durumu güncellendiğinde listeyi yenile
|
||||
socket.on('fuel-slip-updated', (data) => {
|
||||
if (data.goods_manager_id === user.id) {
|
||||
if (eventBelongsToCurrentUser(data)) {
|
||||
loadAssignedSlips();
|
||||
}
|
||||
});
|
||||
@@ -53,8 +61,24 @@
|
||||
});
|
||||
|
||||
async function loadAssignedSlips() {
|
||||
if (!user) {
|
||||
console.error('❌ Kullanıcı bilgisi bulunamadı.');
|
||||
return;
|
||||
}
|
||||
|
||||
const params = new URLSearchParams({ status: 'pending' });
|
||||
if (user.unit_id) {
|
||||
params.set('unit_id', user.unit_id);
|
||||
} else if (user.id) {
|
||||
params.set('manager_id', user.id);
|
||||
} else {
|
||||
error = 'Kullanıcı bilgileri eksik.';
|
||||
loading = false;
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/fuel-slips?manager_id=${user.id}&status=pending`);
|
||||
const response = await fetch(`/api/fuel-slips?${params.toString()}`);
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
assignedSlips = data.fuelSlips || [];
|
||||
@@ -803,4 +827,4 @@
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
@@ -1166,6 +1166,7 @@ app.get('/api/fuel-slips', (req, res) => {
|
||||
const status = searchParams.status;
|
||||
const manager_id = searchParams.manager_id;
|
||||
const fuel_manager_id = searchParams.fuel_manager_id;
|
||||
const unit_id = searchParams.unit_id;
|
||||
|
||||
// Veritabanı sorgusu
|
||||
let query = 'SELECT * FROM fuel_slips WHERE 1=1';
|
||||
@@ -1189,6 +1190,12 @@ app.get('/api/fuel-slips', (req, res) => {
|
||||
params.push(fuel_manager_id);
|
||||
}
|
||||
|
||||
// Birlik filtreleme
|
||||
if (unit_id) {
|
||||
query += ' AND unit_id = ?';
|
||||
params.push(parseInt(unit_id));
|
||||
}
|
||||
|
||||
// Tarihe göre ters sırala
|
||||
query += ' ORDER BY created_at DESC';
|
||||
|
||||
@@ -1354,6 +1361,7 @@ app.post('/api/fuel-slips', async (req, res) => {
|
||||
// Socket.IO ile mal sorumlusuna bildirim gönder
|
||||
const socketData = {
|
||||
goods_manager_id: newSlip.goods_manager_id,
|
||||
unit_id: newSlip.unit_id,
|
||||
fuel_slip_id: newSlip.id,
|
||||
message: `${newSlip.vehicle_info.plate} plakalı araç için yeni yakıt fişi`
|
||||
};
|
||||
@@ -1429,6 +1437,7 @@ app.put('/api/fuel-slips', async (req, res) => {
|
||||
const socketData = {
|
||||
goods_manager_id: updatedSlip.goods_manager_id,
|
||||
fuel_manager_id: updatedSlip.fuel_manager_id,
|
||||
unit_id: updatedSlip.unit_id,
|
||||
fuel_slip_id: updatedSlip.id,
|
||||
status: updatedSlip.status,
|
||||
approval_notes: updatedSlip.approval_notes
|
||||
|
||||
Reference in New Issue
Block a user