Search in sources :

Example 6 with Partner

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

the class AccountingSituationInitServiceImpl method createSupplierAccount.

protected void createSupplierAccount(AccountConfig accountConfig, AccountingSituation situation, int creationMode) throws AxelorException {
    Partner partner = situation.getPartner();
    if (partner.getIsSupplier() == Boolean.FALSE || situation.getSupplierAccount() != null)
        return;
    if (accountConfig.getSupplierAccount() == null) {
        throw new AxelorException(partner, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.ACCOUNT_CUSTOMER_2), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), situation.getCompany().getName());
    }
    final String accountCode;
    if (creationMode == AccountConfigRepository.AUTOMATIC_ACCOUNT_CREATION_PREFIX) {
        final String prefix = accountConfig.getSupplierAccountPrefix();
        if (StringUtils.isBlank(prefix)) {
            throw new AxelorException(situation, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.ACCOUNTING_SITUATION_4), situation.getCompany().getName());
        }
        accountCode = getPrefixedAccountCode(prefix, partner);
    } else if (creationMode == AccountConfigRepository.AUTOMATIC_ACCOUNT_CREATION_SEQUENCE) {
        final Sequence sequence = accountConfig.getSupplierAccountSequence();
        if (sequence == null) {
            throw new AxelorException(situation, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.ACCOUNTING_SITUATION_5), situation.getCompany().getName());
        }
        accountCode = sequenceService.getSequenceNumber(sequence);
    } else {
        throw new AxelorException(situation, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.ACCOUNTING_SITUATION_3), situation.getCompany().getName());
    }
    Account account = this.createAccount(partner.getFullName(), accountCode, accountConfig.getSupplierAccount(), accountConfig.getSupplierAccount().getAccountType(), true, situation.getCompany(), true);
    situation.setSupplierAccount(account);
}
Also used : AxelorException(com.axelor.exception.AxelorException) Account(com.axelor.apps.account.db.Account) Sequence(com.axelor.apps.base.db.Sequence) Partner(com.axelor.apps.base.db.Partner)

Example 7 with Partner

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

the class AccountingSituationInitServiceImpl method createCustomerAccount.

protected void createCustomerAccount(AccountConfig accountConfig, AccountingSituation situation, int creationMode) throws AxelorException {
    Partner partner = situation.getPartner();
    if (partner.getIsCustomer() == Boolean.FALSE || situation.getCustomerAccount() != null)
        return;
    if (accountConfig.getCustomerAccount() == null) {
        throw new AxelorException(partner, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.ACCOUNT_CUSTOMER_1), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), situation.getCompany().getName());
    }
    final String accountCode;
    if (creationMode == AccountConfigRepository.AUTOMATIC_ACCOUNT_CREATION_PREFIX) {
        final String prefix = accountConfig.getCustomerAccountPrefix();
        if (StringUtils.isBlank(prefix)) {
            throw new AxelorException(situation, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.ACCOUNTING_SITUATION_1), situation.getCompany().getName());
        }
        accountCode = getPrefixedAccountCode(prefix, partner);
    } else if (creationMode == AccountConfigRepository.AUTOMATIC_ACCOUNT_CREATION_SEQUENCE) {
        final Sequence sequence = accountConfig.getCustomerAccountSequence();
        if (sequence == null) {
            throw new AxelorException(situation, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.ACCOUNTING_SITUATION_2), situation.getCompany().getName());
        }
        accountCode = sequenceService.getSequenceNumber(sequence);
    } else {
        throw new AxelorException(situation, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.ACCOUNTING_SITUATION_3), situation.getCompany().getName());
    }
    Account account = this.createAccount(partner.getFullName(), accountCode, accountConfig.getCustomerAccount(), accountConfig.getCustomerAccount().getAccountType(), true, situation.getCompany(), true);
    situation.setCustomerAccount(account);
}
Also used : AxelorException(com.axelor.exception.AxelorException) Account(com.axelor.apps.account.db.Account) Sequence(com.axelor.apps.base.db.Sequence) Partner(com.axelor.apps.base.db.Partner)

Example 8 with Partner

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

the class AccountingSituationInitServiceImpl method createEmployeeAccount.

protected void createEmployeeAccount(AccountConfig accountConfig, AccountingSituation situation, int creationMode) throws AxelorException {
    Partner partner = situation.getPartner();
    if (partner.getIsEmployee() == Boolean.FALSE || situation.getEmployeeAccount() != null)
        return;
    if (accountConfig.getEmployeeAccount() == null) {
        throw new AxelorException(partner, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.ACCOUNT_CONFIG_40), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), situation.getCompany().getName());
    }
    final String accountCode;
    if (creationMode == AccountConfigRepository.AUTOMATIC_ACCOUNT_CREATION_PREFIX) {
        final String prefix = accountConfig.getEmployeeAccountPrefix();
        if (StringUtils.isBlank(prefix)) {
            throw new AxelorException(situation, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.ACCOUNTING_SITUATION_6), situation.getCompany().getName());
        }
        accountCode = getPrefixedAccountCode(prefix, partner);
    } else if (creationMode == AccountConfigRepository.AUTOMATIC_ACCOUNT_CREATION_SEQUENCE) {
        final Sequence sequence = accountConfig.getEmployeeAccountSequence();
        if (sequence == null) {
            throw new AxelorException(situation, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.ACCOUNTING_SITUATION_7), situation.getCompany().getName());
        }
        accountCode = sequenceService.getSequenceNumber(sequence);
    } else {
        throw new AxelorException(situation, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.ACCOUNTING_SITUATION_3), situation.getCompany().getName());
    }
    Account account = this.createAccount(partner.getFullName(), accountCode, accountConfig.getEmployeeAccount(), accountConfig.getEmployeeAccount().getAccountType(), true, situation.getCompany(), true);
    situation.setEmployeeAccount(account);
}
Also used : AxelorException(com.axelor.exception.AxelorException) Account(com.axelor.apps.account.db.Account) Sequence(com.axelor.apps.base.db.Sequence) Partner(com.axelor.apps.base.db.Partner)

Example 9 with Partner

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

the class ChequeRejectionService method createChequeRejectionMove.

/**
 * Méthode permettant de créer une écriture de rejet de chèque (L'extourne de l'écriture de
 * paiement)
 *
 * @param chequeRejection Un rejet de cheque brouillon
 * @param company Une société
 * @return L'écriture de rejet de chèque
 * @throws AxelorException
 */
public Move createChequeRejectionMove(ChequeRejection chequeRejection, Company company) throws AxelorException {
    this.testCompanyField(company);
    Journal journal = company.getAccountConfig().getRejectJournal();
    PaymentVoucher paymentVoucher = chequeRejection.getPaymentVoucher();
    Move paymentMove = paymentVoucher.getGeneratedMove();
    Partner partner = paymentVoucher.getPartner();
    InterbankCodeLine interbankCodeLine = chequeRejection.getInterbankCodeLine();
    String description = chequeRejection.getDescription();
    LocalDate rejectionDate = chequeRejection.getRejectionDate();
    // Move
    Move move = moveService.getMoveCreateService().createMove(journal, company, null, partner, rejectionDate, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
    int ref = 1;
    for (MoveLine moveLine : paymentMove.getMoveLineList()) {
        if (moveLine.getCredit().compareTo(BigDecimal.ZERO) > 0) {
            // Debit MoveLine
            MoveLine debitMoveLine = moveLineService.createMoveLine(move, partner, moveLine.getAccount(), moveLine.getCredit(), true, rejectionDate, ref, chequeRejection.getName(), chequeRejection.getDescription());
            move.getMoveLineList().add(debitMoveLine);
            debitMoveLine.setInterbankCodeLine(interbankCodeLine);
            debitMoveLine.setDescription(description);
        } else {
            // Credit MoveLine
            MoveLine creditMoveLine = moveLineService.createMoveLine(move, partner, moveLine.getAccount(), moveLine.getDebit(), false, rejectionDate, ref, chequeRejection.getName(), chequeRejection.getDescription());
            move.getMoveLineList().add(creditMoveLine);
            creditMoveLine.setInterbankCodeLine(interbankCodeLine);
            creditMoveLine.setDescription(description);
        }
        ref++;
    }
    move.setRejectOk(true);
    moveService.getMoveValidateService().validate(move);
    return move;
}
Also used : Move(com.axelor.apps.account.db.Move) InterbankCodeLine(com.axelor.apps.account.db.InterbankCodeLine) MoveLine(com.axelor.apps.account.db.MoveLine) Journal(com.axelor.apps.account.db.Journal) Partner(com.axelor.apps.base.db.Partner) LocalDate(java.time.LocalDate) PaymentVoucher(com.axelor.apps.account.db.PaymentVoucher)

Example 10 with Partner

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

the class ConvertLeadWizardController method createContactData.

@SuppressWarnings("unchecked")
private Partner createContactData(Context context, Partner partner) throws AxelorException {
    Partner contactPartner = null;
    Integer leadToContactSelect = (Integer) context.get("leadToContactSelect");
    ConvertLeadWizardService convertLeadWizardService = Beans.get(ConvertLeadWizardService.class);
    if (leadToContactSelect == null) {
        return null;
    }
    if (leadToContactSelect == LeadRepository.CONVERT_LEAD_CREATE_CONTACT && partner.getPartnerTypeSelect() != PartnerRepository.PARTNER_TYPE_INDIVIDUAL) {
        Address primaryAddress = convertLeadWizardService.createPrimaryAddress(context);
        if (primaryAddress != null && (primaryAddress.getAddressL6() == null || primaryAddress.getAddressL7Country() == null)) {
            throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.LEAD_CONTACT_MISSING_ADDRESS));
        }
        contactPartner = convertLeadWizardService.createPartner((Map<String, Object>) context.get("contactPartner"), primaryAddress);
        contactPartner.setIsContact(true);
    // TODO check all required fields...
    } else if (leadToContactSelect == LeadRepository.CONVERT_LEAD_SELECT_CONTACT && partner.getPartnerTypeSelect() != PartnerRepository.PARTNER_TYPE_INDIVIDUAL) {
        Map<String, Object> selectContactContext = (Map<String, Object>) context.get("selectContact");
        contactPartner = Beans.get(PartnerRepository.class).find(((Integer) selectContactContext.get("id")).longValue());
    }
    return contactPartner;
}
Also used : PartnerRepository(com.axelor.apps.base.db.repo.PartnerRepository) AxelorException(com.axelor.exception.AxelorException) Address(com.axelor.apps.base.db.Address) Partner(com.axelor.apps.base.db.Partner) Map(java.util.Map) ConvertLeadWizardService(com.axelor.apps.crm.service.ConvertLeadWizardService)

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