Subversion Repositories SmartDukaan

Rev

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

Rev 2825 Rev 2843
Line 62... Line 62...
62
    private static Logger logger = LoggerFactory.getLogger(InvoiceServlet.class);
62
    private static Logger logger = LoggerFactory.getLogger(InvoiceServlet.class);
63
    
63
    
64
    @Override
64
    @Override
65
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
65
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
66
        long orderId = Long.parseLong(request.getParameter("id"));
66
        long orderId = Long.parseLong(request.getParameter("id"));
-
 
67
        boolean withBill = false;
-
 
68
        try {
-
 
69
            withBill = Boolean.parseBoolean(request.getParameter("withBill"));
-
 
70
        } catch(Exception e){
-
 
71
            logger.warn("Couldn't infer whether bill should be printed. Not printing the bill.", e);
-
 
72
        }
-
 
73
          
67
        logger.info("Printing invoice for order id: " + orderId);
74
        logger.info("Printing invoice for order id: " + orderId);
68
        
75
        
69
        InvoiceGenerationService invoiceGenerationService = new InvoiceGenerationService();
76
        InvoiceGenerationService invoiceGenerationService = new InvoiceGenerationService();
70
        ByteArrayOutputStream baos = invoiceGenerationService.generateInvoice(orderId);
77
        ByteArrayOutputStream baos = invoiceGenerationService.generateInvoice(orderId, withBill);
71
        response.setContentType("application/pdf");
78
        response.setContentType("application/pdf");
72
        response.setHeader("Content-disposition", "inline; filename=invoice-"+orderId+".pdf" );
79
        response.setHeader("Content-disposition", "inline; filename=invoice-"+orderId+".pdf" );
73
        
80
        
74
        ServletOutputStream sos;
81
        ServletOutputStream sos;
75
        try {
82
        try {
Line 132... Line 139...
132
        } catch (Exception e) {
139
        } catch (Exception e) {
133
            logger.error("Error while instantiating thrift clients.", e);
140
            logger.error("Error while instantiating thrift clients.", e);
134
        }
141
        }
135
    }
142
    }
136
 
143
 
137
    public ByteArrayOutputStream generateInvoice(long orderId) {
144
    public ByteArrayOutputStream generateInvoice(long orderId, boolean withBill) {
138
        ByteArrayOutputStream baosPDF = null;
145
        ByteArrayOutputStream baosPDF = null;
139
        in.shop2020.model.v1.order.TransactionService.Client tclient = tsc.getClient();
146
        in.shop2020.model.v1.order.TransactionService.Client tclient = tsc.getClient();
140
        Client iclient = csc.getClient();
147
        Client iclient = csc.getClient();
141
        in.shop2020.logistics.LogisticsService.Client logisticsClient = lsc.getClient();
148
        in.shop2020.logistics.LogisticsService.Client logisticsClient = lsc.getClient();
142
 
149
 
Line 185... Line 192...
185
            PdfPTable taxTable = getTaxCumRetailInvoiceTable(order, provider);
192
            PdfPTable taxTable = getTaxCumRetailInvoiceTable(order, provider);
186
            taxTable.setSpacingBefore(5.0f);
193
            taxTable.setSpacingBefore(5.0f);
187
            taxTable.setWidthPercentage(90.0f);
194
            taxTable.setWidthPercentage(90.0f);
188
 
195
 
189
            document.add(dispatchAdviceTable);
196
            document.add(dispatchAdviceTable);
-
 
197
            if(withBill){
190
            document.add(new DottedLineSeparator());
198
                document.add(new DottedLineSeparator());
191
            document.add(taxTable);
199
                document.add(taxTable);
-
 
200
            }
192
            document.close();
201
            document.close();
193
            baosPDF.close();
202
            baosPDF.close();
194
        } catch (Exception e) {
203
        } catch (Exception e) {
195
            logger.error("Error while generating Invoice: ", e);
204
            logger.error("Error while generating Invoice: ", e);
196
        }
205
        }
Line 602... Line 611...
602
    }
611
    }
603
    
612
    
604
    public static void main(String[] args) throws IOException {
613
    public static void main(String[] args) throws IOException {
605
        InvoiceGenerationService invoiceGenerationService = new InvoiceGenerationService();
614
        InvoiceGenerationService invoiceGenerationService = new InvoiceGenerationService();
606
        long orderId = 434;
615
        long orderId = 434;
607
        ByteArrayOutputStream baos = invoiceGenerationService.generateInvoice(orderId);
616
        ByteArrayOutputStream baos = invoiceGenerationService.generateInvoice(orderId, true);
608
        String userHome = System.getProperty("user.home");
617
        String userHome = System.getProperty("user.home");
609
        File f = new File(userHome + "/invoice-" + orderId + ".pdf");
618
        File f = new File(userHome + "/invoice-" + orderId + ".pdf");
610
        FileOutputStream fos = new FileOutputStream(f);
619
        FileOutputStream fos = new FileOutputStream(f);
611
        baos.writeTo(fos);
620
        baos.writeTo(fos);
612
        System.out.println("Invoice generated.");
621
        System.out.println("Invoice generated.");