use of com.axelor.apps.account.db.PaymentMode in project axelor-open-suite by axelor.
the class InvoicePaymentValidateServiceBankPayImpl method setInvoicePaymentStatus.
@Override
protected void setInvoicePaymentStatus(InvoicePayment invoicePayment) throws AxelorException {
Invoice invoice = invoicePayment.getInvoice();
PaymentMode paymentMode = invoicePayment.getPaymentMode();
if (paymentMode == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.INVOICE_PAYMENT_MODE_MISSING), invoice.getInvoiceId());
}
int typeSelect = paymentMode.getTypeSelect();
int inOutSelect = paymentMode.getInOutSelect();
if ((typeSelect == PaymentModeRepository.TYPE_DD && inOutSelect == PaymentModeRepository.IN) || (typeSelect == PaymentModeRepository.TYPE_TRANSFER && inOutSelect == PaymentModeRepository.OUT) && paymentMode.getGenerateBankOrder()) {
invoicePayment.setStatusSelect(InvoicePaymentRepository.STATUS_PENDING);
} else {
invoicePayment.setStatusSelect(InvoicePaymentRepository.STATUS_VALIDATED);
}
}
use of com.axelor.apps.account.db.PaymentMode in project axelor-open-suite by axelor.
the class StockMoveMultiInvoiceServiceImpl method areFieldsConflictedToGenerateCustInvoice.
@Override
public Map<String, Object> areFieldsConflictedToGenerateCustInvoice(List<StockMove> stockMoveList) throws AxelorException {
Map<String, Object> mapResult = new HashMap<>();
boolean paymentConditionToCheck = false;
boolean paymentModeToCheck = false;
boolean contactPartnerToCheck = false;
checkForAlreadyInvoicedStockMove(stockMoveList);
List<Invoice> dummyInvoiceList = stockMoveList.stream().map(this::createDummyOutInvoice).collect(Collectors.toList());
checkOutStockMoveRequiredFieldsAreTheSame(dummyInvoiceList);
if (!dummyInvoiceList.isEmpty()) {
PaymentCondition firstPaymentCondition = dummyInvoiceList.get(0).getPaymentCondition();
PaymentMode firstPaymentMode = dummyInvoiceList.get(0).getPaymentMode();
Partner firstContactPartner = dummyInvoiceList.get(0).getContactPartner();
paymentConditionToCheck = !dummyInvoiceList.stream().map(Invoice::getPaymentCondition).allMatch(paymentCondition -> Objects.equals(paymentCondition, firstPaymentCondition));
paymentModeToCheck = !dummyInvoiceList.stream().map(Invoice::getPaymentMode).allMatch(paymentMode -> Objects.equals(paymentMode, firstPaymentMode));
contactPartnerToCheck = !dummyInvoiceList.stream().map(Invoice::getContactPartner).allMatch(contactPartner -> Objects.equals(contactPartner, firstContactPartner));
mapResult.put("paymentCondition", firstPaymentCondition);
mapResult.put("paymentMode", firstPaymentMode);
mapResult.put("contactPartner", firstContactPartner);
}
mapResult.put("paymentConditionToCheck", paymentConditionToCheck);
mapResult.put("paymentModeToCheck", paymentModeToCheck);
mapResult.put("contactPartnerToCheck", contactPartnerToCheck);
return mapResult;
}
use of com.axelor.apps.account.db.PaymentMode in project axelor-open-suite by axelor.
the class StockMoveMultiInvoiceServiceImpl method areFieldsConflictedToGenerateSupplierInvoice.
@Override
public Map<String, Object> areFieldsConflictedToGenerateSupplierInvoice(List<StockMove> stockMoveList) throws AxelorException {
Map<String, Object> mapResult = new HashMap<>();
boolean paymentConditionToCheck = false;
boolean paymentModeToCheck = false;
boolean contactPartnerToCheck = false;
checkForAlreadyInvoicedStockMove(stockMoveList);
List<Invoice> dummyInvoiceList = stockMoveList.stream().map(this::createDummyInInvoice).collect(Collectors.toList());
checkInStockMoveRequiredFieldsAreTheSame(dummyInvoiceList);
if (!dummyInvoiceList.isEmpty()) {
PaymentCondition firstPaymentCondition = dummyInvoiceList.get(0).getPaymentCondition();
PaymentMode firstPaymentMode = dummyInvoiceList.get(0).getPaymentMode();
Partner firstContactPartner = dummyInvoiceList.get(0).getContactPartner();
paymentConditionToCheck = !dummyInvoiceList.stream().map(Invoice::getPaymentCondition).allMatch(paymentCondition -> Objects.equals(paymentCondition, firstPaymentCondition));
paymentModeToCheck = !dummyInvoiceList.stream().map(Invoice::getPaymentMode).allMatch(paymentMode -> Objects.equals(paymentMode, firstPaymentMode));
contactPartnerToCheck = !dummyInvoiceList.stream().map(Invoice::getContactPartner).allMatch(contactPartner -> Objects.equals(contactPartner, firstContactPartner));
mapResult.put("paymentCondition", firstPaymentCondition);
mapResult.put("paymentMode", firstPaymentMode);
mapResult.put("contactPartner", firstContactPartner);
}
mapResult.put("paymentConditionToCheck", paymentConditionToCheck);
mapResult.put("paymentModeToCheck", paymentModeToCheck);
mapResult.put("contactPartnerToCheck", contactPartnerToCheck);
return mapResult;
}
use of com.axelor.apps.account.db.PaymentMode in project axelor-open-suite by axelor.
the class InvoiceController method mergeInvoice.
// Generate single invoice from several
@SuppressWarnings({ "rawtypes", "unchecked" })
public void mergeInvoice(ActionRequest request, ActionResponse response) {
List<Invoice> invoiceList = new ArrayList<Invoice>();
List<Long> invoiceIdList = new ArrayList<Long>();
boolean fromPopup = false;
if (request.getContext().get("invoiceToMerge") != null) {
if (request.getContext().get("invoiceToMerge") instanceof List) {
// No confirmation popup, invoices are content in a parameter list
List<Map> invoiceMap = (List<Map>) request.getContext().get("invoiceToMerge");
for (Map map : invoiceMap) {
invoiceIdList.add(new Long((Integer) map.get("id")));
}
} else {
// After confirmation popup, invoice's id are in a string separated by ","
String invoiceIdListStr = (String) request.getContext().get("invoiceToMerge");
for (String invoiceId : invoiceIdListStr.split(",")) {
invoiceIdList.add(new Long(invoiceId));
}
fromPopup = true;
}
}
// Check if company, currency and partner are the same for all selected invoices
Company commonCompany = null;
Currency commonCurrency = null;
Partner commonPartner = null;
PaymentCondition commonPaymentCondition = null;
// Useful to determine if a difference exists between payment conditions of all invoices
boolean existPaymentConditionDiff = false;
Partner commonContactPartner = null;
// Useful to determine if a difference exists between contact partners of all purchase orders
boolean existContactPartnerDiff = false;
PriceList commonPriceList = null;
// Useful to determine if a difference exists between price lists of all purchase orders
boolean existPriceListDiff = false;
PaymentMode commonPaymentMode = null;
// Useful to determine if a difference exists between stock locations of all purchase orders
boolean existPaymentModeDiff = false;
SaleOrder commonSaleOrder = null;
// Useful to check if all sale orders are null (since this field is not required)
boolean saleOrderIsNull = false;
Invoice invoiceTemp;
int count = 1;
for (Long invoiceId : invoiceIdList) {
invoiceTemp = JPA.em().find(Invoice.class, invoiceId);
invoiceList.add(invoiceTemp);
if (count == 1) {
commonCompany = invoiceTemp.getCompany();
commonCurrency = invoiceTemp.getCurrency();
commonPartner = invoiceTemp.getPartner();
commonPaymentCondition = invoiceTemp.getPaymentCondition();
commonContactPartner = invoiceTemp.getContactPartner();
commonPriceList = invoiceTemp.getPriceList();
commonPaymentMode = invoiceTemp.getPaymentMode();
commonSaleOrder = invoiceTemp.getSaleOrder();
if (commonSaleOrder == null) {
saleOrderIsNull = true;
}
} else {
if (commonCompany != null && !commonCompany.equals(invoiceTemp.getCompany())) {
commonCompany = null;
}
if (commonCurrency != null && !commonCurrency.equals(invoiceTemp.getCurrency())) {
commonCurrency = null;
}
if (commonPartner != null && !commonPartner.equals(invoiceTemp.getPartner())) {
commonPartner = null;
}
if (commonPaymentCondition != null && !commonPaymentCondition.equals(invoiceTemp.getPaymentCondition())) {
commonPaymentCondition = null;
existPaymentConditionDiff = true;
}
if (commonContactPartner != null && !commonContactPartner.equals(invoiceTemp.getContactPartner())) {
commonContactPartner = null;
existContactPartnerDiff = true;
}
if (commonPriceList != null && !commonPriceList.equals(invoiceTemp.getPriceList())) {
commonPriceList = null;
existPriceListDiff = true;
}
if (commonPaymentMode != null && !commonPaymentMode.equals(invoiceTemp.getPaymentMode())) {
commonPaymentMode = null;
existPaymentModeDiff = true;
}
if (commonSaleOrder != null && !commonSaleOrder.equals(invoiceTemp.getSaleOrder())) {
commonSaleOrder = null;
}
if (invoiceTemp.getSaleOrder() != null) {
saleOrderIsNull = false;
}
}
count++;
}
StringBuilder fieldErrors = new StringBuilder();
if (commonCurrency == null) {
fieldErrors.append(I18n.get(IExceptionMessage.INVOICE_MERGE_ERROR_CURRENCY));
}
if (commonCompany == null) {
if (fieldErrors.length() > 0) {
fieldErrors.append("<br/>");
}
fieldErrors.append(I18n.get(IExceptionMessage.INVOICE_MERGE_ERROR_COMPANY));
}
if (commonPartner == null) {
if (fieldErrors.length() > 0) {
fieldErrors.append("<br/>");
}
fieldErrors.append(I18n.get(IExceptionMessage.INVOICE_MERGE_ERROR_PARTNER));
}
if (commonSaleOrder == null && saleOrderIsNull == false) {
if (fieldErrors.length() > 0) {
fieldErrors.append("<br/>");
}
fieldErrors.append(I18n.get(IExceptionMessage.INVOICE_MERGE_ERROR_SALEORDER));
}
if (fieldErrors.length() > 0) {
response.setFlash(fieldErrors.toString());
return;
}
// content in parameters
if (request.getContext().get("contactPartner") != null) {
commonContactPartner = JPA.em().find(Partner.class, new Long((Integer) ((Map) request.getContext().get("contactPartner")).get("id")));
}
if (request.getContext().get("priceList") != null) {
commonPriceList = JPA.em().find(PriceList.class, new Long((Integer) ((Map) request.getContext().get("priceList")).get("id")));
}
if (request.getContext().get("paymentMode") != null) {
commonPaymentMode = JPA.em().find(PaymentMode.class, new Long((Integer) ((Map) request.getContext().get("paymentMode")).get("id")));
}
if (request.getContext().get("paymentCondition") != null) {
commonPaymentCondition = JPA.em().find(PaymentCondition.class, new Long((Integer) ((Map) request.getContext().get("paymentCondition")).get("id")));
}
if (!fromPopup && (existPaymentConditionDiff || existContactPartnerDiff || existPriceListDiff || existPaymentModeDiff)) {
// Need to display intermediate screen to select some values
ActionViewBuilder confirmView = ActionView.define("Confirm merge invoice").model(Wizard.class.getName()).add("form", "customer-invoices-merge-confirm-form").param("popup", "true").param("show-toolbar", "false").param("show-confirm", "false").param("popup-save", "false").param("forceEdit", "true");
if (existContactPartnerDiff) {
confirmView.context("contextContactPartnerToCheck", "true");
confirmView.context("contextPartnerId", commonPartner.getId().toString());
}
if (existPriceListDiff) {
confirmView.context("contextPriceListToCheck", "true");
}
if (existPaymentModeDiff) {
confirmView.context("contextPaymentModeToCheck", "true");
}
if (existPaymentConditionDiff) {
confirmView.context("contextPaymentConditionToCheck", "true");
}
confirmView.context("invoiceToMerge", Joiner.on(",").join(invoiceIdList));
response.setView(confirmView.map());
return;
}
try {
Invoice invoice = Beans.get(SaleOrderInvoiceService.class).mergeInvoice(invoiceList, commonCompany, commonCurrency, commonPartner, commonContactPartner, commonPriceList, commonPaymentMode, commonPaymentCondition, commonSaleOrder);
if (invoice != null) {
// Open the generated invoice in a new tab
response.setView(ActionView.define("Invoice").model(Invoice.class.getName()).add("grid", "invoice-grid").add("form", "invoice-form").param("search-filters", "customer-invoices-filters").param("forceEdit", "true").context("_showRecord", String.valueOf(invoice.getId())).map());
response.setCanClose(true);
}
} catch (Exception e) {
response.setFlash(e.getLocalizedMessage());
}
}
use of com.axelor.apps.account.db.PaymentMode in project axelor-open-suite by axelor.
the class PaymentVoucherConfirmService method createMoveAndConfirm.
/**
* Confirm payment voucher and create move.
*
* @param paymentVoucher
* @throws AxelorException
*/
@Transactional(rollbackOn = { Exception.class })
public void createMoveAndConfirm(PaymentVoucher paymentVoucher) throws AxelorException {
Partner payerPartner = paymentVoucher.getPartner();
PaymentMode paymentMode = paymentVoucher.getPaymentMode();
Company company = paymentVoucher.getCompany();
BankDetails companyBankDetails = paymentVoucher.getCompanyBankDetails();
Journal journal = paymentModeService.getPaymentModeJournal(paymentMode, company, companyBankDetails);
LocalDate paymentDate = paymentVoucher.getPaymentDate();
boolean scheduleToBePaid = false;
Account paymentModeAccount = paymentModeService.getPaymentModeAccount(paymentMode, company, companyBankDetails);
// If paid by a moveline check if all the lines selected have the same account + company
// Excess payment
boolean allRight = paymentVoucherControlService.checkIfSameAccount(paymentVoucher.getPayVoucherElementToPayList(), paymentVoucher.getMoveLine());
// Check if allright=true (means companies and accounts in lines are all the same and same as in
// move line selected for paying
log.debug("allRight : {}", allRight);
if (allRight) {
scheduleToBePaid = this.toPayWithExcessPayment(paymentVoucher.getPayVoucherElementToPayList(), paymentVoucher.getMoveLine(), scheduleToBePaid, paymentDate);
}
if (paymentVoucher.getMoveLine() == null || (paymentVoucher.getMoveLine() != null && !allRight) || (scheduleToBePaid && !allRight && paymentVoucher.getMoveLine() != null)) {
// Manage all the cases in the same way. As if a move line (Excess payment) is selected, we
// cancel it first
Move move = moveService.getMoveCreateService().createMoveWithPaymentVoucher(journal, company, paymentVoucher, payerPartner, paymentDate, paymentMode, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
move.setPaymentVoucher(paymentVoucher);
move.setTradingName(paymentVoucher.getTradingName());
paymentVoucher.setGeneratedMove(move);
// Create move lines for payment lines
BigDecimal paidLineTotal = BigDecimal.ZERO;
int moveLineNo = 1;
boolean isDebitToPay = paymentVoucherToolService.isDebitToPay(paymentVoucher);
for (PayVoucherElementToPay payVoucherElementToPay : this.getPayVoucherElementToPayList(paymentVoucher)) {
MoveLine moveLineToPay = payVoucherElementToPay.getMoveLine();
log.debug("PV moveLineToPay debit : {}", moveLineToPay.getDebit());
log.debug("PV moveLineToPay amountPaid : {}", moveLineToPay.getAmountPaid());
BigDecimal amountToPay = payVoucherElementToPay.getAmountToPayCurrency();
if (amountToPay.compareTo(BigDecimal.ZERO) > 0) {
paidLineTotal = paidLineTotal.add(amountToPay);
this.payMoveLine(move, moveLineNo++, payerPartner, moveLineToPay, amountToPay, payVoucherElementToPay, isDebitToPay, paymentDate);
}
}
// Create move line for the payment amount
MoveLine moveLine = null;
// in the else case we create a classical balance on the bank account of the payment mode
if (paymentVoucher.getMoveLine() != null) {
moveLine = moveLineService.createMoveLine(move, paymentVoucher.getPartner(), paymentVoucher.getMoveLine().getAccount(), paymentVoucher.getPaidAmount(), isDebitToPay, paymentDate, moveLineNo++, paymentVoucher.getRef(), null);
Reconcile reconcile = reconcileService.createReconcile(moveLine, paymentVoucher.getMoveLine(), moveLine.getDebit(), !isDebitToPay);
if (reconcile != null) {
reconcileService.confirmReconcile(reconcile, true);
}
} else {
moveLine = moveLineService.createMoveLine(move, payerPartner, paymentModeAccount, paymentVoucher.getPaidAmount(), isDebitToPay, paymentDate, moveLineNo++, paymentVoucher.getRef(), null);
}
move.getMoveLineList().add(moveLine);
// Then Use Excess payment on old invoices / moveLines
if (paymentVoucher.getPaidAmount().compareTo(paidLineTotal) > 0) {
BigDecimal remainingPaidAmount = paymentVoucher.getRemainingAmount();
// TODO rajouter le process d'imputation automatique
// if(paymentVoucher.getHasAutoInput()) {
//
// List<MoveLine> debitMoveLines =
// Lists.newArrayList(pas.getDebitLinesToPay(contractLine,
// paymentVoucher.getPaymentScheduleToPay()));
// pas.createExcessPaymentWithAmount(debitMoveLines, remainingPaidAmount,
// move, moveLineNo,
// paymentVoucher.getPayerPartner(), company, contractLine, null,
// paymentDate, updateCustomerAccount);
// }
// else {
Account partnerAccount = Beans.get(AccountCustomerService.class).getPartnerAccount(payerPartner, company, paymentVoucherToolService.isPurchase(paymentVoucher));
moveLine = moveLineService.createMoveLine(move, paymentVoucher.getPartner(), partnerAccount, remainingPaidAmount, !isDebitToPay, paymentDate, moveLineNo++, paymentVoucher.getRef(), null);
move.getMoveLineList().add(moveLine);
if (isDebitToPay) {
reconcileService.balanceCredit(moveLine);
}
}
moveService.getMoveValidateService().validate(move);
paymentVoucher.setGeneratedMove(move);
}
paymentVoucher.setStatusSelect(PaymentVoucherRepository.STATUS_CONFIRMED);
deleteUnPaidLines(paymentVoucher);
}
Aggregations