Auto commit: 2025-11-27T11:39:02.361Z
This commit is contained in:
parent
982b6cfee6
commit
893b3b9bfa
@ -1,37 +1,31 @@
|
|||||||
document.addEventListener('DOMContentLoaded', function () {
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
const overrideBtn = document.getElementById('override-btn');
|
const overrideBtns = document.querySelectorAll('.btn-override');
|
||||||
|
|
||||||
if (overrideBtn) {
|
overrideBtns.forEach(btn => {
|
||||||
overrideBtn.addEventListener('click', function () {
|
btn.addEventListener('click', function () {
|
||||||
const projectId = this.dataset.projectId;
|
const projectId = this.dataset.projectId;
|
||||||
const month = this.dataset.month;
|
const month = this.dataset.month;
|
||||||
|
|
||||||
if (this.textContent.trim() === 'Override') {
|
if (this.textContent.trim() === 'Override') {
|
||||||
this.textContent = 'Save';
|
this.textContent = 'Save';
|
||||||
this.classList.remove('btn-warning');
|
this.classList.remove('btn-outline-primary');
|
||||||
this.classList.add('btn-success');
|
this.classList.add('btn-success');
|
||||||
|
|
||||||
makeEditable('WIP', month);
|
makeEditable('WIP', month);
|
||||||
makeEditable('Opening-Balance', month);
|
makeEditable('Opening Balance', month);
|
||||||
makeEditable('Billings', month);
|
makeEditable('Billings', month);
|
||||||
makeEditable('Expenses', month);
|
makeEditable('Expenses', month);
|
||||||
makeEditable('Cost', month);
|
makeEditable('Cost', month);
|
||||||
|
|
||||||
} else if (this.textContent.trim() === 'Save') {
|
} else if (this.textContent.trim() === 'Save') {
|
||||||
const wip = document.getElementById(`wip-${month}-input`).value;
|
|
||||||
const openingBalance = document.getElementById(`opening-balance-${month}-input`).value;
|
|
||||||
const billings = document.getElementById(`billings-${month}-input`).value;
|
|
||||||
const expenses = document.getElementById(`expenses-${month}-input`).value;
|
|
||||||
const cost = document.getElementById(`cost-${month}-input`).value;
|
|
||||||
|
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('projectId', projectId);
|
formData.append('projectId', projectId);
|
||||||
formData.append('month', month);
|
formData.append('month', month + '-01');
|
||||||
formData.append('wip', wip);
|
formData.append('wip', document.getElementById(`wip-${month}-input`).value);
|
||||||
formData.append('openingBalance', openingBalance);
|
formData.append('openingBalance', document.getElementById(`opening-balance-${month}-input`).value);
|
||||||
formData.append('billings', billings);
|
formData.append('billings', document.getElementById(`billings-${month}-input`).value);
|
||||||
formData.append('expenses', expenses);
|
formData.append('expenses', document.getElementById(`expenses-${month}-input`).value);
|
||||||
formData.append('cost', cost);
|
formData.append('cost', document.getElementById(`cost-${month}-input`).value);
|
||||||
|
|
||||||
fetch('save_override.php', {
|
fetch('save_override.php', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@ -40,19 +34,26 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
this.textContent = 'Overridden';
|
// Replace button with "Overridden" badge
|
||||||
this.classList.remove('btn-success');
|
this.parentElement.innerHTML = '<span class="badge bg-success">Overridden</span>';
|
||||||
this.classList.add('btn-secondary');
|
|
||||||
this.disabled = true;
|
|
||||||
|
|
||||||
updateMetricCell('WIP', month, wip);
|
updateMetricCell('WIP', month, data.wip);
|
||||||
updateMetricCell('Opening-Balance', month, openingBalance);
|
updateMetricCell('Opening Balance', month, data.openingBalance);
|
||||||
updateMetricCell('Billings', month, billings);
|
updateMetricCell('Billings', month, data.billings);
|
||||||
updateMetricCell('Expenses', month, expenses);
|
updateMetricCell('Expenses', month, data.expenses);
|
||||||
updateMetricCell('Cost', month, cost);
|
updateMetricCell('Cost', month, data.cost);
|
||||||
updateMetricCell('NSR', month, data.nsr);
|
updateMetricCell('NSR', month, data.nsr);
|
||||||
updateMetricCell('Margin', month, data.margin);
|
updateMetricCell('Margin', month, data.margin);
|
||||||
|
|
||||||
|
// Show the next override button
|
||||||
|
const nextButtonCell = this.parentElement.nextElementSibling;
|
||||||
|
if (nextButtonCell) {
|
||||||
|
const nextButton = nextButtonCell.querySelector('.btn-override');
|
||||||
|
if (nextButton) {
|
||||||
|
nextButton.style.display = 'block';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
alert('Error saving override: ' + data.error);
|
alert('Error saving override: ' + data.error);
|
||||||
}
|
}
|
||||||
@ -63,7 +64,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
function makeEditable(metric, month) {
|
function makeEditable(metric, month) {
|
||||||
const cellId = `${metric.toLowerCase().replace(/\s/g, '-')}-${month}`;
|
const cellId = `${metric.toLowerCase().replace(/\s/g, '-')}-${month}`;
|
||||||
|
|||||||
@ -268,9 +268,6 @@ if (!$project) {
|
|||||||
foreach ($months as $month): ?>
|
foreach ($months as $month): ?>
|
||||||
<th>
|
<th>
|
||||||
<?php echo date('M Y', strtotime($month)); ?>
|
<?php echo date('M Y', strtotime($month)); ?>
|
||||||
<?php if ($is_first_month): ?>
|
|
||||||
<button id="override-btn" class="btn btn-warning btn-sm mt-1" data-project-id="<?php echo $project_id; ?>" data-month="<?php echo $month; ?>">Override</button>
|
|
||||||
<?php endif; ?>
|
|
||||||
</th>
|
</th>
|
||||||
<?php
|
<?php
|
||||||
$is_first_month = false;
|
$is_first_month = false;
|
||||||
@ -284,12 +281,11 @@ if (!$project) {
|
|||||||
<tr>
|
<tr>
|
||||||
<td class="fw-bold bg-body-tertiary"><?php echo $metric; ?></td>
|
<td class="fw-bold bg-body-tertiary"><?php echo $metric; ?></td>
|
||||||
<?php
|
<?php
|
||||||
$is_first_month_for_body = true;
|
|
||||||
foreach ($months as $month):
|
foreach ($months as $month):
|
||||||
$cell_id = '';
|
$cell_id = '';
|
||||||
$refreshable_metrics = array_merge($editable_metrics, ['NSR', 'Margin']);
|
$refreshable_metrics = array_merge($editable_metrics, ['NSR', 'Margin']);
|
||||||
if ($is_first_month_for_body && in_array($metric, $refreshable_metrics)) {
|
if (in_array($metric, $refreshable_metrics)) {
|
||||||
$cell_id = 'id="' . str_replace(' ', '-', strtolower($metric)) . '-' . $month . '"';
|
$cell_id = 'id="' . str_replace(' ', '-', strtolower($metric)) . '-' . date('Y-m', strtotime($month)) . '"';
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
<td class="text-end" <?php echo $cell_id; ?>>
|
<td class="text-end" <?php echo $cell_id; ?>>
|
||||||
@ -302,10 +298,49 @@ if (!$project) {
|
|||||||
?>
|
?>
|
||||||
</td>
|
</td>
|
||||||
<?php
|
<?php
|
||||||
$is_first_month_for_body = false;
|
|
||||||
endforeach; ?>
|
endforeach; ?>
|
||||||
</tr>
|
</tr>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
|
<tr>
|
||||||
|
<td class="fw-bold bg-body-tertiary">Actions</td>
|
||||||
|
<?php
|
||||||
|
$override_status = [];
|
||||||
|
$override_check_stmt = $pdo->prepare("SELECT month, is_overridden FROM projectFinanceMonthly WHERE projectId = :pid GROUP BY month, is_overridden");
|
||||||
|
$override_check_stmt->execute([':pid' => $project_id]);
|
||||||
|
$statuses = $override_check_stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
$monthly_override_status = [];
|
||||||
|
foreach($months as $month){
|
||||||
|
$monthly_override_status[$month] = 0;
|
||||||
|
}
|
||||||
|
foreach($statuses as $status){
|
||||||
|
if($status['is_overridden']){
|
||||||
|
$monthly_override_status[$status['month']] = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$first_unoverridden_month = null;
|
||||||
|
foreach($monthly_override_status as $month => $status){
|
||||||
|
if(!$status){
|
||||||
|
$first_unoverridden_month = $month;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($months as $month):
|
||||||
|
?>
|
||||||
|
<td class="text-center">
|
||||||
|
<?php
|
||||||
|
if ($monthly_override_status[$month]) {
|
||||||
|
echo '<span class="badge bg-success">Overridden</span>';
|
||||||
|
} else {
|
||||||
|
$display_style = ($month === $first_unoverridden_month) ? '' : 'style="display: none;"';
|
||||||
|
echo '<button class="btn btn-sm btn-outline-primary btn-override" data-month="' . date('Y-m', strtotime($month)) . '" id="override-btn-' . $month . '" ' . $display_style . ' data-project-id="' . $project_id . '">Override</button>';
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</td>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -73,7 +73,16 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
':value' => $margin
|
':value' => $margin
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$response = ['success' => true, 'nsr' => $nsr, 'margin' => $margin];
|
$response = [
|
||||||
|
'success' => true,
|
||||||
|
'wip' => $wip,
|
||||||
|
'openingBalance' => $opening_balance,
|
||||||
|
'billings' => $billings,
|
||||||
|
'expenses' => $expenses,
|
||||||
|
'cost' => $cost,
|
||||||
|
'nsr' => $nsr,
|
||||||
|
'margin' => $margin
|
||||||
|
];
|
||||||
|
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
$response['error'] = 'Database error: ' . $e->getMessage();
|
$response['error'] = 'Database error: ' . $e->getMessage();
|
||||||
@ -85,3 +94,4 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
echo json_encode($response);
|
echo json_encode($response);
|
||||||
|
exit;
|
||||||
Loading…
x
Reference in New Issue
Block a user