Subversion Repositories SmartDukaan

Rev

Rev 36109 | Rev 36116 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 36109 Rev 36111
Line 453... Line 453...
453
            Document document = new Document();
453
            Document document = new Document();
454
            document.setMargins(0, 0, 25, 0);
454
            document.setMargins(0, 0, 25, 0);
455
            PdfWriter pdfWriter = PdfWriter.getInstance(document, outputStream);
455
            PdfWriter pdfWriter = PdfWriter.getInstance(document, outputStream);
456
            document.open();
456
            document.open();
457
 
457
 
-
 
458
            // 8 columns: S.No | Description | HSN | Qty | Gross Sale Value | Taxable Value (Margin) | Tax Rate | Tax Amount
458
            float[] marginSchemeWidths = new float[]{0.3f, 2.2f, 0.6f, 0.3f, 0.9f, 0.9f, 0.8f, 0.8f, 0.9f};
459
            float[] marginSchemeWidths = new float[]{0.3f, 2.4f, 0.6f, 0.3f, 0.9f, 0.9f, 0.9f, 0.7f};
459
 
460
 
460
            for (InvoicePdfModel pdfModel : pdfModels) {
461
            for (InvoicePdfModel pdfModel : pdfModels) {
461
                CustomCustomer customer = pdfModel.getCustomer();
462
                CustomCustomer customer = pdfModel.getCustomer();
462
                CustomRetailer retailer = pdfModel.getRetailer();
463
                CustomRetailer retailer = pdfModel.getRetailer();
463
                boolean stateGst = customer.getAddress().getState().equals(retailer.getAddress().getState());
464
                boolean stateGst = customer.getAddress().getState().equals(retailer.getAddress().getState());
Line 468... Line 469...
468
                    cancelledPages = true;
469
                    cancelledPages = true;
469
                } else {
470
                } else {
470
                    cancelledPageList.add(0);
471
                    cancelledPageList.add(0);
471
                }
472
                }
472
 
473
 
473
                document.addTitle("INVOICE OF SUPPLY (MARGIN SCHEME)");
474
                document.addTitle("TAX INVOICE");
474
                document.addAuthor(pdfModel.getAuther());
475
                document.addAuthor(pdfModel.getAuther());
475
 
476
 
476
                Paragraph paragraphTitle = new Paragraph("INVOICE OF SUPPLY (MARGIN SCHEME)", FONT_TITLE);
477
                Paragraph paragraphTitle = new Paragraph("TAX INVOICE", FONT_TITLE);
477
                paragraphTitle.setAlignment(Element.ALIGN_CENTER);
478
                paragraphTitle.setAlignment(Element.ALIGN_CENTER);
478
                document.add(paragraphTitle);
479
                document.add(paragraphTitle);
479
 
480
 
-
 
481
                Font subtitleFont = new Font(Font.FontFamily.HELVETICA, 9, Font.ITALIC);
-
 
482
                Paragraph subtitle = new Paragraph("(GST Payable on Margin Scheme Basis \u2014 ITC not admissible to buyer)", subtitleFont);
-
 
483
                subtitle.setAlignment(Element.ALIGN_CENTER);
-
 
484
                document.add(subtitle);
-
 
485
 
480
                Rectangle rectangle = document.getPageSize();
486
                Rectangle rectangle = document.getPageSize();
481
 
487
 
482
                if (pdfModel.getIrnModel() != null) {
488
                if (pdfModel.getIrnModel() != null) {
483
                    addIrnDetails(pdfModel.getIrnModel(), rectangle, document);
489
                    addIrnDetails(pdfModel.getIrnModel(), rectangle, document);
484
                }
490
                }
485
 
491
 
486
                // Customer and Retailer details
492
                // Customer and Retailer details (same as regular invoice)
487
                PdfPTable tableCustomerRetailer = new PdfPTable(2);
493
                PdfPTable tableCustomerRetailer = new PdfPTable(2);
488
                tableCustomerRetailer.setWidthPercentage(90);
494
                tableCustomerRetailer.setWidthPercentage(90);
489
                tableCustomerRetailer.getDefaultCell().setBorder(Rectangle.NO_BORDER);
495
                tableCustomerRetailer.getDefaultCell().setBorder(Rectangle.NO_BORDER);
490
 
496
 
491
                PdfPCell columnCustomerInfo = new PdfPCell();
497
                PdfPCell columnCustomerInfo = new PdfPCell();
492
                columnCustomerInfo.addElement(new Paragraph("Customer Details", FONT_BOLD));
498
                columnCustomerInfo.addElement(new Paragraph("Buyer Details", FONT_BOLD));
493
                columnCustomerInfo.addElement(new Paragraph(
499
                columnCustomerInfo.addElement(new Paragraph(
494
                        StringUtils.capitalize(customer.getAddress().getName() + (customer.getAddress().getLastName() == null ? "" : " " + customer.getAddress().getLastName())), FONT_NORMAL));
500
                        StringUtils.capitalize(customer.getAddress().getName() + (customer.getAddress().getLastName() == null ? "" : " " + customer.getAddress().getLastName())), FONT_NORMAL));
495
                if (customer.getAddress() != null) {
501
                if (customer.getAddress() != null) {
496
                    if ((customer.getAddress().getLine1() != null && !customer.getAddress().getLine1().trim().isEmpty()) || (customer.getAddress().getLine2() != null && !customer.getAddress().getLine2().trim().isEmpty())) {
502
                    if ((customer.getAddress().getLine1() != null && !customer.getAddress().getLine1().trim().isEmpty()) || (customer.getAddress().getLine2() != null && !customer.getAddress().getLine2().trim().isEmpty())) {
497
                        columnCustomerInfo.addElement(new Paragraph(StringUtils.capitalize(customer.getAddress().getLine1()) + ", " + StringUtils.capitalize(customer.getAddress().getLine2()), FONT_NORMAL));
503
                        columnCustomerInfo.addElement(new Paragraph(StringUtils.capitalize(customer.getAddress().getLine1()) + ", " + StringUtils.capitalize(customer.getAddress().getLine2()), FONT_NORMAL));
Line 505... Line 511...
505
                    columnCustomerInfo.addElement(new Paragraph("GST Number - " + customer.getGstNumber(), FONT_NORMAL));
511
                    columnCustomerInfo.addElement(new Paragraph("GST Number - " + customer.getGstNumber(), FONT_NORMAL));
506
                }
512
                }
507
                columnCustomerInfo.setBorder(Rectangle.NO_BORDER);
513
                columnCustomerInfo.setBorder(Rectangle.NO_BORDER);
508
 
514
 
509
                PdfPCell columnRetailerInfo = new PdfPCell();
515
                PdfPCell columnRetailerInfo = new PdfPCell();
-
 
516
                columnRetailerInfo.addElement(new Paragraph("Supplier Details", FONT_BOLD));
510
                columnRetailerInfo.addElement(new Paragraph(StringUtils.capitalize(retailer.getAddress().getName()), FONT_BOLD));
517
                columnRetailerInfo.addElement(new Paragraph(StringUtils.capitalize(retailer.getAddress().getName()), FONT_BOLD));
511
                columnRetailerInfo.addElement(new Paragraph(StringUtils.capitalize(retailer.getAddress().getLine1()) + ", " + StringUtils.capitalize(retailer.getAddress().getLine2()) + ", " + StringUtils.capitalize(retailer.getAddress().getCity()) + "-" + retailer.getAddress().getPinCode() + ", " + retailer.getAddress().getState() + "(" + (stateGst ? pdfModel.getCustomerAddressStateCode() : pdfModel.getPartnerAddressStateCode()) + ")", FONT_BOLD));
518
                columnRetailerInfo.addElement(new Paragraph(StringUtils.capitalize(retailer.getAddress().getLine1()) + ", " + StringUtils.capitalize(retailer.getAddress().getLine2()) + ", " + StringUtils.capitalize(retailer.getAddress().getCity()) + "-" + retailer.getAddress().getPinCode() + ", " + retailer.getAddress().getState() + "(" + (stateGst ? pdfModel.getCustomerAddressStateCode() : pdfModel.getPartnerAddressStateCode()) + ")", FONT_BOLD));
512
                columnRetailerInfo.addElement(new Paragraph("Contact No.- " + retailer.getAddress().getPhoneNumber(), FONT_BOLD));
519
                columnRetailerInfo.addElement(new Paragraph("Contact No.- " + retailer.getAddress().getPhoneNumber(), FONT_BOLD));
513
                columnRetailerInfo.addElement(new Paragraph("GST NO. " + retailer.getGstNumber(), FONT_BOLD));
520
                columnRetailerInfo.addElement(new Paragraph("GST NO. " + retailer.getGstNumber(), FONT_BOLD));
514
                columnRetailerInfo.setBorder(Rectangle.NO_BORDER);
521
                columnRetailerInfo.setBorder(Rectangle.NO_BORDER);
Line 536... Line 543...
536
                tableInvoiceDateRetailer.addCell(columnRetailerInfo);
543
                tableInvoiceDateRetailer.addCell(columnRetailerInfo);
537
 
544
 
538
                tableCustomerRetailer.addCell(columnCustomerInfo);
545
                tableCustomerRetailer.addCell(columnCustomerInfo);
539
                tableCustomerRetailer.addCell(tableInvoiceDateRetailer);
546
                tableCustomerRetailer.addCell(tableInvoiceDateRetailer);
540
 
547
 
541
                // Item table with margin scheme columns
548
                // Item table — margin scheme columns (no purchase price disclosed)
542
                PdfPTable orders = new PdfPTable(marginSchemeWidths.length);
549
                PdfPTable orders = new PdfPTable(marginSchemeWidths.length);
543
                orders.setWidths(marginSchemeWidths);
550
                orders.setWidths(marginSchemeWidths);
544
                orders.setWidthPercentage(90);
551
                orders.setWidthPercentage(90);
545
 
552
 
546
                orders.addCell(new Paragraph("S.No", FONT_BOLD));
553
                orders.addCell(new Paragraph("S.No", FONT_BOLD));
547
                orders.addCell(new Paragraph("Description", FONT_BOLD));
554
                orders.addCell(new Paragraph("Description of Goods", FONT_BOLD));
548
                orders.addCell(new Paragraph("HSN", FONT_BOLD));
555
                orders.addCell(new Paragraph("HSN\nCode", FONT_BOLD));
549
                orders.addCell(new Paragraph("Qty", FONT_BOLD));
556
                orders.addCell(new Paragraph("Qty", FONT_BOLD));
550
                orders.addCell(new Paragraph("Purchase\nPrice Rs.", FONT_BOLD));
557
                orders.addCell(new Paragraph("Gross Sale\nValue (Rs.)", FONT_BOLD));
551
                orders.addCell(new Paragraph("Selling\nPrice Rs.", FONT_BOLD));
558
                orders.addCell(new Paragraph("Taxable Value\n- Margin (Rs.)", FONT_BOLD));
552
                orders.addCell(new Paragraph("Margin\nRs.", FONT_BOLD));
559
                String taxRateHeader = stateGst ? "CGST+SGST\nRate" : "IGST\nRate";
553
                orders.addCell(new Paragraph("GST on\nMargin Rs.", FONT_BOLD));
560
                orders.addCell(new Paragraph(taxRateHeader, FONT_BOLD));
554
                orders.addCell(new Paragraph("Invoice\nTotal Rs.", FONT_BOLD));
561
                orders.addCell(new Paragraph("Tax Amount\n(Rs.)", FONT_BOLD));
555
                orders.setHeaderRows(1);
562
                orders.setHeaderRows(1);
556
 
563
 
557
                float totalSellingPrice = 0, totalMargin = 0, totalGstOnMargin = 0, totalInvoiceTotal = 0;
564
                float totalGrossSale = 0, totalMargin = 0, totalTaxAmount = 0;
558
                int index = 1;
565
                int index = 1;
559
                for (CustomOrderItem orderItem : orderItems) {
566
                for (CustomOrderItem orderItem : orderItems) {
560
                    float gstOnMargin = orderItem.getCgstAmount() + orderItem.getSgstAmount() + orderItem.getIgstAmount();
567
                    float taxAmount = orderItem.getCgstAmount() + orderItem.getSgstAmount() + orderItem.getIgstAmount();
561
 
568
 
562
                    orders.addCell(new Paragraph(String.valueOf(index++), FONT_NORMAL));
569
                    orders.addCell(new Paragraph(String.valueOf(index++), FONT_NORMAL));
563
                    orders.addCell(new Paragraph(orderItem.getDescription(), FONT_NORMAL));
570
                    orders.addCell(new Paragraph(orderItem.getDescription(), FONT_NORMAL));
564
                    orders.addCell(new Paragraph(orderItem.getHsnCode(), FONT_NORMAL));
571
                    orders.addCell(new Paragraph(orderItem.getHsnCode(), FONT_NORMAL));
565
                    orders.addCell(new Paragraph(String.valueOf(orderItem.getQuantity()), FONT_NORMAL));
572
                    orders.addCell(new Paragraph(String.valueOf(orderItem.getQuantity()), FONT_NORMAL));
566
                    orders.addCell(new Paragraph(String.format("%.2f", orderItem.getPurchasePrice()), FONT_NORMAL));
-
 
567
                    orders.addCell(new Paragraph(String.format("%.2f", orderItem.getSellingPrice()), FONT_NORMAL));
-
 
568
                    orders.addCell(new Paragraph(String.format("%.2f", orderItem.getMargin()), FONT_NORMAL));
-
 
569
                    orders.addCell(new Paragraph(String.format("%.2f", gstOnMargin), FONT_NORMAL));
-
 
570
                    orders.addCell(new Paragraph(String.format("%.2f", orderItem.getNetAmount()), FONT_NORMAL));
573
                    orders.addCell(new Paragraph(String.format("%.2f", orderItem.getNetAmount()), FONT_NORMAL));
-
 
574
                    orders.addCell(new Paragraph(String.format("%.2f", orderItem.getAmount()), FONT_NORMAL));
-
 
575
 
-
 
576
                    String taxRateText;
-
 
577
                    if (stateGst) {
-
 
578
                        taxRateText = String.format("CGST %.1f%%\n+ SGST %.1f%%", orderItem.getCgstRate(), orderItem.getSgstRate());
-
 
579
                    } else {
-
 
580
                        taxRateText = String.format("IGST %.1f%%", orderItem.getIgstRate());
-
 
581
                    }
-
 
582
                    orders.addCell(new Paragraph(taxRateText, FONT_NORMAL));
-
 
583
                    orders.addCell(new Paragraph(String.format("%.2f", taxAmount), FONT_NORMAL));
571
 
584
 
572
                    totalSellingPrice += orderItem.getSellingPrice();
585
                    totalGrossSale += orderItem.getNetAmount();
573
                    totalMargin += orderItem.getMargin();
586
                    totalMargin += orderItem.getAmount();
574
                    totalGstOnMargin += gstOnMargin;
587
                    totalTaxAmount += taxAmount;
575
                    totalInvoiceTotal += orderItem.getNetAmount();
-
 
576
                }
588
                }
577
 
589
 
578
                // Total row
590
                // Total row
579
                PdfPCell totalLabelCell = new PdfPCell(new Paragraph("TOTAL", FONT_BOLD));
591
                PdfPCell totalLabelCell = new PdfPCell(new Paragraph("Total", FONT_BOLD));
580
                totalLabelCell.setColspan(5);
592
                totalLabelCell.setColspan(4);
581
                orders.addCell(totalLabelCell);
593
                orders.addCell(totalLabelCell);
582
                orders.addCell(new Paragraph(String.format("%.2f", totalSellingPrice), FONT_BOLD));
594
                orders.addCell(new Paragraph(String.format("%.2f", totalGrossSale), FONT_BOLD));
583
                orders.addCell(new Paragraph(String.format("%.2f", totalMargin), FONT_BOLD));
595
                orders.addCell(new Paragraph(String.format("%.2f", totalMargin), FONT_BOLD));
584
                orders.addCell(new Paragraph(String.format("%.2f", totalGstOnMargin), FONT_BOLD));
596
                PdfPCell dashCell = new PdfPCell(new Paragraph("\u2014", FONT_BOLD));
-
 
597
                dashCell.setHorizontalAlignment(Element.ALIGN_CENTER);
-
 
598
                orders.addCell(dashCell);
585
                orders.addCell(new Paragraph(String.format("%.2f", totalInvoiceTotal), FONT_BOLD));
599
                orders.addCell(new Paragraph(String.format("%.2f", totalTaxAmount), FONT_BOLD));
586
 
600
 
587
                // Logo and layout
601
                // Logo and layout
588
                iconImg.setAbsolutePosition(25, rectangle.getHeight() - 100);
602
                iconImg.setAbsolutePosition(25, rectangle.getHeight() - 100);
589
                iconImg.scalePercent(30);
603
                iconImg.scalePercent(30);
590
                document.add(iconImg);
604
                document.add(iconImg);
Line 592... Line 606...
592
                document.add(Chunk.NEWLINE);
606
                document.add(Chunk.NEWLINE);
593
                document.add(tableCustomerRetailer);
607
                document.add(tableCustomerRetailer);
594
                document.add(Chunk.NEWLINE);
608
                document.add(Chunk.NEWLINE);
595
                document.add(orders);
609
                document.add(orders);
596
 
610
 
597
                // Grand total
611
                // Declaration box
-
 
612
                document.add(Chunk.NEWLINE);
598
                PdfPTable grandTotalTable = new PdfPTable(3);
613
                PdfPTable declarationTable = new PdfPTable(1);
599
                grandTotalTable.setWidths(new float[]{6.5f, .6f, .9f});
614
                declarationTable.setWidthPercentage(90);
-
 
615
                Font declarationFont = new Font(Font.FontFamily.HELVETICA, 9, Font.BOLD);
-
 
616
                PdfPCell declarationCell = new PdfPCell();
-
 
617
                declarationCell.addElement(new Paragraph("Declaration", declarationFont));
-
 
618
                Font declarationBodyFont = new Font(Font.FontFamily.TIMES_ROMAN, 9, Font.NORMAL);
-
 
619
                declarationCell.addElement(new Paragraph(
-
 
620
                        "GST is payable on margin scheme basis under Section 2(27) read with Rule 32(5) of CGST Rules, 2017. " +
-
 
621
                        "The buyer is NOT eligible to claim Input Tax Credit on this invoice.", declarationBodyFont));
-
 
622
                declarationCell.setPadding(8);
-
 
623
                declarationCell.setBackgroundColor(new BaseColor(245, 245, 245));
-
 
624
                declarationTable.addCell(declarationCell);
-
 
625
                document.add(declarationTable);
-
 
626
 
-
 
627
                // Summary table: Total Selling Price, GST on Margin, Total Invoice Value
-
 
628
                document.add(Chunk.NEWLINE);
-
 
629
                PdfPTable summaryTable = new PdfPTable(2);
600
                grandTotalTable.setWidthPercentage(90);
630
                summaryTable.setWidthPercentage(50);
-
 
631
                summaryTable.setHorizontalAlignment(Element.ALIGN_RIGHT);
-
 
632
                summaryTable.setWidths(new float[]{3f, 2f});
601
 
633
 
602
                Paragraph grandTotalParagraph = new Paragraph("Grand total", FONT_BOLD);
634
                PdfPCell slCell = new PdfPCell(new Paragraph("Total Selling Price", FONT_BOLD));
-
 
635
                slCell.setPadding(4);
-
 
636
                summaryTable.addCell(slCell);
-
 
637
                PdfPCell slValCell = new PdfPCell(new Paragraph(String.format("Rs. %.2f", totalGrossSale), FONT_NORMAL));
603
                grandTotalParagraph.setIndentationRight(20);
638
                slValCell.setPadding(4);
604
                grandTotalTable.addCell(grandTotalParagraph);
639
                summaryTable.addCell(slValCell);
-
 
640
 
605
                grandTotalTable.addCell(new Paragraph("Rs.", FONT_BOLD));
641
                PdfPCell gstCell = new PdfPCell(new Paragraph("GST on Margin", FONT_BOLD));
-
 
642
                gstCell.setPadding(4);
-
 
643
                summaryTable.addCell(gstCell);
-
 
644
                PdfPCell gstValCell = new PdfPCell(new Paragraph(String.format("Rs. %.2f", totalTaxAmount), FONT_NORMAL));
-
 
645
                gstValCell.setPadding(4);
-
 
646
                summaryTable.addCell(gstValCell);
-
 
647
 
-
 
648
                Font grandTotalFont = new Font(Font.FontFamily.HELVETICA, 11, Font.BOLD);
-
 
649
                PdfPCell gtCell = new PdfPCell(new Paragraph("Total Invoice Value", grandTotalFont));
-
 
650
                gtCell.setPadding(5);
-
 
651
                gtCell.setBackgroundColor(new BaseColor(230, 230, 230));
-
 
652
                summaryTable.addCell(gtCell);
606
                grandTotalTable.addCell(new Paragraph(String.format("%.2f", pdfModel.getTotalAmount()), FONT_BOLD));
653
                PdfPCell gtValCell = new PdfPCell(new Paragraph(String.format("Rs. %.2f", pdfModel.getTotalAmount()), grandTotalFont));
-
 
654
                gtValCell.setPadding(5);
-
 
655
                gtValCell.setBackgroundColor(new BaseColor(230, 230, 230));
-
 
656
                summaryTable.addCell(gtValCell);
-
 
657
 
607
                document.add(grandTotalTable);
658
                document.add(summaryTable);
608
 
659
 
609
                // Amount in words
660
                // Amount in words
610
                PdfPTable amountInWordsTable = new PdfPTable(3);
661
                PdfPTable amountInWordsTable = new PdfPTable(1);
611
                amountInWordsTable.setWidthPercentage(90);
662
                amountInWordsTable.setWidthPercentage(90);
612
                amountInWordsTable.setWidths(new float[]{2, 5.1f, 0.9f});
-
 
613
                amountInWordsTable.addCell(new Paragraph("Amount in Words:", FONT_BOLD));
-
 
614
                String amountInWords = toAmountInWords(pdfModel.getTotalAmount());
663
                String amountInWords = toAmountInWords(pdfModel.getTotalAmount());
615
                amountInWordsTable.addCell(new Paragraph(amountInWords, FONT_BOLD));
664
                PdfPCell wordsCell = new PdfPCell(new Paragraph(amountInWords, FONT_BOLD));
-
 
665
                wordsCell.setPadding(5);
616
                amountInWordsTable.addCell(new Paragraph("E & O.E", FONT_NORMAL));
666
                amountInWordsTable.addCell(wordsCell);
617
                document.add(amountInWordsTable);
667
                document.add(amountInWordsTable);
618
 
668
 
619
                // Payment options
669
                // Payment options
620
                if (pdfModel.getPaymentOptions() != null) {
670
                if (pdfModel.getPaymentOptions() != null) {
621
                    PdfPTable paidAmountTable = new PdfPTable(2);
671
                    PdfPTable paidAmountTable = new PdfPTable(2);
Line 668... Line 718...
668
                    body.setIndentationLeft(25);
718
                    body.setIndentationLeft(25);
669
                    body.setIndentationRight(25);
719
                    body.setIndentationRight(25);
670
                    document.add(body);
720
                    document.add(body);
671
                }
721
                }
672
 
722
 
673
                // Margin scheme declaration
-
 
674
                addMarginSchemeDeclaration(document, pdfModel);
-
 
675
 
-
 
676
                if (pdfModel.getTncs() != null) {
-
 
677
                    StringBuffer sb = new StringBuffer();
-
 
678
                    for (String tnc : pdfModel.getTncs()) {
-
 
679
                        sb.append(tnc).append("\n");
-
 
680
                    }
-
 
681
                    Paragraph warningParagraph = new Paragraph(sb.toString(), FONT_NORMAL);
-
 
682
                    warningParagraph.setIndentationLeft(40);
-
 
683
                    document.add(Chunk.NEWLINE);
-
 
684
                    document.add(warningParagraph);
-
 
685
                }
-
 
686
 
-
 
687
                document.newPage();
723
                document.newPage();
688
 
724
 
689
                // E-Way Bill support
725
                // E-Way Bill support
690
                if (pdfModel.geteWayBillPdfModel() != null) {
726
                if (pdfModel.geteWayBillPdfModel() != null) {
691
                    EWayBillPDF.generateDocument(document, pdfWriter, pdfModel.geteWayBillPdfModel());
727
                    EWayBillPDF.generateDocument(document, pdfWriter, pdfModel.geteWayBillPdfModel());