Search in sources :

Example 41 with Partner

use of com.axelor.apps.base.db.Partner in project axelor-open-suite by axelor.

the class InvoiceController method setDefaultMail.

/**
 * set default value for automatic invoice printing
 *
 * @param request
 * @param response
 * @throws AxelorException
 */
public void setDefaultMail(ActionRequest request, ActionResponse response) {
    Invoice invoice = request.getContext().asType(Invoice.class);
    Company company = invoice.getCompany();
    Partner partner = invoice.getPartner();
    if (company != null && partner != null) {
        AccountingSituation accountingSituation = Beans.get(AccountingSituationService.class).getAccountingSituation(partner, company);
        if (accountingSituation != null) {
            response.setValue("invoiceAutomaticMail", accountingSituation.getInvoiceAutomaticMail());
            response.setValue("invoiceMessageTemplate", accountingSituation.getInvoiceMessageTemplate());
            response.setValue("invoiceAutomaticMailOnValidate", accountingSituation.getInvoiceAutomaticMailOnValidate());
            response.setValue("invoiceMessageTemplateOnValidate", accountingSituation.getInvoiceMessageTemplateOnValidate());
        }
    }
}
Also used : Company(com.axelor.apps.base.db.Company) Invoice(com.axelor.apps.account.db.Invoice) AccountingSituation(com.axelor.apps.account.db.AccountingSituation) Partner(com.axelor.apps.base.db.Partner) AccountingSituationService(com.axelor.apps.account.service.AccountingSituationService)

Example 42 with Partner

use of com.axelor.apps.base.db.Partner in project axelor-open-suite by axelor.

the class ImportMove method importFECMove.

@Transactional(rollbackOn = { AxelorException.class, Exception.class })
public Object importFECMove(Object bean, Map<String, Object> values) throws AxelorException {
    assert bean instanceof MoveLine;
    MoveLine moveLine = (MoveLine) bean;
    try {
        moveLine.setCounter(1);
        if (values.get("EcritureNum") == null) {
            return null;
        }
        String moveReference = values.get("EcritureNum").toString();
        MoveLine mvLine = moveLineRepo.all().filter("self.name LIKE '" + moveReference + "-%'").order("-counter").fetchOne();
        if (mvLine != null) {
            int counter = mvLine.getCounter() + 1;
            moveLine.setCounter(counter);
        }
        if (values.get("EcritureDate") != null) {
            LocalDate moveLineDate = LocalDate.parse(values.get("EcritureDate").toString(), DateTimeFormatter.BASIC_ISO_DATE);
            moveLine.setDate(moveLineDate);
        }
        Move move = moveRepository.all().filter("self.reference = ?", moveReference).fetchOne();
        if (move == null) {
            move = new Move();
            move.setReference(moveReference);
            if (values.get("ValidDate") != null) {
                move.setStatusSelect(MoveRepository.STATUS_VALIDATED);
                move.setValidationDate(LocalDate.parse(values.get("ValidDate").toString(), DateTimeFormatter.BASIC_ISO_DATE));
            } else {
                move.setStatusSelect(MoveRepository.STATUS_ACCOUNTED);
            }
            move.setCompany(getCompany(values));
            move.setCompanyCurrency(move.getCompany().getCurrency());
            move.setDate(LocalDate.parse(values.get("EcritureDate").toString(), DateTimeFormatter.BASIC_ISO_DATE));
            move.setPeriod(Beans.get(PeriodService.class).getPeriod(move.getDate(), move.getCompany(), YearRepository.TYPE_FISCAL));
            if (values.get("Idevise") != null) {
                move.setCurrency(Beans.get(CurrencyRepository.class).findByCode(values.get("Idevise").toString()));
                move.setCurrencyCode(values.get("Idevise").toString());
            }
            if (values.get("JournalCode") != null) {
                Journal journal = Beans.get(JournalRepository.class).all().filter("self.code = ?1 AND self.company.id = ?2", values.get("JournalCode").toString(), move.getCompany().getId()).fetchOne();
                move.setJournal(journal);
            }
            if (values.get("CompAuxNum") != null) {
                Partner partner = Beans.get(PartnerRepository.class).all().filter("self.partnerSeq = ?", values.get("CompAuxNum").toString()).fetchOne();
                move.setPartner(partner);
            }
            moveRepository.save(move);
        }
        if (values.get("CompteNum") != null) {
            Account account = Beans.get(AccountRepository.class).all().filter("self.code = ?1 AND self.company.id = ?2", values.get("CompteNum").toString(), move.getCompany().getId()).fetchOne();
            moveLine.setAccount(account);
        }
        moveLine.setMove(move);
    } catch (Exception e) {
        TraceBackService.trace(e);
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, e.getMessage());
    }
    return moveLine;
}
Also used : Account(com.axelor.apps.account.db.Account) AxelorException(com.axelor.exception.AxelorException) AccountRepository(com.axelor.apps.account.db.repo.AccountRepository) Journal(com.axelor.apps.account.db.Journal) LocalDate(java.time.LocalDate) AxelorException(com.axelor.exception.AxelorException) PartnerRepository(com.axelor.apps.base.db.repo.PartnerRepository) JournalRepository(com.axelor.apps.account.db.repo.JournalRepository) Move(com.axelor.apps.account.db.Move) MoveLine(com.axelor.apps.account.db.MoveLine) Partner(com.axelor.apps.base.db.Partner) Transactional(com.google.inject.persist.Transactional)

Example 43 with Partner

use of com.axelor.apps.base.db.Partner in project axelor-open-suite by axelor.

the class ImportMoveLine method importMoveLine.

@Transactional(rollbackOn = Exception.class)
public Object importMoveLine(Object bean, Map<String, Object> values) throws AxelorException {
    assert bean instanceof MoveLine;
    MoveLine moveLine = (MoveLine) bean;
    String accountId = (String) values.get("account_importId");
    Account account = getAccount(accountId);
    if (account != null) {
        moveLine.setAccountCode(account.getCode());
        moveLine.setAccountName(account.getName());
    } else {
        moveLine.setAccountCode((String) values.get("accountCode"));
        moveLine.setAccountName((String) values.get("accountName"));
    }
    String taxLineId = (String) values.get("taxLine_importId");
    TaxLine taxLine = getTaxLine(taxLineId);
    if (taxLine != null) {
        moveLine.setTaxCode(taxLine.getTax().getCode());
        moveLine.setTaxRate(taxLine.getValue());
    } else {
        moveLine.setTaxCode((String) values.get("taxCode"));
        moveLine.setTaxRate(new BigDecimal((String) values.get("taxRate")));
    }
    String partnerId = (String) values.get("partner_importId");
    Partner partner = getPartner(partnerId);
    if (partner != null) {
        moveLine.setPartnerSeq(partner.getPartnerSeq());
        moveLine.setPartnerFullName(partner.getFullName());
    } else {
        moveLine.setPartnerSeq((String) values.get("partnerSeq"));
        moveLine.setPartnerFullName((String) values.get("partnerFullName"));
    }
    moveLineRepository.save(moveLine);
    return moveLine;
}
Also used : Account(com.axelor.apps.account.db.Account) MoveLine(com.axelor.apps.account.db.MoveLine) Partner(com.axelor.apps.base.db.Partner) BigDecimal(java.math.BigDecimal) TaxLine(com.axelor.apps.account.db.TaxLine) Transactional(com.google.inject.persist.Transactional)

Example 44 with Partner

use of com.axelor.apps.base.db.Partner in project axelor-open-suite by axelor.

the class PartnerController method getDefaultSpecificTaxNote.

public void getDefaultSpecificTaxNote(ActionRequest request, ActionResponse response) {
    Partner partner = request.getContext().asType(Partner.class);
    response.setValue("specificTaxNote", Beans.get(PartnerAccountService.class).getDefaultSpecificTaxNote(partner));
}
Also used : Partner(com.axelor.apps.base.db.Partner)

Example 45 with Partner

use of com.axelor.apps.base.db.Partner in project axelor-open-suite by axelor.

the class PaymentVoucherController method fillCompanyBankDetails.

/**
 * Called on load and in 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 {
    PaymentVoucher paymentVoucher = request.getContext().asType(PaymentVoucher.class);
    PaymentMode paymentMode = paymentVoucher.getPaymentMode();
    Company company = paymentVoucher.getCompany();
    Partner partner = paymentVoucher.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) BankDetails(com.axelor.apps.base.db.BankDetails) Partner(com.axelor.apps.base.db.Partner) PaymentVoucher(com.axelor.apps.account.db.PaymentVoucher) PaymentMode(com.axelor.apps.account.db.PaymentMode)

Aggregations

Partner (com.axelor.apps.base.db.Partner)199 AxelorException (com.axelor.exception.AxelorException)68 Company (com.axelor.apps.base.db.Company)67 Transactional (com.google.inject.persist.Transactional)54 BigDecimal (java.math.BigDecimal)43 ArrayList (java.util.ArrayList)34 MoveLine (com.axelor.apps.account.db.MoveLine)32 Move (com.axelor.apps.account.db.Move)30 PaymentMode (com.axelor.apps.account.db.PaymentMode)26 LocalDate (java.time.LocalDate)26 Account (com.axelor.apps.account.db.Account)25 Invoice (com.axelor.apps.account.db.Invoice)24 BankDetails (com.axelor.apps.base.db.BankDetails)24 List (java.util.List)22 PartnerService (com.axelor.apps.base.service.PartnerService)18 Map (java.util.Map)18 Journal (com.axelor.apps.account.db.Journal)17 Address (com.axelor.apps.base.db.Address)14 Currency (com.axelor.apps.base.db.Currency)14 AccountConfig (com.axelor.apps.account.db.AccountConfig)13