Add delete functionality for draft declarations
Delete Feature: - Added deleteDeclaration() method to DeclarationTVA class - Only allows deletion of draft declarations (safety check) - Deletes CA-3 lines first, then declaration record - Added delete button to main interface for draft declarations - Added confirmation dialog before deletion - Added success/error messages for delete operations - Added translations in both English and French Security: - Only draft declarations can be deleted - Confirmation dialog prevents accidental deletion - Proper error handling and user feedback The interface now shows a delete button for each draft declaration!
This commit is contained in:
parent
93d68b1095
commit
c3166b0dcc
@ -456,4 +456,43 @@ class DeclarationTVA
|
||||
$result = $this->db->query($sql);
|
||||
return $result !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a declaration
|
||||
*
|
||||
* @param int $declaration_id Declaration ID
|
||||
* @return bool Success
|
||||
*/
|
||||
public function deleteDeclaration($declaration_id)
|
||||
{
|
||||
$this->db->begin();
|
||||
|
||||
// Check if declaration exists and is in draft status
|
||||
$sql = "SELECT status FROM " . MAIN_DB_PREFIX . "declarationtva_declarations
|
||||
WHERE rowid = " . (int)$declaration_id . " AND entity = " . $this->entity;
|
||||
|
||||
$result = $this->db->query($sql);
|
||||
if ($result) {
|
||||
$obj = $this->db->fetch_object($result);
|
||||
if ($obj && $obj->status == 'draft') {
|
||||
// Delete CA-3 lines first
|
||||
$sql_lines = "DELETE FROM " . MAIN_DB_PREFIX . "declarationtva_ca3_lines
|
||||
WHERE declaration_id = " . (int)$declaration_id;
|
||||
$this->db->query($sql_lines);
|
||||
|
||||
// Delete declaration
|
||||
$sql_declaration = "DELETE FROM " . MAIN_DB_PREFIX . "declarationtva_declarations
|
||||
WHERE rowid = " . (int)$declaration_id . " AND entity = " . $this->entity;
|
||||
|
||||
$result = $this->db->query($sql_declaration);
|
||||
if ($result) {
|
||||
$this->db->commit();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->rollback();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -61,6 +61,12 @@ if ($action == 'create_declaration' && $period_id > 0) {
|
||||
} else {
|
||||
setEventMessages($langs->trans("ErrorSubmittingDeclaration"), null, 'errors');
|
||||
}
|
||||
} elseif ($action == 'delete_declaration' && $declaration_id > 0) {
|
||||
if ($declarationtva->deleteDeclaration($declaration_id)) {
|
||||
setEventMessages($langs->trans("DeclarationDeleted"), null, 'mesgs');
|
||||
} else {
|
||||
setEventMessages($langs->trans("ErrorDeletingDeclaration"), null, 'errors');
|
||||
}
|
||||
}
|
||||
|
||||
// Get data for display
|
||||
@ -129,6 +135,7 @@ if (empty($declarations)) {
|
||||
|
||||
if ($d['status'] == 'draft') {
|
||||
print '<a href="' . $_SERVER['PHP_SELF'] . '?action=validate_declaration&declaration_id=' . $d['rowid'] . '" class="butAction">' . $langs->trans("Validate") . '</a>';
|
||||
print '<a href="' . $_SERVER['PHP_SELF'] . '?action=delete_declaration&declaration_id=' . $d['rowid'] . '" class="butActionDelete" onclick="return confirm(\'' . $langs->trans("ConfirmDeleteDeclaration") . '\')">' . $langs->trans("Delete") . '</a>';
|
||||
} elseif ($d['status'] == 'validated') {
|
||||
print '<a href="' . $_SERVER['PHP_SELF'] . '?action=submit_declaration&declaration_id=' . $d['rowid'] . '" class="butAction">' . $langs->trans("Submit") . '</a>';
|
||||
}
|
||||
|
||||
@ -402,7 +402,11 @@ DeclarationSubmitted = Declaration submitted successfully
|
||||
ErrorCreatingDeclaration = Error creating declaration
|
||||
ErrorValidatingDeclaration = Error validating declaration
|
||||
ErrorSubmittingDeclaration = Error submitting declaration
|
||||
ErrorDeletingDeclaration = Error deleting declaration
|
||||
ErrorMissingDates = Please provide both start and end dates
|
||||
DeclarationDeleted = Declaration deleted successfully
|
||||
Delete = Delete
|
||||
ConfirmDeleteDeclaration = Are you sure you want to delete this declaration? This action cannot be undone.
|
||||
|
||||
# Create Declaration Page
|
||||
DeclarationDetails = Declaration Details
|
||||
|
||||
@ -391,7 +391,11 @@ DeclarationSubmitted = Déclaration soumise avec succès
|
||||
ErrorCreatingDeclaration = Erreur lors de la création de la déclaration
|
||||
ErrorValidatingDeclaration = Erreur lors de la validation de la déclaration
|
||||
ErrorSubmittingDeclaration = Erreur lors de la soumission de la déclaration
|
||||
ErrorDeletingDeclaration = Erreur lors de la suppression de la déclaration
|
||||
ErrorMissingDates = Veuillez fournir les dates de début et de fin
|
||||
DeclarationDeleted = Déclaration supprimée avec succès
|
||||
Delete = Supprimer
|
||||
ConfirmDeleteDeclaration = Êtes-vous sûr de vouloir supprimer cette déclaration ? Cette action ne peut pas être annulée.
|
||||
|
||||
# Create Declaration Page
|
||||
DeclarationDetails = Détails de la déclaration
|
||||
|
||||
Loading…
Reference in New Issue
Block a user