Skip to content

Commit 63330c3

Browse files
committed
Fix: validate end of month
1 parent 090d622 commit 63330c3

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

DebitExpress.VatRelief/Utils/VatTemplateReader.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,14 @@ private static Sales ParseSalesLineItem(IXLRow row, int i)
122122
var eomStr = row.Cell("A").Value.ToString();
123123
if (string.IsNullOrEmpty(eomStr)) throw new ArgumentException($"MONTH_END field is required in SALES sheet cell A{i}");
124124
var eomParsed = DateTime.TryParse(eomStr, out var eom);
125+
125126
if (!eomParsed) throw new ArgumentException($"Invalid [MONTH_END] value in SALES sheet cell A{i}");
126127

128+
var monthEnd = eom.Day;
129+
var expectedMonthEnd = DateTime.DaysInMonth(eom.Year, eom.Month);
130+
if (monthEnd != expectedMonthEnd)
131+
throw new ArgumentException($"Invalid [MONTH_END] value in SALES sheet cell A{i}");
132+
127133
var tin = row.Cell("B").Value.ToString() ?? string.Empty;
128134
if (!string.IsNullOrEmpty(tin) && !tin.IsValidTin())
129135
throw new ArgumentException($"Invalid [TIN] value in SALES sheet cell B{i}");
@@ -179,7 +185,7 @@ private static List<Purchases> GetPurchaseData(IXLWorkbook workbook, Info info)
179185
{
180186
var row = purchaseSheet.Row(i);
181187
var purchase = ParsePurchasesLineItem(row, i);
182-
188+
183189
if (purchase.Tin.Strip() == info.Tin)
184190
throw new ArgumentException($"TIN in PURCHASES sheet cell B{i} cannot be the same as the TIN of the taxpayer");
185191

@@ -197,8 +203,14 @@ private static Purchases ParsePurchasesLineItem(IXLRow row, int i)
197203
var eomStr = row.Cell("A").Value.ToString();
198204
if (string.IsNullOrEmpty(eomStr)) throw new ArgumentException($"MONTH_END field is required in PURCHASES sheet cell A{i}");
199205
var eomParsed = DateTime.TryParse(eomStr, out var eom);
206+
200207
if (!eomParsed) throw new ArgumentException($"Invalid [MONTH_END] value in PURCHASES sheet cell A{i}");
201208

209+
var monthEnd = eom.Day;
210+
var expectedMonthEnd = DateTime.DaysInMonth(eom.Year, eom.Month);
211+
if (monthEnd != expectedMonthEnd)
212+
throw new ArgumentException($"Invalid [MONTH_END] value in PURCHASES sheet cell A{i}");
213+
202214
var tin = row.Cell("B").Value.ToString() ?? string.Empty;
203215
if (!tin.IsValidTin()) throw new ArgumentException($"Invalid [TIN] value in PURCHASES sheet cell B{i}");
204216

161 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)