}
}
Iterator<?> iterator = masterHeader.getInvoiceDetails().iterator();
while (iterator.hasNext()) {
InvoiceDetail masterDetail = (InvoiceDetail) iterator.next();
Iterator<?> taxIterator = masterDetail.getInvoiceDetailTaxes().iterator();
while (taxIterator.hasNext()) {
InvoiceDetailTax masterDetailTax = (InvoiceDetailTax) taxIterator.next();
em.remove(masterDetailTax);
taxIterator.remove();
}
em.remove(masterDetail);
iterator.remove();
}
iterator = invoiceHeader.getInvoiceDetails().iterator();
while (iterator.hasNext()) {
InvoiceDetail invoiceDetail = (InvoiceDetail) iterator.next();
InvoiceDetail masterDetail = new InvoiceDetail();
masterDetail.setInvoiceHeader(masterHeader);
masterDetail.setSeqNum(invoiceDetail.getSeqNum());
masterDetail.setItemInvoiceQty(invoiceDetail.getItemInvoiceQty());
masterDetail.setItemInvoiceAmount(invoiceDetail.getItemInvoiceAmount());
masterDetail.setRecUpdateBy(invoiceDetail.getRecUpdateBy());
masterDetail.setRecUpdateDatetime(invoiceDetail.getRecUpdateDatetime());
masterDetail.setRecCreateBy(invoiceDetail.getRecCreateBy());
masterDetail.setRecCreateDatetime(invoiceDetail.getRecCreateDatetime());
masterDetail.setOrderItemDetail(invoiceDetail.getOrderItemDetail());
em.persist(masterDetail);
masterHeader.getInvoiceDetails().add(masterDetail);
Iterator<?> taxIterator = invoiceDetail.getInvoiceDetailTaxes().iterator();
while (taxIterator.hasNext()) {
InvoiceDetailTax invoiceDetailTax = (InvoiceDetailTax) taxIterator.next();
InvoiceDetailTax masterTax = new InvoiceDetailTax();
masterTax.setTaxName(invoiceDetailTax.getTaxName());
masterTax.setTaxAmount(invoiceDetailTax.getTaxAmount());
masterTax.setRecUpdateBy(invoiceDetailTax.getRecUpdateBy());
masterTax.setRecUpdateDatetime(invoiceDetailTax.getRecUpdateDatetime());
masterTax.setRecCreateBy(invoiceDetailTax.getRecCreateBy());
masterTax.setRecCreateDatetime(invoiceDetailTax.getRecCreateDatetime());
masterTax.setInvoiceDetail(masterDetail);
masterTax.setTax(invoiceDetailTax.getTax());
masterDetail.getInvoiceDetailTaxes().add(masterTax);
masterTax.setInvoiceHeader(masterHeader);
em.persist(masterTax);
}
}