| Line 1000... |
Line 1000... |
| 1000 |
pdfModel.setTncs(tncs);
|
1000 |
pdfModel.setTncs(tncs);
|
| 1001 |
return pdfModel;
|
1001 |
return pdfModel;
|
| 1002 |
|
1002 |
|
| 1003 |
}
|
1003 |
}
|
| 1004 |
|
1004 |
|
| - |
|
1005 |
private PdfModel getInsuranceInvoicePdfModel(FofoOrder fofoOrder) throws ProfitMandiBusinessException {
|
| - |
|
1006 |
|
| - |
|
1007 |
List<PaymentOptionTransaction> paymentOptionTransactions = paymentOptionTransactionRepository
|
| - |
|
1008 |
.selectByReferenceIdAndType(fofoOrder.getId(), PaymentOptionReferenceType.INSURANCE);
|
| - |
|
1009 |
|
| - |
|
1010 |
List<CustomPaymentOption> paymentOptions = new ArrayList<>();
|
| - |
|
1011 |
|
| - |
|
1012 |
PdfModel pdfModel = new PdfModel();
|
| - |
|
1013 |
for (PaymentOptionTransaction paymentOptionTransaction : paymentOptionTransactions) {
|
| - |
|
1014 |
CustomPaymentOption cpi = new CustomPaymentOption();
|
| - |
|
1015 |
cpi.setAmount(paymentOptionTransaction.getAmount());
|
| - |
|
1016 |
cpi.setPaymentOption(
|
| - |
|
1017 |
paymentOptionRepository.selectById(paymentOptionTransaction.getPaymentOptionId()).getName());
|
| - |
|
1018 |
paymentOptions.add(cpi);
|
| - |
|
1019 |
}
|
| - |
|
1020 |
|
| - |
|
1021 |
pdfModel.setTitle("Retailer Invoice");
|
| - |
|
1022 |
|
| - |
|
1023 |
pdfModel.setPaymentOptions(paymentOptions);
|
| - |
|
1024 |
pdfModel.setAuther("SmartDukaan");
|
| - |
|
1025 |
pdfModel.setInvoiceDate(FormattingUtils.formatDate(fofoOrder.getCreateTimestamp()));
|
| - |
|
1026 |
|
| - |
|
1027 |
// insurance calculation
|
| - |
|
1028 |
List<InsurancePolicy> insurancePolicies = insurancePolicyRepository
|
| - |
|
1029 |
.selectByRetailerIdDeviceInvoiceNumber(fofoOrder.getFofoId(), fofoOrder.getInvoiceNumber());
|
| - |
|
1030 |
Set<CustomInsurancePolicy> customInsurancePolicies = new HashSet<>();
|
| - |
|
1031 |
final float totalInsuranceTaxRate = 18;
|
| - |
|
1032 |
for (InsurancePolicy insurancePolicy : insurancePolicies) {
|
| - |
|
1033 |
float taxableInsurancePrice = insurancePolicy.getSaleAmount() / (1 + totalInsuranceTaxRate / 100);
|
| - |
|
1034 |
CustomInsurancePolicy customInsurancePolicy = new CustomInsurancePolicy();
|
| - |
|
1035 |
customInsurancePolicy.setDescription("Damage Protection Plan for device IMEI #"
|
| - |
|
1036 |
+ insurancePolicy.getSerialNumber() + "\n Certificate No. " + insurancePolicy.getPolicyNumber());
|
| - |
|
1037 |
customInsurancePolicy.setHsnCode("998716");
|
| - |
|
1038 |
customInsurancePolicy.setRate(taxableInsurancePrice);
|
| - |
|
1039 |
customInsurancePolicy.setIgstRate(18);
|
| - |
|
1040 |
customInsurancePolicy.setIgstAmount(taxableInsurancePrice * 18 / 100);
|
| - |
|
1041 |
customInsurancePolicy.setCgstRate(9);
|
| - |
|
1042 |
customInsurancePolicy.setCgstAmount(taxableInsurancePrice * 9 / 100);
|
| - |
|
1043 |
customInsurancePolicy.setSgstRate(9);
|
| - |
|
1044 |
customInsurancePolicy.setSgstAmount(taxableInsurancePrice * 9 / 100);
|
| - |
|
1045 |
customInsurancePolicy.setNetAmount(insurancePolicy.getSaleAmount());
|
| - |
|
1046 |
customInsurancePolicies.add(customInsurancePolicy);
|
| - |
|
1047 |
}
|
| - |
|
1048 |
pdfModel.setInsurancePolicies(customInsurancePolicies);
|
| - |
|
1049 |
|
| - |
|
1050 |
pdfModel.setCustomer(getCustomCustomer(fofoOrder));
|
| - |
|
1051 |
pdfModel.setInvoiceNumber(fofoOrder.getInvoiceNumber());
|
| - |
|
1052 |
pdfModel.setTotalAmount(fofoOrder.getTotalAmount());
|
| - |
|
1053 |
|
| - |
|
1054 |
Retailer retailer = retailerRepository.selectById(fofoOrder.getFofoId());
|
| - |
|
1055 |
PrivateDealUser privateDealUser = null;
|
| - |
|
1056 |
try {
|
| - |
|
1057 |
privateDealUser = privateDealUserRepository.selectById(retailer.getId());
|
| - |
|
1058 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| - |
|
1059 |
LOGGER.error("Private Deal User not found : ", profitMandiBusinessException);
|
| - |
|
1060 |
}
|
| - |
|
1061 |
|
| - |
|
1062 |
User user = userRepository.selectById(userAccountRepository.selectUserIdByRetailerId(retailer.getId()));
|
| - |
|
1063 |
CustomRetailer customRetailer = new CustomRetailer();
|
| - |
|
1064 |
customRetailer.setBusinessName(retailer.getName());
|
| - |
|
1065 |
customRetailer.setMobileNumber(user.getMobileNumber());
|
| - |
|
1066 |
// customRetailer.setTinNumber(retailer.getNumber());
|
| - |
|
1067 |
if (privateDealUser == null) {
|
| - |
|
1068 |
customRetailer.setGstNumber(null);
|
| - |
|
1069 |
} else {
|
| - |
|
1070 |
if (null != privateDealUser.getCounterId()) {
|
| - |
|
1071 |
Counter counter = counterRepository.selectById(privateDealUser.getCounterId());
|
| - |
|
1072 |
customRetailer.setGstNumber(counter.getGstin());
|
| - |
|
1073 |
} else {
|
| - |
|
1074 |
customRetailer.setGstNumber(null);
|
| - |
|
1075 |
}
|
| - |
|
1076 |
}
|
| - |
|
1077 |
Address retailerAddress = addressRepository
|
| - |
|
1078 |
.selectById(retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailer.getId()));
|
| - |
|
1079 |
customRetailer.setAddress(this.createCustomAddress(retailerAddress));
|
| - |
|
1080 |
pdfModel.setRetailer(customRetailer);
|
| - |
|
1081 |
|
| - |
|
1082 |
Set<CustomOrderItem> customerFofoOrderItems = new HashSet<>();
|
| - |
|
1083 |
|
| - |
|
1084 |
pdfModel.setOrderItems(customerFofoOrderItems);
|
| - |
|
1085 |
String partnerAddressStateCode = stateRepository.selectByName(pdfModel.getRetailer().getAddress().getState())
|
| - |
|
1086 |
.getCode();
|
| - |
|
1087 |
String customerAddressStateCode = stateRepository.selectByName(pdfModel.getCustomer().getAddress().getState())
|
| - |
|
1088 |
.getCode();
|
| - |
|
1089 |
pdfModel.setPartnerAddressStateCode(partnerAddressStateCode);
|
| - |
|
1090 |
pdfModel.setCustomerAddressStateCode(customerAddressStateCode);
|
| - |
|
1091 |
pdfModel.setCancelled(fofoOrder.getCancelledTimestamp() != null);
|
| - |
|
1092 |
List<String> tncs = new ArrayList<>();
|
| - |
|
1093 |
tncs.add("I agree that goods received are in good working condition");
|
| - |
|
1094 |
tncs.add("Goods once sold cannot be exchanged or taken back");
|
| - |
|
1095 |
tncs.add("Warranty for the goods received by me is the responsibility of the manufacturer only.");
|
| - |
|
1096 |
tncs.add("Customer needs to activate the handset at the time of delivery to be eligible for the discount");
|
| - |
|
1097 |
tncs.add(
|
| - |
|
1098 |
"Tempered Glass Replacement will be done only for the Mobile Phone which was purchased from SmartDukaan");
|
| - |
|
1099 |
tncs.add(
|
| - |
|
1100 |
"Customers requesting Tempered Glass Replacement will have to bring the broken tempered glass, either pasted on the phone or along with the phone");
|
| - |
|
1101 |
tncs.add("Service fee of Rs.20 will be chargeable for each Tempered Glass Replacement");
|
| - |
|
1102 |
if (pdfModel.getInsurancePolicies() != null && pdfModel.getInsurancePolicies().size() > 0) {
|
| - |
|
1103 |
tncs.add("Damage protection provided is the responisibility of Protection Provider only");
|
| - |
|
1104 |
}
|
| - |
|
1105 |
pdfModel.setTncs(tncs);
|
| - |
|
1106 |
return pdfModel;
|
| - |
|
1107 |
|
| - |
|
1108 |
}
|
| - |
|
1109 |
|
| 1005 |
private CustomCustomer getCustomCustomer(FofoOrder fofoOrder) throws ProfitMandiBusinessException {
|
1110 |
private CustomCustomer getCustomCustomer(FofoOrder fofoOrder) throws ProfitMandiBusinessException {
|
| 1006 |
Customer customer = customerRepository.selectById(fofoOrder.getCustomerId());
|
1111 |
Customer customer = customerRepository.selectById(fofoOrder.getCustomerId());
|
| 1007 |
CustomCustomer customCustomer = new CustomCustomer();
|
1112 |
CustomCustomer customCustomer = new CustomCustomer();
|
| 1008 |
customCustomer.setFirstName(customer.getFirstName());
|
1113 |
customCustomer.setFirstName(customer.getFirstName());
|
| 1009 |
customCustomer.setLastName(customer.getLastName());
|
1114 |
customCustomer.setLastName(customer.getLastName());
|
| Line 1019... |
Line 1124... |
| 1019 |
public PdfModel getInvoicePdfModel(int fofoId, int orderId) throws ProfitMandiBusinessException {
|
1124 |
public PdfModel getInvoicePdfModel(int fofoId, int orderId) throws ProfitMandiBusinessException {
|
| 1020 |
FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndOrderId(fofoId, orderId);
|
1125 |
FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndOrderId(fofoId, orderId);
|
| 1021 |
return this.getInvoicePdfModel(fofoOrder);
|
1126 |
return this.getInvoicePdfModel(fofoOrder);
|
| 1022 |
}
|
1127 |
}
|
| 1023 |
|
1128 |
|
| - |
|
1129 |
@Override
|
| - |
|
1130 |
public PdfModel getInsuranceInvoicePdfModel(int fofoId, int orderId) throws ProfitMandiBusinessException {
|
| - |
|
1131 |
FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndOrderId(fofoId, orderId);
|
| - |
|
1132 |
return this.getInsuranceInvoicePdfModel(fofoOrder);
|
| - |
|
1133 |
}
|
| - |
|
1134 |
|
| 1024 |
public String getBillingAddress(CustomerAddress customerAddress) {
|
1135 |
public String getBillingAddress(CustomerAddress customerAddress) {
|
| 1025 |
StringBuilder address = new StringBuilder();
|
1136 |
StringBuilder address = new StringBuilder();
|
| 1026 |
if ((customerAddress.getLine1() != null) && (!customerAddress.getLine1().isEmpty())) {
|
1137 |
if ((customerAddress.getLine1() != null) && (!customerAddress.getLine1().isEmpty())) {
|
| 1027 |
address.append(customerAddress.getLine1());
|
1138 |
address.append(customerAddress.getLine1());
|
| 1028 |
address.append(", ");
|
1139 |
address.append(", ");
|
| Line 1211... |
Line 1322... |
| 1211 |
LOGGER.info("CustomFofoOrderItem -- {}", customFofoOrderItem);
|
1322 |
LOGGER.info("CustomFofoOrderItem -- {}", customFofoOrderItem);
|
| 1212 |
PriceModel priceModel = itemIdMopPriceMap.get(itemId);
|
1323 |
PriceModel priceModel = itemIdMopPriceMap.get(itemId);
|
| 1213 |
if (customFofoOrderItem.getSerialNumberDetails().stream()
|
1324 |
if (customFofoOrderItem.getSerialNumberDetails().stream()
|
| 1214 |
.filter(x -> org.apache.commons.lang.StringUtils.isNotEmpty(x.getSerialNumber()))
|
1325 |
.filter(x -> org.apache.commons.lang.StringUtils.isNotEmpty(x.getSerialNumber()))
|
| 1215 |
.collect(Collectors.toList()).size() > 0) {
|
1326 |
.collect(Collectors.toList()).size() > 0) {
|
| 1216 |
if (Utils.compareFloat(priceModel.getPrice(), customFofoOrderItem.getSellingPrice()
|
1327 |
if (Utils.compareFloat(priceModel.getPrice(),
|
| 1217 |
+ customFofoOrderItem.getDiscountAmount()) > 0) {
|
1328 |
customFofoOrderItem.getSellingPrice() + customFofoOrderItem.getDiscountAmount()) > 0) {
|
| 1218 |
throw new ProfitMandiBusinessException("Selling Price for ",
|
1329 |
throw new ProfitMandiBusinessException("Selling Price for ",
|
| 1219 |
itemRepository.selectById(itemId).getItemDescription(), "FFORDR_1010");
|
1330 |
itemRepository.selectById(itemId).getItemDescription(), "FFORDR_1010");
|
| 1220 |
}
|
1331 |
}
|
| 1221 |
} else {
|
1332 |
} else {
|
| 1222 |
if (priceModel.getPurchasePrice() > customFofoOrderItem.getSellingPrice()) {
|
1333 |
if (priceModel.getPurchasePrice() > customFofoOrderItem.getSellingPrice()) {
|
| Line 1821... |
Line 1932... |
| 1821 |
paymentTransaction.setFofoId(fofoOrder.getFofoId());
|
1932 |
paymentTransaction.setFofoId(fofoOrder.getFofoId());
|
| 1822 |
paymentTransaction.setReferenceId(fofoOrder.getId());
|
1933 |
paymentTransaction.setReferenceId(fofoOrder.getId());
|
| 1823 |
paymentTransaction.setReferenceType(PaymentOptionReferenceType.ORDER);
|
1934 |
paymentTransaction.setReferenceType(PaymentOptionReferenceType.ORDER);
|
| 1824 |
paymentTransaction.setPaymentOptionId(1);
|
1935 |
paymentTransaction.setPaymentOptionId(1);
|
| 1825 |
paymentOptionTransactionRepository.persist(paymentTransaction);
|
1936 |
paymentOptionTransactionRepository.persist(paymentTransaction);
|
| 1826 |
|
1937 |
|
| 1827 |
List<FofoOrderItem> fois = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
1938 |
List<FofoOrderItem> fois = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
| 1828 |
List<InventoryItem> inventoryItems = new ArrayList<>();
|
1939 |
List<InventoryItem> inventoryItems = new ArrayList<>();
|
| 1829 |
fois.stream().forEach(x -> {
|
1940 |
fois.stream().forEach(x -> {
|
| 1830 |
x.getFofoLineItems().stream().forEach(y -> {
|
1941 |
x.getFofoLineItems().stream().forEach(y -> {
|
| 1831 |
inventoryService.rollbackInventory(y.getInventoryItemId(), y.getQuantity(),
|
1942 |
inventoryService.rollbackInventory(y.getInventoryItemId(), y.getQuantity(),
|
| 1832 |
fofoOrder.getFofoId());
|
1943 |
fofoOrder.getFofoId());
|
| 1833 |
inventoryItems.add(inventoryItemRepository.selectById(y.getInventoryItemId()));
|
1944 |
inventoryItems.add(inventoryItemRepository.selectById(y.getInventoryItemId()));
|
| 1834 |
});
|
1945 |
});
|
| 1835 |
});
|
1946 |
});
|
| 1836 |
//if(invoice)
|
1947 |
// if(invoice)
|
| 1837 |
this.reverseScheme(fofoOrder);
|
1948 |
this.reverseScheme(fofoOrder);
|
| 1838 |
insuranceService.cancelInsurance(fofoOrder);
|
1949 |
insuranceService.cancelInsurance(fofoOrder);
|
| 1839 |
}
|
1950 |
}
|
| 1840 |
}
|
1951 |
}
|
| 1841 |
}
|
1952 |
}
|
| 1842 |
|
1953 |
|
| 1843 |
@Override
|
1954 |
@Override
|
| 1844 |
public void reverseScheme(FofoOrder fofoOrder) throws ProfitMandiBusinessException {
|
1955 |
public void reverseScheme(FofoOrder fofoOrder) throws ProfitMandiBusinessException {
|
| 1845 |
String reversalReason = "Order Rolledback/Cancelled/Returned for Invoice #" + fofoOrder.getInvoiceNumber();
|
1956 |
String reversalReason = "Order Rolledback/Cancelled/Returned for Invoice #" + fofoOrder.getInvoiceNumber();
|
| 1846 |
List<FofoOrderItem> fois = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
1957 |
List<FofoOrderItem> fois = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
| - |
|
1958 |
Set<Integer> inventoryItemIds = fois.stream()
|
| 1847 |
Set<Integer> inventoryItemIds = fois.stream().flatMap(x->x.getFofoLineItems().stream().map(y->y.getInventoryItemId())).collect(Collectors.toSet());
|
1959 |
.flatMap(x -> x.getFofoLineItems().stream().map(y -> y.getInventoryItemId()))
|
| - |
|
1960 |
.collect(Collectors.toSet());
|
| 1848 |
List<InventoryItem> inventoryItems = inventoryItemRepository.selectByIds(inventoryItemIds);
|
1961 |
List<InventoryItem> inventoryItems = inventoryItemRepository.selectByIds(inventoryItemIds);
|
| 1849 |
schemeService.reverseSchemes(inventoryItems, fofoOrder.getId(), reversalReason,
|
1962 |
schemeService.reverseSchemes(inventoryItems, fofoOrder.getId(), reversalReason, SchemeService.OUT_SCHEME_TYPES);
|
| 1850 |
SchemeService.OUT_SCHEME_TYPES);
|
- |
|
| 1851 |
schemeService.reverseSchemes(inventoryItems, fofoOrder.getId(), reversalReason,
|
1963 |
schemeService.reverseSchemes(inventoryItems, fofoOrder.getId(), reversalReason,
|
| 1852 |
Arrays.asList(SchemeType.INVESTMENT));
|
1964 |
Arrays.asList(SchemeType.INVESTMENT));
|
| 1853 |
schemeService.reverseSchemes(inventoryItems, fofoOrder.getId(), reversalReason,
|
1965 |
schemeService.reverseSchemes(inventoryItems, fofoOrder.getId(), reversalReason,
|
| 1854 |
Arrays.asList(SchemeType.ACTIVATION));
|
1966 |
Arrays.asList(SchemeType.ACTIVATION));
|
| 1855 |
|
1967 |
|
| 1856 |
}
|
1968 |
}
|
| 1857 |
|
1969 |
|
| 1858 |
@Override
|
1970 |
@Override
|
| 1859 |
public float getSales(int fofoId, LocalDateTime startDate, LocalDateTime endDate) {
|
1971 |
public float getSales(int fofoId, LocalDateTime startDate, LocalDateTime endDate) {
|
| 1860 |
Float sales = fofoOrderRepository.selectSaleSumGroupByFofoIds(startDate, endDate).get(fofoId);
|
1972 |
Float sales = fofoOrderRepository.selectSaleSumGroupByFofoIds(startDate, endDate).get(fofoId);
|