Yakıt Fişlerinin Mal Sorumlusuna iletilmemesi sorunu giderildi.
This commit is contained in:
@@ -1234,6 +1234,9 @@ END;
|
|||||||
- `status`: pending, approved, rejected
|
- `status`: pending, approved, rejected
|
||||||
- `date_from`: Başlangıç tarihi
|
- `date_from`: Başlangıç tarihi
|
||||||
- `date_to`: Bitiş 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):
|
**Response** (200 OK):
|
||||||
```json
|
```json
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<script>
|
<script>
|
||||||
import { onMount, onDestroy } from 'svelte';
|
import { onMount, onDestroy } from 'svelte';
|
||||||
import { io } from 'socket.io-client';
|
import { io } from 'socket.io-client';
|
||||||
|
import { getSocketUrl } from '$lib/utils/socket';
|
||||||
|
|
||||||
export let user = null;
|
export let user = null;
|
||||||
|
|
||||||
@@ -17,6 +18,13 @@
|
|||||||
let approvalNotes = '';
|
let approvalNotes = '';
|
||||||
let rejectionNotes = '';
|
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 () => {
|
onMount(async () => {
|
||||||
console.log('🟢 GoodsManagerContent mounted, user:', user);
|
console.log('🟢 GoodsManagerContent mounted, user:', user);
|
||||||
|
|
||||||
@@ -29,27 +37,27 @@
|
|||||||
|
|
||||||
console.log('🔌 Connecting to Socket.IO...');
|
console.log('🔌 Connecting to Socket.IO...');
|
||||||
// Socket.IO bağlantısı
|
// Socket.IO bağlantısı
|
||||||
socket = io('http://localhost:3000');
|
socket = io(getSocketUrl());
|
||||||
|
|
||||||
console.log('👤 Goods Manager ID:', user.id);
|
console.log('👤 Goods Manager ID:', user.id);
|
||||||
|
|
||||||
// Yeni fiş atandığında bildirim
|
// Yeni fiş atandığında bildirim
|
||||||
socket.on('fuel-slip-assigned', (data) => {
|
socket.on('fuel-slip-assigned', (data) => {
|
||||||
console.log('Socket event received: 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...');
|
console.log('✅ Slip assigned to this manager, reloading...');
|
||||||
loadAssignedSlips();
|
loadAssignedSlips();
|
||||||
successMessage = 'Yeni yakıt fişi atandı!';
|
successMessage = 'Yeni yakıt fişi atandı!';
|
||||||
setTimeout(() => successMessage = '', 3000);
|
setTimeout(() => successMessage = '', 3000);
|
||||||
} else {
|
} 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
|
// Fiş durumu güncellendiğinde listeyi yenile
|
||||||
socket.on('fuel-slip-updated', (data) => {
|
socket.on('fuel-slip-updated', (data) => {
|
||||||
console.log('Socket event received: 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...');
|
console.log('✅ Slip updated for this manager, reloading...');
|
||||||
loadAssignedSlips();
|
loadAssignedSlips();
|
||||||
}
|
}
|
||||||
@@ -72,10 +80,22 @@
|
|||||||
return;
|
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 {
|
try {
|
||||||
const url = `/api/fuel-slips?manager_id=${user.id}&status=pending`;
|
const url = `/api/fuel-slips?${params.toString()}`;
|
||||||
console.log('🌐 Fetching from:', url);
|
console.log('🌐 Fetching from:', url);
|
||||||
|
|
||||||
const response = await fetch(url);
|
const response = await fetch(url);
|
||||||
|
|||||||
@@ -47,7 +47,15 @@
|
|||||||
error = '';
|
error = '';
|
||||||
|
|
||||||
try {
|
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);
|
const response = await fetch(url);
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
import { io } from 'socket.io-client';
|
import { io } from 'socket.io-client';
|
||||||
|
|
||||||
|
const SOCKET_URL = process.env.SOCKET_URL || process.env.VITE_SOCKET_URL || 'http://localhost:3000';
|
||||||
|
|
||||||
let socket = null;
|
let socket = null;
|
||||||
|
|
||||||
export function getSocketClient() {
|
export function getSocketClient() {
|
||||||
if (!socket) {
|
if (!socket) {
|
||||||
socket = io('http://localhost:3000', {
|
socket = io(SOCKET_URL, {
|
||||||
transports: ['websocket', 'polling']
|
transports: ['websocket', 'polling']
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
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 { onMount, onDestroy, tick } from "svelte";
|
||||||
import { goto } from "$app/navigation";
|
import { goto } from "$app/navigation";
|
||||||
import { io } from "socket.io-client";
|
import { io } from "socket.io-client";
|
||||||
|
import { getSocketUrl } from "$lib/utils/socket";
|
||||||
import VehiclesContent from "$lib/components/VehiclesContent.svelte";
|
import VehiclesContent from "$lib/components/VehiclesContent.svelte";
|
||||||
import UnitsContent from "$lib/components/UnitsContent.svelte";
|
import UnitsContent from "$lib/components/UnitsContent.svelte";
|
||||||
import PersonnelContent from "$lib/components/PersonnelContent.svelte";
|
import PersonnelContent from "$lib/components/PersonnelContent.svelte";
|
||||||
@@ -96,7 +97,7 @@
|
|||||||
await loadFuelData();
|
await loadFuelData();
|
||||||
|
|
||||||
// Socket.IO bağlantısı
|
// Socket.IO bağlantısı
|
||||||
socket = io("http://localhost:3000");
|
socket = io(getSocketUrl());
|
||||||
|
|
||||||
// Fiş durumu güncellendiğinde listeyi yenile
|
// Fiş durumu güncellendiğinde listeyi yenile
|
||||||
socket.on("fuel-slip-updated", (data) => {
|
socket.on("fuel-slip-updated", (data) => {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
import { onMount, onDestroy, tick } from 'svelte';
|
import { onMount, onDestroy, tick } from 'svelte';
|
||||||
import { goto } from '$app/navigation';
|
import { goto } from '$app/navigation';
|
||||||
import { io } from 'socket.io-client';
|
import { io } from 'socket.io-client';
|
||||||
|
import { getSocketUrl } from '$lib/utils/socket';
|
||||||
|
|
||||||
let user = null;
|
let user = null;
|
||||||
let vehicles = [];
|
let vehicles = [];
|
||||||
@@ -60,7 +61,7 @@ let filteredVehicles = [];
|
|||||||
user = JSON.parse(userData);
|
user = JSON.parse(userData);
|
||||||
|
|
||||||
// Socket.IO bağlantısı
|
// Socket.IO bağlantısı
|
||||||
socket = io('http://localhost:3000');
|
socket = io(getSocketUrl());
|
||||||
|
|
||||||
// Fiş durumu güncellendiğinde listeyi yenile
|
// Fiş durumu güncellendiğinde listeyi yenile
|
||||||
socket.on('fuel-slip-updated', (data) => {
|
socket.on('fuel-slip-updated', (data) => {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
import { onMount, onDestroy } from 'svelte';
|
import { onMount, onDestroy } from 'svelte';
|
||||||
import { goto } from '$app/navigation';
|
import { goto } from '$app/navigation';
|
||||||
import { io } from 'socket.io-client';
|
import { io } from 'socket.io-client';
|
||||||
|
import { getSocketUrl } from '$lib/utils/socket';
|
||||||
|
|
||||||
let user = null;
|
let user = null;
|
||||||
let assignedSlips = [];
|
let assignedSlips = [];
|
||||||
@@ -25,17 +26,24 @@
|
|||||||
let approvalNotes = '';
|
let approvalNotes = '';
|
||||||
let rejectionNotes = '';
|
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 () => {
|
onMount(async () => {
|
||||||
// Artık mal sorumlu işlemleri dashboard içinde SPA olarak çalışıyor
|
// Artık mal sorumlu işlemleri dashboard içinde SPA olarak çalışıyor
|
||||||
goto('/dashboard');
|
goto('/dashboard');
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Socket.IO bağlantısı
|
// Socket.IO bağlantısı
|
||||||
socket = io('http://localhost:3000');
|
socket = io(getSocketUrl());
|
||||||
|
|
||||||
// Yeni fiş atandığında bildirim
|
// Yeni fiş atandığında bildirim
|
||||||
socket.on('fuel-slip-assigned', (data) => {
|
socket.on('fuel-slip-assigned', (data) => {
|
||||||
if (data.goods_manager_id === user.id) {
|
if (eventBelongsToCurrentUser(data)) {
|
||||||
loadAssignedSlips();
|
loadAssignedSlips();
|
||||||
successMessage = 'Yeni yakıt fişi atandı!';
|
successMessage = 'Yeni yakıt fişi atandı!';
|
||||||
setTimeout(() => successMessage = '', 3000);
|
setTimeout(() => successMessage = '', 3000);
|
||||||
@@ -44,7 +52,7 @@
|
|||||||
|
|
||||||
// Fiş durumu güncellendiğinde listeyi yenile
|
// Fiş durumu güncellendiğinde listeyi yenile
|
||||||
socket.on('fuel-slip-updated', (data) => {
|
socket.on('fuel-slip-updated', (data) => {
|
||||||
if (data.goods_manager_id === user.id) {
|
if (eventBelongsToCurrentUser(data)) {
|
||||||
loadAssignedSlips();
|
loadAssignedSlips();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -53,8 +61,24 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
async function loadAssignedSlips() {
|
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 {
|
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) {
|
if (response.ok) {
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
assignedSlips = data.fuelSlips || [];
|
assignedSlips = data.fuelSlips || [];
|
||||||
|
|||||||
@@ -1166,6 +1166,7 @@ app.get('/api/fuel-slips', (req, res) => {
|
|||||||
const status = searchParams.status;
|
const status = searchParams.status;
|
||||||
const manager_id = searchParams.manager_id;
|
const manager_id = searchParams.manager_id;
|
||||||
const fuel_manager_id = searchParams.fuel_manager_id;
|
const fuel_manager_id = searchParams.fuel_manager_id;
|
||||||
|
const unit_id = searchParams.unit_id;
|
||||||
|
|
||||||
// Veritabanı sorgusu
|
// Veritabanı sorgusu
|
||||||
let query = 'SELECT * FROM fuel_slips WHERE 1=1';
|
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);
|
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
|
// Tarihe göre ters sırala
|
||||||
query += ' ORDER BY created_at DESC';
|
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
|
// Socket.IO ile mal sorumlusuna bildirim gönder
|
||||||
const socketData = {
|
const socketData = {
|
||||||
goods_manager_id: newSlip.goods_manager_id,
|
goods_manager_id: newSlip.goods_manager_id,
|
||||||
|
unit_id: newSlip.unit_id,
|
||||||
fuel_slip_id: newSlip.id,
|
fuel_slip_id: newSlip.id,
|
||||||
message: `${newSlip.vehicle_info.plate} plakalı araç için yeni yakıt fişi`
|
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 = {
|
const socketData = {
|
||||||
goods_manager_id: updatedSlip.goods_manager_id,
|
goods_manager_id: updatedSlip.goods_manager_id,
|
||||||
fuel_manager_id: updatedSlip.fuel_manager_id,
|
fuel_manager_id: updatedSlip.fuel_manager_id,
|
||||||
|
unit_id: updatedSlip.unit_id,
|
||||||
fuel_slip_id: updatedSlip.id,
|
fuel_slip_id: updatedSlip.id,
|
||||||
status: updatedSlip.status,
|
status: updatedSlip.status,
|
||||||
approval_notes: updatedSlip.approval_notes
|
approval_notes: updatedSlip.approval_notes
|
||||||
|
|||||||
Reference in New Issue
Block a user