diff --git a/core/class/declarationtva.class.php b/core/class/declarationtva.class.php
index dca1478..244e6de 100644
--- a/core/class/declarationtva.class.php
+++ b/core/class/declarationtva.class.php
@@ -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;
+ }
}
diff --git a/declarationtvaindex.php b/declarationtvaindex.php
index c33b360..4603ae0 100644
--- a/declarationtvaindex.php
+++ b/declarationtvaindex.php
@@ -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 '' . $langs->trans("Validate") . '';
+ print '' . $langs->trans("Delete") . '';
} elseif ($d['status'] == 'validated') {
print '' . $langs->trans("Submit") . '';
}
diff --git a/langs/en_US/declarationtva.lang b/langs/en_US/declarationtva.lang
index db5987a..d361d43 100644
--- a/langs/en_US/declarationtva.lang
+++ b/langs/en_US/declarationtva.lang
@@ -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
diff --git a/langs/fr_FR/declarationtva.lang b/langs/fr_FR/declarationtva.lang
index 5b93839..ee6c395 100644
--- a/langs/fr_FR/declarationtva.lang
+++ b/langs/fr_FR/declarationtva.lang
@@ -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