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);
}
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;
}
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);
}
}
}
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);
}
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;
}
Aggregations