use of com.axelor.apps.base.db.Company in project axelor-open-suite by axelor.
the class ExpenseServiceImpl method createAndSetMove.
protected Move createAndSetMove(Expense expense) throws AxelorException {
LocalDate moveDate = expense.getMoveDate();
if (moveDate == null) {
moveDate = appAccountService.getTodayDate(expense.getCompany());
expense.setMoveDate(moveDate);
}
Company company = expense.getCompany();
Partner partner = expense.getUser().getPartner();
Account account = null;
AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
if (partner == null) {
throw new AxelorException(expense, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(com.axelor.apps.account.exception.IExceptionMessage.USER_PARTNER), expense.getUser().getName());
}
Move move = moveService.getMoveCreateService().createMove(accountConfigService.getExpenseJournal(accountConfig), company, null, partner, moveDate, partner.getInPaymentMode(), MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PURCHASE);
List<MoveLine> moveLines = new ArrayList<>();
Set<AnalyticAccount> analyticAccounts = new HashSet<>();
BigDecimal exTaxTotal = null;
int moveLineId = 1;
int expenseLineId = 1;
Account employeeAccount = accountingSituationService.getEmployeeAccount(partner, company);
moveLines.add(moveLineService.createMoveLine(move, partner, employeeAccount, expense.getInTaxTotal(), false, moveDate, moveDate, moveLineId++, expense.getExpenseSeq(), expense.getFullName()));
for (ExpenseLine expenseLine : getExpenseLineList(expense)) {
analyticAccounts.clear();
Product product = expenseLine.getExpenseProduct();
account = accountManagementService.getProductAccount(product, company, partner.getFiscalPosition(), true, false);
if (account == null) {
throw new AxelorException(expense, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(com.axelor.apps.account.exception.IExceptionMessage.MOVE_LINE_4), expenseLineId, company.getName());
}
exTaxTotal = expenseLine.getUntaxedAmount();
MoveLine moveLine = moveLineService.createMoveLine(move, partner, account, exTaxTotal, true, moveDate, moveDate, moveLineId++, expense.getExpenseSeq(), expenseLine.getComments() != null ? expenseLine.getComments().replaceAll("(\r\n|\n\r|\r|\n)", " ") : "");
for (AnalyticMoveLine analyticDistributionLineIt : expenseLine.getAnalyticMoveLineList()) {
AnalyticMoveLine analyticDistributionLine = Beans.get(AnalyticMoveLineRepository.class).copy(analyticDistributionLineIt, false);
analyticDistributionLine.setExpenseLine(null);
moveLine.addAnalyticMoveLineListItem(analyticDistributionLine);
}
moveLines.add(moveLine);
expenseLineId++;
}
moveLineService.consolidateMoveLines(moveLines);
account = accountConfigService.getExpenseTaxAccount(accountConfig);
BigDecimal taxTotal = BigDecimal.ZERO;
for (ExpenseLine expenseLine : getExpenseLineList(expense)) {
exTaxTotal = expenseLine.getTotalTax();
taxTotal = taxTotal.add(exTaxTotal);
}
if (taxTotal.signum() != 0) {
MoveLine moveLine = moveLineService.createMoveLine(move, partner, account, taxTotal, true, moveDate, moveDate, moveLineId++, expense.getExpenseSeq(), expense.getFullName());
moveLines.add(moveLine);
}
move.getMoveLineList().addAll(moveLines);
moveService.getMoveValidateService().validate(move);
expense.setMove(move);
return move;
}
use of com.axelor.apps.base.db.Company in project axelor-open-suite by axelor.
the class HumanResourceMobileController method insertLeave.
/*
* This method is used in mobile application.
* It was in LeaveServiceImpl
* @param request
* @param response
*
* POST /open-suite-webapp/ws/action/com.axelor.apps.hr.mobile.HumanResourceMobileController:insertLeave
* Content-Type: application/json
*
* URL: com.axelor.apps.hr.mobile.HumanResourceMobileController:insertLeave
* fields: leaveReason, fromDateT, startOn, toDateT, endOn, comment
*
* payload:
* { "data": {
* "action": "com.axelor.apps.hr.mobile.HumanResourceMobileController:insertLeave",
* "leaveReason": 10,
* "fromDateT": "2018-02-22T10:30:00",
* "startOn": 1,
* "toDateT": "2018-02-24T:19:30:00",
* "endOn": 1,
* "comment": "no"
* } }
*/
@Transactional(rollbackOn = { Exception.class })
public void insertLeave(ActionRequest request, ActionResponse response) throws AxelorException {
AppBaseService appBaseService = Beans.get(AppBaseService.class);
User user = AuthUtils.getUser();
Map<String, Object> requestData = request.getData();
LeaveReason leaveReason = Beans.get(LeaveReasonRepository.class).find(Long.valueOf(requestData.get("leaveReason").toString()));
Employee employee = user.getEmployee();
if (employee == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LEAVE_USER_EMPLOYEE), user.getName());
}
if (leaveReason != null) {
LeaveRequest leave = new LeaveRequest();
leave.setUser(user);
Company company = null;
if (employee.getMainEmploymentContract() != null) {
company = employee.getMainEmploymentContract().getPayCompany();
}
leave.setCompany(company);
LeaveLine leaveLine = Beans.get(LeaveLineRepository.class).all().filter("self.employee = ?1 AND self.leaveReason = ?2", employee, leaveReason).fetchOne();
if (leaveLine == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LEAVE_LINE), employee.getName(), leaveReason.getName());
}
leave.setLeaveReason(leaveReason);
leave.setRequestDate(appBaseService.getTodayDate(company));
if (requestData.get("fromDateT") != null) {
leave.setFromDateT(LocalDateTime.parse(requestData.get("fromDateT").toString(), DateTimeFormatter.ISO_LOCAL_DATE_TIME));
}
leave.setStartOnSelect(new Integer(requestData.get("startOn").toString()));
if (requestData.get("toDateT") != null) {
leave.setToDateT(LocalDateTime.parse(requestData.get("toDateT").toString(), DateTimeFormatter.ISO_LOCAL_DATE_TIME));
}
leave.setEndOnSelect(new Integer(requestData.get("endOn").toString()));
leave.setDuration(Beans.get(LeaveService.class).computeDuration(leave));
leave.setStatusSelect(LeaveRequestRepository.STATUS_AWAITING_VALIDATION);
if (requestData.get("comments") != null) {
leave.setComments(requestData.get("comments").toString());
}
leave = Beans.get(LeaveRequestRepository.class).save(leave);
response.setTotal(1);
response.setValue("id", leave.getId());
}
}
use of com.axelor.apps.base.db.Company 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();
}
use of com.axelor.apps.base.db.Company in project axelor-open-suite by axelor.
the class PurchaseOrderStockServiceImpl method getStartStockLocation.
protected StockLocation getStartStockLocation(PurchaseOrder purchaseOrder) throws AxelorException {
Company company = purchaseOrder.getCompany();
StockLocation startLocation = purchaseOrder.getFromStockLocation();
if (startLocation == null) {
startLocation = partnerStockSettingsService.getDefaultExternalStockLocation(purchaseOrder.getSupplierPartner(), company);
}
if (startLocation == null) {
StockConfigService stockConfigService = Beans.get(StockConfigService.class);
StockConfig stockConfig = stockConfigService.getStockConfig(company);
startLocation = stockConfigService.getSupplierVirtualStockLocation(stockConfig);
}
if (startLocation == null) {
throw new AxelorException(purchaseOrder, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.PURCHASE_ORDER_1), company.getName());
}
return startLocation;
}
use of com.axelor.apps.base.db.Company in project axelor-open-suite by axelor.
the class ReservedQtyServiceImpl method updateRequestedQuantityInToStockLocation.
@Override
public void updateRequestedQuantityInToStockLocation(StockMoveLine stockMoveLine, StockLocation stockLocation, Product product, int toStatus, BigDecimal qty) throws AxelorException {
if (product == null || !product.getStockManaged()) {
return;
}
StockLocationLine stockLocationLine = stockLocationLineService.getStockLocationLine(stockLocation, product);
if (stockLocationLine == null) {
return;
}
Company company = stockLocationLine.getStockLocation().getCompany();
SupplyChainConfig supplyChainConfig = supplychainConfigService.getSupplyChainConfig(company);
if (toStatus == StockMoveRepository.STATUS_REALIZED && supplyChainConfig.getAutoAllocateOnReceipt()) {
reallocateQty(stockMoveLine, stockLocation, stockLocationLine, product, qty);
}
updateRequestedReservedQty(stockLocationLine);
checkReservedQtyStocks(stockLocationLine, stockMoveLine, toStatus);
}
Aggregations