use of com.axelor.apps.base.db.Company in project axelor-open-suite by axelor.
the class InvoicePaymentController method fillBankDetails.
/**
* On payment mode change, fill the bank details field if we find precisely one bank details
* available in the payment mode for the current company.
*
* @param request
* @param response
* @throws AxelorException
*/
@SuppressWarnings("unchecked")
public void fillBankDetails(ActionRequest request, ActionResponse response) throws AxelorException {
InvoicePayment invoicePayment = request.getContext().asType(InvoicePayment.class);
Map<String, Object> partialInvoice = (Map<String, Object>) request.getContext().get("_invoice");
Invoice invoice = Beans.get(InvoiceRepository.class).find(((Integer) partialInvoice.get("id")).longValue());
PaymentMode paymentMode = invoicePayment.getPaymentMode();
Company company = invoice.getCompany();
List<BankDetails> bankDetailsList = Beans.get(InvoicePaymentToolService.class).findCompatibleBankDetails(company, invoicePayment);
if (bankDetailsList.size() == 1) {
response.setValue("companyBankDetails", bankDetailsList.get(0));
} else {
response.setValue("companyBankDetails", null);
}
Partner partner = invoice.getPartner();
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("bankDetails", defaultBankDetails);
}
use of com.axelor.apps.base.db.Company in project axelor-open-suite by axelor.
the class MoveServiceImpl method createMoveUseInvoiceDue.
/**
* Méthode permettant d'employer les dûs sur l'avoir On récupère prioritairement les dûs
* (factures) selectionné sur l'avoir, puis les autres dûs du tiers
*
* <p>2 cas : - le compte des dûs est le même que celui de l'avoir : alors on lettre directement -
* le compte n'est pas le même : on créée une O.D. de passage sur le bon compte
*
* @param invoice
* @return
* @throws AxelorException
*/
@Override
public Move createMoveUseInvoiceDue(Invoice invoice) throws AxelorException {
Company company = invoice.getCompany();
Move move = null;
AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
// Récupération des dûs
List<MoveLine> debitMoveLines = moveDueService.getInvoiceDue(invoice, accountConfig.getAutoReconcileOnInvoice());
if (!debitMoveLines.isEmpty()) {
MoveLine invoiceCustomerMoveLine = moveToolService.getCustomerMoveLineByLoop(invoice);
// Si c'est le même compte sur les trop-perçus et sur la facture, alors on lettre directement
if (moveToolService.isSameAccount(debitMoveLines, invoiceCustomerMoveLine.getAccount())) {
List<MoveLine> creditMoveLineList = new ArrayList<MoveLine>();
creditMoveLineList.add(invoiceCustomerMoveLine);
paymentService.useExcessPaymentOnMoveLines(debitMoveLines, creditMoveLineList);
} else // Sinon on créée une O.D. pour passer du compte de la facture à un autre compte sur les
// trop-perçus
{
this.createMoveUseDebit(invoice, debitMoveLines, invoiceCustomerMoveLine);
}
// Gestion du passage en 580
reconcileService.balanceCredit(invoiceCustomerMoveLine);
invoice.setCompanyInTaxTotalRemaining(moveToolService.getInTaxTotalRemaining(invoice));
}
return move;
}
use of com.axelor.apps.base.db.Company 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.Company in project axelor-open-suite by axelor.
the class AccountingSituationController method setDefaultMail.
/**
* set default value for automatic invoice printing
*
* @param request
* @param response
* @throws AxelorException
*/
public void setDefaultMail(ActionRequest request, ActionResponse response) throws AxelorException {
AccountingSituation accountingSituation = request.getContext().asType(AccountingSituation.class);
Company company = accountingSituation.getCompany();
if (company != null) {
AccountConfig accountConfig = Beans.get(AccountConfigService.class).getAccountConfig(company);
response.setValue("invoiceAutomaticMail", accountConfig.getInvoiceAutomaticMail());
response.setValue("invoiceMessageTemplate", accountConfig.getInvoiceMessageTemplate());
}
}
use of com.axelor.apps.base.db.Company in project axelor-open-suite by axelor.
the class AccountChartController method installChart.
public void installChart(ActionRequest request, ActionResponse response) throws AxelorException {
AccountConfig accountConfig = request.getContext().asType(AccountConfig.class);
AccountChart act = Beans.get(AccountChartRepository.class).find(accountConfig.getAccountChart().getId());
Company company = Beans.get(CompanyRepository.class).find(accountConfig.getCompany().getId());
accountConfig = Beans.get(AccountConfigRepository.class).find(accountConfig.getId());
List<? extends Account> accountList = Beans.get(AccountRepository.class).all().filter("self.company.id = ?1 AND self.parentAccount != null", company.getId()).fetch();
if (accountList.isEmpty()) {
if (Beans.get(AccountChartService.class).installAccountChart(act, company, accountConfig))
response.setFlash(I18n.get(IExceptionMessage.ACCOUNT_CHART_1));
else
response.setFlash(I18n.get(IExceptionMessage.ACCOUNT_CHART_2));
response.setReload(true);
} else
response.setFlash(I18n.get(IExceptionMessage.ACCOUNT_CHART_3));
}
Aggregations