Search in sources :

Example 11 with AccountingSituation

use of com.axelor.apps.account.db.AccountingSituation 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 12 with AccountingSituation

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

the class PartnerController method createAccountingSituations.

public void createAccountingSituations(ActionRequest request, ActionResponse response) throws AxelorException {
    Partner partner = request.getContext().asType(Partner.class);
    List<AccountingSituation> accountingSituationList = Beans.get(AccountingSituationInitService.class).createAccountingSituation(Beans.get(PartnerRepository.class).find(partner.getId()));
    if (accountingSituationList != null) {
        response.setValue("accountingSituationList", accountingSituationList);
    }
}
Also used : AccountingSituationInitService(com.axelor.apps.account.service.AccountingSituationInitService) AccountingSituation(com.axelor.apps.account.db.AccountingSituation) Partner(com.axelor.apps.base.db.Partner)

Example 13 with AccountingSituation

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

the class ImportPartnerAccount method importAccountingSituation.

public Object importAccountingSituation(Object bean, Map<String, Object> values) {
    assert bean instanceof Partner;
    try {
        Partner partner = (Partner) bean;
        for (Company company : partner.getCompanySet()) {
            AccountingSituation accountingSituation = new AccountingSituation();
            accountingSituation.setPartner(partner);
            accountingSituation.setCompany(company);
            accountingSituation.setCustomerAccount(accountRepo.all().filter("self.code = ?1 AND self.company = ?2", values.get("customerAccount_code").toString(), company).fetchOne());
            accountingSituation.setSupplierAccount(accountRepo.all().filter("self.code = ?1 AND self.company = ?2", values.get("supplierAccount_code").toString(), company).fetchOne());
            if (partner.getAccountingSituationList() == null) {
                partner.setAccountingSituationList(new ArrayList<AccountingSituation>());
            }
            partner.getAccountingSituationList().add(accountingSituation);
        }
        return partner;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return bean;
}
Also used : Company(com.axelor.apps.base.db.Company) AccountingSituation(com.axelor.apps.account.db.AccountingSituation) Partner(com.axelor.apps.base.db.Partner)

Example 14 with AccountingSituation

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

the class AccountingSituationSupplychainController method computeUsedCredit.

public void computeUsedCredit(ActionRequest request, ActionResponse response) {
    AccountingSituation accountingSituation = request.getContext().asType(AccountingSituation.class);
    try {
        accountingSituation = Beans.get(AccountingSituationSupplychainServiceImpl.class).computeUsedCredit(accountingSituation);
        response.setValue("usedCredit", accountingSituation.getUsedCredit());
    } catch (Exception e) {
        TraceBackService.trace(e);
        response.setError(e.getMessage());
    }
}
Also used : AccountingSituation(com.axelor.apps.account.db.AccountingSituation)

Example 15 with AccountingSituation

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

the class AccountCustomerService method flagPartners.

@Transactional(rollbackOn = { Exception.class })
public void flagPartners(List<Partner> partnerList, Company company) throws AxelorException {
    for (Partner partner : partnerList) {
        AccountingSituation accountingSituation = accountingSituationService.getAccountingSituation(partner, company);
        if (accountingSituation == null) {
            accountingSituation = accountingSituationInitService.createAccountingSituation(partner, company);
        }
        if (accountingSituation != null) {
            accountingSituation.setCustAccountMustBeUpdateOk(true);
            accSituationRepo.save(accountingSituation);
        }
    }
}
Also used : AccountingSituation(com.axelor.apps.account.db.AccountingSituation) Partner(com.axelor.apps.base.db.Partner) Transactional(com.google.inject.persist.Transactional)

Aggregations

AccountingSituation (com.axelor.apps.account.db.AccountingSituation)26 Partner (com.axelor.apps.base.db.Partner)9 Company (com.axelor.apps.base.db.Company)8 AccountConfig (com.axelor.apps.account.db.AccountConfig)6 AxelorException (com.axelor.exception.AxelorException)6 AccountingSituationService (com.axelor.apps.account.service.AccountingSituationService)5 Transactional (com.google.inject.persist.Transactional)5 BankDetails (com.axelor.apps.base.db.BankDetails)4 BigDecimal (java.math.BigDecimal)4 Account (com.axelor.apps.account.db.Account)3 DebtRecovery (com.axelor.apps.account.db.DebtRecovery)3 Invoice (com.axelor.apps.account.db.Invoice)3 PaymentMode (com.axelor.apps.account.db.PaymentMode)3 AccountingSituationRepository (com.axelor.apps.account.db.repo.AccountingSituationRepository)3 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)2 MoveLine (com.axelor.apps.account.db.MoveLine)2 InvoiceRepository (com.axelor.apps.account.db.repo.InvoiceRepository)2 AccountConfigService (com.axelor.apps.account.service.config.AccountConfigService)2 PaymentModeService (com.axelor.apps.account.service.payment.PaymentModeService)2 Address (com.axelor.apps.base.db.Address)2