use of com.axelor.apps.base.db.BankDetails in project axelor-open-suite by axelor.
the class PaymentScheduleLineServiceImpl method createPaymentMove.
@Override
@Transactional(rollbackOn = { Exception.class })
public Move createPaymentMove(PaymentScheduleLine paymentScheduleLine, BankDetails companyBankDetails, PaymentMode paymentMode) throws AxelorException {
Preconditions.checkNotNull(paymentScheduleLine);
Preconditions.checkNotNull(companyBankDetails);
PaymentSchedule paymentSchedule = paymentScheduleLine.getPaymentSchedule();
Company company = paymentSchedule.getCompany();
Partner partner = paymentSchedule.getPartner();
Journal journal = paymentModeService.getPaymentModeJournal(paymentMode, company, companyBankDetails);
BigDecimal amount = paymentScheduleLine.getInTaxAmount();
String name = paymentScheduleLine.getName();
LocalDate todayDate = appBaseService.getTodayDate(company);
Account account = accountingSituationService.getCustomerAccount(partner, company);
Move move = moveService.getMoveCreateService().createMove(journal, company, null, partner, paymentMode, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
MoveLine creditMoveLine = moveService.getMoveLineService().createMoveLine(move, partner, account, amount, false, todayDate, 1, name, null);
move.addMoveLineListItem(creditMoveLine);
creditMoveLine = moveLineRepo.save(creditMoveLine);
Account paymentModeAccount = paymentModeService.getPaymentModeAccount(paymentMode, company, companyBankDetails);
MoveLine debitMoveLine = moveService.getMoveLineService().createMoveLine(move, partner, paymentModeAccount, amount, true, todayDate, 2, name, null);
move.addMoveLineListItem(debitMoveLine);
debitMoveLine = moveLineRepo.save(debitMoveLine);
moveService.getMoveValidateService().validate(move);
// Reconcile
if (paymentSchedule.getTypeSelect() == PaymentScheduleRepository.TYPE_TERMS && paymentSchedule.getInvoiceSet() != null) {
List<MoveLine> debitMoveLineList = paymentSchedule.getInvoiceSet().stream().sorted(Comparator.comparing(Invoice::getDueDate)).map(invoice -> moveService.getMoveLineService().getDebitCustomerMoveLine(invoice)).collect(Collectors.toList());
if (moveToolService.isSameAccount(debitMoveLineList, account)) {
List<MoveLine> creditMoveLineList = Lists.newArrayList(creditMoveLine);
paymentService.useExcessPaymentOnMoveLines(debitMoveLineList, creditMoveLineList);
}
}
paymentScheduleLine.setDirectDebitAmount(amount);
paymentScheduleLine.setInTaxAmountPaid(amount);
paymentScheduleLine.setAdvanceOrPaymentMove(move);
paymentScheduleLine.setAdvanceMoveLine(creditMoveLine);
paymentScheduleLine.setStatusSelect(PaymentScheduleLineRepository.STATUS_VALIDATED);
paymentScheduleService.closePaymentScheduleIfAllPaid(paymentSchedule);
return move;
}
use of com.axelor.apps.base.db.BankDetails in project axelor-open-suite by axelor.
the class ReimbursementExportService method createReimbursement.
/**
* Méthode permettant de créer un remboursement
*
* @param partner Un tiers
* @param company Une société
* @return Le remboursmeent créé
* @throws AxelorException
*/
public Reimbursement createReimbursement(Partner partner, Company company) throws AxelorException {
Reimbursement reimbursement = new Reimbursement();
reimbursement.setPartner(partner);
reimbursement.setCompany(company);
BankDetails bankDetails = partnerService.getDefaultBankDetails(partner);
reimbursement.setBankDetails(bankDetails);
reimbursement.setRef(sequenceService.getSequenceNumber(SequenceRepository.REIMBOURSEMENT, company));
return reimbursement;
}
use of com.axelor.apps.base.db.BankDetails in project axelor-open-suite by axelor.
the class BankDetailsServiceAccountImpl method getDefaultCompanyBankDetailsFromFactorPartner.
private BankDetails getDefaultCompanyBankDetailsFromFactorPartner(Company company) throws AxelorException {
AccountConfig accountConfig = Beans.get(AccountConfigService.class).getAccountConfig(company);
if (accountConfig.getFactorPartner() == null) {
return null;
}
List<BankDetails> bankDetailsList = accountConfig.getFactorPartner().getBankDetailsList();
return bankDetailsList.stream().filter(bankDetails -> bankDetails.getIsDefault()).findFirst().orElse(null);
}
use of com.axelor.apps.base.db.BankDetails in project axelor-open-suite by axelor.
the class BankDetailsServiceAccountImpl method getDefaultCompanyBankDetailsFromPartner.
/**
* Looks for the bank details in accounting situation.
*
* @param company
* @param paymentMode
* @param partner
* @return The bank details corresponding to the partner and the company with the right payment
* mode null if the partner is null or the accounting situation empty
*/
protected BankDetails getDefaultCompanyBankDetailsFromPartner(Company company, PaymentMode paymentMode, Partner partner) {
if (partner == null) {
return null;
}
AccountingSituation accountingSituation = Beans.get(AccountingSituationService.class).getAccountingSituation(partner, company);
if (accountingSituation == null) {
return null;
}
BankDetails candidateBankDetails = null;
if (paymentMode.getInOutSelect() == PaymentModeRepository.IN) {
candidateBankDetails = accountingSituation.getCompanyInBankDetails();
} else if (paymentMode.getInOutSelect() == PaymentModeRepository.OUT) {
candidateBankDetails = accountingSituation.getCompanyOutBankDetails();
}
return candidateBankDetails;
}
use of com.axelor.apps.base.db.BankDetails in project axelor-open-suite by axelor.
the class SaleOrderController method fillCompanyBankDetails.
/**
* Called on partner, company or payment change. Fill the bank details with a default value.
*
* @param request
* @param response
* @throws AxelorException
*/
public void fillCompanyBankDetails(ActionRequest request, ActionResponse response) throws AxelorException {
SaleOrder saleOrder = request.getContext().asType(SaleOrder.class);
PaymentMode paymentMode = (PaymentMode) request.getContext().get("paymentMode");
Company company = saleOrder.getCompany();
Partner partner = saleOrder.getClientPartner();
if (company == null) {
return;
}
if (partner != null) {
partner = Beans.get(PartnerRepository.class).find(partner.getId());
}
BankDetails defaultBankDetails = Beans.get(BankDetailsService.class).getDefaultCompanyBankDetails(company, paymentMode, partner, null);
response.setValue("companyBankDetails", defaultBankDetails);
}
Aggregations