Subversion Repositories SmartDukaan

Rev

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

Rev 37066 Rev 37397
Line 5... Line 5...
5
import com.itextpdf.text.pdf.PdfCopy;
5
import com.itextpdf.text.pdf.PdfCopy;
6
import com.itextpdf.text.pdf.PdfReader;
6
import com.itextpdf.text.pdf.PdfReader;
7
import com.spice.profitmandi.common.document.DocumentData;
7
import com.spice.profitmandi.common.document.DocumentData;
8
import com.spice.profitmandi.common.document.DocumentDataAdapter;
8
import com.spice.profitmandi.common.document.DocumentDataAdapter;
9
import com.spice.profitmandi.common.document.DocumentRenderer;
9
import com.spice.profitmandi.common.document.DocumentRenderer;
10
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
-
 
11
import com.spice.profitmandi.common.model.CreditNotePdfModel;
10
import com.spice.profitmandi.common.model.CreditNotePdfModel;
12
import com.spice.profitmandi.common.model.DebitNotePdfModel;
11
import com.spice.profitmandi.common.model.DebitNotePdfModel;
13
import com.spice.profitmandi.common.model.InvoicePdfModel;
12
import com.spice.profitmandi.common.model.InvoicePdfModel;
14
 
13
 
15
import java.io.ByteArrayInputStream;
14
import java.io.ByteArrayInputStream;
Line 18... Line 17...
18
import java.io.OutputStream;
17
import java.io.OutputStream;
19
import java.util.ArrayList;
18
import java.util.ArrayList;
20
import java.util.List;
19
import java.util.List;
21
 
20
 
22
/**
21
/**
23
 * Entry points for invoice/note PDF generation. All A4 document rendering is delegated to
22
 * Entry points for invoice/note PDF generation. All document rendering is delegated to
24
 * {@link DocumentRenderer} (package {@code com.spice.profitmandi.common.document}); these methods
23
 * {@link DocumentRenderer} (package {@code com.spice.profitmandi.common.document}); these methods
25
 * are thin adapters kept for their existing callers. Thermal (58/80mm) printing still goes through
24
 * are thin adapters kept for their existing callers.
26
 * {@link InvoiceFormatter}.
-
 
27
 */
25
 */
28
public class PdfUtils {
26
public class PdfUtils {
29
 
27
 
30
    public static final String INVOICE_TITLE = "TAX INVOICE";
28
    public static final String INVOICE_TITLE = "TAX INVOICE";
31
    public static final String DEBIT_NOTE_TITLE = "DEBIT NOTE";
29
    public static final String DEBIT_NOTE_TITLE = "DEBIT NOTE";
32
    public static final String SECURITY_DEPOSIT = "SECURITY DEPOSIT RECEIPT";
30
    public static final String SECURITY_DEPOSIT = "SECURITY DEPOSIT RECEIPT";
33
 
31
 
34
    /** A4 → full document renderer; 58/80mm → thermal formatter. */
-
 
35
    public static void generateAndWrite(List<InvoicePdfModel> pdfModels, PrinterType printerType, ByteArrayOutputStream outputStream) throws ProfitMandiBusinessException {
-
 
36
        if (PrinterType.A4.equals(printerType)) {
-
 
37
            generateAndWrite(pdfModels, outputStream);
-
 
38
        } else {
-
 
39
            if (PrinterType.W80.equals(printerType)) {
-
 
40
                InvoiceFormatter.getInvoice(pdfModels.get(0), outputStream, InvoiceFormatter.WIDTH_80MM);
-
 
41
            } else if (PrinterType.W58.equals(printerType)) {
-
 
42
                InvoiceFormatter.getInvoice(pdfModels.get(0), outputStream, InvoiceFormatter.WIDTH_58MM);
-
 
43
            }
-
 
44
        }
-
 
45
    }
-
 
46
 
-
 
47
    public static void generateAndWrite(List<InvoicePdfModel> pdfModels, ByteArrayOutputStream outputStream) {
32
    public static void generateAndWrite(List<InvoicePdfModel> pdfModels, ByteArrayOutputStream outputStream) {
48
        List<DocumentData> docs = new ArrayList<>();
33
        List<DocumentData> docs = new ArrayList<>();
49
        for (InvoicePdfModel m : pdfModels) docs.add(DocumentDataAdapter.from(m));
34
        for (InvoicePdfModel m : pdfModels) docs.add(DocumentDataAdapter.from(m));
50
        new DocumentRenderer().render(docs, outputStream);
35
        new DocumentRenderer().render(docs, outputStream);
51
    }
36
    }
52
 
37
 
53
    public static void generateMarginSchemeInvoice(List<InvoicePdfModel> pdfModels, ByteArrayOutputStream outputStream) {
-
 
54
        generateInvoiceV2(pdfModels, outputStream);
-
 
55
    }
-
 
56
 
-
 
57
    public static void generateInvoiceV2(List<InvoicePdfModel> pdfModels, ByteArrayOutputStream outputStream) {
38
    public static void generateInvoiceV2(List<InvoicePdfModel> pdfModels, ByteArrayOutputStream outputStream) {
58
        List<DocumentData> docs = new ArrayList<>();
39
        List<DocumentData> docs = new ArrayList<>();
59
        for (InvoicePdfModel m : pdfModels) docs.add(DocumentDataAdapter.from(m));
40
        for (InvoicePdfModel m : pdfModels) docs.add(DocumentDataAdapter.from(m));
60
        new DocumentRenderer().render(docs, outputStream);
41
        new DocumentRenderer().render(docs, outputStream);
61
    }
42
    }