diff --git a/src/modules/parcel-sync/services/epay-client.ts b/src/modules/parcel-sync/services/epay-client.ts index 5eaae0e..bf40da5 100644 --- a/src/modules/parcel-sync/services/epay-client.ts +++ b/src/modules/parcel-sync/services/epay-client.ts @@ -546,10 +546,14 @@ export class EpayClient { const docPattern1 = /"idDocument"\s*:\s*(\d+)[\s\S]*?"nume"\s*:\s*"([^"]+)"[\s\S]*?"dataDocument"\s*:\s*"([^"]+)"[\s\S]*?"linkDownload"\s*:\s*"([^"]*)"/g; - // Pattern 2: DownloadFile links in HTML + // Pattern 2: DownloadFile links in HTML (regular hrefs) const docPattern2 = /DownloadFile\.action\?typeD=4&(?:amp;)?id=(\d+)/g; + // Pattern 2b: Angular ng-click="downloadFile($event, 4, ID, '')" + const docPattern2b = + /downloadFile\s*\(\s*\$event\s*,\s*4\s*,\s*(\d+)/g; + // Pattern 3: Look for solutii JSON array const solutiiMatch = html.match(/solutii['"]\s*:\s*(\[[\s\S]*?\])/); @@ -571,10 +575,19 @@ export class EpayClient { }); } - // If pattern 1 didn't find anything, try pattern 2 (DownloadFile links) + // If pattern 1 didn't find anything, try pattern 2/2b (DownloadFile links / Angular ng-click) if (documents.length === 0) { + // Combine results from both patterns + const allDocIds = new Set(); + while ((docMatch = docPattern2.exec(html)) !== null) { - const docId = parseInt(docMatch[1] ?? "0", 10); + allDocIds.add(parseInt(docMatch[1] ?? "0", 10)); + } + while ((docMatch = docPattern2b.exec(html)) !== null) { + allDocIds.add(parseInt(docMatch[1] ?? "0", 10)); + } + + for (const docId of allDocIds) { if (docId > 0 && !documents.some((d) => d.idDocument === docId)) { documents.push({ idDocument: docId,