changed validity of warehouseoffer

This commit is contained in:
Luca Haid
2026-01-13 07:11:56 +01:00
parent b3f03630d8
commit 48435bc33f
2 changed files with 14 additions and 4 deletions

View File

@@ -61,8 +61,10 @@ if ($includeTax) {
} }
$formattedOfferDate = date("d.m.Y", $offerDate); $formattedOfferDate = date("d.m.Y", $offerDate);
$validityDays = isset($validity) ? (int)$validity : 14; $validityDays = isset($validity) ? (int)$validity : 31;
$formattedValidUntil = date("d.m.Y", strtotime("+$validityDays days", $offerDate)); // Use versionDate (when this version was created) for validity calculation, fallback to offerDate
$validityBaseDate = isset($versionDate) ? $versionDate : $offerDate;
$formattedValidUntil = date("d.m.Y", strtotime("+$validityDays days", $validityBaseDate));
?> ?>
<!DOCTYPE html> <!DOCTYPE html>

View File

@@ -56,7 +56,7 @@ class WarehouseOfferController extends TTCrud
$this->postData['offerNumber'] = 'AN' . date('Y') . '-' . str_pad($currentCount + 1, 4, '0', STR_PAD_LEFT); $this->postData['offerNumber'] = 'AN' . date('Y') . '-' . str_pad($currentCount + 1, 4, '0', STR_PAD_LEFT);
$this->postData['status'] = 'new'; $this->postData['status'] = 'new';
$this->postData['version'] = 1; $this->postData['version'] = 1;
$this->postData['validity'] = 14; $this->postData['validity'] = 31;
$this->postData['alternativePositions'] = json_encode([]); $this->postData['alternativePositions'] = json_encode([]);
return true; return true;
} }
@@ -366,10 +366,13 @@ class WarehouseOfferController extends TTCrud
$version = $this->request->version ?? null; $version = $this->request->version ?? null;
$offerData = null; $offerData = null;
$versionDate = null; // Date when this version was created (for validity calculation)
if ($version) { if ($version) {
$historyEntry = WarehouseHistoryModel::getOneByVersion($id, $this->mod, $version); $historyEntry = WarehouseHistoryModel::getOneByVersion($id, $this->mod, $version);
if ($historyEntry && !empty($historyEntry->data)) { if ($historyEntry && !empty($historyEntry->data)) {
$offerData = json_decode($historyEntry->data); $offerData = json_decode($historyEntry->data);
$versionDate = $historyEntry->create; // Use version creation date
} }
} }
@@ -377,6 +380,10 @@ class WarehouseOfferController extends TTCrud
$offer = WarehouseOfferModel::get($id); $offer = WarehouseOfferModel::get($id);
if (!$offer || !$offer->id) self::sendError('Angebot nicht gefunden'); if (!$offer || !$offer->id) self::sendError('Angebot nicht gefunden');
$offerData = $offer; $offerData = $offer;
// Get latest history entry for current version's date
$latestHistory = WarehouseHistoryModel::getOneByVersion($id, $this->mod, $offer->version);
$versionDate = $latestHistory ? $latestHistory->create : $offer->create;
} }
@@ -432,11 +439,12 @@ class WarehouseOfferController extends TTCrud
"alternativeTotal" => $alternativeTotal, "alternativeTotal" => $alternativeTotal,
"offerNumber" => $offerData->offerNumber, "offerNumber" => $offerData->offerNumber,
"offerDate" => $offerData->create, "offerDate" => $offerData->create,
"versionDate" => $versionDate ?? $offerData->create, // Date for validity calculation
"offerEditorName" => $editor ? $editor->name : 'Unbekannt', "offerEditorName" => $editor ? $editor->name : 'Unbekannt',
"includeTax" => true, "includeTax" => true,
"vatRate" => 0.20, "vatRate" => 0.20,
"offerText" => $offerData->notes ?? '', "offerText" => $offerData->notes ?? '',
"validity" => $offerData->validity ?? 14, "validity" => $offerData->validity ?? 31,
"closingText" => $offerData->closingText ?? '', "closingText" => $offerData->closingText ?? '',
"bank_iban" => TT_INVOICE_BANK_IBAN, "bank_iban" => TT_INVOICE_BANK_IBAN,
"bank_bic" => TT_INVOICE_BANK_BIC, "bank_bic" => TT_INVOICE_BANK_BIC,