Subversion Repositories SmartDukaan

Rev

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

Rev 5554 Rev 5678
Line 28... Line 28...
28
import com.itextpdf.text.pdf.PdfPCell;
28
import com.itextpdf.text.pdf.PdfPCell;
29
import com.itextpdf.text.pdf.PdfPTable;
29
import com.itextpdf.text.pdf.PdfPTable;
30
import com.itextpdf.text.pdf.PdfWriter;
30
import com.itextpdf.text.pdf.PdfWriter;
31
 
31
 
32
import in.shop2020.logistics.LogisticsServiceException;
32
import in.shop2020.logistics.LogisticsServiceException;
-
 
33
import in.shop2020.logistics.PickupStore;
33
import in.shop2020.logistics.Provider;
34
import in.shop2020.logistics.Provider;
34
import in.shop2020.model.v1.catalog.InventoryServiceException;
35
import in.shop2020.model.v1.catalog.InventoryServiceException;
35
import in.shop2020.model.v1.catalog.Warehouse;
36
import in.shop2020.model.v1.catalog.Warehouse;
36
import in.shop2020.model.v1.order.LineItem;
37
import in.shop2020.model.v1.order.LineItem;
37
import in.shop2020.model.v1.order.Order;
38
import in.shop2020.model.v1.order.Order;
Line 170... Line 171...
170
			logger.error("Error while creating the manifest file", e);
171
			logger.error("Error while creating the manifest file", e);
171
		}
172
		}
172
 
173
 
173
		return baosPDF;
174
		return baosPDF;
174
	}
175
	}
-
 
176
 
175
	
177
	
-
 
178
	public ByteArrayOutputStream generateManifestFile(long providerId, long storeId, List<Long> orderIds) {
-
 
179
		ByteArrayOutputStream baosPDF = null;
-
 
180
		in.shop2020.model.v1.order.TransactionService.Client txnClient = tsc.getClient();
-
 
181
		in.shop2020.logistics.LogisticsService.Client logisticsClient = lsc.getClient();
-
 
182
		
-
 
183
		List<OrderStatus> statuses = new ArrayList<OrderStatus>();
-
 
184
		statuses.add(OrderStatus.RET_PICKUP_REQUEST_RAISED);
-
 
185
		
-
 
186
		List<Order> orders = null;
-
 
187
		PickupStore store = null;
-
 
188
		Provider provider = null;
-
 
189
		try {
-
 
190
			orders = txnClient.getOrdersInBatch(statuses, 0, 0, 0);
-
 
191
			store = logisticsClient.getPickupStore(storeId);
-
 
192
			provider = logisticsClient.getProvider(providerId);
-
 
193
		} catch (TException e) {
-
 
194
		    logger.error("Error getting information from one of the Thrift Services: ", e);
-
 
195
			return baosPDF;
-
 
196
		} catch (LogisticsServiceException e) {
-
 
197
		    logger.error("Error getting provider info from the logistics service: ", e);
-
 
198
			return baosPDF;
-
 
199
		} catch (TransactionServiceException e) {
-
 
200
		    logger.error("Error getting orders from the transaction service: ", e);
-
 
201
			return baosPDF;
-
 
202
		}
-
 
203
		
-
 
204
		try {
-
 
205
			baosPDF = new ByteArrayOutputStream();
-
 
206
			Font helvetica8 = FontFactory.getFont(FontFactory.HELVETICA, 8);
-
 
207
			Document document = new Document();
-
 
208
			PdfWriter.getInstance(document, baosPDF);
-
 
209
			document.addAuthor("shop2020");
-
 
210
			document.addTitle("Manifest for store " + storeId + " provider " + providerId);
-
 
211
			document.open();
-
 
212
			PdfPTable table = new PdfPTable(1);
-
 
213
			table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
-
 
214
			table.getDefaultCell().setPaddingBottom(10.0f);
-
 
215
			
-
 
216
			String addressString =  store.getName() + "\nPIN " + store.getPin()+ "\n\n";
-
 
217
			Paragraph addressParagraph = new Paragraph(addressString, new Font(FontFamily.TIMES_ROMAN,8f));
-
 
218
			PdfPCell addressCell = new PdfPCell();
-
 
219
			addressCell.addElement(addressParagraph);
-
 
220
			addressCell.setHorizontalAlignment(Element.ALIGN_LEFT);
-
 
221
			addressCell.setBorder(Rectangle.NO_BORDER);
-
 
222
			
-
 
223
			PdfPTable ordersTable = new PdfPTable(4);
-
 
224
			ordersTable.addCell(new Phrase("Sl No", helvetica8));
-
 
225
			ordersTable.addCell(new Phrase("Order No", helvetica8));
-
 
226
			ordersTable.addCell(new Phrase("AWB No", helvetica8));
-
 
227
			ordersTable.addCell(new Phrase("Packet Wt.", helvetica8));
-
 
228
			
-
 
229
			int serialNo = 0;
-
 
230
			for(int i=0; i < orders.size();i++){
-
 
231
				Order order = orders.get(i);
-
 
232
				if(!orderIds.contains(order.getId()))
-
 
233
					continue;
-
 
234
				if(order.getLogistics_provider_id()!=providerId)
-
 
235
					continue;
-
 
236
				if(order.getPickupStoreId()!=storeId)
-
 
237
					continue;
-
 
238
				//TODO: These are exactly the orders which will be shipped now. Shouldn't we change their status to be SHIPPED?
-
 
239
				serialNo++;
-
 
240
				List<LineItem> lineItems = order.getLineitems();
-
 
241
				double weight = 0;
-
 
242
				for(LineItem lineItem: lineItems)
-
 
243
					weight += lineItem.getTotal_weight();
-
 
244
				
-
 
245
				ordersTable.addCell(new Phrase(serialNo + "", helvetica8));
-
 
246
				ordersTable.addCell(new Phrase(order.getId() + "", helvetica8));
-
 
247
				ordersTable.addCell(new Phrase(order.getAirwaybill_no(), helvetica8));
-
 
248
				ordersTable.addCell(new Phrase(weightFormat.format(weight), helvetica8));
-
 
249
			}
-
 
250
			
-
 
251
			table.addCell(addressCell);
-
 
252
			table.addCell(new Phrase("Courier Name: " + provider.getName(), helvetica8));
-
 
253
			table.addCell(new Phrase("Pick up Date: " + DateFormat.getDateInstance(DateFormat.MEDIUM).format(new Date()), helvetica8));
-
 
254
			table.addCell(ordersTable);
-
 
255
			table.setWidthPercentage(90.0f);
-
 
256
			
-
 
257
			document.add(table);  
-
 
258
			document.close();
-
 
259
			baosPDF.close();
-
 
260
		} catch (DocumentException e) {
-
 
261
		    logger.error("Error while creating the manifest file", e);
-
 
262
		} catch (MalformedURLException e) {
-
 
263
		    logger.error("Error while creating the manifest file", e);
-
 
264
		} catch (IOException e) {
-
 
265
			logger.error("Error while creating the manifest file", e);
-
 
266
		}
-
 
267
 
-
 
268
		return baosPDF;
-
 
269
	}
-
 
270
 
176
	public static void main(String[] args) throws IOException {
271
	public static void main(String[] args) throws IOException {
177
		ManifestGenerator manifestGenerator = new ManifestGenerator();
272
		ManifestGenerator manifestGenerator = new ManifestGenerator();
178
		ByteArrayOutputStream baos = manifestGenerator.generateManifestFile(1, 1, true, null);
273
		ByteArrayOutputStream baos = manifestGenerator.generateManifestFile(1, 1, true, null);
179
		File f = new File("/home/ashish/Downloads/manifest-1-2.pdf");
274
		File f = new File("/home/ashish/Downloads/manifest-1-2.pdf");
180
		FileOutputStream fos = new FileOutputStream(f);
275
		FileOutputStream fos = new FileOutputStream(f);