Subversion Repositories SmartDukaan

Rev

Rev 10497 | Rev 14821 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5185 mandeep.dh 1
/**
2
 * 
3
 */
4
package in.shop2020.inventory.controllers;
5
 
5945 mandeep.dh 6
import in.shop2020.model.v1.inventory.Warehouse;
5185 mandeep.dh 7
import in.shop2020.thrift.clients.CatalogClient;
5945 mandeep.dh 8
import in.shop2020.thrift.clients.InventoryClient;
5185 mandeep.dh 9
import in.shop2020.thrift.clients.PurchaseClient;
10
import in.shop2020.thrift.clients.WarehouseClient;
11
import in.shop2020.utils.ModelUtils;
14491 manish.sha 12
import in.shop2020.warehouse.DoaOutInventoryItem;
5185 mandeep.dh 13
import in.shop2020.warehouse.InventoryItem;
10489 amar.kumar 14
import in.shop2020.warehouse.Scan;
5185 mandeep.dh 15
import in.shop2020.warehouse.ScanType;
16
import in.shop2020.warehouse.WarehouseService.Client;
17
 
9429 amar.kumar 18
import java.util.ArrayList;
10489 amar.kumar 19
import java.util.Date;
5185 mandeep.dh 20
import java.util.List;
21
 
22
import org.apache.commons.logging.Log;
23
import org.apache.commons.logging.LogFactory;
24
 
25
/**
26
 * @author mandeep
27
 *
28
 */
29
public class DoaOutController extends BaseController {
30
    private Log logger = LogFactory.getLog(DoaOutController.class);
31
    private String id;
10497 amar.kumar 32
    private String creditNote;
14491 manish.sha 33
    List<DoaOutInventoryItem> inventoryItems;
5185 mandeep.dh 34
 
35
    public String index() {
36
        try {
9452 amar.kumar 37
        	//List<InventoryItem> tobeRemovedInventoryItems = new ArrayList<InventoryItem>();
5185 mandeep.dh 38
            Client warehouseClient = new WarehouseClient().getClient();
39
            inventoryItems = warehouseClient
14491 manish.sha 40
                    .getAllDoaOutInventoryItems();
9452 amar.kumar 41
           /* for(InventoryItem inventoryItem:inventoryItems) {
9428 amar.kumar 42
            	if(inventoryItem.getId()<59078 ||  
43
            			inventoryItem.getCurrentWarehouseId() == 1 || 
9429 amar.kumar 44
            			inventoryItem.getCurrentWarehouseId() == 9) {//removing doa_in entries before 2013 and all hotspot entries
45
            		tobeRemovedInventoryItems.add(inventoryItem);
9428 amar.kumar 46
            	}
47
            }
9429 amar.kumar 48
            for(InventoryItem inventoryItem:tobeRemovedInventoryItems) {
49
            	inventoryItems.remove(inventoryItem);
9452 amar.kumar 50
            }*/
5185 mandeep.dh 51
        } catch (Exception e) {
52
            logger.error("Could not fetch inventory items", e);
53
        }
54
 
55
        return INDEX;
56
    }
57
 
58
    public String update() {
59
        try {
60
            Client warehouseClient = new WarehouseClient().getClient();
61
            InventoryItem inventoryItem = warehouseClient.getInventoryItemFromId(Long.valueOf(id));
5945 mandeep.dh 62
            in.shop2020.model.v1.inventory.InventoryService.Client catalogClient = new InventoryClient().getClient();
5185 mandeep.dh 63
            Warehouse warehouse = catalogClient.getWarehouse(inventoryItem.getCurrentWarehouseId());
9572 amar.kumar 64
            warehouseClient.scan(inventoryItem, ScanType.DOA_REPLACED, 1, warehouse.getBillingWarehouseId(), 0);
5185 mandeep.dh 65
            in.shop2020.purchase.PurchaseService.Client purchaseClient = new PurchaseClient().getClient();
66
            purchaseClient.unFulfillPO(inventoryItem.getPurchaseId(), inventoryItem.getItemId(), 1);
67
        } catch (Exception e) {
68
            logger.error("Could not fetch inventory items", e);
69
        }
70
 
71
        return index();
72
    }
10308 amar.kumar 73
 
74
    public String doaReject() {
75
        try {
76
            Client warehouseClient = new WarehouseClient().getClient();
77
            InventoryItem inventoryItem = warehouseClient.getInventoryItemFromId(Long.valueOf(id));
78
            in.shop2020.model.v1.inventory.InventoryService.Client catalogClient = new InventoryClient().getClient();
79
            Warehouse warehouse = catalogClient.getWarehouse(inventoryItem.getCurrentWarehouseId());
80
            warehouseClient.scan(inventoryItem, ScanType.DOA_REJECTED, 1, warehouse.getBillingWarehouseId(), 0);
81
        } catch (Exception e) {
82
            logger.error("Could not fetch inventory items", e);
83
        }
5235 mandeep.dh 84
 
10308 amar.kumar 85
        return index();
86
    }
10489 amar.kumar 87
 
88
    public String closeDOAByCreditNote() {
89
        try {
90
        	Client warehouseClient = new WarehouseClient().getClient();
91
            InventoryItem inventoryItem = warehouseClient.getInventoryItemFromId(Long.valueOf(id));
92
            in.shop2020.model.v1.inventory.InventoryService.Client catalogClient = new InventoryClient().getClient();
93
            Warehouse warehouse = catalogClient.getWarehouse(inventoryItem.getCurrentWarehouseId());
94
 
95
            Scan scan = new Scan();
96
            scan.setInventoryItemId(Long.parseLong(id));
97
            scan.setScannedAt((new Date()).getTime());
98
            scan.setType(ScanType.DOA_CLOSED_BY_CREDIT_NOTE);
99
            scan.setQuantity(1);
10497 amar.kumar 100
            scan.setRemarks(creditNote);
10489 amar.kumar 101
            scan.setWarehouseId(inventoryItem.getCurrentWarehouseId());
102
            warehouseClient.genericScan(inventoryItem, scan);
103
        } catch (Exception e) {
104
            logger.error("Could not fetch inventory items", e);
105
        }
10308 amar.kumar 106
 
10489 amar.kumar 107
        return index();
108
    }
109
 
5235 mandeep.dh 110
    public String getPONumber(long purchaseId) {
111
        try {
112
            in.shop2020.purchase.PurchaseService.Client purchaseClient = new PurchaseClient().getClient();
113
            return purchaseClient.getPurchaseOrderForPurchase(purchaseId).getPoNumber();
114
        } catch (Exception e) {
115
            return "N/A";
116
        }
117
    }
118
 
5185 mandeep.dh 119
    public String getWarehouseDisplayName(long warehouseId) {
120
        try {
5945 mandeep.dh 121
            in.shop2020.model.v1.inventory.InventoryService.Client catalogClient = new InventoryClient().getClient();
5185 mandeep.dh 122
            return catalogClient.getWarehouse(warehouseId).getDisplayName();
123
        } catch (Exception e) {
124
            return "N/A";
125
        }
126
    }
127
 
128
    public String getModelName(long itemId) {
129
        try {
5945 mandeep.dh 130
            in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = new CatalogClient()
5185 mandeep.dh 131
                    .getClient();
132
            return ModelUtils.extractProductNameFromItem(catalogClient
133
                    .getItem(itemId));
134
        } catch (Exception e) {
135
            return "N/A";
136
        }
137
    }
138
 
139
    public String getId() {
140
        return id;
141
    }
142
 
143
    public void setId(String id) {
144
        this.id = id;
145
    }
146
 
14491 manish.sha 147
    public List<DoaOutInventoryItem> getInventoryItems() {
5185 mandeep.dh 148
        return inventoryItems;
149
    }
150
 
14491 manish.sha 151
    public void setInventoryItems(List<DoaOutInventoryItem> inventoryItems) {
5185 mandeep.dh 152
        this.inventoryItems = inventoryItems;
153
    }
10497 amar.kumar 154
 
155
	public String getCreditNote() {
156
		return creditNote;
157
	}
158
 
159
	public void setCreditNote(String creditNote) {
160
		this.creditNote = creditNote;
161
	}
5185 mandeep.dh 162
 
163
}