feat: implement exchange rate filtering and validation enhancements in invoice processing

This commit is contained in:
AlexeerCT
2026-01-07 11:45:41 -06:00
parent 9fe07e78a6
commit 8cdcc369bb
12 changed files with 178 additions and 50 deletions

View File

@@ -26,20 +26,13 @@ export interface ExchangeRateListResponse {
*/
export async function getExchangeRateByDate(date: string, companyId: number): Promise<ExchangeRate | null> {
try {
// Get all exchange rates and filter by date on client side
const response = await api.get<ExchangeRateListResponse>(`/v1/a76/exchange-rate/?company_id=${companyId}`);
const dateOnly = date.split('T')[0]; // Ensure YYYY-MM-DD
// Filter by date on server side
const response = await api.get<ExchangeRateListResponse>(`/v1/a76/exchange-rate/?company_id=${companyId}&date=${dateOnly}`);
if (response.data && response.data.items && response.data.items.length > 0) {
// Filter by date and find USD exchange rate
const dateOnly = date.split('T')[0]; // Get YYYY-MM-DD part
const matchingRates = response.data.items.filter(rate => {
const rateDate = rate.date.split('T')[0];
const matches = rateDate === dateOnly && rate.foreign_currency === 'USD';
return matches;
});
return matchingRates.length > 0 ? matchingRates[0] : null;
// Find USD exchange rate (backend might return multiple currencies for same date if they exist)
return response.data.items[0];
}
return null;