use of com.axelor.apps.account.db.Account 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.account.db.Account in project axelor-open-suite by axelor.
the class AccountController method checkIfCodeAccountAlreadyExistForCompany.
public void checkIfCodeAccountAlreadyExistForCompany(ActionRequest request, ActionResponse response) {
try {
Account account = request.getContext().asType(Account.class);
Long accountId = account.getId();
if (accountId == null) {
accountId = 0L;
}
List<Account> sameAccountList = Beans.get(AccountRepository.class).all().filter("self.company = ?1 AND self.code = ?2 AND self.id != ?3", account.getCompany(), account.getCode(), accountId).fetch();
if (!ObjectUtils.isEmpty(sameAccountList)) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.ACCOUNT_CODE_ALREADY_IN_USE_FOR_COMPANY), account.getCode(), account.getCompany().getName());
}
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.account.db.Account 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.account.db.Account in project axelor-open-suite by axelor.
the class AccountingCutOffServiceImpl method generateCutOffMove.
public Move generateCutOffMove(StockMove stockMove, List<StockMoveLine> sortedStockMoveLine, LocalDate moveDate, LocalDate originDate, boolean isPurchase, boolean recoveredTax, boolean ati, String moveDescription, boolean includeNotStockManagedProduct, boolean isReverse) throws AxelorException {
if (moveDate == null || stockMove.getOriginTypeSelect() == null || stockMove.getOriginId() == null) {
return null;
}
Company company = stockMove.getCompany();
AccountConfig accountConfig = accountConfigSupplychainService.getAccountConfig(company);
Partner partner = stockMove.getPartner();
Account partnerAccount = null;
Currency currency = null;
if (StockMoveRepository.ORIGIN_SALE_ORDER.equals(stockMove.getOriginTypeSelect()) && stockMove.getOriginId() != null) {
SaleOrder saleOrder = saleOrderRepository.find(stockMove.getOriginId());
currency = saleOrder.getCurrency();
if (partner == null) {
partner = saleOrder.getClientPartner();
}
partnerAccount = accountConfigSupplychainService.getForecastedInvCustAccount(accountConfig);
}
if (StockMoveRepository.ORIGIN_PURCHASE_ORDER.equals(stockMove.getOriginTypeSelect()) && stockMove.getOriginId() != null) {
PurchaseOrder purchaseOrder = purchaseOrderRepository.find(stockMove.getOriginId());
currency = purchaseOrder.getCurrency();
if (partner == null) {
partner = purchaseOrder.getSupplierPartner();
}
partnerAccount = accountConfigSupplychainService.getForecastedInvSuppAccount(accountConfig);
}
String origin = stockMove.getStockMoveSeq();
Move move = moveCreateService.createMove(accountConfigSupplychainService.getAutoMiscOpeJournal(accountConfig), company, currency, partner, moveDate, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_CUT_OFF);
counter = 0;
this.generateMoveLines(move, stockMove.getStockMoveLineList(), origin, isPurchase, recoveredTax, ati, moveDescription, isReverse, originDate, includeNotStockManagedProduct);
this.generatePartnerMoveLine(move, origin, partnerAccount, moveDescription, originDate);
if (move.getMoveLineList() != null && !move.getMoveLineList().isEmpty()) {
move.setStockMove(stockMove);
moveValidateService.validate(move);
} else {
moveRepository.remove(move);
return null;
}
return move;
}
use of com.axelor.apps.account.db.Account in project axelor-open-suite by axelor.
the class AccountingCutOffServiceImpl method generateTaxMoveLine.
protected void generateTaxMoveLine(Move move, MoveLine productMoveLine, String origin, boolean isPurchase, boolean isFixedAssets, String moveDescription) throws AxelorException {
TaxLine taxLine = productMoveLine.getTaxLine();
Tax tax = taxLine.getTax();
Account taxAccount = taxAccountService.getAccount(tax, move.getCompany(), isPurchase, isFixedAssets);
BigDecimal currencyTaxAmount = InvoiceLineManagement.computeAmount(productMoveLine.getCurrencyAmount(), taxLine.getValue());
MoveLine taxMoveLine = moveLineService.createMoveLine(move, move.getPartner(), taxAccount, currencyTaxAmount, productMoveLine.getDebit().compareTo(BigDecimal.ZERO) == 1, productMoveLine.getOriginDate(), ++counter, origin, moveDescription);
taxMoveLine.setDate(move.getDate());
taxMoveLine.setDueDate(move.getDate());
move.addMoveLineListItem(taxMoveLine);
}
Aggregations