Subversion Repositories SmartDukaan

Rev

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

Rev 24094 Rev 24105
Line 26... Line 26...
26
import org.springframework.http.ResponseEntity;
26
import org.springframework.http.ResponseEntity;
27
import org.springframework.stereotype.Controller;
27
import org.springframework.stereotype.Controller;
28
import org.springframework.transaction.annotation.Transactional;
28
import org.springframework.transaction.annotation.Transactional;
29
import org.springframework.ui.Model;
29
import org.springframework.ui.Model;
30
import org.springframework.web.bind.annotation.PathVariable;
30
import org.springframework.web.bind.annotation.PathVariable;
-
 
31
import org.springframework.web.bind.annotation.PutMapping;
31
import org.springframework.web.bind.annotation.RequestBody;
32
import org.springframework.web.bind.annotation.RequestBody;
32
import org.springframework.web.bind.annotation.RequestMapping;
33
import org.springframework.web.bind.annotation.RequestMapping;
33
import org.springframework.web.bind.annotation.RequestMethod;
34
import org.springframework.web.bind.annotation.RequestMethod;
34
import org.springframework.web.bind.annotation.RequestParam;
35
import org.springframework.web.bind.annotation.RequestParam;
35
 
36
 
Line 38... Line 39...
38
import com.spice.profitmandi.common.model.CartFofo;
39
import com.spice.profitmandi.common.model.CartFofo;
39
import com.spice.profitmandi.common.model.CreateOrderRequest;
40
import com.spice.profitmandi.common.model.CreateOrderRequest;
40
import com.spice.profitmandi.common.model.CreditNotePdfModel;
41
import com.spice.profitmandi.common.model.CreditNotePdfModel;
41
import com.spice.profitmandi.common.model.CustomCustomer;
42
import com.spice.profitmandi.common.model.CustomCustomer;
42
import com.spice.profitmandi.common.model.FoiBadReturnRequest;
43
import com.spice.profitmandi.common.model.FoiBadReturnRequest;
-
 
44
import com.spice.profitmandi.common.model.PaymentOptionTransactionModel;
43
import com.spice.profitmandi.common.model.PdfModel;
45
import com.spice.profitmandi.common.model.PdfModel;
44
import com.spice.profitmandi.common.model.PriceModel;
46
import com.spice.profitmandi.common.model.PriceModel;
45
import com.spice.profitmandi.common.model.ProfitMandiConstants;
47
import com.spice.profitmandi.common.model.ProfitMandiConstants;
46
import com.spice.profitmandi.common.util.PdfUtils;
48
import com.spice.profitmandi.common.util.PdfUtils;
47
import com.spice.profitmandi.common.util.StringUtils;
49
import com.spice.profitmandi.common.util.StringUtils;
Line 77... Line 79...
77
import com.spice.profitmandi.service.authentication.RoleManager;
79
import com.spice.profitmandi.service.authentication.RoleManager;
78
import com.spice.profitmandi.service.order.OrderService;
80
import com.spice.profitmandi.service.order.OrderService;
79
import com.spice.profitmandi.service.pricing.PricingService;
81
import com.spice.profitmandi.service.pricing.PricingService;
80
import com.spice.profitmandi.web.model.LoginDetails;
82
import com.spice.profitmandi.web.model.LoginDetails;
81
import com.spice.profitmandi.web.util.CookiesProcessor;
83
import com.spice.profitmandi.web.util.CookiesProcessor;
-
 
84
import com.spice.profitmandi.web.util.MVCResponseSender;
82
 
85
 
83
@Controller
86
@Controller
84
@Transactional(rollbackFor = Throwable.class)
87
@Transactional(rollbackFor = Throwable.class)
85
public class OrderController {
88
public class OrderController {
86
 
89
 
Line 105... Line 108...
105
 
108
 
106
	@Autowired
109
	@Autowired
107
	private ItemRepository itemRepository;
110
	private ItemRepository itemRepository;
108
 
111
 
109
	@Autowired
112
	@Autowired
-
 
113
	private MVCResponseSender mvcResponseSender;
-
 
114
 
-
 
115
	@Autowired
110
	private FofoOrderRepository fofoOrderRepository;
116
	private FofoOrderRepository fofoOrderRepository;
111
 
117
 
112
	@Autowired
118
	@Autowired
113
	private CustomerAddressRepository customerAddressRepository;
119
	private CustomerAddressRepository customerAddressRepository;
114
 
120
 
Line 350... Line 356...
350
 
356
 
351
		FofoOrder fofoOrder = fofoOrderRepository.selectByInvoiceNumber(invoiceNumber);
357
		FofoOrder fofoOrder = fofoOrderRepository.selectByInvoiceNumber(invoiceNumber);
352
		List<FofoOrderItem> fofoLineItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
358
		List<FofoOrderItem> fofoLineItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
353
		Customer customer = customerRepository.selectById(fofoOrder.getCustomerId());
359
		Customer customer = customerRepository.selectById(fofoOrder.getCustomerId());
354
		CustomerAddress customerAddress = customerAddressRepository.selectById(fofoOrder.getCustomerAddressId());
360
		CustomerAddress customerAddress = customerAddressRepository.selectById(fofoOrder.getCustomerAddressId());
-
 
361
		List<Integer> fofoPartnerPaymentOptions = fofoPartnerPaymentOptionRepository
-
 
362
				.selectPaymentOptionIdsByFofoId(fofoOrder.getFofoId());
-
 
363
		LOGGER.info("fofoPartnerPaymentOptions" + fofoPartnerPaymentOptions);
355
		List<PaymentOptionTransaction> paymentOptionTransactions = fofoOrderPaymentOptionRepository
364
		List<PaymentOptionTransaction> paymentOptionTransactions = fofoOrderPaymentOptionRepository
356
				.selectByReferenceIdAndType(fofoOrder.getId(), PaymentOptionReferenceType.ORDER);
365
				.selectByReferenceIdAndType(fofoOrder.getId(), PaymentOptionReferenceType.ORDER);
-
 
366
		LOGGER.info("paymentOptionTransactions" + paymentOptionTransactions);
357
		Map<Integer, PaymentOption> paymentOptionIdPaymentOptionMap = this
367
		Map<Integer, PaymentOption> paymentOptionIdPaymentOptionMap = this
-
 
368
				.paymentOptionIdPaymentOptionMapUsingPaymentOptions(fofoPartnerPaymentOptions);
-
 
369
		Map<Integer, PaymentOptionTransaction> paymentOptionIdPaymentOptionTransactionMap = this
358
				.paymentOptionIdPaymentOptionMap(paymentOptionTransactions);
370
				.paymentOptionIdPaymentOptionTransactionMap(paymentOptionTransactions);
-
 
371
		LOGGER.info("paymentOptionIdPaymentOptionTransactionMap" + paymentOptionIdPaymentOptionTransactionMap.keySet());
359
		List<InsurancePolicy> insurancePolicies = insurancePolicyRepository
372
		List<InsurancePolicy> insurancePolicies = insurancePolicyRepository
360
				.selectByRetailerIdInvoiceNumber(fofoOrder.getFofoId(), fofoOrder.getInvoiceNumber());
373
				.selectByRetailerIdInvoiceNumber(fofoOrder.getFofoId(), fofoOrder.getInvoiceNumber());
361
		this.addInsuranceProvider(insurancePolicies);
374
		this.addInsuranceProvider(insurancePolicies);
362
		model.addAttribute("fofoOrder", fofoOrder);
375
		model.addAttribute("fofoOrder", fofoOrder);
363
		model.addAttribute("fofoLineItems", fofoLineItems);
376
		model.addAttribute("fofoLineItems", fofoLineItems);
364
		model.addAttribute("customer", customer);
377
		model.addAttribute("customer", customer);
365
		model.addAttribute("customerAddress", customerAddress);
378
		model.addAttribute("customerAddress", customerAddress);
366
		model.addAttribute("paymentOptionTransactions", paymentOptionTransactions);
379
		model.addAttribute("paymentOptionTransactions", paymentOptionTransactions);
367
		model.addAttribute("paymentOptionIdPaymentOptionMap", paymentOptionIdPaymentOptionMap);
380
		model.addAttribute("paymentOptionIdPaymentOptionMap", paymentOptionIdPaymentOptionMap);
-
 
381
		model.addAttribute("paymentOptionIdPaymentOptionTransactionMap", paymentOptionIdPaymentOptionTransactionMap);
368
		model.addAttribute("insurancePolicies", insurancePolicies);
382
		model.addAttribute("insurancePolicies", insurancePolicies);
-
 
383
		model.addAttribute("fofoPartnerPaymentOptions", fofoPartnerPaymentOptions);
-
 
384
		model.addAttribute("totalNumberOfPaymentOptionId", fofoPartnerPaymentOptions.size());
369
		model.addAttribute("stateNames", Utils.getAllStateNames());
385
		model.addAttribute("stateNames", Utils.getAllStateNames());
370
		return "search-order-details";
386
		return "search-order-details";
371
	}
387
	}
372
 
388
 
373
	private Map<Integer, PaymentOption> paymentOptionIdPaymentOptionMap(
389
	private Map<Integer, PaymentOption> paymentOptionIdPaymentOptionMap(
Line 382... Line 398...
382
			paymentOptionIdPaymentOptionMap.put(paymentOption.getId(), paymentOption);
398
			paymentOptionIdPaymentOptionMap.put(paymentOption.getId(), paymentOption);
383
		}
399
		}
384
		return paymentOptionIdPaymentOptionMap;
400
		return paymentOptionIdPaymentOptionMap;
385
	}
401
	}
386
 
402
 
-
 
403
	private Map<Integer, PaymentOption> paymentOptionIdPaymentOptionMapUsingPaymentOptions(
-
 
404
			List<Integer> fofoPartnerPaymentOptions) {
-
 
405
		List<PaymentOption> paymentOptions = paymentOptionRepository
-
 
406
				.selectByIds(new HashSet<>(fofoPartnerPaymentOptions));
-
 
407
		Map<Integer, PaymentOption> paymentOptionIdPaymentOptionMap = new HashMap<>();
-
 
408
		for (PaymentOption paymentOption : paymentOptions) {
-
 
409
			paymentOptionIdPaymentOptionMap.put(paymentOption.getId(), paymentOption);
-
 
410
		}
-
 
411
		return paymentOptionIdPaymentOptionMap;
-
 
412
	}
-
 
413
 
-
 
414
	private Map<Integer, PaymentOptionTransaction> paymentOptionIdPaymentOptionTransactionMap(
-
 
415
			List<PaymentOptionTransaction> paymentOptionTransactions) {
-
 
416
		Map<Integer, PaymentOptionTransaction> paymentOptionIdPaymentOptionTransactionMap = new HashMap<>();
-
 
417
		for (PaymentOptionTransaction paymentOptionTransaction : paymentOptionTransactions) {
-
 
418
			paymentOptionIdPaymentOptionTransactionMap.put(paymentOptionTransaction.getPaymentOptionId(),
-
 
419
					paymentOptionTransaction);
-
 
420
		}
-
 
421
		return paymentOptionIdPaymentOptionTransactionMap;
-
 
422
	}
-
 
423
 
-
 
424
	
-
 
425
 
387
	@RequestMapping(value = "/create-order", method = RequestMethod.POST)
426
	@RequestMapping(value = "/create-order", method = RequestMethod.POST)
388
	public String createOrder(HttpServletRequest request, @RequestBody CreateOrderRequest createOrderRequest,
427
	public String createOrder(HttpServletRequest request, @RequestBody CreateOrderRequest createOrderRequest,
389
			Model model) throws ProfitMandiBusinessException {
428
			Model model) throws ProfitMandiBusinessException {
390
		LOGGER.info("request at uri {} body {}", request.getRequestURI(), createOrderRequest);
429
		LOGGER.info("request at uri {} body {}", request.getRequestURI(), createOrderRequest);
391
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
430
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
Line 478... Line 517...
478
		model.addAllAttributes(map);
517
		model.addAllAttributes(map);
479
 
518
 
480
		return "sale-history-paginated";
519
		return "sale-history-paginated";
481
	}
520
	}
482
 
521
 
-
 
522
	@PutMapping(value = "/updatePaymentTransaction")
-
 
523
	public String updateTransactionDetails(HttpServletRequest request, @RequestParam String referenceType,
-
 
524
			@RequestParam int fofoId, @RequestParam int referenceId,
-
 
525
			@RequestBody List<PaymentOptionTransactionModel> paymentOptionTransactionModels, Model model)
-
 
526
			throws Exception {
-
 
527
		float amount = 0;
-
 
528
		LOGGER.info(paymentOptionTransactionModels);
-
 
529
 
-
 
530
		for (PaymentOptionTransactionModel paymentOptionTransactionModel : paymentOptionTransactionModels) {
-
 
531
			amount = amount + paymentOptionTransactionModel.getAmount();
-
 
532
		}
-
 
533
		FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndOrderId(fofoId, referenceId);
-
 
534
		LOGGER.info("FofoOrder amount" + fofoOrder.getTotalAmount() + "amount" + amount);
-
 
535
		if (amount == fofoOrder.getTotalAmount()) {
-
 
536
			if (paymentOptionTransactionModels.size() > 0) {
-
 
537
				List<PaymentOptionTransaction> paymentOptionTransactions = fofoOrderPaymentOptionRepository
-
 
538
						.selectByReferenceIdAndType(referenceId, PaymentOptionReferenceType.ORDER);
-
 
539
				Map<Integer, PaymentOptionTransaction> paymentOptionIdPaymentOptionTransactionMap = this
-
 
540
						.paymentOptionIdPaymentOptionTransactionMap(paymentOptionTransactions);
-
 
541
				LOGGER.info("paymentOptionIdPaymentOptionTransactionMap"
-
 
542
						+ paymentOptionIdPaymentOptionTransactionMap.keySet());
-
 
543
				for (PaymentOptionTransactionModel paymentOptionTransactionModel : paymentOptionTransactionModels) {
-
 
544
					if (paymentOptionIdPaymentOptionTransactionMap
-
 
545
							.containsKey(paymentOptionTransactionModel.getPaymentOptionId())) {
-
 
546
 
-
 
547
						PaymentOptionTransaction paymentOptionTransaction = paymentOptionIdPaymentOptionTransactionMap
-
 
548
								.get(paymentOptionTransactionModel.getPaymentOptionId());
-
 
549
 
-
 
550
						if (paymentOptionTransactionModel.getAmount() == 0) {
-
 
551
							fofoOrderPaymentOptionRepository.delete(paymentOptionTransaction);
-
 
552
							LOGGER.info("deleted successfully");
-
 
553
						} else {
-
 
554
 
-
 
555
							paymentOptionTransaction.setAmount(paymentOptionTransactionModel.getAmount());
-
 
556
							fofoOrderPaymentOptionRepository.persist(paymentOptionTransaction);
-
 
557
							LOGGER.info("updated successfully");
-
 
558
 
-
 
559
						}
-
 
560
					} else {
-
 
561
						if (paymentOptionTransactionModel.getAmount() > 0) {
-
 
562
							PaymentOptionTransaction paymentOptionTransaction = new PaymentOptionTransaction();
-
 
563
							paymentOptionTransaction.setReferenceId(referenceId);
-
 
564
							paymentOptionTransaction.setReferenceType(PaymentOptionReferenceType.ORDER);
-
 
565
							paymentOptionTransaction
-
 
566
									.setPaymentOptionId(paymentOptionTransactionModel.getPaymentOptionId());
-
 
567
							paymentOptionTransaction.setAmount(paymentOptionTransactionModel.getAmount());
-
 
568
							paymentOptionTransaction.setFofoId(fofoId);
-
 
569
							paymentOptionTransaction.setCreateTimestamp(LocalDateTime.now());
-
 
570
							fofoOrderPaymentOptionRepository.persist(paymentOptionTransaction);
-
 
571
							LOGGER.info("inserted successfully");
-
 
572
						}
-
 
573
					}
-
 
574
 
-
 
575
				}
-
 
576
 
-
 
577
				model.addAttribute("response", mvcResponseSender.createResponseString(true));
-
 
578
			}
-
 
579
		} else {
-
 
580
			throw new ProfitMandiBusinessException("Amount", amount, "Sum of amount is not equal to total amount");
-
 
581
		}
-
 
582
 
-
 
583
		return "response";
-
 
584
	}
483
}
585
}