use of com.axelor.apps.account.db.SubrogationRelease in project axelor-open-suite by axelor.
the class SubrogationReleaseController method exportToCSV.
public void exportToCSV(ActionRequest request, ActionResponse response) {
try {
SubrogationRelease subrogationRelease = request.getContext().asType(SubrogationRelease.class);
Beans.get(SubrogationReleaseService.class).exportToCSV(subrogationRelease);
response.setReload(true);
} catch (Exception e) {
response.setError(e.getMessage());
TraceBackService.trace(e);
}
}
use of com.axelor.apps.account.db.SubrogationRelease in project axelor-open-suite by axelor.
the class InvoiceManagementRepository method populate.
@Override
public Map<String, Object> populate(Map<String, Object> json, Map<String, Object> context) {
try {
final String subrogationStatusSelect = "$subrogationStatusSelect";
if (context.get("_model") != null && context.get("_model").toString().equals(SubrogationRelease.class.getName())) {
if (context.get("id") != null) {
long id = (long) context.get("id");
SubrogationRelease subrogationRelease = Beans.get(SubrogationReleaseRepository.class).find(id);
if (subrogationRelease != null && subrogationRelease.getStatusSelect() != null) {
json.put(subrogationStatusSelect, subrogationRelease.getStatusSelect());
} else {
json.put(subrogationStatusSelect, SubrogationReleaseRepository.STATUS_NEW);
}
}
} else {
json.put(subrogationStatusSelect, SubrogationReleaseRepository.STATUS_NEW);
}
} catch (Exception e) {
TraceBackService.trace(e);
}
return super.populate(json, context);
}
use of com.axelor.apps.account.db.SubrogationRelease in project axelor-open-suite by axelor.
the class SubrogationReleaseManagementRepository method copy.
@Override
public SubrogationRelease copy(SubrogationRelease entity, boolean deep) {
SubrogationRelease srCopy = super.copy(entity, deep);
srCopy.setStatusSelect(STATUS_NEW);
srCopy.clearInvoiceSet();
return srCopy;
}
use of com.axelor.apps.account.db.SubrogationRelease in project axelor-open-suite by axelor.
the class SubrogationReleaseServiceImpl method exportToCSV.
@Override
public String exportToCSV(SubrogationRelease subrogationRelease) throws AxelorException, IOException {
String dataExportDir = appBaseService.getDataExportDir();
List<String[]> allMoveLineData = new ArrayList<>();
Comparator<Invoice> byInvoiceDate = (i1, i2) -> i1.getInvoiceDate().compareTo(i2.getInvoiceDate());
Comparator<Invoice> byDueDate = (i1, i2) -> i1.getDueDate().compareTo(i2.getDueDate());
Comparator<Invoice> byInvoiceId = (i1, i2) -> i1.getInvoiceId().compareTo(i2.getInvoiceId());
List<Invoice> releaseDetails = subrogationRelease.getInvoiceSet().stream().sorted(byInvoiceDate.thenComparing(byDueDate).thenComparing(byInvoiceId)).collect(Collectors.toList());
for (Invoice invoice : releaseDetails) {
String[] items = new String[6];
BigDecimal inTaxTotal = invoice.getInTaxTotal().abs();
if (InvoiceToolService.isOutPayment(invoice)) {
inTaxTotal = inTaxTotal.negate();
}
items[0] = invoice.getPartner().getPartnerSeq();
items[1] = invoice.getInvoiceId();
items[2] = invoice.getInvoiceDate().toString();
items[3] = invoice.getDueDate().toString();
items[4] = inTaxTotal.toString();
items[5] = invoice.getCurrency().getCode();
allMoveLineData.add(items);
}
AccountConfigService accountConfigService = Beans.get(AccountConfigService.class);
String filePath = accountConfigService.getAccountConfig(subrogationRelease.getCompany()).getExportPath();
filePath = filePath == null ? dataExportDir : dataExportDir + filePath;
new File(filePath).mkdirs();
String fileName = String.format("%s %s.csv", I18n.get("Subrogation release"), subrogationRelease.getSequenceNumber());
Files.createDirectories(Paths.get(filePath));
Path path = Paths.get(filePath, fileName);
CsvTool.csvWriter(filePath, fileName, ';', null, allMoveLineData);
try (InputStream is = new FileInputStream(path.toFile())) {
Beans.get(MetaFiles.class).attach(is, fileName, subrogationRelease);
}
return path.toString();
}
use of com.axelor.apps.account.db.SubrogationRelease in project axelor-open-suite by axelor.
the class NotificationServiceImpl method getSubrogationRelease.
protected SubrogationRelease getSubrogationRelease(NotificationItem notificationItem) {
Invoice invoice = notificationItem.getInvoice();
TypedQuery<SubrogationRelease> query = JPA.em().createQuery("SELECT self FROM SubrogationRelease self JOIN self.invoiceSet invoices WHERE self.statusSelect = :statusSelect AND invoices.id IN (:invoiceId)", SubrogationRelease.class);
query.setParameter("statusSelect", SubrogationReleaseRepository.STATUS_ACCOUNTED);
query.setParameter("invoiceId", invoice.getId());
List<SubrogationRelease> subrogationReleaseResultList = query.getResultList();
if (subrogationReleaseResultList != null && !subrogationReleaseResultList.isEmpty()) {
return subrogationReleaseResultList.get(0);
}
return null;
}
Aggregations