Как фильтровать продукты по количеству, используемому в модале Laravel для вмешательства?Php

Кемеровские программисты php общаются здесь
Ответить Пред. темаСлед. тема
Anonymous
 Как фильтровать продукты по количеству, используемому в модале Laravel для вмешательства?

Сообщение Anonymous »

Я работаю над приложением Laravel, которое управляет вмешательствами и отслеживает использование продуктов. У меня есть три связанные таблицы:
  • sorties_approuvees (утвержденный выход продукта)
  • interventions
  • intervention_sortie_approuvee (сводная таблица, связывающая вмешательства с одобренным выходом продукта)
I want if the user wants to add a new intervention, not to display in the list of products those where the quantity used is equal to quantity. And if he wants to modify an intervention, display the products where the quantity is greater than the quantity used but also those which are associated with the intervention even if the quantity used is equal to the quantity.

All my forms are displayed in modal form using a button.

Schema::create('sorties_approuvees', function (Blueprint $table) {
$table->id();
$table->string('designation');
$table->string('marque');
$table->integer('quantite');
$table->integer('quantite_utilisee')->default(0);
$table->integer('prix_unitaire');
$table->unsignedBigInteger('produit_id');
$table->unsignedBigInteger('idcat');
$table->unsignedBigInteger('id_storage');
$table->foreign('produit_id')->references('id')->on('sorties');
$table->foreign('idcat')->references('id')->on('categories');
$table->foreign('id_storage')->references('id')->on('storages');
$table->softDeletes();
$table->timestamps();
});

Schema::create('interventions', function (Blueprint $table) {
$table->id();
$table->text('description');
$table->date('date_debut');
$table->date('date_fin');
$table->unsignedBigInteger('demande_id');
$table->unsignedBigInteger('technicien_id');
$table->unsignedBigInteger('Num_Depart');
$table->unsignedBigInteger('Num_Service');
$table->foreign('demande_id')->references('id')->on('demandes_maintenances');
$table->foreign('technicien_id')->references('id')->on('techniciens');
$table->foreign('Num_Depart')->references('Num_Depart')->on('departements');
$table->foreign('Num_Service')->references('Num_Service')->on('services');
$table->string('statut')->default('en attente');
$table->timestamps();
});

Schema::create('intervention_sortie_approuvee', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('intervention_id');
$table->unsignedBigInteger('sortie_approuvee_id');
$table->foreign('intervention_id')->references('id')->on('interventions')->onDelete('cascade');
$table->foreign('sortie_approuvee_id')->references('id')->on('sorties_approuvees')->onDelete('cascade');
$table->integer('quantite')->default(0);
$table->integer('prix_unitaire')->default(0);
$table->timestamps();
});

Кнопка редактирования:


Скрипт:
document.addEventListener("DOMContentLoaded", function() {
const modal = document.getElementById('editModal');

document.querySelectorAll('.edit-btn').forEach(function(button) {
button.addEventListener('click', function() {
const interventionID = this.getAttribute('data-id');
const interventionDescription = this.getAttribute('data-description');
const interventionDateDebut = this.getAttribute('data-date_debut');
const interventionDateFin = this.getAttribute('data-date_fin');
const interventionPieces = JSON.parse(this.getAttribute('data-pieces'));
const interventionDemande = this.getAttribute('data-demande');
const interventionTechnicien = this.getAttribute('data-technicien');
const interventionDepartement = this.getAttribute('data-departement');
const interventionService = this.getAttribute('data-service');
const interventionStatut = this.getAttribute('data-statut');

// Stocker les pièces pour accès dans d'autres scripts
window.interventionPieces = JSON.parse(this.getAttribute('data-pieces'));

console.log('interventionID:', interventionID);
console.log('interventionDescription:', interventionDescription);
console.log('interventionDateDebut:', interventionDateDebut);
console.log('interventionDateFin:', interventionDateFin);
console.log('interventionPieces:', interventionPieces);
console.log('interventionDemande:', interventionDemande);
console.log('interventionTechnicien:', interventionTechnicien);
console.log('interventionDepartement:', interventionDepartement);
console.log('interventionStatut:', interventionStatut);

// Remplir les champs du formulaire avec les données de l'intervention
document.getElementById('edit-interventionId').value = interventionID;
document.getElementById('edit-description').value = interventionDescription;
document.getElementById('edit-date_debut').value = interventionDateDebut;
document.getElementById('edit-date_fin').value = interventionDateFin;
document.getElementById('edit-demande').value = interventionDemande;
document.getElementById('edit-technicien').value = interventionTechnicien;
document.getElementById('edit-departement').value = interventionDepartement;

// Update the statut select field
const statutElement = document.getElementById('edit-statut');
if (statutElement) {
statutElement.value = interventionStatut || ''; // Set it to the fetched status or empty if none
} else {
console.error("Element with ID 'edit-statut' not found");
}

// Vider les lignes existantes du tableau
const tableBody = document.getElementById('pieces-table-body');
tableBody.innerHTML = '';

// Remplir le tableau avec les pièces et quantités
interventionPieces.forEach(function(piece) {
// Ne rien faire si le stock_id est 0 ou si la quantité est 0
if (piece.stock_id != 0 && piece.quantite != 0) {
const row = document.createElement('tr');

const designationCell = document.createElement('td');
designationCell.textContent = piece.designation;

const quantityCell = document.createElement('td');
const quantityInput = document.createElement('input');
quantityInput.type = 'number';
quantityInput.name = 'quantities[]';
quantityInput.value = piece.quantite;
quantityCell.appendChild(quantityInput);

const hiddenInput = document.createElement('input');
hiddenInput.type = 'hidden';
hiddenInput.name = 'pieces[]';
hiddenInput.value = piece.stock_id;

const hiddenCell = document.createElement('td');
hiddenCell.appendChild(hiddenInput);
hiddenCell.style.display = 'none';

row.appendChild(designationCell);
row.appendChild(quantityCell);
row.appendChild(hiddenCell);

tableBody.appendChild(row);
}
});

// Récupérer les services pour le département sélectionné
fetch('/getServicesByDepartement/' + interventionDepartement)
.then(response => response.json())
.then(data => {
var serviceSelect = document.getElementById('edit-service');
serviceSelect.innerHTML = 'Choisir';

data.forEach(function(service) {
var option = document.createElement('option');
option.value = service.Num_Service;
option.textContent = service.Libellé_Service;
serviceSelect.appendChild(option);
});

// Sélectionner le service actuel après avoir rempli les options
document.getElementById('edit-service').value = interventionService;
});

const form = document.querySelector('.custom-form');
form.action = form.action.replace('edit/', 'edit/' + interventionID);

modal.style.display = 'block';
});
});

document.getElementById('edit-departement').addEventListener('change', function() {
var departementId = this.value;

if (departementId) {
fetch('/getServicesByDepartement/' + departementId)
.then(response => response.json())
.then(data => {
var serviceSelect = document.getElementById('edit-service');
serviceSelect.innerHTML = 'Choisir';

data.forEach(function(service) {
var option = document.createElement('option');
option.value = service.Num_Service;
option.textContent = service.Libellé_Service;
serviceSelect.appendChild(option);
});
});
} else {
document.getElementById('edit-service').innerHTML = 'Choisir';
}
});
});



×


@csrf
Modifier Intervention





Description:


Date de Début:


Date de Fin:


Ajouter des pièces utilisées ?


Oui


Non




Designation
Quantity







Technicien:

Choisir
@foreach($techniciens as $technicien)
{{ $technicien->Nom }}
@endforeach


Département:

Choisir
@foreach($departements as $departement)
{{ $departement->Libellé_Depart }}
@endforeach


Service:

Choisir
@foreach($services as $service)
{{ $service->Libellé_Service }}
@endforeach


@if(auth()->user()->role->name ==='admin')

Statut:

En attente
achevee


@endif
Save Changes





Указатель метода
public function index()
{
$interventions = Intervention::with(['demande','departement', 'service', 'technicien', 'sortieApprouvee'])
->orderBy('created_at','desc')
->get();

// Exclure les demandes avec des interventions achevées
$demandes = DemandeMaintenance::where('statut', 'planifiee')
->whereNotIn('id', function ($query) {
$query->select('demande_id')
->from('interventions')
->where('statut', 'achevee');
})
->get();

$departements = Departement::all();
$services = Service::all();
$techniciens = Technicien::all();

// Récupérer tous les produits disponibles ou utilisés
$produits = SortieApprouvee::where('quantite', '>', 0)
->whereColumn('quantite','>','quantite_utilisee')
->withTrashed() // Inclure les produits supprimés temporairement
->get();

return view('resp_interv.interventions.allinterventions',[
'interventions' => $interventions,
'demandes' => $demandes,
'departements' => $departements,
'services' => $services,
'techniciens' => $techniciens,
'produits' => $produits,
]);
}

If I have a cable with quantity = 2 and lamp with quantity = 5 and I use the 2 cables and 3 lamps in an intervention. When the user clicks on the add intervention button, display only the lamp and if he wants to modify the intervention or he had already used the cable and the lamps, display both products.


Подробнее здесь: https://stackoverflow.com/questions/792 ... erventions
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Php»