use of com.axelor.apps.base.db.Company in project axelor-open-suite by axelor.
the class IntercoServiceImpl method generateIntercoPurchaseFromSale.
@Override
@Transactional(rollbackOn = { Exception.class })
public PurchaseOrder generateIntercoPurchaseFromSale(SaleOrder saleOrder) throws AxelorException {
PurchaseOrderService purchaseOrderService = Beans.get(PurchaseOrderService.class);
Company intercoCompany = findIntercoCompany(saleOrder.getClientPartner());
// create purchase order
PurchaseOrder purchaseOrder = new PurchaseOrder();
purchaseOrder.setCompany(intercoCompany);
purchaseOrder.setContactPartner(saleOrder.getContactPartner());
purchaseOrder.setCurrency(saleOrder.getCurrency());
purchaseOrder.setDeliveryDate(saleOrder.getDeliveryDate());
purchaseOrder.setOrderDate(saleOrder.getCreationDate());
purchaseOrder.setPriceList(saleOrder.getPriceList());
purchaseOrder.setTradingName(saleOrder.getTradingName());
purchaseOrder.setPurchaseOrderLineList(new ArrayList<>());
purchaseOrder.setPrintingSettings(Beans.get(TradingNameService.class).getDefaultPrintingSettings(null, intercoCompany));
purchaseOrder.setStatusSelect(PurchaseOrderRepository.STATUS_DRAFT);
purchaseOrder.setSupplierPartner(saleOrder.getCompany().getPartner());
purchaseOrder.setTradingName(saleOrder.getTradingName());
// in ati
purchaseOrder.setInAti(saleOrder.getInAti());
// copy payments
PaymentMode intercoPaymentMode = Beans.get(PaymentModeService.class).reverseInOut(saleOrder.getPaymentMode());
purchaseOrder.setPaymentMode(intercoPaymentMode);
purchaseOrder.setPaymentCondition(saleOrder.getPaymentCondition());
// copy delivery info
purchaseOrder.setDeliveryDate(saleOrder.getDeliveryDate());
purchaseOrder.setStockLocation(Beans.get(StockLocationService.class).getDefaultReceiptStockLocation(intercoCompany));
purchaseOrder.setShipmentMode(saleOrder.getShipmentMode());
purchaseOrder.setFreightCarrierMode(saleOrder.getFreightCarrierMode());
// copy timetable info
purchaseOrder.setExpectedRealisationDate(saleOrder.getExpectedRealisationDate());
purchaseOrder.setAmountToBeSpreadOverTheTimetable(saleOrder.getAmountToBeSpreadOverTheTimetable());
// create lines
List<SaleOrderLine> saleOrderLineList = saleOrder.getSaleOrderLineList();
if (saleOrderLineList != null) {
for (SaleOrderLine saleOrderLine : saleOrderLineList) {
this.createIntercoPurchaseLineFromSaleLine(saleOrderLine, purchaseOrder);
}
}
purchaseOrder.setPrintingSettings(intercoCompany.getPrintingSettings());
// compute the purchase order
purchaseOrderService.computePurchaseOrder(purchaseOrder);
purchaseOrder.setCreatedByInterco(true);
Beans.get(PurchaseOrderRepository.class).save(purchaseOrder);
if (Beans.get(AppSupplychainService.class).getAppSupplychain().getIntercoPurchaseOrderCreateRequested()) {
Beans.get(PurchaseOrderService.class).requestPurchaseOrder(purchaseOrder);
}
saleOrder.setExternalReference(purchaseOrder.getPurchaseOrderSeq());
purchaseOrder.setExternalReference(saleOrder.getSaleOrderSeq());
return purchaseOrder;
}
use of com.axelor.apps.base.db.Company in project axelor-open-suite by axelor.
the class AccountingCutOffServiceImpl method generateProductMoveLine.
protected MoveLine generateProductMoveLine(Move move, StockMoveLine stockMoveLine, String origin, boolean isPurchase, boolean recoveredTax, boolean ati, String moveDescription, boolean isReverse, LocalDate originDate) throws AxelorException {
SaleOrderLine saleOrderLine = stockMoveLine.getSaleOrderLine();
PurchaseOrderLine purchaseOrderLine = stockMoveLine.getPurchaseOrderLine();
Company company = move.getCompany();
LocalDate moveDate = move.getDate();
Partner partner = move.getPartner();
boolean isFixedAssets = false;
BigDecimal amountInCurrency = null;
BigDecimal totalQty = null;
BigDecimal notInvoicedQty = null;
if (isPurchase && purchaseOrderLine != null) {
totalQty = purchaseOrderLine.getQty();
notInvoicedQty = unitConversionService.convert(stockMoveLine.getUnit(), purchaseOrderLine.getUnit(), stockMoveLine.getRealQty().subtract(stockMoveLine.getQtyInvoiced()), stockMoveLine.getRealQty().scale(), purchaseOrderLine.getProduct());
isFixedAssets = purchaseOrderLine.getFixedAssets();
if (ati && !recoveredTax) {
amountInCurrency = purchaseOrderLine.getInTaxTotal();
} else {
amountInCurrency = purchaseOrderLine.getExTaxTotal();
}
}
if (!isPurchase && saleOrderLine != null) {
totalQty = saleOrderLine.getQty();
notInvoicedQty = unitConversionService.convert(stockMoveLine.getUnit(), saleOrderLine.getUnit(), stockMoveLine.getRealQty().subtract(stockMoveLine.getQtyInvoiced()), stockMoveLine.getRealQty().scale(), saleOrderLine.getProduct());
if (ati) {
amountInCurrency = saleOrderLine.getInTaxTotal();
} else {
amountInCurrency = saleOrderLine.getExTaxTotal();
}
}
if (totalQty == null || BigDecimal.ZERO.compareTo(totalQty) == 0) {
return null;
}
BigDecimal qtyRate = notInvoicedQty.divide(totalQty, 10, RoundingMode.HALF_UP);
amountInCurrency = amountInCurrency.multiply(qtyRate).setScale(2, RoundingMode.HALF_UP);
if (amountInCurrency == null || amountInCurrency.compareTo(BigDecimal.ZERO) == 0) {
return null;
}
Product product = stockMoveLine.getProduct();
Account account = accountManagementAccountService.getProductAccount(product, company, partner.getFiscalPosition(), isPurchase, isFixedAssets);
boolean isDebit = false;
if ((isPurchase && amountInCurrency.compareTo(BigDecimal.ZERO) == 1) || !isPurchase && amountInCurrency.compareTo(BigDecimal.ZERO) == -1) {
isDebit = true;
}
if (isReverse) {
isDebit = !isDebit;
}
MoveLine moveLine = moveLineService.createMoveLine(move, partner, account, amountInCurrency, isDebit, originDate, ++counter, origin, moveDescription);
moveLine.setDate(moveDate);
moveLine.setDueDate(moveDate);
getAndComputeAnalyticDistribution(product, move, moveLine);
move.addMoveLineListItem(moveLine);
if (recoveredTax) {
TaxLine taxLine = accountManagementAccountService.getTaxLine(originDate, product, company, partner.getFiscalPosition(), isPurchase);
if (taxLine != null) {
moveLine.setTaxLine(taxLine);
moveLine.setTaxRate(taxLine.getValue());
moveLine.setTaxCode(taxLine.getTax().getCode());
if (taxLine.getValue().compareTo(BigDecimal.ZERO) != 0) {
generateTaxMoveLine(move, moveLine, origin, isPurchase, isFixedAssets, moveDescription);
}
}
}
return moveLine;
}
use of com.axelor.apps.base.db.Company in project axelor-open-suite by axelor.
the class ProductStockLocationServiceImpl method computeIndicators.
@Override
public Map<String, Object> computeIndicators(Long productId, Long companyId, Long stockLocationId) throws AxelorException {
Map<String, Object> map = new HashMap<>();
Product product = productRepository.find(productId);
Company company = companyRepository.find(companyId);
StockLocation stockLocation = stockLocationRepository.find(stockLocationId);
int scale = appBaseService.getNbDecimalDigitForQty();
if (stockLocationId != 0L && companyId != 0L) {
List<StockLocation> stockLocationList = stockLocationService.getAllLocationAndSubLocation(stockLocation, false);
if (!stockLocationList.isEmpty()) {
BigDecimal realQty = BigDecimal.ZERO;
BigDecimal futureQty = BigDecimal.ZERO;
BigDecimal reservedQty = BigDecimal.ZERO;
BigDecimal requestedReservedQty = BigDecimal.ZERO;
BigDecimal saleOrderQty = BigDecimal.ZERO;
BigDecimal purchaseOrderQty = BigDecimal.ZERO;
BigDecimal availableQty = BigDecimal.ZERO;
saleOrderQty = this.getSaleOrderQty(product, company, stockLocation);
purchaseOrderQty = this.getPurchaseOrderQty(product, company, stockLocation);
availableQty = this.getAvailableQty(product, company, stockLocation);
requestedReservedQty = this.getRequestedReservedQty(product, company, stockLocation);
for (StockLocation sl : stockLocationList) {
realQty = realQty.add(stockLocationService.getRealQty(productId, sl.getId(), companyId));
futureQty = futureQty.add(stockLocationService.getFutureQty(productId, sl.getId(), companyId));
reservedQty = reservedQty.add(stockLocationServiceSupplychain.getReservedQty(productId, sl.getId(), companyId));
}
map.put("$realQty", realQty.setScale(scale, RoundingMode.HALF_UP));
map.put("$futureQty", futureQty.setScale(scale, RoundingMode.HALF_UP));
map.put("$reservedQty", reservedQty.setScale(scale, RoundingMode.HALF_UP));
map.put("$requestedReservedQty", requestedReservedQty.setScale(scale, RoundingMode.HALF_UP));
map.put("$saleOrderQty", saleOrderQty.setScale(scale, RoundingMode.HALF_UP));
map.put("$purchaseOrderQty", purchaseOrderQty.setScale(scale, RoundingMode.HALF_UP));
map.put("$availableQty", availableQty.subtract(reservedQty).setScale(scale, RoundingMode.HALF_UP));
return map;
}
}
BigDecimal reservedQty = stockLocationServiceSupplychain.getReservedQty(productId, stockLocationId, companyId).setScale(scale, RoundingMode.HALF_UP);
map.put("$realQty", stockLocationService.getRealQty(productId, stockLocationId, companyId).setScale(scale, RoundingMode.HALF_UP));
map.put("$futureQty", stockLocationService.getFutureQty(productId, stockLocationId, companyId).setScale(scale, RoundingMode.HALF_UP));
map.put("$reservedQty", reservedQty);
map.put("$requestedReservedQty", this.getRequestedReservedQty(product, company, null).setScale(scale, RoundingMode.HALF_UP));
map.put("$saleOrderQty", this.getSaleOrderQty(product, company, null).setScale(scale, RoundingMode.HALF_UP));
map.put("$purchaseOrderQty", this.getPurchaseOrderQty(product, company, null).setScale(scale, RoundingMode.HALF_UP));
map.put("$availableQty", this.getAvailableQty(product, company, null).subtract(reservedQty).setScale(scale, RoundingMode.HALF_UP));
return map;
}
use of com.axelor.apps.base.db.Company in project axelor-open-suite by axelor.
the class MoveLineServiceImpl method autoTaxLineGenerate.
@Override
public void autoTaxLineGenerate(Move move) throws AxelorException {
List<MoveLine> moveLineList = move.getMoveLineList();
moveLineList.sort(new Comparator<MoveLine>() {
@Override
public int compare(MoveLine o1, MoveLine o2) {
if (o2.getSourceTaxLine() != null) {
return 0;
}
return -1;
}
});
Iterator<MoveLine> moveLineItr = moveLineList.iterator();
Map<String, MoveLine> map = new HashMap<>();
Map<String, MoveLine> newMap = new HashMap<>();
while (moveLineItr.hasNext()) {
MoveLine moveLine = moveLineItr.next();
TaxLine taxLine = moveLine.getTaxLine();
TaxLine sourceTaxLine = moveLine.getSourceTaxLine();
if (sourceTaxLine != null) {
String sourceTaxLineKey = moveLine.getAccount().getCode() + sourceTaxLine.getId();
moveLine.setCredit(BigDecimal.ZERO);
moveLine.setDebit(BigDecimal.ZERO);
map.put(sourceTaxLineKey, moveLine);
moveLineItr.remove();
continue;
}
if (taxLine != null) {
String accountType = moveLine.getAccount().getAccountType().getTechnicalTypeSelect();
if (accountType.equals(AccountTypeRepository.TYPE_DEBT) || accountType.equals(AccountTypeRepository.TYPE_CHARGE) || accountType.equals(AccountTypeRepository.TYPE_INCOME) || accountType.equals(AccountTypeRepository.TYPE_ASSET)) {
BigDecimal debit = moveLine.getDebit();
BigDecimal credit = moveLine.getCredit();
LocalDate date = moveLine.getDate();
Company company = move.getCompany();
MoveLine newOrUpdatedMoveLine = new MoveLine();
if (accountType.equals(AccountTypeRepository.TYPE_DEBT) || accountType.equals(AccountTypeRepository.TYPE_CHARGE)) {
newOrUpdatedMoveLine.setAccount(taxAccountService.getAccount(taxLine.getTax(), company, true, false));
} else if (accountType.equals(AccountTypeRepository.TYPE_INCOME)) {
newOrUpdatedMoveLine.setAccount(taxAccountService.getAccount(taxLine.getTax(), company, false, false));
} else if (accountType.equals(AccountTypeRepository.TYPE_ASSET)) {
newOrUpdatedMoveLine.setAccount(taxAccountService.getAccount(taxLine.getTax(), company, true, true));
}
Account newAccount = newOrUpdatedMoveLine.getAccount();
if (newAccount == null) {
throw new AxelorException(move, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.MOVE_LINE_6), taxLine.getName(), company.getName());
}
String newSourceTaxLineKey = newAccount.getCode() + taxLine.getId();
if (!map.containsKey(newSourceTaxLineKey) && !newMap.containsKey(newSourceTaxLineKey)) {
newOrUpdatedMoveLine = this.createNewMoveLine(debit, credit, date, accountType, taxLine, newOrUpdatedMoveLine);
} else {
if (newMap.containsKey(newSourceTaxLineKey)) {
newOrUpdatedMoveLine = newMap.get(newSourceTaxLineKey);
} else if (!newMap.containsKey(newSourceTaxLineKey) && map.containsKey(newSourceTaxLineKey)) {
newOrUpdatedMoveLine = map.get(newSourceTaxLineKey);
}
newOrUpdatedMoveLine.setDebit(newOrUpdatedMoveLine.getDebit().add(debit.multiply(taxLine.getValue())));
newOrUpdatedMoveLine.setCredit(newOrUpdatedMoveLine.getCredit().add(credit.multiply(taxLine.getValue())));
}
newMap.put(newSourceTaxLineKey, newOrUpdatedMoveLine);
}
}
}
moveLineList.addAll(newMap.values());
}
use of com.axelor.apps.base.db.Company in project axelor-open-suite by axelor.
the class MoveServiceImpl method createMoveUseDebit.
@Override
public Move createMoveUseDebit(Invoice invoice, List<MoveLine> debitMoveLines, MoveLine invoiceCustomerMoveLine) throws AxelorException {
Company company = invoice.getCompany();
Partner partner = invoice.getPartner();
Account account = invoice.getPartnerAccount();
Journal journal = accountConfigService.getAutoMiscOpeJournal(accountConfigService.getAccountConfig(company));
log.debug("Création d'une écriture comptable O.D. spécifique à l'emploie des trop-perçus {} (Société : {}, Journal : {})", new Object[] { invoice.getInvoiceId(), company.getName(), journal.getCode() });
BigDecimal remainingAmount = invoice.getInTaxTotal().abs();
log.debug("Montant à payer avec l'avoir récupéré : {}", remainingAmount);
Move oDmove = moveCreateService.createMove(journal, company, null, partner, invoice.getInvoiceDate(), null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
if (oDmove != null) {
BigDecimal totalDebitAmount = moveToolService.getTotalDebitAmount(debitMoveLines);
BigDecimal amount = totalDebitAmount.min(invoiceCustomerMoveLine.getCredit());
// Création de la ligne au débit
MoveLine debitMoveLine = moveLineService.createMoveLine(oDmove, partner, account, amount, true, appAccountService.getTodayDate(company), 1, invoice.getInvoiceId(), null);
oDmove.getMoveLineList().add(debitMoveLine);
// Emploie des dûs sur les lignes de credit qui seront créées au fil de l'eau
paymentService.createExcessPaymentWithAmount(debitMoveLines, amount, oDmove, 2, partner, company, null, account, appAccountService.getTodayDate(company));
moveValidateService.validate(oDmove);
// Création de la réconciliation
Reconcile reconcile = reconcileService.createReconcile(debitMoveLine, invoiceCustomerMoveLine, amount, false);
if (reconcile != null) {
reconcileService.confirmReconcile(reconcile, true);
}
}
return oDmove;
}
Aggregations