use of com.axelor.apps.base.db.BankDetails in project axelor-open-suite by axelor.
the class InvoicePaymentValidateServiceImpl method createMoveForInvoicePayment.
/**
* Method to create a payment move for an invoice Payment
*
* <p>Create a move and reconcile it with the invoice move
*
* @param invoicePayment An invoice payment
* @throws AxelorException
*/
@Transactional(rollbackOn = { Exception.class })
public InvoicePayment createMoveForInvoicePayment(InvoicePayment invoicePayment) throws AxelorException {
Invoice invoice = invoicePayment.getInvoice();
Company company = invoice.getCompany();
PaymentMode paymentMode = invoicePayment.getPaymentMode();
Partner partner = invoice.getPartner();
LocalDate paymentDate = invoicePayment.getPaymentDate();
BigDecimal paymentAmount = invoicePayment.getAmount();
BankDetails companyBankDetails = invoicePayment.getCompanyBankDetails();
Account customerAccount;
Journal journal = paymentModeService.getPaymentModeJournal(paymentMode, company, companyBankDetails);
boolean isDebitInvoice = moveService.getMoveToolService().isDebitCustomer(invoice, true);
MoveLine invoiceMoveLine = moveService.getMoveToolService().getInvoiceCustomerMoveLineByLoop(invoice);
if (invoice.getOperationSubTypeSelect() == InvoiceRepository.OPERATION_SUB_TYPE_ADVANCE) {
AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
customerAccount = accountConfigService.getAdvancePaymentAccount(accountConfig);
} else {
if (invoiceMoveLine == null) {
return null;
}
customerAccount = invoiceMoveLine.getAccount();
}
String origin = invoicePayment.getInvoice().getInvoiceId();
if (invoicePayment.getPaymentMode().getTypeSelect() == PaymentModeRepository.TYPE_CHEQUE || invoicePayment.getPaymentMode().getTypeSelect() == PaymentModeRepository.TYPE_IPO_CHEQUE) {
origin = invoicePayment.getChequeNumber() != null ? invoicePayment.getChequeNumber() : origin;
} else if (invoicePayment.getPaymentMode().getTypeSelect() == PaymentModeRepository.TYPE_BANK_CARD) {
origin = invoicePayment.getInvoicePaymentRef() != null ? invoicePayment.getInvoicePaymentRef() : origin;
}
if (invoicePayment.getInvoice().getOperationTypeSelect() == InvoiceRepository.OPERATION_TYPE_SUPPLIER_PURCHASE || invoicePayment.getInvoice().getOperationTypeSelect() == InvoiceRepository.OPERATION_TYPE_SUPPLIER_REFUND) {
origin = invoicePayment.getInvoice().getSupplierInvoiceNb();
}
Move move = moveService.getMoveCreateService().createMove(journal, company, invoicePayment.getCurrency(), partner, paymentDate, paymentMode, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
move.setTradingName(invoice.getTradingName());
move.addMoveLineListItem(moveLineService.createMoveLine(move, partner, paymentModeService.getPaymentModeAccount(paymentMode, company, companyBankDetails), paymentAmount, isDebitInvoice, paymentDate, null, 1, origin, invoicePayment.getDescription()));
MoveLine customerMoveLine = moveLineService.createMoveLine(move, partner, customerAccount, paymentAmount, !isDebitInvoice, paymentDate, null, 2, origin, invoicePayment.getDescription());
move.addMoveLineListItem(customerMoveLine);
moveService.getMoveValidateService().validate(move);
if (invoice.getOperationSubTypeSelect() != InvoiceRepository.OPERATION_SUB_TYPE_ADVANCE) {
Reconcile reconcile = reconcileService.reconcile(invoiceMoveLine, customerMoveLine, true, false);
invoicePayment.setReconcile(reconcile);
}
invoicePayment.setMove(move);
invoicePaymentRepository.save(invoicePayment);
return invoicePayment;
}
use of com.axelor.apps.base.db.BankDetails in project axelor-open-suite by axelor.
the class BankDetailsController method validateIban.
public void validateIban(ActionRequest request, ActionResponse response) {
response.setAttr("invalidIbanText", "hidden", true);
if (request.getAction().endsWith("onnew")) {
return;
}
BankDetails bankDetails = request.getContext().asType(BankDetails.class);
Bank bank = bankDetails.getBank();
if (bankDetails.getIban() != null && bank != null && bank.getBankDetailsTypeSelect() == BankRepository.BANK_IDENTIFIER_TYPE_IBAN) {
try {
Beans.get(BankDetailsService.class).validateIban(bankDetails.getIban());
} catch (IbanFormatException | InvalidCheckDigitException | UnsupportedCountryException e) {
if (request.getAction().endsWith("onchange")) {
response.setFlash(I18n.get(IExceptionMessage.BANK_DETAILS_1));
}
response.setAttr("invalidIbanText", "hidden", false);
} finally {
bankDetails = Beans.get(BankDetailsServiceImpl.class).detailsIban(bankDetails);
if (bank.getCountry() != null && bank.getCountry().getAlpha2Code().equals("FR")) {
response.setValue("bankCode", bankDetails.getBankCode());
response.setValue("sortCode", bankDetails.getSortCode());
response.setValue("accountNbr", bankDetails.getAccountNbr());
response.setValue("bbanKey", bankDetails.getBbanKey());
}
}
}
}
use of com.axelor.apps.base.db.BankDetails in project axelor-open-suite by axelor.
the class PartnerController method checkIbanValidity.
public void checkIbanValidity(ActionRequest request, ActionResponse response) throws AxelorException {
List<BankDetails> bankDetailsList = request.getContext().asType(Partner.class).getBankDetailsList();
List<String> ibanInError = Lists.newArrayList();
if (bankDetailsList != null && !bankDetailsList.isEmpty()) {
for (BankDetails bankDetails : bankDetailsList) {
Bank bank = bankDetails.getBank();
if (bankDetails.getIban() != null && bank != null && bank.getBankDetailsTypeSelect() == BankRepository.BANK_IDENTIFIER_TYPE_IBAN) {
LOG.debug("checking iban code : {}", bankDetails.getIban());
try {
Beans.get(BankDetailsService.class).validateIban(bankDetails.getIban());
} catch (IbanFormatException | InvalidCheckDigitException | UnsupportedCountryException e) {
ibanInError.add(bankDetails.getIban());
}
}
}
}
if (!ibanInError.isEmpty()) {
Function<String, String> addLi = new Function<String, String>() {
@Override
public String apply(String s) {
return "<li>".concat(s).concat("</li>").toString();
}
};
response.setAlert(String.format(IExceptionMessage.BANK_DETAILS_2, "<ul>" + Joiner.on("").join(Iterables.transform(ibanInError, addLi)) + "<ul>"));
}
}
use of com.axelor.apps.base.db.BankDetails in project axelor-open-suite by axelor.
the class ExpenseServiceImpl method createMoveForExpensePayment.
public Move createMoveForExpensePayment(Expense expense) throws AxelorException {
Company company = expense.getCompany();
PaymentMode paymentMode = expense.getPaymentMode();
Partner partner = expense.getUser().getPartner();
LocalDate paymentDate = expense.getPaymentDate();
BigDecimal paymentAmount = expense.getInTaxTotal();
BankDetails companyBankDetails = company.getDefaultBankDetails();
Account employeeAccount;
Journal journal = paymentModeService.getPaymentModeJournal(paymentMode, company, companyBankDetails);
MoveLine expenseMoveLine = this.getExpenseEmployeeMoveLineByLoop(expense);
if (expenseMoveLine == null) {
return null;
}
employeeAccount = expenseMoveLine.getAccount();
Move move = moveService.getMoveCreateService().createMove(journal, company, expense.getMove().getCurrency(), partner, paymentDate, paymentMode, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
move.addMoveLineListItem(moveLineService.createMoveLine(move, partner, paymentModeService.getPaymentModeAccount(paymentMode, company, companyBankDetails), paymentAmount, false, paymentDate, null, 1, expense.getExpenseSeq(), null));
MoveLine employeeMoveLine = moveLineService.createMoveLine(move, partner, employeeAccount, paymentAmount, true, paymentDate, null, 2, expense.getExpenseSeq(), null);
employeeMoveLine.setTaxAmount(expense.getTaxTotal());
move.addMoveLineListItem(employeeMoveLine);
moveService.getMoveValidateService().validate(move);
expense.setPaymentMove(move);
Beans.get(ReconcileService.class).reconcile(expenseMoveLine, employeeMoveLine, true, false);
expenseRepository.save(expense);
return move;
}
use of com.axelor.apps.base.db.BankDetails in project axelor-open-suite by axelor.
the class IntercoServiceImpl method generateIntercoInvoice.
@Override
public Invoice generateIntercoInvoice(Invoice invoice) throws AxelorException {
PartnerService partnerService = Beans.get(PartnerService.class);
InvoiceRepository invoiceRepository = Beans.get(InvoiceRepository.class);
InvoiceService invoiceService = Beans.get(InvoiceService.class);
boolean isPurchase;
// set the status
int generatedOperationTypeSelect;
int priceListRepositoryType;
switch(invoice.getOperationTypeSelect()) {
case InvoiceRepository.OPERATION_TYPE_SUPPLIER_PURCHASE:
generatedOperationTypeSelect = InvoiceRepository.OPERATION_TYPE_CLIENT_SALE;
priceListRepositoryType = PriceListRepository.TYPE_SALE;
isPurchase = false;
break;
case InvoiceRepository.OPERATION_TYPE_SUPPLIER_REFUND:
generatedOperationTypeSelect = InvoiceRepository.OPERATION_TYPE_CLIENT_REFUND;
priceListRepositoryType = PriceListRepository.TYPE_SALE;
isPurchase = false;
break;
case InvoiceRepository.OPERATION_TYPE_CLIENT_SALE:
generatedOperationTypeSelect = InvoiceRepository.OPERATION_TYPE_SUPPLIER_PURCHASE;
priceListRepositoryType = PriceListRepository.TYPE_PURCHASE;
isPurchase = true;
break;
case InvoiceRepository.OPERATION_TYPE_CLIENT_REFUND:
generatedOperationTypeSelect = InvoiceRepository.OPERATION_TYPE_SUPPLIER_REFUND;
priceListRepositoryType = PriceListRepository.TYPE_PURCHASE;
isPurchase = true;
break;
default:
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.INVOICE_MISSING_TYPE), invoice);
}
Company intercoCompany = findIntercoCompany(invoice.getPartner());
Partner intercoPartner = invoice.getCompany().getPartner();
PaymentMode intercoPaymentMode = Beans.get(PaymentModeService.class).reverseInOut(invoice.getPaymentMode());
Address intercoAddress = partnerService.getInvoicingAddress(intercoPartner);
BankDetails intercoBankDetails = partnerService.getDefaultBankDetails(intercoPartner);
AccountingSituation accountingSituation = Beans.get(AccountingSituationService.class).getAccountingSituation(intercoPartner, intercoCompany);
PriceList intercoPriceList = Beans.get(PartnerPriceListService.class).getDefaultPriceList(intercoPartner, priceListRepositoryType);
Invoice intercoInvoice = invoiceRepository.copy(invoice, true);
intercoInvoice.setOperationTypeSelect(generatedOperationTypeSelect);
intercoInvoice.setCompany(intercoCompany);
intercoInvoice.setPartner(intercoPartner);
intercoInvoice.setAddress(intercoAddress);
intercoInvoice.setAddressStr(Beans.get(AddressService.class).computeAddressStr(intercoAddress));
intercoInvoice.setPaymentMode(intercoPaymentMode);
intercoInvoice.setBankDetails(intercoBankDetails);
Set<Invoice> invoices = invoiceService.getDefaultAdvancePaymentInvoice(intercoInvoice);
intercoInvoice.setAdvancePaymentInvoiceSet(invoices);
if (accountingSituation != null) {
intercoInvoice.setInvoiceAutomaticMail(accountingSituation.getInvoiceAutomaticMail());
intercoInvoice.setInvoiceMessageTemplate(accountingSituation.getInvoiceMessageTemplate());
intercoInvoice.setPfpValidatorUser(accountingSituation.getPfpValidatorUser());
}
intercoInvoice.setPriceList(intercoPriceList);
intercoInvoice.setInvoicesCopySelect((intercoPartner.getInvoicesCopySelect() == 0) ? DEFAULT_INVOICE_COPY : intercoPartner.getInvoicesCopySelect());
intercoInvoice.setCreatedByInterco(true);
intercoInvoice.setInterco(false);
intercoInvoice.setPrintingSettings(intercoCompany.getPrintingSettings());
if (intercoInvoice.getInvoiceLineList() != null) {
for (InvoiceLine invoiceLine : intercoInvoice.getInvoiceLineList()) {
invoiceLine.setInvoice(intercoInvoice);
createIntercoInvoiceLine(invoiceLine, isPurchase);
}
}
invoiceService.compute(intercoInvoice);
intercoInvoice.setExternalReference(invoice.getInvoiceId());
intercoInvoice = invoiceRepository.save(intercoInvoice);
if (Beans.get(AppSupplychainService.class).getAppSupplychain().getIntercoInvoiceCreateValidated()) {
Beans.get(InvoiceService.class).validate(intercoInvoice);
}
invoice.setExternalReference(intercoInvoice.getInvoiceId());
return intercoInvoice;
}
Aggregations