Subversion Repositories SmartDukaan

Rev

Rev 36400 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 36400 Rev 37399
Line 32... Line 32...
32
import org.springframework.web.bind.annotation.RequestMethod;
32
import org.springframework.web.bind.annotation.RequestMethod;
33
 
33
 
34
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
34
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
35
import com.spice.profitmandi.common.model.CustomAddress;
35
import com.spice.profitmandi.common.model.CustomAddress;
36
import com.spice.profitmandi.common.model.CustomCustomer;
36
import com.spice.profitmandi.common.model.CustomCustomer;
37
import com.spice.profitmandi.common.model.CustomInsurancePolicy;
-
 
38
import com.spice.profitmandi.common.model.CustomOrderItem;
37
import com.spice.profitmandi.common.model.CustomOrderItem;
39
import com.spice.profitmandi.common.model.CustomRetailer;
38
import com.spice.profitmandi.common.model.CustomRetailer;
40
import com.spice.profitmandi.common.model.GadgetCopsDocumentInsuranceModel;
39
import com.spice.profitmandi.common.model.GadgetCopsDocumentInsuranceModel;
41
import com.spice.profitmandi.common.model.InvoicePdfModel;
40
import com.spice.profitmandi.common.model.InvoicePdfModel;
42
 
41
 
Line 51... Line 50...
51
import com.spice.profitmandi.dao.entity.dtr.GadgetCopsInsuranceCalc;
50
import com.spice.profitmandi.dao.entity.dtr.GadgetCopsInsuranceCalc;
52
import com.spice.profitmandi.dao.entity.dtr.InsurancePolicy;
51
import com.spice.profitmandi.dao.entity.dtr.InsurancePolicy;
53
import com.spice.profitmandi.dao.entity.dtr.InsuranceProvider;
52
import com.spice.profitmandi.dao.entity.dtr.InsuranceProvider;
54
import com.spice.profitmandi.dao.entity.dtr.PolicyNumberGenerationSequence;
53
import com.spice.profitmandi.dao.entity.dtr.PolicyNumberGenerationSequence;
55
import com.spice.profitmandi.dao.entity.dtr.ThirdPartyInvoiceSequence;
54
import com.spice.profitmandi.dao.entity.dtr.ThirdPartyInvoiceSequence;
-
 
55
import com.spice.profitmandi.dao.entity.inventory.State;
56
import com.spice.profitmandi.dao.enumuration.dtr.ThirdParty;
56
import com.spice.profitmandi.dao.enumuration.dtr.ThirdParty;
57
import com.spice.profitmandi.dao.model.UserCart;
57
import com.spice.profitmandi.dao.model.UserCart;
58
import com.spice.profitmandi.dao.repository.catalog.RangeItemPriceRepository;
58
import com.spice.profitmandi.dao.repository.catalog.RangeItemPriceRepository;
59
import com.spice.profitmandi.dao.repository.catalog.RangeItemRepository;
59
import com.spice.profitmandi.dao.repository.catalog.RangeItemRepository;
60
import com.spice.profitmandi.dao.repository.dtr.DocumentRepository;
60
import com.spice.profitmandi.dao.repository.dtr.DocumentRepository;
61
import com.spice.profitmandi.dao.repository.dtr.GadgetCopsInsuranceCalcRepository;
-
 
62
import com.spice.profitmandi.dao.repository.dtr.InsurancePolicyRepository;
61
import com.spice.profitmandi.dao.repository.dtr.InsurancePolicyRepository;
63
import com.spice.profitmandi.dao.repository.dtr.InsuranceProviderRepository;
62
import com.spice.profitmandi.dao.repository.dtr.InsuranceProviderRepository;
64
import com.spice.profitmandi.dao.repository.dtr.PolicyNumberGenerationSequenceRepository;
63
import com.spice.profitmandi.dao.repository.dtr.PolicyNumberGenerationSequenceRepository;
65
import com.spice.profitmandi.dao.repository.dtr.ThirdPartyInvoiceSequenceRepository;
64
import com.spice.profitmandi.dao.repository.dtr.ThirdPartyInvoiceSequenceRepository;
66
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
65
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
67
import com.spice.profitmandi.dao.repository.fofo.InvoiceNumberGenerationSequenceRepository;
66
import com.spice.profitmandi.dao.repository.fofo.InvoiceNumberGenerationSequenceRepository;
-
 
67
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
68
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
68
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
-
 
69
import com.spice.profitmandi.service.order.InsuranceInvoiceLine;
69
import com.spice.profitmandi.service.pricing.PricingService;
70
import com.spice.profitmandi.service.pricing.PricingService;
70
import com.spice.profitmandi.service.wallet.WalletService;
71
import com.spice.profitmandi.service.wallet.WalletService;
71
import com.spice.profitmandi.dao.service.OtpProcessor;
72
import com.spice.profitmandi.dao.service.OtpProcessor;
72
 
73
 
73
import in.shop2020.model.v1.order.WalletReferenceType;
74
import in.shop2020.model.v1.order.WalletReferenceType;
Line 77... Line 78...
77
public class InsuranceController {
78
public class InsuranceController {
78
	private static final Logger LOGGER = LogManager.getLogger(InsuranceController.class);
79
	private static final Logger LOGGER = LogManager.getLogger(InsuranceController.class);
79
	private static final String gadgetCopsFilePath = "/GadgetCops";
80
	private static final String gadgetCopsFilePath = "/GadgetCops";
80
 
81
 
81
	@Autowired
82
	@Autowired
-
 
83
	private StateRepository stateRepository;
-
 
84
 
-
 
85
	@Autowired
82
	private RangeItemPriceRepository rangeItemPriceRepository;
86
	private RangeItemPriceRepository rangeItemPriceRepository;
83
 
87
 
84
	@Autowired
88
	@Autowired
85
	private RangeItemRepository rangeItemRepository;
89
	private RangeItemRepository rangeItemRepository;
86
 
90
 
Line 103... Line 107...
103
 
107
 
104
	@Autowired
108
	@Autowired
105
	ResponseSender<?> responseSender;
109
	ResponseSender<?> responseSender;
106
 
110
 
107
	@Autowired
111
	@Autowired
108
	GadgetCopsInsuranceCalcRepository gadgetCopsInsuranceCalcRepository;
-
 
109
 
-
 
110
	@Autowired
-
 
111
	ThirdPartyInvoiceSequenceRepository thirdPartyInvoiceSequenceRepository;
112
	ThirdPartyInvoiceSequenceRepository thirdPartyInvoiceSequenceRepository;
112
 
113
 
113
	@Autowired
114
	@Autowired
114
	DocumentRepository documentRepository;
115
	DocumentRepository documentRepository;
115
 
116
 
Line 288... Line 289...
288
	public String getFormattedDate(LocalDateTime localDate) {
289
	public String getFormattedDate(LocalDateTime localDate) {
289
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-YYYY HH:mm");
290
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-YYYY HH:mm");
290
		return localDate.format(formatter);
291
		return localDate.format(formatter);
291
	}
292
	}
292
 
293
 
-
 
294
	/**
-
 
295
	 * GST state code for a state name, or null when the name is blank or unknown to us — the
-
 
296
	 * renderer simply omits the line rather than failing the policy purchase.
-
 
297
	 */
-
 
298
	private String stateCode(String stateName) {
-
 
299
		if (stateName == null || stateName.trim().isEmpty()) {
-
 
300
			return null;
-
 
301
		}
-
 
302
		State state = stateRepository.selectByName(stateName);
-
 
303
		return state != null ? state.getCode() : null;
-
 
304
	}
-
 
305
 
293
	private InvoicePdfModel getInvoicePdfModel(InsurancePolicy insurancePolicy) throws ProfitMandiBusinessException {
306
	private InvoicePdfModel getInvoicePdfModel(InsurancePolicy insurancePolicy) throws ProfitMandiBusinessException {
294
 
307
 
295
		InvoicePdfModel pdfModel = new InvoicePdfModel();
308
		InvoicePdfModel pdfModel = new InvoicePdfModel();
296
		pdfModel.setAuther("profitmandi");
309
		pdfModel.setAuther("profitmandi");
297
		pdfModel.setTitle("Retailer Invoice");
310
		pdfModel.setTitle("Retailer Invoice");
298
		pdfModel.setInvoiceDate(getFormattedDate(insurancePolicy.getCreateTimestamp()));
311
		pdfModel.setInvoiceDate(getFormattedDate(insurancePolicy.getCreateTimestamp()));
299
 
312
 
300
		// insurance calculation
313
		// insurance calculation
301
		List<CustomInsurancePolicy> customInsurancePolicies = new ArrayList<>();
314
		pdfModel.setInsurancePolicies(Arrays.asList(InsuranceInvoiceLine.from(insurancePolicy)));
302
		final float totalInsuranceTaxRate = 18;
-
 
303
 
315
 
304
		float taxableInsurancePrice = insurancePolicy.getSaleAmount() / (1 + totalInsuranceTaxRate / 100);
-
 
305
		CustomInsurancePolicy customInsurancePolicy = new CustomInsurancePolicy();
-
 
306
		customInsurancePolicy.setDescription("Damage Protection Plan for device IMEI #"
-
 
307
				+ insurancePolicy.getSerialNumber() + "\n Certificate No. " + insurancePolicy.getPolicyNumber());
-
 
308
		customInsurancePolicy.setHsnCode("998716");
-
 
309
		customInsurancePolicy.setRate(taxableInsurancePrice);
-
 
310
		customInsurancePolicy.setIgstRate(18);
-
 
311
		customInsurancePolicy.setIgstAmount(taxableInsurancePrice * 18 / 100);
-
 
312
		customInsurancePolicy.setCgstRate(9);
-
 
313
		customInsurancePolicy.setCgstAmount(taxableInsurancePrice * 9 / 100);
-
 
314
		customInsurancePolicy.setSgstRate(9);
-
 
315
		customInsurancePolicy.setSgstAmount(taxableInsurancePrice * 9 / 100);
-
 
316
		customInsurancePolicy.setNetAmount(insurancePolicy.getSaleAmount());
-
 
317
		customInsurancePolicies.add(customInsurancePolicy);
-
 
318
 
-
 
319
		pdfModel.setInsurancePolicies(customInsurancePolicies);
-
 
320
		CustomCustomer customCustomer = new CustomCustomer();
316
		CustomCustomer customCustomer = new CustomCustomer();
321
		customCustomer.setFirstName(insurancePolicy.getCustomerFirstName());
317
		customCustomer.setFirstName(insurancePolicy.getCustomerFirstName());
322
		customCustomer.setLastName(insurancePolicy.getCustomerLastName());
318
		customCustomer.setLastName(insurancePolicy.getCustomerLastName());
323
		customCustomer.setEmailId(insurancePolicy.getCustomerEmailId());
319
		customCustomer.setEmailId(insurancePolicy.getCustomerEmailId());
324
		customCustomer.setMobileNumber(insurancePolicy.getCustomerMobileNumber());
320
		customCustomer.setMobileNumber(insurancePolicy.getCustomerMobileNumber());
Line 335... Line 331...
335
		customCustomer.setAddress(customAddress);
331
		customCustomer.setAddress(customAddress);
336
		pdfModel.setCustomer(customCustomer);
332
		pdfModel.setCustomer(customCustomer);
337
 
333
 
338
		// TODO get invoice number for damageProtection provider
334
		// TODO get invoice number for damageProtection provider
339
		pdfModel.setInvoiceNumber(thirdPartyInvoiceSequenceRepository.getNextSequence(ThirdParty.GADGET_COP));
335
		pdfModel.setInvoiceNumber(thirdPartyInvoiceSequenceRepository.getNextSequence(ThirdParty.GADGET_COP));
340
		pdfModel.setTotalAmount(gadgetCopsInsuranceCalcRepository.selectByPrice(insurancePolicy.getSellingPrice()));
-
 
341
 
336
 
342
		// Here bill is generated on behalf of GadgetCop
337
		// Here bill is generated on behalf of GadgetCop
343
		ThirdPartyInvoiceSequence damageProtectionProvider = thirdPartyInvoiceSequenceRepository
338
		ThirdPartyInvoiceSequence damageProtectionProvider = thirdPartyInvoiceSequenceRepository
344
				.selectByThirdParty(ThirdParty.GADGET_COP);
339
				.selectByThirdParty(ThirdParty.GADGET_COP);
345
		// Gadget Cop
340
		// Gadget Cop
Line 359... Line 354...
359
		providerAddress.setState(damageProtectionProvider.getState());
354
		providerAddress.setState(damageProtectionProvider.getState());
360
 
355
 
361
		customRetailer.setAddress(providerAddress);
356
		customRetailer.setAddress(providerAddress);
362
		pdfModel.setRetailer(customRetailer);
357
		pdfModel.setRetailer(customRetailer);
363
 
358
 
-
 
359
		// Place of supply: needed on the face of the invoice whenever the buyer is registered, and
-
 
360
		// it is what decides the CGST+SGST vs IGST split on the policy line.
-
 
361
		pdfModel.setPartnerAddressStateCode(stateCode(providerAddress.getState()));
-
 
362
		pdfModel.setCustomerAddressStateCode(stateCode(customAddress.getState()));
-
 
363
 
364
		List<CustomOrderItem> customerFofoOrderItems = new ArrayList<>();
364
		List<CustomOrderItem> customerFofoOrderItems = new ArrayList<>();
365
		pdfModel.setOrderItems(customerFofoOrderItems);
365
		pdfModel.setOrderItems(customerFofoOrderItems);
366
		pdfModel.setTncs(Arrays.asList("Please check out Policy Schedule for detailed terms and conditions."));
366
		pdfModel.setTncs(Arrays.asList("Please check out Policy Schedule for detailed terms and conditions."));
367
		return pdfModel;
367
		return pdfModel;
368
	}
368
	}