Add unvalidate functionality for testing purposes
- Added unvalidateDeclaration() method to DeclarationTVA class - Added unvalidate action handler in declarationtva_view.php - Added red 'Unvalidate' button for validated declarations - Added confirmation dialog for unvalidate action - Added French and English language strings - Allows reverting validated declarations back to draft status - Useful for testing validation process multiple times
This commit is contained in:
parent
77027debf5
commit
a95e0782b6
@ -1035,6 +1035,50 @@ class DeclarationTVA
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unvalidate a declaration (for testing purposes)
|
||||||
|
*
|
||||||
|
* @param int $declaration_id Declaration ID
|
||||||
|
* @return bool Success
|
||||||
|
*/
|
||||||
|
public function unvalidateDeclaration($declaration_id)
|
||||||
|
{
|
||||||
|
// Check if the validated_date and validated_by columns exist
|
||||||
|
$sql_check_columns = "SHOW COLUMNS FROM " . MAIN_DB_PREFIX . "declarationtva_declarations LIKE 'validated_date'";
|
||||||
|
$result_check = $this->db->query($sql_check_columns);
|
||||||
|
$has_validated_columns = ($result_check && $this->db->num_rows($result_check) > 0);
|
||||||
|
|
||||||
|
if ($has_validated_columns) {
|
||||||
|
// Use the enhanced version with validated_date and validated_by
|
||||||
|
$sql = "UPDATE " . MAIN_DB_PREFIX . "declarationtva_declarations
|
||||||
|
SET status = 'draft',
|
||||||
|
validated_date = NULL,
|
||||||
|
validated_by = NULL
|
||||||
|
WHERE rowid = " . (int)$declaration_id . "
|
||||||
|
AND entity = " . $this->entity;
|
||||||
|
} else {
|
||||||
|
// Use the basic version without the additional columns
|
||||||
|
$sql = "UPDATE " . MAIN_DB_PREFIX . "declarationtva_declarations
|
||||||
|
SET status = 'draft'
|
||||||
|
WHERE rowid = " . (int)$declaration_id . "
|
||||||
|
AND entity = " . $this->entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = $this->db->query($sql);
|
||||||
|
if (!$result) {
|
||||||
|
$this->error = "Database error updating declaration: " . $this->db->lasterror();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the update actually affected any rows
|
||||||
|
if ($this->db->affected_rows($result) == 0) {
|
||||||
|
$this->error = "No declaration found with ID " . $declaration_id . " or insufficient permissions";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save validated PDF to Dolibarr documents
|
* Save validated PDF to Dolibarr documents
|
||||||
*
|
*
|
||||||
|
|||||||
@ -122,6 +122,15 @@ if ($action == 'validate' && $token) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($action == 'unvalidate' && $token) {
|
||||||
|
// Unvalidate the declaration (for testing purposes)
|
||||||
|
if ($declarationtva->unvalidateDeclaration($id)) {
|
||||||
|
setEventMessages($langs->trans("DeclarationUnvalidated"), null, 'mesgs');
|
||||||
|
} else {
|
||||||
|
setEventMessages($langs->trans("ErrorUnvalidatingDeclaration") . ": " . $declarationtva->error, null, 'errors');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Fetch declaration
|
// Fetch declaration
|
||||||
if ($declarationtva->fetch($id) < 0) {
|
if ($declarationtva->fetch($id) < 0) {
|
||||||
setEventMessages($langs->trans("DeclarationNotFound"), null, 'errors');
|
setEventMessages($langs->trans("DeclarationNotFound"), null, 'errors');
|
||||||
@ -447,6 +456,8 @@ if ($declarationtva->status == 'draft') {
|
|||||||
print '<a href="#" onclick="confirmValidation(' . $id . '); return false;" class="butAction">' . $langs->trans("Validate") . '</a> ';
|
print '<a href="#" onclick="confirmValidation(' . $id . '); return false;" class="butAction">' . $langs->trans("Validate") . '</a> ';
|
||||||
} elseif ($declarationtva->status == 'validated') {
|
} elseif ($declarationtva->status == 'validated') {
|
||||||
print '<a href="' . $_SERVER['PHP_SELF'] . '?id=' . $id . '&action=submit" class="butAction">' . $langs->trans("Submit") . '</a> ';
|
print '<a href="' . $_SERVER['PHP_SELF'] . '?id=' . $id . '&action=submit" class="butAction">' . $langs->trans("Submit") . '</a> ';
|
||||||
|
// Add unvalidate button for testing
|
||||||
|
print '<a href="' . $_SERVER['PHP_SELF'] . '?id=' . $id . '&action=unvalidate&token=' . newToken() . '" class="butAction" style="background-color: #dc3545;" onclick="return confirm(\'' . $langs->trans("ConfirmUnvalidate") . '\')">' . $langs->trans("Unvalidate") . '</a> ';
|
||||||
}
|
}
|
||||||
|
|
||||||
print '<a href="declarationtvaindex.php" class="butAction">' . $langs->trans("BackToList") . '</a>';
|
print '<a href="declarationtvaindex.php" class="butAction">' . $langs->trans("BackToList") . '</a>';
|
||||||
|
|||||||
@ -501,6 +501,10 @@ YesValidate = Yes, validate
|
|||||||
Cancel = Cancel
|
Cancel = Cancel
|
||||||
DeclarationValidated = Declaration validated successfully
|
DeclarationValidated = Declaration validated successfully
|
||||||
ErrorValidatingDeclaration = Error validating declaration
|
ErrorValidatingDeclaration = Error validating declaration
|
||||||
|
DeclarationUnvalidated = Declaration reverted to draft
|
||||||
|
ErrorUnvalidatingDeclaration = Error reverting to draft
|
||||||
|
Unvalidate = Revert to Draft
|
||||||
|
ConfirmUnvalidate = Are you sure you want to revert this declaration to draft status?
|
||||||
|
|
||||||
# Document and status icons
|
# Document and status icons
|
||||||
Document = Document
|
Document = Document
|
||||||
|
|||||||
@ -473,6 +473,10 @@ YesValidate = Oui, valider
|
|||||||
Cancel = Annuler
|
Cancel = Annuler
|
||||||
DeclarationValidated = Déclaration validée avec succès
|
DeclarationValidated = Déclaration validée avec succès
|
||||||
ErrorValidatingDeclaration = Erreur lors de la validation de la déclaration
|
ErrorValidatingDeclaration = Erreur lors de la validation de la déclaration
|
||||||
|
DeclarationUnvalidated = Déclaration remise en brouillon
|
||||||
|
ErrorUnvalidatingDeclaration = Erreur lors de la remise en brouillon
|
||||||
|
Unvalidate = Remettre en brouillon
|
||||||
|
ConfirmUnvalidate = Êtes-vous sûr de vouloir remettre cette déclaration en brouillon ?
|
||||||
|
|
||||||
# Document and status icons
|
# Document and status icons
|
||||||
Document = Document
|
Document = Document
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user