use of com.axelor.apps.account.db.InvoiceLine in project axelor-open-suite by axelor.
the class FixedAssetServiceImpl method createFixedAssets.
@Override
@Transactional(rollbackOn = { Exception.class })
public List<FixedAsset> createFixedAssets(Invoice invoice) throws AxelorException {
List<FixedAsset> fixedAssetList = new ArrayList<>();
if (invoice == null || CollectionUtils.isEmpty(invoice.getInvoiceLineList())) {
return fixedAssetList;
}
AccountConfig accountConfig = accountConfigService.getAccountConfig(invoice.getCompany());
for (InvoiceLine invoiceLine : invoice.getInvoiceLineList()) {
if (accountConfig.getFixedAssetCatReqOnInvoice() && invoiceLine.getFixedAssets() && invoiceLine.getFixedAssetCategory() == null) {
throw new AxelorException(invoiceLine, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.INVOICE_LINE_ERROR_FIXED_ASSET_CATEGORY), invoiceLine.getProductName());
}
if (!invoiceLine.getFixedAssets() || invoiceLine.getFixedAssetCategory() == null) {
continue;
}
FixedAsset fixedAsset = new FixedAsset();
fixedAsset.setFixedAssetCategory(invoiceLine.getFixedAssetCategory());
if (fixedAsset.getFixedAssetCategory().getIsValidateFixedAsset()) {
fixedAsset.setStatusSelect(FixedAssetRepository.STATUS_VALIDATED);
} else {
fixedAsset.setStatusSelect(FixedAssetRepository.STATUS_DRAFT);
}
fixedAsset.setAcquisitionDate(invoice.getInvoiceDate());
fixedAsset.setFirstDepreciationDate(invoice.getInvoiceDate());
fixedAsset.setReference(invoice.getInvoiceId());
fixedAsset.setName(invoiceLine.getProductName() + " (" + invoiceLine.getQty() + ")");
fixedAsset.setCompany(fixedAsset.getFixedAssetCategory().getCompany());
fixedAsset.setJournal(fixedAsset.getFixedAssetCategory().getJournal());
fixedAsset.setComputationMethodSelect(fixedAsset.getFixedAssetCategory().getComputationMethodSelect());
fixedAsset.setDegressiveCoef(fixedAsset.getFixedAssetCategory().getDegressiveCoef());
fixedAsset.setNumberOfDepreciation(fixedAsset.getFixedAssetCategory().getNumberOfDepreciation());
fixedAsset.setPeriodicityInMonth(fixedAsset.getFixedAssetCategory().getPeriodicityInMonth());
fixedAsset.setDurationInMonth(fixedAsset.getFixedAssetCategory().getDurationInMonth());
fixedAsset.setGrossValue(invoiceLine.getCompanyExTaxTotal());
fixedAsset.setPartner(invoice.getPartner());
fixedAsset.setPurchaseAccount(invoiceLine.getAccount());
fixedAsset.setInvoiceLine(invoiceLine);
this.generateAndComputeLines(fixedAsset);
fixedAssetList.add(fixedAssetRepo.save(fixedAsset));
}
return fixedAssetList;
}
use of com.axelor.apps.account.db.InvoiceLine in project axelor-open-suite by axelor.
the class TimesheetServiceImpl method createInvoiceLines.
@Override
public List<InvoiceLine> createInvoiceLines(Invoice invoice, List<TimesheetLine> timesheetLineList, int priority) throws AxelorException {
List<InvoiceLine> invoiceLineList = new ArrayList<>();
int count = 0;
DateFormat ddmmFormat = new SimpleDateFormat("dd/MM");
HashMap<String, Object[]> timeSheetInformationsMap = new HashMap<>();
// Check if a consolidation by product and user must be done
boolean consolidate = appHumanResourceService.getAppTimesheet().getConsolidateTSLine();
for (TimesheetLine timesheetLine : timesheetLineList) {
Object[] tabInformations = new Object[5];
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.getHoursDuration();
String key = null;
if (consolidate) {
key = timesheetLine.getProduct().getId() + "|" + timesheetLine.getUser().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.getHoursDuration());
} else {
timeSheetInformationsMap.put(key, tabInformations);
}
} else {
key = String.valueOf(timesheetLine.getId());
timeSheetInformationsMap.put(key, tabInformations);
}
timesheetLine.setInvoiced(true);
}
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];
PriceList priceList = Beans.get(PartnerPriceListService.class).getDefaultPriceList(invoice.getPartner(), PriceListRepository.TYPE_SALE);
if (consolidate) {
strDate = ddmmFormat.format(startDate) + " - " + ddmmFormat.format(endDate);
} else {
strDate = ddmmFormat.format(startDate);
}
invoiceLineList.addAll(this.createInvoiceLine(invoice, product, user, strDate, hoursDuration, priority * 100 + count, priceList));
count++;
}
return invoiceLineList;
}
use of com.axelor.apps.account.db.InvoiceLine in project axelor-open-suite by axelor.
the class TimesheetServiceImpl method createInvoiceLine.
@Override
public List<InvoiceLine> createInvoiceLine(Invoice invoice, Product product, User user, String date, BigDecimal hoursDuration, int priority, PriceList priceList) throws AxelorException {
int discountMethodTypeSelect = PriceListLineRepository.TYPE_DISCOUNT;
int discountTypeSelect = PriceListLineRepository.AMOUNT_TYPE_NONE;
if (product == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.TIMESHEET_PRODUCT));
}
BigDecimal price = (BigDecimal) productCompanyService.get(product, "salePrice", invoice.getCompany());
BigDecimal discountAmount = BigDecimal.ZERO;
BigDecimal priceDiscounted = price;
BigDecimal qtyConverted = Beans.get(UnitConversionService.class).convert(appHumanResourceService.getAppBase().getUnitHours(), (Unit) productCompanyService.get(product, "unit", invoice.getCompany()), hoursDuration, AppBaseService.DEFAULT_NB_DECIMAL_DIGITS, product);
if (priceList != null) {
PriceListLine priceListLine = priceListService.getPriceListLine(product, qtyConverted, priceList, price);
if (priceListLine != null) {
discountMethodTypeSelect = priceListLine.getTypeSelect();
}
Map<String, Object> discounts = priceListService.getDiscounts(priceList, priceListLine, price);
if (discounts != null) {
discountAmount = (BigDecimal) discounts.get("discountAmount");
discountTypeSelect = (int) discounts.get("discountTypeSelect");
priceDiscounted = priceListService.computeDiscount(price, discountTypeSelect, discountAmount);
}
if ((appHumanResourceService.getAppBase().getComputeMethodDiscountSelect() == AppBaseRepository.INCLUDE_DISCOUNT_REPLACE_ONLY && discountMethodTypeSelect == PriceListLineRepository.TYPE_REPLACE) || appHumanResourceService.getAppBase().getComputeMethodDiscountSelect() == AppBaseRepository.INCLUDE_DISCOUNT) {
discountTypeSelect = PriceListLineRepository.AMOUNT_TYPE_NONE;
price = priceDiscounted;
}
}
String description = user.getFullName();
String productName = (String) productCompanyService.get(product, "name", invoice.getCompany());
if (date != null) {
productName += " " + "(" + date + ")";
}
InvoiceLineGenerator invoiceLineGenerator = new InvoiceLineGenerator(invoice, product, productName, price, price, priceDiscounted, description, qtyConverted, (Unit) productCompanyService.get(product, "unit", invoice.getCompany()), null, priority, discountAmount, discountTypeSelect, price.multiply(qtyConverted), null, false) {
@Override
public List<InvoiceLine> creates() throws AxelorException {
InvoiceLine invoiceLine = this.createInvoiceLine();
List<InvoiceLine> invoiceLines = new ArrayList<>();
invoiceLines.add(invoiceLine);
return invoiceLines;
}
};
return invoiceLineGenerator.creates();
}
use of com.axelor.apps.account.db.InvoiceLine in project axelor-open-suite by axelor.
the class InvoiceLineController method updatePrice.
/**
* Update the ex. tax unit price of an invoice line from its in. tax unit price.
*
* @param request
* @param response
*/
public void updatePrice(ActionRequest request, ActionResponse response) {
Context context = request.getContext();
InvoiceLine invoiceLine = context.asType(InvoiceLine.class);
try {
BigDecimal inTaxPrice = invoiceLine.getInTaxPrice();
TaxLine taxLine = invoiceLine.getTaxLine();
response.setValue("price", Beans.get(InvoiceLineService.class).convertUnitPrice(true, taxLine, inTaxPrice));
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.account.db.InvoiceLine in project axelor-open-suite by axelor.
the class InvoiceLineController method compute.
public void compute(ActionRequest request, ActionResponse response) throws AxelorException {
Context context = request.getContext();
InvoiceLine invoiceLine = context.asType(InvoiceLine.class);
Invoice invoice = this.getInvoice(context);
if (invoice == null || invoiceLine.getPrice() == null || invoiceLine.getInTaxPrice() == null || invoiceLine.getQty() == null) {
return;
}
InvoiceLineService invoiceLineService = Beans.get(InvoiceLineService.class);
BigDecimal exTaxTotal;
BigDecimal companyExTaxTotal;
BigDecimal inTaxTotal;
BigDecimal companyInTaxTotal;
BigDecimal priceDiscounted = invoiceLineService.computeDiscount(invoiceLine, invoice.getInAti());
response.setValue("priceDiscounted", priceDiscounted);
response.setAttr("priceDiscounted", "hidden", priceDiscounted.compareTo(invoice.getInAti() ? invoiceLine.getInTaxPrice() : invoiceLine.getPrice()) == 0);
BigDecimal taxRate = BigDecimal.ZERO;
if (invoiceLine.getTaxLine() != null) {
taxRate = invoiceLine.getTaxLine().getValue();
response.setValue("taxRate", taxRate);
response.setValue("taxCode", invoiceLine.getTaxLine().getTax().getCode());
}
if (!invoice.getInAti()) {
exTaxTotal = InvoiceLineManagement.computeAmount(invoiceLine.getQty(), priceDiscounted);
inTaxTotal = exTaxTotal.add(exTaxTotal.multiply(taxRate));
} else {
inTaxTotal = InvoiceLineManagement.computeAmount(invoiceLine.getQty(), priceDiscounted);
exTaxTotal = inTaxTotal.divide(taxRate.add(BigDecimal.ONE), 2, BigDecimal.ROUND_HALF_UP);
}
companyExTaxTotal = invoiceLineService.getCompanyExTaxTotal(exTaxTotal, invoice);
companyInTaxTotal = invoiceLineService.getCompanyExTaxTotal(inTaxTotal, invoice);
response.setValue("exTaxTotal", exTaxTotal);
response.setValue("inTaxTotal", inTaxTotal);
response.setValue("companyInTaxTotal", companyInTaxTotal);
response.setValue("companyExTaxTotal", companyExTaxTotal);
}
Aggregations