use of com.axelor.apps.account.db.Move in project axelor-open-suite by axelor.
the class MoveServiceImpl method createMove.
/**
* Créer une écriture comptable propre à la facture.
*
* @param invoice
* @param consolidate
* @return
* @throws AxelorException
*/
@Transactional(rollbackOn = { Exception.class })
@Override
public Move createMove(Invoice invoice) throws AxelorException {
Move move = null;
if (invoice != null && invoice.getInvoiceLineList() != null) {
Journal journal = invoice.getJournal();
Company company = invoice.getCompany();
Partner partner = invoice.getPartner();
Account account = invoice.getPartnerAccount();
log.debug("Création d'une écriture comptable spécifique à la facture {} (Société : {}, Journal : {})", new Object[] { invoice.getInvoiceId(), company.getName(), journal.getCode() });
int functionalOrigin = Beans.get(InvoiceService.class).getPurchaseTypeOrSaleType(invoice);
if (functionalOrigin == PriceListRepository.TYPE_PURCHASE) {
functionalOrigin = MoveRepository.FUNCTIONAL_ORIGIN_PURCHASE;
} else if (functionalOrigin == PriceListRepository.TYPE_SALE) {
functionalOrigin = MoveRepository.FUNCTIONAL_ORIGIN_SALE;
} else {
functionalOrigin = 0;
}
move = moveCreateService.createMove(journal, company, invoice.getCurrency(), partner, invoice.getInvoiceDate(), invoice.getPaymentMode(), MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, functionalOrigin);
if (move != null) {
move.setInvoice(invoice);
move.setTradingName(invoice.getTradingName());
boolean isPurchase = InvoiceToolService.isPurchase(invoice);
boolean isDebitCustomer = moveToolService.isDebitCustomer(invoice, false);
move.getMoveLineList().addAll(moveLineService.createMoveLines(invoice, move, company, partner, account, journal.getIsInvoiceMoveConsolidated(), isPurchase, isDebitCustomer));
moveRepository.save(move);
invoice.setMove(move);
invoice.setCompanyInTaxTotalRemaining(moveToolService.getInTaxTotalRemaining(invoice));
moveValidateService.validate(move);
}
}
return move;
}
use of com.axelor.apps.account.db.Move in project axelor-open-suite by axelor.
the class MoveTemplateService method generateMove.
@Transactional(rollbackOn = { Exception.class })
public List<Long> generateMove(MoveTemplate moveTemplate, List<HashMap<String, Object>> dataList) throws AxelorException {
List<Long> moveList = new ArrayList<>();
BigDecimal hundred = new BigDecimal(100);
for (HashMap<String, Object> data : dataList) {
LocalDate moveDate = LocalDate.parse(data.get("date").toString(), DateTimeFormatter.ISO_DATE);
boolean isDebit = false;
Partner debitPartner = null;
Partner creditPartner = null;
BigDecimal moveBalance = new BigDecimal(data.get("moveBalance").toString());
Partner partner = null;
if (data.get("debitPartner") != null) {
debitPartner = partnerRepo.find(Long.parseLong(((HashMap<String, Object>) data.get("debitPartner")).get("id").toString()));
partner = debitPartner;
}
if (data.get("creditPartner") != null) {
creditPartner = partnerRepo.find(Long.parseLong(((HashMap<String, Object>) data.get("creditPartner")).get("id").toString()));
partner = creditPartner;
}
if (moveTemplate.getJournal().getCompany() != null) {
Move move = moveService.getMoveCreateService().createMove(moveTemplate.getJournal(), moveTemplate.getJournal().getCompany(), null, partner, moveDate, null, MoveRepository.TECHNICAL_ORIGIN_TEMPLATE, 0);
int counter = 1;
for (MoveTemplateLine moveTemplateLine : moveTemplate.getMoveTemplateLineList()) {
partner = null;
if (moveTemplateLine.getDebitCreditSelect().equals(MoveTemplateLineRepository.DEBIT)) {
isDebit = true;
if (moveTemplateLine.getHasPartnerToDebit()) {
partner = debitPartner;
}
} else if (moveTemplateLine.getDebitCreditSelect().equals(MoveTemplateLineRepository.CREDIT)) {
isDebit = false;
if (moveTemplateLine.getHasPartnerToCredit()) {
partner = creditPartner;
}
}
BigDecimal amount = moveBalance.multiply(moveTemplateLine.getPercentage()).divide(hundred, RoundingMode.HALF_UP);
MoveLine moveLine = moveLineService.createMoveLine(move, partner, moveTemplateLine.getAccount(), amount, isDebit, moveDate, moveDate, counter, moveTemplate.getFullName(), moveTemplateLine.getName());
move.getMoveLineList().add(moveLine);
Tax tax = moveTemplateLine.getTax();
if (tax != null) {
TaxLine taxLine = taxService.getTaxLine(tax, moveDate);
if (taxLine != null) {
moveLine.setTaxLine(taxLine);
moveLine.setTaxRate(taxLine.getValue());
moveLine.setTaxCode(tax.getCode());
}
}
moveLine.setAnalyticDistributionTemplate(moveTemplateLine.getAnalyticDistributionTemplate());
moveLineService.generateAnalyticMoveLines(moveLine);
counter++;
}
if (moveTemplate.getAutomaticallyValidate()) {
moveValidateService.validate(move);
}
moveRepo.save(move);
moveList.add(move.getId());
}
}
return moveList;
}
use of com.axelor.apps.account.db.Move in project axelor-open-suite by axelor.
the class MoveTemplateService method generateMove.
@Transactional(rollbackOn = { Exception.class })
public List<Long> generateMove(LocalDate moveDate, List<HashMap<String, Object>> moveTemplateList) throws AxelorException {
List<Long> moveList = new ArrayList<>();
for (HashMap<String, Object> moveTemplateMap : moveTemplateList) {
MoveTemplate moveTemplate = moveTemplateRepo.find(Long.valueOf((Integer) moveTemplateMap.get("id")));
if (moveTemplate.getJournal().getCompany() != null) {
Move move = moveService.getMoveCreateService().createMove(moveTemplate.getJournal(), moveTemplate.getJournal().getCompany(), null, null, moveDate, null, MoveRepository.TECHNICAL_ORIGIN_TEMPLATE, 0);
int counter = 1;
for (MoveTemplateLine moveTemplateLine : moveTemplate.getMoveTemplateLineList()) {
BigDecimal amount = moveTemplateLine.getDebit().add(moveTemplateLine.getCredit());
MoveLine moveLine = moveLineService.createMoveLine(move, moveTemplateLine.getPartner(), moveTemplateLine.getAccount(), amount, moveTemplateLine.getDebit().compareTo(BigDecimal.ZERO) > 0, moveDate, moveDate, counter, moveTemplate.getFullName(), moveTemplateLine.getName());
move.getMoveLineList().add(moveLine);
Tax tax = moveTemplateLine.getTax();
if (tax != null) {
TaxLine taxLine = taxService.getTaxLine(tax, moveDate);
if (taxLine != null) {
moveLine.setTaxLine(taxLine);
moveLine.setTaxRate(taxLine.getValue());
moveLine.setTaxCode(tax.getCode());
}
}
moveLine.setAnalyticDistributionTemplate(moveTemplateLine.getAnalyticDistributionTemplate());
moveLineService.generateAnalyticMoveLines(moveLine);
counter++;
}
if (moveTemplate.getAutomaticallyValidate()) {
moveValidateService.validate(move);
}
moveRepo.save(move);
moveList.add(move.getId());
}
}
return moveList;
}
use of com.axelor.apps.account.db.Move in project axelor-open-suite by axelor.
the class MoveValidateService method validateMultiple.
public void validateMultiple(Query<Move> moveListQuery) throws AxelorException {
Move move;
while (!((move = moveListQuery.fetchOne()) == null)) {
validate(move);
JPA.clear();
}
}
use of com.axelor.apps.account.db.Move in project axelor-open-suite by axelor.
the class MoveAdjustementService method createAdjustmentDebitMove.
/**
* Creating move of passage in gap regulation (on debit)
*
* @param debitMoveLine
* @return
* @throws AxelorException
*/
@Transactional(rollbackOn = { Exception.class })
public void createAdjustmentDebitMove(MoveLine debitMoveLine) throws AxelorException {
Partner partner = debitMoveLine.getPartner();
Account account = debitMoveLine.getAccount();
Move debitMove = debitMoveLine.getMove();
Company company = debitMove.getCompany();
AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
BigDecimal debitAmountRemaining = debitMoveLine.getAmountRemaining();
Journal miscOperationJournal = accountConfigService.getAutoMiscOpeJournal(accountConfig);
Move adjustmentMove = moveCreateService.createMove(miscOperationJournal, company, null, partner, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, debitMove.getFunctionalOriginSelect());
// Création de la ligne au crédit
MoveLine creditAdjustmentMoveLine = moveLineService.createMoveLine(adjustmentMove, partner, account, debitAmountRemaining, false, appAccountService.getTodayDate(company), 1, null, null);
// Création de la ligne au debit
MoveLine debitAdjustmentMoveLine = moveLineService.createMoveLine(adjustmentMove, partner, accountConfigService.getCashPositionVariationAccount(accountConfig), debitAmountRemaining, true, appAccountService.getTodayDate(company), 2, null, null);
adjustmentMove.addMoveLineListItem(creditAdjustmentMoveLine);
adjustmentMove.addMoveLineListItem(debitAdjustmentMoveLine);
moveValidateService.validate(adjustmentMove);
moveRepository.save(adjustmentMove);
}
Aggregations