First commit (wating to add alerts in budget)
This commit is contained in:
@@ -671,21 +671,22 @@ public class AccountingCutOffServiceImpl implements AccountingCutOffService {
|
||||
.all()
|
||||
.filter("self.product = ?1 and self.company = ?2", line.getProduct(), company)
|
||||
.fetchOne();
|
||||
if(stockMove.getToStockLocation().getTypeSelect() == StockLocationRepository.TYPE_EXTERNAL){
|
||||
Account stockAccount = null ;
|
||||
if(line.getProduct().getFamilleProduit().getId() == 67L || line.getProduct().getFamilleProduit().getId() == 68L){
|
||||
stockAccount = Beans.get(AccountRepository.class).find(595L);
|
||||
|
||||
}else if(line.getProduct().getFamilleProduit().getId() == 59L){
|
||||
stockAccount = Beans.get(AccountRepository.class).find(3518L);
|
||||
}else{
|
||||
stockAccount = Beans.get(AccountRepository.class).find(4113L);
|
||||
if (stockMove.getToStockLocation().getTypeSelect() == StockLocationRepository.TYPE_EXTERNAL) {
|
||||
Account stockAccount = null;
|
||||
if (line.getProduct().getFamilleProduit().getId() == 67L
|
||||
|| line.getProduct().getFamilleProduit().getId() == 68L) {
|
||||
stockAccount = Beans.get(AccountRepository.class).find(595L);
|
||||
|
||||
} else if (line.getProduct().getFamilleProduit().getId() == 59L) {
|
||||
stockAccount = Beans.get(AccountRepository.class).find(3518L);
|
||||
} else {
|
||||
stockAccount = Beans.get(AccountRepository.class).find(4113L);
|
||||
}
|
||||
accountMap.put("stockAccount", stockAccount);
|
||||
}else{
|
||||
} else {
|
||||
accountMap.put("stockAccount", accountManagement.getStockAccount());
|
||||
}
|
||||
|
||||
|
||||
accountMap.put("purchaseAccount", accountManagement.getPurchaseAccount());
|
||||
accountMap.put("consumptionAccount", accountManagement.getConsumptionAccount());
|
||||
stockAccounts.put(line, accountMap);
|
||||
@@ -727,45 +728,43 @@ public class AccountingCutOffServiceImpl implements AccountingCutOffService {
|
||||
description += "-" + line.getTrackingNumber().getTrackingNumberSeq();
|
||||
}
|
||||
|
||||
if(line.getRealQty().compareTo(BigDecimal.ZERO) > 0 ){
|
||||
|
||||
MoveLine moveLine =
|
||||
moveLineService.createMoveLine(
|
||||
move,
|
||||
partner,
|
||||
acc,
|
||||
amountInCurrency,
|
||||
isDebit(stockMove),
|
||||
moveDate,
|
||||
++counter,
|
||||
stockMove.getStockMoveSeq(),
|
||||
description);
|
||||
moveLine.setDate(moveDate);
|
||||
moveLine.setDueDate(moveDate);
|
||||
moveLine.setAccountId(acc.getId());
|
||||
moveLine.setAccountCode(acc.getCode());
|
||||
|
||||
MoveLine moveLine2 =
|
||||
moveLineService.createMoveLine(
|
||||
move,
|
||||
partner,
|
||||
acc2,
|
||||
amountInCurrency,
|
||||
!isDebit(stockMove),
|
||||
moveDate,
|
||||
++counter,
|
||||
stockMove.getStockMoveSeq(),
|
||||
description);
|
||||
moveLine2.setDate(moveDate);
|
||||
moveLine2.setDueDate(moveDate);
|
||||
moveLine2.setAccountId(acc2.getId());
|
||||
moveLine2.setAccountCode(acc2.getCode());
|
||||
|
||||
if (line.getRealQty().compareTo(BigDecimal.ZERO) > 0) {
|
||||
|
||||
move.addMoveLineListItem(moveLine);
|
||||
move.addMoveLineListItem(moveLine2);
|
||||
MoveLine moveLine =
|
||||
moveLineService.createMoveLine(
|
||||
move,
|
||||
partner,
|
||||
acc,
|
||||
amountInCurrency,
|
||||
isDebit(stockMove),
|
||||
moveDate,
|
||||
++counter,
|
||||
stockMove.getStockMoveSeq(),
|
||||
description);
|
||||
moveLine.setDate(moveDate);
|
||||
moveLine.setDueDate(moveDate);
|
||||
moveLine.setAccountId(acc.getId());
|
||||
moveLine.setAccountCode(acc.getCode());
|
||||
|
||||
MoveLine moveLine2 =
|
||||
moveLineService.createMoveLine(
|
||||
move,
|
||||
partner,
|
||||
acc2,
|
||||
amountInCurrency,
|
||||
!isDebit(stockMove),
|
||||
moveDate,
|
||||
++counter,
|
||||
stockMove.getStockMoveSeq(),
|
||||
description);
|
||||
moveLine2.setDate(moveDate);
|
||||
moveLine2.setDueDate(moveDate);
|
||||
moveLine2.setAccountId(acc2.getId());
|
||||
moveLine2.setAccountCode(acc2.getCode());
|
||||
|
||||
move.addMoveLineListItem(moveLine);
|
||||
move.addMoveLineListItem(moveLine2);
|
||||
}
|
||||
|
||||
}
|
||||
stockMove.setIsVentilated(true);
|
||||
move.setIgnoreInAccountingOk(false);
|
||||
@@ -783,7 +782,7 @@ public class AccountingCutOffServiceImpl implements AccountingCutOffService {
|
||||
Move move = this.generateStockAccountMove(stockMove);
|
||||
movesId.add(move.getId());
|
||||
}
|
||||
;
|
||||
;
|
||||
return movesId;
|
||||
}
|
||||
|
||||
@@ -807,7 +806,7 @@ public class AccountingCutOffServiceImpl implements AccountingCutOffService {
|
||||
Journal journal;
|
||||
// stockMove.getToStockLocation().getTypeSelect() == StockLocationRepository.TYPE_VIRTUAL
|
||||
if (stockMove.getTypeSelect() == StockMoveRepository.TYPE_INCOMING) {
|
||||
journal = Beans.get(JournalRepository.class).find(10L);
|
||||
journal = Beans.get(JournalRepository.class).find(10L);
|
||||
} else if (stockMove.getTypeSelect() == StockMoveRepository.TYPE_OUTGOING) {
|
||||
journal = Beans.get(JournalRepository.class).find(30L);
|
||||
} else
|
||||
@@ -835,44 +834,44 @@ public class AccountingCutOffServiceImpl implements AccountingCutOffService {
|
||||
return isDebit;
|
||||
}
|
||||
|
||||
|
||||
public Boolean isGapPositive(InventoryLine line){
|
||||
if(line.getGap().compareTo(BigDecimal.ZERO) > 0){
|
||||
public Boolean isGapPositive(InventoryLine line) {
|
||||
if (line.getGap().compareTo(BigDecimal.ZERO) > 0) {
|
||||
return true;
|
||||
}else{
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional(rollbackOn = {Exception.class})
|
||||
public Move generateInventoryLineMove(InventoryLine inventoryLine) throws AxelorException {
|
||||
|
||||
|
||||
Map<InventoryLine, Map<String, Account>> stockAccounts = new HashMap<>();
|
||||
Company company = inventoryLine.getInventory().getCompany();
|
||||
Currency currency = inventoryLine.getInventory().getCompany().getCurrency();
|
||||
Partner partner = inventoryLine.getInventory().getCompany().getPartner();
|
||||
LocalDate moveDate = inventoryLine.getInventory().getPlannedEndDateT().toLocalDate();
|
||||
Journal journal = Beans.get(JournalRepository.class).find(10L);
|
||||
|
||||
|
||||
Map<String, Account> accountMap = new HashMap<String, Account>();
|
||||
AccountManagement accountManagement =
|
||||
Beans.get(AccountManagementRepository.class)
|
||||
.all()
|
||||
.filter("self.product = ?1 and self.company = ?2", inventoryLine.getProduct(), company)
|
||||
.fetchOne();
|
||||
|
||||
if(accountManagement.getStockAccount() == null || accountManagement.getConsumptionAccount() == null){
|
||||
throw new AxelorException(
|
||||
AccountManagement accountManagement =
|
||||
Beans.get(AccountManagementRepository.class)
|
||||
.all()
|
||||
.filter("self.product = ?1 and self.company = ?2", inventoryLine.getProduct(), company)
|
||||
.fetchOne();
|
||||
|
||||
if (accountManagement.getStockAccount() == null
|
||||
|| accountManagement.getConsumptionAccount() == null) {
|
||||
throw new AxelorException(
|
||||
inventoryLine,
|
||||
TraceBackRepository.CATEGORY_MISSING_FIELD,
|
||||
I18n.get(IExceptionMessage.VENTILATE_STATE_6),
|
||||
inventoryLine.getProduct().getFullName());
|
||||
}
|
||||
}
|
||||
|
||||
accountMap.put("stockAccount", accountManagement.getStockAccount());
|
||||
accountMap.put("consumptionAccount", accountManagement.getConsumptionAccount());
|
||||
accountMap.put("stockAccount", accountManagement.getStockAccount());
|
||||
accountMap.put("consumptionAccount", accountManagement.getConsumptionAccount());
|
||||
|
||||
stockAccounts.put(inventoryLine, accountMap);
|
||||
stockAccounts.put(inventoryLine, accountMap);
|
||||
|
||||
Move move =
|
||||
moveCreateService.createMove(
|
||||
@@ -885,87 +884,81 @@ public class AccountingCutOffServiceImpl implements AccountingCutOffService {
|
||||
MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC);
|
||||
|
||||
int counter = 0;
|
||||
|
||||
|
||||
Account acc = stockAccounts.get(inventoryLine).get("consumptionAccount");
|
||||
Account acc2 = stockAccounts.get(inventoryLine).get("stockAccount");
|
||||
Account acc = stockAccounts.get(inventoryLine).get("consumptionAccount");
|
||||
Account acc2 = stockAccounts.get(inventoryLine).get("stockAccount");
|
||||
|
||||
if(inventoryLine.getJustifiedGap()){
|
||||
if(isGapPositive(inventoryLine)){
|
||||
acc = stockAccounts.get(inventoryLine).get("consumptionAccount");
|
||||
acc2 = stockAccounts.get(inventoryLine).get("stockAccount");
|
||||
}else if(!isGapPositive(inventoryLine)){
|
||||
acc = stockAccounts.get(inventoryLine).get("stockAccount");
|
||||
acc2 = stockAccounts.get(inventoryLine).get("consumptionAccount");
|
||||
}
|
||||
}else{
|
||||
if(isGapPositive(inventoryLine)){
|
||||
acc = Beans.get(AccountRepository.class).find(1360L);
|
||||
acc2 = stockAccounts.get(inventoryLine).get("stockAccount");
|
||||
}else if(!isGapPositive(inventoryLine)){
|
||||
acc = stockAccounts.get(inventoryLine).get("stockAccount");
|
||||
acc2 = Beans.get(AccountRepository.class).find(1400L);
|
||||
}
|
||||
if (inventoryLine.getJustifiedGap()) {
|
||||
if (isGapPositive(inventoryLine)) {
|
||||
acc = stockAccounts.get(inventoryLine).get("consumptionAccount");
|
||||
acc2 = stockAccounts.get(inventoryLine).get("stockAccount");
|
||||
} else if (!isGapPositive(inventoryLine)) {
|
||||
acc = stockAccounts.get(inventoryLine).get("stockAccount");
|
||||
acc2 = stockAccounts.get(inventoryLine).get("consumptionAccount");
|
||||
}
|
||||
|
||||
|
||||
|
||||
BigDecimal amountInCurrency = inventoryLine.getGapValue().multiply(inventoryLine.getGap());
|
||||
String description = inventoryLine.getInventory().getInventorySeq() + "-" + inventoryLine.getProduct().getCode();
|
||||
if (inventoryLine.getTrackingNumber() != null) {
|
||||
description += "-" + inventoryLine.getTrackingNumber().getTrackingNumberSeq();
|
||||
} else {
|
||||
if (isGapPositive(inventoryLine)) {
|
||||
acc = Beans.get(AccountRepository.class).find(1360L);
|
||||
acc2 = stockAccounts.get(inventoryLine).get("stockAccount");
|
||||
} else if (!isGapPositive(inventoryLine)) {
|
||||
acc = stockAccounts.get(inventoryLine).get("stockAccount");
|
||||
acc2 = Beans.get(AccountRepository.class).find(1400L);
|
||||
}
|
||||
}
|
||||
|
||||
MoveLine moveLine =
|
||||
moveLineService.createMoveLine(
|
||||
move,
|
||||
partner,
|
||||
acc,
|
||||
amountInCurrency,
|
||||
isDebitInventoryLine(inventoryLine),
|
||||
moveDate,
|
||||
++counter,
|
||||
inventoryLine.getInventory().getInventorySeq(),
|
||||
description);
|
||||
moveLine.setDescription(description);
|
||||
moveLine.setDate(moveDate);
|
||||
moveLine.setDueDate(moveDate);
|
||||
moveLine.setAccountId(acc.getId());
|
||||
moveLine.setAccountCode(acc.getCode());
|
||||
moveLine.setAccountName(acc.getName());
|
||||
BigDecimal amountInCurrency = inventoryLine.getGapValue().multiply(inventoryLine.getGap());
|
||||
String description =
|
||||
inventoryLine.getInventory().getInventorySeq() + "-" + inventoryLine.getProduct().getCode();
|
||||
if (inventoryLine.getTrackingNumber() != null) {
|
||||
description += "-" + inventoryLine.getTrackingNumber().getTrackingNumberSeq();
|
||||
}
|
||||
|
||||
MoveLine moveLine2 =
|
||||
moveLineService.createMoveLine(
|
||||
move,
|
||||
partner,
|
||||
acc2,
|
||||
amountInCurrency,
|
||||
!isDebitInventoryLine(inventoryLine),
|
||||
moveDate,
|
||||
++counter,
|
||||
inventoryLine.getInventory().getInventorySeq(),
|
||||
description);
|
||||
moveLine2.setDescription(description);
|
||||
moveLine2.setDate(moveDate);
|
||||
moveLine2.setDueDate(moveDate);
|
||||
moveLine2.setAccountId(acc2.getId());
|
||||
moveLine2.setAccountCode(acc2.getCode());
|
||||
moveLine2.setAccountName(acc2.getName());
|
||||
MoveLine moveLine =
|
||||
moveLineService.createMoveLine(
|
||||
move,
|
||||
partner,
|
||||
acc,
|
||||
amountInCurrency,
|
||||
isDebitInventoryLine(inventoryLine),
|
||||
moveDate,
|
||||
++counter,
|
||||
inventoryLine.getInventory().getInventorySeq(),
|
||||
description);
|
||||
moveLine.setDescription(description);
|
||||
moveLine.setDate(moveDate);
|
||||
moveLine.setDueDate(moveDate);
|
||||
moveLine.setAccountId(acc.getId());
|
||||
moveLine.setAccountCode(acc.getCode());
|
||||
moveLine.setAccountName(acc.getName());
|
||||
|
||||
MoveLine moveLine2 =
|
||||
moveLineService.createMoveLine(
|
||||
move,
|
||||
partner,
|
||||
acc2,
|
||||
amountInCurrency,
|
||||
!isDebitInventoryLine(inventoryLine),
|
||||
moveDate,
|
||||
++counter,
|
||||
inventoryLine.getInventory().getInventorySeq(),
|
||||
description);
|
||||
moveLine2.setDescription(description);
|
||||
moveLine2.setDate(moveDate);
|
||||
moveLine2.setDueDate(moveDate);
|
||||
moveLine2.setAccountId(acc2.getId());
|
||||
moveLine2.setAccountCode(acc2.getCode());
|
||||
moveLine2.setAccountName(acc2.getName());
|
||||
|
||||
move.addMoveLineListItem(moveLine);
|
||||
move.addMoveLineListItem(moveLine2);
|
||||
move.setInventoryLine(inventoryLine);
|
||||
inventoryLine.setIsVentilated(true);
|
||||
|
||||
move.addMoveLineListItem(moveLine);
|
||||
move.addMoveLineListItem(moveLine2);
|
||||
move.setInventoryLine(inventoryLine);
|
||||
inventoryLine.setIsVentilated(true);
|
||||
|
||||
move.setIgnoreInAccountingOk(false);
|
||||
move.setStatusSelect(MoveRepository.STATUS_DAYBOOK);
|
||||
return move;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public List<Long> massGenerationInventoryLineMove(List<Long> ids) throws AxelorException {
|
||||
|
||||
List<Long> movesId = new ArrayList<>();
|
||||
@@ -978,8 +971,6 @@ public class AccountingCutOffServiceImpl implements AccountingCutOffService {
|
||||
return movesId;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// public boolean isPurchase(StockMove stockMove){
|
||||
// boolean isPurchase;
|
||||
// Partner partner = stockMove.getPartner() ;
|
||||
|
||||
@@ -181,12 +181,12 @@ public class BudgetSupplychainService extends BudgetService {
|
||||
|
||||
boolean idbudgetDistExist = true;
|
||||
for (PurchaseOrderLine line : purchaseOrderLineList) {
|
||||
if(line.getBudgetDistributionList() == null){
|
||||
idbudgetDistExist = false;
|
||||
if (line.getBudgetDistributionList() == null) {
|
||||
idbudgetDistExist = false;
|
||||
}
|
||||
}
|
||||
|
||||
if(idbudgetDistExist){
|
||||
if (idbudgetDistExist) {
|
||||
purchaseOrderLineList
|
||||
.stream()
|
||||
.flatMap(x -> x.getBudgetDistributionList().stream())
|
||||
@@ -196,6 +196,6 @@ public class BudgetSupplychainService extends BudgetService {
|
||||
updateLines(budget);
|
||||
computeTotalAmountCommitted(budget);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,34 @@
|
||||
package com.axelor.apps.supplychain.service;
|
||||
|
||||
import com.axelor.apps.account.db.Account;
|
||||
import com.axelor.apps.account.db.Invoice;
|
||||
import com.axelor.apps.account.db.InvoiceLine;
|
||||
import com.axelor.apps.account.db.InvoiceTemplate;
|
||||
import com.axelor.apps.account.db.TaxLine;
|
||||
import com.axelor.apps.account.db.repo.AccountRepository;
|
||||
import com.axelor.apps.account.db.repo.InvoiceLineRepository;
|
||||
import com.axelor.apps.account.db.repo.InvoiceRepository;
|
||||
import com.axelor.apps.account.db.repo.TaxLineRepository;
|
||||
import com.axelor.apps.account.service.InvoiceTemplateService;
|
||||
import com.axelor.apps.account.service.invoice.generator.InvoiceLineGenerator;
|
||||
import com.axelor.apps.base.db.Product;
|
||||
import com.axelor.apps.base.db.repo.ProductRepository;
|
||||
import com.axelor.apps.purchase.db.ImportationFolder;
|
||||
import com.axelor.apps.purchase.db.repo.ImportationFolderRepository;
|
||||
import com.axelor.apps.stock.db.ImportationFolderCostPrice;
|
||||
import com.axelor.apps.stock.db.StockLocation;
|
||||
import com.axelor.apps.stock.db.StockMove;
|
||||
import com.axelor.apps.stock.db.StockMoveLine;
|
||||
import com.axelor.apps.stock.db.repo.ImportationFolderCostPriceRepository;
|
||||
import com.axelor.apps.stock.db.repo.StockMoveLineRepository;
|
||||
import com.axelor.apps.supplychain.service.invoice.generator.InvoiceLineGeneratorSupplyChain;
|
||||
import com.axelor.auth.AuthUtils;
|
||||
import com.axelor.exception.AxelorException;
|
||||
import com.axelor.exception.db.repo.TraceBackRepository;
|
||||
import com.axelor.i18n.I18n;
|
||||
import com.axelor.inject.Beans;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.persist.Transactional;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
@@ -14,71 +43,23 @@ import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.axelor.apps.account.db.Account;
|
||||
import com.axelor.apps.account.db.Invoice;
|
||||
import com.axelor.apps.account.db.InvoiceLine;
|
||||
import com.axelor.apps.account.db.InvoiceTemplate;
|
||||
import com.axelor.apps.account.db.PaymentVoucher;
|
||||
import com.axelor.apps.account.db.TaxLine;
|
||||
import com.axelor.apps.account.db.repo.AccountRepository;
|
||||
import com.axelor.apps.account.db.repo.InvoiceLineRepository;
|
||||
import com.axelor.apps.account.db.repo.InvoiceRepository;
|
||||
import com.axelor.apps.account.db.repo.PaymentVoucherRepository;
|
||||
import com.axelor.apps.account.db.repo.TaxLineRepository;
|
||||
import com.axelor.apps.account.service.InvoiceTemplateService;
|
||||
import com.axelor.apps.account.service.invoice.InvoiceLineServiceImpl;
|
||||
import com.axelor.apps.account.service.invoice.InvoiceServiceImpl;
|
||||
import com.axelor.apps.account.service.invoice.generator.InvoiceLineGenerator;
|
||||
import com.axelor.apps.account.service.payment.paymentvoucher.PaymentVoucherConfirmService;
|
||||
import com.axelor.apps.base.db.Product;
|
||||
import com.axelor.apps.base.db.Wizard;
|
||||
import com.axelor.apps.base.db.repo.ProductRepository;
|
||||
import com.axelor.apps.purchase.db.ImportationFolder;
|
||||
import com.axelor.apps.purchase.db.PurchaseOrder;
|
||||
import com.axelor.apps.stock.db.ImportationFolderCostPrice;
|
||||
import com.axelor.apps.stock.db.StockLocation;
|
||||
import com.axelor.apps.purchase.db.PurchaseOrderLine;
|
||||
import com.axelor.apps.stock.db.repo.ImportationFolderCostPriceRepository;
|
||||
import com.axelor.apps.purchase.db.repo.ImportationFolderRepository;
|
||||
import com.axelor.apps.purchase.db.repo.PurchaseOrderLineRepository;
|
||||
import com.axelor.apps.purchase.service.PurchaseOrderLineService;
|
||||
import com.axelor.apps.purchase.service.PurchaseOrderService;
|
||||
import com.axelor.apps.stock.db.StockMove;
|
||||
import com.axelor.apps.stock.db.StockMoveLine;
|
||||
import com.axelor.apps.stock.db.repo.StockMoveLineRepository;
|
||||
import com.axelor.apps.supplychain.service.invoice.generator.InvoiceLineGeneratorSupplyChain;
|
||||
import com.axelor.auth.AuthUtils;
|
||||
import com.axelor.exception.AxelorException;
|
||||
import com.axelor.exception.db.repo.TraceBackRepository;
|
||||
import com.axelor.exception.service.TraceBackService;
|
||||
import com.axelor.i18n.I18n;
|
||||
import com.axelor.inject.Beans;
|
||||
import com.axelor.meta.schema.actions.ActionView;
|
||||
import com.axelor.meta.schema.actions.ActionView.ActionViewBuilder;
|
||||
import com.axelor.rpc.ActionRequest;
|
||||
import com.axelor.rpc.ActionResponse;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.persist.Transactional;
|
||||
|
||||
import wslite.json.JSONException;
|
||||
|
||||
public class ImportationFolderServiceImpl {
|
||||
|
||||
@Inject protected ImportationFolderRepository importationFolderRepository;
|
||||
private final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
|
||||
@Inject protected ImportationFolderRepository importationFolderRepository;
|
||||
private final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
|
||||
|
||||
|
||||
@Transactional
|
||||
public List<Long> calculateAvgPriceAndGenerateInvoice(List<StockMoveLine> stockMoveLines, ImportationFolder importationFolder)
|
||||
public List<Long> calculateAvgPriceAndGenerateInvoice(
|
||||
List<StockMoveLine> stockMoveLines, ImportationFolder importationFolder)
|
||||
throws MalformedURLException, JSONException, AxelorException {
|
||||
|
||||
|
||||
Set<StockMove> stockMovesSet = new HashSet<>();
|
||||
HashMap<String,List<StockMove>> stockMovesMap = new HashMap<>();
|
||||
|
||||
HashMap<String, List<StockMove>> stockMovesMap = new HashMap<>();
|
||||
|
||||
for (StockMoveLine stockMoveLine : stockMoveLines) {
|
||||
stockMovesSet.add(stockMoveLine.getStockMove());
|
||||
}
|
||||
@@ -92,349 +73,541 @@ public class ImportationFolderServiceImpl {
|
||||
.add(stockMove);
|
||||
}
|
||||
|
||||
stockMovesMap.forEach((ref, stockMoveList) -> {
|
||||
stockMovesMap.forEach(
|
||||
(ref, stockMoveList) -> {
|
||||
// List<StockMove> stockMoveList = new ArrayList<>(stockMovesSet);
|
||||
if (stockMoveList.size() > 0) {
|
||||
|
||||
// List<StockMove> stockMoveList = new ArrayList<>(stockMovesSet);
|
||||
if(stockMoveList.size() > 0) {
|
||||
Optional<Invoice> invoiceOpt;
|
||||
try {
|
||||
invoiceOpt =
|
||||
Beans.get(StockMoveMultiInvoiceService.class)
|
||||
.createInvoiceFromMultiIncomingStockMove(stockMoveList);
|
||||
|
||||
Optional<Invoice> invoiceOpt;
|
||||
try {
|
||||
invoiceOpt = Beans.get(StockMoveMultiInvoiceService.class).createInvoiceFromMultiIncomingStockMove(stockMoveList);
|
||||
|
||||
Invoice invoice = invoiceOpt.get();
|
||||
Product product = Beans.get(ProductRepository.class).find(8931L);
|
||||
BigDecimal freightPrice = importationFolder.getFreight();
|
||||
StockLocation stockLocation = importationFolder.getStockMoveLineList().get(0).getStockMove().getToStockLocation();
|
||||
TaxLine taxLine = null;
|
||||
if(stockLocation.getId() == 61 || stockLocation.getId() == 60){
|
||||
taxLine = Beans.get(TaxLineRepository.class).find(27L);
|
||||
}else{
|
||||
if(importationFolder.getStockMoveLineList().get(0).getPurchaseOrderLine() == null){
|
||||
throw new AxelorException(
|
||||
importationFolder,
|
||||
TraceBackRepository.CATEGORY_CONFIGURATION_ERROR,
|
||||
"Purchase order missing",
|
||||
I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION));
|
||||
}
|
||||
|
||||
taxLine = importationFolder.getStockMoveLineList().get(0).getPurchaseOrderLine().getTaxLine();
|
||||
}
|
||||
|
||||
|
||||
InvoiceLineGenerator invoiceLineGenerator =
|
||||
new InvoiceLineGeneratorSupplyChain(
|
||||
invoice,
|
||||
product,
|
||||
product.getName(),
|
||||
freightPrice,
|
||||
freightPrice,
|
||||
freightPrice,
|
||||
"",
|
||||
BigDecimal.ONE,
|
||||
product.getUnit(),
|
||||
taxLine,
|
||||
100,
|
||||
BigDecimal.ZERO,
|
||||
0,
|
||||
freightPrice,
|
||||
freightPrice,
|
||||
false,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
null) {
|
||||
@Override
|
||||
public List<InvoiceLine> creates() throws AxelorException {
|
||||
|
||||
InvoiceLine invoiceLine = this.createInvoiceLine();
|
||||
invoiceLine.setPrice(stockMoveList.get(0).getStockMoveLineList().get(0).getFreight());
|
||||
Long categoryId = importationFolder.getStockMoveLineList().get(0).getProduct().getFamilleProduit().getId();
|
||||
Account account = null;
|
||||
switch (categoryId.intValue()) {
|
||||
case 67:
|
||||
account= Beans.get(AccountRepository.class).find(1430L);
|
||||
break;
|
||||
case 68:
|
||||
account= Beans.get(AccountRepository.class).find(1430L);
|
||||
break;
|
||||
case 59:
|
||||
account= Beans.get(AccountRepository.class).find(1431L);
|
||||
break;
|
||||
default:
|
||||
account= Beans.get(AccountRepository.class).find(1431L);
|
||||
break;
|
||||
Invoice invoice = invoiceOpt.get();
|
||||
Product product = Beans.get(ProductRepository.class).find(8931L);
|
||||
// BigDecimal freightPrice = importationFolder.getFreight();
|
||||
|
||||
BigDecimal freightPrice =
|
||||
stockMoveLines
|
||||
.stream()
|
||||
.filter(line -> line.getStockMove() == stockMovesMap.get(ref).get(0))
|
||||
.findFirst()
|
||||
.get()
|
||||
.getFreight()
|
||||
.setScale(2);
|
||||
StockLocation stockLocation =
|
||||
importationFolder
|
||||
.getStockMoveLineList()
|
||||
.get(0)
|
||||
.getStockMove()
|
||||
.getToStockLocation();
|
||||
TaxLine taxLine = null;
|
||||
if (stockLocation.getId() == 86) {
|
||||
// if (stockLocation.getId() == 61 || stockLocation.getId() == 60) {
|
||||
taxLine = Beans.get(TaxLineRepository.class).find(27L);
|
||||
} else {
|
||||
if (importationFolder.getStockMoveLineList().get(0).getPurchaseOrderLine()
|
||||
== null) {
|
||||
throw new AxelorException(
|
||||
importationFolder,
|
||||
TraceBackRepository.CATEGORY_CONFIGURATION_ERROR,
|
||||
"Purchase order missing",
|
||||
I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION));
|
||||
}
|
||||
|
||||
taxLine =
|
||||
importationFolder
|
||||
.getStockMoveLineList()
|
||||
.get(0)
|
||||
.getPurchaseOrderLine()
|
||||
.getTaxLine();
|
||||
}
|
||||
|
||||
InvoiceLineGenerator invoiceLineGenerator =
|
||||
new InvoiceLineGeneratorSupplyChain(
|
||||
invoice,
|
||||
product,
|
||||
product.getName(),
|
||||
freightPrice,
|
||||
freightPrice,
|
||||
freightPrice,
|
||||
"",
|
||||
BigDecimal.ONE,
|
||||
product.getUnit(),
|
||||
taxLine,
|
||||
100,
|
||||
BigDecimal.ZERO,
|
||||
0,
|
||||
freightPrice,
|
||||
freightPrice,
|
||||
false,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
null) {
|
||||
@Override
|
||||
public List<InvoiceLine> creates() throws AxelorException {
|
||||
|
||||
InvoiceLine invoiceLine = this.createInvoiceLine();
|
||||
invoiceLine.setPrice(freightPrice);
|
||||
invoiceLine.setPriceDiscounted(freightPrice);
|
||||
Long categoryId =
|
||||
importationFolder
|
||||
.getStockMoveLineList()
|
||||
.get(0)
|
||||
.getProduct()
|
||||
.getFamilleProduit()
|
||||
.getId();
|
||||
Account account = null;
|
||||
switch (categoryId.intValue()) {
|
||||
case 67:
|
||||
account = Beans.get(AccountRepository.class).find(1430L);
|
||||
break;
|
||||
case 68:
|
||||
account = Beans.get(AccountRepository.class).find(1430L);
|
||||
break;
|
||||
case 59:
|
||||
account = Beans.get(AccountRepository.class).find(1431L);
|
||||
break;
|
||||
default:
|
||||
account = Beans.get(AccountRepository.class).find(1431L);
|
||||
break;
|
||||
}
|
||||
invoiceLine.setAccount(account);
|
||||
List<InvoiceLine> invoiceLines = new ArrayList<InvoiceLine>();
|
||||
invoiceLines.add(invoiceLine);
|
||||
|
||||
return invoiceLines;
|
||||
}
|
||||
};
|
||||
|
||||
List<InvoiceLine> invoiceLines = invoiceLineGenerator.creates();
|
||||
invoice.addInvoiceLineListItem(invoiceLines.get(0));
|
||||
|
||||
logger.debug(
|
||||
"invoice.getInvoiceLineList() ********** ", invoice.getInvoiceLineList());
|
||||
|
||||
BigDecimal inTaxTotal = BigDecimal.ZERO;
|
||||
BigDecimal exTaxTotal = BigDecimal.ZERO;
|
||||
BigDecimal taxTotal = BigDecimal.ZERO;
|
||||
|
||||
for (InvoiceLine invoiceLine : invoice.getInvoiceLineList()) {
|
||||
BigDecimal currencyRate = BigDecimal.ZERO;
|
||||
// if(invoiceLine.getProduct().getId() == product.getId()){
|
||||
currencyRate = importationFolder.getStockMoveLineList().get(0).getCurrencyRate();
|
||||
// }else{
|
||||
// currencyRate = invoiceLine.getStockMoveLine().getCurrencyRate();
|
||||
// }
|
||||
|
||||
inTaxTotal =
|
||||
inTaxTotal.add(
|
||||
invoiceLine
|
||||
.getInTaxTotal()
|
||||
.multiply(currencyRate)
|
||||
.setScale(2, RoundingMode.HALF_UP));
|
||||
exTaxTotal =
|
||||
exTaxTotal.add(
|
||||
invoiceLine
|
||||
.getExTaxTotal()
|
||||
.multiply(currencyRate)
|
||||
.setScale(2, RoundingMode.HALF_UP));
|
||||
taxTotal = taxTotal.add(inTaxTotal.subtract(exTaxTotal));
|
||||
|
||||
BigDecimal price =
|
||||
(invoiceLine.getPrice().multiply(currencyRate))
|
||||
.setScale(2, RoundingMode.HALF_UP);
|
||||
|
||||
invoiceLine.setPrice(price);
|
||||
invoiceLine.setPriceDiscounted(
|
||||
invoiceLine
|
||||
.getPriceDiscounted()
|
||||
.multiply(currencyRate)
|
||||
.setScale(2, RoundingMode.HALF_UP));
|
||||
invoiceLine.setInTaxTotal(
|
||||
invoiceLine
|
||||
.getInTaxTotal()
|
||||
.multiply(currencyRate)
|
||||
.setScale(2, RoundingMode.HALF_UP));
|
||||
invoiceLine.setExTaxTotal(
|
||||
invoiceLine
|
||||
.getExTaxTotal()
|
||||
.multiply(currencyRate)
|
||||
.setScale(2, RoundingMode.HALF_UP));
|
||||
invoiceLine.setInTaxPrice(
|
||||
invoiceLine
|
||||
.getInTaxPrice()
|
||||
.multiply(currencyRate)
|
||||
.setScale(2, RoundingMode.HALF_UP));
|
||||
invoiceLine.setCompanyExTaxTotal(
|
||||
invoiceLine
|
||||
.getCompanyExTaxTotal()
|
||||
.multiply(currencyRate)
|
||||
.setScale(2, RoundingMode.HALF_UP));
|
||||
invoiceLine.setCompanyInTaxTotal(
|
||||
invoiceLine
|
||||
.getCompanyInTaxTotal()
|
||||
.multiply(currencyRate)
|
||||
.setScale(2, RoundingMode.HALF_UP));
|
||||
|
||||
Beans.get(InvoiceLineRepository.class).save(invoiceLine);
|
||||
|
||||
logger.debug("currencyRate****** {}", currencyRate);
|
||||
logger.debug("Invoice line in importation folder {}", invoiceLine.toString());
|
||||
}
|
||||
|
||||
invoice.setInTaxTotal(inTaxTotal);
|
||||
invoice.setExTaxTotal(exTaxTotal);
|
||||
invoice.setCompanyExTaxTotal(exTaxTotal);
|
||||
invoice.setCompanyInTaxTotal(inTaxTotal);
|
||||
invoice.setAmountRemaining(inTaxTotal);
|
||||
invoice.setCurrency(invoice.getCompany().getCurrency());
|
||||
invoice.setTaxTotal(taxTotal);
|
||||
invoice.setImportationFolder(importationFolder);
|
||||
invoice.setIsImportationPartnerInvoice(true);
|
||||
|
||||
importationFolder.setInvoicedFolder(true);
|
||||
|
||||
Invoice generatedInvoice = Beans.get(InvoiceRepository.class).save(invoice);
|
||||
invoiceIds.add(generatedInvoice.getId());
|
||||
} catch (AxelorException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
invoiceLine.setAccount(account);
|
||||
List<InvoiceLine> invoiceLines = new ArrayList<InvoiceLine>();
|
||||
invoiceLines.add(invoiceLine);
|
||||
|
||||
return invoiceLines;
|
||||
}
|
||||
};
|
||||
|
||||
List<InvoiceLine> invoiceLines = invoiceLineGenerator.creates();
|
||||
invoice.addInvoiceLineListItem(invoiceLines.get(0));
|
||||
|
||||
logger.debug("invoice.getInvoiceLineList() ********** ",invoice.getInvoiceLineList());
|
||||
|
||||
BigDecimal inTaxTotal = BigDecimal.ZERO;
|
||||
BigDecimal exTaxTotal = BigDecimal.ZERO;
|
||||
BigDecimal taxTotal = BigDecimal.ZERO;
|
||||
|
||||
for (InvoiceLine invoiceLine : invoice.getInvoiceLineList()) {
|
||||
BigDecimal currencyRate = BigDecimal.ZERO;
|
||||
// if(invoiceLine.getProduct().getId() == product.getId()){
|
||||
currencyRate = importationFolder.getStockMoveLineList().get(0).getCurrencyRate();
|
||||
// }else{
|
||||
// currencyRate = invoiceLine.getStockMoveLine().getCurrencyRate();
|
||||
// }
|
||||
|
||||
inTaxTotal = inTaxTotal.add(invoiceLine.getInTaxTotal().multiply(currencyRate).setScale(2,RoundingMode.HALF_UP));
|
||||
exTaxTotal = exTaxTotal.add(invoiceLine.getExTaxTotal().multiply(currencyRate).setScale(2,RoundingMode.HALF_UP));
|
||||
taxTotal = taxTotal.add(inTaxTotal.subtract(exTaxTotal));
|
||||
|
||||
BigDecimal price = (invoiceLine.getPrice().multiply(currencyRate)).setScale(2,RoundingMode.HALF_UP);
|
||||
|
||||
invoiceLine.setPrice(price);
|
||||
invoiceLine.setPriceDiscounted(invoiceLine.getPriceDiscounted().multiply(currencyRate).setScale(2,RoundingMode.HALF_UP));
|
||||
invoiceLine.setInTaxTotal(invoiceLine.getInTaxTotal().multiply(currencyRate).setScale(2,RoundingMode.HALF_UP));
|
||||
invoiceLine.setExTaxTotal(invoiceLine.getExTaxTotal().multiply(currencyRate).setScale(2,RoundingMode.HALF_UP));
|
||||
invoiceLine.setInTaxPrice(invoiceLine.getInTaxPrice().multiply(currencyRate).setScale(2,RoundingMode.HALF_UP));
|
||||
invoiceLine.setCompanyExTaxTotal(invoiceLine.getCompanyExTaxTotal().multiply(currencyRate).setScale(2,RoundingMode.HALF_UP));
|
||||
invoiceLine.setCompanyInTaxTotal(invoiceLine.getCompanyInTaxTotal().multiply(currencyRate).setScale(2,RoundingMode.HALF_UP));
|
||||
|
||||
Beans.get(InvoiceLineRepository.class).save(invoiceLine);
|
||||
|
||||
logger.debug("currencyRate****** {}",currencyRate);
|
||||
logger.debug("Invoice line in importation folder {}",invoiceLine.toString());
|
||||
|
||||
}
|
||||
|
||||
invoice.setInTaxTotal(inTaxTotal);
|
||||
invoice.setExTaxTotal(exTaxTotal);
|
||||
invoice.setCompanyExTaxTotal(exTaxTotal);
|
||||
invoice.setCompanyInTaxTotal(inTaxTotal);
|
||||
invoice.setAmountRemaining(inTaxTotal);
|
||||
invoice.setCurrency(invoice.getCompany().getCurrency());
|
||||
invoice.setTaxTotal(taxTotal);
|
||||
invoice.setImportationFolder(importationFolder);
|
||||
invoice.setIsImportationPartnerInvoice(true);
|
||||
|
||||
importationFolder.setInvoicedFolder(true);
|
||||
|
||||
Invoice generatedInvoice = Beans.get(InvoiceRepository.class).save(invoice);
|
||||
invoiceIds.add(generatedInvoice.getId());
|
||||
} catch (AxelorException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
return invoiceIds;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public String computeCostPrice(ImportationFolder importationFolder) {
|
||||
|
||||
List<StockMoveLine> stockMoveLines = importationFolder.getStockMoveLineList();
|
||||
String message = "";
|
||||
BigDecimal costPrice = BigDecimal.ZERO;
|
||||
Set<Product> productSet = new HashSet<>();
|
||||
|
||||
// int scale = Beans.get(AppBaseService.class).getNbDecimalDigitForUnitPrice();
|
||||
int scale = 20;
|
||||
|
||||
for (StockMoveLine line : stockMoveLines) {
|
||||
productSet.add(line.getProduct());
|
||||
productSet.add(line.getProduct());
|
||||
}
|
||||
|
||||
|
||||
|
||||
this.resetCostPriceList(importationFolder);
|
||||
|
||||
if(productSet.size() > 1) {
|
||||
List<Invoice> supplierInvoices = importationFolder.getInvoices().stream().filter(t -> t.getIsImportationPartnerInvoice()).collect(Collectors.toList());
|
||||
// BigDecimal totalQty = stockMoveLines.stream().map(StockMoveLine::getRealQty).reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
BigDecimal totalNetMass = stockMoveLines.stream().map(StockMoveLine::getNetMass).reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
BigDecimal totalVolume = stockMoveLines.stream().map(StockMoveLine::getVolume).reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
BigDecimal freight = importationFolder.getFreight().multiply(stockMoveLines.get(0).getCurrencyRate()).setScale(2,RoundingMode.HALF_EVEN);
|
||||
|
||||
Map<Product,Double> splitting = new HashMap<>();
|
||||
Map<Product,Double> splittingQty = new HashMap<>();
|
||||
if (productSet.size() > 1) {
|
||||
List<Invoice> supplierInvoices =
|
||||
importationFolder
|
||||
.getInvoices()
|
||||
.stream()
|
||||
.filter(t -> t.getIsImportationPartnerInvoice())
|
||||
.collect(Collectors.toList());
|
||||
// BigDecimal totalQty =
|
||||
// stockMoveLines.stream().map(StockMoveLine::getRealQty).reduce(BigDecimal.ZERO,
|
||||
// BigDecimal::add);
|
||||
BigDecimal totalNetMass =
|
||||
stockMoveLines
|
||||
.stream()
|
||||
.map(StockMoveLine::getNetMass)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
BigDecimal totalVolume =
|
||||
stockMoveLines
|
||||
.stream()
|
||||
.map(StockMoveLine::getVolume)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
|
||||
BigDecimal freight = BigDecimal.ZERO;
|
||||
|
||||
Set<StockMove> stockMovesSet = new HashSet<>();
|
||||
HashMap<String, List<StockMove>> stockMovesMap = new HashMap<>();
|
||||
|
||||
for (StockMoveLine stockMoveLine : stockMoveLines) {
|
||||
stockMovesSet.add(stockMoveLine.getStockMove());
|
||||
}
|
||||
|
||||
for (StockMove stockMove : stockMovesSet) {
|
||||
stockMovesMap
|
||||
.computeIfAbsent(stockMove.getSupplierShipmentRef(), k -> new ArrayList<>())
|
||||
.add(stockMove);
|
||||
}
|
||||
|
||||
freight =
|
||||
new BigDecimal(
|
||||
stockMovesMap
|
||||
.values()
|
||||
.stream()
|
||||
.filter(t ->
|
||||
t.get(0)
|
||||
.getStockMoveLineList()
|
||||
.stream()
|
||||
.filter(line -> line.getRealQty() != null && line.getRealQty().compareTo(BigDecimal.ZERO) > 0)
|
||||
.findFirst()
|
||||
.isPresent())
|
||||
.mapToDouble(t ->
|
||||
t.get(0)
|
||||
.getStockMoveLineList()
|
||||
.stream()
|
||||
.filter(line -> line.getRealQty() != null && line.getRealQty().compareTo(BigDecimal.ZERO) > 0)
|
||||
.findFirst()
|
||||
.map(line -> line.getFreight()
|
||||
.multiply(stockMoveLines.get(0).getCurrencyRate())
|
||||
.setScale(2, RoundingMode.HALF_EVEN)
|
||||
.doubleValue())
|
||||
.orElse(0.0)) // In case no valid line found, fallback to 0.0
|
||||
.sum());
|
||||
|
||||
|
||||
System.out.println("*****************freight**************************************");
|
||||
System.out.println(freight);
|
||||
System.out.println("*******************************************************");
|
||||
|
||||
Map<Product, Double> splitting = new HashMap<>();
|
||||
Map<Product, Double> splittingQty = new HashMap<>();
|
||||
List<InvoiceLine> invoiceLines = new ArrayList<>();
|
||||
BigDecimal totalInvoiceWithoutFreight = BigDecimal.ZERO;
|
||||
BigDecimal totalQty = BigDecimal.ZERO;
|
||||
|
||||
|
||||
for (Invoice supplierInvoice : supplierInvoices) {
|
||||
BigDecimal freightInvoice = BigDecimal.ZERO;
|
||||
Optional<InvoiceLine> invoiceLine = supplierInvoice.getInvoiceLineList().stream().filter(t -> t.getProduct().getId() == 8931L).findAny();
|
||||
if(invoiceLine.isPresent()){
|
||||
freightInvoice = invoiceLine.get().getInTaxTotal();
|
||||
}
|
||||
BigDecimal invoiceWithoutFreight = supplierInvoice.getInTaxTotal().subtract(freightInvoice).setScale(2, RoundingMode.HALF_EVEN);
|
||||
totalInvoiceWithoutFreight = totalInvoiceWithoutFreight.add(invoiceWithoutFreight);
|
||||
invoiceLines.addAll(supplierInvoice.getInvoiceLineList());
|
||||
// total qty without freight qty = 1
|
||||
Optional<InvoiceLine> invoiceLine =
|
||||
supplierInvoice
|
||||
.getInvoiceLineList()
|
||||
.stream()
|
||||
.filter(t -> t.getProduct().getId() == 8931L)
|
||||
.findAny();
|
||||
if (invoiceLine.isPresent()) {
|
||||
freightInvoice = invoiceLine.get().getInTaxTotal();
|
||||
}
|
||||
BigDecimal invoiceWithoutFreight =
|
||||
supplierInvoice
|
||||
.getInTaxTotal()
|
||||
.subtract(freightInvoice)
|
||||
.setScale(2, RoundingMode.HALF_EVEN);
|
||||
totalInvoiceWithoutFreight = totalInvoiceWithoutFreight.add(invoiceWithoutFreight);
|
||||
invoiceLines.addAll(supplierInvoice.getInvoiceLineList());
|
||||
// total qty without freight qty = 1
|
||||
}
|
||||
totalQty =invoiceLines.stream().filter(t -> t.getProduct().getId() != 8931L).map(InvoiceLine::getQty).reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
splittingQty = invoiceLines.stream().collect(
|
||||
Collectors.groupingBy(
|
||||
t -> t.getProduct(),
|
||||
Collectors.summingDouble(o -> o.getQty().doubleValue())));
|
||||
|
||||
if(importationFolder.getValorisation() == 1){
|
||||
splitting = invoiceLines.stream().collect(
|
||||
Collectors.groupingBy(
|
||||
t -> t.getProduct(),
|
||||
Collectors.summingDouble(o -> o.getInTaxTotal().doubleValue())));
|
||||
}else if(importationFolder.getValorisation() == 2){
|
||||
splitting = invoiceLines.stream().collect(
|
||||
Collectors.groupingBy(
|
||||
t -> t.getProduct(),
|
||||
Collectors.summingDouble(o -> o.getQty().doubleValue())));
|
||||
}else if(importationFolder.getValorisation() == 3){
|
||||
splitting = stockMoveLines.stream().collect(
|
||||
Collectors.groupingBy(
|
||||
t -> t.getProduct(),
|
||||
Collectors.summingDouble(o -> o.getNetMass().doubleValue())));
|
||||
totalQty =
|
||||
invoiceLines
|
||||
.stream()
|
||||
.filter(t -> t.getProduct().getId() != 8931L)
|
||||
.map(InvoiceLine::getQty)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
splittingQty =
|
||||
invoiceLines
|
||||
.stream()
|
||||
.collect(
|
||||
Collectors.groupingBy(
|
||||
t -> t.getProduct(),
|
||||
Collectors.summingDouble(o -> o.getQty().doubleValue())));
|
||||
|
||||
}else if(importationFolder.getValorisation() == 4){
|
||||
splitting = stockMoveLines.stream().collect(
|
||||
Collectors.groupingBy(
|
||||
t -> t.getProduct(),
|
||||
Collectors.summingDouble(o -> o.getVolume().doubleValue())));
|
||||
}
|
||||
|
||||
List<Invoice> invoices = importationFolder.getInvoices().stream().filter(t -> !t.getIsImportationPartnerInvoice()).collect(Collectors.toList());
|
||||
BigDecimal totalApproachs = invoices.stream().map(Invoice::getInTaxTotal).reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
|
||||
|
||||
for (Product product : productSet) {
|
||||
Stream<InvoiceLine> invoiceLineStream = invoiceLines.stream().filter(t -> t.getProduct() == product);
|
||||
|
||||
BigDecimal productQty = new BigDecimal(splitting.get(product));
|
||||
BigDecimal productQty2 = new BigDecimal(splittingQty.get(product));
|
||||
BigDecimal freightSplit = BigDecimal.ZERO;
|
||||
// BigDecimal freightPerInvoiceForProduct= invoiceLineStream.findFirst().get().getInvoice().getInvoiceLineList().stream().filter(t -> t.getProduct().getId() == 8931L).findFirst().get().getInTaxTotal();
|
||||
|
||||
// total per product
|
||||
BigDecimal totalInvoiceProduct = invoiceLineStream.map(InvoiceLine::getInTaxTotal).reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
if (importationFolder.getValorisation() == 1) {
|
||||
splitting =
|
||||
invoiceLines
|
||||
.stream()
|
||||
.collect(
|
||||
Collectors.groupingBy(
|
||||
t -> t.getProduct(),
|
||||
Collectors.summingDouble(o -> o.getInTaxTotal().doubleValue())));
|
||||
} else if (importationFolder.getValorisation() == 2) {
|
||||
splitting =
|
||||
invoiceLines
|
||||
.stream()
|
||||
.collect(
|
||||
Collectors.groupingBy(
|
||||
t -> t.getProduct(),
|
||||
Collectors.summingDouble(o -> o.getQty().doubleValue())));
|
||||
} else if (importationFolder.getValorisation() == 3) {
|
||||
splitting =
|
||||
stockMoveLines
|
||||
.stream()
|
||||
.collect(
|
||||
Collectors.groupingBy(
|
||||
t -> t.getProduct(),
|
||||
Collectors.summingDouble(o -> o.getNetMass().doubleValue())));
|
||||
|
||||
BigDecimal percent = BigDecimal.ZERO;
|
||||
} else if (importationFolder.getValorisation() == 4) {
|
||||
splitting =
|
||||
stockMoveLines
|
||||
.stream()
|
||||
.collect(
|
||||
Collectors.groupingBy(
|
||||
t -> t.getProduct(),
|
||||
Collectors.summingDouble(o -> o.getVolume().doubleValue())));
|
||||
}
|
||||
|
||||
if(totalInvoiceWithoutFreight.compareTo(BigDecimal.ZERO) == 0){
|
||||
percent = productQty.divide(totalQty,10,RoundingMode.HALF_EVEN);
|
||||
}else{
|
||||
switch (importationFolder.getValorisation()) {
|
||||
case 1:
|
||||
percent = totalInvoiceProduct.divide(totalInvoiceWithoutFreight,10,RoundingMode.HALF_EVEN);
|
||||
break;
|
||||
case 2:
|
||||
percent = productQty.divide(totalQty,2,RoundingMode.HALF_EVEN);
|
||||
break;
|
||||
case 3:
|
||||
percent = productQty.divide(totalNetMass,2,RoundingMode.HALF_EVEN);
|
||||
break;
|
||||
case 4:
|
||||
percent = productQty.divide(totalVolume,2,RoundingMode.HALF_EVEN);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
List<Invoice> invoices =
|
||||
importationFolder
|
||||
.getInvoices()
|
||||
.stream()
|
||||
.filter(t -> !t.getIsImportationPartnerInvoice())
|
||||
.collect(Collectors.toList());
|
||||
BigDecimal totalApproachs =
|
||||
invoices.stream().map(Invoice::getInTaxTotal).reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
|
||||
for (Product product : productSet) {
|
||||
Stream<InvoiceLine> invoiceLineStream =
|
||||
invoiceLines.stream().filter(t -> t.getProduct() == product);
|
||||
|
||||
BigDecimal productQty = new BigDecimal(splitting.get(product));
|
||||
BigDecimal productQty2 = new BigDecimal(splittingQty.get(product));
|
||||
BigDecimal freightSplit = BigDecimal.ZERO;
|
||||
// BigDecimal freightPerInvoiceForProduct=
|
||||
// invoiceLineStream.findFirst().get().getInvoice().getInvoiceLineList().stream().filter(t
|
||||
// -> t.getProduct().getId() == 8931L).findFirst().get().getInTaxTotal();
|
||||
|
||||
// total per product
|
||||
BigDecimal totalInvoiceProduct =
|
||||
invoiceLineStream
|
||||
.map(InvoiceLine::getInTaxTotal)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
|
||||
BigDecimal percent = BigDecimal.ZERO;
|
||||
|
||||
if (totalInvoiceWithoutFreight.compareTo(BigDecimal.ZERO) == 0) {
|
||||
percent = productQty.divide(totalQty, scale, RoundingMode.HALF_EVEN);
|
||||
} else {
|
||||
switch (importationFolder.getValorisation()) {
|
||||
case 1:
|
||||
percent =
|
||||
totalInvoiceProduct.divide(
|
||||
totalInvoiceWithoutFreight, scale, RoundingMode.HALF_EVEN);
|
||||
break;
|
||||
case 2:
|
||||
percent = productQty.divide(totalQty, scale, RoundingMode.HALF_EVEN);
|
||||
break;
|
||||
case 3:
|
||||
percent = productQty.divide(totalNetMass, scale, RoundingMode.HALF_EVEN);
|
||||
break;
|
||||
case 4:
|
||||
percent = productQty.divide(totalVolume, scale, RoundingMode.HALF_EVEN);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
freightSplit = freight.multiply(percent).setScale(2, RoundingMode.HALF_EVEN);
|
||||
|
||||
BigDecimal totalApproachsPerProduct = totalApproachs.multiply(percent).setScale(2, RoundingMode.HALF_EVEN);
|
||||
|
||||
BigDecimal allPerProduct = totalApproachsPerProduct.add(totalInvoiceProduct).add(freightSplit);
|
||||
|
||||
System.out.println("---------------------------------------------------------------------");
|
||||
System.out.println("allPerProduct *************"+allPerProduct.toString());
|
||||
System.out.println("totalApproachsPerProduct *************"+totalApproachsPerProduct.toString());
|
||||
System.out.println("totalInvoiceProduct *************"+totalInvoiceProduct.toString());
|
||||
System.out.println("freightSplit *************"+freightSplit.toString());
|
||||
System.out.println("productQty2 *************"+productQty2.toString());
|
||||
System.out.println("---------------------------------------------------------------------");
|
||||
|
||||
costPrice = allPerProduct.divide(productQty2,10, RoundingMode.HALF_EVEN);
|
||||
|
||||
message += "Cost price of " + product.getName() + " is " + costPrice + " || ";
|
||||
|
||||
List<StockMoveLine> lines = stockMoveLines.stream().filter(t -> t.getProduct() == product).collect(Collectors.toList());
|
||||
for (StockMoveLine line : lines) {
|
||||
this.computeCostPriceAndPersist(importationFolder, line, freightSplit,percent, totalInvoiceProduct,totalInvoiceProduct,costPrice);
|
||||
}
|
||||
|
||||
}
|
||||
}else{
|
||||
|
||||
List<Invoice> invoices = importationFolder.getInvoices();
|
||||
BigDecimal inTaxTotal = invoices.stream().map(Invoice::getInTaxTotal).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2,RoundingMode.HALF_UP);
|
||||
BigDecimal totalQty = stockMoveLines.stream().map(StockMoveLine::getRealQty).reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
freightSplit = freight.multiply(percent).setScale(scale, RoundingMode.HALF_EVEN);
|
||||
|
||||
BigDecimal totalApproachsPerProduct =
|
||||
totalApproachs.multiply(percent).setScale(scale, RoundingMode.HALF_EVEN);
|
||||
|
||||
BigDecimal allPerProduct =
|
||||
totalApproachsPerProduct.add(totalInvoiceProduct).add(freightSplit);
|
||||
|
||||
costPrice = allPerProduct.divide(productQty2, scale, RoundingMode.HALF_EVEN);
|
||||
|
||||
message += "Cost price of " + product.getName() + " is " + costPrice + " || ";
|
||||
|
||||
List<StockMoveLine> lines =
|
||||
stockMoveLines
|
||||
.stream()
|
||||
.filter(t -> t.getProduct() == product)
|
||||
.collect(Collectors.toList());
|
||||
for (StockMoveLine line : lines) {
|
||||
this.computeCostPriceAndPersist(
|
||||
importationFolder,
|
||||
line,
|
||||
freightSplit,
|
||||
percent,
|
||||
totalApproachsPerProduct,
|
||||
totalInvoiceProduct,
|
||||
costPrice);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
List<Invoice> invoices = importationFolder.getInvoices();
|
||||
BigDecimal percent = BigDecimal.ZERO;
|
||||
BigDecimal inTaxTotal =
|
||||
invoices
|
||||
.stream()
|
||||
.map(Invoice::getInTaxTotal)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add)
|
||||
.setScale(scale, RoundingMode.HALF_UP);
|
||||
BigDecimal totalQty =
|
||||
stockMoveLines
|
||||
.stream()
|
||||
.map(StockMoveLine::getRealQty)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
|
||||
costPrice = inTaxTotal.divide(totalQty, scale, RoundingMode.HALF_UP);
|
||||
|
||||
costPrice = inTaxTotal.divide(totalQty,10, RoundingMode.HALF_UP);
|
||||
|
||||
// this.resetCostPriceList(importationFolder);
|
||||
|
||||
for (StockMoveLine stockMoveLine : stockMoveLines) {
|
||||
this.computeCostPriceAndPersist(importationFolder, stockMoveLine,null,null,null,null, costPrice);
|
||||
this.computeCostPriceAndPersist(
|
||||
importationFolder,
|
||||
stockMoveLine,
|
||||
BigDecimal.ZERO,
|
||||
BigDecimal.ONE,
|
||||
BigDecimal.ZERO,
|
||||
BigDecimal.ZERO,
|
||||
costPrice);
|
||||
}
|
||||
|
||||
message = "CostPrice is : " + costPrice.toString();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
|
||||
@Transactional
|
||||
public void setStockMoveLineCurrenyRate(List<StockMoveLine> stockMoveLineList, BigDecimal currencyRate) {
|
||||
for (StockMoveLine stockMoveLine : stockMoveLineList) {
|
||||
stockMoveLine.setCurrencyRate(currencyRate);
|
||||
Beans.get(StockMoveLineRepository.class).save(stockMoveLine);
|
||||
}
|
||||
public void setStockMoveLineCurrenyRate(
|
||||
List<StockMoveLine> stockMoveLineList, BigDecimal currencyRate) {
|
||||
for (StockMoveLine stockMoveLine : stockMoveLineList) {
|
||||
stockMoveLine.setCurrencyRate(currencyRate);
|
||||
Beans.get(StockMoveLineRepository.class).save(stockMoveLine);
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void setStockMoveLineFreight(List<StockMoveLine> stockMoveLineList, BigDecimal freight) {
|
||||
for (StockMoveLine stockMoveLine : stockMoveLineList) {
|
||||
stockMoveLine.setFreight(freight);
|
||||
Beans.get(StockMoveLineRepository.class).save(stockMoveLine);
|
||||
}
|
||||
for (StockMoveLine stockMoveLine : stockMoveLineList) {
|
||||
stockMoveLine.setFreight(freight);
|
||||
Beans.get(StockMoveLineRepository.class).save(stockMoveLine);
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void resetCostPriceList(ImportationFolder importationFolder){
|
||||
public void resetCostPriceList(ImportationFolder importationFolder) {
|
||||
importationFolder.getImportationFolderCostPriceList().clear();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void computeCostPriceAndPersist(ImportationFolder importationFolder,StockMoveLine stockMoveLine,BigDecimal freightSplit,BigDecimal precent,BigDecimal totalApproachsPerProduct,BigDecimal totalInvoiceProduct,BigDecimal costPrice) {
|
||||
public void computeCostPriceAndPersist(
|
||||
ImportationFolder importationFolder,
|
||||
StockMoveLine stockMoveLine,
|
||||
BigDecimal freightSplit,
|
||||
BigDecimal precent,
|
||||
BigDecimal totalApproachsPerProduct,
|
||||
BigDecimal totalInvoiceProduct,
|
||||
BigDecimal costPrice) {
|
||||
|
||||
ImportationFolderCostPrice importationFolderCostPrice = new ImportationFolderCostPrice();
|
||||
importationFolderCostPrice.setImportationFolder(importationFolder);
|
||||
importationFolderCostPrice.setStockMoveLine(stockMoveLine);
|
||||
importationFolderCostPrice.setCostPrice(costPrice);
|
||||
importationFolderCostPrice.setCostPrice(costPrice.setScale(4, RoundingMode.HALF_EVEN));
|
||||
importationFolderCostPrice.setValorisation(importationFolder.getValorisation());
|
||||
importationFolderCostPrice.setPercent(precent);
|
||||
importationFolderCostPrice.setFreightSplit(freightSplit);
|
||||
importationFolderCostPrice.setTotalApproach(totalApproachsPerProduct);
|
||||
importationFolderCostPrice.setTotalInvoice(totalInvoiceProduct);
|
||||
importationFolderCostPrice.setPercent(
|
||||
precent.multiply(new BigDecimal(100)).setScale(2, RoundingMode.HALF_EVEN));
|
||||
importationFolderCostPrice.setFreightSplit(freightSplit.setScale(2, RoundingMode.HALF_EVEN));
|
||||
importationFolderCostPrice.setTotalApproach(
|
||||
totalApproachsPerProduct.setScale(2, RoundingMode.HALF_EVEN));
|
||||
importationFolderCostPrice.setTotalInvoice(
|
||||
totalInvoiceProduct.setScale(2, RoundingMode.HALF_EVEN));
|
||||
importationFolderCostPrice.setProduct(stockMoveLine.getProduct());
|
||||
importationFolder.addImportationFolderCostPriceListItem(importationFolderCostPrice);
|
||||
importationFolderRepository.save(importationFolder);
|
||||
}
|
||||
|
||||
|
||||
// public void valisateCostPrice(ActionRequest request, ActionResponse response) {
|
||||
@Transactional
|
||||
public void validateCostPrice(ImportationFolderCostPrice importationFolderCostPrice) {
|
||||
|
||||
ImportationFolderCostPriceRepository importationFolderCostPriceRepository = Beans.get(ImportationFolderCostPriceRepository.class);
|
||||
ImportationFolderCostPriceRepository importationFolderCostPriceRepository =
|
||||
Beans.get(ImportationFolderCostPriceRepository.class);
|
||||
|
||||
StockMove stockMove = importationFolderCostPrice.getStockMoveLine().getStockMove();
|
||||
Long productId = importationFolderCostPrice.getProduct().getId();
|
||||
@@ -443,9 +616,12 @@ public class ImportationFolderServiceImpl {
|
||||
BigDecimal costPrice = importationFolderCostPrice.getCostPrice();
|
||||
|
||||
try {
|
||||
Beans.get(StockMoveLineServiceSupplychainImpl.class).resetValorization(productId, stockMoveId, toDate,false);
|
||||
Beans.get(StockMoveLineServiceSupplychainImpl.class).fillStockMoveLines(productId, toDate, stockMoveId,false);
|
||||
Beans.get(StockMoveLineServiceSupplychainImpl.class).valorize(productId, stockMoveId, toDate, costPrice,false,false);
|
||||
Beans.get(StockMoveLineServiceSupplychainImpl.class)
|
||||
.resetValorization(productId, stockMoveId, toDate, false);
|
||||
Beans.get(StockMoveLineServiceSupplychainImpl.class)
|
||||
.fillStockMoveLines(productId, toDate, stockMoveId, false);
|
||||
Beans.get(StockMoveLineServiceSupplychainImpl.class)
|
||||
.valorize(productId, stockMoveId, toDate, costPrice, false, false);
|
||||
importationFolderCostPrice.setStatusSelect(2);
|
||||
importationFolderCostPrice.setValidationDate(LocalDate.now());
|
||||
importationFolderCostPriceRepository.save(importationFolderCostPrice);
|
||||
@@ -455,7 +631,6 @@ public class ImportationFolderServiceImpl {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Transactional
|
||||
public void setStockMoveLineNetMass(List<StockMoveLine> stockMoveLineList, BigDecimal netMass) {
|
||||
for (StockMoveLine stockMoveLine : stockMoveLineList) {
|
||||
@@ -474,22 +649,22 @@ public class ImportationFolderServiceImpl {
|
||||
|
||||
@Transactional
|
||||
public void rejectImportationFolder(ImportationFolder importationFolder, String rejectionRaison) {
|
||||
|
||||
|
||||
importationFolder.setStatusSelect(ImportationFolderRepository.STATUS_REJECTED);
|
||||
importationFolder.setRejectionRaison(rejectionRaison);
|
||||
importationFolder.setRejectedDate(LocalDate.now());
|
||||
importationFolder.setRejectedByUser(AuthUtils.getUser());
|
||||
importationFolder.setRejectedInstanceSelect(1);
|
||||
importationFolderRepository.save(importationFolder);
|
||||
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Invoice generateFromModel(ImportationFolder importationFolder,InvoiceTemplate invoiceTemplate) throws AxelorException{
|
||||
Invoice invoice = Beans.get(InvoiceTemplateService.class).generateInvoiceFromTemplate(invoiceTemplate);
|
||||
public Invoice generateFromModel(
|
||||
ImportationFolder importationFolder, InvoiceTemplate invoiceTemplate) throws AxelorException {
|
||||
Invoice invoice =
|
||||
Beans.get(InvoiceTemplateService.class).generateInvoiceFromTemplate(invoiceTemplate);
|
||||
invoice.setImportationFolder(importationFolder);
|
||||
invoice.setIsInvoiceApproach(true);
|
||||
return Beans.get(InvoiceRepository.class).save(invoice);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,14 +17,12 @@
|
||||
*/
|
||||
package com.axelor.apps.supplychain.service;
|
||||
|
||||
import com.axelor.apps.base.db.ABCAnalysis;
|
||||
import com.axelor.apps.base.db.ABCAnalysisLine;
|
||||
import com.axelor.apps.base.db.Company;
|
||||
import com.axelor.apps.base.db.Partner;
|
||||
import com.axelor.apps.base.db.Product;
|
||||
import com.axelor.apps.base.db.Unit;
|
||||
import com.axelor.apps.base.db.repo.ABCAnalysisLineRepository;
|
||||
import com.axelor.apps.base.db.repo.ABCAnalysisRepository;
|
||||
import com.axelor.apps.base.db.repo.ProductRepository;
|
||||
import com.axelor.apps.base.service.UnitConversionService;
|
||||
import com.axelor.apps.base.service.app.AppBaseService;
|
||||
@@ -80,15 +78,12 @@ import java.lang.invoke.MethodHandles;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.LocalDate;
|
||||
import java.time.Month;
|
||||
import java.time.format.TextStyle;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -122,7 +117,6 @@ public class MrpServiceImpl implements MrpService {
|
||||
protected LocalDate today;
|
||||
public List<MrpForecast> mrpForecastListAll;
|
||||
|
||||
|
||||
@Inject
|
||||
public MrpServiceImpl(
|
||||
AppBaseService appBaseService,
|
||||
@@ -197,9 +191,18 @@ public class MrpServiceImpl implements MrpService {
|
||||
public void resetSophalLine(Mrp mrp) {
|
||||
|
||||
Beans.get(MrpLineSophalRepository.class).all().filter("self.mrp.id = ?1", mrp.getId()).remove();
|
||||
Beans.get(MrpLineSaleAndMarginRepository.class).all().filter("self.mrp.id = ?1", mrp.getId()).remove();
|
||||
Beans.get(SalesMasterPlanRepository.class).all().filter("self.mrp.id = ?1", mrp.getId()).remove();
|
||||
Beans.get(ProductionMasterPlanRepository.class).all().filter("self.mrp.id = ?1", mrp.getId()).remove();
|
||||
Beans.get(MrpLineSaleAndMarginRepository.class)
|
||||
.all()
|
||||
.filter("self.mrp.id = ?1", mrp.getId())
|
||||
.remove();
|
||||
Beans.get(SalesMasterPlanRepository.class)
|
||||
.all()
|
||||
.filter("self.mrp.id = ?1", mrp.getId())
|
||||
.remove();
|
||||
Beans.get(ProductionMasterPlanRepository.class)
|
||||
.all()
|
||||
.filter("self.mrp.id = ?1", mrp.getId())
|
||||
.remove();
|
||||
|
||||
mrp.setStatusSelect(MrpRepository.STATUS_DRAFT);
|
||||
|
||||
@@ -1196,18 +1199,17 @@ public class MrpServiceImpl implements MrpService {
|
||||
.order("monthSelect")
|
||||
.fetch());
|
||||
|
||||
mrpForecastListAll = new ArrayList<>();
|
||||
mrpForecastListAll = new ArrayList<>();
|
||||
|
||||
|
||||
mrpForecastListAll.addAll( mrpForecastRepository
|
||||
mrpForecastListAll.addAll(
|
||||
mrpForecastRepository
|
||||
.all()
|
||||
.filter(
|
||||
"self.product.id in (?1) AND self.stockLocation in (?2) AND self.statusSelect = ?3 AND self.forecastDate < ?4",
|
||||
this.productMap.keySet(),
|
||||
slList2.stream().collect(Collectors.toList()),
|
||||
MrpForecastRepository.STATUS_CONFIRMED,
|
||||
LocalDate.parse(String.valueOf(LocalDate.now().getYear())+"-01-01")
|
||||
)
|
||||
LocalDate.parse(String.valueOf(LocalDate.now().getYear()) + "-01-01"))
|
||||
.order("monthSelect")
|
||||
.fetch());
|
||||
|
||||
@@ -1219,11 +1221,8 @@ public class MrpServiceImpl implements MrpService {
|
||||
BigDecimal qty = new BigDecimal(entry.getValue());
|
||||
if (this.productMap.get(product.getId()) == 0) {
|
||||
this.createMrpLineSophal(mrp, product, product.getUnit(), qty, mrpForecastList, productQty);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@@ -1240,8 +1239,8 @@ public class MrpServiceImpl implements MrpService {
|
||||
mrpLineSophal.setQty(qty);
|
||||
BigDecimal reelQty = qty;
|
||||
BigDecimal sumQty = BigDecimal.ZERO;
|
||||
Collections.sort(mrpForecastList, Comparator.comparingInt(MrpForecast ::getMonthSelect));
|
||||
for (MrpForecast forecast : mrpForecastList){
|
||||
Collections.sort(mrpForecastList, Comparator.comparingInt(MrpForecast::getMonthSelect));
|
||||
for (MrpForecast forecast : mrpForecastList) {
|
||||
if (forecast.getProduct() == product) {
|
||||
reelQty = reelQty.subtract(forecast.getQty());
|
||||
BigDecimal displayedQty = reelQty;
|
||||
@@ -1298,248 +1297,273 @@ public class MrpServiceImpl implements MrpService {
|
||||
Beans.get(MrpLineSophalRepository.class).save(mrpLineSophal);
|
||||
}
|
||||
|
||||
|
||||
@Transactional
|
||||
public void createMargeAndSaleLineSophal(
|
||||
Mrp mrp,
|
||||
Product product,
|
||||
List<MrpForecast> mrpForecastList,
|
||||
BigDecimal qty
|
||||
)
|
||||
Mrp mrp, Product product, List<MrpForecast> mrpForecastList, BigDecimal qty)
|
||||
throws AxelorException {
|
||||
|
||||
MrpLineSaleAndMargin mrpLineSaleAndMargin = new MrpLineSaleAndMargin();
|
||||
MrpLineSaleAndMargin mrpLineSaleAndMargin = new MrpLineSaleAndMargin();
|
||||
|
||||
ArrayList<Integer> lastThreeMonths = new ArrayList<>();
|
||||
lastThreeMonths.add(10);
|
||||
lastThreeMonths.add(11);
|
||||
lastThreeMonths.add(12);
|
||||
BigDecimal totalLastThree = BigDecimal.ZERO;
|
||||
BigDecimal avgLastThree = BigDecimal.ZERO;
|
||||
|
||||
ArrayList<Integer> lastThreeMonths = new ArrayList<>();
|
||||
lastThreeMonths.add(10);
|
||||
lastThreeMonths.add(11);
|
||||
lastThreeMonths.add(12);
|
||||
BigDecimal totalLastThree = BigDecimal.ZERO;
|
||||
BigDecimal avgLastThree = BigDecimal.ZERO;
|
||||
|
||||
totalLastThree = mrpForecastList.stream().filter(t -> (t.getForecastDate().getYear() == (LocalDate.now().getYear() - 1)) && (t.getProduct().getId() == product.getId()) && lastThreeMonths.contains(t.getMonthSelect())).map(MrpForecast::getQty)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
totalLastThree =
|
||||
mrpForecastList
|
||||
.stream()
|
||||
.filter(
|
||||
t ->
|
||||
(t.getForecastDate().getYear() == (LocalDate.now().getYear() - 1))
|
||||
&& (t.getProduct().getId() == product.getId())
|
||||
&& lastThreeMonths.contains(t.getMonthSelect()))
|
||||
.map(MrpForecast::getQty)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
|
||||
avgLastThree = totalLastThree.divide(new BigDecimal("3"), 2, RoundingMode.HALF_UP);
|
||||
|
||||
avgLastThree = totalLastThree.divide(new BigDecimal("3"),2,RoundingMode.HALF_UP);
|
||||
log.debug("******* mrpForecastList {}", mrpForecastList);
|
||||
log.debug("******* lastThreeMonths {}", lastThreeMonths);
|
||||
log.debug("******* totalLastThree {}", totalLastThree);
|
||||
log.debug("******* avgLastThree {}", avgLastThree);
|
||||
|
||||
log.debug("******* mrpForecastList {}",mrpForecastList);
|
||||
log.debug("******* lastThreeMonths {}",lastThreeMonths);
|
||||
log.debug("******* totalLastThree {}",totalLastThree);
|
||||
log.debug("******* avgLastThree {}",avgLastThree);
|
||||
|
||||
BigDecimal maxJan = getMaxOfMonth(1, product, mrpForecastList);
|
||||
BigDecimal maxFeb = getMaxOfMonth(2, product, mrpForecastList);
|
||||
BigDecimal maxMar = getMaxOfMonth(3, product, mrpForecastList);
|
||||
BigDecimal maxApril = getMaxOfMonth(4, product, mrpForecastList);
|
||||
BigDecimal maxMay = getMaxOfMonth(5, product, mrpForecastList);
|
||||
BigDecimal maxJune = getMaxOfMonth(6, product, mrpForecastList);
|
||||
BigDecimal maxJuly = getMaxOfMonth(7, product, mrpForecastList);
|
||||
BigDecimal maxAugust = getMaxOfMonth(8, product, mrpForecastList);
|
||||
BigDecimal maxSep = getMaxOfMonth(9, product, mrpForecastList);
|
||||
BigDecimal maxOct = getMaxOfMonth(10, product, mrpForecastList);
|
||||
BigDecimal maxNov = getMaxOfMonth(11, product, mrpForecastList);
|
||||
BigDecimal maxDec = getMaxOfMonth(12, product, mrpForecastList);
|
||||
|
||||
BigDecimal maxFirstQuarter = maxJan.add(maxFeb).add(maxMar).divide(new BigDecimal("3"), RoundingMode.HALF_UP);
|
||||
BigDecimal maxSecQuarter = maxJune.add(maxApril).add(maxMay).divide(new BigDecimal("3"), RoundingMode.HALF_UP);
|
||||
BigDecimal maxthirdQuarter = maxSep.add(maxJuly).add(maxAugust).divide(new BigDecimal("3"), RoundingMode.HALF_UP);
|
||||
BigDecimal maxforthQuarter = maxOct.add(maxNov).add(maxDec).divide(new BigDecimal("3"), RoundingMode.HALF_UP);
|
||||
BigDecimal maxJan = getMaxOfMonth(1, product, mrpForecastList);
|
||||
BigDecimal maxFeb = getMaxOfMonth(2, product, mrpForecastList);
|
||||
BigDecimal maxMar = getMaxOfMonth(3, product, mrpForecastList);
|
||||
BigDecimal maxApril = getMaxOfMonth(4, product, mrpForecastList);
|
||||
BigDecimal maxMay = getMaxOfMonth(5, product, mrpForecastList);
|
||||
BigDecimal maxJune = getMaxOfMonth(6, product, mrpForecastList);
|
||||
BigDecimal maxJuly = getMaxOfMonth(7, product, mrpForecastList);
|
||||
BigDecimal maxAugust = getMaxOfMonth(8, product, mrpForecastList);
|
||||
BigDecimal maxSep = getMaxOfMonth(9, product, mrpForecastList);
|
||||
BigDecimal maxOct = getMaxOfMonth(10, product, mrpForecastList);
|
||||
BigDecimal maxNov = getMaxOfMonth(11, product, mrpForecastList);
|
||||
BigDecimal maxDec = getMaxOfMonth(12, product, mrpForecastList);
|
||||
|
||||
|
||||
if(maxFirstQuarter.compareTo(avgLastThree) > 0){
|
||||
mrpLineSaleAndMargin.setFirstQuarterMax(maxFirstQuarter);
|
||||
}else{
|
||||
maxFirstQuarter = avgLastThree;
|
||||
mrpLineSaleAndMargin.setFirstQuarterMax(maxFirstQuarter);
|
||||
}
|
||||
BigDecimal maxFirstQuarter =
|
||||
maxJan.add(maxFeb).add(maxMar).divide(new BigDecimal("3"), RoundingMode.HALF_UP);
|
||||
BigDecimal maxSecQuarter =
|
||||
maxJune.add(maxApril).add(maxMay).divide(new BigDecimal("3"), RoundingMode.HALF_UP);
|
||||
BigDecimal maxthirdQuarter =
|
||||
maxSep.add(maxJuly).add(maxAugust).divide(new BigDecimal("3"), RoundingMode.HALF_UP);
|
||||
BigDecimal maxforthQuarter =
|
||||
maxOct.add(maxNov).add(maxDec).divide(new BigDecimal("3"), RoundingMode.HALF_UP);
|
||||
|
||||
if (maxFirstQuarter.compareTo(avgLastThree) > 0) {
|
||||
mrpLineSaleAndMargin.setFirstQuarterMax(maxFirstQuarter);
|
||||
} else {
|
||||
maxFirstQuarter = avgLastThree;
|
||||
mrpLineSaleAndMargin.setFirstQuarterMax(maxFirstQuarter);
|
||||
}
|
||||
|
||||
mrpLineSaleAndMargin.setSecondQuarterMax(maxSecQuarter);
|
||||
mrpLineSaleAndMargin.setThirdQuarterMax(maxthirdQuarter);
|
||||
mrpLineSaleAndMargin.setForthQuarterMax(maxforthQuarter);
|
||||
mrpLineSaleAndMargin.setSecondQuarterMax(maxSecQuarter);
|
||||
mrpLineSaleAndMargin.setThirdQuarterMax(maxthirdQuarter);
|
||||
mrpLineSaleAndMargin.setForthQuarterMax(maxforthQuarter);
|
||||
|
||||
String className = "";
|
||||
List<ABCAnalysisLine> abcAnalysisLines = Beans.get(ABCAnalysisLineRepository.class).all().fetch();
|
||||
ABCAnalysisLine abcAnalysisLine = abcAnalysisLines.stream().filter(t -> t.getProduct() == product).findFirst().get();
|
||||
if(abcAnalysisLine == null) {
|
||||
throw new AxelorException(
|
||||
mrp,
|
||||
TraceBackRepository.CATEGORY_NO_VALUE,
|
||||
"ABC classification needed");
|
||||
}else{
|
||||
className = abcAnalysisLine.getAbcAnalysisClass().getName();
|
||||
}
|
||||
String className = "";
|
||||
List<ABCAnalysisLine> abcAnalysisLines =
|
||||
Beans.get(ABCAnalysisLineRepository.class).all().fetch();
|
||||
ABCAnalysisLine abcAnalysisLine =
|
||||
abcAnalysisLines.stream().filter(t -> t.getProduct() == product).findFirst().get();
|
||||
if (abcAnalysisLine == null) {
|
||||
throw new AxelorException(
|
||||
mrp, TraceBackRepository.CATEGORY_NO_VALUE, "ABC classification needed");
|
||||
} else {
|
||||
className = abcAnalysisLine.getAbcAnalysisClass().getName();
|
||||
}
|
||||
|
||||
|
||||
BigDecimal firstQuarterMargin = BigDecimal.ZERO;
|
||||
BigDecimal secondQuarterMargin = BigDecimal.ZERO;
|
||||
BigDecimal thirdQuarterMargin = BigDecimal.ZERO;
|
||||
BigDecimal fourthQuarterMargin = BigDecimal.ZERO;
|
||||
BigDecimal firstQuarterMargin = BigDecimal.ZERO;
|
||||
BigDecimal secondQuarterMargin = BigDecimal.ZERO;
|
||||
BigDecimal thirdQuarterMargin = BigDecimal.ZERO;
|
||||
BigDecimal fourthQuarterMargin = BigDecimal.ZERO;
|
||||
|
||||
switch (className) {
|
||||
case "A":
|
||||
firstQuarterMargin = maxFirstQuarter.add(maxFirstQuarter.multiply(new BigDecimal("0.15")));
|
||||
secondQuarterMargin = maxSecQuarter.add(maxSecQuarter.multiply(new BigDecimal("0.20"))) ;
|
||||
thirdQuarterMargin = maxthirdQuarter.add(maxthirdQuarter.multiply(new BigDecimal("0.15")));
|
||||
fourthQuarterMargin = maxforthQuarter.add(maxforthQuarter.multiply(new BigDecimal("0.15")));
|
||||
switch (className) {
|
||||
case "A":
|
||||
firstQuarterMargin = maxFirstQuarter.add(maxFirstQuarter.multiply(new BigDecimal("0.15")));
|
||||
secondQuarterMargin = maxSecQuarter.add(maxSecQuarter.multiply(new BigDecimal("0.20")));
|
||||
thirdQuarterMargin = maxthirdQuarter.add(maxthirdQuarter.multiply(new BigDecimal("0.15")));
|
||||
fourthQuarterMargin = maxforthQuarter.add(maxforthQuarter.multiply(new BigDecimal("0.15")));
|
||||
|
||||
break;
|
||||
case "B":
|
||||
firstQuarterMargin = maxFirstQuarter.add(maxFirstQuarter.multiply(new BigDecimal("0.10")));
|
||||
secondQuarterMargin = maxSecQuarter.add(maxSecQuarter.multiply(new BigDecimal("0.10"))) ;
|
||||
thirdQuarterMargin = maxthirdQuarter.add(maxthirdQuarter.multiply(new BigDecimal("0.10")));
|
||||
fourthQuarterMargin = maxforthQuarter.add(maxforthQuarter.multiply(new BigDecimal("0.10")));
|
||||
break;
|
||||
case "C":
|
||||
firstQuarterMargin = maxFirstQuarter.add(maxFirstQuarter.multiply(new BigDecimal("0.05")));
|
||||
secondQuarterMargin = maxSecQuarter.add(maxSecQuarter.multiply(new BigDecimal("0.05"))) ;
|
||||
thirdQuarterMargin = maxthirdQuarter.add(maxthirdQuarter.multiply(new BigDecimal("0.05")));
|
||||
fourthQuarterMargin = maxforthQuarter.add(maxforthQuarter.multiply(new BigDecimal("0.05")));
|
||||
break;
|
||||
default:
|
||||
firstQuarterMargin = maxFirstQuarter;
|
||||
secondQuarterMargin = maxSecQuarter;
|
||||
thirdQuarterMargin = maxthirdQuarter;
|
||||
fourthQuarterMargin = maxforthQuarter;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "B":
|
||||
firstQuarterMargin = maxFirstQuarter.add(maxFirstQuarter.multiply(new BigDecimal("0.10")));
|
||||
secondQuarterMargin = maxSecQuarter.add(maxSecQuarter.multiply(new BigDecimal("0.10")));
|
||||
thirdQuarterMargin = maxthirdQuarter.add(maxthirdQuarter.multiply(new BigDecimal("0.10")));
|
||||
fourthQuarterMargin = maxforthQuarter.add(maxforthQuarter.multiply(new BigDecimal("0.10")));
|
||||
break;
|
||||
case "C":
|
||||
firstQuarterMargin = maxFirstQuarter.add(maxFirstQuarter.multiply(new BigDecimal("0.05")));
|
||||
secondQuarterMargin = maxSecQuarter.add(maxSecQuarter.multiply(new BigDecimal("0.05")));
|
||||
thirdQuarterMargin = maxthirdQuarter.add(maxthirdQuarter.multiply(new BigDecimal("0.05")));
|
||||
fourthQuarterMargin = maxforthQuarter.add(maxforthQuarter.multiply(new BigDecimal("0.05")));
|
||||
break;
|
||||
default:
|
||||
firstQuarterMargin = maxFirstQuarter;
|
||||
secondQuarterMargin = maxSecQuarter;
|
||||
thirdQuarterMargin = maxthirdQuarter;
|
||||
fourthQuarterMargin = maxforthQuarter;
|
||||
break;
|
||||
}
|
||||
|
||||
BigDecimal j = getMaxLastYear(2, product, mrpForecastList);
|
||||
BigDecimal f = getMaxLastYear(3, product, mrpForecastList);
|
||||
BigDecimal max = j.max(f);
|
||||
BigDecimal j = getMaxLastYear(2, product, mrpForecastList);
|
||||
BigDecimal f = getMaxLastYear(3, product, mrpForecastList);
|
||||
BigDecimal max = j.max(f);
|
||||
|
||||
log.debug("sssssss margin {} max : {} class {} ",firstQuarterMargin,maxFirstQuarter,className);
|
||||
log.debug("last year jan {} feb {}",j,f);
|
||||
log.debug("maxxxxxxxxxxx {}",max);
|
||||
log.debug(
|
||||
"sssssss margin {} max : {} class {} ", firstQuarterMargin, maxFirstQuarter, className);
|
||||
log.debug("last year jan {} feb {}", j, f);
|
||||
log.debug("maxxxxxxxxxxx {}", max);
|
||||
|
||||
firstQuarterMargin = firstQuarterMargin.add(max);
|
||||
firstQuarterMargin = firstQuarterMargin.add(max);
|
||||
|
||||
mrpLineSaleAndMargin.setFirstQuarterMarge(firstQuarterMargin.setScale(0,RoundingMode.CEILING));
|
||||
mrpLineSaleAndMargin.setSecondQuarterMarge(secondQuarterMargin.setScale(0,RoundingMode.CEILING));
|
||||
mrpLineSaleAndMargin.setThirdQuarterMarge(thirdQuarterMargin.setScale(0,RoundingMode.CEILING));
|
||||
mrpLineSaleAndMargin.setForthQuarterMarge(fourthQuarterMargin.setScale(0,RoundingMode.CEILING));
|
||||
mrpLineSaleAndMargin.setFirstQuarterMarge(firstQuarterMargin.setScale(0, RoundingMode.CEILING));
|
||||
mrpLineSaleAndMargin.setSecondQuarterMarge(
|
||||
secondQuarterMargin.setScale(0, RoundingMode.CEILING));
|
||||
mrpLineSaleAndMargin.setThirdQuarterMarge(thirdQuarterMargin.setScale(0, RoundingMode.CEILING));
|
||||
mrpLineSaleAndMargin.setForthQuarterMarge(
|
||||
fourthQuarterMargin.setScale(0, RoundingMode.CEILING));
|
||||
|
||||
this.createdSalesMasterPlanLine(
|
||||
firstQuarterMargin,
|
||||
secondQuarterMargin,
|
||||
thirdQuarterMargin,
|
||||
fourthQuarterMargin,
|
||||
product,
|
||||
mrp);
|
||||
|
||||
this.createdSalesMasterPlanLine(firstQuarterMargin, secondQuarterMargin, thirdQuarterMargin, fourthQuarterMargin, product, mrp);
|
||||
|
||||
mrpLineSaleAndMargin.setProduct(product);
|
||||
mrpLineSaleAndMargin.setProductOrigin(product);
|
||||
mrpLineSaleAndMargin.setMrp(mrp);
|
||||
Beans.get(MrpLineSaleAndMarginRepository.class).save(mrpLineSaleAndMargin);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Transactional
|
||||
public void createdProductionMasterPlan(Product product,Mrp mrp,BigDecimal qty, BigDecimal batchQty) throws AxelorException {
|
||||
|
||||
this.createMargeAndSaleLineSophal(mrp, product, mrpForecastListAll,qty);
|
||||
|
||||
|
||||
ProductionMasterPlan productionMasterPlan = new ProductionMasterPlan();
|
||||
int currentMonth = LocalDate.now().getMonth().getValue();
|
||||
BigDecimal decreasingQty = qty;
|
||||
BigDecimal currentMargin= BigDecimal.ZERO;
|
||||
BigDecimal remaining= BigDecimal.ZERO;
|
||||
BigDecimal annualQty= BigDecimal.ZERO;
|
||||
BigDecimal batchQtyPerMonth = BigDecimal.ZERO;
|
||||
|
||||
|
||||
for (int index = currentMonth; index < 13; index++) {
|
||||
currentMargin = getCurrentSaleMargin(product, mrp, index);
|
||||
|
||||
if(decreasingQty.compareTo(currentMargin) > 0) {
|
||||
remaining = decreasingQty.subtract(currentMargin);
|
||||
decreasingQty = BigDecimal.ZERO;
|
||||
}else{
|
||||
remaining = BigDecimal.ZERO;
|
||||
decreasingQty = currentMargin.subtract(decreasingQty);
|
||||
}
|
||||
|
||||
batchQtyPerMonth = decreasingQty.divide(batchQty,0,RoundingMode.UP);
|
||||
|
||||
annualQty = annualQty.add(decreasingQty);
|
||||
|
||||
switch (index) {
|
||||
case 1:
|
||||
productionMasterPlan.setJanuary(decreasingQty);
|
||||
productionMasterPlan.setJanuaryBatchQty(batchQtyPerMonth);
|
||||
break;
|
||||
case 2:
|
||||
productionMasterPlan.setFebruary(decreasingQty);
|
||||
productionMasterPlan.setFebruaryBatchQty(batchQtyPerMonth);
|
||||
break;
|
||||
case 3:
|
||||
productionMasterPlan.setMarch(decreasingQty);
|
||||
productionMasterPlan.setMarchBatchQty(batchQtyPerMonth);
|
||||
break;
|
||||
case 4:
|
||||
productionMasterPlan.setApril(decreasingQty);
|
||||
productionMasterPlan.setAprilBatchQty(batchQtyPerMonth);
|
||||
case 5:
|
||||
productionMasterPlan.setMay(decreasingQty);
|
||||
productionMasterPlan.setMayBatchQty(batchQtyPerMonth);
|
||||
case 6:
|
||||
productionMasterPlan.setJuin(decreasingQty);
|
||||
productionMasterPlan.setJuinBatchQty(batchQtyPerMonth);
|
||||
break;
|
||||
case 7:
|
||||
productionMasterPlan.setJuly(decreasingQty);
|
||||
productionMasterPlan.setJulyBatchQty(batchQtyPerMonth);
|
||||
break;
|
||||
case 8:
|
||||
productionMasterPlan.setAugust(decreasingQty);
|
||||
productionMasterPlan.setAugustBatchQty(batchQtyPerMonth);
|
||||
break;
|
||||
case 9:
|
||||
productionMasterPlan.setSeptember(decreasingQty);
|
||||
productionMasterPlan.setSeptemberBatchQty(batchQtyPerMonth);
|
||||
break;
|
||||
case 10:
|
||||
productionMasterPlan.setOctober(decreasingQty);
|
||||
productionMasterPlan.setOctoberBatchQty(batchQtyPerMonth);
|
||||
break;
|
||||
case 11:
|
||||
productionMasterPlan.setNovember(decreasingQty);
|
||||
productionMasterPlan.setNovemberBatchQty(batchQtyPerMonth);
|
||||
break;
|
||||
case 12:
|
||||
productionMasterPlan.setDecember(decreasingQty);
|
||||
productionMasterPlan.setDecemberBatchQty(batchQtyPerMonth);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if(remaining.compareTo(BigDecimal.ZERO) > 0){
|
||||
decreasingQty = decreasingQty.add(remaining);
|
||||
}else{
|
||||
decreasingQty = BigDecimal.ZERO;
|
||||
}
|
||||
}
|
||||
|
||||
productionMasterPlan.setAnnualQty(annualQty);
|
||||
productionMasterPlan.setMrp(mrp);
|
||||
productionMasterPlan.setProduct(product);
|
||||
|
||||
Beans.get(ProductionMasterPlanRepository.class).save(productionMasterPlan);
|
||||
|
||||
}
|
||||
|
||||
BigDecimal getMaxOfMonth(int monthSelect,Product product,List<MrpForecast> mrpForecastList){
|
||||
return mrpForecastList.stream().filter(t -> t.getProduct() == product && t.getMonthSelect() == monthSelect).map(t -> t.getQty()).max(Comparator.naturalOrder()).orElse(BigDecimal.ZERO);
|
||||
}
|
||||
|
||||
|
||||
BigDecimal getMaxLastYear(int monthSelect,Product product,List<MrpForecast> mrpForecastList){
|
||||
int lastYear = LocalDate.now().getYear() - 1;
|
||||
return mrpForecastList.stream().filter(t -> t.getProduct() == product && t.getMonthSelect() == monthSelect && t.getForecastDate().getYear() == lastYear).map(t -> t.getQty()).max(Comparator.naturalOrder()).orElse(BigDecimal.ZERO);
|
||||
mrpLineSaleAndMargin.setProduct(product);
|
||||
mrpLineSaleAndMargin.setProductOrigin(product);
|
||||
mrpLineSaleAndMargin.setMrp(mrp);
|
||||
Beans.get(MrpLineSaleAndMarginRepository.class).save(mrpLineSaleAndMargin);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void createdSalesMasterPlanLine(BigDecimal firstQuarterMargin,BigDecimal secondQuarterMargin,BigDecimal thirdQuarterMargin,BigDecimal fourthQuarterMargin,Product product,Mrp mrp){
|
||||
public void createdProductionMasterPlan(
|
||||
Product product, Mrp mrp, BigDecimal qty, BigDecimal batchQty) throws AxelorException {
|
||||
|
||||
this.createMargeAndSaleLineSophal(mrp, product, mrpForecastListAll, qty);
|
||||
|
||||
ProductionMasterPlan productionMasterPlan = new ProductionMasterPlan();
|
||||
int currentMonth = LocalDate.now().getMonth().getValue();
|
||||
BigDecimal decreasingQty = qty;
|
||||
BigDecimal currentMargin = BigDecimal.ZERO;
|
||||
BigDecimal remaining = BigDecimal.ZERO;
|
||||
BigDecimal annualQty = BigDecimal.ZERO;
|
||||
BigDecimal batchQtyPerMonth = BigDecimal.ZERO;
|
||||
|
||||
for (int index = currentMonth; index < 13; index++) {
|
||||
currentMargin = getCurrentSaleMargin(product, mrp, index);
|
||||
|
||||
if (decreasingQty.compareTo(currentMargin) > 0) {
|
||||
remaining = decreasingQty.subtract(currentMargin);
|
||||
decreasingQty = BigDecimal.ZERO;
|
||||
} else {
|
||||
remaining = BigDecimal.ZERO;
|
||||
decreasingQty = currentMargin.subtract(decreasingQty);
|
||||
}
|
||||
|
||||
batchQtyPerMonth = decreasingQty.divide(batchQty, 0, RoundingMode.UP);
|
||||
|
||||
annualQty = annualQty.add(decreasingQty);
|
||||
|
||||
switch (index) {
|
||||
case 1:
|
||||
productionMasterPlan.setJanuary(decreasingQty);
|
||||
productionMasterPlan.setJanuaryBatchQty(batchQtyPerMonth);
|
||||
break;
|
||||
case 2:
|
||||
productionMasterPlan.setFebruary(decreasingQty);
|
||||
productionMasterPlan.setFebruaryBatchQty(batchQtyPerMonth);
|
||||
break;
|
||||
case 3:
|
||||
productionMasterPlan.setMarch(decreasingQty);
|
||||
productionMasterPlan.setMarchBatchQty(batchQtyPerMonth);
|
||||
break;
|
||||
case 4:
|
||||
productionMasterPlan.setApril(decreasingQty);
|
||||
productionMasterPlan.setAprilBatchQty(batchQtyPerMonth);
|
||||
case 5:
|
||||
productionMasterPlan.setMay(decreasingQty);
|
||||
productionMasterPlan.setMayBatchQty(batchQtyPerMonth);
|
||||
case 6:
|
||||
productionMasterPlan.setJuin(decreasingQty);
|
||||
productionMasterPlan.setJuinBatchQty(batchQtyPerMonth);
|
||||
break;
|
||||
case 7:
|
||||
productionMasterPlan.setJuly(decreasingQty);
|
||||
productionMasterPlan.setJulyBatchQty(batchQtyPerMonth);
|
||||
break;
|
||||
case 8:
|
||||
productionMasterPlan.setAugust(decreasingQty);
|
||||
productionMasterPlan.setAugustBatchQty(batchQtyPerMonth);
|
||||
break;
|
||||
case 9:
|
||||
productionMasterPlan.setSeptember(decreasingQty);
|
||||
productionMasterPlan.setSeptemberBatchQty(batchQtyPerMonth);
|
||||
break;
|
||||
case 10:
|
||||
productionMasterPlan.setOctober(decreasingQty);
|
||||
productionMasterPlan.setOctoberBatchQty(batchQtyPerMonth);
|
||||
break;
|
||||
case 11:
|
||||
productionMasterPlan.setNovember(decreasingQty);
|
||||
productionMasterPlan.setNovemberBatchQty(batchQtyPerMonth);
|
||||
break;
|
||||
case 12:
|
||||
productionMasterPlan.setDecember(decreasingQty);
|
||||
productionMasterPlan.setDecemberBatchQty(batchQtyPerMonth);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (remaining.compareTo(BigDecimal.ZERO) > 0) {
|
||||
decreasingQty = decreasingQty.add(remaining);
|
||||
} else {
|
||||
decreasingQty = BigDecimal.ZERO;
|
||||
}
|
||||
}
|
||||
|
||||
productionMasterPlan.setAnnualQty(annualQty);
|
||||
productionMasterPlan.setMrp(mrp);
|
||||
productionMasterPlan.setProduct(product);
|
||||
|
||||
Beans.get(ProductionMasterPlanRepository.class).save(productionMasterPlan);
|
||||
}
|
||||
|
||||
BigDecimal getMaxOfMonth(int monthSelect, Product product, List<MrpForecast> mrpForecastList) {
|
||||
return mrpForecastList
|
||||
.stream()
|
||||
.filter(t -> t.getProduct() == product && t.getMonthSelect() == monthSelect)
|
||||
.map(t -> t.getQty())
|
||||
.max(Comparator.naturalOrder())
|
||||
.orElse(BigDecimal.ZERO);
|
||||
}
|
||||
|
||||
BigDecimal getMaxLastYear(int monthSelect, Product product, List<MrpForecast> mrpForecastList) {
|
||||
int lastYear = LocalDate.now().getYear() - 1;
|
||||
return mrpForecastList
|
||||
.stream()
|
||||
.filter(
|
||||
t ->
|
||||
t.getProduct() == product
|
||||
&& t.getMonthSelect() == monthSelect
|
||||
&& t.getForecastDate().getYear() == lastYear)
|
||||
.map(t -> t.getQty())
|
||||
.max(Comparator.naturalOrder())
|
||||
.orElse(BigDecimal.ZERO);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void createdSalesMasterPlanLine(
|
||||
BigDecimal firstQuarterMargin,
|
||||
BigDecimal secondQuarterMargin,
|
||||
BigDecimal thirdQuarterMargin,
|
||||
BigDecimal fourthQuarterMargin,
|
||||
Product product,
|
||||
Mrp mrp) {
|
||||
SalesMasterPlan salesMasterPlan = new SalesMasterPlan();
|
||||
salesMasterPlan.setJanuary(firstQuarterMargin);
|
||||
salesMasterPlan.setFebruary(firstQuarterMargin);
|
||||
@@ -1553,42 +1577,48 @@ public class MrpServiceImpl implements MrpService {
|
||||
salesMasterPlan.setOctober(fourthQuarterMargin);
|
||||
salesMasterPlan.setNovember(fourthQuarterMargin);
|
||||
salesMasterPlan.setDecember(fourthQuarterMargin);
|
||||
salesMasterPlan.setAnnualQty((firstQuarterMargin.add(secondQuarterMargin).add(thirdQuarterMargin).add(fourthQuarterMargin)).multiply(new BigDecimal("3")));
|
||||
salesMasterPlan.setAnnualQty(
|
||||
(firstQuarterMargin
|
||||
.add(secondQuarterMargin)
|
||||
.add(thirdQuarterMargin)
|
||||
.add(fourthQuarterMargin))
|
||||
.multiply(new BigDecimal("3")));
|
||||
salesMasterPlan.setMrp(mrp);
|
||||
salesMasterPlan.setProduct(product);
|
||||
Beans.get(SalesMasterPlanRepository.class).save(salesMasterPlan);
|
||||
}
|
||||
|
||||
private BigDecimal getCurrentSaleMargin(Product product,Mrp mrp,int monthSelect){
|
||||
private BigDecimal getCurrentSaleMargin(Product product, Mrp mrp, int monthSelect) {
|
||||
|
||||
MrpLineSaleAndMargin mrpLineSaleAndMargin = Beans.get(MrpLineSaleAndMarginRepository.class).all().fetchStream().filter(t -> t.getProduct() == product && t.getMrp() == mrp).findFirst().orElse(null);
|
||||
MrpLineSaleAndMargin mrpLineSaleAndMargin =
|
||||
Beans.get(MrpLineSaleAndMarginRepository.class)
|
||||
.all()
|
||||
.fetchStream()
|
||||
.filter(t -> t.getProduct() == product && t.getMrp() == mrp)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
if(mrpLineSaleAndMargin != null){
|
||||
if(monthSelect == 1 || monthSelect == 2 || monthSelect == 3){
|
||||
return mrpLineSaleAndMargin.getFirstQuarterMarge();
|
||||
if (mrpLineSaleAndMargin != null) {
|
||||
if (monthSelect == 1 || monthSelect == 2 || monthSelect == 3) {
|
||||
return mrpLineSaleAndMargin.getFirstQuarterMarge();
|
||||
|
||||
}else if(monthSelect == 4 || monthSelect == 5 || monthSelect == 6){
|
||||
return mrpLineSaleAndMargin.getSecondQuarterMarge();
|
||||
} else if (monthSelect == 4 || monthSelect == 5 || monthSelect == 6) {
|
||||
return mrpLineSaleAndMargin.getSecondQuarterMarge();
|
||||
|
||||
}else if(monthSelect == 7 || monthSelect == 8 || monthSelect == 9){
|
||||
return mrpLineSaleAndMargin.getThirdQuarterMarge();
|
||||
} else if (monthSelect == 7 || monthSelect == 8 || monthSelect == 9) {
|
||||
return mrpLineSaleAndMargin.getThirdQuarterMarge();
|
||||
|
||||
}else if(monthSelect == 10 || monthSelect == 11 || monthSelect == 12){
|
||||
return mrpLineSaleAndMargin.getForthQuarterMarge();
|
||||
} else if (monthSelect == 10 || monthSelect == 11 || monthSelect == 12) {
|
||||
return mrpLineSaleAndMargin.getForthQuarterMarge();
|
||||
|
||||
}else{
|
||||
return BigDecimal.ZERO;
|
||||
} else {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return BigDecimal.ZERO;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public boolean contains(final Object[] objects, final int key)
|
||||
{
|
||||
return Arrays.stream(objects).anyMatch(n-> (int) n ==key);
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
public boolean contains(final Object[] objects, final int key) {
|
||||
return Arrays.stream(objects).anyMatch(n -> (int) n == key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.axelor.apps.supplychain.service;
|
||||
|
||||
import com.axelor.apps.purchase.db.PurchaseOrderLineFile;
|
||||
import com.axelor.apps.purchase.db.repo.PurchaseOrderLineFileRepository;
|
||||
import com.axelor.apps.purchase.service.app.AppPurchaseService;
|
||||
import com.axelor.auth.AuthUtils;
|
||||
import com.axelor.exception.AxelorException;
|
||||
import com.axelor.inject.Beans;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.persist.Transactional;
|
||||
|
||||
public class PurchaseOrderLineFileServiceService {
|
||||
|
||||
@Inject
|
||||
protected AppPurchaseService appPurchaseService;
|
||||
|
||||
@Transactional(rollbackOn = { Exception.class })
|
||||
public void refuseCoa(PurchaseOrderLineFile purchaseOrderLineFile, String raison, String refusalOrigin)
|
||||
throws AxelorException {
|
||||
|
||||
System.out.println("purchaseOrderLineFile************************************");
|
||||
System.out.println(refusalOrigin);
|
||||
System.out.println(raison);
|
||||
System.out.println("purchaseOrderLineFile************************************");
|
||||
|
||||
switch (refusalOrigin) {
|
||||
case PurchaseOrderLineFileRepository.DT_STATUS_SELECT:
|
||||
purchaseOrderLineFile.setDtStatusSelect(4);
|
||||
purchaseOrderLineFile.setDt_refusal_date(appPurchaseService.getTodayDateTime().toLocalDateTime());
|
||||
purchaseOrderLineFile.setDt_validator_refusal_user(AuthUtils.getUser());
|
||||
purchaseOrderLineFile.setDt_refusal_reason(raison);
|
||||
break;
|
||||
case PurchaseOrderLineFileRepository.RD_STATUS_SELECT:
|
||||
purchaseOrderLineFile.setRdStatusSelect(4);
|
||||
purchaseOrderLineFile.setRd_refusal_date(appPurchaseService.getTodayDateTime().toLocalDateTime());
|
||||
purchaseOrderLineFile.setRd_refusal_user(AuthUtils.getUser());
|
||||
purchaseOrderLineFile.setRd_refusal_reason(raison);
|
||||
break;
|
||||
|
||||
case PurchaseOrderLineFileRepository.QA_STATUS_SELECT:
|
||||
purchaseOrderLineFile.setQaStatusSelect(4);
|
||||
purchaseOrderLineFile.setQa_refusal_date(appPurchaseService.getTodayDateTime().toLocalDateTime());
|
||||
purchaseOrderLineFile.setQa_validator_refusal_user(AuthUtils.getUser());
|
||||
purchaseOrderLineFile.setQa_refusal_reason(raison);
|
||||
break;
|
||||
|
||||
case PurchaseOrderLineFileRepository.QC_STATUS_SELECT:
|
||||
purchaseOrderLineFile.setQcStatusSelect(4);
|
||||
purchaseOrderLineFile.setQc_refusal_date(appPurchaseService.getTodayDateTime().toLocalDateTime());
|
||||
purchaseOrderLineFile.setQc_validator_refusal_user(AuthUtils.getUser());
|
||||
purchaseOrderLineFile.setQc_refusal_reason(raison);
|
||||
break;
|
||||
|
||||
case PurchaseOrderLineFileRepository.PRODUCTION_STATUS_SELECT:
|
||||
purchaseOrderLineFile.setProductionStatusSelect(4);
|
||||
purchaseOrderLineFile.setProduction_refusal_date(appPurchaseService.getTodayDateTime().toLocalDateTime());
|
||||
purchaseOrderLineFile.setProduction_validator_refusal_user(AuthUtils.getUser());
|
||||
purchaseOrderLineFile.setProduction_refusal_reason(raison);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Beans.get(PurchaseOrderLineFileRepository.class).save(purchaseOrderLineFile);
|
||||
}
|
||||
}
|
||||
@@ -17,10 +17,14 @@
|
||||
*/
|
||||
package com.axelor.apps.supplychain.service;
|
||||
|
||||
import com.axelor.apps.account.db.AnalyticAccount;
|
||||
import com.axelor.apps.account.db.AnalyticDistributionTemplate;
|
||||
import com.axelor.apps.account.db.AnalyticMoveLine;
|
||||
import com.axelor.apps.account.db.Budget;
|
||||
import com.axelor.apps.account.db.BudgetDistribution;
|
||||
import com.axelor.apps.account.db.repo.AnalyticMoveLineRepository;
|
||||
import com.axelor.apps.account.db.repo.BudgetDistributionRepository;
|
||||
import com.axelor.apps.account.db.repo.BudgetRepository;
|
||||
import com.axelor.apps.account.service.AnalyticMoveLineService;
|
||||
import com.axelor.apps.account.service.app.AppAccountService;
|
||||
import com.axelor.apps.base.db.Product;
|
||||
@@ -29,15 +33,19 @@ import com.axelor.apps.base.db.repo.AppAccountRepository;
|
||||
import com.axelor.apps.base.service.UnitConversionService;
|
||||
import com.axelor.apps.purchase.db.PurchaseOrder;
|
||||
import com.axelor.apps.purchase.db.PurchaseOrderLine;
|
||||
import com.axelor.apps.purchase.db.PurchaseRequestLine;
|
||||
import com.axelor.apps.purchase.db.repo.PurchaseOrderLineRepository;
|
||||
import com.axelor.apps.purchase.service.PurchaseOrderLineServiceImpl;
|
||||
import com.axelor.apps.sale.db.SaleOrderLine;
|
||||
import com.axelor.apps.sale.db.repo.SaleOrderLineRepository;
|
||||
import com.axelor.exception.AxelorException;
|
||||
import com.axelor.exception.db.repo.TraceBackRepository;
|
||||
import com.axelor.inject.Beans;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.inject.Inject;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import org.slf4j.Logger;
|
||||
@@ -110,12 +118,45 @@ public class PurchaseOrderLineServiceSupplychainImpl extends PurchaseOrderLineSe
|
||||
String productName,
|
||||
String description,
|
||||
BigDecimal qty,
|
||||
Unit unit)
|
||||
Unit unit,
|
||||
PurchaseRequestLine purchaseRequestLine)
|
||||
throws AxelorException {
|
||||
|
||||
PurchaseOrderLine purchaseOrderLine =
|
||||
super.createPurchaseOrderLine(purchaseOrder, product, productName, description, qty, unit);
|
||||
super.createPurchaseOrderLine(purchaseOrder, product, productName, description, qty, unit,purchaseRequestLine);
|
||||
|
||||
List<AnalyticMoveLine> analyticMoveLines = purchaseRequestLine.getAnalyticMoveLineList();
|
||||
|
||||
// if(analyticMoveLines.size() == 0){
|
||||
// throw new AxelorException(
|
||||
// purchaseRequestLine.getPurchaseRequest(),
|
||||
// TraceBackRepository.CATEGORY_CONFIGURATION_ERROR,
|
||||
// "Vous avez une lignes expression des besoins sans Compte analytique");
|
||||
// }
|
||||
|
||||
if(analyticMoveLines.size() != 0){
|
||||
for (AnalyticMoveLine analyticMoveLine : analyticMoveLines) {
|
||||
AnalyticMoveLine analyticMoveLineCopy = Beans.get(AnalyticMoveLineRepository.class).copy(analyticMoveLine, false);
|
||||
System.out.println("**************************************************");
|
||||
System.out.println(analyticMoveLine.getAnalyticAccount());
|
||||
System.out.println(analyticMoveLine.getAnalyticAccount().getParent());
|
||||
// Budget budget = Beans.get(BudgetRepository.class).findByAnalyticAccount(analyticMoveLine.getAnalyticAccount());
|
||||
Budget budget = findBudgetRecursive(analyticMoveLine.getAnalyticAccount());
|
||||
System.out.println(budget);
|
||||
System.out.println("**************************************************");
|
||||
if(budget != null){
|
||||
BudgetDistribution newBudgetDistribution = new BudgetDistribution();
|
||||
newBudgetDistribution.setAmount(purchaseOrderLine.getCompanyExTaxTotal().multiply(analyticMoveLine.getPercentage()).divide(new BigDecimal("100")).setScale(2, RoundingMode.HALF_EVEN));
|
||||
newBudgetDistribution.setBudget(budget);
|
||||
newBudgetDistribution.setPurchaseOrderLine(purchaseOrderLine);
|
||||
newBudgetDistribution.setAnalyticMoveLine(analyticMoveLineCopy);
|
||||
Beans.get(BudgetDistributionRepository.class).save(newBudgetDistribution);
|
||||
Beans.get(PurchaseOrderLineServiceSupplychainImpl.class).computeBudgetDistributionSumAmount(purchaseOrderLine, purchaseOrder);
|
||||
}
|
||||
purchaseOrderLine.addAnalyticMoveLineListItem(analyticMoveLineCopy);
|
||||
}
|
||||
}
|
||||
|
||||
// purchaseOrderLine.setAmountInvoiced(BigDecimal.ZERO);
|
||||
//
|
||||
// purchaseOrderLine.setIsInvoiced(false);
|
||||
@@ -123,6 +164,33 @@ public class PurchaseOrderLineServiceSupplychainImpl extends PurchaseOrderLineSe
|
||||
return purchaseOrderLine;
|
||||
}
|
||||
|
||||
public PurchaseOrderLine createPurchaseOrderLineFromSplit(
|
||||
PurchaseOrderLine purchaseOrderLine)
|
||||
throws AxelorException {
|
||||
|
||||
PurchaseOrderLine purchaseOrderLineNew = Beans.get(PurchaseOrderLineRepository.class).copy(purchaseOrderLine, true);
|
||||
|
||||
List<AnalyticMoveLine> analyticMoveLines = purchaseOrderLine.getAnalyticMoveLineList();
|
||||
|
||||
// if(analyticMoveLines.size() == 0){
|
||||
// throw new AxelorException(
|
||||
// purchaseRequestLine.getPurchaseRequest(),
|
||||
// TraceBackRepository.CATEGORY_CONFIGURATION_ERROR,
|
||||
// "Vous avez une lignes expression des besoins sans Compte analytique");
|
||||
// }
|
||||
|
||||
// for (AnalyticMoveLine analyticMoveLine : analyticMoveLines) {
|
||||
// AnalyticMoveLine analyticMoveLineCopy = Beans.get(AnalyticMoveLineRepository.class).copy(analyticMoveLine, false);
|
||||
// purchaseOrderLineNew.addAnalyticMoveLineListItem(analyticMoveLineCopy);
|
||||
// }
|
||||
|
||||
// purchaseOrderLine.setAmountInvoiced(BigDecimal.ZERO);
|
||||
//
|
||||
// purchaseOrderLine.setIsInvoiced(false);
|
||||
|
||||
return purchaseOrderLineNew;
|
||||
}
|
||||
|
||||
public PurchaseOrderLine getAndComputeAnalyticDistribution(
|
||||
PurchaseOrderLine purchaseOrderLine, PurchaseOrder purchaseOrder) {
|
||||
|
||||
@@ -208,4 +276,24 @@ public class PurchaseOrderLineServiceSupplychainImpl extends PurchaseOrderLineSe
|
||||
}
|
||||
purchaseOrderLine.setBudgetDistributionSumAmount(budgetDistributionSumAmount);
|
||||
}
|
||||
|
||||
|
||||
private Budget findBudgetRecursive(AnalyticAccount account) {
|
||||
while (account != null) {
|
||||
System.out.println("???????????????????????????????? while loop");
|
||||
Budget budget = Beans.get(BudgetRepository.class)
|
||||
.findByAnalyticAccount(account);
|
||||
if (budget != null) {
|
||||
System.out.println("???????????????????????????????? while loop inside if");
|
||||
System.out.println(account);
|
||||
System.out.println(budget);
|
||||
|
||||
return budget; // found budget, stop here
|
||||
}
|
||||
account = account.getParent(); // go up one level
|
||||
}
|
||||
return null; // no budget found in hierarchy
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -120,6 +120,9 @@ public class PurchaseOrderServiceSupplychainImpl extends PurchaseOrderServiceImp
|
||||
externalReference,
|
||||
supplierPartner.getFullName());
|
||||
|
||||
|
||||
System.out.println("Création d'une commande fournisseur : Société = {}, Reference externe = {}, Fournisseur = {}");
|
||||
|
||||
PurchaseOrder purchaseOrder =
|
||||
super.createPurchaseOrder(
|
||||
buyerUser,
|
||||
@@ -434,8 +437,18 @@ public class PurchaseOrderServiceSupplychainImpl extends PurchaseOrderServiceImp
|
||||
public void finishSockMoves(
|
||||
PurchaseOrder purchaseOrder, CancelReason raison, String cancelReasonStr)
|
||||
throws AxelorException {
|
||||
Beans.get(PurchaseOrderStockServiceImpl.class)
|
||||
.cancelReceiptWithRaison(purchaseOrder, raison, cancelReasonStr);
|
||||
Beans.get(PurchaseOrderStockServiceImpl.class).cancelReceiptWithRaison(purchaseOrder, raison, cancelReasonStr);
|
||||
this.finishPurchaseOrder(purchaseOrder, cancelReasonStr);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void computeBudgetDistribution(PurchaseOrderLine purchaseOrderLine) {
|
||||
List<BudgetDistribution> budgetDistributionList = purchaseOrderLine.getBudgetDistributionList();
|
||||
for (BudgetDistribution budgetDistribution : budgetDistributionList) {
|
||||
BigDecimal percent = budgetDistribution.getAnalyticMoveLine().getPercentage();
|
||||
budgetDistribution.setAmount(purchaseOrderLine.getCompanyExTaxTotal().multiply(percent).setScale(2).divide(new BigDecimal("100")));
|
||||
Beans.get(BudgetDistributionRepository.class).save(budgetDistribution);
|
||||
Beans.get(PurchaseOrderLineServiceSupplychainImpl.class).computeBudgetDistributionSumAmount(purchaseOrderLine, purchaseOrderLine.getPurchaseOrder());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,9 @@
|
||||
*/
|
||||
package com.axelor.apps.supplychain.service;
|
||||
|
||||
import com.axelor.apps.account.db.AnalyticMoveLine;
|
||||
import com.axelor.apps.account.db.TaxLine;
|
||||
import com.axelor.apps.account.db.repo.AnalyticMoveLineRepository;
|
||||
import com.axelor.apps.base.db.Address;
|
||||
import com.axelor.apps.base.db.CancelReason;
|
||||
import com.axelor.apps.base.db.Company;
|
||||
@@ -219,6 +221,8 @@ public class PurchaseOrderStockServiceImpl implements PurchaseOrderStockService
|
||||
stockMove.setFixTax(purchaseOrder.getFixTax());
|
||||
stockMove.setPayerPartner(purchaseOrder.getPayerPartner());
|
||||
stockMove.setDeliveryPartner(purchaseOrder.getDeliveryPartner());
|
||||
stockMove.setAnalyticAccount(purchaseOrder.getAnalyticAccount());
|
||||
stockMove.setAnalyticAxis(purchaseOrder.getAnalyticAxis());
|
||||
|
||||
qualityStockMove.setOriginId(purchaseOrder.getId());
|
||||
qualityStockMove.setOriginTypeSelect(StockMoveRepository.ORIGIN_PURCHASE_ORDER);
|
||||
@@ -336,6 +340,14 @@ public class PurchaseOrderStockServiceImpl implements PurchaseOrderStockService
|
||||
} else if (purchaseOrderLine.getIsTitleLine()) {
|
||||
stockMoveLine = createTitleStockMoveLine(purchaseOrderLine, stockMove);
|
||||
}
|
||||
stockMoveLine.setAnalyticDistributionTemplate(purchaseOrderLine.getAnalyticDistributionTemplate());
|
||||
List<AnalyticMoveLine> analyticMoveLines = purchaseOrderLine.getAnalyticMoveLineList();
|
||||
if(analyticMoveLines.size() != 0){
|
||||
for (AnalyticMoveLine analyticMoveLine : analyticMoveLines) {
|
||||
AnalyticMoveLine analyticMoveLineCopy = Beans.get(AnalyticMoveLineRepository.class).copy(analyticMoveLine, false);
|
||||
stockMoveLine.addAnalyticMoveLineListItem(analyticMoveLineCopy);
|
||||
}
|
||||
}
|
||||
return stockMoveLine;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,12 +17,19 @@
|
||||
*/
|
||||
package com.axelor.apps.supplychain.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.axelor.apps.account.db.AnalyticMoveLine;
|
||||
import com.axelor.apps.account.db.repo.AnalyticMoveLineRepository;
|
||||
import com.axelor.apps.purchase.db.PurchaseOrder;
|
||||
import com.axelor.apps.purchase.db.PurchaseOrderLine;
|
||||
import com.axelor.apps.purchase.db.PurchaseRequest;
|
||||
import com.axelor.apps.purchase.db.PurchaseRequestLine;
|
||||
import com.axelor.apps.purchase.service.PurchaseRequestServiceImpl;
|
||||
import com.axelor.apps.stock.db.StockLocation;
|
||||
import com.axelor.apps.stock.db.repo.StockLocationRepository;
|
||||
import com.axelor.exception.AxelorException;
|
||||
import com.axelor.inject.Beans;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
public class PurchaseRequestServiceSupplychainImpl extends PurchaseRequestServiceImpl {
|
||||
@@ -35,6 +42,8 @@ public class PurchaseRequestServiceSupplychainImpl extends PurchaseRequestServic
|
||||
|
||||
PurchaseOrder purchaseOrder = super.createPurchaseOrder(purchaseRequest);
|
||||
purchaseOrder.setStockLocation(purchaseRequest.getStockLocation());
|
||||
purchaseOrder.setAnalyticAccount(purchaseRequest.getAnalyticAccount());
|
||||
purchaseOrder.setAnalyticAxis(purchaseRequest.getAnalyticAxis());
|
||||
return purchaseOrder;
|
||||
}
|
||||
|
||||
@@ -47,4 +56,13 @@ public class PurchaseRequestServiceSupplychainImpl extends PurchaseRequestServic
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setPurchaseOrderLineAnalyticMoveLine(PurchaseRequestLine purchaseRequestLine,PurchaseOrderLine purchaseOrderLine){
|
||||
List<AnalyticMoveLine> analyticMoveLines = purchaseRequestLine.getAnalyticMoveLineList();
|
||||
|
||||
for (AnalyticMoveLine analyticMoveLine : analyticMoveLines) {
|
||||
AnalyticMoveLine aml = Beans.get(AnalyticMoveLineRepository.class).copy(analyticMoveLine, true);
|
||||
purchaseOrderLine.addAnalyticMoveLineListItem(aml);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.axelor.apps.supplychain.service;
|
||||
|
||||
import com.axelor.apps.base.db.Company;
|
||||
import com.axelor.apps.stock.db.StockConfig;
|
||||
import com.axelor.apps.stock.db.StockLocation;
|
||||
import com.axelor.apps.stock.exception.IExceptionMessage;
|
||||
import com.axelor.exception.AxelorException;
|
||||
import com.axelor.exception.db.repo.TraceBackRepository;
|
||||
import com.axelor.i18n.I18n;
|
||||
|
||||
public class StockConfigService {
|
||||
public StockConfig getStockConfig(Company company) throws AxelorException {
|
||||
|
||||
StockConfig stockConfig = company.getStockConfig();
|
||||
|
||||
if (stockConfig == null) {
|
||||
throw new AxelorException(
|
||||
company,
|
||||
TraceBackRepository.CATEGORY_CONFIGURATION_ERROR,
|
||||
I18n.get(IExceptionMessage.STOCK_CONFIG_1),
|
||||
company.getName());
|
||||
}
|
||||
|
||||
return stockConfig;
|
||||
}
|
||||
|
||||
public StockLocation getWarehouseNonCompliant(StockConfig stockConfig)
|
||||
throws AxelorException {
|
||||
if (stockConfig.getPickupDefaultStockLocation() == null) {
|
||||
throw new AxelorException(
|
||||
stockConfig,
|
||||
TraceBackRepository.CATEGORY_CONFIGURATION_ERROR,
|
||||
I18n.get(IExceptionMessage.STOCK_CONFIG_1),
|
||||
stockConfig.getCompany().getName());
|
||||
}
|
||||
return stockConfig.getWarehouseNonCompliant();
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,8 @@
|
||||
*/
|
||||
package com.axelor.apps.supplychain.service;
|
||||
|
||||
import com.axelor.apps.account.db.AnalyticMoveLine;
|
||||
import com.axelor.apps.account.db.repo.AnalyticMoveLineRepository;
|
||||
import com.axelor.apps.base.db.Company;
|
||||
import com.axelor.apps.base.db.Product;
|
||||
import com.axelor.apps.base.db.Unit;
|
||||
@@ -33,6 +35,7 @@ import com.axelor.apps.purchase.service.PurchaseOrderLineService;
|
||||
import com.axelor.apps.purchase.service.PurchaseOrderLineServiceImpl;
|
||||
import com.axelor.apps.purchase.service.PurchaseOrderServiceImpl;
|
||||
import com.axelor.apps.sale.db.SaleOrderLine;
|
||||
import com.axelor.apps.stock.db.InternalTrackingNumber;
|
||||
import com.axelor.apps.stock.db.StockLocation;
|
||||
import com.axelor.apps.stock.db.StockLocationLine;
|
||||
import com.axelor.apps.stock.db.StockMove;
|
||||
@@ -68,7 +71,6 @@ import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RequestScoped
|
||||
@@ -155,6 +157,11 @@ public class StockMoveLineServiceSupplychainImpl extends StockMoveLineServiceImp
|
||||
TrackingNumberConfiguration trackingNumberConfiguration =
|
||||
product.getTrackingNumberConfiguration();
|
||||
|
||||
if(purchaseOrderLine != null){
|
||||
System.out.println("Stepper loading ::::::::::::::::");
|
||||
// this.inheretAccountAnalyticMoveLine(purchaseOrderLine,stockMoveLine);
|
||||
}
|
||||
|
||||
return assignOrGenerateTrackingNumber(
|
||||
stockMoveLine, stockMove, product, trackingNumberConfiguration, type);
|
||||
} else {
|
||||
@@ -172,6 +179,18 @@ public class StockMoveLineServiceSupplychainImpl extends StockMoveLineServiceImp
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
private void inheretAccountAnalyticMoveLine(PurchaseOrderLine purchaseOrderLine, StockMoveLine stockMoveLine) {
|
||||
List<AnalyticMoveLine> analyticMoveLines = purchaseOrderLine.getAnalyticMoveLineList();
|
||||
if(analyticMoveLines.size() != 0){
|
||||
for (AnalyticMoveLine analyticMoveLine : analyticMoveLines) {
|
||||
AnalyticMoveLine aml = Beans.get(AnalyticMoveLineRepository.class).copy(analyticMoveLine, false);
|
||||
aml.setStockMoveLine(stockMoveLine);
|
||||
stockMoveLine.addAnalyticMoveLineListItem(aml);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public StockMoveLine compute(StockMoveLine stockMoveLine, StockMove stockMove)
|
||||
throws AxelorException {
|
||||
@@ -482,35 +501,43 @@ public class StockMoveLineServiceSupplychainImpl extends StockMoveLineServiceImp
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void resetValorization(Long productId, Long stockMoveId, LocalDate toDateTime,Boolean excludeValotisationStocklocation) {
|
||||
public void resetValorization(
|
||||
Long productId,
|
||||
Long stockMoveId,
|
||||
LocalDate toDateTime,
|
||||
Boolean excludeValotisationStocklocation) {
|
||||
StockMove stockMove = Beans.get(StockMoveRepository.class).find(stockMoveId);
|
||||
Product product = Beans.get(ProductRepository.class).find(productId);
|
||||
|
||||
if(excludeValotisationStocklocation){
|
||||
this.stockMoveLines = getStockMoveLines(product, toDateTime, stockMove,true);
|
||||
}else{
|
||||
this.stockMoveLines = getStockMoveLines(product, toDateTime, stockMove,false);
|
||||
if (excludeValotisationStocklocation) {
|
||||
this.stockMoveLines = getStockMoveLines(product, toDateTime, stockMove, true);
|
||||
} else {
|
||||
this.stockMoveLines = getStockMoveLines(product, toDateTime, stockMove, false);
|
||||
}
|
||||
|
||||
|
||||
List<StockMoveLine> lines = new ArrayList<>();
|
||||
|
||||
if(this.stockMoveLines.size() > 1){
|
||||
lines = sliceStockMoveLines(this.stockMoveLines,stockMoveId,product);
|
||||
}else{
|
||||
if (this.stockMoveLines.size() > 1) {
|
||||
lines = sliceStockMoveLines(this.stockMoveLines, stockMoveId, product);
|
||||
} else {
|
||||
lines.addAll(stockMoveLines);
|
||||
}
|
||||
|
||||
|
||||
for (StockMoveLine stockMoveLine : lines) {
|
||||
stockMoveLine.setIsWapUpdated(false);
|
||||
Beans.get(StockMoveLineRepository.class).save(stockMoveLine);
|
||||
}
|
||||
}
|
||||
|
||||
public void fillStockMoveLines(Long productId,LocalDate toDateTime,Long stockMoveId,Boolean excludeValotisationStocklocation){
|
||||
public void fillStockMoveLines(
|
||||
Long productId,
|
||||
LocalDate toDateTime,
|
||||
Long stockMoveId,
|
||||
Boolean excludeValotisationStocklocation) {
|
||||
StockMove stockMove = Beans.get(StockMoveRepository.class).find(stockMoveId);
|
||||
Product product = Beans.get(ProductRepository.class).find(productId);
|
||||
this.stockMoveLines = getStockMoveLines(product, toDateTime, stockMove,excludeValotisationStocklocation);
|
||||
this.stockMoveLines =
|
||||
getStockMoveLines(product, toDateTime, stockMove, excludeValotisationStocklocation);
|
||||
|
||||
System.out.println("***********************stockMoveLines****************************");
|
||||
System.out.println(this.stockMoveLines);
|
||||
@@ -518,7 +545,13 @@ public class StockMoveLineServiceSupplychainImpl extends StockMoveLineServiceImp
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void valorize(Long productId, Long stockMoveId, LocalDate toDateTime, BigDecimal price,Boolean updatePo,Boolean excludeValotisationStocklocation)
|
||||
public void valorize(
|
||||
Long productId,
|
||||
Long stockMoveId,
|
||||
LocalDate toDateTime,
|
||||
BigDecimal price,
|
||||
Boolean updatePo,
|
||||
Boolean excludeValotisationStocklocation)
|
||||
throws AxelorException {
|
||||
StockMove stockMove = Beans.get(StockMoveRepository.class).find(stockMoveId);
|
||||
Product product = Beans.get(ProductRepository.class).find(productId);
|
||||
@@ -530,32 +563,30 @@ public class StockMoveLineServiceSupplychainImpl extends StockMoveLineServiceImp
|
||||
// this.updatePurchaseOrderPrices(stockMove, product, price);
|
||||
// }
|
||||
|
||||
List<StockMoveLine> lines = sliceStockMoveLines(this.stockMoveLines,stockMoveId,product);
|
||||
|
||||
BigDecimal currentQty = this.getTotalQty(product, stockMove.getCompany(),false);
|
||||
BigDecimal oldWap = this.getPreviousWap(lines.get(0),false);
|
||||
|
||||
if(excludeValotisationStocklocation){
|
||||
currentQty = this.getTotalQty(product, stockMove.getCompany(),true);
|
||||
oldWap = this.getPreviousWap(lines.get(0),true);
|
||||
|
||||
}
|
||||
List<StockMoveLine> lines = sliceStockMoveLines(this.stockMoveLines, stockMoveId, product);
|
||||
|
||||
|
||||
BigDecimal currentQty = this.getTotalQty(product, stockMove.getCompany(), false);
|
||||
BigDecimal oldWap = this.getPreviousWap(lines.get(0), false);
|
||||
|
||||
if (excludeValotisationStocklocation) {
|
||||
currentQty = this.getTotalQty(product, stockMove.getCompany(), true);
|
||||
oldWap = this.getPreviousWap(lines.get(0), true);
|
||||
}
|
||||
|
||||
for (StockMoveLine stockMoveLine : lines) {
|
||||
if (stockMoveLine.getStockMove().getFromStockLocation().getTypeSelect()
|
||||
== StockLocationRepository.TYPE_VIRTUAL && stockMoveLine.getStockMove().getToStockLocation().getId() != 6L) {
|
||||
== StockLocationRepository.TYPE_VIRTUAL
|
||||
&& stockMoveLine.getStockMove().getToStockLocation().getId() != 6L) {
|
||||
currentQty = currentQty.subtract(stockMoveLine.getRealQty());
|
||||
} else if (stockMoveLine.getStockMove().getToStockLocation().getTypeSelect()
|
||||
== StockLocationRepository.TYPE_VIRTUAL || (stockMoveLine.getStockMove().getToStockLocation().getId() == 6L && stockMoveLine.getStockMove().getFromStockLocation().getTypeSelect()
|
||||
!= StockLocationRepository.TYPE_VIRTUAL)) {
|
||||
== StockLocationRepository.TYPE_VIRTUAL
|
||||
|| (stockMoveLine.getStockMove().getToStockLocation().getId() == 6L
|
||||
&& stockMoveLine.getStockMove().getFromStockLocation().getTypeSelect()
|
||||
!= StockLocationRepository.TYPE_VIRTUAL)) {
|
||||
currentQty = currentQty.add(stockMoveLine.getRealQty());
|
||||
}
|
||||
System.out.println("..................>>>>>>>>>>>>>>>><<<<<"+currentQty.toString());
|
||||
System.out.println("..................>>>>>>>>>>>>>>>><<<<<" + currentQty.toString());
|
||||
}
|
||||
|
||||
|
||||
|
||||
BigDecimal newQty = lines.get(0).getRealQty();
|
||||
BigDecimal newPrice = price;
|
||||
@@ -566,14 +597,12 @@ public class StockMoveLineServiceSupplychainImpl extends StockMoveLineServiceImp
|
||||
.add(currentQty.multiply(oldWap))
|
||||
.divide(currentQty.add(newQty), scale, BigDecimal.ROUND_HALF_UP);
|
||||
|
||||
|
||||
|
||||
this.updateStockMoveLinePrices(product, price, stockMove, true, newWap);
|
||||
|
||||
int index = 1;
|
||||
List<StockMoveLine> lines2 = new ArrayList<>();
|
||||
if(lines.size() > 1){
|
||||
lines2 = this.stockMoveLineStartingFromIndex(index, lines);
|
||||
if (lines.size() > 1) {
|
||||
lines2 = this.stockMoveLineStartingFromIndex(index, lines);
|
||||
}
|
||||
|
||||
for (StockMoveLine stockMoveLine : lines2) {
|
||||
@@ -596,7 +625,9 @@ public class StockMoveLineServiceSupplychainImpl extends StockMoveLineServiceImp
|
||||
productId,
|
||||
stockMoveLine.getStockMove().getId(),
|
||||
toDateTime,
|
||||
stockMoveLine.getUnitPriceUntaxed(),updatePo,excludeValotisationStocklocation);
|
||||
stockMoveLine.getUnitPriceUntaxed(),
|
||||
updatePo,
|
||||
excludeValotisationStocklocation);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -650,11 +681,19 @@ public class StockMoveLineServiceSupplychainImpl extends StockMoveLineServiceImp
|
||||
// stockMoveLineRepository
|
||||
// .all()
|
||||
// .filter(
|
||||
// "self.stockMove.id = ?1 and self.product.id = ?2 and self.stockMove.statusSelect = 3 and self.realQty > 0",
|
||||
// "self.stockMove.id = ?1 and self.product.id = ?2 and self.stockMove.statusSelect
|
||||
// = 3 and self.realQty > 0",
|
||||
// stockMoveId,
|
||||
// productId)
|
||||
// .fetch();
|
||||
stockMove.getStockMoveLineList().stream().filter(t -> (t.getProduct().getId() == product.getId() && t.getRealQty().compareTo(BigDecimal.ZERO) > 0)).collect(Collectors.toList());
|
||||
stockMove
|
||||
.getStockMoveLineList()
|
||||
.stream()
|
||||
.filter(
|
||||
t ->
|
||||
(t.getProduct().getId() == product.getId()
|
||||
&& t.getRealQty().compareTo(BigDecimal.ZERO) > 0))
|
||||
.collect(Collectors.toList());
|
||||
if (!updatePmp) {
|
||||
for (StockMoveLine stockMoveLine : stockMoveLines) {
|
||||
stockMoveLine.setCompanyUnitPriceUntaxed(price);
|
||||
@@ -695,21 +734,25 @@ public class StockMoveLineServiceSupplychainImpl extends StockMoveLineServiceImp
|
||||
}
|
||||
|
||||
public List<StockMoveLine> getStockMoveLines(
|
||||
Product product, LocalDate toDate, StockMove stockMove,Boolean excludeValotisationStocklocation) {
|
||||
Product product,
|
||||
LocalDate toDate,
|
||||
StockMove stockMove,
|
||||
Boolean excludeValotisationStocklocation) {
|
||||
|
||||
String query =
|
||||
String query =
|
||||
"self.stockMove.statusSelect = ?1 AND self.stockMove.realDate <= ?2 AND self.product = ?3 AND self.stockMove.realDate >= ?4 AND self.realQty > 0 AND (self.archived is null OR self.archived is false)";
|
||||
|
||||
if (excludeValotisationStocklocation) {
|
||||
query += " AND (self.stockMove.toStockLocation.excludeValorisation is true or self.stockMove.fromStockLocation.excludeValorisation is true)";
|
||||
}else{
|
||||
query += " AND ((self.stockMove.toStockLocation.excludeValorisation is false or self.stockMove.toStockLocation.excludeValorisation is null) AND (self.stockMove.fromStockLocation.excludeValorisation is false or self.stockMove.fromStockLocation.excludeValorisation is null))";
|
||||
query +=
|
||||
" AND (self.stockMove.toStockLocation.excludeValorisation is true or self.stockMove.fromStockLocation.excludeValorisation is true)";
|
||||
} else {
|
||||
query +=
|
||||
" AND ((self.stockMove.toStockLocation.excludeValorisation is false or self.stockMove.toStockLocation.excludeValorisation is null) AND (self.stockMove.fromStockLocation.excludeValorisation is false or self.stockMove.fromStockLocation.excludeValorisation is null))";
|
||||
}
|
||||
|
||||
System.out.println("***************getStockMoveLines************");
|
||||
System.out.println(query);
|
||||
System.out.println("***************getStockMoveLines************");
|
||||
|
||||
|
||||
System.out.println("***************getStockMoveLines************");
|
||||
System.out.println(query);
|
||||
System.out.println("***************getStockMoveLines************");
|
||||
|
||||
List<Object> params = Lists.newArrayList();
|
||||
params.add(StockMoveRepository.STATUS_REALIZED);
|
||||
@@ -729,12 +772,14 @@ public class StockMoveLineServiceSupplychainImpl extends StockMoveLineServiceImp
|
||||
return lines;
|
||||
}
|
||||
|
||||
public BigDecimal getPreviousWap(StockMoveLine stockMoveLine,Boolean excludeValotisationStocklocation) {
|
||||
public BigDecimal getPreviousWap(
|
||||
StockMoveLine stockMoveLine, Boolean excludeValotisationStocklocation) {
|
||||
String query =
|
||||
"self.stockMove.statusSelect = ?1 AND self.product = ?2 and self.stockMove.realDate < ?3 AND self.realQty > 0";
|
||||
|
||||
if (excludeValotisationStocklocation) {
|
||||
query += " AND (self.stockMove.toStockLocation.excludeValorisation is true or self.stockMove.fromStockLocation.excludeValorisation is true)";
|
||||
query +=
|
||||
" AND (self.stockMove.toStockLocation.excludeValorisation is true or self.stockMove.fromStockLocation.excludeValorisation is true)";
|
||||
}
|
||||
|
||||
StockMoveLine l = stockMoveLineRepository.find(stockMoveLine.getId());
|
||||
@@ -758,7 +803,8 @@ public class StockMoveLineServiceSupplychainImpl extends StockMoveLineServiceImp
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public BigDecimal getTotalQty(Product product, Company company,Boolean excludeValotisationStocklocation) {
|
||||
public BigDecimal getTotalQty(
|
||||
Product product, Company company, Boolean excludeValotisationStocklocation) {
|
||||
Long productId = product.getId();
|
||||
String query =
|
||||
"SELECT new list(self.id, self.avgPrice, self.currentQty) FROM StockLocationLine as self "
|
||||
@@ -769,15 +815,15 @@ public class StockMoveLineServiceSupplychainImpl extends StockMoveLineServiceImp
|
||||
|
||||
if (excludeValotisationStocklocation) {
|
||||
query += " AND (self.stockLocation.excludeValorisation is true)";
|
||||
}else{
|
||||
query += " AND (self.stockLocation.excludeValorisation is false or self.stockLocation.excludeValorisation is null)";
|
||||
} else {
|
||||
query +=
|
||||
" AND (self.stockLocation.excludeValorisation is false or self.stockLocation.excludeValorisation is null)";
|
||||
}
|
||||
|
||||
if (company != null) {
|
||||
query += " AND self.stockLocation.company = " + company.getId();
|
||||
}
|
||||
|
||||
|
||||
BigDecimal qtyTot = BigDecimal.ZERO;
|
||||
List<List<Object>> results = JPA.em().createQuery(query).getResultList();
|
||||
if (results.isEmpty()) {
|
||||
@@ -791,7 +837,6 @@ public class StockMoveLineServiceSupplychainImpl extends StockMoveLineServiceImp
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
|
||||
System.out.println("***************query*************");
|
||||
System.out.println(query);
|
||||
System.out.println("***************qtyTot*************");
|
||||
@@ -806,7 +851,7 @@ public class StockMoveLineServiceSupplychainImpl extends StockMoveLineServiceImp
|
||||
public void showLines(Long productId, Long stockMoveId, LocalDate toDateTime, BigDecimal price) {
|
||||
StockMove stockMove = Beans.get(StockMoveRepository.class).find(stockMoveId);
|
||||
Product product = Beans.get(ProductRepository.class).find(productId);
|
||||
List<StockMoveLine> lines = getStockMoveLines(product, toDateTime, stockMove,false);
|
||||
List<StockMoveLine> lines = getStockMoveLines(product, toDateTime, stockMove, false);
|
||||
System.out.println("*****************************************************");
|
||||
for (StockMoveLine line : lines) {
|
||||
System.out.println(line.getStockMove().getStockMoveSeq());
|
||||
@@ -837,64 +882,76 @@ public class StockMoveLineServiceSupplychainImpl extends StockMoveLineServiceImp
|
||||
public void valorizeAll(LocalDate fromDateTime, Long productCategoryId) throws AxelorException {
|
||||
// ,67
|
||||
String query =
|
||||
"self.stockMove.statusSelect = ?1 "+
|
||||
"and self.stockMove.realDate >= ?2 and self.realQty > 0 and "+
|
||||
"self.product.familleProduit.id in ("+String.valueOf(productCategoryId)+") and self.stockMove.fromStockLocation.id = 12 and self.stockMove.partner.id != 853";
|
||||
List<Object> params = Lists.newArrayList();
|
||||
params.add(StockMoveRepository.STATUS_REALIZED);
|
||||
params.add(fromDateTime);
|
||||
|
||||
List<StockMoveLine> lines =
|
||||
stockMoveLineRepository
|
||||
.all()
|
||||
.filter(query, params.toArray())
|
||||
.order("stockMove.realDate")
|
||||
.order("id")
|
||||
.fetch();
|
||||
"self.stockMove.statusSelect = ?1 "
|
||||
+ "and self.stockMove.realDate >= ?2 and self.realQty > 0 and "
|
||||
+ "self.product.familleProduit.id in ("
|
||||
+ String.valueOf(productCategoryId)
|
||||
+ ") and self.stockMove.fromStockLocation.id = 12 and self.stockMove.partner.id != 853";
|
||||
List<Object> params = Lists.newArrayList();
|
||||
params.add(StockMoveRepository.STATUS_REALIZED);
|
||||
params.add(fromDateTime);
|
||||
|
||||
List<StockMoveLine> lines =
|
||||
stockMoveLineRepository
|
||||
.all()
|
||||
.filter(query, params.toArray())
|
||||
.order("stockMove.realDate")
|
||||
.order("id")
|
||||
.fetch();
|
||||
|
||||
List<StockMoveLine> distinctLines = new ArrayList<>();
|
||||
List<Product> products = new ArrayList<>();
|
||||
|
||||
for (StockMoveLine line : lines) {
|
||||
if(products.indexOf(line.getProduct()) == -1){
|
||||
if (products.indexOf(line.getProduct()) == -1) {
|
||||
distinctLines.add(line);
|
||||
products.add(line.getProduct());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int index = lines.size();
|
||||
for (StockMoveLine line : distinctLines) {
|
||||
System.out.println("Starting ............... "+String.valueOf(index));
|
||||
System.out.println("Size ............... "+String.valueOf(distinctLines.size()));
|
||||
System.out.println("Starting ............... " + String.valueOf(index));
|
||||
System.out.println("Size ............... " + String.valueOf(distinctLines.size()));
|
||||
System.out.println(line.getStockMove().getStockMoveSeq());
|
||||
System.out.println(line.getProductName());
|
||||
System.out.println(line.getProduct().getId());
|
||||
this.resetValorization(line.getProduct().getId(), line.getStockMove().getId(), LocalDate.now(),false);
|
||||
this.fillStockMoveLines(line.getProduct().getId(), LocalDate.now(), line.getStockMove().getId(),false);
|
||||
this.valorize(line.getProduct().getId(), line.getStockMove().getId(), LocalDate.now(), line.getUnitPriceUntaxed(), false,false);
|
||||
this.resetValorization(
|
||||
line.getProduct().getId(), line.getStockMove().getId(), LocalDate.now(), false);
|
||||
this.fillStockMoveLines(
|
||||
line.getProduct().getId(), LocalDate.now(), line.getStockMove().getId(), false);
|
||||
this.valorize(
|
||||
line.getProduct().getId(),
|
||||
line.getStockMove().getId(),
|
||||
LocalDate.now(),
|
||||
line.getUnitPriceUntaxed(),
|
||||
false,
|
||||
false);
|
||||
System.out.println("End .....................");
|
||||
index --;
|
||||
index--;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public List<StockMoveLine> sliceStockMoveLines(
|
||||
List<StockMoveLine> lines, Long stockMoveId, Product product) {
|
||||
|
||||
public List<StockMoveLine> sliceStockMoveLines(List<StockMoveLine> lines,Long stockMoveId,Product product){
|
||||
|
||||
StockMoveLine emp = lines.stream().filter((t) -> {
|
||||
return t.getStockMove().getId() == stockMoveId && t.getProduct() == product;
|
||||
}).findFirst().orElse(null);
|
||||
StockMoveLine emp =
|
||||
lines
|
||||
.stream()
|
||||
.filter(
|
||||
(t) -> {
|
||||
return t.getStockMove().getId() == stockMoveId && t.getProduct() == product;
|
||||
})
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
int index = lines.indexOf(emp);
|
||||
int index = lines.indexOf(emp);
|
||||
|
||||
List<StockMoveLine> slicedLines = new ArrayList<>();
|
||||
|
||||
for (int i = index; i < lines.size(); i++) {
|
||||
slicedLines.add(lines.get(i));
|
||||
}
|
||||
return slicedLines;
|
||||
List<StockMoveLine> slicedLines = new ArrayList<>();
|
||||
|
||||
for (int i = index; i < lines.size(); i++) {
|
||||
slicedLines.add(lines.get(i));
|
||||
}
|
||||
return slicedLines;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,8 +14,6 @@ import com.axelor.apps.supplychain.db.SupplierRating;
|
||||
import com.axelor.apps.supplychain.db.repo.SupplierRatingRepository;
|
||||
import com.axelor.inject.Beans;
|
||||
import com.google.inject.persist.Transactional;
|
||||
import com.thoughtworks.xstream.mapper.Mapper;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.LocalDate;
|
||||
@@ -26,353 +24,354 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class SupplierRatingServiceImpl implements SupplierRatingService {
|
||||
|
||||
public final int COEF_PAYMENT_DELAY = 1;
|
||||
public final int COEF_DELIVERY_TIME = 1;
|
||||
public final int COEF_COMPLIANCE_WITH_TECHNICAL_SPECIFICATIONS = 3;
|
||||
public final int COEF_PRICE = 3;
|
||||
public final int COEF_QUANTITY_COMPLIANCE = 1;
|
||||
public final int COEF_COMPLAINT_MANAGEMENT = 1;
|
||||
public final int COEF_PRICE_STABILITY = 1;
|
||||
public final int SUM_COEF =
|
||||
COEF_PAYMENT_DELAY
|
||||
+ COEF_DELIVERY_TIME
|
||||
+ COEF_COMPLIANCE_WITH_TECHNICAL_SPECIFICATIONS
|
||||
+ COEF_PRICE
|
||||
+ COEF_QUANTITY_COMPLIANCE
|
||||
+ COEF_COMPLAINT_MANAGEMENT
|
||||
+ COEF_PRICE_STABILITY;
|
||||
public final int COEF_PAYMENT_DELAY = 1;
|
||||
public final int COEF_DELIVERY_TIME = 1;
|
||||
public final int COEF_COMPLIANCE_WITH_TECHNICAL_SPECIFICATIONS = 3;
|
||||
public final int COEF_PRICE = 3;
|
||||
public final int COEF_QUANTITY_COMPLIANCE = 1;
|
||||
public final int COEF_COMPLAINT_MANAGEMENT = 1;
|
||||
public final int COEF_PRICE_STABILITY = 1;
|
||||
public final int SUM_COEF =
|
||||
COEF_PAYMENT_DELAY
|
||||
+ COEF_DELIVERY_TIME
|
||||
+ COEF_COMPLIANCE_WITH_TECHNICAL_SPECIFICATIONS
|
||||
+ COEF_PRICE
|
||||
+ COEF_QUANTITY_COMPLIANCE
|
||||
+ COEF_COMPLAINT_MANAGEMENT
|
||||
+ COEF_PRICE_STABILITY;
|
||||
|
||||
public void calculatRating(SupplierRating supplierRating) {
|
||||
Integer paymentDelayRatingSelect = supplierRating.getPaymentDelayRatingSelect();
|
||||
Integer deliveryTimeRatingSelect = supplierRating.getDeliveryTimeRatingSelect();
|
||||
Integer complianceWithTechnicalSpecificationsRatingSelect =
|
||||
supplierRating.getComplianceWithTechnicalSpecificationsRatingSelect();
|
||||
Integer priceRatingSelect = supplierRating.getPriceRatingSelect();
|
||||
Integer quantityComplianceRatingSelect = supplierRating.getQuantityComplianceRatingSelect();
|
||||
Integer complaintManagementRatingSelect = supplierRating.getComplaintManagementRatingSelect();
|
||||
Integer priceStabilityRatingSelect = supplierRating.getPriceStabilityRatingSelect();
|
||||
public void calculatRating(SupplierRating supplierRating) {
|
||||
Integer paymentDelayRatingSelect = supplierRating.getPaymentDelayRatingSelect();
|
||||
Integer deliveryTimeRatingSelect = supplierRating.getDeliveryTimeRatingSelect();
|
||||
Integer complianceWithTechnicalSpecificationsRatingSelect =
|
||||
supplierRating.getComplianceWithTechnicalSpecificationsRatingSelect();
|
||||
Integer priceRatingSelect = supplierRating.getPriceRatingSelect();
|
||||
Integer quantityComplianceRatingSelect = supplierRating.getQuantityComplianceRatingSelect();
|
||||
Integer complaintManagementRatingSelect = supplierRating.getComplaintManagementRatingSelect();
|
||||
Integer priceStabilityRatingSelect = supplierRating.getPriceStabilityRatingSelect();
|
||||
|
||||
// Calculate the overall score based on ratings
|
||||
int score =
|
||||
(paymentDelayRatingSelect * COEF_PAYMENT_DELAY)
|
||||
+ (deliveryTimeRatingSelect * COEF_DELIVERY_TIME)
|
||||
+ (complianceWithTechnicalSpecificationsRatingSelect
|
||||
* COEF_COMPLIANCE_WITH_TECHNICAL_SPECIFICATIONS)
|
||||
+ (priceRatingSelect * COEF_PRICE)
|
||||
+ (quantityComplianceRatingSelect * COEF_QUANTITY_COMPLIANCE)
|
||||
+ (complaintManagementRatingSelect * COEF_COMPLAINT_MANAGEMENT)
|
||||
+ (priceStabilityRatingSelect * COEF_PRICE_STABILITY);
|
||||
// Calculate the overall score based on ratings
|
||||
int score =
|
||||
(paymentDelayRatingSelect * COEF_PAYMENT_DELAY)
|
||||
+ (deliveryTimeRatingSelect * COEF_DELIVERY_TIME)
|
||||
+ (complianceWithTechnicalSpecificationsRatingSelect
|
||||
* COEF_COMPLIANCE_WITH_TECHNICAL_SPECIFICATIONS)
|
||||
+ (priceRatingSelect * COEF_PRICE)
|
||||
+ (quantityComplianceRatingSelect * COEF_QUANTITY_COMPLIANCE)
|
||||
+ (complaintManagementRatingSelect * COEF_COMPLAINT_MANAGEMENT)
|
||||
+ (priceStabilityRatingSelect * COEF_PRICE_STABILITY);
|
||||
|
||||
// Set the overall score
|
||||
BigDecimal overallScore =
|
||||
BigDecimal.valueOf(score * 20)
|
||||
.divide(BigDecimal.valueOf(SUM_COEF * 3), 2, BigDecimal.ROUND_HALF_UP);
|
||||
supplierRating.setOverallScore(overallScore);
|
||||
// Set the overall score
|
||||
BigDecimal overallScore =
|
||||
BigDecimal.valueOf(score * 20)
|
||||
.divide(BigDecimal.valueOf(SUM_COEF * 3), 2, BigDecimal.ROUND_HALF_UP);
|
||||
supplierRating.setOverallScore(overallScore);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void createRating(StockMove stockMove) {
|
||||
|
||||
StockMove stockMoveOrigin = stockMove.getStockMoveOrigin();
|
||||
Boolean isWithBackorder = stockMove.getIsWithBackorder();
|
||||
|
||||
if (stockMoveOrigin == null) {
|
||||
LocalDateTime realDate;
|
||||
if (isWithBackorder == true) {
|
||||
realDate = stockMove.getRealDate();
|
||||
} else {
|
||||
realDate = LocalDateTime.now();
|
||||
}
|
||||
|
||||
Partner partner = stockMove.getPartner();
|
||||
|
||||
// Stock Move Lines
|
||||
List<StockMoveLine> stockMoveLinesList = stockMove.getStockMoveLineList();
|
||||
|
||||
// Purchase Order
|
||||
Long originId = stockMove.getOriginId();
|
||||
PurchaseOrder purchaseOrder = Beans.get(PurchaseOrderRepository.class).find(originId);
|
||||
|
||||
// Purchase Order Lines
|
||||
List<PurchaseOrderLine> purchaseOrderLinesList = purchaseOrder.getPurchaseOrderLineList();
|
||||
|
||||
// Délai de payment
|
||||
PaymentCondition paymentCondition = purchaseOrder.getPaymentCondition();
|
||||
Integer paymentTime = paymentCondition.getPaymentTime();
|
||||
Integer paymentDelayRatingSelect = calculatPaymentDelayRatingSelect(paymentTime);
|
||||
|
||||
// Date
|
||||
LocalDate estimatedDate = purchaseOrder.getDeliveryDate();
|
||||
Integer deliveryTimeRatingSelect = calculatDeliveryTimeRatingSelect(estimatedDate, realDate);
|
||||
|
||||
// Quantité
|
||||
Integer quantityComplianceRatingSelect =
|
||||
calculatQuantityComplianceRatingSelect(stockMoveLinesList);
|
||||
|
||||
// Stabilité des prix
|
||||
Integer priceStabilityRatingSelect =
|
||||
calculatPriceStabilityRatingSelectLastPrice(purchaseOrderLinesList, partner);
|
||||
|
||||
// Creation
|
||||
SupplierRating supplierRating = new SupplierRating();
|
||||
supplierRating.setPaymentDelayRatingSelect(paymentDelayRatingSelect);
|
||||
supplierRating.setDeliveryTimeRatingSelect(deliveryTimeRatingSelect);
|
||||
supplierRating.setQuantityComplianceRatingSelect(quantityComplianceRatingSelect);
|
||||
supplierRating.setPriceStabilityRatingSelect(priceStabilityRatingSelect);
|
||||
supplierRating.setPurchaseOrder(purchaseOrder);
|
||||
supplierRating.setSupplierPartner(partner);
|
||||
Beans.get(SupplierRatingRepository.class).save(supplierRating);
|
||||
|
||||
} else {
|
||||
// Purchase Order
|
||||
Long originId = stockMove.getOriginId();
|
||||
PurchaseOrder purchaseOrder = Beans.get(PurchaseOrderRepository.class).find(originId);
|
||||
|
||||
List<StockMove> originStockMoves =
|
||||
Beans.get(StockMoveRepository.class)
|
||||
.all()
|
||||
.fetch()
|
||||
.stream()
|
||||
.filter(t -> t.getOriginId() == originId && t.getStatusSelect() == 3)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// Purchase Order Lines
|
||||
List<PurchaseOrderLine> purchaseOrderLinesList = purchaseOrder.getPurchaseOrderLineList();
|
||||
|
||||
// Related Stock Moves Lines
|
||||
List<StockMoveLine> originStockMovesLines = new ArrayList<>();
|
||||
for (StockMove originStockMove : originStockMoves) {
|
||||
// Stock Move Lines
|
||||
List<StockMoveLine> originStockMovesLinesList = originStockMove.getStockMoveLineList();
|
||||
originStockMovesLines.addAll(originStockMovesLinesList);
|
||||
}
|
||||
// Quantité
|
||||
Integer quantityComplianceRatingSelect =
|
||||
calculatQuantityComplianceRatingSelect(purchaseOrderLinesList, originStockMovesLines);
|
||||
|
||||
// update
|
||||
SupplierRating supplierRating = purchaseOrder.getSupplierRating();
|
||||
supplierRating.setQuantityComplianceRatingSelect(quantityComplianceRatingSelect);
|
||||
}
|
||||
}
|
||||
|
||||
private Integer calculatPaymentDelayRatingSelect(Integer paymentTime) {
|
||||
Integer paymentDelayRatingSelect;
|
||||
if (paymentTime == 0) {
|
||||
paymentDelayRatingSelect = 0;
|
||||
} else if (paymentTime <= 15) {
|
||||
paymentDelayRatingSelect = 1;
|
||||
} else if (paymentTime <= 30) {
|
||||
paymentDelayRatingSelect = 2;
|
||||
} else {
|
||||
paymentDelayRatingSelect = 3;
|
||||
}
|
||||
return paymentDelayRatingSelect;
|
||||
}
|
||||
|
||||
private Integer calculatDeliveryTimeRatingSelect(
|
||||
LocalDate estimatedDate, LocalDateTime realDate) {
|
||||
int deliveryTimeRatingSelect;
|
||||
if (realDate.toLocalDate().isBefore(estimatedDate.plusDays(1))) {
|
||||
deliveryTimeRatingSelect = 3;
|
||||
} else if (realDate.toLocalDate().isBefore(estimatedDate.plusDays(5))) {
|
||||
deliveryTimeRatingSelect = 2;
|
||||
} else if (realDate.toLocalDate().isBefore(estimatedDate.plusDays(15))) {
|
||||
deliveryTimeRatingSelect = 1;
|
||||
} else {
|
||||
deliveryTimeRatingSelect = 0;
|
||||
}
|
||||
return deliveryTimeRatingSelect;
|
||||
}
|
||||
|
||||
private Integer calculatQuantityComplianceRatingSelect(List<StockMoveLine> stockMoveLinesList) {
|
||||
// Calculate total ordered quantity
|
||||
BigDecimal totalOrderedQty = BigDecimal.ZERO;
|
||||
BigDecimal totalReceivedQty = BigDecimal.ZERO;
|
||||
for (StockMoveLine stockMoveLine : stockMoveLinesList) {
|
||||
BigDecimal orderedQty = stockMoveLine.getQty();
|
||||
totalOrderedQty = totalOrderedQty.add(orderedQty);
|
||||
BigDecimal receivedQty = stockMoveLine.getRealQty();
|
||||
totalReceivedQty = totalReceivedQty.add(receivedQty);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void createRating(StockMove stockMove) {
|
||||
|
||||
StockMove stockMoveOrigin = stockMove.getStockMoveOrigin();
|
||||
Boolean isWithBackorder = stockMove.getIsWithBackorder();
|
||||
|
||||
if (stockMoveOrigin == null) {
|
||||
LocalDateTime realDate;
|
||||
if (isWithBackorder == true) {
|
||||
realDate = stockMove.getRealDate();
|
||||
} else {
|
||||
realDate = LocalDateTime.now();
|
||||
}
|
||||
|
||||
Partner partner = stockMove.getPartner();
|
||||
|
||||
// Stock Move Lines
|
||||
List<StockMoveLine> stockMoveLinesList = stockMove.getStockMoveLineList();
|
||||
|
||||
// Purchase Order
|
||||
Long originId = stockMove.getOriginId();
|
||||
PurchaseOrder purchaseOrder = Beans.get(PurchaseOrderRepository.class).find(originId);
|
||||
|
||||
// Purchase Order Lines
|
||||
List<PurchaseOrderLine> purchaseOrderLinesList = purchaseOrder.getPurchaseOrderLineList();
|
||||
|
||||
// Délai de payment
|
||||
PaymentCondition paymentCondition = purchaseOrder.getPaymentCondition();
|
||||
Integer paymentTime = paymentCondition.getPaymentTime();
|
||||
Integer paymentDelayRatingSelect = calculatPaymentDelayRatingSelect(paymentTime);
|
||||
|
||||
// Date
|
||||
LocalDate estimatedDate = purchaseOrder.getDeliveryDate();
|
||||
Integer deliveryTimeRatingSelect = calculatDeliveryTimeRatingSelect(estimatedDate, realDate);
|
||||
|
||||
// Quantité
|
||||
Integer quantityComplianceRatingSelect =
|
||||
calculatQuantityComplianceRatingSelect(stockMoveLinesList);
|
||||
|
||||
// Stabilité des prix
|
||||
Integer priceStabilityRatingSelect =
|
||||
calculatPriceStabilityRatingSelectLastPrice(purchaseOrderLinesList, partner);
|
||||
|
||||
// Creation
|
||||
SupplierRating supplierRating = new SupplierRating();
|
||||
supplierRating.setPaymentDelayRatingSelect(paymentDelayRatingSelect);
|
||||
supplierRating.setDeliveryTimeRatingSelect(deliveryTimeRatingSelect);
|
||||
supplierRating.setQuantityComplianceRatingSelect(quantityComplianceRatingSelect);
|
||||
supplierRating.setPriceStabilityRatingSelect(priceStabilityRatingSelect);
|
||||
supplierRating.setPurchaseOrder(purchaseOrder);
|
||||
supplierRating.setSupplierPartner(partner);
|
||||
Beans.get(SupplierRatingRepository.class).save(supplierRating);
|
||||
|
||||
} else {
|
||||
// Purchase Order
|
||||
Long originId = stockMove.getOriginId();
|
||||
PurchaseOrder purchaseOrder = Beans.get(PurchaseOrderRepository.class).find(originId);
|
||||
|
||||
List<StockMove> originStockMoves =
|
||||
Beans.get(StockMoveRepository.class)
|
||||
.all()
|
||||
.fetch()
|
||||
.stream()
|
||||
.filter(t -> t.getOriginId() == originId && t.getStatusSelect() == 3)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// Purchase Order Lines
|
||||
List<PurchaseOrderLine> purchaseOrderLinesList = purchaseOrder.getPurchaseOrderLineList();
|
||||
|
||||
// Related Stock Moves Lines
|
||||
List<StockMoveLine> originStockMovesLines = new ArrayList<>();
|
||||
for (StockMove originStockMove : originStockMoves) {
|
||||
// Stock Move Lines
|
||||
List<StockMoveLine> originStockMovesLinesList = originStockMove.getStockMoveLineList();
|
||||
originStockMovesLines.addAll(originStockMovesLinesList);
|
||||
}
|
||||
// Quantité
|
||||
Integer quantityComplianceRatingSelect =
|
||||
calculatQuantityComplianceRatingSelect(purchaseOrderLinesList, originStockMovesLines);
|
||||
|
||||
// update
|
||||
SupplierRating supplierRating = purchaseOrder.getSupplierRating();
|
||||
supplierRating.setQuantityComplianceRatingSelect(quantityComplianceRatingSelect);
|
||||
}
|
||||
// Calculate quantity compliance
|
||||
BigDecimal compliancePercentage;
|
||||
if (totalOrderedQty.compareTo(BigDecimal.ZERO) != 0) {
|
||||
compliancePercentage =
|
||||
totalReceivedQty
|
||||
.divide(totalOrderedQty, 2, RoundingMode.HALF_UP)
|
||||
.multiply(BigDecimal.valueOf(100));
|
||||
} else {
|
||||
// Handle division by zero if necessary
|
||||
compliancePercentage = BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
private Integer calculatPaymentDelayRatingSelect(Integer paymentTime) {
|
||||
Integer paymentDelayRatingSelect;
|
||||
if (paymentTime == 0) {
|
||||
paymentDelayRatingSelect = 0;
|
||||
} else if (paymentTime <= 15) {
|
||||
paymentDelayRatingSelect = 1;
|
||||
} else if (paymentTime <= 30) {
|
||||
paymentDelayRatingSelect = 2;
|
||||
} else {
|
||||
paymentDelayRatingSelect = 3;
|
||||
}
|
||||
return paymentDelayRatingSelect;
|
||||
System.out.println("totalOrderedQty1:" + totalOrderedQty);
|
||||
System.out.println("totalReceivedQty1:" + totalReceivedQty);
|
||||
System.out.println("compliancePercentage1:" + compliancePercentage);
|
||||
|
||||
// Determine quantityComplianceRatingSelect based on compliancePercentage
|
||||
Integer quantityComplianceRatingSelect;
|
||||
if (compliancePercentage.compareTo(BigDecimal.valueOf(100)) >= 0) {
|
||||
quantityComplianceRatingSelect = 3;
|
||||
} else if (compliancePercentage.compareTo(BigDecimal.valueOf(80)) >= 0) {
|
||||
quantityComplianceRatingSelect = 2;
|
||||
} else if (compliancePercentage.compareTo(BigDecimal.valueOf(70)) >= 0) {
|
||||
quantityComplianceRatingSelect = 1;
|
||||
} else {
|
||||
quantityComplianceRatingSelect = 0;
|
||||
}
|
||||
return quantityComplianceRatingSelect;
|
||||
}
|
||||
|
||||
private Integer calculatQuantityComplianceRatingSelect(
|
||||
List<PurchaseOrderLine> purchaseOrderLineslist, List<StockMoveLine> stockMoveLinesList) {
|
||||
// Calculate total ordered quantity
|
||||
BigDecimal totalOrderedQty = BigDecimal.ZERO;
|
||||
BigDecimal totalReceivedQty = BigDecimal.ZERO;
|
||||
for (StockMoveLine stockMoveLine : stockMoveLinesList) {
|
||||
BigDecimal receivedQty = stockMoveLine.getRealQty();
|
||||
totalReceivedQty = totalReceivedQty.add(receivedQty);
|
||||
}
|
||||
|
||||
private Integer calculatDeliveryTimeRatingSelect(LocalDate estimatedDate, LocalDateTime realDate) {
|
||||
int deliveryTimeRatingSelect;
|
||||
if (realDate.toLocalDate().isBefore(estimatedDate.plusDays(1))) {
|
||||
deliveryTimeRatingSelect = 3;
|
||||
} else if (realDate.toLocalDate().isBefore(estimatedDate.plusDays(5))) {
|
||||
deliveryTimeRatingSelect = 2;
|
||||
} else if (realDate.toLocalDate().isBefore(estimatedDate.plusDays(15))) {
|
||||
deliveryTimeRatingSelect = 1;
|
||||
} else {
|
||||
deliveryTimeRatingSelect = 0;
|
||||
}
|
||||
return deliveryTimeRatingSelect;
|
||||
for (PurchaseOrderLine purchaseOrderLine : purchaseOrderLineslist) {
|
||||
BigDecimal orderedQty = purchaseOrderLine.getQty();
|
||||
totalOrderedQty = totalOrderedQty.add(orderedQty);
|
||||
}
|
||||
// Calculate quantity compliance
|
||||
BigDecimal compliancePercentage;
|
||||
if (totalOrderedQty.compareTo(BigDecimal.ZERO) != 0) {
|
||||
compliancePercentage =
|
||||
totalReceivedQty
|
||||
.divide(totalOrderedQty, 2, RoundingMode.HALF_UP)
|
||||
.multiply(BigDecimal.valueOf(100));
|
||||
} else {
|
||||
// Handle division by zero if necessary
|
||||
compliancePercentage = BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
private Integer calculatQuantityComplianceRatingSelect(List<StockMoveLine> stockMoveLinesList) {
|
||||
// Calculate total ordered quantity
|
||||
BigDecimal totalOrderedQty = BigDecimal.ZERO;
|
||||
BigDecimal totalReceivedQty = BigDecimal.ZERO;
|
||||
for (StockMoveLine stockMoveLine : stockMoveLinesList) {
|
||||
BigDecimal orderedQty = stockMoveLine.getQty();
|
||||
totalOrderedQty = totalOrderedQty.add(orderedQty);
|
||||
BigDecimal receivedQty = stockMoveLine.getRealQty();
|
||||
totalReceivedQty = totalReceivedQty.add(receivedQty);
|
||||
}
|
||||
System.out.println("totalOrderedQty2:" + totalOrderedQty);
|
||||
System.out.println("totalReceivedQty2:" + totalReceivedQty);
|
||||
System.out.println("compliancePercentage2:" + compliancePercentage);
|
||||
|
||||
// Calculate quantity compliance
|
||||
BigDecimal compliancePercentage;
|
||||
if (totalOrderedQty.compareTo(BigDecimal.ZERO) != 0) {
|
||||
compliancePercentage =
|
||||
totalReceivedQty
|
||||
.divide(totalOrderedQty, 2, RoundingMode.HALF_UP)
|
||||
.multiply(BigDecimal.valueOf(100));
|
||||
} else {
|
||||
// Handle division by zero if necessary
|
||||
compliancePercentage = BigDecimal.ZERO;
|
||||
}
|
||||
// Determine quantityComplianceRatingSelect based on compliancePercentage
|
||||
Integer quantityComplianceRatingSelect;
|
||||
if (compliancePercentage.compareTo(BigDecimal.valueOf(100)) >= 0) {
|
||||
quantityComplianceRatingSelect = 3;
|
||||
} else if (compliancePercentage.compareTo(BigDecimal.valueOf(80)) >= 0) {
|
||||
quantityComplianceRatingSelect = 2;
|
||||
} else if (compliancePercentage.compareTo(BigDecimal.valueOf(70)) >= 0) {
|
||||
quantityComplianceRatingSelect = 1;
|
||||
} else {
|
||||
quantityComplianceRatingSelect = 0;
|
||||
}
|
||||
return quantityComplianceRatingSelect;
|
||||
}
|
||||
|
||||
System.out.println("totalOrderedQty1:" + totalOrderedQty);
|
||||
System.out.println("totalReceivedQty1:" + totalReceivedQty);
|
||||
System.out.println("compliancePercentage1:" + compliancePercentage);
|
||||
|
||||
// Determine quantityComplianceRatingSelect based on compliancePercentage
|
||||
Integer quantityComplianceRatingSelect;
|
||||
if (compliancePercentage.compareTo(BigDecimal.valueOf(100)) >= 0) {
|
||||
quantityComplianceRatingSelect = 3;
|
||||
} else if (compliancePercentage.compareTo(BigDecimal.valueOf(80)) >= 0) {
|
||||
quantityComplianceRatingSelect = 2;
|
||||
} else if (compliancePercentage.compareTo(BigDecimal.valueOf(70)) >= 0) {
|
||||
quantityComplianceRatingSelect = 1;
|
||||
} else {
|
||||
quantityComplianceRatingSelect = 0;
|
||||
}
|
||||
return quantityComplianceRatingSelect;
|
||||
private Integer calculatPriceStabilityRatingSelect(
|
||||
List<PurchaseOrderLine> purchaseOrderLinesList, Partner partner) {
|
||||
List<Product> products = new ArrayList<>();
|
||||
for (PurchaseOrderLine purchaseOrderLine : purchaseOrderLinesList) {
|
||||
Product product = purchaseOrderLine.getProduct();
|
||||
products.add(product);
|
||||
}
|
||||
|
||||
private Integer calculatQuantityComplianceRatingSelect(
|
||||
List<PurchaseOrderLine> purchaseOrderLineslist, List<StockMoveLine> stockMoveLinesList) {
|
||||
// Calculate total ordered quantity
|
||||
BigDecimal totalOrderedQty = BigDecimal.ZERO;
|
||||
BigDecimal totalReceivedQty = BigDecimal.ZERO;
|
||||
for (StockMoveLine stockMoveLine : stockMoveLinesList) {
|
||||
BigDecimal receivedQty = stockMoveLine.getRealQty();
|
||||
totalReceivedQty = totalReceivedQty.add(receivedQty);
|
||||
}
|
||||
|
||||
for (PurchaseOrderLine purchaseOrderLine : purchaseOrderLineslist) {
|
||||
BigDecimal orderedQty = purchaseOrderLine.getQty();
|
||||
totalOrderedQty = totalOrderedQty.add(orderedQty);
|
||||
}
|
||||
// Calculate quantity compliance
|
||||
BigDecimal compliancePercentage;
|
||||
if (totalOrderedQty.compareTo(BigDecimal.ZERO) != 0) {
|
||||
compliancePercentage =
|
||||
totalReceivedQty
|
||||
.divide(totalOrderedQty, 2, RoundingMode.HALF_UP)
|
||||
.multiply(BigDecimal.valueOf(100));
|
||||
} else {
|
||||
// Handle division by zero if necessary
|
||||
compliancePercentage = BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
System.out.println("totalOrderedQty2:" + totalOrderedQty);
|
||||
System.out.println("totalReceivedQty2:" + totalReceivedQty);
|
||||
System.out.println("compliancePercentage2:" + compliancePercentage);
|
||||
|
||||
// Determine quantityComplianceRatingSelect based on compliancePercentage
|
||||
Integer quantityComplianceRatingSelect;
|
||||
if (compliancePercentage.compareTo(BigDecimal.valueOf(100)) >= 0) {
|
||||
quantityComplianceRatingSelect = 3;
|
||||
} else if (compliancePercentage.compareTo(BigDecimal.valueOf(80)) >= 0) {
|
||||
quantityComplianceRatingSelect = 2;
|
||||
} else if (compliancePercentage.compareTo(BigDecimal.valueOf(70)) >= 0) {
|
||||
quantityComplianceRatingSelect = 1;
|
||||
} else {
|
||||
quantityComplianceRatingSelect = 0;
|
||||
}
|
||||
return quantityComplianceRatingSelect;
|
||||
List<BigDecimal> averages = new ArrayList<>();
|
||||
for (Product product : products) {
|
||||
BigDecimal avg = calculateAvgProduct(product, partner);
|
||||
averages.add(avg);
|
||||
}
|
||||
|
||||
private Integer calculatPriceStabilityRatingSelect(
|
||||
List<PurchaseOrderLine> purchaseOrderLinesList, Partner partner) {
|
||||
List<Product> products = new ArrayList<>();
|
||||
for (PurchaseOrderLine purchaseOrderLine : purchaseOrderLinesList) {
|
||||
Product product = purchaseOrderLine.getProduct();
|
||||
products.add(product);
|
||||
}
|
||||
List<BigDecimal> differences = new ArrayList<>();
|
||||
for (int i = 0; i < purchaseOrderLinesList.size(); i++) {
|
||||
BigDecimal price = purchaseOrderLinesList.get(i).getPrice();
|
||||
BigDecimal avg = averages.get(i);
|
||||
|
||||
List<BigDecimal> averages = new ArrayList<>();
|
||||
for (Product product : products) {
|
||||
BigDecimal avg = calculateAvgProduct(product, partner);
|
||||
averages.add(avg);
|
||||
}
|
||||
BigDecimal difference = price.subtract(avg);
|
||||
BigDecimal percentage =
|
||||
difference.divide(avg, 4, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
|
||||
|
||||
List<BigDecimal> differences = new ArrayList<>();
|
||||
for (int i = 0; i < purchaseOrderLinesList.size(); i++) {
|
||||
BigDecimal price = purchaseOrderLinesList.get(i).getPrice();
|
||||
BigDecimal avg = averages.get(i);
|
||||
|
||||
BigDecimal difference = price.subtract(avg);
|
||||
BigDecimal percentage =
|
||||
difference.divide(avg, 4, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100));
|
||||
|
||||
differences.add(percentage.abs());
|
||||
}
|
||||
|
||||
BigDecimal totalDifference = BigDecimal.ZERO;
|
||||
for (BigDecimal difference : differences) {
|
||||
totalDifference = totalDifference.add(difference);
|
||||
}
|
||||
|
||||
// Calculate the average percentage difference
|
||||
BigDecimal averageDifference =
|
||||
totalDifference.divide(BigDecimal.valueOf(differences.size()), 2, BigDecimal.ROUND_HALF_UP);
|
||||
|
||||
// Determine priceStabilityRatingSelect based on the average percentage difference
|
||||
Integer priceStabilityRatingSelect;
|
||||
if (averageDifference.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
priceStabilityRatingSelect = 3; // Stable prices
|
||||
} else if (averageDifference.compareTo(BigDecimal.valueOf(5)) <= 0) {
|
||||
priceStabilityRatingSelect = 2; // Moderately stable prices
|
||||
} else if (averageDifference.compareTo(BigDecimal.valueOf(10)) <= 0) {
|
||||
priceStabilityRatingSelect = 1; // Unstable prices
|
||||
} else {
|
||||
priceStabilityRatingSelect = 0;
|
||||
}
|
||||
|
||||
return priceStabilityRatingSelect;
|
||||
differences.add(percentage.abs());
|
||||
}
|
||||
|
||||
private Integer calculatPriceStabilityRatingSelectLastPrice(
|
||||
List<PurchaseOrderLine> purchaseOrderLinesList, Partner partner) {
|
||||
List<Product> products = new ArrayList<>();
|
||||
for (PurchaseOrderLine purchaseOrderLine : purchaseOrderLinesList) {
|
||||
Product product = purchaseOrderLine.getProduct();
|
||||
products.add(product);
|
||||
}
|
||||
|
||||
List<BigDecimal> lastPrices = new ArrayList<>();
|
||||
for (Product product : products) {
|
||||
BigDecimal lastPrice = getLastPriceProduct(product, partner);
|
||||
lastPrices.add(lastPrice);
|
||||
}
|
||||
|
||||
List<BigDecimal> differences = new ArrayList<>();
|
||||
for (int i = 0; i < purchaseOrderLinesList.size(); i++) {
|
||||
BigDecimal price = purchaseOrderLinesList.get(i).getPrice();
|
||||
BigDecimal lastPrice = lastPrices.get(i);
|
||||
|
||||
BigDecimal difference = price.subtract(lastPrice);
|
||||
BigDecimal percentage =
|
||||
difference
|
||||
.divide(lastPrice, 4, BigDecimal.ROUND_HALF_UP)
|
||||
.multiply(BigDecimal.valueOf(100));
|
||||
|
||||
differences.add(percentage);
|
||||
}
|
||||
|
||||
BigDecimal totalDifference = BigDecimal.ZERO;
|
||||
for (BigDecimal difference : differences) {
|
||||
totalDifference = totalDifference.add(difference);
|
||||
}
|
||||
|
||||
// Calculate the average percentage difference
|
||||
BigDecimal averageDifference =
|
||||
totalDifference.divide(BigDecimal.valueOf(differences.size()), 2, BigDecimal.ROUND_HALF_UP);
|
||||
|
||||
// Determine priceStabilityRatingSelect based on the average percentage difference
|
||||
Integer priceStabilityRatingSelect;
|
||||
if (averageDifference.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
priceStabilityRatingSelect = 3; // Stable prices
|
||||
} else if (averageDifference.compareTo(BigDecimal.valueOf(5)) <= 0) {
|
||||
priceStabilityRatingSelect = 2; // Moderately stable prices
|
||||
} else if (averageDifference.compareTo(BigDecimal.valueOf(10)) <= 0) {
|
||||
priceStabilityRatingSelect = 1; // Unstable prices
|
||||
} else {
|
||||
priceStabilityRatingSelect = 0;
|
||||
}
|
||||
|
||||
return priceStabilityRatingSelect;
|
||||
BigDecimal totalDifference = BigDecimal.ZERO;
|
||||
for (BigDecimal difference : differences) {
|
||||
totalDifference = totalDifference.add(difference);
|
||||
}
|
||||
|
||||
private BigDecimal calculateAvgProduct(Product product, Partner partner) {
|
||||
// Beans.get(PurchaseOrderRepository.class).find(originId);
|
||||
// Calculate the average percentage difference
|
||||
BigDecimal averageDifference =
|
||||
totalDifference.divide(BigDecimal.valueOf(differences.size()), 2, BigDecimal.ROUND_HALF_UP);
|
||||
|
||||
// Determine priceStabilityRatingSelect based on the average percentage difference
|
||||
Integer priceStabilityRatingSelect;
|
||||
if (averageDifference.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
priceStabilityRatingSelect = 3; // Stable prices
|
||||
} else if (averageDifference.compareTo(BigDecimal.valueOf(5)) <= 0) {
|
||||
priceStabilityRatingSelect = 2; // Moderately stable prices
|
||||
} else if (averageDifference.compareTo(BigDecimal.valueOf(10)) <= 0) {
|
||||
priceStabilityRatingSelect = 1; // Unstable prices
|
||||
} else {
|
||||
priceStabilityRatingSelect = 0;
|
||||
}
|
||||
|
||||
return priceStabilityRatingSelect;
|
||||
}
|
||||
|
||||
private Integer calculatPriceStabilityRatingSelectLastPrice(
|
||||
List<PurchaseOrderLine> purchaseOrderLinesList, Partner partner) {
|
||||
List<Product> products = new ArrayList<>();
|
||||
for (PurchaseOrderLine purchaseOrderLine : purchaseOrderLinesList) {
|
||||
Product product = purchaseOrderLine.getProduct();
|
||||
products.add(product);
|
||||
}
|
||||
|
||||
List<BigDecimal> lastPrices = new ArrayList<>();
|
||||
for (Product product : products) {
|
||||
BigDecimal lastPrice = getLastPriceProduct(product, partner);
|
||||
lastPrices.add(lastPrice);
|
||||
}
|
||||
|
||||
List<BigDecimal> differences = new ArrayList<>();
|
||||
for (int i = 0; i < purchaseOrderLinesList.size(); i++) {
|
||||
BigDecimal price = purchaseOrderLinesList.get(i).getPrice();
|
||||
BigDecimal lastPrice = lastPrices.get(i);
|
||||
|
||||
BigDecimal difference = price.subtract(lastPrice);
|
||||
BigDecimal percentage =
|
||||
difference
|
||||
.divide(lastPrice, 4, BigDecimal.ROUND_HALF_UP)
|
||||
.multiply(BigDecimal.valueOf(100));
|
||||
|
||||
differences.add(percentage);
|
||||
}
|
||||
|
||||
BigDecimal totalDifference = BigDecimal.ZERO;
|
||||
for (BigDecimal difference : differences) {
|
||||
totalDifference = totalDifference.add(difference);
|
||||
}
|
||||
|
||||
// Calculate the average percentage difference
|
||||
BigDecimal averageDifference =
|
||||
totalDifference.divide(BigDecimal.valueOf(differences.size()), 2, BigDecimal.ROUND_HALF_UP);
|
||||
|
||||
// Determine priceStabilityRatingSelect based on the average percentage difference
|
||||
Integer priceStabilityRatingSelect;
|
||||
if (averageDifference.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
priceStabilityRatingSelect = 3; // Stable prices
|
||||
} else if (averageDifference.compareTo(BigDecimal.valueOf(5)) <= 0) {
|
||||
priceStabilityRatingSelect = 2; // Moderately stable prices
|
||||
} else if (averageDifference.compareTo(BigDecimal.valueOf(10)) <= 0) {
|
||||
priceStabilityRatingSelect = 1; // Unstable prices
|
||||
} else {
|
||||
priceStabilityRatingSelect = 0;
|
||||
}
|
||||
|
||||
return priceStabilityRatingSelect;
|
||||
}
|
||||
|
||||
private BigDecimal calculateAvgProduct(Product product, Partner partner) {
|
||||
// Beans.get(PurchaseOrderRepository.class).find(originId);
|
||||
/*List<PurchaseOrderLine> purchaseOrderLines = Beans.get(PurchaseOrderLineRepository.class)
|
||||
.all()
|
||||
.filter("self.purchaseOrder.supplierPartner = :partner AND self.product = :product")
|
||||
@@ -380,47 +379,48 @@ public class SupplierRatingServiceImpl implements SupplierRatingService {
|
||||
.bind("product", product)
|
||||
.fetch();*/
|
||||
|
||||
List<PurchaseOrderLine> purchaseOrderLines =
|
||||
Beans.get(PurchaseOrderLineRepository.class)
|
||||
.all()
|
||||
.fetch()
|
||||
.stream()
|
||||
.filter(
|
||||
t ->
|
||||
t.getPurchaseOrder().getSupplierPartner() == partner
|
||||
&& t.getProduct() == product)
|
||||
.collect(Collectors.toList());
|
||||
List<PurchaseOrderLine> purchaseOrderLines =
|
||||
Beans.get(PurchaseOrderLineRepository.class)
|
||||
.all()
|
||||
.fetch()
|
||||
.stream()
|
||||
.filter(
|
||||
t ->
|
||||
t.getPurchaseOrder().getSupplierPartner() == partner
|
||||
&& t.getProduct() == product)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (purchaseOrderLines != null && !purchaseOrderLines.isEmpty()) {
|
||||
BigDecimal total = BigDecimal.ZERO;
|
||||
for (PurchaseOrderLine purchaseOrderLine : purchaseOrderLines) {
|
||||
BigDecimal price = purchaseOrderLine.getPrice();
|
||||
total = total.add(price);
|
||||
}
|
||||
BigDecimal avgPrice =
|
||||
total.divide(BigDecimal.valueOf(purchaseOrderLines.size()), 2, BigDecimal.ROUND_HALF_UP);
|
||||
return avgPrice;
|
||||
}
|
||||
// Handle the case where there are no purchase order lines for the given product and partner
|
||||
return BigDecimal.ZERO;
|
||||
if (purchaseOrderLines != null && !purchaseOrderLines.isEmpty()) {
|
||||
BigDecimal total = BigDecimal.ZERO;
|
||||
for (PurchaseOrderLine purchaseOrderLine : purchaseOrderLines) {
|
||||
BigDecimal price = purchaseOrderLine.getPrice();
|
||||
total = total.add(price);
|
||||
}
|
||||
BigDecimal avgPrice =
|
||||
total.divide(BigDecimal.valueOf(purchaseOrderLines.size()), 2, BigDecimal.ROUND_HALF_UP);
|
||||
return avgPrice;
|
||||
}
|
||||
// Handle the case where there are no purchase order lines for the given product and partner
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
private BigDecimal getLastPriceProduct(Product product, Partner partner) {
|
||||
private BigDecimal getLastPriceProduct(Product product, Partner partner) {
|
||||
|
||||
List<PurchaseOrderLine> purchaseOrderLines = Beans.get(PurchaseOrderLineRepository.class)
|
||||
.all()
|
||||
.filter("self.purchaseOrder.supplierPartner = :partner AND self.product = :product")
|
||||
.bind("partner", partner)
|
||||
.bind("product", product)
|
||||
.fetch();
|
||||
List<PurchaseOrderLine> purchaseOrderLines =
|
||||
Beans.get(PurchaseOrderLineRepository.class)
|
||||
.all()
|
||||
.filter("self.purchaseOrder.supplierPartner = :partner AND self.product = :product")
|
||||
.bind("partner", partner)
|
||||
.bind("product", product)
|
||||
.fetch();
|
||||
|
||||
PurchaseOrderLine lastPurchaseOrderLine =
|
||||
purchaseOrderLines.isEmpty() ? null : purchaseOrderLines.get(purchaseOrderLines.size() - 1);
|
||||
if (lastPurchaseOrderLine != null) {
|
||||
BigDecimal price = lastPurchaseOrderLine.getPrice();
|
||||
return price;
|
||||
} else {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
PurchaseOrderLine lastPurchaseOrderLine =
|
||||
purchaseOrderLines.isEmpty() ? null : purchaseOrderLines.get(purchaseOrderLines.size() - 1);
|
||||
if (lastPurchaseOrderLine != null) {
|
||||
BigDecimal price = lastPurchaseOrderLine.getPrice();
|
||||
return price;
|
||||
} else {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,7 +219,7 @@ public abstract class InvoiceLineGeneratorSupplyChain extends InvoiceLineGenerat
|
||||
|
||||
} else if (purchaseOrderLine != null) {
|
||||
|
||||
if (purchaseOrderLine.getAnalyticDistributionTemplate() != null) {
|
||||
if (purchaseOrderLine.getAnalyticDistributionTemplate() != null || purchaseOrderLine.getAnalyticMoveLineList().size() != 0) {
|
||||
invoiceLine.setAnalyticDistributionTemplate(
|
||||
purchaseOrderLine.getAnalyticDistributionTemplate());
|
||||
this.copyAnalyticMoveLines(purchaseOrderLine.getAnalyticMoveLineList(), invoiceLine);
|
||||
|
||||
@@ -1,51 +1,20 @@
|
||||
package com.axelor.apps.supplychain.web;
|
||||
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.net.MalformedURLException;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collector;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.axelor.apps.account.db.Invoice;
|
||||
import com.axelor.apps.account.db.InvoiceLine;
|
||||
import com.axelor.apps.account.db.InvoiceTemplate;
|
||||
import com.axelor.apps.account.db.PaymentVoucher;
|
||||
import com.axelor.apps.account.db.repo.InvoiceTemplateRepository;
|
||||
import com.axelor.apps.base.db.Product;
|
||||
import com.axelor.apps.base.db.Wizard;
|
||||
import com.axelor.apps.purchase.db.ImportationFolder;
|
||||
import com.axelor.apps.purchase.db.repo.ImportationFolderRepository;
|
||||
import com.axelor.apps.purchase.service.print.ImportationFolderPrintService;
|
||||
import com.axelor.apps.report.engine.ReportSettings;
|
||||
import com.axelor.apps.stock.db.ImportationFolderCostPrice;
|
||||
import com.axelor.apps.stock.db.StockMove;
|
||||
import com.axelor.apps.stock.db.StockMoveLine;
|
||||
import com.axelor.apps.stock.db.StockProductionRequest;
|
||||
import com.axelor.apps.stock.db.repo.ImportationFolderCostPriceRepository;
|
||||
import com.axelor.apps.stock.db.repo.StockMoveLineRepository;
|
||||
import com.axelor.apps.stock.db.repo.StockMoveRepository;
|
||||
import com.axelor.apps.stock.exception.IExceptionMessage;
|
||||
import com.axelor.apps.stock.service.StockMoveService;
|
||||
import com.axelor.apps.stock.service.stockmove.print.StockProductionRequestPrintService;
|
||||
import com.axelor.apps.supplychain.service.ImportationFolderServiceImpl;
|
||||
import com.axelor.apps.supplychain.service.StockMoveLineServiceSupplychainImpl;
|
||||
import com.axelor.apps.supplychain.service.app.AppSupplychainService;
|
||||
import com.axelor.common.ObjectUtils;
|
||||
import com.axelor.db.mapper.Mapper;
|
||||
import com.axelor.exception.AxelorException;
|
||||
import com.axelor.exception.db.repo.TraceBackRepository;
|
||||
@@ -57,16 +26,22 @@ import com.axelor.meta.schema.actions.ActionView.ActionViewBuilder;
|
||||
import com.axelor.rpc.ActionRequest;
|
||||
import com.axelor.rpc.ActionResponse;
|
||||
import com.axelor.rpc.Context;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.math.BigDecimal;
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import wslite.json.JSONException;
|
||||
|
||||
public class ImportationFolderController {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
|
||||
|
||||
|
||||
public void calculateAvgPrice(ActionRequest request, ActionResponse response)
|
||||
throws MalformedURLException, JSONException, AxelorException {
|
||||
|
||||
@@ -77,20 +52,20 @@ public class ImportationFolderController {
|
||||
List<StockMoveLine> stockMoveLines = importationFolder.getStockMoveLineList();
|
||||
|
||||
List<Long> invoiceIds =
|
||||
Beans.get(ImportationFolderServiceImpl.class).calculateAvgPriceAndGenerateInvoice(stockMoveLines, importationFolder);
|
||||
|
||||
response.setView(
|
||||
ActionView.define("Invoice")
|
||||
.model(Invoice.class.getName())
|
||||
.add("grid", "invoice-grid")
|
||||
.add("form", "invoice-form")
|
||||
.domain("self.id in (" + Joiner.on(",").join(invoiceIds) + ")")
|
||||
.param("forceEdit", "true")
|
||||
.context("todayDate", Beans.get(AppSupplychainService.class).getTodayDate())
|
||||
.map());
|
||||
Beans.get(ImportationFolderServiceImpl.class)
|
||||
.calculateAvgPriceAndGenerateInvoice(stockMoveLines, importationFolder);
|
||||
|
||||
response.setView(
|
||||
ActionView.define("Invoice")
|
||||
.model(Invoice.class.getName())
|
||||
.add("grid", "invoice-grid")
|
||||
.add("form", "invoice-form")
|
||||
.domain("self.id in (" + Joiner.on(",").join(invoiceIds) + ")")
|
||||
.param("forceEdit", "true")
|
||||
.context("todayDate", Beans.get(AppSupplychainService.class).getTodayDate())
|
||||
.map());
|
||||
}
|
||||
|
||||
|
||||
public void computeCostPrice(ActionRequest request, ActionResponse response)
|
||||
throws MalformedURLException, JSONException, AxelorException {
|
||||
|
||||
@@ -98,20 +73,19 @@ public class ImportationFolderController {
|
||||
(ImportationFolder) request.getContext().asType(ImportationFolder.class);
|
||||
ImportationFolder importationFolder =
|
||||
Beans.get(ImportationFolderRepository.class).find(iimportationFolder.getId());
|
||||
|
||||
|
||||
String msg = Beans.get(ImportationFolderServiceImpl.class).computeCostPrice(importationFolder);
|
||||
|
||||
response.setAlert(msg);
|
||||
|
||||
response.setAlert(msg);
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public void setStockMoveLineCurrenyRate(ActionRequest request, ActionResponse response) {
|
||||
try {
|
||||
List<HashMap> selectedStockMoveLineMapList =
|
||||
(List<HashMap>) request.getContext().get("stockMoveLineList");
|
||||
Map importationFolderMap = (Map<String, Object>) request.getContext().get("importationFolder");
|
||||
Map importationFolderMap =
|
||||
(Map<String, Object>) request.getContext().get("importationFolder");
|
||||
if (selectedStockMoveLineMapList == null) {
|
||||
response.setFlash(I18n.get(IExceptionMessage.STOCK_MOVE_14));
|
||||
return;
|
||||
@@ -135,8 +109,10 @@ public class ImportationFolderController {
|
||||
return;
|
||||
}
|
||||
|
||||
ImportationFolder importationFolder = Mapper.toBean(ImportationFolder.class, importationFolderMap);
|
||||
importationFolder = Beans.get(ImportationFolderRepository.class).find(importationFolder.getId());
|
||||
ImportationFolder importationFolder =
|
||||
Mapper.toBean(ImportationFolder.class, importationFolderMap);
|
||||
importationFolder =
|
||||
Beans.get(ImportationFolderRepository.class).find(importationFolder.getId());
|
||||
Beans.get(ImportationFolderServiceImpl.class)
|
||||
.setStockMoveLineCurrenyRate(stockMoveLineList, currencyRate);
|
||||
response.setCanClose(true);
|
||||
@@ -150,7 +126,8 @@ public class ImportationFolderController {
|
||||
try {
|
||||
List<HashMap> selectedStockMoveLineMapList =
|
||||
(List<HashMap>) request.getContext().get("stockMoveLineList");
|
||||
Map importationFolderMap = (Map<String, Object>) request.getContext().get("importationFolder");
|
||||
Map importationFolderMap =
|
||||
(Map<String, Object>) request.getContext().get("importationFolder");
|
||||
if (selectedStockMoveLineMapList == null) {
|
||||
response.setFlash(I18n.get(IExceptionMessage.STOCK_MOVE_14));
|
||||
return;
|
||||
@@ -174,9 +151,12 @@ public class ImportationFolderController {
|
||||
return;
|
||||
}
|
||||
|
||||
ImportationFolder importationFolder = Mapper.toBean(ImportationFolder.class, importationFolderMap);
|
||||
importationFolder = Beans.get(ImportationFolderRepository.class).find(importationFolder.getId());
|
||||
Beans.get(ImportationFolderServiceImpl.class).setStockMoveLineFreight(stockMoveLineList, freight);
|
||||
ImportationFolder importationFolder =
|
||||
Mapper.toBean(ImportationFolder.class, importationFolderMap);
|
||||
importationFolder =
|
||||
Beans.get(ImportationFolderRepository.class).find(importationFolder.getId());
|
||||
Beans.get(ImportationFolderServiceImpl.class)
|
||||
.setStockMoveLineFreight(stockMoveLineList, freight);
|
||||
response.setCanClose(true);
|
||||
} catch (Exception e) {
|
||||
TraceBackService.trace(response, e);
|
||||
@@ -188,7 +168,8 @@ public class ImportationFolderController {
|
||||
try {
|
||||
List<HashMap> selectedStockMoveLineMapList =
|
||||
(List<HashMap>) request.getContext().get("stockMoveLineList");
|
||||
Map importationFolderMap = (Map<String, Object>) request.getContext().get("importationFolder");
|
||||
Map importationFolderMap =
|
||||
(Map<String, Object>) request.getContext().get("importationFolder");
|
||||
if (selectedStockMoveLineMapList == null) {
|
||||
response.setFlash("No selected move line");
|
||||
return;
|
||||
@@ -212,8 +193,10 @@ public class ImportationFolderController {
|
||||
return;
|
||||
}
|
||||
|
||||
ImportationFolder importationFolder = Mapper.toBean(ImportationFolder.class, importationFolderMap);
|
||||
importationFolder = Beans.get(ImportationFolderRepository.class).find(importationFolder.getId());
|
||||
ImportationFolder importationFolder =
|
||||
Mapper.toBean(ImportationFolder.class, importationFolderMap);
|
||||
importationFolder =
|
||||
Beans.get(ImportationFolderRepository.class).find(importationFolder.getId());
|
||||
Beans.get(ImportationFolderServiceImpl.class)
|
||||
.setStockMoveLineNetMass(stockMoveLineList, netMass);
|
||||
response.setCanClose(true);
|
||||
@@ -227,7 +210,8 @@ public class ImportationFolderController {
|
||||
try {
|
||||
List<HashMap> selectedStockMoveLineMapList =
|
||||
(List<HashMap>) request.getContext().get("stockMoveLineList");
|
||||
Map importationFolderMap = (Map<String, Object>) request.getContext().get("importationFolder");
|
||||
Map importationFolderMap =
|
||||
(Map<String, Object>) request.getContext().get("importationFolder");
|
||||
if (selectedStockMoveLineMapList == null) {
|
||||
response.setFlash("No selected move line");
|
||||
return;
|
||||
@@ -251,8 +235,10 @@ public class ImportationFolderController {
|
||||
return;
|
||||
}
|
||||
|
||||
ImportationFolder importationFolder = Mapper.toBean(ImportationFolder.class, importationFolderMap);
|
||||
importationFolder = Beans.get(ImportationFolderRepository.class).find(importationFolder.getId());
|
||||
ImportationFolder importationFolder =
|
||||
Mapper.toBean(ImportationFolder.class, importationFolderMap);
|
||||
importationFolder =
|
||||
Beans.get(ImportationFolderRepository.class).find(importationFolder.getId());
|
||||
Beans.get(ImportationFolderServiceImpl.class)
|
||||
.setStockMoveLineVolume(stockMoveLineList, volume);
|
||||
response.setCanClose(true);
|
||||
@@ -261,14 +247,13 @@ public class ImportationFolderController {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void validateCostPrice(ActionRequest request, ActionResponse response) {
|
||||
|
||||
ImportationFolderCostPrice importationFolderCostPrice =
|
||||
Beans.get(ImportationFolderCostPriceRepository.class)
|
||||
.find(request.getContext().asType(ImportationFolderCostPrice.class).getId());
|
||||
// sophal refresh purchase order price
|
||||
|
||||
|
||||
try {
|
||||
Beans.get(ImportationFolderServiceImpl.class).validateCostPrice(importationFolderCostPrice);
|
||||
response.setReload(true);
|
||||
@@ -277,9 +262,30 @@ public class ImportationFolderController {
|
||||
}
|
||||
}
|
||||
|
||||
public void confirmRejectView(ActionRequest request, ActionResponse response) {
|
||||
ImportationFolder ImportationFolderContext = request.getContext().asType(ImportationFolder.class);
|
||||
ImportationFolder importationFolder =
|
||||
public void massValidateCostPrice(ActionRequest request, ActionResponse response) {
|
||||
|
||||
ImportationFolder iimportationFolder =
|
||||
(ImportationFolder) request.getContext().asType(ImportationFolder.class);
|
||||
ImportationFolder importationFolder =
|
||||
Beans.get(ImportationFolderRepository.class).find(iimportationFolder.getId());
|
||||
|
||||
List<ImportationFolderCostPrice> importationFolderCostPriceList =
|
||||
importationFolder.getImportationFolderCostPriceList();
|
||||
// TODO gorup by product and stockmove to minimize the proccessed line
|
||||
for (ImportationFolderCostPrice line : importationFolderCostPriceList) {
|
||||
try {
|
||||
Beans.get(ImportationFolderServiceImpl.class).validateCostPrice(line);
|
||||
} catch (Exception e) {
|
||||
System.out.println(e.toString());
|
||||
}
|
||||
}
|
||||
response.setReload(true);
|
||||
}
|
||||
|
||||
public void confirmRejectView(ActionRequest request, ActionResponse response) {
|
||||
ImportationFolder ImportationFolderContext =
|
||||
request.getContext().asType(ImportationFolder.class);
|
||||
ImportationFolder importationFolder =
|
||||
Beans.get(ImportationFolderRepository.class).find(ImportationFolderContext.getId());
|
||||
|
||||
ActionViewBuilder confirmView =
|
||||
@@ -296,7 +302,6 @@ public class ImportationFolderController {
|
||||
response.setView(confirmView.map());
|
||||
}
|
||||
|
||||
|
||||
public void rejectImportationFolder(ActionRequest request, ActionResponse response)
|
||||
throws AxelorException {
|
||||
|
||||
@@ -306,29 +311,28 @@ public class ImportationFolderController {
|
||||
ImportationFolder importationFolder =
|
||||
Beans.get(ImportationFolderRepository.class).find((long) importationFolderId);
|
||||
|
||||
Beans.get(ImportationFolderServiceImpl.class).rejectImportationFolder(importationFolder, rejectionRaison);
|
||||
Beans.get(ImportationFolderServiceImpl.class)
|
||||
.rejectImportationFolder(importationFolder, rejectionRaison);
|
||||
|
||||
response.setCanClose(true);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void print(ActionRequest request, ActionResponse response) {
|
||||
|
||||
Context context = request.getContext();
|
||||
String fileLink;
|
||||
String title;
|
||||
|
||||
ImportationFolderPrintService importationFolderPrintService = Beans.get(ImportationFolderPrintService.class);
|
||||
|
||||
ImportationFolderPrintService importationFolderPrintService =
|
||||
Beans.get(ImportationFolderPrintService.class);
|
||||
|
||||
try {
|
||||
if (context.get("id") != null) {
|
||||
if (context.get("id") != null) {
|
||||
ImportationFolder importationFolder = request.getContext().asType(ImportationFolder.class);
|
||||
title = importationFolderPrintService.getFileName(importationFolder);
|
||||
fileLink =
|
||||
importationFolderPrintService.printCostPriceSheet(
|
||||
importationFolder, ReportSettings.FORMAT_PDF);
|
||||
importationFolderPrintService.printCostPriceSheet(
|
||||
importationFolder, ReportSettings.FORMAT_PDF);
|
||||
logger.debug("Printing " + title);
|
||||
} else {
|
||||
throw new AxelorException(
|
||||
@@ -341,25 +345,28 @@ public class ImportationFolderController {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void generateFromModel(ActionRequest request, ActionResponse response) throws AxelorException{
|
||||
public void generateFromModel(ActionRequest request, ActionResponse response)
|
||||
throws AxelorException {
|
||||
Long importationFolderId = (Long) request.getContext().get("id");
|
||||
ImportationFolder importationFolder =
|
||||
Beans.get(ImportationFolderRepository.class).find((long) importationFolderId);
|
||||
InvoiceTemplate template = (InvoiceTemplate) request.getContext().get("$invoiceTemplate");
|
||||
InvoiceTemplate invoiceTemplate = Beans.get(InvoiceTemplateRepository.class).find(template.getId());
|
||||
InvoiceTemplate template = (InvoiceTemplate) request.getContext().get("$invoiceTemplate");
|
||||
InvoiceTemplate invoiceTemplate =
|
||||
Beans.get(InvoiceTemplateRepository.class).find(template.getId());
|
||||
|
||||
Invoice invoice = Beans.get(ImportationFolderServiceImpl.class).generateFromModel(importationFolder, invoiceTemplate);
|
||||
|
||||
response.setView(
|
||||
ActionView.define("Invoice")
|
||||
.model(Invoice.class.getName())
|
||||
.add("grid", "invoice-grid")
|
||||
.add("form", "invoice-form")
|
||||
.param("forceEdit", "true")
|
||||
.context("_showRecord", String.valueOf(invoice.getId()))
|
||||
.context("_operationTypeSelect", invoice.getOperationTypeSelect())
|
||||
.context("todayDate", Beans.get(AppSupplychainService.class).getTodayDate())
|
||||
.map());
|
||||
Invoice invoice =
|
||||
Beans.get(ImportationFolderServiceImpl.class)
|
||||
.generateFromModel(importationFolder, invoiceTemplate);
|
||||
|
||||
response.setView(
|
||||
ActionView.define("Invoice")
|
||||
.model(Invoice.class.getName())
|
||||
.add("grid", "invoice-grid")
|
||||
.add("form", "invoice-form")
|
||||
.param("forceEdit", "true")
|
||||
.context("_showRecord", String.valueOf(invoice.getId()))
|
||||
.context("_operationTypeSelect", invoice.getOperationTypeSelect())
|
||||
.context("todayDate", Beans.get(AppSupplychainService.class).getTodayDate())
|
||||
.map());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,8 +20,12 @@ package com.axelor.apps.supplychain.web;
|
||||
import com.axelor.apps.account.service.app.AppAccountService;
|
||||
import com.axelor.apps.purchase.db.PurchaseOrder;
|
||||
import com.axelor.apps.purchase.db.PurchaseOrderLine;
|
||||
import com.axelor.apps.purchase.db.PurchaseOrderLineFile;
|
||||
import com.axelor.apps.purchase.db.repo.PurchaseOrderLineFileRepository;
|
||||
import com.axelor.apps.supplychain.service.PurchaseOrderLineFileServiceService;
|
||||
import com.axelor.apps.supplychain.service.PurchaseOrderLineServiceSupplychainImpl;
|
||||
import com.axelor.exception.AxelorException;
|
||||
import com.axelor.exception.service.TraceBackService;
|
||||
import com.axelor.inject.Beans;
|
||||
import com.axelor.rpc.ActionRequest;
|
||||
import com.axelor.rpc.ActionResponse;
|
||||
@@ -63,4 +67,22 @@ public class PurchaseOrderLineController {
|
||||
"budgetDistributionSumAmount", purchaseOrderLine.getBudgetDistributionSumAmount());
|
||||
response.setValue("budgetDistributionList", purchaseOrderLine.getBudgetDistributionList());
|
||||
}
|
||||
|
||||
public void refuseCoa(ActionRequest request, ActionResponse response) {
|
||||
|
||||
System.out.println(String.valueOf(request.getContext().get("_id")));
|
||||
Long id = new Long(String.valueOf(request.getContext().get("_id")));
|
||||
String raison = (String) request.getContext().get("refusalRaison");
|
||||
String refusalOrigin = (String) request.getContext().get("refusalOrigin"); // Assuming refusal origin is passed here
|
||||
|
||||
|
||||
try {
|
||||
PurchaseOrderLineFile purchaseOrderLineFile =
|
||||
Beans.get(PurchaseOrderLineFileRepository.class).find(id);
|
||||
Beans.get(PurchaseOrderLineFileServiceService.class).refuseCoa(purchaseOrderLineFile, raison,refusalOrigin);
|
||||
|
||||
} catch (Exception e) {
|
||||
TraceBackService.trace(response, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.axelor.apps.supplychain.web;
|
||||
|
||||
import com.axelor.apps.base.db.Company;
|
||||
import com.axelor.apps.sale.db.SaleOrder;
|
||||
import com.axelor.apps.stock.db.StockLocation;
|
||||
import com.axelor.apps.stock.db.StockMove;
|
||||
import com.axelor.apps.stock.db.StockMoveLine;
|
||||
import com.axelor.apps.stock.db.repo.StockMoveRepository;
|
||||
@@ -26,19 +27,31 @@ import com.axelor.apps.supplychain.db.SupplyChainConfig;
|
||||
import com.axelor.apps.supplychain.exception.IExceptionMessage;
|
||||
import com.axelor.apps.supplychain.service.SaleOrderReservedQtyService;
|
||||
import com.axelor.apps.supplychain.service.SaleOrderStockService;
|
||||
import com.axelor.apps.supplychain.service.StockConfigService;
|
||||
import com.axelor.apps.supplychain.service.StockMoveServiceSupplychain;
|
||||
import com.axelor.apps.supplychain.service.StockMoveServiceSupplychainImpl;
|
||||
import com.axelor.apps.supplychain.service.app.AppSupplychainService;
|
||||
import com.axelor.apps.supplychain.service.config.SupplyChainConfigService;
|
||||
import com.axelor.db.JPA;
|
||||
import com.axelor.exception.AxelorException;
|
||||
import com.axelor.exception.db.repo.TraceBackRepository;
|
||||
import com.axelor.exception.service.TraceBackService;
|
||||
import com.axelor.i18n.I18n;
|
||||
import com.axelor.inject.Beans;
|
||||
import com.axelor.rpc.ActionRequest;
|
||||
import com.axelor.rpc.ActionResponse;
|
||||
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.persistence.Query;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class StockMoveController {
|
||||
private final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
|
||||
|
||||
public void addSubLines(ActionRequest request, ActionResponse response) {
|
||||
try {
|
||||
@@ -125,7 +138,8 @@ public class StockMoveController {
|
||||
|
||||
try {
|
||||
StockMove newStockMove =
|
||||
Beans.get(StockMoveServiceSupplychainImpl.class).splitInto2SameMove(stockMove, modifiedStockMoveLineList);
|
||||
Beans.get(StockMoveServiceSupplychainImpl.class)
|
||||
.splitInto2SameMove(stockMove, modifiedStockMoveLineList);
|
||||
|
||||
if (newStockMove == null) {
|
||||
response.setFlash(I18n.get(""));
|
||||
@@ -137,5 +151,93 @@ public class StockMoveController {
|
||||
}
|
||||
}
|
||||
|
||||
public void checkIfQuarantine(ActionRequest request, ActionResponse response)
|
||||
throws AxelorException {
|
||||
|
||||
StockMove stockMoveFromRequest = request.getContext().asType(StockMove.class);
|
||||
|
||||
StockMove stockMove = Beans.get(StockMoveRepository.class).find(stockMoveFromRequest.getId());
|
||||
Query sql =
|
||||
JPA.em()
|
||||
.createNativeQuery(
|
||||
"SELECT LINE.ID"+
|
||||
" FROM STOCK_STOCK_MOVE_LINE LINE LEFT JOIN STOCK_STOCK_LOCATION_LINE LOCATION_LINE ON LINE.TRACKING_NUMBER = LOCATION_LINE.TRACKING_NUMBER and LINE.product = LOCATION_LINE.product"+
|
||||
" where LOCATION_LINE.DETAILS_STOCK_LOCATION = ?1 AND LOCATION_LINE.CONFORMITY_SELECT != 2 AND LOCATION_LINE.CONFORMITY_SELECT != 5 AND LINE.STOCK_MOVE = ?2");
|
||||
sql.setParameter(1, stockMove.getFromStockLocation().getId());
|
||||
sql.setParameter(2, stockMove.getId());
|
||||
logger.debug("sql.getResultList().size()",sql.getResultList().size());
|
||||
if (sql.getResultList().size() > 0) {
|
||||
throw new AxelorException(
|
||||
stockMove,
|
||||
TraceBackRepository.CATEGORY_CONFIGURATION_ERROR,
|
||||
"vous avez une ligne en etat qurantaine");
|
||||
}
|
||||
}
|
||||
|
||||
public void checkIfDiffNonCompliant(ActionRequest request, ActionResponse response)
|
||||
throws AxelorException {
|
||||
|
||||
StockMove stockMoveFromContext = request.getContext().asType(StockMove.class);
|
||||
StockMove stockMove = Beans.get(StockMoveRepository.class).find(stockMoveFromContext.getId());
|
||||
Query sql =
|
||||
JPA.em()
|
||||
.createNativeQuery(
|
||||
"SELECT LINE.ID" +
|
||||
" FROM STOCK_STOCK_MOVE_LINE LINE LEFT JOIN STOCK_STOCK_LOCATION_LINE LOCATION_LINE ON LINE.TRACKING_NUMBER = LOCATION_LINE.TRACKING_NUMBER and LINE.product = LOCATION_LINE.product" +
|
||||
" where LOCATION_LINE.DETAILS_STOCK_LOCATION = ?1 AND LOCATION_LINE.CONFORMITY_SELECT != 3 AND LINE.STOCK_MOVE = ?2");
|
||||
sql.setParameter(1, stockMove.getFromStockLocation().getId());
|
||||
sql.setParameter(2, stockMove.getId());
|
||||
logger.debug("sql.getResultList().size()",sql.getResultList().size());
|
||||
if (sql.getResultList().size() > 0) {
|
||||
throw new AxelorException(
|
||||
stockMove,
|
||||
TraceBackRepository.CATEGORY_CONFIGURATION_ERROR,
|
||||
"vous avez une ligne differente de NC");
|
||||
}
|
||||
}
|
||||
|
||||
public void checkIfNonCompliant(ActionRequest request, ActionResponse response)
|
||||
throws AxelorException {
|
||||
|
||||
StockMove stockMoveFromContext = request.getContext().asType(StockMove.class);
|
||||
StockMove stockMove = Beans.get(StockMoveRepository.class).find(stockMoveFromContext.getId());
|
||||
Query sql =
|
||||
JPA.em()
|
||||
.createNativeQuery(
|
||||
"SELECT LINE.ID" +
|
||||
" FROM STOCK_STOCK_MOVE_LINE LINE LEFT JOIN STOCK_STOCK_LOCATION_LINE LOCATION_LINE ON LINE.TRACKING_NUMBER = LOCATION_LINE.TRACKING_NUMBER and LINE.product = LOCATION_LINE.product" +
|
||||
" where LOCATION_LINE.DETAILS_STOCK_LOCATION = ?1 AND LOCATION_LINE.CONFORMITY_SELECT = 3 AND LINE.STOCK_MOVE = ?2");
|
||||
sql.setParameter(1, stockMove.getFromStockLocation().getId());
|
||||
sql.setParameter(2, stockMove.getId());
|
||||
logger.debug("sql.getResultList().size()",sql.getResultList().size());
|
||||
if (sql.getResultList().size() > 0) {
|
||||
throw new AxelorException(
|
||||
stockMove,
|
||||
TraceBackRepository.CATEGORY_CONFIGURATION_ERROR,
|
||||
"vous avez une ligne NC");
|
||||
}
|
||||
}
|
||||
|
||||
public void checkIfNonConformityTag(ActionRequest request, ActionResponse response)
|
||||
throws AxelorException {
|
||||
|
||||
StockMove stockMoveFromContext = request.getContext().asType(StockMove.class);
|
||||
StockMove stockMove = Beans.get(StockMoveRepository.class).find(stockMoveFromContext.getId());
|
||||
Query sql =
|
||||
JPA.em()
|
||||
.createNativeQuery(
|
||||
"SELECT LINE.ID" +
|
||||
" FROM STOCK_STOCK_MOVE_LINE LINE LEFT JOIN STOCK_STOCK_LOCATION_LINE LOCATION_LINE ON LINE.TRACKING_NUMBER = LOCATION_LINE.TRACKING_NUMBER and LINE.product = LOCATION_LINE.product" +
|
||||
" where LOCATION_LINE.DETAILS_STOCK_LOCATION = ?1 AND LOCATION_LINE.is_conform_tag is not true AND LINE.STOCK_MOVE = ?2");
|
||||
sql.setParameter(1, stockMove.getFromStockLocation().getId());
|
||||
sql.setParameter(2, stockMove.getId());
|
||||
logger.debug("sql.getResultList().size {}",sql.getResultList().size());
|
||||
if (sql.getResultList().size() > 0) {
|
||||
throw new AxelorException(
|
||||
stockMove,
|
||||
TraceBackRepository.CATEGORY_CONFIGURATION_ERROR,
|
||||
"vous avez une ligne non étiqueté");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,47 +13,47 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
public class SupplierRatingController {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(SupplierRatingController.class);
|
||||
private static final Logger LOG = LoggerFactory.getLogger(SupplierRatingController.class);
|
||||
|
||||
private SupplierRatingServiceImpl service;
|
||||
private SupplierRatingServiceImpl service;
|
||||
|
||||
@Inject
|
||||
public SupplierRatingController(SupplierRatingServiceImpl service) {
|
||||
this.service = service;
|
||||
@Inject
|
||||
public SupplierRatingController(SupplierRatingServiceImpl service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
public void rating(ActionRequest request, ActionResponse response) {
|
||||
|
||||
SupplierRating supplierRating = request.getContext().asType(SupplierRating.class);
|
||||
|
||||
Integer paymentDelayRatingSelect = supplierRating.getPaymentDelayRatingSelect();
|
||||
Integer deliveryTimeRatingSelect = supplierRating.getDeliveryTimeRatingSelect();
|
||||
Integer complianceWithTechnicalSpecificationsRatingSelect =
|
||||
supplierRating.getComplianceWithTechnicalSpecificationsRatingSelect();
|
||||
Integer priceRatingSelect = supplierRating.getPriceRatingSelect();
|
||||
Integer quantityComplianceRatingSelect = supplierRating.getQuantityComplianceRatingSelect();
|
||||
Integer complaintManagementRatingSelect = supplierRating.getComplaintManagementRatingSelect();
|
||||
Integer priceStabilityRatingSelect = supplierRating.getPriceStabilityRatingSelect();
|
||||
|
||||
if (paymentDelayRatingSelect != null
|
||||
&& deliveryTimeRatingSelect != null
|
||||
&& complianceWithTechnicalSpecificationsRatingSelect != null
|
||||
&& priceRatingSelect != null
|
||||
&& quantityComplianceRatingSelect != null
|
||||
&& complaintManagementRatingSelect != null
|
||||
&& priceStabilityRatingSelect != null) {
|
||||
service.calculatRating(supplierRating);
|
||||
response.setValue("overallScore", supplierRating.getOverallScore());
|
||||
} else {
|
||||
String message = "You should fill all Fields First.";
|
||||
response.setFlash(message);
|
||||
}
|
||||
}
|
||||
|
||||
public void rating(ActionRequest request, ActionResponse response) {
|
||||
|
||||
SupplierRating supplierRating = request.getContext().asType(SupplierRating.class);
|
||||
|
||||
Integer paymentDelayRatingSelect = supplierRating.getPaymentDelayRatingSelect();
|
||||
Integer deliveryTimeRatingSelect = supplierRating.getDeliveryTimeRatingSelect();
|
||||
Integer complianceWithTechnicalSpecificationsRatingSelect =
|
||||
supplierRating.getComplianceWithTechnicalSpecificationsRatingSelect();
|
||||
Integer priceRatingSelect = supplierRating.getPriceRatingSelect();
|
||||
Integer quantityComplianceRatingSelect = supplierRating.getQuantityComplianceRatingSelect();
|
||||
Integer complaintManagementRatingSelect = supplierRating.getComplaintManagementRatingSelect();
|
||||
Integer priceStabilityRatingSelect = supplierRating.getPriceStabilityRatingSelect();
|
||||
|
||||
if (paymentDelayRatingSelect != null
|
||||
&& deliveryTimeRatingSelect != null
|
||||
&& complianceWithTechnicalSpecificationsRatingSelect != null
|
||||
&& priceRatingSelect != null
|
||||
&& quantityComplianceRatingSelect != null
|
||||
&& complaintManagementRatingSelect != null
|
||||
&& priceStabilityRatingSelect != null) {
|
||||
service.calculatRating(supplierRating);
|
||||
response.setValue("overallScore", supplierRating.getOverallScore());
|
||||
} else {
|
||||
String message = "You should fill all Fields First.";
|
||||
response.setFlash(message);
|
||||
}
|
||||
}
|
||||
|
||||
public void rateSupplier(ActionRequest request, ActionResponse response) {
|
||||
System.out.println("Start");
|
||||
StockMove stockMovetemp = request.getContext().asType(StockMove.class);
|
||||
StockMove stockMove = Beans.get(StockMoveRepository.class).find(stockMovetemp.getId());
|
||||
service.createRating(stockMove);
|
||||
}
|
||||
}
|
||||
public void rateSupplier(ActionRequest request, ActionResponse response) {
|
||||
System.out.println("Start");
|
||||
StockMove stockMovetemp = request.getContext().asType(StockMove.class);
|
||||
StockMove stockMove = Beans.get(StockMoveRepository.class).find(stockMovetemp.getId());
|
||||
service.createRating(stockMove);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,14 +87,14 @@ public class SupplychainBatchController {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Long> ids =
|
||||
(List)
|
||||
(((List) request.getContext().get("_ids"))
|
||||
.stream()
|
||||
.filter(ObjectUtils::notEmpty)
|
||||
.map(input -> Long.parseLong(input.toString()))
|
||||
.collect(Collectors.toList()));
|
||||
List<Long> moveList = Beans.get(AccountingCutOffServiceImpl.class).massGenerationMove(ids);
|
||||
|
||||
(List)
|
||||
(((List) request.getContext().get("_ids"))
|
||||
.stream()
|
||||
.filter(ObjectUtils::notEmpty)
|
||||
.map(input -> Long.parseLong(input.toString()))
|
||||
.collect(Collectors.toList()));
|
||||
List<Long> moveList = Beans.get(AccountingCutOffServiceImpl.class).massGenerationMove(ids);
|
||||
|
||||
if (moveList != null && !moveList.isEmpty()) {
|
||||
response.setView(
|
||||
ActionView.define(I18n.get(IExceptionMessage.MOVE_TEMPLATE_3))
|
||||
@@ -109,20 +109,20 @@ public class SupplychainBatchController {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void generateInventoryLineMove(ActionRequest request, ActionResponse response) {
|
||||
try {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Long> ids =
|
||||
(List)
|
||||
(((List) request.getContext().get("_ids"))
|
||||
.stream()
|
||||
.filter(ObjectUtils::notEmpty)
|
||||
.map(input -> Long.parseLong(input.toString()))
|
||||
.collect(Collectors.toList()));
|
||||
List<Long> moveList = Beans.get(AccountingCutOffServiceImpl.class).massGenerationInventoryLineMove(ids);
|
||||
|
||||
(List)
|
||||
(((List) request.getContext().get("_ids"))
|
||||
.stream()
|
||||
.filter(ObjectUtils::notEmpty)
|
||||
.map(input -> Long.parseLong(input.toString()))
|
||||
.collect(Collectors.toList()));
|
||||
List<Long> moveList =
|
||||
Beans.get(AccountingCutOffServiceImpl.class).massGenerationInventoryLineMove(ids);
|
||||
|
||||
if (moveList != null && !moveList.isEmpty()) {
|
||||
response.setView(
|
||||
ActionView.define(I18n.get(IExceptionMessage.MOVE_TEMPLATE_3))
|
||||
@@ -136,5 +136,4 @@ public class SupplychainBatchController {
|
||||
TraceBackService.trace(response, e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,7 +9,13 @@
|
||||
|
||||
<many-to-one name="saleOrderLine" ref="com.axelor.apps.sale.db.SaleOrderLine"/>
|
||||
<many-to-one name="purchaseOrderLine" ref="com.axelor.apps.purchase.db.PurchaseOrderLine"/>
|
||||
|
||||
<many-to-one name="purchaseRequestLine" ref="com.axelor.apps.purchase.db.PurchaseRequestLine"/>
|
||||
<many-to-one name="stockMoveLine" ref="com.axelor.apps.stock.db.StockMoveLine"/>
|
||||
<many-to-one name="stockMove" ref="com.axelor.apps.stock.db.StockMove"/>
|
||||
<string name="accountStr" title="Account" />
|
||||
<many-to-one name="parent" ref="com.axelor.apps.account.db.AnalyticAccount" title="Analytic Acc." />
|
||||
<many-to-one name="invoiceLine" ref="com.axelor.apps.account.db.InvoiceLine"/>
|
||||
|
||||
</entity>
|
||||
|
||||
</domain-models>
|
||||
|
||||
@@ -8,7 +8,10 @@
|
||||
<entity name="BudgetDistribution" lang="java" cacheable="true">
|
||||
|
||||
<many-to-one name="purchaseOrderLine" ref="com.axelor.apps.purchase.db.PurchaseOrderLine"/>
|
||||
<many-to-one name="purchaseRequestLine" ref="com.axelor.apps.purchase.db.PurchaseRequestLine"/>
|
||||
<many-to-one name="stockMoveLine" ref="com.axelor.apps.stock.db.StockMoveLine"/>
|
||||
<decimal name="budgetAmountAvailable"/>
|
||||
<string name="description" title="Description"/>
|
||||
|
||||
</entity>
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
<date name="forecastDate" title="Forecast date" required="true"/>
|
||||
<decimal name="qty" title="Qty"/>
|
||||
<decimal name="value" title="Value"/>
|
||||
<many-to-one name="unit" ref="com.axelor.apps.base.db.Unit" title="Unit"/>
|
||||
<many-to-one name="product" ref="com.axelor.apps.base.db.Product" title="Product" required="true"/>
|
||||
<many-to-one name="stockLocation" ref="com.axelor.apps.stock.db.StockLocation" title="Stock location" required="true"/>
|
||||
@@ -15,7 +16,7 @@
|
||||
<integer name="statusSelect" title="Status" selection="supplychain.mrp.forecast.status.select" readonly="true" default="1"/>
|
||||
<integer name="monthSelect" selection="iadministration.month.select"/>
|
||||
<integer name="scenario" title="Scenario" selection="mrp.scenario.select"/>
|
||||
|
||||
<many-to-one name="period" title="Period" ref="com.axelor.apps.base.db.Period"/>
|
||||
<extra-code><![CDATA[
|
||||
|
||||
// STATUS SELECT
|
||||
|
||||
@@ -25,6 +25,9 @@
|
||||
|
||||
<many-to-one name="budget" ref="com.axelor.apps.account.db.Budget" title="Budget"/>
|
||||
<long name="generatedSaleOrderId"/>
|
||||
<many-to-one name="analyticAccount" ref="com.axelor.apps.account.db.AnalyticAccount" title="Analytic account"/>
|
||||
<many-to-one name="analyticAxis" ref="com.axelor.apps.account.db.AnalyticAxis" title="Analytic axis" />
|
||||
|
||||
</entity>
|
||||
|
||||
</domain-models>
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
<entity name="PurchaseRequest" lang="java" cacheable="true">
|
||||
|
||||
<many-to-one name="stockLocation" ref="com.axelor.apps.stock.db.StockLocation" title="Stock location"/>
|
||||
<many-to-one name="analyticAccount" ref="com.axelor.apps.account.db.AnalyticAccount" title="Analytic account"/>
|
||||
<many-to-one name="analyticAxis" ref="com.axelor.apps.account.db.AnalyticAxis" title="Analytic axis" />
|
||||
|
||||
<track>
|
||||
<field name="stockLocation"/>
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<domain-models xmlns="http://axelor.com/xml/ns/domain-models"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://axelor.com/xml/ns/domain-models http://axelor.com/xml/ns/domain-models/domain-models_5.0.xsd">
|
||||
|
||||
<module name="purchase" package="com.axelor.apps.purchase.db"/>
|
||||
|
||||
<entity name="PurchaseRequestLine" lang="java">
|
||||
<one-to-many name="analyticMoveLineList" ref="com.axelor.apps.account.db.AnalyticMoveLine" title="Analytic distribution lines" mappedBy="purchaseRequestLine"/>
|
||||
<many-to-one name="analyticDistributionTemplate" title="Analytic distribution template" ref="com.axelor.apps.account.db.AnalyticDistributionTemplate"/>
|
||||
</entity>
|
||||
|
||||
</domain-models>
|
||||
@@ -7,7 +7,9 @@
|
||||
|
||||
<entity name="StockConfig" lang="java" cacheable="true">
|
||||
<many-to-one name="directOrderStockLocation" ref="com.axelor.apps.stock.db.StockLocation" title="Direct order default stock location"/>
|
||||
|
||||
<many-to-one name="warehouseNonCompliant" ref="com.axelor.apps.stock.db.StockLocation" title="WH Non compliant stock location"/>
|
||||
<one-to-many name="lockedStockLocationList" ref="com.axelor.apps.stock.db.StockLocation" title="Locked stock location"/>
|
||||
|
||||
<track>
|
||||
<field name="directOrderStockLocation" on="UPDATE"/>
|
||||
</track>
|
||||
|
||||
@@ -18,6 +18,14 @@
|
||||
|
||||
<integer name="pfpValidateStatusSelect" title="PFP Status" selection="invoice.pfp.validate.status.select" readonly="true" default="1"/>
|
||||
|
||||
<many-to-one ref="com.axelor.apps.purchase.db.PurchaseRequest" name="purchaseRequest" title="Purchase request"/>
|
||||
|
||||
<many-to-one name="analyticAccount" ref="com.axelor.apps.account.db.AnalyticAccount" title="Analytic Acc."/>
|
||||
|
||||
<many-to-one name="analyticAxis" ref="com.axelor.apps.account.db.AnalyticAxis" title="Analytic axis" />
|
||||
|
||||
<many-to-many name="purchaseRequestSet" ref="com.axelor.apps.purchase.db.PurchaseRequest" title="Purchase requests"/>
|
||||
|
||||
<finder-method name="findAllBySaleOrderAndStatus" using="originTypeSelect,originId,statusSelect" all="true"/>
|
||||
|
||||
<extra-code>
|
||||
|
||||
@@ -23,6 +23,12 @@
|
||||
|
||||
<many-to-one name="account" ref="com.axelor.apps.account.db.Account" title="Accounting.Account"/>
|
||||
|
||||
<one-to-many name="analyticMoveLineList" ref="com.axelor.apps.account.db.AnalyticMoveLine" title="Analytic distribution lines" mappedBy="stockMoveLine"/>
|
||||
<many-to-one name="analyticDistributionTemplate" title="Analytic distribution template" ref="com.axelor.apps.account.db.AnalyticDistributionTemplate"/>
|
||||
<many-to-one name="analyticAccount" ref="com.axelor.apps.account.db.AnalyticAccount" title="Analytic Acc."/>
|
||||
<many-to-one name="analyticAxis" ref="com.axelor.apps.account.db.AnalyticAxis" title="Analytic axis" />
|
||||
|
||||
|
||||
<finder-method name="findAllBySaleOrder"
|
||||
using="com.axelor.apps.sale.db.SaleOrder:saleOrder" all="true"
|
||||
filter="self.stockMove.originTypeSelect LIKE 'com.axelor.apps.sale.db.SaleOrder' AND self.stockMove.originId = :saleOrder.id" />
|
||||
|
||||
Reference in New Issue
Block a user