Skip to content

Commit

Permalink
fix: invoice pdf total per product calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
abuomerSD committed Jan 14, 2025
1 parent 9adbc73 commit 5c464b2
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/badrbillingsystem/reports/SalesInvoiceReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,12 @@ public String saveSalesInvoiceAsPdf(long id, SalesInvoiceHeader header, ArrayLis
double invoiceDiscount = header.getDiscount();

double oldTotalWithoutTaxAndDiscount = (invoiceTotal + tax) - invoiceDiscount;
double oldTotalWithoutTaxAndDiscount1 = (invoiceTotal - tax) + invoiceDiscount;

double taxPercentage = tax / oldTotalWithoutTaxAndDiscount;
// double taxPercentage = tax / oldTotalWithoutTaxAndDiscount;
double taxPercentage = tax / oldTotalWithoutTaxAndDiscount1;
// double taxPercentage = (tax / invoiceTotal - invoiceDiscount) ;

addPageHeader(document, id, header, details, c, pageNumber);
int productsPerPage = 17;
int rowNumber = 1;
Expand All @@ -105,13 +109,16 @@ public String saveSalesInvoiceAsPdf(long id, SalesInvoiceHeader header, ArrayLis
// PdfPTable productsDetailsInnerTable = new PdfPTable(fullPageWidth);
PdfPTable productsDetailsInnerTable = new PdfPTable(productsTableWidth);

PdfPCell pdTotalCell = getUnborderdCell(decimalFormat.format(detail.getTotal()), almarai);
pdTotalCell.setHorizontalAlignment(1);
PdfPCell pdQuantityCell = getUnborderdCell(decimalFormat.format(detail.getQuantity()), almarai);
pdQuantityCell.setHorizontalAlignment(1);
double pPrice = detail.getPrice();
double ptax = pPrice * taxPercentage;
double pPriceWithTax = ptax+ pPrice;
double pTotal = pPriceWithTax * detail.getQuantity();

PdfPCell pdTotalCell = getUnborderdCell(decimalFormat.format(pTotal), almarai);
pdTotalCell.setHorizontalAlignment(1);
PdfPCell pdQuantityCell = getUnborderdCell(decimalFormat.format(detail.getQuantity()), almarai);
pdQuantityCell.setHorizontalAlignment(1);

PdfPCell pdPriceWithTaxCell = getUnborderdCell(decimalFormat.format(pPriceWithTax), almarai);
pdPriceWithTaxCell.setHorizontalAlignment(1);
PdfPCell pdTaxCell = getUnborderdCell(decimalFormat.format(ptax), almarai);
Expand Down

0 comments on commit 5c464b2

Please sign in to comment.