@@ -976,12 +1032,30 @@ {:else if user.role === "goods_manager" && showGoodsManagerVehicles} + {:else if user.role === "goods_manager" && showUnitPersonnel} + {:else if user.role === "goods_manager" && showMonthlyReport} {:else if user.role === "goods_manager" && showDevriçark} + {:else if user.role === "goods_manager" && showUnitJournal} +
+
+
+ +
+

Birlik Akaryakıt Jurnali

+
+
+

+ Birliklerin aylık yakıt giriş/çıkış hareketlerini bu alandan + görüntüleyebilir ve raporlayabilirsiniz. Özellik geliştirme + aşamasında, yakında detaylı veri görünümleri eklenecek. +

+
+
{:else if user.role === "admin"} diff --git a/src/server.js b/src/server.js index 2ca3ec4..ee95ecf 100644 --- a/src/server.js +++ b/src/server.js @@ -1029,11 +1029,30 @@ app.delete('/api/fuel-personnel', (req, res) => { // Unit Personnel API endpoint'leri (Teslim Alan personeller) app.get('/api/unit-personnel', (req, res) => { - res.json({ unitPersonnel }); + try { + const { isGoodsManager, unitId } = getGoodsManagerUnit(req); + let filteredPersonnel = unitPersonnel; + const requestedUnitId = req.query.unit_id ? parseInt(req.query.unit_id) : null; + + if (isGoodsManager) { + if (!unitId) { + return res.status(400).json({ message: 'Birlik bilginiz tanımlı değil. Lütfen sistem yöneticisi ile iletişime geçin.' }); + } + filteredPersonnel = filteredPersonnel.filter(person => person.unit_id === unitId); + } else if (requestedUnitId) { + filteredPersonnel = filteredPersonnel.filter(person => person.unit_id === requestedUnitId); + } + + res.json({ unitPersonnel: filteredPersonnel }); + } catch (error) { + console.error('GET /api/unit-personnel error:', error); + res.status(500).json({ message: 'Sunucu hatası.' }); + } }); app.post('/api/unit-personnel', (req, res) => { try { + const { isGoodsManager, unitId: managerUnitId } = getGoodsManagerUnit(req); const { full_name, rank, @@ -1044,10 +1063,16 @@ app.post('/api/unit-personnel', (req, res) => { is_active = true } = req.body; - if (!full_name || !rank || !registration_number || !tc_kimlik || !phone || !unit_id) { + const normalizedUnitId = isGoodsManager ? managerUnitId : parseInt(unit_id); + + if (!full_name || !rank || !registration_number || !tc_kimlik || !phone || !normalizedUnitId) { return res.status(400).json({ message: 'Tüm alanlar zorunludur.' }); } + if (isGoodsManager && !managerUnitId) { + return res.status(400).json({ message: 'Birlik bilginiz tanımlı değil. Lütfen sistem yöneticisi ile iletişime geçin.' }); + } + if (!/^[0-9]{11}$/.test(tc_kimlik)) { return res.status(400).json({ message: 'TC Kimlik numarası 11 haneli olmalıdır.' }); } @@ -1066,7 +1091,7 @@ app.post('/api/unit-personnel', (req, res) => { registration_number: registration_number.trim(), tc_kimlik: tc_kimlik.trim(), phone: phone.trim(), - unit_id: parseInt(unit_id), + unit_id: parseInt(normalizedUnitId), is_active: Boolean(is_active), created_at: new Date().toISOString() }; @@ -1085,6 +1110,7 @@ app.post('/api/unit-personnel', (req, res) => { app.put('/api/unit-personnel', (req, res) => { try { + const { isGoodsManager, unitId: managerUnitId } = getGoodsManagerUnit(req); const { id, full_name, @@ -1096,10 +1122,16 @@ app.put('/api/unit-personnel', (req, res) => { is_active } = req.body; - if (!id || !full_name || !rank || !registration_number || !tc_kimlik || !phone || !unit_id) { + const normalizedUnitId = isGoodsManager ? managerUnitId : parseInt(unit_id); + + if (!id || !full_name || !rank || !registration_number || !tc_kimlik || !phone || !normalizedUnitId) { return res.status(400).json({ message: 'Tüm alanlar zorunludur.' }); } + if (isGoodsManager && !managerUnitId) { + return res.status(400).json({ message: 'Birlik bilginiz tanımlı değil. Lütfen sistem yöneticisi ile iletişime geçin.' }); + } + if (!/^[0-9]{11}$/.test(tc_kimlik)) { return res.status(400).json({ message: 'TC Kimlik numarası 11 haneli olmalıdır.' }); } @@ -1109,6 +1141,10 @@ app.put('/api/unit-personnel', (req, res) => { return res.status(404).json({ message: 'Personel bulunamadı.' }); } + if (isGoodsManager && unitPersonnel[personnelIndex].unit_id !== managerUnitId) { + return res.status(403).json({ message: 'Bu personeli güncelleme yetkiniz yok.' }); + } + const duplicate = unitPersonnel.find(p => p.id !== parseInt(id) && (p.registration_number === registration_number || p.tc_kimlik === tc_kimlik) ); @@ -1123,7 +1159,7 @@ app.put('/api/unit-personnel', (req, res) => { registration_number: registration_number.trim(), tc_kimlik: tc_kimlik.trim(), phone: phone.trim(), - unit_id: parseInt(unit_id), + unit_id: parseInt(normalizedUnitId), is_active: Boolean(is_active) }; @@ -1139,6 +1175,7 @@ app.put('/api/unit-personnel', (req, res) => { app.delete('/api/unit-personnel', (req, res) => { try { + const { isGoodsManager, unitId: managerUnitId } = getGoodsManagerUnit(req); const { id } = req.body; if (!id) { @@ -1150,6 +1187,15 @@ app.delete('/api/unit-personnel', (req, res) => { return res.status(404).json({ message: 'Personel bulunamadı.' }); } + if (isGoodsManager) { + if (!managerUnitId) { + return res.status(400).json({ message: 'Birlik bilginiz tanımlı değil. Lütfen sistem yöneticisi ile iletişime geçin.' }); + } + if (unitPersonnel[personnelIndex].unit_id !== managerUnitId) { + return res.status(403).json({ message: 'Bu personeli silme yetkiniz yok.' }); + } + } + const deletedPersonnel = unitPersonnel.splice(personnelIndex, 1)[0]; res.json({