use of com.axelor.apps.hr.db.TimesheetLine in project axelor-open-suite by axelor.
the class TimesheetTimerServiceImpl method generateTimesheetLine.
@Transactional
public TimesheetLine generateTimesheetLine(TSTimer timer) {
BigDecimal durationHours = this.convertSecondDurationInHours(timer.getDuration());
Timesheet timesheet = Beans.get(TimesheetService.class).getCurrentOrCreateTimesheet();
LocalDate startDateTime = (timer.getStartDateTime() == null) ? Beans.get(AppBaseService.class).getTodayDateTime().toLocalDate() : timer.getStartDateTime().toLocalDate();
TimesheetLine timesheetLine = Beans.get(TimesheetLineService.class).createTimesheetLine(timer.getProject(), timer.getProduct(), timer.getUser(), startDateTime, timesheet, durationHours, timer.getComments());
Beans.get(TimesheetRepository.class).save(timesheet);
Beans.get(TimesheetLineRepository.class).save(timesheetLine);
timer.setTimesheetLine(timesheetLine);
return timesheetLine;
}
use of com.axelor.apps.hr.db.TimesheetLine in project axelor-open-suite by axelor.
the class TimesheetHRRepository method validate.
@Override
public Map<String, Object> validate(Map<String, Object> json, Map<String, Object> context) {
Map<String, Object> obj = super.validate(json, context);
if (json.get("id") == null) {
Timesheet timesheet = create(json);
if (timesheet.getTimesheetLineList() == null || timesheet.getTimesheetLineList().isEmpty()) {
timesheet.setTimesheetLineList(new ArrayList<TimesheetLine>());
obj.put("timesheetLineList", timesheetService.createDefaultLines(timesheet));
}
}
return obj;
}
use of com.axelor.apps.hr.db.TimesheetLine in project axelor-open-suite by axelor.
the class OperationOrderTimesheetServiceImpl method updateOperationOrders.
@Override
@Transactional(rollbackOn = { Exception.class })
public void updateOperationOrders(Timesheet timesheet) throws AxelorException {
if (timesheet.getTimesheetLineList() == null) {
return;
}
// ensure that correct hoursDuration is filled
TimesheetLineService timesheetLineService = Beans.get(TimesheetLineService.class);
for (TimesheetLine timesheetLine : timesheet.getTimesheetLineList()) {
BigDecimal hoursDuration = timesheetLineService.computeHoursDuration(timesheet, timesheetLine.getDuration(), true);
timesheetLine.setHoursDuration(hoursDuration);
}
if (!Beans.get(AppProductionService.class).getAppProduction().getEnableTimesheetOnManufOrder()) {
return;
}
List<TimesheetLine> oldTimesheetLineList = Beans.get(TimesheetLineRepository.class).all().filter("self.timesheet.id = :timesheetId").bind("timesheetId", timesheet.getId()).fetch();
List<TimesheetLine> newTimesheetLineList = timesheet.getTimesheetLineList();
List<TimesheetLine> allTimesheetLineList = new ArrayList<>(oldTimesheetLineList);
allTimesheetLineList.addAll(newTimesheetLineList);
List<OperationOrder> operationOrdersToUpdate = allTimesheetLineList.stream().map(TimesheetLine::getOperationOrder).filter(Objects::nonNull).distinct().collect(Collectors.toList());
operationOrdersToUpdate.forEach(operationOrder -> updateOperationOrder(operationOrder, oldTimesheetLineList, newTimesheetLineList));
}
use of com.axelor.apps.hr.db.TimesheetLine in project axelor-open-suite by axelor.
the class TimesheetProjectServiceImpl method createInvoiceLines.
@Override
public List<InvoiceLine> createInvoiceLines(Invoice invoice, List<TimesheetLine> timesheetLineList, int priority) throws AxelorException {
if (!Beans.get(AppHumanResourceService.class).isApp("business-project")) {
return super.createInvoiceLines(invoice, timesheetLineList, priority);
}
List<InvoiceLine> invoiceLineList = new ArrayList<InvoiceLine>();
int count = 0;
DateTimeFormatter ddmmFormat = DateTimeFormatter.ofPattern("dd/MM");
HashMap<String, Object[]> timeSheetInformationsMap = new HashMap<String, Object[]>();
// Check if a consolidation by product and user must be done
boolean consolidate = appHumanResourceService.getAppTimesheet().getConsolidateTSLine();
for (TimesheetLine timesheetLine : timesheetLineList) {
Object[] tabInformations = new Object[6];
tabInformations[0] = timesheetLine.getProduct();
tabInformations[1] = timesheetLine.getUser();
// Start date
tabInformations[2] = timesheetLine.getDate();
// End date, useful only for consolidation
tabInformations[3] = timesheetLine.getDate();
tabInformations[4] = timesheetLine.getDurationForCustomer() != null ? this.computeDurationForCustomer(timesheetLine) : timesheetLine.getHoursDuration();
tabInformations[5] = timesheetLine.getProject();
String key = null;
if (consolidate) {
key = timesheetLine.getProduct().getId() + "|" + timesheetLine.getUser().getId() + "|" + timesheetLine.getProject().getId();
if (timeSheetInformationsMap.containsKey(key)) {
tabInformations = timeSheetInformationsMap.get(key);
// Update date
if (timesheetLine.getDate().compareTo((LocalDate) tabInformations[2]) < 0) {
// If date is lower than start date then replace start date by this one
tabInformations[2] = timesheetLine.getDate();
} else if (timesheetLine.getDate().compareTo((LocalDate) tabInformations[3]) > 0) {
// If date is upper than end date then replace end date by this one
tabInformations[3] = timesheetLine.getDate();
}
tabInformations[4] = ((BigDecimal) tabInformations[4]).add(timesheetLine.getDurationForCustomer() != null ? this.computeDurationForCustomer(timesheetLine) : timesheetLine.getHoursDuration());
} else {
timeSheetInformationsMap.put(key, tabInformations);
}
} else {
key = String.valueOf(timesheetLine.getId());
timeSheetInformationsMap.put(key, tabInformations);
}
}
for (Object[] timesheetInformations : timeSheetInformationsMap.values()) {
String strDate = null;
Product product = (Product) timesheetInformations[0];
User user = (User) timesheetInformations[1];
LocalDate startDate = (LocalDate) timesheetInformations[2];
LocalDate endDate = (LocalDate) timesheetInformations[3];
BigDecimal hoursDuration = (BigDecimal) timesheetInformations[4];
Project project = (Project) timesheetInformations[5];
PriceList priceList = project.getPriceList();
if (consolidate) {
if (startDate != null && endDate != null) {
strDate = startDate.format(ddmmFormat) + " - " + endDate.format(ddmmFormat);
}
} else {
if (startDate != null) {
strDate = startDate.format(ddmmFormat);
}
}
invoiceLineList.addAll(this.createInvoiceLine(invoice, product, user, strDate, hoursDuration, priority * 100 + count, priceList));
invoiceLineList.get(invoiceLineList.size() - 1).setProject(project);
count++;
}
return invoiceLineList;
}
use of com.axelor.apps.hr.db.TimesheetLine in project axelor-open-suite by axelor.
the class WorkflowVentilationProjectServiceImpl method afterVentilation.
@Override
@Transactional(rollbackOn = { Exception.class })
public void afterVentilation(Invoice invoice) throws AxelorException {
super.afterVentilation(invoice);
if (!Beans.get(AppBusinessProjectService.class).isApp("business-project")) {
return;
}
InvoicingProject invoicingProject = invoicingProjectRepo.all().filter("self.invoice.id = ?", invoice.getId()).fetchOne();
if (invoicingProject != null) {
for (SaleOrderLine saleOrderLine : invoicingProject.getSaleOrderLineSet()) {
saleOrderLine.setInvoiced(true);
}
for (PurchaseOrderLine purchaseOrderLine : invoicingProject.getPurchaseOrderLineSet()) {
purchaseOrderLine.setInvoiced(true);
}
for (TimesheetLine timesheetLine : invoicingProject.getLogTimesSet()) {
timesheetLine.setInvoiced(true);
if (timesheetLine.getProjectTask() == null) {
continue;
}
timesheetLine.getProjectTask().setInvoiced(this.checkInvoicedTimesheetLines(timesheetLine.getProjectTask()));
}
for (ExpenseLine expenseLine : invoicingProject.getExpenseLineSet()) {
expenseLine.setInvoiced(true);
}
for (ProjectTask projectTask : invoicingProject.getProjectTaskSet()) {
projectTask.setInvoiced(true);
}
for (Project project : invoicingProject.getProjectSet()) {
project.setInvoiced(true);
}
invoicingProject.setStatusSelect(InvoicingProjectRepository.STATUS_VENTILATED);
invoicingProjectRepo.save(invoicingProject);
}
}
Aggregations