Search in sources :

Example 6 with AppBaseService

use of com.axelor.apps.base.service.app.AppBaseService in project axelor-open-suite by axelor.

the class TimesheetLineServiceImpl method computeHoursDuration.

@Override
public BigDecimal computeHoursDuration(Timesheet timesheet, BigDecimal duration, boolean toHours) throws AxelorException {
    if (duration == null) {
        return null;
    }
    AppBaseService appBaseService = Beans.get(AppBaseService.class);
    BigDecimal dailyWorkHrs;
    String timePref;
    log.debug("Get user duration for duration: {}, timesheet: {}", duration, timesheet == null ? "null" : timesheet.getFullName());
    if (timesheet != null) {
        User user = timesheet.getUser();
        timePref = timesheet.getTimeLoggingPreferenceSelect();
        if (user.getEmployee() != null) {
            Employee employee = employeeRepository.find(user.getEmployee().getId());
            log.debug("Employee: {}", employee);
            dailyWorkHrs = employee.getDailyWorkHours();
            if (timePref == null) {
                timePref = employee.getTimeLoggingPreferenceSelect();
            }
        } else {
            dailyWorkHrs = appBaseService.getAppBase().getDailyWorkHours();
        }
    } else {
        timePref = appBaseService.getAppBase().getTimeLoggingPreferenceSelect();
        dailyWorkHrs = appBaseService.getAppBase().getDailyWorkHours();
    }
    return computeHoursDuration(timePref, duration, dailyWorkHrs, toHours);
}
Also used : User(com.axelor.auth.db.User) Employee(com.axelor.apps.hr.db.Employee) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) BigDecimal(java.math.BigDecimal)

Example 7 with AppBaseService

use of com.axelor.apps.base.service.app.AppBaseService in project axelor-open-suite by axelor.

the class SaleOrderServiceImpl method handleComplementaryProducts.

@Override
public List<SaleOrderLine> handleComplementaryProducts(SaleOrder saleOrder) throws AxelorException {
    List<SaleOrderLine> saleOrderLineList = saleOrder.getSaleOrderLineList();
    if (saleOrderLineList == null) {
        saleOrderLineList = new ArrayList<>();
    }
    SaleOrderLine originSoLine = null;
    for (SaleOrderLine soLine : saleOrderLineList) {
        if (soLine.getIsComplementaryProductsUnhandledYet()) {
            originSoLine = soLine;
            if (originSoLine.getManualId() == null || originSoLine.getManualId().equals("")) {
                this.setNewManualId(originSoLine);
            }
            break;
        }
    }
    if (originSoLine != null && originSoLine.getProduct() != null && originSoLine.getSelectedComplementaryProductList() != null) {
        SaleOrderLineService saleOrderLineService = Beans.get(SaleOrderLineService.class);
        AppBaseService appBaseService = Beans.get(AppBaseService.class);
        for (ComplementaryProductSelected compProductSelected : originSoLine.getSelectedComplementaryProductList()) {
            // Search if there is already a line for this product to modify or remove
            SaleOrderLine newSoLine = null;
            for (SaleOrderLine soLine : saleOrderLineList) {
                if (originSoLine.getManualId().equals(soLine.getParentId()) && soLine.getProduct() != null && soLine.getProduct().equals(compProductSelected.getProduct())) {
                    // exists and is no longer selected
                    if (compProductSelected.getIsSelected()) {
                        newSoLine = soLine;
                    } else {
                        saleOrderLineList.remove(soLine);
                    }
                    break;
                }
            }
            if (newSoLine == null) {
                if (compProductSelected.getIsSelected()) {
                    newSoLine = new SaleOrderLine();
                    newSoLine.setProduct(compProductSelected.getProduct());
                    newSoLine.setSaleOrder(saleOrder);
                    newSoLine.setQty(originSoLine.getQty().multiply(compProductSelected.getQty()).setScale(appBaseService.getNbDecimalDigitForQty(), RoundingMode.HALF_EVEN));
                    saleOrderLineService.computeProductInformation(newSoLine, newSoLine.getSaleOrder());
                    saleOrderLineService.computeValues(newSoLine.getSaleOrder(), newSoLine);
                    newSoLine.setParentId(originSoLine.getManualId());
                    int targetIndex = saleOrderLineList.indexOf(originSoLine) + 1;
                    saleOrderLineList.add(targetIndex, newSoLine);
                }
            } else {
                newSoLine.setQty(originSoLine.getQty().multiply(compProductSelected.getQty()).setScale(appBaseService.getNbDecimalDigitForQty(), RoundingMode.HALF_EVEN));
                saleOrderLineService.computeProductInformation(newSoLine, newSoLine.getSaleOrder());
                saleOrderLineService.computeValues(newSoLine.getSaleOrder(), newSoLine);
            }
        }
        originSoLine.setIsComplementaryProductsUnhandledYet(false);
    }
    for (int i = 0; i < saleOrderLineList.size(); i++) {
        saleOrderLineList.get(i).setSequence(i);
    }
    return saleOrderLineList;
}
Also used : ComplementaryProductSelected(com.axelor.apps.sale.db.ComplementaryProductSelected) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine)

Example 8 with AppBaseService

use of com.axelor.apps.base.service.app.AppBaseService in project axelor-open-suite by axelor.

the class CompanyServiceImpl method checkMultiBanks.

/**
 * {@inheritDoc}
 */
@Override
public void checkMultiBanks(Company company) {
    if (countActiveBankDetails(company) > 1) {
        AppBaseService appBaseService = Beans.get(AppBaseService.class);
        AppBase appBase = appBaseService.getAppBase();
        if (!appBase.getManageMultiBanks()) {
            appBaseService.setManageMultiBanks(true);
        }
    }
}
Also used : AppBaseService(com.axelor.apps.base.service.app.AppBaseService) AppBase(com.axelor.apps.base.db.AppBase)

Example 9 with AppBaseService

use of com.axelor.apps.base.service.app.AppBaseService in project axelor-open-suite by axelor.

the class SubrogationReleaseServiceImpl method enterReleaseInTheAccounts.

@Override
@Transactional(rollbackOn = { Exception.class })
public void enterReleaseInTheAccounts(SubrogationRelease subrogationRelease) throws AxelorException {
    MoveService moveService = Beans.get(MoveService.class);
    MoveRepository moveRepository = Beans.get(MoveRepository.class);
    AccountConfigService accountConfigService = Beans.get(AccountConfigService.class);
    AppBaseService appBaseService = Beans.get(AppBaseService.class);
    Company company = subrogationRelease.getCompany();
    AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
    Journal journal = accountConfigService.getAutoMiscOpeJournal(accountConfig);
    Account factorCreditAccount = accountConfigService.getFactorCreditAccount(accountConfig);
    Account factorDebitAccount = accountConfigService.getFactorDebitAccount(accountConfig);
    if (subrogationRelease.getAccountingDate() == null) {
        subrogationRelease.setAccountingDate(appBaseService.getTodayDate(company));
    }
    this.checkIfAnOtherSubrogationAlreadyExist(subrogationRelease);
    for (Invoice invoice : subrogationRelease.getInvoiceSet()) {
        boolean isRefund = false;
        if (invoice.getOperationTypeSelect() == InvoiceRepository.OPERATION_TYPE_CLIENT_REFUND) {
            isRefund = true;
        }
        LocalDate date = subrogationRelease.getAccountingDate();
        Move move = moveService.getMoveCreateService().createMove(journal, company, company.getCurrency(), invoice.getPartner(), date, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
        MoveLine creditMoveLine, debitMoveLine;
        debitMoveLine = moveService.getMoveLineService().createMoveLine(move, invoice.getPartner(), factorDebitAccount, invoice.getCompanyInTaxTotalRemaining(), !isRefund, date, null, 1, subrogationRelease.getSequenceNumber(), invoice.getInvoiceId());
        creditMoveLine = moveService.getMoveLineService().createMoveLine(move, invoice.getPartner(), factorCreditAccount, invoice.getCompanyInTaxTotalRemaining(), isRefund, date, null, 2, subrogationRelease.getSequenceNumber(), invoice.getInvoiceId());
        move.addMoveLineListItem(debitMoveLine);
        move.addMoveLineListItem(creditMoveLine);
        move = moveRepository.save(move);
        moveService.getMoveValidateService().validate(move);
        invoice.setSubrogationRelease(subrogationRelease);
        invoice.setSubrogationReleaseMove(move);
        subrogationRelease.addMoveListItem(move);
    }
    subrogationRelease.setStatusSelect(SubrogationReleaseRepository.STATUS_ACCOUNTED);
}
Also used : MoveRepository(com.axelor.apps.account.db.repo.MoveRepository) Account(com.axelor.apps.account.db.Account) Company(com.axelor.apps.base.db.Company) Invoice(com.axelor.apps.account.db.Invoice) MoveService(com.axelor.apps.account.service.move.MoveService) Journal(com.axelor.apps.account.db.Journal) LocalDate(java.time.LocalDate) AccountConfig(com.axelor.apps.account.db.AccountConfig) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) Move(com.axelor.apps.account.db.Move) AccountConfigService(com.axelor.apps.account.service.config.AccountConfigService) MoveLine(com.axelor.apps.account.db.MoveLine) Transactional(com.google.inject.persist.Transactional)

Example 10 with AppBaseService

use of com.axelor.apps.base.service.app.AppBaseService in project axelor-open-suite by axelor.

the class ManufOrderServiceImpl method generateWasteStockMove.

@Override
@Transactional(rollbackOn = { Exception.class })
public StockMove generateWasteStockMove(ManufOrder manufOrder) throws AxelorException {
    StockMove wasteStockMove = null;
    Company company = manufOrder.getCompany();
    if (manufOrder.getWasteProdProductList() == null || company == null || manufOrder.getWasteProdProductList().isEmpty()) {
        return wasteStockMove;
    }
    StockConfigProductionService stockConfigService = Beans.get(StockConfigProductionService.class);
    StockMoveService stockMoveService = Beans.get(StockMoveService.class);
    StockMoveLineService stockMoveLineService = Beans.get(StockMoveLineService.class);
    AppBaseService appBaseService = Beans.get(AppBaseService.class);
    StockConfig stockConfig = stockConfigService.getStockConfig(company);
    StockLocation virtualStockLocation = stockConfigService.getProductionVirtualStockLocation(stockConfig, false);
    StockLocation wasteStockLocation = stockConfigService.getWasteStockLocation(stockConfig);
    wasteStockMove = stockMoveService.createStockMove(virtualStockLocation.getAddress(), wasteStockLocation.getAddress(), company, virtualStockLocation, wasteStockLocation, null, appBaseService.getTodayDate(company), manufOrder.getWasteProdDescription(), StockMoveRepository.TYPE_INTERNAL);
    for (ProdProduct prodProduct : manufOrder.getWasteProdProductList()) {
        stockMoveLineService.createStockMoveLine(prodProduct.getProduct(), (String) productCompanyService.get(prodProduct.getProduct(), "name", company), (String) productCompanyService.get(prodProduct.getProduct(), "description", company), prodProduct.getQty(), (BigDecimal) productCompanyService.get(prodProduct.getProduct(), "costPrice", company), (BigDecimal) productCompanyService.get(prodProduct.getProduct(), "costPrice", company), prodProduct.getUnit(), wasteStockMove, StockMoveLineService.TYPE_WASTE_PRODUCTIONS, false, BigDecimal.ZERO);
    }
    stockMoveService.validate(wasteStockMove);
    manufOrder.setWasteStockMove(wasteStockMove);
    return wasteStockMove;
}
Also used : StockMoveLineService(com.axelor.apps.stock.service.StockMoveLineService) Company(com.axelor.apps.base.db.Company) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveService(com.axelor.apps.stock.service.StockMoveService) OperationOrderStockMoveService(com.axelor.apps.production.service.operationorder.OperationOrderStockMoveService) StockConfig(com.axelor.apps.stock.db.StockConfig) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) StockLocation(com.axelor.apps.stock.db.StockLocation) StockConfigProductionService(com.axelor.apps.production.service.config.StockConfigProductionService) ProdProduct(com.axelor.apps.production.db.ProdProduct) Transactional(com.google.inject.persist.Transactional)

Aggregations

AppBaseService (com.axelor.apps.base.service.app.AppBaseService)10 Transactional (com.google.inject.persist.Transactional)4 Company (com.axelor.apps.base.db.Company)3 Employee (com.axelor.apps.hr.db.Employee)3 LocalDate (java.time.LocalDate)3 StockMove (com.axelor.apps.stock.db.StockMove)2 User (com.axelor.auth.db.User)2 BigDecimal (java.math.BigDecimal)2 Account (com.axelor.apps.account.db.Account)1 AccountConfig (com.axelor.apps.account.db.AccountConfig)1 Invoice (com.axelor.apps.account.db.Invoice)1 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)1 Journal (com.axelor.apps.account.db.Journal)1 Move (com.axelor.apps.account.db.Move)1 MoveLine (com.axelor.apps.account.db.MoveLine)1 MoveRepository (com.axelor.apps.account.db.repo.MoveRepository)1 AccountConfigService (com.axelor.apps.account.service.config.AccountConfigService)1 InvoiceLineService (com.axelor.apps.account.service.invoice.InvoiceLineService)1 MoveService (com.axelor.apps.account.service.move.MoveService)1 AppBase (com.axelor.apps.base.db.AppBase)1