Search in sources :

Example 31 with PaymentMode

use of com.axelor.apps.account.db.PaymentMode in project axelor-open-suite by axelor.

the class IntercoServiceImpl method generateIntercoSaleFromPurchase.

@Override
@Transactional(rollbackOn = { Exception.class })
public SaleOrder generateIntercoSaleFromPurchase(PurchaseOrder purchaseOrder) throws AxelorException {
    SaleOrderCreateService saleOrderCreateService = Beans.get(SaleOrderCreateService.class);
    SaleOrderComputeService saleOrderComputeService = Beans.get(SaleOrderComputeService.class);
    Company intercoCompany = findIntercoCompany(purchaseOrder.getSupplierPartner());
    // create sale order
    SaleOrder saleOrder = saleOrderCreateService.createSaleOrder(null, intercoCompany, purchaseOrder.getContactPartner(), purchaseOrder.getCurrency(), purchaseOrder.getDeliveryDate(), null, null, purchaseOrder.getPriceList(), purchaseOrder.getCompany().getPartner(), null);
    // in ati
    saleOrder.setInAti(purchaseOrder.getInAti());
    // copy date
    saleOrder.setOrderDate(purchaseOrder.getOrderDate());
    // copy payments
    PaymentMode intercoPaymentMode = Beans.get(PaymentModeService.class).reverseInOut(purchaseOrder.getPaymentMode());
    saleOrder.setPaymentMode(intercoPaymentMode);
    saleOrder.setPaymentCondition(purchaseOrder.getPaymentCondition());
    // copy delivery info
    saleOrder.setDeliveryDate(purchaseOrder.getDeliveryDate());
    saleOrder.setShipmentMode(purchaseOrder.getShipmentMode());
    saleOrder.setFreightCarrierMode(purchaseOrder.getFreightCarrierMode());
    // get stock location
    saleOrder.setStockLocation(Beans.get(StockLocationService.class).getPickupDefaultStockLocation(intercoCompany));
    // copy timetable info
    saleOrder.setExpectedRealisationDate(purchaseOrder.getExpectedRealisationDate());
    saleOrder.setAmountToBeSpreadOverTheTimetable(purchaseOrder.getAmountToBeSpreadOverTheTimetable());
    // create lines
    List<PurchaseOrderLine> purchaseOrderLineList = purchaseOrder.getPurchaseOrderLineList();
    if (purchaseOrderLineList != null) {
        for (PurchaseOrderLine purchaseOrderLine : purchaseOrderLineList) {
            this.createIntercoSaleLineFromPurchaseLine(purchaseOrderLine, saleOrder);
        }
    }
    saleOrder.setPrintingSettings(intercoCompany.getPrintingSettings());
    // compute the sale order
    saleOrderComputeService.computeSaleOrder(saleOrder);
    saleOrder.setCreatedByInterco(true);
    Beans.get(SaleOrderRepository.class).save(saleOrder);
    if (Beans.get(AppSupplychainService.class).getAppSupplychain().getIntercoSaleOrderCreateFinalized()) {
        Beans.get(SaleOrderWorkflowService.class).finalizeQuotation(saleOrder);
    }
    purchaseOrder.setExternalReference(saleOrder.getSaleOrderSeq());
    saleOrder.setExternalReference(purchaseOrder.getPurchaseOrderSeq());
    return saleOrder;
}
Also used : SaleOrderCreateService(com.axelor.apps.sale.service.saleorder.SaleOrderCreateService) PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) Company(com.axelor.apps.base.db.Company) PaymentModeService(com.axelor.apps.account.service.payment.PaymentModeService) SaleOrderWorkflowService(com.axelor.apps.sale.service.saleorder.SaleOrderWorkflowService) SaleOrderRepository(com.axelor.apps.sale.db.repo.SaleOrderRepository) SaleOrderComputeService(com.axelor.apps.sale.service.saleorder.SaleOrderComputeService) SaleOrder(com.axelor.apps.sale.db.SaleOrder) PaymentMode(com.axelor.apps.account.db.PaymentMode) Transactional(com.google.inject.persist.Transactional)

Example 32 with PaymentMode

use of com.axelor.apps.account.db.PaymentMode 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;
}
Also used : AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) PaymentModeService(com.axelor.apps.account.service.payment.PaymentModeService) Invoice(com.axelor.apps.account.db.Invoice) Address(com.axelor.apps.base.db.Address) PartnerPriceListService(com.axelor.apps.base.service.PartnerPriceListService) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) BankDetails(com.axelor.apps.base.db.BankDetails) InvoiceService(com.axelor.apps.account.service.invoice.InvoiceService) PartnerService(com.axelor.apps.base.service.PartnerService) AccountingSituation(com.axelor.apps.account.db.AccountingSituation) InvoiceRepository(com.axelor.apps.account.db.repo.InvoiceRepository) Partner(com.axelor.apps.base.db.Partner) PriceList(com.axelor.apps.base.db.PriceList) AccountingSituationService(com.axelor.apps.account.service.AccountingSituationService) PaymentMode(com.axelor.apps.account.db.PaymentMode)

Example 33 with PaymentMode

use of com.axelor.apps.account.db.PaymentMode in project axelor-open-suite by axelor.

the class AdvancePaymentServiceSupplychainImpl method createMoveForAdvancePayment.

@Transactional(rollbackOn = { Exception.class })
public Move createMoveForAdvancePayment(AdvancePayment advancePayment) throws AxelorException {
    SaleOrder saleOrder = advancePayment.getSaleOrder();
    Company company = saleOrder.getCompany();
    PaymentMode paymentMode = advancePayment.getPaymentMode();
    Partner clientPartner = saleOrder.getClientPartner();
    LocalDate advancePaymentDate = advancePayment.getAdvancePaymentDate();
    BankDetails bankDetails = saleOrder.getCompanyBankDetails();
    String ref = saleOrder.getSaleOrderSeq();
    AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
    Journal journal = paymentModeService.getPaymentModeJournal(paymentMode, company, bankDetails);
    Move move = moveService.getMoveCreateService().createMove(journal, company, advancePayment.getCurrency(), clientPartner, advancePaymentDate, paymentMode, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
    BigDecimal amountConverted = currencyService.getAmountCurrencyConvertedAtDate(advancePayment.getCurrency(), saleOrder.getCurrency(), advancePayment.getAmount(), advancePaymentDate);
    move.addMoveLineListItem(moveLineService.createMoveLine(move, clientPartner, paymentModeService.getPaymentModeAccount(paymentMode, company, bankDetails), amountConverted, true, advancePaymentDate, null, 1, ref, null));
    move.addMoveLineListItem(moveLineService.createMoveLine(move, clientPartner, accountConfigService.getAdvancePaymentAccount(accountConfig), amountConverted, false, advancePaymentDate, null, 2, ref, null));
    moveService.getMoveValidateService().validate(move);
    advancePayment.setMove(move);
    advancePaymentRepository.save(advancePayment);
    return move;
}
Also used : Company(com.axelor.apps.base.db.Company) Move(com.axelor.apps.account.db.Move) BankDetails(com.axelor.apps.base.db.BankDetails) Journal(com.axelor.apps.account.db.Journal) SaleOrder(com.axelor.apps.sale.db.SaleOrder) Partner(com.axelor.apps.base.db.Partner) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) PaymentMode(com.axelor.apps.account.db.PaymentMode) AccountConfig(com.axelor.apps.account.db.AccountConfig) Transactional(com.google.inject.persist.Transactional)

Example 34 with PaymentMode

use of com.axelor.apps.account.db.PaymentMode in project axelor-open-suite by axelor.

the class PaymentScheduleController method fillCompanyBankDetails.

/**
 * Called on partner, company or payment mode change. Fill the bank details with a default value.
 *
 * @param request
 * @param response
 * @throws AxelorException
 */
public void fillCompanyBankDetails(ActionRequest request, ActionResponse response) throws AxelorException {
    PaymentSchedule paymentSchedule = request.getContext().asType(PaymentSchedule.class);
    PaymentMode paymentMode = paymentSchedule.getPaymentMode();
    Company company = paymentSchedule.getCompany();
    Partner partner = paymentSchedule.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("companyBankDetails", defaultBankDetails);
}
Also used : BankDetailsService(com.axelor.apps.base.service.BankDetailsService) Company(com.axelor.apps.base.db.Company) PaymentSchedule(com.axelor.apps.account.db.PaymentSchedule) BankDetails(com.axelor.apps.base.db.BankDetails) Partner(com.axelor.apps.base.db.Partner) PaymentMode(com.axelor.apps.account.db.PaymentMode)

Example 35 with PaymentMode

use of com.axelor.apps.account.db.PaymentMode in project axelor-open-suite by axelor.

the class BankOrderCreateServiceHr method createBankOrder.

/**
 * Method to create a bank order for an expense
 *
 * @param expense An expense
 * @throws AxelorException
 */
public BankOrder createBankOrder(Expense expense, BankDetails bankDetails) throws AxelorException {
    Company company = expense.getCompany();
    Partner partner = expense.getUser().getPartner();
    PaymentMode paymentMode = expense.getPaymentMode();
    BigDecimal amount = expense.getInTaxTotal().subtract(expense.getAdvanceAmount()).subtract(expense.getWithdrawnCash()).subtract(expense.getPersonalExpenseAmount());
    Currency currency = company.getCurrency();
    LocalDate paymentDate = Beans.get(AppBaseService.class).getTodayDate(company);
    BankOrder bankOrder = super.createBankOrder(paymentMode, BankOrderRepository.PARTNER_TYPE_EMPLOYEE, paymentDate, company, bankDetails, currency, expense.getFullName(), expense.getFullName(), BankOrderRepository.TECHNICAL_ORIGIN_AUTOMATIC);
    bankOrder.addBankOrderLineListItem(bankOrderLineService.createBankOrderLine(paymentMode.getBankOrderFileFormat(), partner, amount, currency, paymentDate, expense.getExpenseSeq(), expense.getFullName(), expense));
    bankOrder = bankOrderRepo.save(bankOrder);
    return bankOrder;
}
Also used : Company(com.axelor.apps.base.db.Company) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) Currency(com.axelor.apps.base.db.Currency) BankOrder(com.axelor.apps.bankpayment.db.BankOrder) Partner(com.axelor.apps.base.db.Partner) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) PaymentMode(com.axelor.apps.account.db.PaymentMode)

Aggregations

PaymentMode (com.axelor.apps.account.db.PaymentMode)45 Company (com.axelor.apps.base.db.Company)27 Partner (com.axelor.apps.base.db.Partner)26 BankDetails (com.axelor.apps.base.db.BankDetails)21 Invoice (com.axelor.apps.account.db.Invoice)18 AxelorException (com.axelor.exception.AxelorException)17 Transactional (com.google.inject.persist.Transactional)13 BigDecimal (java.math.BigDecimal)11 LocalDate (java.time.LocalDate)10 PaymentCondition (com.axelor.apps.account.db.PaymentCondition)9 Currency (com.axelor.apps.base.db.Currency)9 ArrayList (java.util.ArrayList)8 Journal (com.axelor.apps.account.db.Journal)7 PaymentModeService (com.axelor.apps.account.service.payment.PaymentModeService)7 Map (java.util.Map)7 BankOrder (com.axelor.apps.bankpayment.db.BankOrder)6 BankDetailsService (com.axelor.apps.base.service.BankDetailsService)6 Account (com.axelor.apps.account.db.Account)5 Move (com.axelor.apps.account.db.Move)5 PriceList (com.axelor.apps.base.db.PriceList)5