Subversion Repositories SmartDukaan

Rev

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

Rev 6630 Rev 7410
Line 15... Line 15...
15
import java.util.List;
15
import java.util.List;
16
import java.util.Map;
16
import java.util.Map;
17
 
17
 
18
import org.apache.commons.logging.Log;
18
import org.apache.commons.logging.Log;
19
import org.apache.commons.logging.LogFactory;
19
import org.apache.commons.logging.LogFactory;
-
 
20
import org.apache.shiro.SecurityUtils;
20
 
21
 
21
/**
22
/**
22
 * @author mandeep
23
 * @author mandeep
23
 * 
24
 * 
24
 */
25
 */
Line 29... Line 30...
29
    private String invoiceNumber;
30
    private String invoiceNumber;
30
    private String date;
31
    private String date;
31
    private String receivedFrom;
32
    private String receivedFrom;
32
    private String supplierId;
33
    private String supplierId;
33
    private String numItems;
34
    private String numItems;
-
 
35
    private Long warehouseId;
34
    private SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
36
    private SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
35
    private Map<Long, Supplier> suppliers = new HashMap<Long, Supplier>();
37
    private Map<Long, Supplier> suppliers = new HashMap<Long, Supplier>();
36
 
38
 
37
    /*
39
    /*
38
     * (non-Javadoc)
40
     * (non-Javadoc)
Line 78... Line 80...
78
        return calendar.getTime();
80
        return calendar.getTime();
79
    }
81
    }
80
 
82
 
81
    public String create() {
83
    public String create() {
82
        try {
84
        try {
-
 
85
        	if(!isAutorizedToAccessWarehouse(warehouseId)){
-
 
86
        		logger.error("Unauthorized Access for WarehouseId " + warehouseId + " by " + SecurityUtils.getSubject().getPrincipal().toString());
-
 
87
        		addActionError("Unauthorized Access for WarehouseId " + warehouseId);
-
 
88
        		return EDIT_NEW;
-
 
89
        	}
83
        	Client purchaseClient = new PurchaseClient().getClient();
90
        	Client purchaseClient = new PurchaseClient().getClient();
84
        	if(purchaseClient.getInvoice(invoiceNumber, Long.parseLong(supplierId))== null) {
91
       	if(!purchaseClient.isInvoiceReceived(invoiceNumber, Long.parseLong(supplierId))) {
85
	            Invoice invoice = new Invoice();
92
	            Invoice invoice = new Invoice();
86
	            invoice.setInvoiceNumber(invoiceNumber);
93
	            invoice.setInvoiceNumber(invoiceNumber);
87
	            invoice.setDate(sdf.parse(date).getTime());
94
	            invoice.setDate(sdf.parse(date).getTime());
88
	            invoice.setNumItems(Long.valueOf(numItems));
95
	            invoice.setNumItems(Long.valueOf(numItems));
89
	            invoice.setReceivedFrom(receivedFrom);
96
	            invoice.setReceivedFrom(receivedFrom);
90
	            invoice.setSupplierId(Long.valueOf(supplierId));
97
	            invoice.setSupplierId(Long.valueOf(supplierId));
-
 
98
	            invoice.setWarehouseId(warehouseId);
91
	            purchaseClient = new PurchaseClient().getClient();
99
	            purchaseClient = new PurchaseClient().getClient();
92
	            purchaseClient.createInvoice(invoice);
100
	            purchaseClient.createInvoice(invoice);
-
 
101
        	} else {
-
 
102
        		addActionError("Duplicate invoice " + invoiceNumber + " for supplierId " + supplierId);
-
 
103
        		return EDIT_NEW;
93
        	}
104
        	}
94
        } catch (Exception e) {
105
        } catch (Exception e) {
95
            logger.error("Could not create invoice", e);
106
            logger.error("Could not create invoice", e);
96
        }
107
        }
97
 
108
 
Line 162... Line 173...
162
    }
173
    }
163
 
174
 
164
    public void setSuppliers(Map<Long, Supplier> suppliers) {
175
    public void setSuppliers(Map<Long, Supplier> suppliers) {
165
        this.suppliers = suppliers;
176
        this.suppliers = suppliers;
166
    }
177
    }
-
 
178
 
-
 
179
	public Long getWarehouseId() {
-
 
180
		return warehouseId;
-
 
181
	}
-
 
182
 
-
 
183
	public void setWarehouseId(Long warehouseId) {
-
 
184
		this.warehouseId = warehouseId;
-
 
185
	}
167
}
186
}