Yakıt Fişi Oluşturma ekranındaki sorun giderildi.
This commit is contained in:
@@ -48,6 +48,7 @@
|
|||||||
let personnel = [];
|
let personnel = [];
|
||||||
let goodsManagers = [];
|
let goodsManagers = [];
|
||||||
let filteredGoodsManagers = [];
|
let filteredGoodsManagers = [];
|
||||||
|
let filteredVehicles = [];
|
||||||
let formError = "";
|
let formError = "";
|
||||||
let formSuccess = "";
|
let formSuccess = "";
|
||||||
let isSubmitting = false;
|
let isSubmitting = false;
|
||||||
@@ -65,6 +66,13 @@
|
|||||||
notes: ""
|
notes: ""
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function setFormField(field, value) {
|
||||||
|
if (formData[field] === value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
formData = { ...formData, [field]: value };
|
||||||
|
}
|
||||||
|
|
||||||
$: displayPendingSlips = pendingSlips;
|
$: displayPendingSlips = pendingSlips;
|
||||||
$: displayHistorySlips = approvedRejectedSlips;
|
$: displayHistorySlips = approvedRejectedSlips;
|
||||||
|
|
||||||
@@ -167,6 +175,7 @@
|
|||||||
if (vehiclesRes.ok) {
|
if (vehiclesRes.ok) {
|
||||||
const vehiclesData = await vehiclesRes.json();
|
const vehiclesData = await vehiclesRes.json();
|
||||||
vehicles = vehiclesData.vehicles || [];
|
vehicles = vehiclesData.vehicles || [];
|
||||||
|
await syncVehicleSelection(formData.unit_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unitsRes.ok) {
|
if (unitsRes.ok) {
|
||||||
@@ -208,6 +217,7 @@
|
|||||||
notes: ""
|
notes: ""
|
||||||
};
|
};
|
||||||
syncGoodsManagerSelection("");
|
syncGoodsManagerSelection("");
|
||||||
|
syncVehicleSelection("");
|
||||||
}
|
}
|
||||||
|
|
||||||
function getGoodsManagersByUnit(unitId) {
|
function getGoodsManagersByUnit(unitId) {
|
||||||
@@ -221,7 +231,7 @@
|
|||||||
filteredGoodsManagers = candidates;
|
filteredGoodsManagers = candidates;
|
||||||
|
|
||||||
if (!unitId || candidates.length === 0) {
|
if (!unitId || candidates.length === 0) {
|
||||||
formData.goods_manager_id = "";
|
setFormField("goods_manager_id", "");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,13 +241,56 @@
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (!hasCurrent) {
|
if (!hasCurrent) {
|
||||||
formData.goods_manager_id = candidates[0].id.toString();
|
setFormField("goods_manager_id", candidates[0].id.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleUnitChange(event) {
|
function getVehiclesByUnit(unitId) {
|
||||||
formData.unit_id = event.target.value;
|
if (!unitId) {
|
||||||
syncGoodsManagerSelection(formData.unit_id);
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
const normalized = parseInt(unitId);
|
||||||
|
return vehicles.filter((vehicle) => vehicle.unit_id === normalized);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function syncVehicleSelection(unitId = formData.unit_id) {
|
||||||
|
const candidates = getVehiclesByUnit(unitId);
|
||||||
|
filteredVehicles = candidates;
|
||||||
|
|
||||||
|
await tick();
|
||||||
|
|
||||||
|
if (!unitId || candidates.length === 0) {
|
||||||
|
setFormField("vehicle_id", "");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const hasVehicle = candidates.some(
|
||||||
|
(vehicle) =>
|
||||||
|
vehicle.id.toString() === (formData.vehicle_id ?? "").toString()
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!hasVehicle) {
|
||||||
|
setFormField("vehicle_id", candidates[0].id.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$: if (formData.unit_id && filteredVehicles.length > 0) {
|
||||||
|
const hasVehicle = filteredVehicles.some(
|
||||||
|
(vehicle) =>
|
||||||
|
vehicle.id.toString() === (formData.vehicle_id ?? "").toString()
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!hasVehicle) {
|
||||||
|
setFormField("vehicle_id", filteredVehicles[0].id.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleUnitChange(event) {
|
||||||
|
const value = event.target.value;
|
||||||
|
setFormField("unit_id", value);
|
||||||
|
syncGoodsManagerSelection(value);
|
||||||
|
await syncVehicleSelection(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleCreateSlip() {
|
async function handleCreateSlip() {
|
||||||
@@ -1252,14 +1305,19 @@
|
|||||||
id="vehicle_id"
|
id="vehicle_id"
|
||||||
class="form-select"
|
class="form-select"
|
||||||
bind:value={formData.vehicle_id}
|
bind:value={formData.vehicle_id}
|
||||||
|
disabled={!formData.unit_id || filteredVehicles.length === 0}
|
||||||
required
|
required
|
||||||
>
|
>
|
||||||
<option value="">Araç Seçin</option>
|
<option value="" class="s-jZJiUkwef1J0">Araç Seçin</option>
|
||||||
{#each vehicles as vehicle}
|
{#if !formData.unit_id}
|
||||||
<option value={vehicle.id}
|
<option value="">Önce birlik seçin</option>
|
||||||
>{vehicle.brand}
|
{:else if filteredVehicles.length === 0}
|
||||||
{vehicle.model} ({vehicle.plate})</option
|
<option value="">Bu birliğe kayıtlı araç yok</option>
|
||||||
>
|
{/if}
|
||||||
|
{#each filteredVehicles as vehicle}
|
||||||
|
<option value={vehicle.id.toString()}>
|
||||||
|
{vehicle.brand} {vehicle.model} ({vehicle.plate})
|
||||||
|
</option>
|
||||||
{/each}
|
{/each}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
@@ -1310,9 +1368,9 @@
|
|||||||
>
|
>
|
||||||
<option value="">Personel Seçin</option>
|
<option value="">Personel Seçin</option>
|
||||||
{#each personnel as person}
|
{#each personnel as person}
|
||||||
<option value={person.id}
|
<option value={person.id.toString()}>
|
||||||
>{person.rank} {person.full_name}</option
|
{person.rank} {person.full_name}
|
||||||
>
|
</option>
|
||||||
{/each}
|
{/each}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -7,18 +7,19 @@
|
|||||||
</svelte:head>
|
</svelte:head>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { onMount, onDestroy } 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';
|
||||||
|
|
||||||
let user = null;
|
let user = null;
|
||||||
let vehicles = [];
|
let vehicles = [];
|
||||||
let units = [];
|
let units = [];
|
||||||
let personnel = [];
|
let personnel = [];
|
||||||
let fuelSlips = [];
|
let fuelSlips = [];
|
||||||
let approvedRejectedSlips = [];
|
let approvedRejectedSlips = [];
|
||||||
let receivingPersonnel = [];
|
let receivingPersonnel = [];
|
||||||
let filteredReceivingPersonnel = [];
|
let filteredReceivingPersonnel = [];
|
||||||
|
let filteredVehicles = [];
|
||||||
let loading = true;
|
let loading = true;
|
||||||
let error = '';
|
let error = '';
|
||||||
let showCreateModal = false;
|
let showCreateModal = false;
|
||||||
@@ -30,18 +31,25 @@ let filteredReceivingPersonnel = [];
|
|||||||
|
|
||||||
// Form değişkenleri
|
// Form değişkenleri
|
||||||
let formData = {
|
let formData = {
|
||||||
date: new Date().toISOString().split('T')[0],
|
date: new Date().toISOString().split('T')[0],
|
||||||
force_command: '',
|
force_command: '',
|
||||||
unit_id: '',
|
unit_id: '',
|
||||||
vehicle_id: '',
|
vehicle_id: '',
|
||||||
fuel_type: 'benzin',
|
fuel_type: 'benzin',
|
||||||
liters: '',
|
liters: '',
|
||||||
km: '',
|
km: '',
|
||||||
personnel_id: '',
|
personnel_id: '',
|
||||||
goods_manager_id: '',
|
goods_manager_id: '',
|
||||||
notes: ''
|
notes: ''
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function setFormField(field, value) {
|
||||||
|
if (formData[field] === value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
formData = { ...formData, [field]: value };
|
||||||
|
}
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
const userData = localStorage.getItem('user');
|
const userData = localStorage.getItem('user');
|
||||||
if (!userData || JSON.parse(userData).role !== 'fuel_manager') {
|
if (!userData || JSON.parse(userData).role !== 'fuel_manager') {
|
||||||
@@ -89,6 +97,7 @@ let filteredReceivingPersonnel = [];
|
|||||||
if (vehiclesRes.ok) {
|
if (vehiclesRes.ok) {
|
||||||
const vehiclesData = await vehiclesRes.json();
|
const vehiclesData = await vehiclesRes.json();
|
||||||
vehicles = vehiclesData.vehicles || [];
|
vehicles = vehiclesData.vehicles || [];
|
||||||
|
await syncVehicleSelection(formData.unit_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unitsRes.ok) {
|
if (unitsRes.ok) {
|
||||||
@@ -141,30 +150,76 @@ let filteredReceivingPersonnel = [];
|
|||||||
return receivingPersonnel.filter(person => person.unit_id === normalizedUnit);
|
return receivingPersonnel.filter(person => person.unit_id === normalizedUnit);
|
||||||
}
|
}
|
||||||
|
|
||||||
function syncReceiverSelection(unitId = formData.unit_id) {
|
function syncReceiverSelection(unitId = formData.unit_id) {
|
||||||
const candidates = getUnitPersonnelByUnit(unitId);
|
const candidates = getUnitPersonnelByUnit(unitId);
|
||||||
filteredReceivingPersonnel = candidates;
|
filteredReceivingPersonnel = candidates;
|
||||||
|
|
||||||
if (!unitId) {
|
if (!unitId) {
|
||||||
formData.goods_manager_id = '';
|
setFormField('goods_manager_id', '');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (candidates.length === 0) {
|
if (candidates.length === 0) {
|
||||||
formData.goods_manager_id = '';
|
setFormField('goods_manager_id', '');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const hasCurrent = candidates.some(person => person.id.toString() === formData.goods_manager_id?.toString());
|
const hasCurrent = candidates.some(person => person.id.toString() === formData.goods_manager_id?.toString());
|
||||||
if (!hasCurrent) {
|
if (!hasCurrent) {
|
||||||
formData.goods_manager_id = candidates[0].id.toString();
|
setFormField('goods_manager_id', candidates[0].id.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleUnitChange(event) {
|
function getVehiclesByUnit(unitId) {
|
||||||
|
if (!unitId) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
const normalized = parseInt(unitId);
|
||||||
|
return vehicles.filter((vehicle) => vehicle.unit_id === normalized);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function syncVehicleSelection(unitId = formData.unit_id) {
|
||||||
|
if (!unitId) {
|
||||||
|
filteredVehicles = [];
|
||||||
|
setFormField('vehicle_id', '');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const candidates = getVehiclesByUnit(unitId);
|
||||||
|
filteredVehicles = candidates;
|
||||||
|
|
||||||
|
await tick();
|
||||||
|
|
||||||
|
if (candidates.length === 0) {
|
||||||
|
setFormField('vehicle_id', '');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const hasVehicle = candidates.some(
|
||||||
|
(vehicle) => vehicle.id.toString() === formData.vehicle_id?.toString()
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!hasVehicle) {
|
||||||
|
setFormField('vehicle_id', candidates[0].id.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$: if (formData.unit_id && filteredVehicles.length > 0) {
|
||||||
|
const hasVehicle = filteredVehicles.some(
|
||||||
|
(vehicle) => vehicle.id.toString() === formData.vehicle_id?.toString()
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!hasVehicle) {
|
||||||
|
setFormField('vehicle_id', filteredVehicles[0].id.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleUnitChange(event) {
|
||||||
const value = event.target.value;
|
const value = event.target.value;
|
||||||
formData.unit_id = value;
|
setFormField('unit_id', value);
|
||||||
syncReceiverSelection(value);
|
syncReceiverSelection(value);
|
||||||
|
await syncVehicleSelection(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetForm() {
|
function resetForm() {
|
||||||
@@ -181,6 +236,7 @@ let filteredReceivingPersonnel = [];
|
|||||||
notes: ''
|
notes: ''
|
||||||
};
|
};
|
||||||
syncReceiverSelection('');
|
syncReceiverSelection('');
|
||||||
|
syncVehicleSelection('');
|
||||||
}
|
}
|
||||||
|
|
||||||
function openCreateModal() {
|
function openCreateModal() {
|
||||||
@@ -424,17 +480,28 @@ let filteredReceivingPersonnel = [];
|
|||||||
required
|
required
|
||||||
>
|
>
|
||||||
<option value="">Birlik Seçin</option>
|
<option value="">Birlik Seçin</option>
|
||||||
{#each units as unit}
|
{#each units as unit}
|
||||||
<option value={unit.id}>{unit.name}</option>
|
<option value={unit.id.toString()}>{unit.name}</option>
|
||||||
{/each}
|
{/each}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="vehicle_id">Araç</label>
|
<label for="vehicle_id">Araç</label>
|
||||||
<select id="vehicle_id" class="form-select" bind:value={formData.vehicle_id} required>
|
<select
|
||||||
<option value="">Araç Seçin</option>
|
id="vehicle_id"
|
||||||
{#each vehicles as vehicle}
|
class="form-select"
|
||||||
<option value={vehicle.id}>{vehicle.brand} {vehicle.model} ({vehicle.plate})</option>
|
bind:value={formData.vehicle_id}
|
||||||
|
disabled={!formData.unit_id || filteredVehicles.length === 0}
|
||||||
|
required
|
||||||
|
>
|
||||||
|
<option value="" class="s-jZJiUkwef1J0">Araç Seçin</option>
|
||||||
|
{#if !formData.unit_id}
|
||||||
|
<option value="">Önce birlik seçin</option>
|
||||||
|
{:else if filteredVehicles.length === 0}
|
||||||
|
<option value="">Bu birliğe kayıtlı araç yok</option>
|
||||||
|
{/if}
|
||||||
|
{#each filteredVehicles as vehicle}
|
||||||
|
<option value={vehicle.id.toString()}>{vehicle.brand} {vehicle.model} ({vehicle.plate})</option>
|
||||||
{/each}
|
{/each}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
@@ -474,9 +541,9 @@ let filteredReceivingPersonnel = [];
|
|||||||
<label for="personnel_id">Teslim Eden</label>
|
<label for="personnel_id">Teslim Eden</label>
|
||||||
<select id="personnel_id" class="form-select" bind:value={formData.personnel_id} required>
|
<select id="personnel_id" class="form-select" bind:value={formData.personnel_id} required>
|
||||||
<option value="">Personel Seçin</option>
|
<option value="">Personel Seçin</option>
|
||||||
{#each personnel as person}
|
{#each personnel as person}
|
||||||
<option value={person.id}>{person.rank} {person.full_name}</option>
|
<option value={person.id.toString()}>{person.rank} {person.full_name}</option>
|
||||||
{/each}
|
{/each}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
@@ -494,7 +561,7 @@ let filteredReceivingPersonnel = [];
|
|||||||
<option value="">Bu birliğe kayıtlı personel yok</option>
|
<option value="">Bu birliğe kayıtlı personel yok</option>
|
||||||
{/if}
|
{/if}
|
||||||
{#each filteredReceivingPersonnel as person}
|
{#each filteredReceivingPersonnel as person}
|
||||||
<option value={person.id}>{person.rank} {person.full_name}</option>
|
<option value={person.id.toString()}>{person.rank} {person.full_name}</option>
|
||||||
{/each}
|
{/each}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user