Subversion Repositories SmartDukaan

Rev

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

Rev 4828 Rev 4830
Line 59... Line 59...
59
 
59
 
60
    private static final String REPORT_DIR = "/inventory-report";
60
    private static final String REPORT_DIR = "/inventory-report";
61
    
61
    
62
    private static final String DEFAULT_PINCODE = "110001"; 
62
    private static final String DEFAULT_PINCODE = "110001"; 
63
    private static final long REPORT_GENERATION_INTERVAL = 1;
63
    private static final long REPORT_GENERATION_INTERVAL = 1;
-
 
64
    private static final long CUT_OFF_TIME = 15;
-
 
65
    private static long NEXT_DAY_DELAY = 1;
64
 
66
 
65
    private static final int ID = 0, BRAND = 1, MODEL_NUMBER = 2, MODEL_NAME = 3, COLOR = 4, TOTAL_AVAILABILITY = 5, TOTAL_RESERVED = 6;
67
    private static final int ID = 0, BRAND = 1, MODEL_NUMBER = 2, MODEL_NAME = 3, COLOR = 4, DELIVERY_DAYS = 5, TOTAL_AVAILABILITY = 6, TOTAL_RESERVED = 7;
66
	private static final int WH1_AVAILABILITY = 7, WH1_RESERVED = 8, WH5_AVALABILITY = 9, WH5_RESERVED = 10, WH7_AVALABILITY = 11, WH7_RESERVED = 12;
68
	private static final int WH1_AVAILABILITY = 8, WH1_RESERVED = 9, WH5_AVALABILITY = 10, WH5_RESERVED = 11, WH7_AVALABILITY = 12, WH7_RESERVED = 13;
67
		
69
		
68
    private HttpSession session;
70
    private HttpSession session;
69
    private HttpServletRequest request;
71
    private HttpServletRequest request;
70
    private HttpServletResponse response;
72
    private HttpServletResponse response;
71
    private ServletContext context;
73
    private ServletContext context;
Line 83... Line 85...
83
        
85
        
84
        Calendar date = new GregorianCalendar();
86
        Calendar date = new GregorianCalendar();
85
        int year = date.get(Calendar.YEAR);
87
        int year = date.get(Calendar.YEAR);
86
        int month = date.get(Calendar.MONTH) +1;
88
        int month = date.get(Calendar.MONTH) +1;
87
        int day = date.get(Calendar.DAY_OF_MONTH);
89
        int day = date.get(Calendar.DAY_OF_MONTH);
-
 
90
        int hour = date.get(Calendar.HOUR_OF_DAY);
88
        long currentTimestamp = date.getTimeInMillis();
91
        long currentTimestamp = date.getTimeInMillis();
89
        String lastTimestampString = org.apache.commons.io.FileUtils.readFileToString(new File(REPORT_DIR + File.separator + "last.timestamp"));
92
        String lastTimestampString = org.apache.commons.io.FileUtils.readFileToString(new File(REPORT_DIR + File.separator + "last.timestamp"));
90
        lastTimestampString = lastTimestampString.replace("\"", "").replace("\n", "");
93
        lastTimestampString = lastTimestampString.replace("\"", "").replace("\n", "");
91
        long lastTimestamp = Long.parseLong(lastTimestampString);
94
        long lastTimestamp = Long.parseLong(lastTimestampString);
92
        
95
        
93
        String filename = "inventory-report." + year + "-" + month + "-" + day + "-" + lastTimestamp + ".xls";
96
        String filename = "inventory-report." + year + "-" + month + "-" + day + "-" + lastTimestamp + ".xls";
-
 
97
        if(hour >= CUT_OFF_TIME){
-
 
98
        	NEXT_DAY_DELAY = 2;
-
 
99
        }else{
-
 
100
        	NEXT_DAY_DELAY = 1;
-
 
101
        }
94
        if(currentTimestamp - lastTimestamp > REPORT_GENERATION_INTERVAL*60*60*1000){
102
        if(currentTimestamp - lastTimestamp > REPORT_GENERATION_INTERVAL*60*60*1000){
95
        	filename = "inventory-report." + year + "-" + month + "-" + day + "-" + currentTimestamp + ".xls";
103
        	filename = "inventory-report." + year + "-" + month + "-" + day + "-" + currentTimestamp + ".xls";
96
        	File inventoryReportFile = new File(REPORT_DIR + File.separator + filename);
104
        	File inventoryReportFile = new File(REPORT_DIR + File.separator + filename);
97
            ByteArrayOutputStream baosXLS = generateInventoryStockReport();
105
            ByteArrayOutputStream baosXLS = generateInventoryStockReport();
98
            if (baosXLS == null) {
106
            if (baosXLS == null) {
Line 155... Line 163...
155
                case PHASED_OUT:
163
                case PHASED_OUT:
156
                    continue;
164
                    continue;
157
                case PAUSED:
165
                case PAUSED:
158
                case PAUSED_BY_RISK:
166
                case PAUSED_BY_RISK:
159
                case ACTIVE:
167
                case ACTIVE:
160
                    RowItem rowItem = new RowItem(item);
-
 
161
                    if(state == status.ACTIVE){
-
 
162
                    	long deliveryDays = 3;
168
                    long deliveryDays = 3;
163
                    	try{
169
                	try{
164
                    		deliveryDays = logisticsClient.getLogisticsEstimation(item.getId(), DEFAULT_PINCODE, DeliveryType.PREPAID).getDeliveryTime();
170
                		deliveryDays = logisticsClient.getLogisticsEstimation(item.getId(), DEFAULT_PINCODE, DeliveryType.PREPAID).getDeliveryTime();
165
                    	}catch (LogisticsServiceException e) {
171
                	}catch (LogisticsServiceException e) {
166
                    		logger.error("Error while getting estimate of the inventory for item " + item.getId(), e);
172
                		logger.error("Error while getting estimate of the inventory for item " + item.getId(), e);
167
                    	}
173
                	}
-
 
174
                	RowItem rowItem = new RowItem(item, deliveryDays);
-
 
175
                	if(state == status.ACTIVE){
168
                        if(deliveryDays == 1)
176
                    	if(deliveryDays == NEXT_DAY_DELAY)
169
                            itemsDeliverableNextDay.add(rowItem);
177
                            itemsDeliverableNextDay.add(rowItem);
170
                        else
178
                        else
171
                            itemsNotDeliverableNextDay.add(rowItem);    
179
                            itemsNotDeliverableNextDay.add(rowItem);    
172
                    }else
180
                    }else
173
                        outOfStockItems.add(rowItem);
181
                        outOfStockItems.add(rowItem);
Line 209... Line 217...
209
        headerRow.createCell(ID).setCellValue("Item Id");
217
        headerRow.createCell(ID).setCellValue("Item Id");
210
        headerRow.createCell(BRAND).setCellValue("Brand");
218
        headerRow.createCell(BRAND).setCellValue("Brand");
211
        headerRow.createCell(MODEL_NUMBER).setCellValue("Model Number");
219
        headerRow.createCell(MODEL_NUMBER).setCellValue("Model Number");
212
        headerRow.createCell(MODEL_NAME).setCellValue("Model Name");
220
        headerRow.createCell(MODEL_NAME).setCellValue("Model Name");
213
        headerRow.createCell(COLOR).setCellValue("Color");
221
        headerRow.createCell(COLOR).setCellValue("Color");
-
 
222
        headerRow.createCell(DELIVERY_DAYS).setCellValue("Delivery Days");
214
        headerRow.createCell(TOTAL_AVAILABILITY).setCellValue("Total Availability");
223
        headerRow.createCell(TOTAL_AVAILABILITY).setCellValue("Total Availability");
215
        headerRow.createCell(TOTAL_RESERVED).setCellValue("Total Reserved");
224
        headerRow.createCell(TOTAL_RESERVED).setCellValue("Total Reserved");
216
        headerRow.createCell(WH1_AVAILABILITY).setCellValue("WH1 Availabality");
225
        headerRow.createCell(WH1_AVAILABILITY).setCellValue("901 Availabality");
217
        headerRow.createCell(WH1_RESERVED).setCellValue("WH1 Reserved");
226
        headerRow.createCell(WH1_RESERVED).setCellValue("901 Reserved");
218
        headerRow.createCell(WH5_AVALABILITY).setCellValue("WH5 Availabality");
227
        headerRow.createCell(WH5_AVALABILITY).setCellValue("9D2 Availabality");
219
        headerRow.createCell(WH5_RESERVED).setCellValue("WH5 Reserved");
228
        headerRow.createCell(WH5_RESERVED).setCellValue("9D2 Reserved");
220
        headerRow.createCell(WH7_AVALABILITY).setCellValue("WH7 Availabality");
229
        headerRow.createCell(WH7_AVALABILITY).setCellValue("MP Availabality");
221
        headerRow.createCell(WH7_RESERVED).setCellValue("WH7 Reserved");
230
        headerRow.createCell(WH7_RESERVED).setCellValue("MP Reserved");
222
 
231
 
223
        //        headerRow.createCell(WH2_A).setCellValue("WH2 Availabality");
232
        //        headerRow.createCell(WH2_A).setCellValue("WH2 Availabality");
224
        //        headerRow.createCell(WH3_A).setCellValue("WH3 Availabality");
233
        //        headerRow.createCell(WH3_A).setCellValue("WH3 Availabality");
225
        //        headerRow.createCell(WH4_A).setCellValue("WH4 Availabality");     
234
        //        headerRow.createCell(WH4_A).setCellValue("WH4 Availabality");     
226
        //        headerRow.createCell(WH2_R).setCellValue("WH2 Reserved");
235
        //        headerRow.createCell(WH2_R).setCellValue("WH2 Reserved");
Line 232... Line 241...
232
            contentRow.createCell(ID).setCellValue(item.id);
241
            contentRow.createCell(ID).setCellValue(item.id);
233
            contentRow.createCell(BRAND).setCellValue(item.brand);
242
            contentRow.createCell(BRAND).setCellValue(item.brand);
234
            contentRow.createCell(MODEL_NUMBER).setCellValue(item.modelNumber);
243
            contentRow.createCell(MODEL_NUMBER).setCellValue(item.modelNumber);
235
            contentRow.createCell(MODEL_NAME).setCellValue(item.modelName);
244
            contentRow.createCell(MODEL_NAME).setCellValue(item.modelName);
236
            contentRow.createCell(COLOR).setCellValue(item.color);
245
            contentRow.createCell(COLOR).setCellValue(item.color);
-
 
246
            contentRow.createCell(DELIVERY_DAYS).setCellValue(item.deliveryEstimate);
237
            contentRow.createCell(TOTAL_AVAILABILITY).setCellValue(item.totalAvailability);
247
            contentRow.createCell(TOTAL_AVAILABILITY).setCellValue(item.totalAvailability);
238
            contentRow.createCell(TOTAL_RESERVED).setCellValue(item.totalReserved);
248
            contentRow.createCell(TOTAL_RESERVED).setCellValue(item.totalReserved);
239
            contentRow.createCell(WH1_AVAILABILITY).setCellValue(item.wh1Availability);
249
            contentRow.createCell(WH1_AVAILABILITY).setCellValue(item.wh1Availability);
240
            contentRow.createCell(WH1_RESERVED).setCellValue(item.wh1Reserved);
250
            contentRow.createCell(WH1_RESERVED).setCellValue(item.wh1Reserved);
241
            contentRow.createCell(WH5_AVALABILITY).setCellValue(item.wh5Availability);
251
            contentRow.createCell(WH5_AVALABILITY).setCellValue(item.wh5Availability);
Line 289... Line 299...
289
        public long id;
299
        public long id;
290
        public String brand;
300
        public String brand;
291
        public String modelNumber;
301
        public String modelNumber;
292
        public String modelName;
302
        public String modelName;
293
        public String color;
303
        public String color;
-
 
304
        public long deliveryEstimate = 0;
294
        public long totalAvailability = 0;
305
        public long totalAvailability = 0;
295
        public long totalReserved = 0;
306
        public long totalReserved = 0;
296
        public long wh1Availability = 0;
307
        public long wh1Availability = 0;
297
        public long wh1Reserved = 0;
308
        public long wh1Reserved = 0;
298
        public long wh5Availability = 0;
309
        public long wh5Availability = 0;
299
        public long wh5Reserved = 0;
310
        public long wh5Reserved = 0;
300
        public long wh7Availability = 0;
311
        public long wh7Availability = 0;
301
        public long wh7Reserved = 0;
312
        public long wh7Reserved = 0;
302
        
313
        
303
        public RowItem(Item item){
314
        public RowItem(Item item, long estimate){
304
           id = item.getId();
315
           id = item.getId();
305
           brand = item.getBrand();
316
           brand = item.getBrand();
306
           modelNumber = item.getModelNumber();
317
           modelNumber = item.getModelNumber();
307
           modelName = item.getModelName();
318
           modelName = item.getModelName();
308
           color = item.getColor();
319
           color = item.getColor();
-
 
320
           deliveryEstimate = estimate;
309
           totalAvailability = 0;
321
           totalAvailability = 0;
310
           ItemInventory itemInventory = item.getItemInventory();
322
           ItemInventory itemInventory = item.getItemInventory();
311
           for(Map.Entry<Long, Long> entry : itemInventory.getAvailability().entrySet()){
323
           for(Map.Entry<Long, Long> entry : itemInventory.getAvailability().entrySet()){
312
        	   long value = entry.getValue();
324
        	   long value = entry.getValue();
313
        	   switch (entry.getKey().intValue()) {
325
        	   switch (entry.getKey().intValue()) {