ivan
(Ivan Martinez)
August 30, 2016, 8:37pm
#1
Hi, i need to help us in a tip:
We have been attached a samplebillingproject and capture.
I need to make this:
When i clic a button to Duplicate invoice, show a Popup for select what linees would like to copy to the new invoice, and when selected, create a new invoice with the selected lines.
Thanks for your support.
SampleAppBilling.zip (35.9K)
krivopustov
(Konstantin Krivopustov)
September 1, 2016, 6:38pm
#2
Hi Ivan,
The simplest solution is the following:
enable “multiselect” for detailsTable - then the user can select multiple invoice details records
implement the copying as follows:
public class InvoiceEdit extends AbstractEditor<Invoice> {
@Inject
private Table<InvoiceDetails> detailsTable;
@Inject
private Metadata metadata;
public void duplicate(Component source) {
if (detailsTable.getSelected().isEmpty()) {
showNotification("Select detail rows first", NotificationType.HUMANIZED);
return;
}
Invoice newInvoice = metadata.create(Invoice.class);
newInvoice.setCustomer(getItem().getCustomer());
newInvoice.setTitle(getItem().getTitle());
newInvoice.setDetails(new ArrayList<>());
for (InvoiceDetails details : detailsTable.getSelected()) {
InvoiceDetails newDetails = metadata.create(InvoiceDetails.class);
newDetails.setInvoice(newInvoice);
newDetails.setProduct(details.getProduct());
newDetails.setPrice(details.getPrice());
newInvoice.getDetails().add(newDetails);
}
openEditor(newInvoice, WindowManager.OpenType.DIALOG);
}
}
The working project is attached.
SampleAppBilling.zip (37.3K)
ivan
(Ivan Martinez)
September 3, 2016, 9:14am
#3
Hi Konstantin, but it’s possible to show grid in popup for select what lines i want to pass to the new invoice?
The reason is simple i have a Quote, and i would like to pass some lines to Order, passed lines can’t pass to another new quote, example:
if i have a quote line with 4 units, and i convert this line (only 2 units) to a new Order, i put in a field converted (2 units).
if customer needs the other lines, i can’t copy to a new order 4 units, only 2 (units pending) .
And what the reason for a popup for select only available units, make some verification when i select a line, for example, available stock, or something.
Thanks!
krivopustov
(Konstantin Krivopustov)
September 21, 2016, 6:12pm
#4
Hi Ivan,
The solution with a separate selection screen can be as follows.
I’ve created a new screen with table and OK-Cancel buttons:
public class InvoiceLinesSelect extends AbstractWindow {
@WindowParam
private Collection<InvoiceDetails> details;
@Inject
private CollectionDatasource<InvoiceDetails, UUID> invoiceDetailsDs;
@Inject
private Table<InvoiceDetails> invoiceDetailsTable;
@Override
public void init(Map<String, Object> params) {
for (InvoiceDetails detail : details) {
invoiceDetailsDs.addItem(detail);
}
}
public void onOkBtnClick(Component source) {
close(Window.COMMIT_ACTION_ID);
}
public void onCancelBtnClick(Component source) {
close(Window.CLOSE_ACTION_ID);
}
public Collection<InvoiceDetails> getSelected() {
return invoiceDetailsTable.getSelected();
}
}
The copying method in Invoice editor:
public void duplicate(Component source) {
InvoiceLinesSelect selectWindow = (InvoiceLinesSelect) openWindow("invoice-lines-select",
WindowManager.OpenType.DIALOG, ParamsMap.of("details", detailsDs.getItems()));
selectWindow.addCloseWithCommitListener(() -> {
if (selectWindow.getSelected().isEmpty()) {
showNotification("Please select detail rows", NotificationType.HUMANIZED);
return;
}
Invoice newInvoice = metadata.create(Invoice.class);
newInvoice.setCustomer(getItem().getCustomer());
newInvoice.setTitle(getItem().getTitle());
newInvoice.setDetails(new ArrayList<>());
for (InvoiceDetails details : selectWindow.getSelected()) {
InvoiceDetails newDetails = metadata.create(InvoiceDetails.class);
newDetails.setInvoice(newInvoice);
newDetails.setProduct(details.getProduct());
newDetails.setPrice(details.getPrice());
newInvoice.getDetails().add(newDetails);
}
openEditor(newInvoice, WindowManager.OpenType.DIALOG);
});
}
The project is attached.
SampleAppBilling.zip (39.6K)