Subversion Repositories SmartDukaan

Rev

Rev 36177 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 36177 Rev 36183
Line 485... Line 485...
485
        cell.setPadding(4f);
485
        cell.setPadding(4f);
486
        table.addCell(cell);
486
        table.addCell(cell);
487
    }
487
    }
488
 
488
 
489
    private static void msAddDataCell(PdfPTable table, String text, int align, boolean bold, boolean totalRow) {
489
    private static void msAddDataCell(PdfPTable table, String text, int align, boolean bold, boolean totalRow) {
-
 
490
        if (text == null) text = "";
490
        Font font = bold ? MS_BOLD : MS_NORMAL;
491
        Font font = bold ? MS_BOLD : MS_NORMAL;
491
        PdfPCell cell = new PdfPCell();
492
        PdfPCell cell = new PdfPCell();
492
        cell.setHorizontalAlignment(align);
493
        cell.setHorizontalAlignment(align);
493
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
494
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
494
        cell.setBorderColor(MS_BORDER);
495
        cell.setBorderColor(MS_BORDER);
Line 638... Line 639...
638
                        + "  |  Code: " + stateCode, MS_NORMAL));
639
                        + "  |  Code: " + stateCode, MS_NORMAL));
639
                headerTable.addCell(supplierCell);
640
                headerTable.addCell(supplierCell);
640
 
641
 
641
                boolean isChallan = titleText.contains("CHALLAN");
642
                boolean isChallan = titleText.contains("CHALLAN");
642
                boolean isCreditNote = titleText.contains("CREDIT");
643
                boolean isCreditNote = titleText.contains("CREDIT");
-
 
644
                String docName = isCreditNote ? "credit note" : (isChallan ? "delivery challan" : "invoice");
643
                String docLabel = isCreditNote ? "CN No:" : (isChallan ? "Challan No:" : "Invoice No:");
645
                String docLabel = isCreditNote ? "CN No:" : (isChallan ? "Challan No:" : "Invoice No:");
644
                String sectionLabel = isCreditNote ? "CREDIT NOTE DETAILS" : (isChallan ? "CHALLAN DETAILS" : "INVOICE DETAILS");
646
                String sectionLabel = isCreditNote ? "CREDIT NOTE DETAILS" : (isChallan ? "CHALLAN DETAILS" : "INVOICE DETAILS");
645
                PdfPCell invoiceCell = new PdfPCell();
647
                PdfPCell invoiceCell = new PdfPCell();
646
                invoiceCell.setBorder(Rectangle.NO_BORDER);
648
                invoiceCell.setBorder(Rectangle.NO_BORDER);
647
                invoiceCell.setPadding(4f);
649
                invoiceCell.setPadding(4f);
Line 693... Line 695...
693
                }
695
                }
694
                buyerTable.addCell(buyerCell);
696
                buyerTable.addCell(buyerCell);
695
                document.add(buyerTable);
697
                document.add(buyerTable);
696
 
698
 
697
                // ── Item Table ─────────────────────────────────────────────
699
                // ── Item Table ─────────────────────────────────────────────
-
 
700
                boolean showOrderId = orderItems.stream().anyMatch(oi -> oi.getOrderId() != 0);
698
                PdfPTable itemTable;
701
                PdfPTable itemTable;
-
 
702
                if (showOrderId) {
699
                // 10 columns for both margin and regular
703
                    itemTable = new PdfPTable(10);
-
 
704
                    itemTable.setWidths(new float[]{0.7f, 1.4f, 3.5f, 1.2f, 0.6f, 1.8f, 1.8f, 2.4f, 1.6f, 1.6f});
-
 
705
                } else {
700
                itemTable = new PdfPTable(10);
706
                    itemTable = new PdfPTable(9);
701
                itemTable.setWidths(new float[]{0.7f, 1.4f, 3.5f, 1.2f, 0.6f, 1.8f, 1.8f, 2.4f, 1.6f, 1.6f});
707
                    itemTable.setWidths(new float[]{0.7f, 4.9f, 1.2f, 0.6f, 1.8f, 1.8f, 2.4f, 1.6f, 1.6f});
-
 
708
                }
702
                itemTable.setWidthPercentage(100);
709
                itemTable.setWidthPercentage(100);
703
                itemTable.setSpacingAfter(0f);
710
                itemTable.setSpacingAfter(0f);
704
                itemTable.setHeaderRows(1);
711
                itemTable.setHeaderRows(1);
705
 
712
 
706
                msAddHeader(itemTable, "S.No.",      Element.ALIGN_CENTER);
713
                msAddHeader(itemTable, "S.No.",      Element.ALIGN_CENTER);
707
                msAddHeader(itemTable, "Order Id",   Element.ALIGN_CENTER);
714
                if (showOrderId) msAddHeader(itemTable, "Order Id", Element.ALIGN_CENTER);
708
                msAddHeader(itemTable, "Description of Goods", Element.ALIGN_LEFT);
715
                msAddHeader(itemTable, "Description of Goods", Element.ALIGN_LEFT);
709
                msAddHeader(itemTable, "HSN\nCode",  Element.ALIGN_CENTER);
716
                msAddHeader(itemTable, "HSN\nCode",  Element.ALIGN_CENTER);
710
                msAddHeader(itemTable, "Qty",        Element.ALIGN_CENTER);
717
                msAddHeader(itemTable, "Qty",        Element.ALIGN_CENTER);
711
 
718
 
712
                msAddHeader(itemTable, "Rate\n(Rs.)", Element.ALIGN_RIGHT);
719
                msAddHeader(itemTable, "Rate\n(Rs.)", Element.ALIGN_RIGHT);
Line 720... Line 727...
720
                int index = 1;
727
                int index = 1;
721
                for (CustomOrderItem orderItem : orderItems) {
728
                for (CustomOrderItem orderItem : orderItems) {
722
                    float taxAmount = orderItem.getCgstAmount() + orderItem.getSgstAmount() + orderItem.getIgstAmount();
729
                    float taxAmount = orderItem.getCgstAmount() + orderItem.getSgstAmount() + orderItem.getIgstAmount();
723
 
730
 
724
                    msAddDataCell(itemTable, String.valueOf(index++),                    Element.ALIGN_CENTER, false, false);
731
                    msAddDataCell(itemTable, String.valueOf(index++),                    Element.ALIGN_CENTER, false, false);
725
                    msAddDataCell(itemTable, String.valueOf(orderItem.getOrderId()),     Element.ALIGN_CENTER, false, false);
732
                    if (showOrderId) msAddDataCell(itemTable, String.valueOf(orderItem.getOrderId()), Element.ALIGN_CENTER, false, false);
726
                    msAddDataCell(itemTable, orderItem.getDescription(),                 Element.ALIGN_LEFT,   false, false);
733
                    msAddDataCell(itemTable, orderItem.getDescription(),                 Element.ALIGN_LEFT,   false, false);
727
                    msAddDataCell(itemTable, orderItem.getHsnCode(),                     Element.ALIGN_CENTER, false, false);
734
                    msAddDataCell(itemTable, orderItem.getHsnCode(),                     Element.ALIGN_CENTER, false, false);
728
                    msAddDataCell(itemTable, String.valueOf(orderItem.getQuantity()),     Element.ALIGN_CENTER, false, false);
735
                    msAddDataCell(itemTable, String.valueOf(orderItem.getQuantity()),     Element.ALIGN_CENTER, false, false);
729
 
736
 
730
                    if (isMargin) {
737
                    if (isMargin) {
Line 755... Line 762...
755
                }
762
                }
756
 
763
 
757
                // Total row
764
                // Total row
758
                int totalPcs = 0;
765
                int totalPcs = 0;
759
                for (CustomOrderItem oi : orderItems) totalPcs += oi.getQuantity();
766
                for (CustomOrderItem oi : orderItems) totalPcs += oi.getQuantity();
760
                int totalColSpan = 5;
767
                int totalColSpan = showOrderId ? 5 : 4;
761
                PdfPCell totalSpan = new PdfPCell(new Phrase("Total " + totalPcs + " pc(s)", MS_BOLD));
768
                PdfPCell totalSpan = new PdfPCell(new Phrase("Total " + totalPcs + " pc(s)", MS_BOLD));
762
                totalSpan.setColspan(totalColSpan);
769
                totalSpan.setColspan(totalColSpan);
763
                totalSpan.setHorizontalAlignment(Element.ALIGN_RIGHT);
770
                totalSpan.setHorizontalAlignment(Element.ALIGN_RIGHT);
764
                totalSpan.setBorderColor(MS_BORDER);
771
                totalSpan.setBorderColor(MS_BORDER);
765
                totalSpan.setBackgroundColor(MS_TOTAL_BG);
772
                totalSpan.setBackgroundColor(MS_TOTAL_BG);
Line 816... Line 823...
816
                    msAddSummaryRow(sumTable, "GST on Margin", "Rs. " + formatIndianCurrency(totalTaxAmount), false);
823
                    msAddSummaryRow(sumTable, "GST on Margin", "Rs. " + formatIndianCurrency(totalTaxAmount), false);
817
                } else {
824
                } else {
818
                    msAddSummaryRow(sumTable, "Total Taxable Value", "Rs. " + formatIndianCurrency(totalTaxable), false);
825
                    msAddSummaryRow(sumTable, "Total Taxable Value", "Rs. " + formatIndianCurrency(totalTaxable), false);
819
                    msAddSummaryRow(sumTable, "Total GST", "Rs. " + formatIndianCurrency(totalTaxAmount), false);
826
                    msAddSummaryRow(sumTable, "Total GST", "Rs. " + formatIndianCurrency(totalTaxAmount), false);
820
                }
827
                }
-
 
828
                String totalValueLabel = isCreditNote ? "Total Credit Note Value" : (isChallan ? "Total Challan Value" : "Total Invoice Value");
821
                msAddSummaryRow(sumTable, "Total Invoice Value", "Rs. " + formatIndianCurrency(totalInvoiceValue), true);
829
                msAddSummaryRow(sumTable, totalValueLabel, "Rs. " + formatIndianCurrency(totalInvoiceValue), true);
822
                summaryCell.addElement(sumTable);
830
                summaryCell.addElement(sumTable);
823
                bottomTable.addCell(summaryCell);
831
                bottomTable.addCell(summaryCell);
824
 
832
 
825
                // Row 2: empty (left) + Amount in words (right) — no gap
833
                // Row 2: empty (left) + Amount in words (right) — no gap
826
                PdfPCell emptyLeft = new PdfPCell(new Phrase("", MS_NORMAL));
834
                PdfPCell emptyLeft = new PdfPCell(new Phrase("", MS_NORMAL));
Line 870... Line 878...
870
                    paidTable.addCell(tpVal);
878
                    paidTable.addCell(tpVal);
871
                    document.add(paidTable);
879
                    document.add(paidTable);
872
                }
880
                }
873
 
881
 
874
                // ── Note + Credit Terms ────────────────────────────────────
882
                // ── Note + Credit Terms ────────────────────────────────────
875
                Paragraph note = new Paragraph("This is a computer-generated invoice and does not require a physical signature.", MS_SMALL);
883
                Paragraph note = new Paragraph("This is a computer-generated " + docName + " and does not require a physical signature.", MS_SMALL);
876
                note.setAlignment(Element.ALIGN_CENTER);
884
                note.setAlignment(Element.ALIGN_CENTER);
877
                note.setSpacingBefore(8f);
885
                note.setSpacingBefore(8f);
878
                note.setSpacingAfter(4f);
886
                note.setSpacingAfter(4f);
879
                document.add(note);
887
                document.add(note);
880
 
888