Skip to content

Commit a925646

Browse files
authored
Merge pull request #4 from no-comment/new-subsidiary
Add APAC Subsidiary
2 parents a09f8db + 0179107 commit a925646

File tree

4 files changed

+338
-146
lines changed

4 files changed

+338
-146
lines changed

Sources/PlutusFinancialReportSlicer/PlutusFinancialReportSlicer+CSVParser.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,6 @@ public enum ParsingError: Error {
4343
case LineNoCurrencySymbol
4444
case FailedParsingValue
4545
case CurrencyDataNotFound
46+
/// Apple changed its subsidiary structure on October 26, 2024. Sales must occur either before or after that date.
47+
case DateRangeOverlappingBreakingChangeDate
4648
}

Sources/PlutusFinancialReportSlicer/PlutusFinancialReportSlicer.swift

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ public enum PlutusFinancialReportSlicer {
9999
break
100100
}
101101
}
102+
103+
let localizationsAP = ["Pacif", "Pacíf", "Pazif"]
104+
for localization in localizationsAP {
105+
if currencyCol.lowercased().contains(localization.lowercased()) {
106+
currency = "USD - AP"
107+
break
108+
}
109+
}
102110
}
103111

104112
guard let preTaxString = line[safe: columnIndexAmountPreTax]?.replacingOccurrences(of: ",", with: ""),
@@ -190,6 +198,13 @@ public enum PlutusFinancialReportSlicer {
190198
// remember currency of current line's country
191199
currencies[countryCode] = currency
192200

201+
if let start = formatDate(startDate), start >= Date.subsidiaryChange2024 {
202+
// special case affecting countries Apple put in the "South Asia and Pacific" group: currency for those is listed as "USD"
203+
// in the sales reports but the corresponding exchange rate is keyed "USD - AP"
204+
if Subsidiary.pacificCountries.contains(countryCode) && currency == "USD" {
205+
currencies[countryCode] = "USD - AP"
206+
}
207+
}
193208
// special case affecting countries Apple put in the "Rest of World" group: currency for those is listed as "USD"
194209
// in the sales reports but the corresponding exchange rate is keyed "USD - RoW"
195210
if Subsidiary.restOfWorldCountries.contains(countryCode) && currency == "USD" {
@@ -219,7 +234,11 @@ public enum PlutusFinancialReportSlicer {
219234
let localCurrency: String = localCurrency ?? currencyData.map(\.bankAccountCurrency).reduce(into: [:], { $0[$1, default: 0] += 1 }).max(by: { $0.value < $1.value })?.key ?? "EUR"
220235
var invoices: [Invoice] = []
221236

222-
let corporations: [Subsidiary?: [SalesForCountry]] = Dictionary(grouping: sales, by: { Subsidiary(code: $0.countryCode) })
237+
guard dateRange.start >= Date.subsidiaryChange2024 || dateRange.end <= Date.subsidiaryChange2024 else {
238+
throw ParsingError.DateRangeOverlappingBreakingChangeDate
239+
}
240+
241+
let corporations: [Subsidiary?: [SalesForCountry]] = Dictionary(grouping: sales, by: { Subsidiary(code: $0.countryCode, date: dateRange.start) })
223242

224243
for (corporation, salesInCorp) in corporations {
225244
guard let corporation else { continue }

0 commit comments

Comments
 (0)