use of com.axelor.apps.account.db.Invoice in project axelor-open-suite by axelor.
the class InvoiceController method setDefaultMail.
/**
* set default value for automatic invoice printing
*
* @param request
* @param response
* @throws AxelorException
*/
public void setDefaultMail(ActionRequest request, ActionResponse response) {
Invoice invoice = request.getContext().asType(Invoice.class);
Company company = invoice.getCompany();
Partner partner = invoice.getPartner();
if (company != null && partner != null) {
AccountingSituation accountingSituation = Beans.get(AccountingSituationService.class).getAccountingSituation(partner, company);
if (accountingSituation != null) {
response.setValue("invoiceAutomaticMail", accountingSituation.getInvoiceAutomaticMail());
response.setValue("invoiceMessageTemplate", accountingSituation.getInvoiceMessageTemplate());
response.setValue("invoiceAutomaticMailOnValidate", accountingSituation.getInvoiceAutomaticMailOnValidate());
response.setValue("invoiceMessageTemplateOnValidate", accountingSituation.getInvoiceMessageTemplateOnValidate());
}
}
}
use of com.axelor.apps.account.db.Invoice 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);
}
use of com.axelor.apps.account.db.Invoice in project axelor-open-suite by axelor.
the class InvoiceLineController method getDiscount.
public void getDiscount(ActionRequest request, ActionResponse response) {
Context context = request.getContext();
InvoiceLine invoiceLine = context.asType(InvoiceLine.class);
Invoice invoice = this.getInvoice(context);
if (invoice == null || invoiceLine.getProduct() == null) {
return;
}
try {
Map<String, Object> discounts = Beans.get(InvoiceLineService.class).getDiscount(invoice, invoiceLine, invoiceLine.getProduct().getInAti() ? Beans.get(InvoiceLineService.class).getInTaxUnitPrice(invoice, invoiceLine, invoiceLine.getTaxLine(), InvoiceToolService.isPurchase(invoice)) : Beans.get(InvoiceLineService.class).getExTaxUnitPrice(invoice, invoiceLine, invoiceLine.getTaxLine(), InvoiceToolService.isPurchase(invoice)));
for (Entry<String, Object> entry : discounts.entrySet()) {
response.setValue(entry.getKey(), entry.getValue());
}
} catch (Exception e) {
response.setFlash(e.getMessage());
}
}
use of com.axelor.apps.account.db.Invoice in project axelor-open-suite by axelor.
the class InvoiceLineController method getProductInformation.
public void getProductInformation(ActionRequest request, ActionResponse response) throws AxelorException {
Context context = request.getContext();
InvoiceLine invoiceLine = context.asType(InvoiceLine.class);
Invoice invoice = this.getInvoice(context);
Product product = invoiceLine.getProduct();
Map<String, Object> productInformation = new HashMap<>();
if (invoice != null && product != null) {
try {
productInformation = Beans.get(InvoiceLineService.class).fillProductInformation(invoice, invoiceLine);
String errorMsg = (String) productInformation.get("error");
if (!Strings.isNullOrEmpty(errorMsg)) {
response.setFlash(errorMsg);
}
} catch (Exception e) {
TraceBackService.trace(response, e);
}
} else {
productInformation = Beans.get(InvoiceLineService.class).resetProductInformation(invoice);
}
response.setValues(productInformation);
}
use of com.axelor.apps.account.db.Invoice in project axelor-open-suite by axelor.
the class InvoicePaymentController method filterBankDetails.
/**
* Create the domain for companyBankDetails field.
*
* @param request
* @param response
*/
@SuppressWarnings("unchecked")
public void filterBankDetails(ActionRequest request, ActionResponse response) {
InvoicePayment invoicePayment = request.getContext().asType(InvoicePayment.class);
Map<String, Object> partialInvoice = (Map<String, Object>) request.getContext().get("_invoice");
Invoice invoice = Beans.get(InvoiceRepository.class).find(((Integer) partialInvoice.get("id")).longValue());
Company company = invoice.getCompany();
List<BankDetails> bankDetailsList = Beans.get(InvoicePaymentToolService.class).findCompatibleBankDetails(company, invoicePayment);
if (bankDetailsList.isEmpty()) {
response.setAttr("companyBankDetails", "domain", "self.id IN (0)");
} else {
String idList = StringTool.getIdListString(bankDetailsList);
response.setAttr("companyBankDetails", "domain", "self.id IN (" + idList + ")");
}
}
Aggregations