rights->declarationtva->read) {
accessforbidden();
}
// Load language files
$langs->load("declarationtva@declarationtva");
// Initialize objects
$declarationtva = new DeclarationTVA($db, $conf->entity);
$config = new DeclarationTVA_Config($db, $conf->entity);
$period = new DeclarationTVA_Period($db, $conf->entity);
// Handle actions
$action = GETPOST('action', 'alpha');
$declaration_id = GETPOST('declaration_id', 'int');
$period_id = GETPOST('period_id', 'int');
// Process actions
if ($action == 'create_declaration' && $period_id > 0) {
$declaration_id = $declarationtva->createDeclaration($period_id);
if ($declaration_id > 0) {
setEventMessages($langs->trans("DeclarationCreated"), null, 'mesgs');
} else {
setEventMessages($langs->trans("ErrorCreatingDeclaration") . ": " . $declarationtva->error, null, 'errors');
}
} elseif ($action == 'validate_declaration' && $declaration_id > 0) {
if ($declarationtva->validateDeclaration($declaration_id)) {
setEventMessages($langs->trans("DeclarationValidated"), null, 'mesgs');
} else {
setEventMessages($langs->trans("ErrorValidatingDeclaration"), null, 'errors');
}
} elseif ($action == 'submit_declaration' && $declaration_id > 0) {
if ($declarationtva->submitDeclaration($declaration_id)) {
setEventMessages($langs->trans("DeclarationSubmitted"), null, 'mesgs');
} else {
setEventMessages($langs->trans("ErrorSubmittingDeclaration"), null, 'errors');
}
}
// Get data for display
$periods = $period->getAllPeriods();
$declarations = array();
// Get declarations for each period
foreach ($periods as $p) {
$sql = "SELECT * FROM " . MAIN_DB_PREFIX . "declarationtva_declarations
WHERE period_id = " . $p['rowid'] . " AND entity = " . $conf->entity . "
ORDER BY created_date DESC";
$result = $db->query($sql);
if ($result) {
while ($obj = $db->fetch_object($result)) {
$declarations[] = array(
'rowid' => $obj->rowid,
'declaration_number' => $obj->declaration_number,
'status' => $obj->status,
'total_vat_collected' => $obj->total_vat_collected,
'total_vat_deductible' => $obj->total_vat_deductible,
'net_vat_due' => $obj->net_vat_due,
'vat_credit' => $obj->vat_credit,
'created_date' => $obj->created_date,
'period_name' => $p['period_name']
);
}
}
}
// Page title
$title = $langs->trans("DeclarationTVAMainInterface");
llxHeader('', $title);
// Print page header
print load_fiche_titre($title, '', 'title_accountancy');
// Print periods section
print '
';
print '
';
print '
' . $langs->trans("DeclarationTVAPeriods") . '
';
if (empty($periods)) {
print '
' . $langs->trans("NoPeriodsFound") . '
';
} else {
print '
';
print '';
print '| ' . $langs->trans("PeriodName") . ' | ';
print '' . $langs->trans("StartDate") . ' | ';
print '' . $langs->trans("EndDate") . ' | ';
print '' . $langs->trans("Status") . ' | ';
print '' . $langs->trans("Actions") . ' | ';
print '
';
foreach ($periods as $p) {
print '';
print '| ' . $p['period_name'] . ' | ';
print '' . dol_print_date($p['start_date'], 'day') . ' | ';
print '' . dol_print_date($p['end_date'], 'day') . ' | ';
print '' . $langs->trans("Status" . ucfirst($p['status'])) . ' | ';
print '';
print '' . $langs->trans("CreateDeclaration") . '';
print ' | ';
print '
';
}
print '
';
}
print '
';
print '
';
// Print declarations section
print '';
print '
';
print '
' . $langs->trans("DeclarationTVADeclarations") . '
';
if (empty($declarations)) {
print '
' . $langs->trans("NoDeclarationsFound") . '
';
} else {
print '
';
print '';
print '| ' . $langs->trans("DeclarationNumber") . ' | ';
print '' . $langs->trans("Period") . ' | ';
print '' . $langs->trans("Status") . ' | ';
print '' . $langs->trans("NetVATDue") . ' | ';
print '' . $langs->trans("Actions") . ' | ';
print '
';
foreach ($declarations as $d) {
print '';
print '| ' . $d['declaration_number'] . ' | ';
print '' . $d['period_name'] . ' | ';
print '' . $langs->trans("Status" . ucfirst($d['status'])) . ' | ';
print '' . price($d['net_vat_due']) . ' | ';
print '';
if ($d['status'] == 'draft') {
print '' . $langs->trans("Validate") . '';
} elseif ($d['status'] == 'validated') {
print '' . $langs->trans("Submit") . '';
}
print '' . $langs->trans("View") . '';
print ' | ';
print '
';
}
print '
';
}
print '
';
print '
';
// Print configuration section
print '';
print '
' . $langs->trans("DeclarationTVAConfiguration") . '
';
print '
';
print '
';
// Print footer
llxFooter();
?>