Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
27391 tejbeer 1
package com.spice.profitmandi.web.controller;
2
 
29900 amit.gupta 3
import java.awt.image.BufferedImage;
27876 amit.gupta 4
import java.io.ByteArrayInputStream;
29900 amit.gupta 5
import java.io.File;
6
import java.io.FileNotFoundException;
27876 amit.gupta 7
import java.io.InputStream;
29900 amit.gupta 8
import java.time.Instant;
27876 amit.gupta 9
import java.time.LocalDate;
27391 tejbeer 10
import java.time.LocalDateTime;
27876 amit.gupta 11
import java.time.YearMonth;
27391 tejbeer 12
import java.util.ArrayList;
27876 amit.gupta 13
import java.util.Arrays;
14
import java.util.Collection;
15
import java.util.Comparator;
29900 amit.gupta 16
import java.util.HashMap;
27391 tejbeer 17
import java.util.List;
18
import java.util.Map;
19
import java.util.Set;
20
import java.util.stream.Collectors;
21
 
29900 amit.gupta 22
import javax.imageio.ImageIO;
27391 tejbeer 23
import javax.servlet.http.HttpServletRequest;
24
import javax.transaction.Transactional;
25
 
29900 amit.gupta 26
import org.apache.commons.io.FileUtils;
27876 amit.gupta 27
import org.apache.commons.io.output.ByteArrayOutputStream;
27391 tejbeer 28
import org.apache.logging.log4j.LogManager;
29
import org.apache.logging.log4j.Logger;
29900 amit.gupta 30
import org.apache.velocity.app.VelocityEngine;
27391 tejbeer 31
import org.springframework.beans.factory.annotation.Autowired;
29809 amit.gupta 32
import org.springframework.cache.CacheManager;
27876 amit.gupta 33
import org.springframework.core.io.InputStreamResource;
34
import org.springframework.http.HttpHeaders;
35
import org.springframework.http.HttpStatus;
36
import org.springframework.http.ResponseEntity;
27391 tejbeer 37
import org.springframework.stereotype.Controller;
38
import org.springframework.ui.Model;
29900 amit.gupta 39
import org.springframework.ui.velocity.VelocityEngineUtils;
27876 amit.gupta 40
import org.springframework.web.bind.annotation.PathVariable;
29682 amit.gupta 41
import org.springframework.web.bind.annotation.PostMapping;
27391 tejbeer 42
import org.springframework.web.bind.annotation.RequestBody;
43
import org.springframework.web.bind.annotation.RequestMapping;
44
import org.springframework.web.bind.annotation.RequestMethod;
45
import org.springframework.web.bind.annotation.RequestParam;
29682 amit.gupta 46
import org.springframework.web.bind.annotation.RequestPart;
47
import org.springframework.web.multipart.MultipartFile;
29900 amit.gupta 48
import org.xhtmlrenderer.simple.Graphics2DRenderer;
27391 tejbeer 49
 
50
import com.google.gson.Gson;
29900 amit.gupta 51
import com.jcraft.jsch.ChannelSftp;
52
import com.jcraft.jsch.JSch;
53
import com.jcraft.jsch.JSchException;
54
import com.jcraft.jsch.Session;
55
import com.jcraft.jsch.SftpATTRS;
56
import com.jcraft.jsch.SftpException;
57
import com.spice.profitmandi.common.enumuration.MessageType;
27391 tejbeer 58
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
59
import com.spice.profitmandi.common.model.CustomRetailer;
27876 amit.gupta 60
import com.spice.profitmandi.common.model.ProfitMandiConstants;
29900 amit.gupta 61
import com.spice.profitmandi.common.model.SendNotificationModel;
27876 amit.gupta 62
import com.spice.profitmandi.common.util.FileUtil;
29904 amit.gupta 63
import com.spice.profitmandi.common.util.FormattingUtils;
27876 amit.gupta 64
import com.spice.profitmandi.common.web.util.ResponseSender;
27391 tejbeer 65
import com.spice.profitmandi.dao.entity.catalog.Offer;
66
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
67
import com.spice.profitmandi.dao.enumuration.catalog.ItemCriteriaType;
68
import com.spice.profitmandi.dao.model.CreateOfferRequest;
27876 amit.gupta 69
import com.spice.profitmandi.dao.model.OfferRowModel;
27391 tejbeer 70
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
71
import com.spice.profitmandi.dao.repository.catalog.OfferMarginRepository;
72
import com.spice.profitmandi.dao.repository.catalog.OfferPartnerRepository;
73
import com.spice.profitmandi.dao.repository.catalog.OfferRepository;
74
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
75
import com.spice.profitmandi.dao.repository.dtr.Mongo;
76
import com.spice.profitmandi.dao.repository.fofo.PartnerTypeChangeService;
29900 amit.gupta 77
import com.spice.profitmandi.service.NotificationService;
29785 amit.gupta 78
import com.spice.profitmandi.service.authentication.RoleManager;
27876 amit.gupta 79
import com.spice.profitmandi.service.offers.OfferService;
27391 tejbeer 80
import com.spice.profitmandi.service.user.RetailerService;
81
import com.spice.profitmandi.web.model.LoginDetails;
82
import com.spice.profitmandi.web.util.CookiesProcessor;
83
import com.spice.profitmandi.web.util.MVCResponseSender;
84
 
85
@Controller
86
@Transactional(rollbackOn = Throwable.class)
87
public class OfferController {
88
	private static final Logger LOGGER = LogManager.getLogger(OfferController.class);
89
	@Autowired
90
	private OfferRepository offerRepository;
91
 
92
	@Autowired
93
	private OfferMarginRepository offerMarginRepository;
94
 
95
	@Autowired
96
	private FofoStoreRepository fofoStoreRepository;
97
 
98
	@Autowired
27876 amit.gupta 99
	private ResponseSender responseSender;
100
 
101
	@Autowired
27391 tejbeer 102
	private OfferPartnerRepository offerPartnerRepository;
103
 
29900 amit.gupta 104
	private static final String IMAGE_REMOTE_DIR = "/var/www/dtrdashboard/uploads/campaigns/";
105
	private static final String IMAGE_STATIC_SERVER_URL = "https://images.smartdukaan.com/uploads/campaigns";
106
 
27391 tejbeer 107
	@Autowired
108
	private ItemRepository itemRepository;
109
 
110
	@Autowired
111
	private MVCResponseSender mvcResponseSender;
112
 
113
	@Autowired
114
	private Gson gson;
115
 
116
	@Autowired
117
	private RetailerService retailerService;
118
 
119
	@Autowired
120
	private Mongo mongoClient;
121
 
122
	@Autowired
29900 amit.gupta 123
	private NotificationService notificationService;
124
 
125
	@Autowired
27391 tejbeer 126
	private CookiesProcessor cookiesProcessor;
127
 
128
	@Autowired
27876 amit.gupta 129
	private OfferService offerService;
29900 amit.gupta 130
 
29809 amit.gupta 131
	@Autowired
132
	private CacheManager thirtyMinsTimeOutCacheManager;
29900 amit.gupta 133
 
29855 amit.gupta 134
	@Autowired
135
	private CacheManager oneDayCacheManager;
27876 amit.gupta 136
 
137
	@Autowired
27391 tejbeer 138
	private PartnerTypeChangeService partnerTypeChangeService;
139
 
140
	@RequestMapping(value = "/getCreateOffer", method = RequestMethod.GET)
141
	public String getCreateOffer(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
142
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
143
		List<Integer> fofoIds = fofoStoreRepository.selectActiveStores().stream().map(x -> x.getId())
144
				.collect(Collectors.toList());
145
 
27876 amit.gupta 146
		Set<String> brands = mongoClient.getMongoBrands(loginDetails.getFofoId(), null, 3).stream()
147
				.map(x -> (String) x.get("name")).collect(Collectors.toSet());
27391 tejbeer 148
 
149
		Map<Integer, CustomRetailer> customRetailersMap = retailerService.getFofoRetailers(fofoIds);
150
 
151
		model.addAttribute("customRetailersMap", customRetailersMap);
152
		model.addAttribute("itemCriteriaType", ItemCriteriaType.values());
153
		model.addAttribute("brands", brands);
154
		model.addAttribute("partnerCategories", PartnerType.values());
27876 amit.gupta 155
		model.addAttribute("warehouseRegion", ProfitMandiConstants.WAREHOUSE_MAP);
27391 tejbeer 156
		return "scheme_offer";
157
 
158
	}
159
 
160
	@RequestMapping(value = "/createOffer", method = RequestMethod.POST)
161
	public String createOffer(HttpServletRequest request, @RequestBody CreateOfferRequest createOfferRequest,
162
			Model model) throws Exception {
27876 amit.gupta 163
		LOGGER.info("createOfferRequest [{}]", createOfferRequest);
164
		offerService.addOfferService(createOfferRequest);
29809 amit.gupta 165
		thirtyMinsTimeOutCacheManager.getCache("allOffers").evict(YearMonth.now());
27391 tejbeer 166
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
167
		return "response";
168
 
169
	}
170
 
27876 amit.gupta 171
	@RequestMapping(value = "/offers/published", method = RequestMethod.GET)
172
	public String getPublishedOffers(HttpServletRequest request, @RequestParam int fofoId, Model model)
27391 tejbeer 173
			throws Exception {
27876 amit.gupta 174
		LOGGER.info("Published");
175
		offerService.getPublishedOffers(fofoId, YearMonth.from(LocalDateTime.now()));
176
		return "scheme_offer/published";
27391 tejbeer 177
 
27876 amit.gupta 178
	}
27391 tejbeer 179
 
27876 amit.gupta 180
	@RequestMapping(value = "/offer/active/{offerId}", method = RequestMethod.GET)
29909 amit.gupta 181
	public String activateOffer(HttpServletRequest request, @PathVariable int offerId, Model model, @RequestParam(defaultValue = "true") boolean active)
27876 amit.gupta 182
			throws ProfitMandiBusinessException, Exception {
183
		Offer offer = offerRepository.selectById(offerId);
29909 amit.gupta 184
		boolean alreadyActive = offer.isActive();
185
		if(alreadyActive != active) {
186
			offer.setActive(active);
29900 amit.gupta 187
			oneDayCacheManager.getCache("catalog.published_yearmonth").evict(YearMonth.now());
188
		}
29909 amit.gupta 189
		if(active && !alreadyActive) {
190
			this.sendNotification(offer);
191
		}
27876 amit.gupta 192
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
193
		return "response";
29900 amit.gupta 194
		//CreateOfferRequest createOfferRequest = offerService.getCreateOfferRequest(offer);
195
		//model.addAttribute("offer", createOfferRequest);
196
		//return "offer_margin_detail_partner2";
27876 amit.gupta 197
	}
27391 tejbeer 198
 
29900 amit.gupta 199
	@Autowired
200
	private com.spice.profitmandi.dao.repository.dtr.UserRepository dtrUserRepository;
201
 
29917 amit.gupta 202
	@RequestMapping(value = "/offer/active/fofo/{fofoId}", method = RequestMethod.GET)
203
	public String sendOfferNotification(HttpServletRequest request, @PathVariable int fofoId, Model model, @RequestParam(defaultValue = "true") boolean active)
204
			throws ProfitMandiBusinessException, Exception {
205
		List<Offer> offers = offerRepository.selectAllPublishedMapByPartner(YearMonth.now()).get(fofoId);
206
		for(Offer offer : offers) {
207
			this.sendNotification(offer);
208
		}
209
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
210
		return "response";
211
	}
212
 
29900 amit.gupta 213
	private void sendNotification(Offer offer) throws Exception {
214
		String fileName = "offer-" + offer.getId() + ".png";
215
		CreateOfferRequest createOfferRequest = offerService.getCreateOfferRequest(offer);
216
		SendNotificationModel sendNotificationModel = new SendNotificationModel();
217
		sendNotificationModel.setCampaignName("SchemeOffer");
218
		sendNotificationModel.setTitle(offer.getName());
29905 amit.gupta 219
		sendNotificationModel.setMessage(createOfferRequest.getSchemeType().name() + " of select models, " 
220
		+ FormattingUtils.formatDateMonth(offer.getStartDate()) + " to " + FormattingUtils.formatDateMonth(offer.getEndDate()));
29900 amit.gupta 221
		sendNotificationModel.setType("url");
222
		sendNotificationModel.setImageUrl(IMAGE_STATIC_SERVER_URL + "/" + "image" + LocalDate.now() + "/" + fileName);
223
		sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/notifications");
224
		sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
225
		sendNotificationModel.setMessageType(MessageType.scheme);
226
		Map<Integer, Map<Integer, Long>> partnerWiseMap = null;
227
		Map<Integer, List<Offer>> offersMap = offerRepository.selectAllPublishedMapByPartner(YearMonth.now());
228
		List<Integer> fofoIds = offersMap.entrySet().stream().filter(x -> x.getValue().contains(offer))
229
				.map(x -> x.getKey()).collect(Collectors.toList());
230
		sendNotificationModel.setFofoIds(fofoIds);
231
		Map<String, InputStream> fileStreamsMap = new HashMap<>();
232
		List<Integer> dtrIds = dtrUserRepository
233
				.selectAllByEmailIds(Arrays.asList("tarun.verma@smartdukaan.com", "amit.gupta@shop2020.in"))
234
				.stream().map(x->x.getId()).collect(Collectors.toList());
235
		sendNotificationModel.setUserIds(dtrIds);
236
		notificationService.sendNotification(sendNotificationModel);
237
		try {
238
			Map<String, Object> model = new HashMap<>();
239
			model.put("offer", createOfferRequest);
240
			String htmlContent=this.getContentFromTemplate("offer_margin_detail_partner.vm", model);
241
			LOGGER.info("this.getContentFromTemplate {}", htmlContent);
242
			fileStreamsMap.put(fileName, this.getImageBuffer(htmlContent));
243
			this.uploadFile(fileStreamsMap);
244
		} catch (Exception e) {
245
			e.printStackTrace();
246
		}
247
 
248
	}
249
 
250
	private InputStream	asInputStream(BufferedImage bi) throws Exception {
251
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
252
		ImageIO.write(bi, "png", baos);
253
		return new ByteArrayInputStream(baos.toByteArray());
254
 
255
	}
256
 
257
	private ChannelSftp setupJsch() throws JSchException {
258
		JSch jsch = new JSch();
259
		Session jschSession = jsch.getSession("root", "192.168.179.131");
260
		//Session jschSession = jsch.getSession("root", "173.255.254.24");
261
		LOGGER.info("getClass().getResource(\"id_rsa\") {}", getClass().getClassLoader().getResource("id_rsa").getPath());
262
		jsch.addIdentity(getClass().getClassLoader().getResource("id_rsa").getPath());
263
		//jschSession.setPassword("spic@2015static0");
264
		jschSession.setConfig("StrictHostKeyChecking", "no");
265
		jschSession.connect();
266
		return (ChannelSftp) jschSession.openChannel("sftp");
267
	}
268
 
269
	private void fileUpload(ChannelSftp channelSftp, Map<String, InputStream> streamsFileMap, String destinationPath)
270
			throws SftpException, FileNotFoundException {
271
 
272
		channelSftp.cd(destinationPath);
273
		String folderName = "image" + LocalDate.now();
274
 
275
		channelSftp.cd(destinationPath);
276
		SftpATTRS attrs = null;
277
 
278
		// check if the directory is already existing
279
		try {
280
			attrs = channelSftp.stat(folderName);
281
		} catch (Exception e) {
282
			System.out.println(destinationPath + "/" + folderName + " not found");
283
		}
284
 
285
		// else create a directory
286
		if (attrs == null) {
287
			channelSftp.mkdir(folderName);
288
			channelSftp.chmod(0755, ".");
289
		}
290
		channelSftp.cd(folderName);
291
 
292
		for (Map.Entry<String, InputStream> streamsFileEntry : streamsFileMap.entrySet()) {
293
			channelSftp.put(streamsFileEntry.getValue(), streamsFileEntry.getKey(), ChannelSftp.OVERWRITE);
294
		}
295
 
296
	}
297
 
298
	private void uploadFile(Map<String, InputStream> fileStreamsMap) throws Exception {
299
		ChannelSftp channelSftp = setupJsch();
300
		channelSftp.connect();
301
		this.fileUpload(channelSftp, fileStreamsMap, IMAGE_REMOTE_DIR + "");
302
		channelSftp.exit();
303
	}
304
 
305
	private InputStream getImageBuffer (String html) throws Exception {
306
		String fileName = "/tmp/" + Instant.now().toEpochMilli();
307
		FileUtils.writeStringToFile(new File(fileName), html, "UTF-8");
308
		return this.asInputStream(Graphics2DRenderer.renderToImageAutoSize("file:" + fileName, 500));
309
	}
310
 
311
	@Autowired
312
	VelocityEngine velocityEngine;
313
 
314
	private String getContentFromTemplate(String template, Map<String, Object> model) {
315
		StringBuffer content = new StringBuffer();
316
		try {
317
			content.append(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, template, model));
318
		} catch (Exception e) {
319
			e.printStackTrace();
320
		}
321
		return content.toString();
322
	}
323
 
27876 amit.gupta 324
	@RequestMapping(value = "/offerHistory", method = RequestMethod.GET)
325
	public String getPaginatedOffers(HttpServletRequest request, @RequestParam YearMonth yearMonth, Model model)
326
			throws ProfitMandiBusinessException {
27391 tejbeer 327
 
29900 amit.gupta 328
		List<CreateOfferRequest> publishedOffers = offerService.getAllOffers(yearMonth).values().stream()
329
				.sorted(Comparator.comparing(CreateOfferRequest::getId).reversed()).collect(Collectors.toList());
27876 amit.gupta 330
		model.addAttribute("offers", publishedOffers);
331
		model.addAttribute("yearMonth", yearMonth);
27391 tejbeer 332
 
333
		return "offer_history";
334
	}
335
 
27876 amit.gupta 336
	@RequestMapping(value = "/offer-details", method = RequestMethod.GET)
337
	public String schemeDetails(HttpServletRequest request, @RequestParam int offerId, Model model)
27391 tejbeer 338
			throws ProfitMandiBusinessException {
29839 amit.gupta 339
		CreateOfferRequest createOfferRequest = offerService.getOffer(0, offerId);
27391 tejbeer 340
 
27876 amit.gupta 341
		model.addAttribute("offer", createOfferRequest);
342
		return "offer-details";
27391 tejbeer 343
	}
344
 
27876 amit.gupta 345
	@RequestMapping(value = "/offerDownload", method = RequestMethod.GET)
346
	public ResponseEntity<?> dowloadOfferSummary(HttpServletRequest request, @RequestParam int offerId, Model model)
347
			throws Exception {
348
		List<List<?>> listOfRows = new ArrayList<>();
349
		final HttpHeaders headers = new HttpHeaders();
350
		headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
351
		headers.set("Content-disposition", "inline; filename=offer-" + offerId + ".csv");
29785 amit.gupta 352
		CreateOfferRequest createOfferRequest = offerService.getOffer(0, offerId);
27876 amit.gupta 353
		Collection<OfferRowModel> offerRowModels = offerRepository.getOfferRows(createOfferRequest);
27391 tejbeer 354
 
27876 amit.gupta 355
		for (OfferRowModel offerRowModel : offerRowModels) {
356
			CustomRetailer customRetailer = retailerService.getFofoRetailer(offerRowModel.getFofoId());
357
			listOfRows.add(Arrays.asList(createOfferRequest.getId(), createOfferRequest.getName(),
358
					createOfferRequest.getTargetType(), createOfferRequest.getSchemeType(),
359
					createOfferRequest.getBrandShareTerms(), createOfferRequest.getSellinPercentage(),
360
					createOfferRequest.getPartnerCriteriaString(), createOfferRequest.getItemCriteriaString(),
361
					createOfferRequest.getStartDate(), createOfferRequest.getEndDate(),
362
					createOfferRequest.getCreatedOn(), customRetailer.getPartnerId(), customRetailer.getBusinessName(),
363
					customRetailer.getCode(), offerRowModel.getTotalSale(), offerRowModel.getEligibleSale(),
364
					offerRowModel.getAchievedTarget(), offerRowModel.getNextTarget(), offerRowModel.getEligibleSaleDp(),
365
					offerRowModel.getTotalPurchaseValue(), offerRowModel.getCurrentPayoutTarget(),
366
					offerRowModel.getPayoutTargetAchieved(), offerRowModel.getAmountType(),
367
					offerRowModel.getPayoutValue(), offerRowModel.getPayoutValueDp(), offerRowModel.getFinalPayout(),
368
					String.join(", ", offerRowModel.getPendingImeis())));
27391 tejbeer 369
		}
27876 amit.gupta 370
		ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
371
				Arrays.asList("Id", "Name", "Target Type", "Scheme Type", "Brand %", "Sellin %", "Partner Criteria",
372
						"Item Criteria", "Start", "End", "Created", "Partner Id", "Partner Name", "Partner Code",
373
						"Total Sale", "Eligible Sale", "Achieved Target", "Next Target", "Eligible Sale DP",
374
						"Total Purchase DP", "Current Payout Target", "Payout Target Achieved", "Payout Amount Type",
375
						"Payout Value", "Payout Value DP", "Amount to be credited", "IMEIs pending for Activation"
376
				// "Payout Sale Qty", "Activated Value", "Activated Qty",
377
				), listOfRows);
378
		final InputStream inputStream = new ByteArrayInputStream(baos.toByteArray());
379
		final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
380
		return new ResponseEntity<>(inputStreamResource, headers, HttpStatus.OK);
27391 tejbeer 381
	}
29900 amit.gupta 382
 
27876 amit.gupta 383
	@RequestMapping(value = "/offerById", method = RequestMethod.GET)
384
	public String offerById(HttpServletRequest request, int offerId, Model model) throws ProfitMandiBusinessException {
27391 tejbeer 385
		Offer offer = offerRepository.selectById(offerId);
386
 
387
		model.addAttribute("offer", offer);
388
 
27876 amit.gupta 389
		return "offer-edit";
27391 tejbeer 390
 
391
	}
29900 amit.gupta 392
 
29675 amit.gupta 393
	@RequestMapping(value = "/published-offers/{yearMonth}", method = RequestMethod.GET)
29900 amit.gupta 394
	public String publishedOffersOnMonthBefore(HttpServletRequest request, @PathVariable int yearMonth, Model model)
395
			throws ProfitMandiBusinessException {
29675 amit.gupta 396
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
397
		int fofoId = loginDetails.getFofoId();
29900 amit.gupta 398
		List<CreateOfferRequest> createOffers = offerService.getPublishedOffers(fofoId,
399
				YearMonth.from(LocalDate.now()).minusMonths(yearMonth));
400
 
29675 amit.gupta 401
		model.addAttribute("publishedOffers", createOffers);
29900 amit.gupta 402
 
29675 amit.gupta 403
		return "published-offers";
404
	}
29900 amit.gupta 405
 
29682 amit.gupta 406
	@PostMapping(value = "/offers/upload")
407
	public String uploadOffers(HttpServletRequest request, @RequestPart("file") MultipartFile targetFile, Model model)
408
			throws Exception {
409
		offerService.createOffers(targetFile.getInputStream());
410
		model.addAttribute("response", true);
411
		return "response";
412
	}
29900 amit.gupta 413
 
29785 amit.gupta 414
	@Autowired
415
	RoleManager roleManager;
27391 tejbeer 416
 
27876 amit.gupta 417
	@RequestMapping(value = "/getOfferMargins", method = RequestMethod.GET)
418
	public String getOfferMargins(HttpServletRequest request,
419
			@RequestParam(name = "offerId", defaultValue = "0") int offerId, Model model) throws Exception {
420
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
29785 amit.gupta 421
		boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
29900 amit.gupta 422
		CreateOfferRequest createOfferRequest = offerService.getOffer(isAdmin ? 0 : loginDetails.getFofoId(), offerId);
423
 
27876 amit.gupta 424
		model.addAttribute("offer", createOfferRequest);
27391 tejbeer 425
 
27876 amit.gupta 426
		return "offer_margin_detail_partner";
27391 tejbeer 427
 
428
	}
429
 
27895 amit.gupta 430
}