| Line 3... |
Line 3... |
| 3 |
|
3 |
|
| 4 |
import com.spice.profitmandi.common.enumuration.ItemType;
|
4 |
import com.spice.profitmandi.common.enumuration.ItemType;
|
| 5 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
5 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 6 |
import com.spice.profitmandi.common.util.ExcelUtils;
|
6 |
import com.spice.profitmandi.common.util.ExcelUtils;
|
| 7 |
import com.spice.profitmandi.common.util.Utils;
|
7 |
import com.spice.profitmandi.common.util.Utils;
|
| - |
|
8 |
import com.spice.profitmandi.dao.entity.catalog.BrandCatalog;
|
| - |
|
9 |
import com.spice.profitmandi.dao.entity.catalog.Catalog;
|
| 8 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
10 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
| - |
|
11 |
import com.spice.profitmandi.dao.entity.dtr.Brand;
|
| 9 |
import com.spice.profitmandi.dao.entity.inventory.VendorCatalogPricing;
|
12 |
import com.spice.profitmandi.dao.entity.inventory.VendorCatalogPricing;
|
| 10 |
import com.spice.profitmandi.dao.entity.inventory.VendorItemPricing;
|
13 |
import com.spice.profitmandi.dao.entity.inventory.VendorItemPricing;
|
| 11 |
import com.spice.profitmandi.dao.entity.warehouse.Supplier;
|
14 |
import com.spice.profitmandi.dao.entity.warehouse.Supplier;
|
| 12 |
import com.spice.profitmandi.dao.model.StateGstRateModel;
|
15 |
import com.spice.profitmandi.dao.model.StateGstRateModel;
|
| - |
|
16 |
import com.spice.profitmandi.dao.repository.catalog.BrandsRepository;
|
| - |
|
17 |
import com.spice.profitmandi.dao.repository.catalog.CatalogRepository;
|
| 13 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
18 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 14 |
import com.spice.profitmandi.dao.repository.catalog.StateGstRateRepository;
|
19 |
import com.spice.profitmandi.dao.repository.catalog.StateGstRateRepository;
|
| 15 |
import com.spice.profitmandi.dao.repository.inventory.VendorCatalogPricingRepository;
|
20 |
import com.spice.profitmandi.dao.repository.inventory.VendorCatalogPricingRepository;
|
| 16 |
import com.spice.profitmandi.dao.repository.inventory.VendorItemPricingRepository;
|
21 |
import com.spice.profitmandi.dao.repository.inventory.VendorItemPricingRepository;
|
| 17 |
import com.spice.profitmandi.dao.repository.warehouse.SupplierRepository;
|
22 |
import com.spice.profitmandi.dao.repository.warehouse.SupplierRepository;
|
| Line 36... |
Line 41... |
| 36 |
|
41 |
|
| 37 |
@Component
|
42 |
@Component
|
| 38 |
public class ItemLoaderService {
|
43 |
public class ItemLoaderService {
|
| 39 |
|
44 |
|
| 40 |
@Autowired
|
45 |
@Autowired
|
| - |
|
46 |
BrandsRepository brandsRepository;
|
| - |
|
47 |
|
| - |
|
48 |
@Autowired
|
| 41 |
ItemRepository itemRepository;
|
49 |
ItemRepository itemRepository;
|
| 42 |
|
50 |
|
| 43 |
@Autowired
|
51 |
@Autowired
|
| 44 |
VendorCatalogPricingRepository vendorCatalogPricingRepository;
|
52 |
VendorCatalogPricingRepository vendorCatalogPricingRepository;
|
| 45 |
|
53 |
|
| Line 82... |
Line 90... |
| 82 |
itemLoaderModel.setProductGroup(row.getCell(i++).getStringCellValue().trim());
|
90 |
itemLoaderModel.setProductGroup(row.getCell(i++).getStringCellValue().trim());
|
| 83 |
itemLoaderModel.setCategoryId((int) row.getCell(i++).getNumericCellValue());
|
91 |
itemLoaderModel.setCategoryId((int) row.getCell(i++).getNumericCellValue());
|
| 84 |
itemLoaderModel.setCategory(row.getCell(i++).getStringCellValue().trim());
|
92 |
itemLoaderModel.setCategory(row.getCell(i++).getStringCellValue().trim());
|
| 85 |
itemLoaderModel.setHsnCode(String.valueOf((int) row.getCell(i++).getNumericCellValue()));
|
93 |
itemLoaderModel.setHsnCode(String.valueOf((int) row.getCell(i++).getNumericCellValue()));
|
| 86 |
itemLoaderModel.setBrand(row.getCell(i++).getStringCellValue().trim());
|
94 |
itemLoaderModel.setBrand(row.getCell(i++).getStringCellValue().trim());
|
| - |
|
95 |
Cell modelNumberCell = row.getCell(i++);
|
| - |
|
96 |
if(modelNumberCell== null || modelNumberCell.getStringCellValue().trim().equals("")) {
|
| - |
|
97 |
throw new Exception("Model Number cant be null or empty");
|
| - |
|
98 |
} else {
|
| 87 |
itemLoaderModel.setModelNumber(row.getCell(i++).getStringCellValue().trim());
|
99 |
itemLoaderModel.setModelNumber(modelNumberCell.getStringCellValue().trim());
|
| - |
|
100 |
}
|
| 88 |
Cell modelCell = row.getCell(i++);
|
101 |
Cell modelNameCell = row.getCell(i++);
|
| 89 |
if (modelCell == null) {
|
102 |
if (modelNameCell == null) {
|
| 90 |
itemLoaderModel.setModelName("");
|
103 |
itemLoaderModel.setModelName("");
|
| 91 |
} else {
|
104 |
} else {
|
| 92 |
itemLoaderModel.setModelName(modelCell.getStringCellValue().trim());
|
105 |
itemLoaderModel.setModelName(modelNameCell.getStringCellValue().trim());
|
| 93 |
}
|
106 |
}
|
| 94 |
itemLoaderModel.setColor(row.getCell(i++).getStringCellValue().trim());
|
107 |
itemLoaderModel.setColor(row.getCell(i++).getStringCellValue().trim());
|
| 95 |
//MRP SP MOP DP TP NLC Startdate Preferred Vendor Risky
|
108 |
//MRP SP MOP DP TP NLC Startdate Preferred Vendor Risky
|
| 96 |
// Weight Item type(1 for Serialized and 2 for non-serialized) TaxRate
|
109 |
// Weight Item type(1 for Serialized and 2 for non-serialized) TaxRate
|
| 97 |
itemLoaderModel.setMrp(row.getCell(i++).getNumericCellValue());
|
110 |
itemLoaderModel.setMrp(row.getCell(i++).getNumericCellValue());
|
| Line 127... |
Line 140... |
| 127 |
|
140 |
|
| 128 |
}
|
141 |
}
|
| 129 |
|
142 |
|
| 130 |
|
143 |
|
| 131 |
|
144 |
|
| 132 |
//@Autowired
|
145 |
@Autowired
|
| - |
|
146 |
CatalogRepository catalogRepository;
|
| 133 |
|
147 |
|
| 134 |
private void addItem(ItemLoaderModel itemLoaderModel) throws ProfitMandiBusinessException {
|
148 |
private void addItem(ItemLoaderModel itemLoaderModel) throws ProfitMandiBusinessException {
|
| 135 |
this.validateItemLoaderModel(itemLoaderModel);
|
149 |
this.validateItemLoaderModel(itemLoaderModel);
|
| 136 |
List<Item> items = itemRepository.selectAll(itemLoaderModel.getBrand(), itemLoaderModel.getModelName(), itemLoaderModel.getModelNumber());
|
150 |
Catalog catalog = catalogRepository.selectCatalog(itemLoaderModel.getBrand(), itemLoaderModel.getModelNumber(), itemLoaderModel.getModelName());
|
| 137 |
int catalogId = 0;
|
151 |
if (catalog != null) {
|
| 138 |
if (items.size() > 0) {
|
- |
|
| 139 |
//Check if color already exist
|
152 |
List<Item> items = itemRepository.selectAllByCatalogItemId(catalog.getId());
|
| 140 |
long similarColorCount = items.stream().filter(x -> itemLoaderModel.getColor().equals(x.getColorNatural())).count();
|
153 |
long similarColorCount = items.stream().filter(x -> itemLoaderModel.getColor().equals(x.getColorNatural())).count();
|
| 141 |
if (similarColorCount > 0) {
|
154 |
if (similarColorCount > 0) {
|
| 142 |
throw new ProfitMandiBusinessException("Color alerady exist", "Pls check", itemLoaderModel.getColor());
|
155 |
throw new ProfitMandiBusinessException("Color alerady exist", "Pls check", itemLoaderModel.getColor());
|
| 143 |
}
|
156 |
}
|
| 144 |
|
157 |
|
| Line 156... |
Line 169... |
| 156 |
for (Map.Entry<String, Long> colorCountEntrySet : colorsCount.entrySet()) {
|
169 |
for (Map.Entry<String, Long> colorCountEntrySet : colorsCount.entrySet()) {
|
| 157 |
if (colorCountEntrySet.getValue() > 1) {
|
170 |
if (colorCountEntrySet.getValue() > 1) {
|
| 158 |
throw new ProfitMandiBusinessException("Model repeats the same color", "Pls check", colorCountEntrySet.getKey());
|
171 |
throw new ProfitMandiBusinessException("Model repeats the same color", "Pls check", colorCountEntrySet.getKey());
|
| 159 |
}
|
172 |
}
|
| 160 |
}
|
173 |
}
|
| 161 |
catalogId = items.get(0).getCatalogItemId();
|
- |
|
| 162 |
} else {
|
174 |
} else {
|
| - |
|
175 |
catalog = new Catalog();
|
| - |
|
176 |
BrandCatalog brand = brandsRepository.selectByBrand(itemLoaderModel.getBrand());
|
| - |
|
177 |
if(brand == null) {
|
| - |
|
178 |
throw new ProfitMandiBusinessException("Brand Does not exist", "Pls check", itemLoaderModel.getBrand());
|
| - |
|
179 |
}
|
| - |
|
180 |
catalog.setBrandId(brand.getId());
|
| - |
|
181 |
catalog.setBrand(itemLoaderModel.getBrand());
|
| - |
|
182 |
catalog.setModelName(itemLoaderModel.getModelName());
|
| - |
|
183 |
catalog.setModelNumber(itemLoaderModel.getModelNumber());
|
| - |
|
184 |
catalog.setCreated(LocalDateTime.now());
|
| - |
|
185 |
catalog.setCreatedBy("System");
|
| 163 |
catalogId = itemRepository.getNextEntity();
|
186 |
catalogRepository.persist(catalog);
|
| 164 |
}
|
187 |
}
|
| 165 |
//Finally either got valid existing model or new model altogether
|
188 |
//Finally either got valid existing model or new model altogether
|
| 166 |
Item item = new Item();
|
189 |
Item item = new Item();
|
| 167 |
item.setBrand(itemLoaderModel.getBrand());
|
190 |
item.setBrand(itemLoaderModel.getBrand());
|
| 168 |
item.setModelName(itemLoaderModel.getModelName());
|
191 |
item.setModelName(itemLoaderModel.getModelName());
|
| Line 172... |
Line 195... |
| 172 |
item.setMrp(new Float(Math.round(itemLoaderModel.getMrp())));
|
195 |
item.setMrp(new Float(Math.round(itemLoaderModel.getMrp())));
|
| 173 |
item.setStartDate(itemLoaderModel.getStartDate());
|
196 |
item.setStartDate(itemLoaderModel.getStartDate());
|
| 174 |
item.setCategoryId(itemLoaderModel.getCategoryId());
|
197 |
item.setCategoryId(itemLoaderModel.getCategoryId());
|
| 175 |
item.setPreferredVendor(itemLoaderModel.getPreferredVendor());
|
198 |
item.setPreferredVendor(itemLoaderModel.getPreferredVendor());
|
| 176 |
item.setRisky(itemLoaderModel.isRisky());
|
199 |
item.setRisky(itemLoaderModel.isRisky());
|
| 177 |
item.setCatalogItemId(catalogId);
|
200 |
item.setCatalogItemId(catalog.getId());
|
| 178 |
if (itemLoaderModel.getWeight() <= 0) {
|
201 |
if (itemLoaderModel.getWeight() <= 0) {
|
| 179 |
throw new ProfitMandiBusinessException("Weight", "0", "Weight should be greater than 0");
|
202 |
throw new ProfitMandiBusinessException("Weight", "0", "Weight should be greater than 0");
|
| 180 |
}
|
203 |
}
|
| 181 |
item.setWeight(itemLoaderModel.getWeight());
|
204 |
item.setWeight(itemLoaderModel.getWeight());
|
| 182 |
item.setStatus(status.PARTIALLY_ACTIVE);
|
205 |
item.setStatus(status.PARTIALLY_ACTIVE);
|