diff --git a/db/routines/vn/procedures/company_getSuppliersDebt.sql b/db/routines/vn/procedures/company_getSuppliersDebt.sql index 6b0494db7..3f91a2328 100644 --- a/db/routines/vn/procedures/company_getSuppliersDebt.sql +++ b/db/routines/vn/procedures/company_getSuppliersDebt.sql @@ -185,10 +185,12 @@ BEGIN vp.endingBalance, cr.amount clientRiskAmount FROM tPendingDuedates vp - LEFT JOIN supplier s ON s.id = vp.supplierFk + LEFT JOIN supplier s ON s.id = vp.supplierFk LEFT JOIN client c ON c.fi = s.nif - JOIN clientRisk cr ON cr.clientFk = c.id - AND cr.companyFk = vp.companyFk; + JOIN clientRisk cr ON cr.clientFk = c.id AND cr.companyFk = vp.companyFk + LEFT JOIN supplierAccount sa ON sa.supplierFk = s.id + LEFT JOIN bankEntity be ON be.id = sa.bankEntityFk + LEFT JOIN country co ON co.id = be.countryFk; DROP TEMPORARY TABLE tOpeningBalances; DROP TEMPORARY TABLE tPendingDuedates;