Subversion Repositories SmartDukaan

Rev

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

Rev 5387 Rev 5527
Line 1... Line 1...
1
package in.shop2020.hotspot.dashbaord.server;
1
package in.shop2020.hotspot.dashbaord.server;
2
 
2
 
3
import in.shop2020.config.ConfigException;
3
import in.shop2020.config.ConfigException;
4
import in.shop2020.logistics.DeliveryType;
4
import in.shop2020.logistics.DeliveryType;
5
import in.shop2020.logistics.LogisticsServiceException;
5
import in.shop2020.logistics.LogisticsServiceException;
-
 
6
import in.shop2020.logistics.PickUpType;
6
import in.shop2020.logistics.Provider;
7
import in.shop2020.logistics.Provider;
7
import in.shop2020.model.v1.catalog.InventoryServiceException;
8
import in.shop2020.model.v1.catalog.InventoryServiceException;
8
import in.shop2020.model.v1.catalog.Warehouse;
9
import in.shop2020.model.v1.catalog.Warehouse;
9
import in.shop2020.model.v1.catalog.InventoryService.Client;
10
import in.shop2020.model.v1.catalog.InventoryService.Client;
-
 
11
import in.shop2020.model.v1.order.Attribute;
10
import in.shop2020.model.v1.order.LineItem;
12
import in.shop2020.model.v1.order.LineItem;
11
import in.shop2020.model.v1.order.Order;
13
import in.shop2020.model.v1.order.Order;
12
import in.shop2020.model.v1.order.OrderStatus;
14
import in.shop2020.model.v1.order.OrderStatus;
-
 
15
import in.shop2020.model.v1.order.OrderType;
13
import in.shop2020.thrift.clients.CatalogClient;
16
import in.shop2020.thrift.clients.CatalogClient;
14
import in.shop2020.thrift.clients.LogisticsClient;
17
import in.shop2020.thrift.clients.LogisticsClient;
15
import in.shop2020.thrift.clients.TransactionClient;
18
import in.shop2020.thrift.clients.TransactionClient;
16
import in.shop2020.thrift.clients.config.ConfigClient;
19
import in.shop2020.thrift.clients.config.ConfigClient;
17
 
20
 
Line 191... Line 194...
191
            	int barcodeFontSize = 0;
194
            	int barcodeFontSize = 0;
192
            	try {
195
            	try {
193
            		warehouse = iclient.getWarehouse(order.getWarehouse_id());
196
            		warehouse = iclient.getWarehouse(order.getWarehouse_id());
194
            		long providerId = order.getLogistics_provider_id();
197
            		long providerId = order.getLogistics_provider_id();
195
            		provider = logisticsClient.getProvider(providerId);
198
            		provider = logisticsClient.getProvider(providerId);
196
            		if(providerId == SELF_PICKUP)
199
            		if(provider.getPickup().equals(PickUpType.SELF) || provider.getPickup().equals(PickUpType.RUNNER))
197
            			destCode = "SELF";
200
            			destCode = provider.getPickup().toString();
198
            		else
201
            		else
199
            			destCode = logisticsClient.getDestinationCode(providerId, order.getCustomer_pincode());
202
            			destCode = logisticsClient.getDestinationCode(providerId, order.getCustomer_pincode());
200
 
203
 
201
            		barcodeFontSize = Integer.parseInt(ConfigClient.getClient().get(provider.getName().toLowerCase() + "_barcode_fontsize"));
204
            		barcodeFontSize = Integer.parseInt(ConfigClient.getClient().get(provider.getName().toLowerCase() + "_barcode_fontsize"));
202
            	} catch (InventoryServiceException ise) {
205
            	} catch (InventoryServiceException ise) {
Line 425... Line 428...
425
        return addressCell;
428
        return addressCell;
426
    }
429
    }
427
    
430
    
428
    private PdfPTable getTaxCumRetailInvoiceTable(Order order, Provider provider){
431
    private PdfPTable getTaxCumRetailInvoiceTable(Order order, Provider provider){
429
        PdfPTable taxTable = new PdfPTable(1);
432
        PdfPTable taxTable = new PdfPTable(1);
-
 
433
        Phrase phrase = null;
430
        taxTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
434
        taxTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
431
        taxTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
435
        taxTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
432
        
436
        
-
 
437
        if (order.getOrderType().equals(OrderType.B2B)) {
-
 
438
            phrase = new Phrase("TAX INVOICE", helveticaBold12);
-
 
439
        } else {
-
 
440
            phrase = new Phrase("RETAIL INVOICE", helveticaBold12);
-
 
441
        }
433
        PdfPCell retailInvoiceTitleCell = new PdfPCell(new Phrase("TAX CUM RETAIL INVOICE", helveticaBold12));
442
        PdfPCell retailInvoiceTitleCell = new PdfPCell(phrase);
434
        retailInvoiceTitleCell.setHorizontalAlignment(Element.ALIGN_CENTER);
443
        retailInvoiceTitleCell.setHorizontalAlignment(Element.ALIGN_CENTER);
435
        retailInvoiceTitleCell.setBorder(Rectangle.NO_BORDER);
444
        retailInvoiceTitleCell.setBorder(Rectangle.NO_BORDER);
436
        
445
        
437
        Paragraph sorlAddress = new Paragraph(ourAddress + "TIN NO. " + tinNo, new Font(FontFamily.TIMES_ROMAN, 8f, Element.ALIGN_CENTER));
446
        Paragraph sorlAddress = new Paragraph(ourAddress + "TIN NO. " + tinNo, new Font(FontFamily.TIMES_ROMAN, 8f, Element.ALIGN_CENTER));
438
        PdfPCell sorlAddressCell = new PdfPCell(sorlAddress);
447
        PdfPCell sorlAddressCell = new PdfPCell(sorlAddress);
Line 449... Line 458...
449
        addrAndOrderDetailsTable.addCell(orderDetails);
458
        addrAndOrderDetailsTable.addCell(orderDetails);
450
        
459
        
451
        boolean isVAT = order.getCustomer_pincode().startsWith(delhiPincodePrefix);
460
        boolean isVAT = order.getCustomer_pincode().startsWith(delhiPincodePrefix);
452
        PdfPTable invoiceTable = getBottomInvoiceTable(order, isVAT);
461
        PdfPTable invoiceTable = getBottomInvoiceTable(order, isVAT);
453
        
462
        
454
        PdfPCell disclaimerCell = new PdfPCell(new Phrase("Goods once sold will not be taken back.\nAll disputes subject to Delhi Jurisdiction.", helvetica8));
463
        PdfPCell disclaimerCell = new PdfPCell(new Phrase("Goods once sold will not be taken back.\nAll disputes subject to Delhi Jurisdiction.\nThis is a Computer generated Invoice.", helvetica8));
455
        disclaimerCell.setHorizontalAlignment(Element.ALIGN_LEFT);
464
        disclaimerCell.setHorizontalAlignment(Element.ALIGN_LEFT);
456
        disclaimerCell.setBorder(Rectangle.NO_BORDER);
465
        disclaimerCell.setBorder(Rectangle.NO_BORDER);
457
                
466
                
458
        taxTable.addCell(retailInvoiceTitleCell);
467
        taxTable.addCell(retailInvoiceTitleCell);
459
        taxTable.addCell(sorlAddress);
468
        taxTable.addCell(sorlAddress);
Line 474... Line 483...
474
        if(destCode != null)
483
        if(destCode != null)
475
            customerTable.addCell(new Phrase(order.getCustomer_pincode() + " - " + destCode, helvetica16));
484
            customerTable.addCell(new Phrase(order.getCustomer_pincode() + " - " + destCode, helvetica16));
476
        else
485
        else
477
            customerTable.addCell(new Phrase(order.getCustomer_pincode(), font));
486
            customerTable.addCell(new Phrase(order.getCustomer_pincode(), font));
478
        customerTable.addCell(new Phrase("Phone :" + order.getCustomer_mobilenumber(), font));
487
        customerTable.addCell(new Phrase("Phone :" + order.getCustomer_mobilenumber(), font));
-
 
488
        if(order.getOrderType().equals(OrderType.B2B)) {
-
 
489
            String tin = null;
-
 
490
            in.shop2020.model.v1.order.TransactionService.Client tclient = tsc.getClient();
-
 
491
            List<Attribute> attributes;
-
 
492
            try {
-
 
493
                attributes = tclient.getAllAttributesForOrderId(order.getId());
-
 
494
 
-
 
495
                for(Attribute attribute : attributes) {
-
 
496
                    if(attribute.getName().equals("tinNumber")) {
-
 
497
                        tin = attribute.getValue();
-
 
498
                    }
-
 
499
                }
-
 
500
                if (tin != null) {
-
 
501
                    customerTable.addCell(new Phrase("TIN :" + tin, font));
-
 
502
                }
-
 
503
                
-
 
504
            } catch (Exception e) {
-
 
505
                logger.error("Error while getting order attributes", e);
-
 
506
            }
-
 
507
        }
479
        if(showPaymentMode){
508
        if(showPaymentMode){
480
            customerTable.addCell(new Phrase(" ", font));
509
            customerTable.addCell(new Phrase(" ", font));
481
            customerTable.addCell(new Phrase("Payment Mode: Prepaid", font));
510
            customerTable.addCell(new Phrase("Payment Mode: Prepaid", font));
482
        }
511
        }
483
        return customerTable;
512
        return customerTable;
Line 716... Line 745...
716
        extraInfoTable.addCell(extraInfoCell);
745
        extraInfoTable.addCell(extraInfoCell);
717
        
746
        
718
        
747
        
719
        return extraInfoTable;
748
        return extraInfoTable;
720
    }
749
    }
-
 
750
    
721
    public static void main(String[] args) throws IOException {
751
    public static void main(String[] args) throws IOException {
722
        InvoiceGenerationService invoiceGenerationService = new InvoiceGenerationService();
752
        InvoiceGenerationService invoiceGenerationService = new InvoiceGenerationService();
723
        long orderId = 542;
753
        long orderId = 148574;
724
        ByteArrayOutputStream baos = invoiceGenerationService.generateInvoice(orderId, false, false, 1);
754
        ByteArrayOutputStream baos = invoiceGenerationService.generateInvoice(orderId, false, false, 1);
725
        String userHome = System.getProperty("user.home");
755
        String userHome = System.getProperty("user.home");
726
        File f = new File(userHome + "/invoice-" + orderId + ".pdf");
756
        File f = new File(userHome + "/invoice-" + orderId + ".pdf");
727
        FileOutputStream fos = new FileOutputStream(f);
757
        FileOutputStream fos = new FileOutputStream(f);
728
        baos.writeTo(fos);
758
        baos.writeTo(fos);