Search in sources :

Example 51 with Partner

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

the class EmployeeServiceImpl method generateNewDPAE.

@Override
@Transactional(rollbackOn = { Exception.class })
public Long generateNewDPAE(Employee employee) throws AxelorException {
    EmploymentContract mainEmploymentContract = employee.getMainEmploymentContract();
    if (mainEmploymentContract == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.EMPLOYEE_CONTRACT_OF_EMPLOYMENT), employee.getName());
    }
    Company payCompany = mainEmploymentContract.getPayCompany();
    Partner employer = payCompany.getPartner();
    DPAE newDPAE = new DPAE();
    // Employer
    newDPAE.setRegistrationCode(employer.getRegistrationCode());
    if (employer.getMainActivity() != null && employer.getMainActivity().getFullName() != null) {
        newDPAE.setMainActivityCode(employer.getMainActivity().getFullName());
    }
    newDPAE.setCompany(payCompany);
    newDPAE.setCompanyAddress(employer.getMainAddress());
    newDPAE.setCompanyFixedPhone(employer.getFixedPhone());
    if (payCompany.getHrConfig() != null) {
        newDPAE.setHealthService(payCompany.getHrConfig().getHealthService());
        newDPAE.setHealthServiceAddress(payCompany.getHrConfig().getHealthServiceAddress());
    }
    // Employee
    newDPAE.setLastName(employee.getContactPartner().getName());
    newDPAE.setFirstName(employee.getContactPartner().getFirstName());
    newDPAE.setSocialSecurityNumber(employee.getSocialSecurityNumber());
    newDPAE.setSexSelect(employee.getSexSelect());
    newDPAE.setBirthDate(employee.getBirthDate());
    newDPAE.setDepartmentOfBirth(employee.getDepartmentOfBirth());
    newDPAE.setCityOfBirth(employee.getCityOfBirth());
    newDPAE.setCountryOfBirth(employee.getCountryOfBirth());
    // Contract
    newDPAE.setHireDate(mainEmploymentContract.getStartDate());
    newDPAE.setHireTime(mainEmploymentContract.getStartTime());
    newDPAE.setTrialPeriodDuration(mainEmploymentContract.getTrialPeriodDuration());
    newDPAE.setContractType(mainEmploymentContract.getContractType());
    newDPAE.setContractEndDate(mainEmploymentContract.getEndDate());
    employee.addDpaeListItem(newDPAE);
    Beans.get(EmployeeRepository.class).save(employee);
    return newDPAE.getId();
}
Also used : EmploymentContract(com.axelor.apps.hr.db.EmploymentContract) DPAE(com.axelor.apps.hr.db.DPAE) AxelorException(com.axelor.exception.AxelorException) EmployeeRepository(com.axelor.apps.hr.db.repo.EmployeeRepository) Company(com.axelor.apps.base.db.Company) Partner(com.axelor.apps.base.db.Partner) Transactional(com.google.inject.persist.Transactional)

Example 52 with Partner

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

the class EmployeeHRRepository method save.

@Override
public Employee save(Employee entity) {
    Partner partner = entity.getContactPartner();
    if (!partner.getIsContact() && partner.getPartnerTypeSelect() == 0) {
        partner.setIsContact(true);
        partner.setIsEmployee(true);
        Beans.get(PartnerHRRepository.class).save(partner);
    } else {
        Beans.get(PartnerService.class).setPartnerFullName(partner);
    }
    EmploymentContract employmentContract = entity.getMainEmploymentContract();
    if (employmentContract != null && employmentContract.getEmployee() == null) {
        employmentContract.setEmployee(entity);
    }
    return super.save(entity);
}
Also used : EmploymentContract(com.axelor.apps.hr.db.EmploymentContract) PartnerService(com.axelor.apps.base.service.PartnerService) Partner(com.axelor.apps.base.db.Partner)

Example 53 with Partner

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

the class SaleOrderInvoiceServiceImpl method createInvoiceAndLines.

public Invoice createInvoiceAndLines(SaleOrder saleOrder, List<SaleOrderLineTax> taxLineList, Product invoicingProduct, BigDecimal percentToInvoice, int operationSubTypeSelect, Account partnerAccount) throws AxelorException {
    InvoiceGenerator invoiceGenerator = this.createInvoiceGenerator(saleOrder);
    Invoice invoice = invoiceGenerator.generate();
    List<InvoiceLine> invoiceLinesList = (taxLineList != null && !taxLineList.isEmpty()) ? this.createInvoiceLinesFromTax(invoice, taxLineList, invoicingProduct, percentToInvoice) : this.createInvoiceLinesFromSO(invoice, saleOrder, invoicingProduct, percentToInvoice);
    invoiceGenerator.populate(invoice, invoiceLinesList);
    invoice.setAddressStr(saleOrder.getMainInvoicingAddressStr());
    invoice.setOperationSubTypeSelect(operationSubTypeSelect);
    if (partnerAccount != null) {
        Partner partner = invoice.getPartner();
        if (partner != null) {
            partnerAccount = Beans.get(FiscalPositionAccountService.class).getAccount(partner.getFiscalPosition(), partnerAccount);
        }
        invoice.setPartnerAccount(partnerAccount);
    }
    return invoice;
}
Also used : Invoice(com.axelor.apps.account.db.Invoice) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) InvoiceGenerator(com.axelor.apps.account.service.invoice.generator.InvoiceGenerator) Partner(com.axelor.apps.base.db.Partner)

Example 54 with Partner

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

the class IntercoServiceImpl method createIntercoInvoiceLine.

protected InvoiceLine createIntercoInvoiceLine(InvoiceLine invoiceLine, boolean isPurchase) throws AxelorException {
    AccountManagementAccountService accountManagementAccountService = Beans.get(AccountManagementAccountService.class);
    InvoiceLineService invoiceLineService = Beans.get(InvoiceLineService.class);
    Invoice intercoInvoice = invoiceLine.getInvoice();
    Partner partner = intercoInvoice.getPartner();
    if (intercoInvoice.getCompany() != null) {
        Account account = accountManagementAccountService.getProductAccount(invoiceLine.getProduct(), intercoInvoice.getCompany(), partner.getFiscalPosition(), isPurchase, false);
        invoiceLine.setAccount(account);
        TaxLine taxLine = invoiceLineService.getTaxLine(intercoInvoice, invoiceLine, isPurchase);
        invoiceLine.setTaxLine(taxLine);
        invoiceLine.setTaxRate(taxLine.getValue());
        invoiceLine.setTaxCode(taxLine.getTax().getCode());
        TaxEquiv taxEquiv = accountManagementAccountService.getProductTaxEquiv(invoiceLine.getProduct(), intercoInvoice.getCompany(), intercoInvoice.getPartner().getFiscalPosition(), isPurchase);
        invoiceLine.setTaxEquiv(taxEquiv);
        invoiceLine.setCompanyExTaxTotal(invoiceLineService.getCompanyExTaxTotal(invoiceLine.getExTaxTotal(), intercoInvoice));
        invoiceLine.setCompanyInTaxTotal(invoiceLineService.getCompanyExTaxTotal(invoiceLine.getInTaxTotal(), intercoInvoice));
        if (invoiceLine.getAnalyticDistributionTemplate() != null) {
            invoiceLine.setAnalyticDistributionTemplate(accountManagementAccountService.getAnalyticDistributionTemplate(invoiceLine.getProduct(), intercoInvoice.getCompany()));
            List<AnalyticMoveLine> analyticMoveLineList = invoiceLineService.createAnalyticDistributionWithTemplate(invoiceLine);
            analyticMoveLineList.forEach(analyticMoveLine -> analyticMoveLine.setInvoiceLine(invoiceLine));
            invoiceLine.setAnalyticMoveLineList(analyticMoveLineList);
        }
    }
    return invoiceLine;
}
Also used : Account(com.axelor.apps.account.db.Account) Invoice(com.axelor.apps.account.db.Invoice) AccountManagementAccountService(com.axelor.apps.account.service.AccountManagementAccountService) InvoiceLineService(com.axelor.apps.account.service.invoice.InvoiceLineService) Partner(com.axelor.apps.base.db.Partner) TaxEquiv(com.axelor.apps.account.db.TaxEquiv) TaxLine(com.axelor.apps.account.db.TaxLine) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine)

Example 55 with Partner

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

the class AccountingSituationSupplychainServiceImpl method updateCustomerCreditFromSaleOrder.

@Override
@Transactional(rollbackOn = { AxelorException.class, Exception.class }, ignore = { BlockedSaleOrderException.class })
public void updateCustomerCreditFromSaleOrder(SaleOrder saleOrder) throws AxelorException {
    if (!appAccountService.getAppAccount().getManageCustomerCredit()) {
        return;
    }
    Partner partner = saleOrder.getClientPartner();
    List<AccountingSituation> accountingSituationList = partner.getAccountingSituationList();
    for (AccountingSituation accountingSituation : accountingSituationList) {
        if (accountingSituation.getCompany().equals(saleOrder.getCompany())) {
            // Update UsedCredit
            accountingSituation = this.computeUsedCredit(accountingSituation);
            if (saleOrder.getStatusSelect() == SaleOrderRepository.STATUS_DRAFT_QUOTATION) {
                BigDecimal inTaxInvoicedAmount = getInTaxInvoicedAmount(saleOrder);
                BigDecimal usedCredit = accountingSituation.getUsedCredit().add(saleOrder.getInTaxTotal()).subtract(inTaxInvoicedAmount);
                accountingSituation.setUsedCredit(usedCredit);
            }
            boolean usedCreditExceeded = isUsedCreditExceeded(accountingSituation);
            if (usedCreditExceeded) {
                saleOrder.setBlockedOnCustCreditExceed(true);
                if (!saleOrder.getManualUnblock()) {
                    String message = accountingSituation.getCompany().getOrderBloquedMessage();
                    if (Strings.isNullOrEmpty(message)) {
                        message = String.format(I18n.get(IExceptionMessage.SALE_ORDER_CLIENT_PARTNER_EXCEEDED_CREDIT), partner.getFullName(), saleOrder.getSaleOrderSeq());
                    }
                    throw new BlockedSaleOrderException(accountingSituation, message);
                }
            }
        }
    }
}
Also used : AccountingSituation(com.axelor.apps.account.db.AccountingSituation) BlockedSaleOrderException(com.axelor.apps.sale.exception.BlockedSaleOrderException) Partner(com.axelor.apps.base.db.Partner) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

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