Iterator<?> creditIterator = orderItemDetail.getCreditDetails().iterator();
int itemCreditQty = 0;
while (creditIterator.hasNext()) {
CreditDetail creditDetail = (CreditDetail) creditIterator.next();
CreditHeader cHeader = creditDetail.getCreditHeader();
if (cHeader.getCreditHeaderId() == null) {
continue;
}
if (creditHeader != null) {
if (cHeader.getCreditHeaderId().equals(creditHeader.getCreditHeaderId())) {
continue;
}
}
String status = cHeader.getCreditStatus();
if (status.equals(Constants.ORDERSTATUS_CANCELLED) || status.equals(Constants.ORDERSTATUS_VOIDED)) {
continue;
}
itemCreditQty += creditDetail.getItemCreditQty();
itemCreditTotal += creditDetail.getItemCreditQty();
}
itemDisplay.setItemCreditQty(Format.getInt(itemCreditQty));
Iterator<?> shipIterator = orderItemDetail.getShipDetails().iterator();
int itemShipQty = 0;
while (shipIterator.hasNext()) {
ShipDetail shipDetail = (ShipDetail) shipIterator.next();
ShipHeader sHeader = shipDetail.getShipHeader();
if (sHeader.getShipHeaderId() == null) {
continue;
}
if (shipHeader != null) {
if (sHeader.getShipHeaderId().equals(shipHeader.getShipHeaderId())) {
continue;
}
}
String status = sHeader.getShipStatus();
if (status.equals(Constants.ORDERSTATUS_CANCELLED) || status.equals(Constants.ORDERSTATUS_VOIDED)) {
continue;
}
itemShipQty += shipDetail.getItemShipQty();
itemShipTotal += shipDetail.getItemShipQty();
}
itemDisplay.setItemShipQty(Format.getInt(itemShipQty));
itemOrderTotal += orderItemDetail.getItemOrderQty();
itemDetailAmount += orderItemDetail.getItemDetailAmount();
itemDetailDiscountAmount += orderItemDetail.getItemDetailDiscountAmount();
itemDetailSubTotal += total;
int itemSuggestInvoiceQty = orderItemDetail.getItemOrderQty() - itemInvoiceQty + itemCreditQty;
int itemSuggestShipQty = orderItemDetail.getItemOrderQty() - itemShipQty;
int itemSuggestCreditQty = itemInvoiceQty - itemCreditQty;
itemDisplay.setItemSuggestInvoiceQty(itemSuggestInvoiceQty);
itemDisplay.setItemSuggestShipQty(itemSuggestShipQty);
itemDisplay.setItemSuggestCreditQty(itemSuggestCreditQty);
orderItemDetails.add(itemDisplay);
}
form.setOrderItemDetails(orderItemDetails);
orderHeaderDisplayForm.setItemOrderQty(Format.getInt(itemOrderTotal));
orderHeaderDisplayForm.setItemInvoiceQty(Format.getInt(itemInvoiceTotal));
orderHeaderDisplayForm.setItemCreditQty(Format.getInt(itemCreditTotal));
orderHeaderDisplayForm.setItemShipQty(Format.getInt(itemShipTotal));
orderHeaderDisplayForm.setItemDetailAmount(Format.getFloat(itemDetailAmount));
orderHeaderDisplayForm.setItemDetailDiscountAmount(Format.getFloat(itemDetailDiscountAmount));
orderHeaderDisplayForm.setItemDetailSubTotal(Format.getFloat(itemDetailSubTotal));
form.setAllowCredit(false);
form.setAllowInvoice(false);
form.setAllowShip(false);
form.setAllowCancel(false);
// TODO should move the following logic into OrderHeaderDAO
if (!orderHeader.getOrderStatus().equals(Constants.ORDERSTATUS_CANCELLED) && itemInvoiceTotal < itemOrderTotal) {
form.setAllowInvoice(true);
}
if (!orderHeader.getOrderStatus().equals(Constants.ORDERSTATUS_CANCELLED) && itemShipTotal < itemOrderTotal) {
form.setAllowShip(true);
}
if (OrderHeaderDAO.isAllowCancel(orderHeader)) {
form.setAllowCancel(true);
}
if (invoiceHeader != null) {
float creditTotal = 0;
for (CreditHeader cHeader : invoiceHeader.getCreditHeaders()) {
creditTotal += cHeader.getCreditTotal();
}
if (!orderHeader.getOrderStatus().equals(Constants.ORDERSTATUS_CANCELLED) && creditTotal < invoiceHeader.getInvoiceTotal()) {
if (orderHeader.getPaymentGatewayProvider() == null || !orderHeader.getPaymentGatewayProvider().equals(PayPalEngine.class.getSimpleName())) {
form.setAllowCredit(true);
}
}
}
Vector<OrderOtherDetailDisplayForm> orderOtherDetails = new Vector<OrderOtherDetailDisplayForm>();
iterator = orderHeader.getOrderOtherDetails().iterator();
float orderOtherDetailAmount = 0;
while (iterator.hasNext()) {
OrderOtherDetail orderOtherDetail = (OrderOtherDetail) iterator.next();
OrderOtherDetailDisplayForm otherDisplay = new OrderOtherDetailDisplayForm();
otherDisplay.setOrderOtherDetailId(orderOtherDetail.getOrderOtherDetailId().toString());
otherDisplay.setOrderOtherDetailNum(orderOtherDetail.getOrderOtherDetailNum());
otherDisplay.setOrderOtherDetailDesc(orderOtherDetail.getOrderOtherDetailDesc());
otherDisplay.setOrderOtherDetailAmount(Format.getFloat(orderOtherDetail.getOrderOtherDetailAmount()));
orderOtherDetailAmount += orderOtherDetail.getOrderOtherDetailAmount();
orderOtherDetails.add(otherDisplay);
}
form.setOrderOtherDetails(orderOtherDetails);
orderHeaderDisplayForm.setOrderOtherDetailAmount(Format.getFloat(orderOtherDetailAmount));
iterator = orderEngine.getOrderTaxes().iterator();
Vector<OrderTax> orderTaxes = new Vector<OrderTax>();
while (iterator.hasNext()) {
OrderDetailTax orderDetailTax = (OrderDetailTax) iterator.next();
OrderTax orderTax = new OrderTax();
orderTax.setTaxName(orderDetailTax.getTax().getTaxLanguage().getTaxName());
orderTax.setTaxAmount(Format.getFloat(orderDetailTax.getTaxAmount()));
orderTaxes.add(orderTax);
}
form.setOrderTaxes(orderTaxes);
iterator = orderHeader.getOrderTrackings().iterator();
Vector<OrderTrackingDisplayForm> orderTrackings = new Vector<OrderTrackingDisplayForm>();
while (iterator.hasNext()) {
OrderTracking orderTracking = (OrderTracking) iterator.next();
if (orderTracking.getCreditHeader() != null) {
continue;
}
if (orderTracking.getInvoiceHeader() != null) {
continue;
}
OrderTrackingDisplayForm orderTrackingDisplayForm = new OrderTrackingDisplayForm();
orderTrackingDisplayForm.setOrderTrackingId(orderTracking.getOrderTrackingId().toString());
orderTrackingDisplayForm.setOrderTrackingMessage(orderTracking.getOrderTrackingMessage());
orderTrackingDisplayForm.setOrderTrackingInternal(false);
if (orderTracking.getOrderTrackingInternal().equals(String.valueOf(Constants.VALUE_YES))) {
orderTrackingDisplayForm.setOrderTrackingInternal(true);
}
orderTrackingDisplayForm.setRecUpdateDatetime(Format.getFullDatetime(orderTracking.getRecUpdateDatetime()));
orderTrackings.add(orderTrackingDisplayForm);
}
orderHeaderDisplayForm.setOrderTrackings(orderTrackings);
Vector<InvoiceHeaderDisplayForm> invoiceHeaders = new Vector<InvoiceHeaderDisplayForm>();
iterator = orderHeader.getInvoiceHeaders().iterator();
while (iterator.hasNext()) {
InvoiceHeader iHeader = (InvoiceHeader) iterator.next();
// invoiceHeader might have been updated. eg.capture
if (invoiceHeader != null) {
if (iHeader.getInvoiceHeaderId().equals(invoiceHeader.getInvoiceHeaderId())) {
iHeader = invoiceHeader;
}
}
InvoiceHeaderDisplayForm invoiceHeaderDisplayForm = new InvoiceHeaderDisplayForm();
if (iHeader.getInvoiceHeaderId() != null) {
invoiceHeaderDisplayForm.setInvoiceHeaderId(iHeader.getInvoiceHeaderId().toString());
}
invoiceHeaderDisplayForm.setInvoiceNum(iHeader.getInvoiceNum());
invoiceHeaderDisplayForm.setShippingTotal(Format.getFloat(iHeader.getShippingTotal()));
invoiceHeaderDisplayForm.setInvoiceTotal(Format.getFloat(iHeader.getInvoiceTotal()));
invoiceHeaderDisplayForm.setInvoiceStatus(resources.getMessage("order.status." + iHeader.getInvoiceStatus()));
invoiceHeaderDisplayForm.setInvoiceDate(Format.getFullDate(iHeader.getInvoiceDate()));
Iterator<?> trackingIterator = iHeader.getInvoiceTrackings().iterator();
Vector<OrderTrackingDisplayForm> invoiceTrackings = new Vector<OrderTrackingDisplayForm>();
while (trackingIterator.hasNext()) {
OrderTracking orderTracking = (OrderTracking) trackingIterator.next();
OrderTrackingDisplayForm orderTrackingDisplayForm = new OrderTrackingDisplayForm();
orderTrackingDisplayForm.setOrderTrackingId(orderTracking.getOrderTrackingId().toString());
orderTrackingDisplayForm.setOrderTrackingMessage(orderTracking.getOrderTrackingMessage());
orderTrackingDisplayForm.setOrderTrackingInternal(false);
if (orderTracking.getOrderTrackingInternal().equals(String.valueOf(Constants.VALUE_YES))) {
orderTrackingDisplayForm.setOrderTrackingInternal(true);
}
orderTrackingDisplayForm.setRecUpdateDatetime(Format.getFullDatetime(orderTracking.getRecUpdateDatetime()));
invoiceTrackings.add(orderTrackingDisplayForm);
}
invoiceHeaderDisplayForm.setOrderTrackings(invoiceTrackings);
if (iHeader.getPaymentTran() != null) {
PaymentTran paymentTran = iHeader.getPaymentTran();
PaymentTranDisplayForm paymentForm = new PaymentTranDisplayForm();
paymentForm.setAuthCode(paymentTran.getAuthCode());
paymentForm.setPaymentReference1(paymentTran.getPaymentReference1());
paymentForm.setPaymentReference2(paymentTran.getPaymentReference2());
paymentForm.setPaymentReference3(paymentTran.getPaymentReference3());
paymentForm.setPaymentReference4(paymentTran.getPaymentReference4());
paymentForm.setPaymentReference5(paymentTran.getPaymentReference5());
invoiceHeaderDisplayForm.setPaymentTran(paymentForm);
}
if (iHeader.getVoidPaymentTran() != null) {
PaymentTran paymentTran = iHeader.getVoidPaymentTran();
PaymentTranDisplayForm paymentForm = new PaymentTranDisplayForm();
paymentForm.setAuthCode(paymentTran.getAuthCode());
paymentForm.setPaymentReference1(paymentTran.getPaymentReference1());
paymentForm.setPaymentReference2(paymentTran.getPaymentReference2());
paymentForm.setPaymentReference3(paymentTran.getPaymentReference3());
paymentForm.setPaymentReference4(paymentTran.getPaymentReference4());
paymentForm.setPaymentReference5(paymentTran.getPaymentReference5());
invoiceHeaderDisplayForm.setVoidPaymentTran(paymentForm);
}
invoiceHeaders.add(invoiceHeaderDisplayForm);
}
form.setInvoiceHeaders(invoiceHeaders);
Vector<CreditHeaderDisplayForm> creditHeaders = new Vector<CreditHeaderDisplayForm>();
iterator = orderHeader.getCreditHeaders().iterator();
while (iterator.hasNext()) {
CreditHeader iHeader = (CreditHeader) iterator.next();
// creditHeader might have been updated. eg.capture
if (creditHeader != null) {
if (iHeader.getCreditHeaderId().equals(creditHeader.getCreditHeaderId())) {
iHeader = creditHeader;
}
}
CreditHeaderDisplayForm creditHeaderDisplayForm = new CreditHeaderDisplayForm();
if (iHeader.getCreditHeaderId() != null) {
creditHeaderDisplayForm.setCreditHeaderId(iHeader.getCreditHeaderId().toString());
}
creditHeaderDisplayForm.setCreditNum(iHeader.getCreditNum());
creditHeaderDisplayForm.setUpdateInventory(false);
if (iHeader.getUpdateInventory().equals(String.valueOf(Constants.VALUE_YES))) {
creditHeaderDisplayForm.setUpdateInventory(true);
}
creditHeaderDisplayForm.setShippingTotal(Format.getFloat(iHeader.getShippingTotal()));
creditHeaderDisplayForm.setCreditTotal(Format.getFloat(iHeader.getCreditTotal()));
creditHeaderDisplayForm.setCreditStatus(resources.getMessage("order.status." + iHeader.getCreditStatus()));
creditHeaderDisplayForm.setCreditDate(Format.getFullDate(iHeader.getCreditDate()));
Iterator<?> trackingIterator = iHeader.getCreditTrackings().iterator();
Vector<OrderTrackingDisplayForm> creditTrackings = new Vector<OrderTrackingDisplayForm>();
while (trackingIterator.hasNext()) {
OrderTracking orderTracking = (OrderTracking) trackingIterator.next();
OrderTrackingDisplayForm orderTrackingDisplayForm = new OrderTrackingDisplayForm();
orderTrackingDisplayForm.setOrderTrackingId(orderTracking.getOrderTrackingId().toString());
orderTrackingDisplayForm.setOrderTrackingMessage(orderTracking.getOrderTrackingMessage());
orderTrackingDisplayForm.setOrderTrackingInternal(false);
if (orderTracking.getOrderTrackingInternal().equals(String.valueOf(Constants.VALUE_YES))) {
orderTrackingDisplayForm.setOrderTrackingInternal(true);
}
orderTrackingDisplayForm.setRecUpdateDatetime(Format.getFullDatetime(orderTracking.getRecUpdateDatetime()));
creditTrackings.add(orderTrackingDisplayForm);
}
creditHeaderDisplayForm.setOrderTrackings(creditTrackings);
if (iHeader.getPaymentTran() != null) {
PaymentTran paymentTran = iHeader.getPaymentTran();
PaymentTranDisplayForm paymentForm = new PaymentTranDisplayForm();
paymentForm.setAuthCode(paymentTran.getAuthCode());
paymentForm.setPaymentReference1(paymentTran.getPaymentReference1());
paymentForm.setPaymentReference2(paymentTran.getPaymentReference2());
paymentForm.setPaymentReference3(paymentTran.getPaymentReference3());
paymentForm.setPaymentReference4(paymentTran.getPaymentReference4());
paymentForm.setPaymentReference5(paymentTran.getPaymentReference5());
creditHeaderDisplayForm.setPaymentTran(paymentForm);
}
if (iHeader.getVoidPaymentTran() != null) {
PaymentTran paymentTran = iHeader.getVoidPaymentTran();
PaymentTranDisplayForm paymentForm = new PaymentTranDisplayForm();
paymentForm.setAuthCode(paymentTran.getAuthCode());
paymentForm.setPaymentReference1(paymentTran.getPaymentReference1());
paymentForm.setPaymentReference2(paymentTran.getPaymentReference2());
paymentForm.setPaymentReference3(paymentTran.getPaymentReference3());
paymentForm.setPaymentReference4(paymentTran.getPaymentReference4());
paymentForm.setPaymentReference5(paymentTran.getPaymentReference5());
creditHeaderDisplayForm.setVoidPaymentTran(paymentForm);
}
creditHeaders.add(creditHeaderDisplayForm);
}
form.setCreditHeaders(creditHeaders);
Vector<ShipHeaderDisplayForm> shipHeaders = new Vector<ShipHeaderDisplayForm>();
iterator = orderHeader.getShipHeaders().iterator();
while (iterator.hasNext()) {
ShipHeader iHeader = (ShipHeader) iterator.next();
// shipHeader might have been updated. eg.capture
if (shipHeader != null) {
if (iHeader.getShipHeaderId().equals(shipHeader.getShipHeaderId())) {
iHeader = shipHeader;
}
}
ShipHeaderDisplayForm shipHeaderDisplayForm = new ShipHeaderDisplayForm();
if (iHeader.getShipHeaderId() != null) {
shipHeaderDisplayForm.setShipHeaderId(iHeader.getShipHeaderId().toString());
}
shipHeaderDisplayForm.setShipNum(iHeader.getShipNum());
shipHeaderDisplayForm.setUpdateInventory(false);
if (iHeader.getUpdateInventory().equals(String.valueOf(Constants.VALUE_YES))) {
shipHeaderDisplayForm.setUpdateInventory(true);
}
shipHeaderDisplayForm.setShipStatus(resources.getMessage("order.status." + iHeader.getShipStatus()));
shipHeaderDisplayForm.setShipDate(Format.getFullDate(iHeader.getShipDate()));
Iterator<?> trackingIterator = iHeader.getShipTrackings().iterator();
Vector<OrderTrackingDisplayForm> shipTrackings = new Vector<OrderTrackingDisplayForm>();
while (trackingIterator.hasNext()) {
OrderTracking orderTracking = (OrderTracking) trackingIterator.next();
OrderTrackingDisplayForm orderTrackingDisplayForm = new OrderTrackingDisplayForm();
orderTrackingDisplayForm.setOrderTrackingId(orderTracking.getOrderTrackingId().toString());