use of com.axelor.apps.businessproject.db.InvoicingProject in project axelor-open-suite by axelor.
the class InvoicingProjectService method generateInvoicingProject.
@Transactional(rollbackOn = { AxelorException.class, Exception.class })
public InvoicingProject generateInvoicingProject(Project project, int consolidatePhaseSelect) {
if (project == null) {
return null;
}
InvoicingProject invoicingProject = new InvoicingProject();
invoicingProject.setProject(project);
if (consolidatePhaseSelect == ProjectInvoicingAssistantBatchRepository.CONSOLIDATE_PHASE_CONSOLIDATE_ALL) {
invoicingProject.setConsolidatePhaseWhenInvoicing(true);
} else if (consolidatePhaseSelect == ProjectInvoicingAssistantBatchRepository.CONSOLIDATE_PHASE_DONT_CONSOLIDATE) {
invoicingProject.setConsolidatePhaseWhenInvoicing(false);
} else if (consolidatePhaseSelect == ProjectInvoicingAssistantBatchRepository.CONSOLIDATE_PHASE_DEFAULT_VALUE) {
invoicingProject.setConsolidatePhaseWhenInvoicing(invoicingProject.getProject().getConsolidatePhaseWhenInvoicing());
}
clearLines(invoicingProject);
setLines(invoicingProject, project, 0);
if (invoicingProject.getSaleOrderLineSet().isEmpty() && invoicingProject.getPurchaseOrderLineSet().isEmpty() && invoicingProject.getLogTimesSet().isEmpty() && invoicingProject.getExpenseLineSet().isEmpty() && invoicingProject.getProjectSet().isEmpty() && invoicingProject.getProjectTaskSet().isEmpty()) {
return invoicingProject;
}
return invoicingProjectRepo.save(invoicingProject);
}
use of com.axelor.apps.businessproject.db.InvoicingProject in project axelor-open-suite by axelor.
the class InvoicingProjectService method generateInvoice.
@Transactional(rollbackOn = { Exception.class })
public Invoice generateInvoice(InvoicingProject invoicingProject) throws AxelorException {
Project project = invoicingProject.getProject();
Partner customer = project.getClientPartner();
Partner customerContact = project.getContactPartner();
if (invoicingProject.getSaleOrderLineSet().isEmpty() && invoicingProject.getPurchaseOrderLineSet().isEmpty() && invoicingProject.getLogTimesSet().isEmpty() && invoicingProject.getExpenseLineSet().isEmpty() && invoicingProject.getProjectSet().isEmpty() && invoicingProject.getProjectTaskSet().isEmpty()) {
throw new AxelorException(invoicingProject, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.INVOICING_PROJECT_EMPTY));
}
if (invoicingProject.getProject() == null) {
throw new AxelorException(invoicingProject, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.INVOICING_PROJECT_PROJECT));
}
if (invoicingProject.getProject().getClientPartner() == null) {
throw new AxelorException(invoicingProject, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.INVOICING_PROJECT_PROJECT_PARTNER));
}
if (customerContact == null && customer.getContactPartnerSet().size() == 1) {
customerContact = customer.getContactPartnerSet().iterator().next();
}
Company company = this.getRootCompany(project);
if (company == null) {
throw new AxelorException(invoicingProject, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.INVOICING_PROJECT_PROJECT_COMPANY));
}
InvoiceGenerator invoiceGenerator = new InvoiceGenerator(InvoiceRepository.OPERATION_TYPE_CLIENT_SALE, company, customer.getPaymentCondition(), customer.getInPaymentMode(), partnerService.getInvoicingAddress(customer), customer, customerContact, customer.getCurrency(), Beans.get(PartnerPriceListService.class).getDefaultPriceList(customer, PriceListRepository.TYPE_SALE), null, null, null, null, null, null) {
@Override
public Invoice generate() throws AxelorException {
Invoice invoice = super.createInvoiceHeader();
invoice.setProject(project);
invoice.setPriceList(project.getPriceList());
return invoice;
}
};
Invoice invoice = invoiceGenerator.generate();
AccountConfigService accountConfigService = Beans.get(AccountConfigService.class);
AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
invoice.setDisplayTimesheetOnPrinting(accountConfig.getDisplayTimesheetOnPrinting());
invoice.setDisplayExpenseOnPrinting(accountConfig.getDisplayExpenseOnPrinting());
invoiceGenerator.populate(invoice, this.populate(invoice, invoicingProject));
Beans.get(InvoiceRepository.class).save(invoice);
invoicingProject.setInvoice(invoice);
invoicingProject.setStatusSelect(InvoicingProjectRepository.STATUS_GENERATED);
invoicingProjectRepo.save(invoicingProject);
return invoice;
}
use of com.axelor.apps.businessproject.db.InvoicingProject in project axelor-open-suite by axelor.
the class InvoiceProjectRepository method remove.
@Override
public void remove(Invoice entity) {
if (Beans.get(AppBusinessProjectService.class).isApp("business-project")) {
List<InvoicingProject> invoiceProjectList = Beans.get(InvoicingProjectRepository.class).all().filter("self.invoice.id = ?", entity.getId()).fetch();
List<ProjectTask> projectTaskList = Beans.get(ProjectTaskRepository.class).all().filter("self.invoiceLine.invoice = ?1", entity).fetch();
if (ObjectUtils.notEmpty(projectTaskList)) {
for (ProjectTask projectTask : projectTaskList) {
projectTask.setInvoiceLine(null);
}
}
for (InvoicingProject invoiceProject : invoiceProjectList) {
invoiceProject.setInvoice(null);
invoiceProject.setStatusSelect(InvoicingProjectRepository.STATUS_DRAFT);
}
}
super.remove(entity);
}
use of com.axelor.apps.businessproject.db.InvoicingProject in project axelor-open-suite by axelor.
the class BatchInvoicingProjectService method process.
@Override
protected void process() {
Map<String, Object> contextValues = null;
try {
contextValues = ProjectInvoicingAssistantBatchService.createJsonContext(batch);
} catch (Exception e) {
TraceBackService.trace(e);
}
List<Object> generatedInvoicingProjectList = new ArrayList<Object>();
List<Project> projectList = projectRepo.all().filter("self.isBusinessProject = :isBusinessProject " + "AND self.toInvoice = :toInvoice AND " + "(self.statusSelect != :statusCanceled AND self.statusSelect != :statusFinished)").bind("isBusinessProject", true).bind("toInvoice", true).bind("statusCanceled", ProjectRepository.STATE_CANCELED).bind("statusFinished", ProjectRepository.STATE_FINISHED).fetch();
for (Project project : projectList) {
try {
InvoicingProject invoicingProject = invoicingProjectService.generateInvoicingProject(project, batch.getProjectInvoicingAssistantBatch().getConsolidatePhaseSelect());
if (invoicingProject != null && invoicingProject.getId() != null) {
incrementDone();
if (batch.getProjectInvoicingAssistantBatch().getActionSelect() == ProjectInvoicingAssistantBatchRepository.ACTION_GENERATE_INVOICING_PROJECT) {
invoicingProject.setDeadlineDate(batch.getProjectInvoicingAssistantBatch().getDeadlineDate());
}
Map<String, Object> map = new HashMap<String, Object>();
map.put("id", invoicingProject.getId());
generatedInvoicingProjectList.add(map);
}
} catch (Exception e) {
incrementAnomaly();
TraceBackService.trace(new Exception(String.format(I18n.get(IExceptionMessage.BATCH_INVOICING_PROJECT_1), project.getId()), e), ExceptionOriginRepository.INVOICE_ORIGIN, batch.getId());
}
}
ProjectInvoicingAssistantBatchService.updateJsonObject(batch, generatedInvoicingProjectList, "generatedInvoicingProjectSet", contextValues);
}
use of com.axelor.apps.businessproject.db.InvoicingProject in project axelor-open-suite by axelor.
the class InvoicingProjectController method generateInvoice.
@SuppressWarnings("unchecked")
public void generateInvoice(ActionRequest request, ActionResponse response) throws AxelorException {
Invoice invoice;
List<Long> invoiceIdList = new ArrayList<Long>();
List<InvoicingProject> projects = new ArrayList<InvoicingProject>();
String ids = null;
if (request.getContext().get("_ids") != null) {
projects = invoicingProjectRepository.all().filter("self.id in ? and self.invoice = null", (List<Integer>) request.getContext().get("_ids")).fetch();
} else if (request.getContext().asType(InvoicingProject.class).getId() != null) {
projects.add(invoicingProjectRepository.find(request.getContext().asType(InvoicingProject.class).getId()));
} else {
response.setError(IExceptionMessage.LINES_NOT_SELECTED);
return;
}
if (projects.size() > 0) {
for (InvoicingProject invProject : projects) {
invoice = Beans.get(InvoicingProjectService.class).generateInvoice(invProject);
if (invoice != null) {
invoiceIdList.add(invoice.getId());
try {
Beans.get(InvoicingProjectService.class).generateAnnex(invProject);
} catch (IOException e) {
TraceBackService.trace(response, e);
}
}
}
ids = StringUtils.join(invoiceIdList, ",");
ActionViewBuilder view = ActionView.define(I18n.get("Invoice")).model(Invoice.class.getName()).add("grid", "invoice-grid").add("form", "invoice-form").param("search-filters", "customer-invoices-filters");
response.setReload(true);
response.setView((ids.contains(",")) ? view.domain("self.id IN (" + ids + ")").map() : view.context("_showRecord", ids).map());
}
}
Aggregations