Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
37066 amit 1
package com.spice.profitmandi.common.document;
2
 
3
import com.spice.profitmandi.common.model.CustomCustomer;
4
import com.spice.profitmandi.common.model.CustomOrderItem;
5
import com.spice.profitmandi.common.model.CustomPaymentOption;
6
import com.spice.profitmandi.common.model.CustomRetailer;
7
import com.spice.profitmandi.common.model.EWayBillPdfModel;
8
import com.spice.profitmandi.common.model.InvoicePdfModel;
9
import com.spice.profitmandi.common.model.IrnModel;
10
 
11
import java.util.List;
12
 
13
/**
14
 * Normalized view of a printable document, consumed by the rendering {@code Section}s.
15
 *
16
 * <p>All four document types (tax invoice V1/V2, delivery challan, debit note, credit note)
17
 * ultimately carry an {@link InvoicePdfModel}; debit/credit notes simply wrap one and override the
18
 * document number/date. This holder resolves those differences once — document number, date,
19
 * {@link DocumentType} and display title — and delegates everything else to the wrapped model, so
20
 * the sections never branch on which source type produced the document.
21
 */
22
public class DocumentData {
23
 
24
    public enum DocumentType {
25
        TAX_INVOICE("Invoice No:", "INVOICE DETAILS", "Total Invoice Value", "invoice"),
26
        DELIVERY_CHALLAN("Challan No:", "CHALLAN DETAILS", "Total Challan Value", "delivery challan"),
27
        DEBIT_NOTE("DN No:", "DEBIT NOTE DETAILS", "Total Debit Note Value", "debit note"),
28
        CREDIT_NOTE("CN No:", "CREDIT NOTE DETAILS", "Total Credit Note Value", "credit note");
29
 
30
        private final String numberLabel;
31
        private final String sectionLabel;
32
        private final String totalValueLabel;
33
        private final String noun;
34
 
35
        DocumentType(String numberLabel, String sectionLabel, String totalValueLabel, String noun) {
36
            this.numberLabel = numberLabel;
37
            this.sectionLabel = sectionLabel;
38
            this.totalValueLabel = totalValueLabel;
39
            this.noun = noun;
40
        }
41
 
42
        /** Label preceding the document number, e.g. "Invoice No:" / "DN No:". */
43
        public String numberLabel() { return numberLabel; }
44
        /** Right-aligned section heading, e.g. "INVOICE DETAILS". */
45
        public String sectionLabel() { return sectionLabel; }
46
        /** Grand-total row label, e.g. "Total Invoice Value". */
47
        public String totalValueLabel() { return totalValueLabel; }
48
        /** Lower-case noun for prose, e.g. "invoice" in "computer-generated invoice". */
49
        public String noun() { return noun; }
50
    }
51
 
52
    private final InvoicePdfModel model;
53
    private final DocumentType type;
54
    private final String title;
55
    private final String documentNumber;
56
    private final String documentDate;
57
    private final String originalInvoiceNumber;
58
    private final String originalInvoiceDate;
59
 
60
    public DocumentData(InvoicePdfModel model, DocumentType type, String title,
61
                        String documentNumber, String documentDate,
62
                        String originalInvoiceNumber, String originalInvoiceDate) {
63
        this.model = model;
64
        this.type = type;
65
        this.title = title;
66
        this.documentNumber = documentNumber;
67
        this.documentDate = documentDate;
68
        this.originalInvoiceNumber = originalInvoiceNumber;
69
        this.originalInvoiceDate = originalInvoiceDate;
70
    }
71
 
72
    public InvoicePdfModel model() { return model; }
73
    public DocumentType type() { return type; }
74
 
75
    /** Upper-cased display title shown in the header banner (e.g. "TAX INVOICE", "DEBIT NOTE"). */
76
    public String title() { return title; }
77
 
78
    public String documentNumber() { return documentNumber; }
79
    public String documentDate() { return documentDate; }
80
 
81
    /** Original document reference shown on a note (e.g. supplier invoice no for a warehouse debit note); null on invoices. */
82
    public String originalInvoiceNumber() { return originalInvoiceNumber; }
83
    public String originalInvoiceDate() { return originalInvoiceDate; }
84
 
85
    public boolean isNote() {
86
        return type == DocumentType.DEBIT_NOTE || type == DocumentType.CREDIT_NOTE;
87
    }
88
 
89
    public CustomCustomer customer() { return model.getCustomer(); }
90
    public CustomRetailer retailer() { return model.getRetailer(); }
91
    public List<CustomOrderItem> items() { return model.getOrderItems(); }
92
    public List<CustomPaymentOption> paymentOptions() { return model.getPaymentOptions(); }
93
    public List<String> creditTerms() { return model.getCreditTerms(); }
94
    public IrnModel irnModel() { return model.getIrnModel(); }
95
    public String irnErrorMessage() { return model.getIrnErrorMessage(); }
96
    public EWayBillPdfModel eWayBill() { return model.geteWayBillPdfModel(); }
97
    public boolean isCancelled() { return model.isCancelled(); }
98
    public boolean isMargin() { return model.isHasMarginSchemeItems(); }
99
    public String customerAddressStateCode() { return model.getCustomerAddressStateCode(); }
100
    public String partnerAddressStateCode() { return model.getPartnerAddressStateCode(); }
101
 
102
    /** Mapped purchase-order number (transaction.order only); null when unmapped — then not printed. */
103
    public String poNumber() { return model.getPoNumber(); }
104
 
105
    /** Order placed date; printed whenever present. */
106
    public String orderDate() { return model.getOrderDate(); }
107
 
108
    /** Intra-state supply iff buyer and supplier are in the same state. Mirrors the legacy rule. */
109
    public boolean intraState() {
110
        return customer().getAddress().getState().equals(retailer().getAddress().getState());
111
    }
112
 
113
    /** State code printed in the supplier block — buyer's for intra-state, partner's for inter-state. */
114
    public String stateCode() {
115
        return intraState() ? customerAddressStateCode() : partnerAddressStateCode();
116
    }
117
 
118
    /** True when any line carries an order id, which adds the "Order Id" column. */
119
    public boolean showOrderId() {
120
        if (items() == null) return false;
121
        for (CustomOrderItem item : items()) {
122
            if (item.getOrderId() != 0) return true;
123
        }
124
        return false;
125
    }
126
}