changed assegna proprietario
This commit is contained in:
@@ -77,6 +77,8 @@ $resultAvailableOwners = $queryAvailableOwners->get_result();
|
||||
<link href="assets/css/bootstrap.min.css" rel="stylesheet" type="text/css">
|
||||
<link href="assets/css/icons.css" rel="stylesheet" type="text/css">
|
||||
<link href="assets/css/style.css" rel="stylesheet" type="text/css">
|
||||
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
||||
|
||||
</head>
|
||||
|
||||
<body class="fixed-left">
|
||||
@@ -105,42 +107,46 @@ $resultAvailableOwners = $queryAvailableOwners->get_result();
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php if ($resultOwners->num_rows > 0) { ?>
|
||||
<table class="table table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Nome</th>
|
||||
<th>Codice Fiscale</th>
|
||||
<th>%</th>
|
||||
<th>Note</th>
|
||||
<th>Azioni</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php while ($owner = $resultOwners->fetch_assoc()) { ?>
|
||||
<div id="ownersTable">
|
||||
<table class="table table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<td>
|
||||
<?php
|
||||
echo htmlspecialchars($owner['first_name'] . ' ' . $owner['last_name']);
|
||||
if ($owner['company_name']) {
|
||||
echo ' (' . htmlspecialchars($owner['company_name']) . ')';
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
<td><?php echo htmlspecialchars($owner['tax_code']); ?></td>
|
||||
<td><?php echo htmlspecialchars($owner['ownership_percentage']); ?></td>
|
||||
<td><?php echo htmlspecialchars($owner['notes']); ?></td>
|
||||
<td>
|
||||
<?php if (!$disableEditing) { ?>
|
||||
<button class="btn btn-danger btn-sm remove-owner-btn" data-id="<?php echo $owner['owner_id']; ?>">
|
||||
<i class="fas fa-trash-alt"></i> Rimuovi
|
||||
</button>
|
||||
<?php } ?>
|
||||
</td>
|
||||
|
||||
<th>Nome</th>
|
||||
<th>Codice Fiscale</th>
|
||||
<th>%</th>
|
||||
<th>Note</th>
|
||||
<th>Azioni</th>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</thead>
|
||||
<tbody id="ownersTableBody">
|
||||
<?php
|
||||
$totalPercentage = 0;
|
||||
while ($owner = $resultOwners->fetch_assoc()) {
|
||||
$totalPercentage += $owner['ownership_percentage'];
|
||||
echo "<tr>
|
||||
<td>" . htmlspecialchars($owner['first_name'] . ' ' . $owner['last_name']) . "</td>
|
||||
<td>" . htmlspecialchars($owner['tax_code']) . "</td>
|
||||
<td class='ownership-percentage'>" . htmlspecialchars($owner['ownership_percentage']) . "</td>
|
||||
<td>" . htmlspecialchars($owner['notes']) . "</td>
|
||||
<td>
|
||||
<button class='btn btn-danger btn-sm remove-owner-btn' data-id='" . $owner['owner_id'] . "'>
|
||||
<i class='fas fa-trash-alt'></i> Rimuovi
|
||||
</button>
|
||||
</td>
|
||||
</tr>";
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td colspan="2"><strong>Totale % Proprietà:</strong></td>
|
||||
<td id="totalOwnership" class="font-weight-bold text-center"><?php echo $totalPercentage; ?>%</td>
|
||||
<td colspan="2"></td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<?php } else { ?>
|
||||
<p class="text-muted">Nessun proprietario associato.</p>
|
||||
<?php } ?>
|
||||
@@ -151,7 +157,7 @@ $resultAvailableOwners = $queryAvailableOwners->get_result();
|
||||
<?php if (!$disableEditing) { ?>
|
||||
<div class="card mb-4">
|
||||
<div class="card-header bg-info text-white">
|
||||
<h5 class="mb-0">Aggiungi Proprietari</h5>
|
||||
<h5 class="mb-0">Assegna Proprietari</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form id="addOwnerForm" method="POST" action="add-owner-to-home.php">
|
||||
@@ -171,17 +177,24 @@ $resultAvailableOwners = $queryAvailableOwners->get_result();
|
||||
?>
|
||||
</option>
|
||||
<?php } ?>
|
||||
<option value="new_owner">➕ Aggiungi nuovo proprietario</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label for="ownershipPercentage">Percentuale di Proprietà</label>
|
||||
<input type="number" step="0.01" class="form-control" id="ownershipPercentage" name="ownership_percentage" placeholder="Inserisci la percentuale (es. 50.00)">
|
||||
<input type="number" step="0.01" class="form-control" id="ownershipPercentage"
|
||||
name="ownership_percentage" placeholder="Inserisci la percentuale (es. 50.00)"
|
||||
oninput="validatePercentage()" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="notes">Note</label>
|
||||
<textarea class="form-control" id="notes" name="notes" rows="3" placeholder="Aggiungi eventuali note"></textarea>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-success mt-3">Aggiungi</button>
|
||||
<!-- Messaggio di errore -->
|
||||
<small id="percentageError" class="text-danger" style="display:none;">La somma totale non può superare il 100%.</small>
|
||||
<button type="submit" id="addOwnerBtn" class="btn btn-success mt-3">Aggiungi</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
@@ -198,26 +211,293 @@ $resultAvailableOwners = $queryAvailableOwners->get_result();
|
||||
<?php include('include/footer.php'); ?>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Modal Aggiungi Nuovo Proprietario -->
|
||||
<div class="modal fade" id="newOwnerModal" tabindex="-1" aria-labelledby="newOwnerModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-lg"> <!-- Più largo per migliorare la leggibilità -->
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="newOwnerModalLabel">Aggiungi Nuovo Proprietario</h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form id="newOwnerForm">
|
||||
<input type="hidden" name="user_id" value="<?php echo $iduserlogin; ?>">
|
||||
|
||||
<div class="row">
|
||||
<!-- Tipo Proprietario -->
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<label for="ownerType">Tipo Proprietario</label>
|
||||
<select class="form-control" id="ownerType" name="owner_type" required>
|
||||
<option value="individual">Persona Fisica</option>
|
||||
<option value="company">Azienda</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Codice Fiscale / P. IVA -->
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<label for="taxCode">Codice Fiscale / Partita IVA</label>
|
||||
<input type="text" class="form-control" id="taxCode" name="tax_code" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Nome -->
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<label for="firstName">Nome</label>
|
||||
<input type="text" class="form-control" id="firstName" name="first_name">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Cognome -->
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<label for="lastName">Cognome</label>
|
||||
<input type="text" class="form-control" id="lastName" name="last_name">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Nome Azienda -->
|
||||
<div class="col-md-12">
|
||||
<div class="form-group">
|
||||
<label for="companyName">Nome Azienda</label>
|
||||
<input type="text" class="form-control" id="companyName" name="company_name" disabled>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Email -->
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<label for="email">Email</label>
|
||||
<input type="email" class="form-control" id="email" name="email" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Telefono -->
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<label for="phone">Telefono</label>
|
||||
<input type="text" class="form-control" id="phone" name="phone">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Indirizzo -->
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<label for="address">Indirizzo</label>
|
||||
<input type="text" class="form-control" id="address" name="address">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- CAP -->
|
||||
<div class="col-md-3">
|
||||
<div class="form-group">
|
||||
<label for="postalCode">CAP</label>
|
||||
<input type="text" class="form-control" id="postalCode" name="postal_code">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Città -->
|
||||
<div class="col-md-3">
|
||||
<div class="form-group">
|
||||
<label for="city">Città</label>
|
||||
<input type="text" class="form-control" id="city" name="city">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Provincia -->
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<label for="province">Provincia</label>
|
||||
<input type="text" class="form-control" id="province" name="province">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Nazione (Select2) -->
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<label for="country">Nazione</label>
|
||||
<select class="form-control" id="country" name="country">
|
||||
<option value="">-- Seleziona --</option>
|
||||
<?php
|
||||
$queryCountries = $conn->query("SELECT id, name FROM auth_countries ORDER BY name");
|
||||
while ($country = $queryCountries->fetch_assoc()) {
|
||||
echo "<option value='{$country['id']}'>" . htmlspecialchars($country['name']) . "</option>";
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Ruolo -->
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<label for="role">Ruolo</label>
|
||||
<input type="text" class="form-control" id="role" name="role">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Note -->
|
||||
<div class="col-md-12">
|
||||
<div class="form-group">
|
||||
<label for="notes">Note</label>
|
||||
<textarea class="form-control" id="notes" name="notes" rows="3"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-success">Salva Proprietario</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<script src="assets/js/jquery.min.js"></script>
|
||||
<script src="assets/js/bootstrap.min.js"></script>
|
||||
<script>
|
||||
$(document).on('click', '.remove-owner-btn', function() {
|
||||
const ownerId = $(this).data('id');
|
||||
const idhome = "<?php echo $idhome; ?>";
|
||||
<!-- Include Select2 -->
|
||||
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/css/select2.min.css" rel="stylesheet" />
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/js/select2.min.js"></script>
|
||||
|
||||
if (confirm('Sei sicuro di voler rimuovere questo proprietario?')) {
|
||||
$.post('remove-owner-from-home.php', {
|
||||
owner_id: ownerId,
|
||||
idhome: idhome
|
||||
}, function(response) {
|
||||
location.reload();
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
// Attiva Select2 per il campo "Nazione"
|
||||
$("#country").select2({
|
||||
width: '100%',
|
||||
placeholder: "Seleziona un paese...",
|
||||
allowClear: true
|
||||
});
|
||||
|
||||
// Selezione del proprietario nel dropdown
|
||||
$("#ownerSelect").change(function() {
|
||||
if ($(this).val() === "new_owner") {
|
||||
$("#newOwnerModal").modal("show"); // Apri il modale
|
||||
$(this).val(""); // Resetta il valore del dropdown
|
||||
}
|
||||
});
|
||||
|
||||
// Abilita/disabilita i campi in base al tipo di proprietario
|
||||
$("#ownerType").change(function() {
|
||||
if ($(this).val() === "company") {
|
||||
$("#companyName").prop("disabled", false);
|
||||
$("#firstName, #lastName").prop("disabled", true).val("");
|
||||
} else {
|
||||
$("#companyName").prop("disabled", true).val("");
|
||||
$("#firstName, #lastName").prop("disabled", false);
|
||||
}
|
||||
});
|
||||
|
||||
// Invio dati AJAX per aggiungere il nuovo proprietario
|
||||
$("#newOwnerForm").submit(function(e) {
|
||||
e.preventDefault(); // Evita il refresh della pagina
|
||||
let formData = $(this).serialize();
|
||||
|
||||
$.post("add-new-owner.php", formData, function(response) {
|
||||
let result = JSON.parse(response);
|
||||
|
||||
if (result.success) {
|
||||
Swal.fire({
|
||||
icon: "success",
|
||||
title: "Proprietario aggiunto!",
|
||||
text: result.message,
|
||||
timer: 1500,
|
||||
showConfirmButton: false
|
||||
}).then(() => {
|
||||
$("#newOwnerModal").modal("hide"); // Chiudi il modale
|
||||
|
||||
// Aggiungi il nuovo proprietario al dropdown
|
||||
$("#ownerSelect").prepend(`<option value="${result.owner_id}" selected>
|
||||
${result.owner_name} - ${result.tax_code}
|
||||
</option>`);
|
||||
});
|
||||
} else {
|
||||
Swal.fire({
|
||||
icon: "error",
|
||||
title: "Errore!",
|
||||
text: result.message
|
||||
});
|
||||
}
|
||||
}).fail(function() {
|
||||
alert('Errore durante la rimozione del proprietario.');
|
||||
Swal.fire({
|
||||
icon: "error",
|
||||
title: "Errore!",
|
||||
text: "Si è verificato un problema."
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
function getTotalOwnership() {
|
||||
let total = 0;
|
||||
document.querySelectorAll(".ownership-percentage").forEach(function(el) {
|
||||
total += parseFloat(el.textContent) || 0;
|
||||
});
|
||||
return total;
|
||||
}
|
||||
|
||||
function validatePercentage() {
|
||||
let totalOwnership = getTotalOwnership();
|
||||
let newPercentage = parseFloat(document.getElementById("ownershipPercentage").value) || 0;
|
||||
let remainingPercentage = 100 - totalOwnership;
|
||||
|
||||
let errorMsg = document.getElementById("percentageError");
|
||||
let submitBtn = document.getElementById("addOwnerBtn");
|
||||
|
||||
if (newPercentage > remainingPercentage) {
|
||||
errorMsg.style.display = "block";
|
||||
submitBtn.disabled = true;
|
||||
} else {
|
||||
errorMsg.style.display = "none";
|
||||
submitBtn.disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Disabilita il form se già 100%
|
||||
let addOwnerForm = document.getElementById("addOwnerForm");
|
||||
let addOwnerBtn = document.getElementById("addOwnerBtn");
|
||||
if (getTotalOwnership() >= 100) {
|
||||
addOwnerForm.style.display = "none";
|
||||
document.getElementById("totalOwnership").style.backgroundColor = "#28a745"; // Verde
|
||||
document.getElementById("totalOwnership").style.color = "#fff";
|
||||
}
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
let totalOwnership = 0;
|
||||
|
||||
// Somma tutte le percentuali di proprietà
|
||||
document.querySelectorAll(".ownership-percentage").forEach(function(el) {
|
||||
totalOwnership += parseFloat(el.textContent) || 0;
|
||||
});
|
||||
|
||||
// Seleziona il campo nel footer
|
||||
let totalCell = document.getElementById("totalOwnership");
|
||||
|
||||
// Imposta il valore e il colore di sfondo in base al totale
|
||||
totalCell.textContent = totalOwnership.toFixed(2) + "%";
|
||||
if (totalOwnership >= 100) {
|
||||
totalCell.style.backgroundColor = "#28a745"; // Verde
|
||||
totalCell.style.color = "#fff";
|
||||
} else {
|
||||
totalCell.style.backgroundColor = "#ffc107"; // Arancione
|
||||
totalCell.style.color = "#212529";
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
<script>
|
||||
$(document).on('click', '.remove-owner-btn', function() {
|
||||
const ownerId = $(this).data('id');
|
||||
@@ -276,7 +556,83 @@ $resultAvailableOwners = $queryAvailableOwners->get_result();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
document.getElementById("addOwnerForm").addEventListener("submit", function(e) {
|
||||
e.preventDefault(); // Previene il refresh della pagina
|
||||
|
||||
let formData = new FormData(this);
|
||||
|
||||
fetch("add-owner-to-home.php", {
|
||||
method: "POST",
|
||||
body: formData,
|
||||
})
|
||||
.then(response => response.json()) // Converti la risposta in JSON
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
Swal.fire({
|
||||
icon: "success",
|
||||
title: "Proprietario aggiunto!",
|
||||
text: data.message,
|
||||
timer: 1500,
|
||||
showConfirmButton: false
|
||||
}).then(() => {
|
||||
// Aggiorna la tabella dei proprietari
|
||||
fetch("get-owners.php?idhome=<?php echo $idhome; ?>")
|
||||
.then(response => response.text())
|
||||
.then(html => {
|
||||
document.getElementById("ownersTable").innerHTML = html;
|
||||
});
|
||||
|
||||
// **Aggiorna il dropdown con i proprietari disponibili**
|
||||
fetch("get-available-owners.php?idhome=<?php echo $idhome; ?>")
|
||||
.then(response => response.text())
|
||||
.then(html => {
|
||||
document.getElementById("ownerSelectContainer").innerHTML = html;
|
||||
});
|
||||
|
||||
// Resetta il form
|
||||
document.getElementById("addOwnerForm").reset();
|
||||
});
|
||||
} else {
|
||||
Swal.fire({
|
||||
icon: "error",
|
||||
title: "Errore!",
|
||||
text: data.message
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error("Errore AJAX:", error);
|
||||
Swal.fire({
|
||||
icon: "error",
|
||||
title: "Errore!",
|
||||
text: "Si è verificato un problema con la richiesta."
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
function validatePercentage() {
|
||||
let totalOwnership = 0;
|
||||
document.querySelectorAll(".ownership-percentage").forEach(function(el) {
|
||||
totalOwnership += parseFloat(el.textContent) || 0;
|
||||
});
|
||||
|
||||
let newPercentage = parseFloat(document.getElementById("ownershipPercentage").value) || 0;
|
||||
let remainingPercentage = 100 - totalOwnership;
|
||||
|
||||
let errorMsg = document.getElementById("percentageError");
|
||||
let submitBtn = document.getElementById("addOwnerBtn");
|
||||
|
||||
if (newPercentage > remainingPercentage) {
|
||||
errorMsg.style.display = "block";
|
||||
submitBtn.disabled = true;
|
||||
} else {
|
||||
errorMsg.style.display = "none";
|
||||
submitBtn.disabled = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user