private String composeLine(InvoiceDTO invoice, InvoiceLineDTO invoiceLine, Integer userId) { StringBuffer line = new StringBuffer(); ContactBL contact = new ContactBL(); contact.set(userId); // cono line.append("\"" + emptyIfNull(contact.getEntity().getPostalCode()) + "\""); line.append(","); // custno line.append("\"" + userId + "\""); line.append(","); // naddrcode line.append("\"" + "000" + "\""); line.append(","); // lookupnm line.append("\"" + emptyIfNull(contact.getEntity().getOrganizationName()) + "\""); line.append(","); // totallineamt line.append("\"" + invoiceLine.getAmount() + "\""); line.append(","); // period line.append("\"" + new SimpleDateFormat("yyyyMM").format(invoice.getCreateDatetime()) + "\""); line.append(","); // name line.append("\"" + emptyIfNull(contact.getEntity().getOrganizationName()) + "\""); line.append(","); // deliveryaddr line.append("\"" + emptyIfNull(contact.getEntity().getAddress1()) + "\""); line.append(","); // city line.append("\"" + emptyIfNull(contact.getEntity().getCity()) + "\""); line.append(","); // state line.append("\"" + emptyIfNull(contact.getEntity().getStateProvince()) + "\""); line.append(","); // zip5 line.append("\"" + emptyIfNull(contact.getEntity().getPostalCode()) + "\""); line.append(","); // totdue - round to two decimals line.append("\"" + new UserBL().getBalance(userId).round(new MathContext(2)) + "\""); line.append(","); // qty line.append("\"" + invoiceLine.getQuantity() + "\""); line.append(","); // description line.append("\"" + invoiceLine.getDescription() + "\""); line.append(","); // invoiceno line.append("\"" + invoice.getNumber() + "\""); line.append(","); // custstatus line.append("\"" + "TRUE" + "\""); LOG.debug("Line to export:" + line); return line.toString(); }
public static InvoiceWS getWS(InvoiceDTO i) { if (i == null) { return null; } InvoiceWS retValue = new InvoiceWS(); retValue.setId(i.getId()); retValue.setCreateDateTime(i.getCreateDatetime()); retValue.setCreateTimeStamp(i.getCreateTimestamp()); retValue.setLastReminder(i.getLastReminder()); retValue.setDueDate(i.getDueDate()); retValue.setTotal(i.getTotal()); retValue.setToProcess(i.getToProcess()); retValue.setStatusId(i.getInvoiceStatus().getId()); retValue.setBalance(i.getBalance()); retValue.setCarriedBalance(i.getCarriedBalance()); retValue.setInProcessPayment(i.getInProcessPayment()); retValue.setDeleted(i.getDeleted()); retValue.setPaymentAttempts(i.getPaymentAttempts()); retValue.setIsReview(i.getIsReview()); retValue.setCurrencyId(i.getCurrency().getId()); retValue.setCustomerNotes(i.getCustomerNotes()); retValue.setNumber(i.getPublicNumber()); retValue.setOverdueStep(i.getOverdueStep()); retValue.setUserId(i.getBaseUser().getId()); Integer delegatedInvoiceId = i.getInvoice() == null ? null : i.getInvoice().getId(); Integer userId = i.getBaseUser().getId(); Integer payments[] = new Integer[i.getPaymentMap().size()]; com.sapienter.jbilling.server.entity.InvoiceLineDTO invoiceLines[] = new com.sapienter.jbilling.server.entity.InvoiceLineDTO[i.getInvoiceLines().size()]; Integer orders[] = new Integer[i.getOrderProcesses().size()]; int f; f = 0; for (PaymentInvoiceMapDTO p : i.getPaymentMap()) { payments[f++] = p.getPayment().getId(); } f = 0; for (OrderProcessDTO orderP : i.getOrderProcesses()) { orders[f++] = orderP.getPurchaseOrder().getId(); } f = 0; for (InvoiceLineDTO line : i.getInvoiceLines()) { invoiceLines[f++] = new com.sapienter.jbilling.server.entity.InvoiceLineDTO( line.getId(), line.getDescription(), line.getAmount(), line.getPrice(), line.getQuantity(), line.getDeleted(), line.getItem() == null ? null : line.getItem().getId(), line.getSourceUserId(), line.getIsPercentage()); } retValue.setDelegatedInvoiceId(delegatedInvoiceId); retValue.setUserId(userId); retValue.setPayments(payments); retValue.setInvoiceLines(invoiceLines); retValue.setOrders(orders); retValue.setMetaFields(MetaFieldBL.convertMetaFieldsToWS(new UserBL().getEntityId(userId), i)); return retValue; }
public void createLines(NewInvoiceDTO newInvoice) { Collection invoiceLines = invoice.getInvoiceLines(); // Now create all the invoice lines, from the lines in the DTO // put there by the invoice composition pluggable tasks InvoiceLineDAS invoiceLineDas = new InvoiceLineDAS(); // get the result DTO lines Iterator dueInvoiceLines = newInvoice.getResultLines().iterator(); // go over the DTO lines, creating one invoice line for each // #2196 - GET Invoice Rounding Preference for entity entityId PreferenceBL pref = new PreferenceBL(); Integer entityId = newInvoice.getEntityId(); if (null == entityId) { entityId = newInvoice.getBaseUser().getEntity().getId(); } int decimals = Constants.BIGDECIMAL_SCALE; try { pref.set(entityId, Constants.PREFERENCE_INVOICE_DECIMALS); decimals = pref.getInt(); } catch (EmptyResultDataAccessException e) { // ignore } // #2196 while (dueInvoiceLines.hasNext()) { InvoiceLineDTO lineToAdd = (InvoiceLineDTO) dueInvoiceLines.next(); // define if the line is a percentage or not lineToAdd.setIsPercentage(0); if (lineToAdd.getItem() != null) { try { ItemBL item = new ItemBL(lineToAdd.getItem()); if (item.getEntity().getPercentage() != null) { lineToAdd.setIsPercentage(1); } } catch (SessionInternalError e) { LOG.error("Could not find item to create invoice line " + lineToAdd.getItem().getId()); } } // #2196 - Use Invoice Rounding Preference to round Invoice Lines if (null != lineToAdd.getAmount()) { lineToAdd.setAmount(lineToAdd.getAmount().setScale(decimals, Constants.BIGDECIMAL_ROUND)); } // #2196 // create the database row InvoiceLineDTO newLine = invoiceLineDas.create( lineToAdd.getDescription(), lineToAdd.getAmount(), lineToAdd.getQuantity(), lineToAdd.getPrice(), lineToAdd.getTypeId(), lineToAdd.getItem(), lineToAdd.getSourceUserId(), lineToAdd.getIsPercentage()); // update the invoice-lines relationship newLine.setInvoice(invoice); invoiceLines.add(newLine); } getHome().save(invoice); EventManager.process(new NewInvoiceEvent(invoice)); }