use of com.axelor.apps.base.db.PriceList 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.base.db.PriceList in project axelor-open-suite by axelor.
the class ProjectTaskBusinessProjectServiceImpl method updateDiscount.
@Override
public ProjectTask updateDiscount(ProjectTask projectTask) {
PriceList priceList = projectTask.getProject().getPriceList();
if (priceList == null) {
this.emptyDiscounts(projectTask);
return projectTask;
}
PriceListLine priceListLine = this.getPriceListLine(projectTask, priceList, projectTask.getUnitPrice());
Map<String, Object> discounts = priceListService.getReplacedPriceAndDiscounts(priceList, priceListLine, projectTask.getUnitPrice());
if (discounts == null) {
this.emptyDiscounts(projectTask);
} else {
projectTask.setDiscountTypeSelect((Integer) discounts.get("discountTypeSelect"));
projectTask.setDiscountAmount((BigDecimal) discounts.get("discountAmount"));
if (discounts.get("price") != null) {
projectTask.setPriceDiscounted((BigDecimal) discounts.get("price"));
}
}
return projectTask;
}
use of com.axelor.apps.base.db.PriceList in project axelor-open-suite by axelor.
the class PurchaseOrderInvoiceProjectServiceImpl method createInvoiceLine.
@Override
public List<InvoiceLine> createInvoiceLine(Invoice invoice, PurchaseOrderLine purchaseOrderLine) throws AxelorException {
Product product = purchaseOrderLine.getProduct();
Company company = purchaseOrderLine.getPurchaseOrder() != null ? purchaseOrderLine.getPurchaseOrder().getCompany() : null;
BigDecimal price = (BigDecimal) productCompanyService.get(product, "costPrice", company);
BigDecimal discountAmount = price;
int discountTypeSelect = 1;
if (invoice.getPartner().getChargeBackPurchaseSelect() == PartnerRepository.CHARGING_BACK_TYPE_PRICE_LIST) {
PriceList priceList = Beans.get(PartnerPriceListService.class).getDefaultPriceList(invoice.getPartner(), PriceListRepository.TYPE_SALE);
if (priceList != null) {
PriceListLine priceListLine = purchaseOrderLineServiceImpl.getPriceListLine(purchaseOrderLine, priceList, price);
if (priceListLine != null) {
discountTypeSelect = priceListLine.getTypeSelect();
}
if ((appBusinessProjectService.getAppBase().getComputeMethodDiscountSelect() == AppBaseRepository.INCLUDE_DISCOUNT_REPLACE_ONLY && discountTypeSelect == PriceListLineRepository.TYPE_REPLACE) || appBusinessProjectService.getAppBase().getComputeMethodDiscountSelect() == AppBaseRepository.INCLUDE_DISCOUNT) {
Map<String, Object> discounts = priceListService.getDiscounts(priceList, priceListLine, price);
if (discounts != null) {
discountAmount = (BigDecimal) discounts.get("discountAmount");
price = priceListService.computeDiscount(price, (int) discounts.get("discountTypeSelect"), discountAmount);
}
} else {
Map<String, Object> discounts = priceListService.getDiscounts(priceList, priceListLine, price);
if (discounts != null) {
discountAmount = (BigDecimal) discounts.get("discountAmount");
if (discounts.get("price") != null) {
price = (BigDecimal) discounts.get("price");
}
}
}
}
InvoiceLineGenerator invoiceLineGenerator = new InvoiceLineGenerator(invoice, product, (String) productCompanyService.get(product, "name", company), price, price, price, purchaseOrderLine.getDescription(), purchaseOrderLine.getQty(), purchaseOrderLine.getUnit(), null, InvoiceLineGenerator.DEFAULT_SEQUENCE, discountAmount, discountTypeSelect, null, null, false) {
@Override
public List<InvoiceLine> creates() throws AxelorException {
InvoiceLine invoiceLine = this.createInvoiceLine();
invoiceLine.setProject(purchaseOrderLine.getProject());
List<InvoiceLine> invoiceLines = new ArrayList<InvoiceLine>();
invoiceLines.add(invoiceLine);
return invoiceLines;
}
};
return invoiceLineGenerator.creates();
} else if (invoice.getPartner().getChargeBackPurchaseSelect() == PartnerRepository.CHARGING_BACK_TYPE_PERCENTAGE) {
price = price.multiply(invoice.getPartner().getChargeBackPurchase().divide(new BigDecimal(100), appBusinessProjectService.getNbDecimalDigitForUnitPrice(), BigDecimal.ROUND_HALF_UP)).setScale(appBusinessProjectService.getNbDecimalDigitForUnitPrice(), BigDecimal.ROUND_HALF_UP);
InvoiceLineGenerator invoiceLineGenerator = new InvoiceLineGenerator(invoice, product, (String) productCompanyService.get(product, "name", company), price, price, price, purchaseOrderLine.getDescription(), purchaseOrderLine.getQty(), purchaseOrderLine.getUnit(), null, InvoiceLineGenerator.DEFAULT_SEQUENCE, discountAmount, discountTypeSelect, null, null, false) {
@Override
public List<InvoiceLine> creates() throws AxelorException {
InvoiceLine invoiceLine = this.createInvoiceLine();
invoiceLine.setProject(purchaseOrderLine.getProject());
List<InvoiceLine> invoiceLines = new ArrayList<InvoiceLine>();
invoiceLines.add(invoiceLine);
return invoiceLines;
}
};
return invoiceLineGenerator.creates();
} else {
InvoiceLineGeneratorSupplyChain invoiceLineGenerator = new InvoiceLineGeneratorSupplyChain(invoice, product, purchaseOrderLine.getProductName(), purchaseOrderLine.getDescription(), purchaseOrderLine.getQty(), purchaseOrderLine.getUnit(), purchaseOrderLine.getSequence(), false, null, purchaseOrderLine, null) {
@Override
public List<InvoiceLine> creates() throws AxelorException {
InvoiceLine invoiceLine = this.createInvoiceLine();
invoiceLine.setProject(purchaseOrderLine.getProject());
List<InvoiceLine> invoiceLines = new ArrayList<InvoiceLine>();
invoiceLines.add(invoiceLine);
return invoiceLines;
}
};
return invoiceLineGenerator.creates();
}
}
use of com.axelor.apps.base.db.PriceList in project axelor-open-suite by axelor.
the class InvoiceLineServiceImpl method getDiscountsFromPriceLists.
@Override
public Map<String, Object> getDiscountsFromPriceLists(Invoice invoice, InvoiceLine invoiceLine, BigDecimal price) {
Map<String, Object> discounts = null;
PriceList priceList = invoice.getPriceList();
if (priceList != null) {
PriceListLine priceListLine = this.getPriceListLine(invoiceLine, priceList, price);
discounts = priceListService.getReplacedPriceAndDiscounts(priceList, priceListLine, price);
}
return discounts;
}
Aggregations