Simplify declaration creation by removing period selection

Create Declaration Improvements:
- Removed period dropdown selection
- Moved date fields to top of form
- Made start_date and end_date mandatory fields
- Added createDeclarationWithDates() method to DeclarationTVA class
- Added generateDeclarationNumberFromDates() helper method
- Simplified form with direct date input
- Better user experience with mandatory date fields

The form is now more straightforward - users just enter the dates
directly instead of selecting from predefined periods.
This commit is contained in:
Frank Cools 2025-10-02 18:13:16 +02:00
parent c61a964f14
commit e64c1f5a6d
2 changed files with 62 additions and 30 deletions

View File

@ -78,6 +78,45 @@ class DeclarationTVA
return $declaration_id; return $declaration_id;
} }
/**
* Create a new declaration with specific dates
*
* @param string $start_date Start date (YYYY-MM-DD)
* @param string $end_date End date (YYYY-MM-DD)
* @param string $declaration_name Declaration name
* @return int Declaration ID or -1 if error
*/
public function createDeclarationWithDates($start_date, $end_date, $declaration_name = '')
{
global $user;
$this->db->begin();
// Generate declaration number
$declaration_number = $this->generateDeclarationNumberFromDates($start_date, $end_date);
// Create declaration record
$sql = "INSERT INTO " . MAIN_DB_PREFIX . "declarationtva_declarations
(entity, period_id, declaration_number, declaration_name, start_date, end_date, status, created_date)
VALUES (" . $this->entity . ", 0, '" . $declaration_number . "', '" . $this->db->escape($declaration_name) . "', '" . $start_date . "', '" . $end_date . "', 'draft', NOW())";
$result = $this->db->query($sql);
if (!$result) {
$this->error = "Error creating declaration: " . $this->db->lasterror();
$this->db->rollback();
return -1;
}
$declaration_id = $this->db->last_insert_id(MAIN_DB_PREFIX . "declarationtva_declarations");
// Calculate CA-3 amounts
$period = array('start_date' => $start_date, 'end_date' => $end_date);
$this->calculateCA3Amounts($declaration_id, $period);
$this->db->commit();
return $declaration_id;
}
/** /**
* Calculate CA-3 amounts for a declaration * Calculate CA-3 amounts for a declaration
* *
@ -257,6 +296,21 @@ class DeclarationTVA
return 'CA3-' . $year . '-Q' . $quarter . '-' . date('YmdHis'); return 'CA3-' . $year . '-Q' . $quarter . '-' . date('YmdHis');
} }
/**
* Generate declaration number from dates
*
* @param string $start_date Start date
* @param string $end_date End date
* @return string Declaration number
*/
public function generateDeclarationNumberFromDates($start_date, $end_date)
{
$year = date('Y', strtotime($start_date));
$quarter = ceil(date('n', strtotime($start_date)) / 3);
return 'CA3-' . $year . '-Q' . $quarter . '-' . date('YmdHis');
}
/** /**
* Get declaration information * Get declaration information
* *

View File

@ -38,7 +38,6 @@ $period = new DeclarationTVA_Period($db, $conf->entity);
// Handle form submission // Handle form submission
$action = GETPOST('action', 'alpha'); $action = GETPOST('action', 'alpha');
$period_id = GETPOST('period_id', 'int');
$declaration_name = GETPOST('declaration_name', 'alpha'); $declaration_name = GETPOST('declaration_name', 'alpha');
$start_date = GETPOST('start_date', 'alpha'); $start_date = GETPOST('start_date', 'alpha');
$end_date = GETPOST('end_date', 'alpha'); $end_date = GETPOST('end_date', 'alpha');
@ -46,9 +45,9 @@ $end_date = GETPOST('end_date', 'alpha');
$error = ''; $error = '';
$success = ''; $success = '';
if ($action == 'create' && $period_id > 0) { if ($action == 'create' && !empty($start_date) && !empty($end_date)) {
// Create the declaration // Create the declaration with dates
$declaration_id = $declarationtva->createDeclaration($period_id, $declaration_name); $declaration_id = $declarationtva->createDeclarationWithDates($start_date, $end_date, $declaration_name);
if ($declaration_id > 0) { if ($declaration_id > 0) {
$success = $langs->trans("DeclarationCreated"); $success = $langs->trans("DeclarationCreated");
@ -60,9 +59,6 @@ if ($action == 'create' && $period_id > 0) {
} }
} }
// Get available periods
$periods = $period->getAllPeriods();
// Page title // Page title
$title = $langs->trans("CreateDeclaration"); $title = $langs->trans("CreateDeclaration");
llxHeader('', $title); llxHeader('', $title);
@ -87,21 +83,14 @@ print '<input type="hidden" name="action" value="create">';
print '<table class="noborder centpercent">'; print '<table class="noborder centpercent">';
// Period selection // Date range (now mandatory and at the top)
print '<tr>'; print '<tr>';
print '<td class="fieldrequired">' . $langs->trans("SelectPeriod") . '</td>'; print '<td class="fieldrequired">' . $langs->trans("SelectPeriod") . '</td>';
print '<td>'; print '<td>';
print '<select name="period_id" class="flat" required>'; print '<input type="date" name="start_date" class="flat" value="' . dol_escape_htmltag($start_date) . '" required>';
print '<option value="">' . $langs->trans("ChoosePeriod") . '</option>'; print ' - ';
print '<input type="date" name="end_date" class="flat" value="' . dol_escape_htmltag($end_date) . '" required>';
foreach ($periods as $p) { print '<br><small>' . $langs->trans("DateRangeHelp") . '</small>';
$selected = ($period_id == $p['rowid']) ? ' selected' : '';
print '<option value="' . $p['rowid'] . '"' . $selected . '>';
print $p['period_name'] . ' (' . dol_print_date($p['start_date'], 'day') . ' - ' . dol_print_date($p['end_date'], 'day') . ')';
print '</option>';
}
print '</select>';
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
@ -114,17 +103,6 @@ print '<br><small>' . $langs->trans("DeclarationNameHelp") . '</small>';
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
// Date range (optional override)
print '<tr>';
print '<td>' . $langs->trans("DateRange") . '</td>';
print '<td>';
print '<input type="date" name="start_date" class="flat" value="' . dol_escape_htmltag($start_date) . '">';
print ' - ';
print '<input type="date" name="end_date" class="flat" value="' . dol_escape_htmltag($end_date) . '">';
print '<br><small>' . $langs->trans("DateRangeHelp") . '</small>';
print '</td>';
print '</tr>';
print '</table>'; print '</table>';
// Buttons // Buttons