diff --git a/src/lib/components/VehiclesContent.svelte b/src/lib/components/VehiclesContent.svelte
index bf242e1..5c7b45d 100644
--- a/src/lib/components/VehiclesContent.svelte
+++ b/src/lib/components/VehiclesContent.svelte
@@ -16,7 +16,12 @@
brand: '',
model: '',
year: new Date().getFullYear(),
- plate: ''
+ plate: '',
+ fuel_type: 'Benzin',
+ fuel_capacity: 50,
+ current_fuel: 0,
+ yazlik_mukannen: 0,
+ kislik_mukannen: 0
};
onMount(async () => {
@@ -45,7 +50,12 @@
brand: '',
model: '',
year: new Date().getFullYear(),
- plate: ''
+ plate: '',
+ fuel_type: 'Benzin',
+ fuel_capacity: 50,
+ current_fuel: 0,
+ yazlik_mukannen: 0,
+ kislik_mukannen: 0
};
selectedVehicle = null;
}
@@ -61,7 +71,12 @@
brand: vehicle.brand,
model: vehicle.model,
year: vehicle.year,
- plate: vehicle.plate
+ plate: vehicle.plate,
+ fuel_type: vehicle.fuel_type || 'Benzin',
+ fuel_capacity: vehicle.fuel_capacity || 50,
+ current_fuel: vehicle.current_fuel || 0,
+ yazlik_mukannen: vehicle.yazlik_mukannen || 0,
+ kislik_mukannen: vehicle.kislik_mukannen || 0
};
showEditModal = true;
}
@@ -72,9 +87,19 @@
resetForm();
}
+ function validateMukannen(value) {
+ // Sadece pozitif tam sayı kabul et
+ return /^[0-9]*$/.test(value) && value >= 0;
+ }
+
async function handleAddVehicle() {
- if (!formData.brand || !formData.model || !formData.year || !formData.plate) {
- error = 'Tüm alanlar zorunludur.';
+ if (!formData.brand || !formData.model || !formData.year || !formData.plate || !formData.fuel_type || !formData.fuel_capacity) {
+ error = 'Tüm zorunlu alanları doldurun.';
+ return;
+ }
+
+ if (!validateMukannen(formData.yazlik_mukannen) || !validateMukannen(formData.kislik_mukannen)) {
+ error = 'Mukannen değerleri sadece rakam içermelidir.';
return;
}
@@ -103,8 +128,13 @@
}
async function handleUpdateVehicle() {
- if (!formData.brand || !formData.model || !formData.year || !formData.plate) {
- error = 'Tüm alanlar zorunludur.';
+ if (!formData.brand || !formData.model || !formData.year || !formData.plate || !formData.fuel_type || !formData.fuel_capacity) {
+ error = 'Tüm zorunlu alanları doldurun.';
+ return;
+ }
+
+ if (!validateMukannen(formData.yazlik_mukannen) || !validateMukannen(formData.kislik_mukannen)) {
+ error = 'Mukannen değerleri sadece rakam içermelidir.';
return;
}
@@ -214,6 +244,10 @@
{vehicle.brand} {vehicle.model}
{vehicle.year}
+
+ Yaz: {vehicle.yazlik_mukannen || 0}
+ Kış: {vehicle.kislik_mukannen || 0}
+
{vehicle.plate}
@@ -295,6 +329,76 @@
required
/>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -358,6 +462,76 @@
required
/>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -502,6 +676,21 @@
margin: 0;
}
+ .vehicle-mukannen {
+ display: flex;
+ gap: 0.75rem;
+ margin-top: 0.25rem;
+ }
+
+ .mukannen-item {
+ background: rgba(59, 130, 246, 0.1);
+ color: #3B82F6;
+ padding: 0.25rem 0.5rem;
+ border-radius: 4px;
+ font-size: 0.75rem;
+ font-weight: 500;
+ }
+
.plate-badge {
background: var(--primary-color);
color: white;
diff --git a/src/routes/api/fuel-personnel/+server.js b/src/routes/api/fuel-personnel/+server.js
deleted file mode 100644
index 3f8c26d..0000000
--- a/src/routes/api/fuel-personnel/+server.js
+++ /dev/null
@@ -1,190 +0,0 @@
-import { json } from '@sveltejs/kit';
-
-// Geçici veritabanı simülasyonu
-let fuelPersonnel = [
- {
- id: 1,
- full_name: 'Ahmet Demir',
- rank: 'Üsteğmen',
- registration_number: '111222',
- tc_kimlik: '11111111111',
- phone: '05321112233',
- is_active: true,
- created_at: new Date().toISOString()
- },
- {
- id: 2,
- full_name: 'Mustafa Çelik',
- rank: 'Astsubay',
- registration_number: '333444',
- tc_kimlik: '22222222222',
- phone: '05334455566',
- is_active: true,
- created_at: new Date().toISOString()
- }
-];
-
-let nextId = 3;
-
-// GET - Tüm yakıt personelini listele
-export async function GET({ request }) {
- // Yetki kontrolü (temporary - will be implemented with proper session)
- return json({ fuelPersonnel });
-}
-
-// POST - Yeni yakıt personeli ekle
-export async function POST({ request }) {
- // Yetki kontrolü (temporary - will be implemented with proper session)
-
- try {
- const {
- full_name,
- rank,
- registration_number,
- tc_kimlik,
- phone
- } = await request.json();
-
- // Validasyon
- if (!full_name || !rank || !registration_number || !tc_kimlik || !phone) {
- return json({ message: 'Tüm alanlar zorunludur.' }, { status: 400 });
- }
-
- // TC Kimlik numarası validasyonu
- if (!/^[0-9]{11}$/.test(tc_kimlik)) {
- return json({ message: 'TC Kimlik numarası 11 haneli olmalıdır.' }, { status: 400 });
- }
-
- // Sicil numarası tekrar kontrolü
- const existingPersonnel = fuelPersonnel.find(p =>
- p.registration_number.toLowerCase() === registration_number.toLowerCase()
- );
- if (existingPersonnel) {
- return json({ message: 'Bu sicil numarası zaten kayıtlı.' }, { status: 400 });
- }
-
- // TC Kimlik numarası tekrar kontrolü
- const existingTC = fuelPersonnel.find(p => p.tc_kimlik === tc_kimlik);
- if (existingTC) {
- return json({ message: 'Bu TC Kimlik numarası zaten kayıtlı.' }, { status: 400 });
- }
-
- // Yeni personel oluştur
- const newPersonnel = {
- id: nextId++,
- full_name: full_name.trim(),
- rank: rank.trim(),
- registration_number: registration_number.trim().toUpperCase(),
- tc_kimlik: tc_kimlik.trim(),
- phone: phone.trim(),
- is_active: true,
- created_at: new Date().toISOString()
- };
-
- fuelPersonnel.push(newPersonnel);
-
- return json({
- message: 'Yakıt personeli başarıyla eklendi.',
- personnel: newPersonnel
- });
-
- } catch (error) {
- return json({ message: 'Sunucu hatası.' }, { status: 500 });
- }
-}
-
-// PUT - Yakıt personeli güncelle
-export async function PUT({ request }) {
- // Yetki kontrolü (temporary - will be implemented with proper session)
-
- try {
- const {
- id,
- full_name,
- rank,
- registration_number,
- tc_kimlik,
- phone,
- is_active
- } = await request.json();
-
- // Validasyon
- if (!id || !full_name || !rank || !registration_number || !tc_kimlik || !phone) {
- return json({ message: 'Tüm alanlar zorunludur.' }, { status: 400 });
- }
-
- // TC Kimlik numarası validasyonu
- if (!/^[0-9]{11}$/.test(tc_kimlik)) {
- return json({ message: 'TC Kimlik numarası 11 haneli olmalıdır.' }, { status: 400 });
- }
-
- // Personnel bul
- const personnelIndex = fuelPersonnel.findIndex(p => p.id === parseInt(id));
- if (personnelIndex === -1) {
- return json({ message: 'Yakıt personeli bulunamadı.' }, { status: 404 });
- }
-
- // Sicil numarası tekrar kontrolü (diğer personeller için)
- const existingPersonnel = fuelPersonnel.find(p =>
- p.id !== parseInt(id) && p.registration_number.toLowerCase() === registration_number.toLowerCase()
- );
- if (existingPersonnel) {
- return json({ message: 'Bu sicil numarası başka bir personelde kullanılıyor.' }, { status: 400 });
- }
-
- // TC Kimlik numarası tekrar kontrolü (diğer personeller için)
- const existingTC = fuelPersonnel.find(p => p.id !== parseInt(id) && p.tc_kimlik === tc_kimlik);
- if (existingTC) {
- return json({ message: 'Bu TC Kimlik numarası başka bir personelde kullanılıyor.' }, { status: 400 });
- }
-
- // Personnel güncelle
- fuelPersonnel[personnelIndex] = {
- ...fuelPersonnel[personnelIndex],
- full_name: full_name.trim(),
- rank: rank.trim(),
- registration_number: registration_number.trim().toUpperCase(),
- tc_kimlik: tc_kimlik.trim(),
- phone: phone.trim(),
- is_active: is_active !== undefined ? Boolean(is_active) : fuelPersonnel[personnelIndex].is_active
- };
-
- return json({
- message: 'Yakıt personeli başarıyla güncellendi.',
- personnel: fuelPersonnel[personnelIndex]
- });
-
- } catch (error) {
- return json({ message: 'Sunucu hatası.' }, { status: 500 });
- }
-}
-
-// DELETE - Yakıt personeli sil
-export async function DELETE({ request }) {
- // Yetki kontrolü (temporary - will be implemented with proper session)
-
- try {
- const { id } = await request.json();
-
- if (!id) {
- return json({ message: 'Personel ID zorunludur.' }, { status: 400 });
- }
-
- // Personnel bul
- const personnelIndex = fuelPersonnel.findIndex(p => p.id === parseInt(id));
- if (personnelIndex === -1) {
- return json({ message: 'Yakıt personeli bulunamadı.' }, { status: 404 });
- }
-
- // Personnel sil
- const deletedPersonnel = fuelPersonnel.splice(personnelIndex, 1)[0];
-
- return json({
- message: 'Yakıt personeli başarıyla silindi.',
- personnel: deletedPersonnel
- });
-
- } catch (error) {
- return json({ message: 'Sunucu hatası.' }, { status: 500 });
- }
-}
\ No newline at end of file
diff --git a/src/routes/api/fuel-slips/+server.js b/src/routes/api/fuel-slips/+server.js
deleted file mode 100644
index 9196ee4..0000000
--- a/src/routes/api/fuel-slips/+server.js
+++ /dev/null
@@ -1,407 +0,0 @@
-import { json } from '@sveltejs/kit';
-import { emitSocketEvent } from '$lib/server/socketClient.js';
-
-// Veritabanı bağlantısı
-const dbPath = 'db/yakit_takip.db';
-import sqlite3 from 'sqlite3';
-
-// Veritabanı bağlantısı al
-function getDatabase() {
- return new sqlite3.Database(dbPath);
-}
-
-// GET - Yakıt fişlerini listele
-export async function GET({ request, url }) {
- const searchParams = url.searchParams;
- const status = searchParams.get('status');
- const manager_id = searchParams.get('manager_id');
- const fuel_manager_id = searchParams.get('fuel_manager_id');
-
-
- return new Promise((resolve) => {
- const db = getDatabase();
-
- let query = 'SELECT * FROM fuel_slips WHERE 1=1';
- const params = [];
-
- // Status filtreleme
- if (status) {
- query += ' AND status = ?';
- params.push(status);
- }
-
- // Mal sorumlusu filtreleme
- if (manager_id) {
- query += ' AND goods_manager_id = ?';
- params.push(manager_id);
- }
-
- // Yakıt sorumlusu filtreleme
- if (fuel_manager_id) {
- query += ' AND fuel_manager_id = ?';
- params.push(fuel_manager_id);
- }
-
-
-
- // Tarihe göre ters sırala
- query += ' ORDER BY created_at DESC';
-
- console.log(`🔍 API Query: ${query}`);
- console.log(`📋 API Parameters:`, params);
-
- db.all(query, params, (err, rows) => {
- db.close();
-
- if (err) {
- console.error('GET fuel slips error:', err);
- resolve(json({ message: 'Veritabanı hatası.' }, { status: 500 }));
- return;
- }
-
- console.log(`📊 Database returned ${rows.length} rows`);
-
- // JSON string olarak saklanan alanları parse et
- const fuelSlips = rows.map(row => ({
- ...row,
- vehicle_info: row.vehicle_info ? JSON.parse(row.vehicle_info) : null,
- personnel_info: row.personnel_info ? JSON.parse(row.personnel_info) : null,
- goods_manager_info: row.goods_manager_info ? JSON.parse(row.goods_manager_info) : null,
- fuel_manager_info: row.fuel_manager_info ? JSON.parse(row.fuel_manager_info) : null
- }));
-
- console.log(`✅ Processed ${fuelSlips.length} fuel slips for API response`);
- console.log(`📋 Fuel slips summary:`, fuelSlips.map(s => ({
- id: s.id,
- date: s.date,
- goods_manager_id: s.goods_manager_id,
- status: s.status,
- liters: s.liters,
- vehicle: s.vehicle_info?.plate
- })));
-
- resolve(json({ fuelSlips }));
- });
- });
-}
-
-// POST - Yeni yakıt fişi oluştur
-export async function POST({ request }) {
- try {
- const slipData = await request.json();
- console.log('📝 Creating new fuel slip with data:', slipData);
-
- // Validasyon
- const requiredFields = [
- 'date', 'force_command', 'unit_id', 'vehicle_id',
- 'fuel_type', 'liters', 'km', 'personnel_id',
- 'goods_manager_id', 'fuel_manager_id'
- ];
-
- for (const field of requiredFields) {
- if (!slipData[field]) {
- return json({ message: `${field} alanı zorunludur.` }, { status: 400 });
- }
- }
-
- // Litre ve KM validasyonu
- if (slipData.liters <= 0 || slipData.km < 0) {
- return json({ message: 'Litre ve KM değerleri geçersiz.' }, { status: 400 });
- }
-
- // Araç, personel ve mal sorumlusu bilgilerini getir
- const baseUrl = request.url.split('/api/')[0];
-
- const [vehiclesRes, unitsRes, personnelRes, goodsManagersRes] = await Promise.all([
- fetch(`${baseUrl}/api/vehicles`).catch(() => null),
- fetch(`${baseUrl}/api/units`).catch(() => null),
- fetch(`${baseUrl}/api/fuel-personnel`).catch(() => null),
- fetch(`${baseUrl}/api/goods-managers`).catch(() => null)
- ]);
-
- const vehicles = vehiclesRes ? await vehiclesRes.json().catch(() => ({ vehicles: [] })) : { vehicles: [] };
- const units = unitsRes ? await unitsRes.json().catch(() => ({ units: [] })) : { units: [] };
- const personnel = personnelRes ? await personnelRes.json().catch(() => ({ fuelPersonnel: [] })) : { fuelPersonnel: [] };
- const goodsManagers = goodsManagersRes ? await goodsManagersRes.json().catch(() => ({ goodsManagers: [] })) : { goodsManagers: [] };
-
- const vehicle = vehicles.vehicles?.find(v => v.id === slipData.vehicle_id);
- const unit = units.units?.find(u => u.id === slipData.unit_id);
- const person = personnel.fuelPersonnel?.find(p => p.id === slipData.personnel_id);
- const goodsManager = goodsManagers.goodsManagers?.find(gm => gm.id === slipData.goods_manager_id);
-
- return new Promise((resolve) => {
- const db = getDatabase();
-
- const vehicleInfo = vehicle ? {
- brand: vehicle.brand,
- model: vehicle.model,
- plate: vehicle.plate,
- year: vehicle.year
- } : {
- brand: 'Bilinmeyen',
- model: 'Araç',
- plate: 'Bilinmiyor',
- year: 0
- };
-
- const personnelInfo = person ? {
- full_name: person.full_name,
- rank: person.rank
- } : {
- full_name: 'Bilinmeyen Personel',
- rank: ''
- };
-
- const goodsManagerInfo = goodsManager ? {
- full_name: goodsManager.full_name,
- rank: goodsManager.rank
- } : {
- full_name: 'Bilinmeyen Mal Sorumlusu',
- rank: ''
- };
-
- const fuelManagerInfo = { full_name: 'Yakıt Sorumlusu', rank: 'Yüzbaşı' };
-
- const query = `
- INSERT INTO fuel_slips (
- date, force_command, unit_id, unit_name, vehicle_id, vehicle_info,
- fuel_type, liters, km, personnel_id, personnel_info, goods_manager_id,
- goods_manager_info, fuel_manager_id, fuel_manager_info, status, notes
- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
- `;
-
- const params = [
- slipData.date,
- slipData.force_command,
- slipData.unit_id,
- unit?.name || `Birim ${slipData.unit_id}`,
- slipData.vehicle_id,
- JSON.stringify(vehicleInfo),
- slipData.fuel_type,
- parseFloat(slipData.liters),
- parseInt(slipData.km),
- slipData.personnel_id,
- JSON.stringify(personnelInfo),
- slipData.goods_manager_id,
- JSON.stringify(goodsManagerInfo),
- slipData.fuel_manager_id,
- JSON.stringify(fuelManagerInfo),
- 'pending',
- slipData.notes || ''
- ];
-
- db.run(query, params, function(err) {
- db.close();
-
- if (err) {
- console.error('Create fuel slip error:', err);
- resolve(json({ message: 'Veritabanı hatası.' }, { status: 500 }));
- return;
- }
-
- const newSlip = {
- id: this.lastID,
- date: slipData.date,
- force_command: slipData.force_command,
- unit_id: slipData.unit_id,
- unit_name: unit?.name || `Birim ${slipData.unit_id}`,
- vehicle_id: slipData.vehicle_id,
- vehicle_info: vehicleInfo,
- fuel_type: slipData.fuel_type,
- liters: parseFloat(slipData.liters),
- km: parseInt(slipData.km),
- personnel_id: slipData.personnel_id,
- personnel_info: personnelInfo,
- goods_manager_id: slipData.goods_manager_id,
- goods_manager_info: goodsManagerInfo,
- fuel_manager_id: slipData.fuel_manager_id,
- fuel_manager_info: fuelManagerInfo,
- status: 'pending',
- notes: slipData.notes || '',
- created_at: new Date().toISOString()
- };
-
- console.log('✅ Fuel slip created:', newSlip);
-
- // Socket.IO ile mal sorumlusuna bildirim gönder
- const socketData = {
- goods_manager_id: newSlip.goods_manager_id,
- fuel_slip_id: newSlip.id,
- message: `${newSlip.vehicle_info.plate} plakalı araç için yeni yakıt fişi`
- };
- console.log('📢 Sending socket notification: fuel-slip-assigned', socketData);
-
- // Socket client kullanarak bildirim gönder
- const sent = emitSocketEvent('fuel-slip-assigned', socketData);
- if (!sent) {
- console.warn('⚠️ Socket notification could not be sent');
- }
-
- resolve(json({
- message: 'Yakıt fişi başarıyla oluşturuldu.',
- fuelSlip: newSlip
- }));
- });
- });
-
- } catch (error) {
- console.error('Create fuel slip error:', error);
- return json({ message: 'Sunucu hatası.' }, { status: 500 });
- }
-}
-
-// PUT - Fiş durumunu güncelle (onay/reddet)
-export async function PUT({ request }) {
- try {
- const { id, status, approval_notes } = await request.json();
-
- if (!id || !status) {
- return json({ message: 'ID ve durum zorunludur.' }, { status: 400 });
- }
-
- if (!['approved', 'rejected'].includes(status)) {
- return json({ message: 'Geçersiz durum.' }, { status: 400 });
- }
-
- return new Promise((resolve) => {
- const db = getDatabase();
-
- const query = `
- UPDATE fuel_slips
- SET status = ?, approval_date = ?, approval_notes = ?
- WHERE id = ?
- `;
-
- const params = [
- status,
- new Date().toISOString(),
- approval_notes || '',
- parseInt(id)
- ];
-
- db.run(query, params, function(err) {
- if (err) {
- db.close();
- console.error('Update fuel slip error:', err);
- resolve(json({ message: 'Veritabanı hatası.' }, { status: 500 }));
- return;
- }
-
- if (this.changes === 0) {
- db.close();
- resolve(json({ message: 'Fiş bulunamadı.' }, { status: 404 }));
- return;
- }
-
- // Güncellenmiş fişi getir
- db.get('SELECT * FROM fuel_slips WHERE id = ?', [id], (err, row) => {
- db.close();
-
- if (err) {
- console.error('Get updated fuel slip error:', err);
- resolve(json({ message: 'Veritabanı hatası.' }, { status: 500 }));
- return;
- }
-
- const updatedSlip = {
- ...row,
- vehicle_info: row.vehicle_info ? JSON.parse(row.vehicle_info) : null,
- personnel_info: row.personnel_info ? JSON.parse(row.personnel_info) : null,
- goods_manager_info: row.goods_manager_info ? JSON.parse(row.goods_manager_info) : null,
- fuel_manager_info: row.fuel_manager_info ? JSON.parse(row.fuel_manager_info) : null
- };
-
- console.log('✅ Fuel slip updated:', updatedSlip);
-
- // Socket.IO ile yakıt sorumlusuna bildirim gönder
- const socketData = {
- goods_manager_id: updatedSlip.goods_manager_id,
- fuel_manager_id: updatedSlip.fuel_manager_id,
- fuel_slip_id: updatedSlip.id,
- status: updatedSlip.status,
- approval_notes: updatedSlip.approval_notes
- };
- console.log('📢 Sending socket notification: fuel-slip-updated', socketData);
-
- // Socket client kullanarak bildirim gönder
- const sent = emitSocketEvent('fuel-slip-updated', socketData);
- if (!sent) {
- console.warn('⚠️ Socket notification could not be sent');
- }
-
- resolve(json({
- message: `Fiş başarıyla ${status === 'approved' ? 'onaylandı' : 'reddedildi'}.`,
- fuelSlip: updatedSlip
- }));
- });
- });
- });
-
- } catch (error) {
- console.error('Update fuel slip error:', error);
- return json({ message: 'Sunucu hatası.' }, { status: 500 });
- }
-}
-
-// DELETE - Fiş sil
-export async function DELETE({ request }) {
- try {
- const { id } = await request.json();
-
- if (!id) {
- return json({ message: 'Fiş ID zorunludur.' }, { status: 400 });
- }
-
- return new Promise((resolve) => {
- const db = getDatabase();
-
- // Önce fişin durumunu kontrol et
- db.get('SELECT status FROM fuel_slips WHERE id = ?', [id], (err, row) => {
- if (err) {
- db.close();
- console.error('Check fuel slip error:', err);
- resolve(json({ message: 'Veritabanı hatası.' }, { status: 500 }));
- return;
- }
-
- if (!row) {
- db.close();
- resolve(json({ message: 'Fiş bulunamadı.' }, { status: 404 }));
- return;
- }
-
- // Sadece pending olan fişler silinebilir
- if (row.status !== 'pending') {
- db.close();
- resolve(json({ message: 'Sadece bekleyen fişler silinebilir.' }, { status: 400 }));
- return;
- }
-
- // Fiş sil
- db.run('DELETE FROM fuel_slips WHERE id = ?', [id], function(err) {
- db.close();
-
- if (err) {
- console.error('Delete fuel slip error:', err);
- resolve(json({ message: 'Veritabanı hatası.' }, { status: 500 }));
- return;
- }
-
- if (this.changes === 0) {
- resolve(json({ message: 'Fiş bulunamadı.' }, { status: 404 }));
- return;
- }
-
- resolve(json({
- message: 'Fiş başarıyla silindi.',
- fuelSlipId: parseInt(id)
- }));
- });
- });
- });
-
- } catch (error) {
- console.error('Delete fuel slip error:', error);
- return json({ message: 'Sunucu hatası.' }, { status: 500 });
- }
-}
\ No newline at end of file
diff --git a/src/routes/api/goods-managers/+server.js b/src/routes/api/goods-managers/+server.js
deleted file mode 100644
index 05b2ffd..0000000
--- a/src/routes/api/goods-managers/+server.js
+++ /dev/null
@@ -1,136 +0,0 @@
-import { json } from '@sveltejs/kit';
-import {
- getGoodsManagers,
- addGoodsManager,
- updateGoodsManager,
- deleteGoodsManager
-} from '$lib/data/goodsManagers.js';
-
-// GET - Tüm mal sorumlularını listele
-export async function GET({ request }) {
- // Yetki kontrolü (temporary - will be implemented with proper session)
- try {
- const goodsManagers = getGoodsManagers();
- return json({ goodsManagers });
- } catch (error) {
- return json({ message: 'Mal sorumluları alınırken hata oluştu.' }, { status: 500 });
- }
-}
-
-// POST - Yeni mal sorumlusu ekle
-export async function POST({ request }) {
- // Yetki kontrolü (temporary - will be implemented with proper session)
-
- try {
- const {
- full_name,
- rank,
- registration_number,
- tc_kimlik,
- phone,
- unit_id,
- username,
- password,
- is_active = true
- } = await request.json();
-
- const newManager = addGoodsManager({
- full_name,
- rank,
- registration_number,
- tc_kimlik,
- phone,
- unit_id,
- username,
- password,
- is_active
- });
-
- return json({
- message: 'Personel başarıyla eklendi.',
- goodsManager: newManager
- });
-
- } catch (error) {
- if (error.message.includes('zorunludur') ||
- error.message.includes('zaten kayıtlı') ||
- error.message.includes('Geçersiz') ||
- error.message.includes('karakter')) {
- return json({ message: error.message }, { status: 400 });
- }
- return json({ message: 'Sunucu hatası.' }, { status: 500 });
- }
-}
-
-// PUT - Mal sorumlusu güncelle
-export async function PUT({ request }) {
- // Yetki kontrolü (temporary - will be implemented with proper session)
-
- try {
- const {
- id,
- full_name,
- rank,
- registration_number,
- tc_kimlik,
- phone,
- unit_id,
- username,
- password,
- is_active
- } = await request.json();
-
- const updatedManager = updateGoodsManager(id, {
- full_name,
- rank,
- registration_number,
- tc_kimlik,
- phone,
- unit_id,
- username,
- password,
- is_active
- });
-
- return json({
- message: 'Personel başarıyla güncellendi.',
- goodsManager: updatedManager
- });
-
- } catch (error) {
- if (error.message.includes('zorunludur') ||
- error.message.includes('bulunamadı') ||
- error.message.includes('zaten kayıtlı') ||
- error.message.includes('Geçersiz') ||
- error.message.includes('karakter')) {
- return json({ message: error.message }, { status: error.message.includes('bulunamadı') ? 404 : 400 });
- }
- return json({ message: 'Sunucu hatası.' }, { status: 500 });
- }
-}
-
-// DELETE - Mal sorumlusu sil
-export async function DELETE({ request }) {
- // Yetki kontrolü (temporary - will be implemented with proper session)
-
- try {
- const { id } = await request.json();
-
- if (!id) {
- return json({ message: 'Mal sorumlusu ID zorunludur.' }, { status: 400 });
- }
-
- const deletedManager = deleteGoodsManager(id);
-
- return json({
- message: 'Mal sorumlusu başarıyla silindi.',
- goodsManager: deletedManager
- });
-
- } catch (error) {
- if (error.message.includes('bulunamadı')) {
- return json({ message: error.message }, { status: 404 });
- }
- return json({ message: 'Sunucu hatası.' }, { status: 500 });
- }
-}
\ No newline at end of file
diff --git a/src/routes/api/logout/+server.js b/src/routes/api/logout/+server.js
deleted file mode 100644
index d5d8591..0000000
--- a/src/routes/api/logout/+server.js
+++ /dev/null
@@ -1,6 +0,0 @@
-import { json } from '@sveltejs/kit';
-
-export async function POST() {
- // TODO: Session implementasyonu
- return json({ message: 'Çıkış başarılı.' });
-}
\ No newline at end of file
diff --git a/src/routes/api/units/+server.js b/src/routes/api/units/+server.js
deleted file mode 100644
index 4973fad..0000000
--- a/src/routes/api/units/+server.js
+++ /dev/null
@@ -1,193 +0,0 @@
-import { json } from '@sveltejs/kit';
-
-// Geçici veritabanı simülasyonu
-let units = [
- {
- id: 1,
- name: '1. Motorlu Piyade Tugayı',
- address: 'Mecidiyeköy, Şişli/İstanbul',
- stk: 'STK-12345',
- btk: 'BTK-67890',
- commander: {
- full_name: 'Mehmet Yılmaz',
- rank: 'Yüzbaşı',
- registration_number: '123456',
- tc_kimlik: '12345678901',
- phone: '05321234567'
- },
- created_at: new Date().toISOString()
- },
- {
- id: 2,
- name: '2. Zırhlı Tabur',
- address: 'Havran, Balıkesir',
- stk: 'STK-54321',
- btk: 'BTK-09876',
- commander: {
- full_name: 'Ali Kaya',
- rank: 'Binbaşı',
- registration_number: '654321',
- tc_kimlik: '98765432109',
- phone: '05337654321'
- },
- created_at: new Date().toISOString()
- }
-];
-
-let nextId = 3;
-
-// GET - Tüm birlikleri listele
-export async function GET({ request }) {
- // Yetki kontrolü (temporary - will be implemented with proper session)
- return json({ units });
-}
-
-// POST - Yeni birlik ekle
-export async function POST({ request }) {
- // Yetki kontrolü (temporary - will be implemented with proper session)
-
- try {
- const {
- name,
- address,
- stk,
- btk,
- commander
- } = await request.json();
-
- // Validasyon
- if (!name || !address || !stk || !btk || !commander) {
- return json({ message: 'Tüm alanlar zorunludur.' }, { status: 400 });
- }
-
- // Komutan validasyonu
- const { full_name, rank, registration_number, tc_kimlik, phone } = commander;
- if (!full_name || !rank || !registration_number || !tc_kimlik || !phone) {
- return json({ message: 'Birlik sorumlusunun tüm bilgileri zorunludur.' }, { status: 400 });
- }
-
- // TC Kimlik numarası validasyonu
- if (!/^[0-9]{11}$/.test(tc_kimlik)) {
- return json({ message: 'TC Kimlik numarası 11 haneli olmalıdır.' }, { status: 400 });
- }
-
- // Yeni birlik oluştur
- const newUnit = {
- id: nextId++,
- name: name.trim(),
- address: address.trim(),
- stk: stk.trim().toUpperCase(),
- btk: btk.trim().toUpperCase(),
- commander: {
- full_name: full_name.trim(),
- rank: rank.trim(),
- registration_number: registration_number.trim(),
- tc_kimlik: tc_kimlik.trim(),
- phone: phone.trim()
- },
- created_at: new Date().toISOString()
- };
-
- units.push(newUnit);
-
- return json({
- message: 'Birlik başarıyla eklendi.',
- unit: newUnit
- });
-
- } catch (error) {
- return json({ message: 'Sunucu hatası.' }, { status: 500 });
- }
-}
-
-// PUT - Birlik güncelle
-export async function PUT({ request }) {
- // Yetki kontrolü (temporary - will be implemented with proper session)
-
- try {
- const {
- id,
- name,
- address,
- stk,
- btk,
- commander
- } = await request.json();
-
- // Validasyon
- if (!id || !name || !address || !stk || !btk || !commander) {
- return json({ message: 'Tüm alanlar zorunludur.' }, { status: 400 });
- }
-
- // Komutan validasyonu
- const { full_name, rank, registration_number, tc_kimlik, phone } = commander;
- if (!full_name || !rank || !registration_number || !tc_kimlik || !phone) {
- return json({ message: 'Birlik sorumlusunun tüm bilgileri zorunludur.' }, { status: 400 });
- }
-
- // TC Kimlik numarası validasyonu
- if (!/^[0-9]{11}$/.test(tc_kimlik)) {
- return json({ message: 'TC Kimlik numarası 11 haneli olmalıdır.' }, { status: 400 });
- }
-
- // Birlik bul
- const unitIndex = units.findIndex(u => u.id === parseInt(id));
- if (unitIndex === -1) {
- return json({ message: 'Birlik bulunamadı.' }, { status: 404 });
- }
-
- // Birlik güncelle
- units[unitIndex] = {
- ...units[unitIndex],
- name: name.trim(),
- address: address.trim(),
- stk: stk.trim().toUpperCase(),
- btk: btk.trim().toUpperCase(),
- commander: {
- full_name: full_name.trim(),
- rank: rank.trim(),
- registration_number: registration_number.trim(),
- tc_kimlik: tc_kimlik.trim(),
- phone: phone.trim()
- }
- };
-
- return json({
- message: 'Birlik başarıyla güncellendi.',
- unit: units[unitIndex]
- });
-
- } catch (error) {
- return json({ message: 'Sunucu hatası.' }, { status: 500 });
- }
-}
-
-// DELETE - Birlik sil
-export async function DELETE({ request }) {
- // Yetki kontrolü (temporary - will be implemented with proper session)
-
- try {
- const { id } = await request.json();
-
- if (!id) {
- return json({ message: 'Birlik ID zorunludur.' }, { status: 400 });
- }
-
- // Birlik bul
- const unitIndex = units.findIndex(u => u.id === parseInt(id));
- if (unitIndex === -1) {
- return json({ message: 'Birlik bulunamadı.' }, { status: 404 });
- }
-
- // Birlik sil
- const deletedUnit = units.splice(unitIndex, 1)[0];
-
- return json({
- message: 'Birlik başarıyla silindi.',
- unit: deletedUnit
- });
-
- } catch (error) {
- return json({ message: 'Sunucu hatası.' }, { status: 500 });
- }
-}
\ No newline at end of file
diff --git a/src/routes/api/vehicles/+server.js b/src/routes/api/vehicles/+server.js
deleted file mode 100644
index bb5fede..0000000
--- a/src/routes/api/vehicles/+server.js
+++ /dev/null
@@ -1,144 +0,0 @@
-import { json } from '@sveltejs/kit';
-
-// Geçici veritabanı simülasyonu
-let vehicles = [
- {
- id: 1,
- brand: 'Toyota',
- model: 'Corolla',
- year: 2022,
- plate: '34ABC123',
- created_at: new Date().toISOString()
- },
- {
- id: 2,
- brand: 'Ford',
- model: 'Transit',
- year: 2021,
- plate: '34XYZ789',
- created_at: new Date().toISOString()
- }
-];
-
-let nextId = 3;
-
-// GET - Tüm araçları listele
-export async function GET({ request }) {
- // Yetki kontrolü (temporary - header'dan token kontrolü)
- const authHeader = request.headers.get('authorization');
-
- return json({ vehicles });
-}
-
-// POST - Yeni araç ekle
-export async function POST({ request }) {
- // Yetki kontrolü (temporary - will be implemented with proper session)
-
- try {
- const { brand, model, year, plate } = await request.json();
-
- // Validasyon
- if (!brand || !model || !year || !plate) {
- return json({ message: 'Tüm alanlar zorunludur.' }, { status: 400 });
- }
-
- // Plaka tekrar kontrolü
- const existingVehicle = vehicles.find(v => v.plate.toLowerCase() === plate.toLowerCase());
- if (existingVehicle) {
- return json({ message: 'Bu plaka zaten kayıtlı.' }, { status: 400 });
- }
-
- // Yeni araç oluştur
- const newVehicle = {
- id: nextId++,
- brand: brand.trim(),
- model: model.trim(),
- year: parseInt(year),
- plate: plate.toUpperCase().trim(),
- created_at: new Date().toISOString()
- };
-
- vehicles.push(newVehicle);
-
- return json({
- message: 'Araç başarıyla eklendi.',
- vehicle: newVehicle
- });
-
- } catch (error) {
- return json({ message: 'Sunucu hatası.' }, { status: 500 });
- }
-}
-
-// PUT - Araç güncelle
-export async function PUT({ request }) {
- // Yetki kontrolü (temporary - will be implemented with proper session)
-
- try {
- const { id, brand, model, year, plate } = await request.json();
-
- // Validasyon
- if (!id || !brand || !model || !year || !plate) {
- return json({ message: 'Tüm alanlar zorunludur.' }, { status: 400 });
- }
-
- // Araç bul
- const vehicleIndex = vehicles.findIndex(v => v.id === parseInt(id));
- if (vehicleIndex === -1) {
- return json({ message: 'Araç bulunamadı.' }, { status: 404 });
- }
-
- // Plaka tekrar kontrolü (diğer araçlar için)
- const existingVehicle = vehicles.find(v => v.id !== parseInt(id) && v.plate.toLowerCase() === plate.toLowerCase());
- if (existingVehicle) {
- return json({ message: 'Bu plaka başka bir araçta kullanılıyor.' }, { status: 400 });
- }
-
- // Araç güncelle
- vehicles[vehicleIndex] = {
- ...vehicles[vehicleIndex],
- brand: brand.trim(),
- model: model.trim(),
- year: parseInt(year),
- plate: plate.toUpperCase().trim()
- };
-
- return json({
- message: 'Araç başarıyla güncellendi.',
- vehicle: vehicles[vehicleIndex]
- });
-
- } catch (error) {
- return json({ message: 'Sunucu hatası.' }, { status: 500 });
- }
-}
-
-// DELETE - Araç sil
-export async function DELETE({ request }) {
- // Yetki kontrolü (temporary - will be implemented with proper session)
-
- try {
- const { id } = await request.json();
-
- if (!id) {
- return json({ message: 'Araç ID zorunludur.' }, { status: 400 });
- }
-
- // Araç bul
- const vehicleIndex = vehicles.findIndex(v => v.id === parseInt(id));
- if (vehicleIndex === -1) {
- return json({ message: 'Araç bulunamadı.' }, { status: 404 });
- }
-
- // Araç sil
- const deletedVehicle = vehicles.splice(vehicleIndex, 1)[0];
-
- return json({
- message: 'Araç başarıyla silindi.',
- vehicle: deletedVehicle
- });
-
- } catch (error) {
- return json({ message: 'Sunucu hatası.' }, { status: 500 });
- }
-}
\ No newline at end of file
diff --git a/src/server.js b/src/server.js
index 1c6479c..eb144e4 100644
--- a/src/server.js
+++ b/src/server.js
@@ -1031,6 +1031,8 @@ app.post('/api/vehicles', (req, res) => {
fuel_type,
fuel_capacity,
current_fuel,
+ yazlik_mukannen = 0,
+ kislik_mukannen = 0,
status = 'Aktif',
driver_id,
driver_name
@@ -1067,6 +1069,8 @@ app.post('/api/vehicles', (req, res) => {
fuel_type: fuel_type.trim(),
fuel_capacity: parseInt(fuel_capacity),
current_fuel: parseInt(current_fuel) || 0,
+ yazlik_mukannen: parseInt(yazlik_mukannen) || 0,
+ kislik_mukannen: parseInt(kislik_mukannen) || 0,
status: status.trim(),
driver_id: driver_id ? parseInt(driver_id) : null,
driver_name: driver_name ? driver_name.trim() : null,
@@ -1099,6 +1103,8 @@ app.put('/api/vehicles', (req, res) => {
fuel_type,
fuel_capacity,
current_fuel,
+ yazlik_mukannen,
+ kislik_mukannen,
status,
driver_id,
driver_name
@@ -1141,6 +1147,8 @@ app.put('/api/vehicles', (req, res) => {
fuel_type: fuel_type.trim(),
fuel_capacity: parseInt(fuel_capacity),
current_fuel: parseInt(current_fuel) || 0,
+ yazlik_mukannen: parseInt(yazlik_mukannen) || 0,
+ kislik_mukannen: parseInt(kislik_mukannen) || 0,
status: status.trim(),
driver_id: driver_id ? parseInt(driver_id) : null,
driver_name: driver_name ? driver_name.trim() : null