Script: Class dw.order.Invoice

Class Invoice

The Invoice can be a debit or credit invoice, and is created from custom scripts using one of the methods ShippingOrder.createInvoice(String), Appeasement.createInvoice(String), ReturnCase.createInvoice(String) or Return.createInvoice(String).

Order post-processing APIs (gillian) are now inactive by default and will throw an exception if accessed. Activation needs preliminary approval by Product Management. Please contact support in this case. Existing customers using these APIs are not affected by this change and can use the APIs until further notice.

Constants

ORDERBY_CREATION_DATE : Object

Sorting by creation date. Use with method getPaymentTransactions() as an argument to method FilteringCollection.sort(Object).

ORDERBY_ITEMID : Object

Sorting by item id. Use with method getItems() as an argument to method FilteringCollection.sort(Object).

ORDERBY_ITEMPOSITION : Object

Sorting by the position of the related oder item. Use with method getItems() as an argument to method FilteringCollection.sort(Object).

ORDERBY_REVERSE : Object

Reverse orders. Use as an argument to method FilteringCollection.sort(Object).

ORDERBY_UNSORTED : Object

Unsorted , as it is. Use with method getItems() as an argument to method FilteringCollection.sort(Object).

QUALIFIER_CAPTURE : Object

Selects the capture transactions. Use with method getPaymentTransactions() as an argument to method FilteringCollection.select(Object).

QUALIFIER_PRODUCTITEMS : Object

Selects the product items. Use with method getItems() as an argument to method FilteringCollection.select(Object).

QUALIFIER_REFUND : Object

Selects the refund transactions. Use with method getPaymentTransactions() as an argument to method FilteringCollection.select(Object).

QUALIFIER_SERVICEITEMS : Object

Selects for the service items. Use with method getItems() as an argument to method FilteringCollection.select(Object).

STATUS_FAILED : String = "FAILED"

Constant for Invoice Status Failed.
The invoice handling failed.

STATUS_MANUAL : String = "MANUAL"

Constant for Invoice Status Manual.
The invoice is not paid but will not be handled automatically.
A manual invoice handling (capture or refund) is necessary.

STATUS_NOT_PAID : String = "NOT_PAID"

Constant for Invoice Status Not Paid.
The invoice is not paid and will be handled automatically.

STATUS_PAID : String = "PAID"

Constant for Invoice Status Paid.
The invoice was successfully paid.

TYPE_APPEASEMENT : String = "APPEASEMENT"

Constant for Invoice Type Appeasement.
The invoice was created for an appeasement.
The invoice amount needs to be refunded.

TYPE_RETURN : String = "RETURN"

Constant for Invoice Type Return.
The invoice was created for a return.
The invoice amount needs to be refunded.

TYPE_RETURN_CASE : String = "RETURN_CASE"

Constant for Invoice Type Return Case.
The invoice was created for a return case.
The invoice amount needs to be refunded.

TYPE_SHIPPING : String = "SHIPPING"

Constant for Invoice Type Shipping.
The invoice was created for a shipping order.
The invoice amount needs to be captured.

Properties

capturedAmount : Money Read Only

The sum of the captured amounts. The captured amounts are calculated on the fly.
Associate a payment capture for a OrderPaymentInstrument with an Invoice using addCaptureTransaction(OrderPaymentInstrument, Money).

invoiceNumber : String Read Only

The invoice number.

items : FilteringCollection Read Only

Access the collection of InvoiceItems.

This FilteringCollection can be sorted / filtered using:

paymentTransactions : FilteringCollection Read Only

The payment transactions belonging to this Invoice.

This FilteringCollection can be sorted / filtered using:

refundedAmount : Money Read Only

The sum of the refunded amounts. The refunded amounts are calculated on the fly.
Associate a payment capture for a OrderPaymentInstrument with an Invoice using addRefundTransaction(OrderPaymentInstrument, Money).

status : EnumValue

The invoice status.
The possible values are STATUS_NOT_PAID, STATUS_MANUAL, STATUS_PAID, STATUS_FAILED.

type : EnumValue Read Only

The invoice type.
The possible values are TYPE_SHIPPING, TYPE_RETURN, TYPE_RETURN_CASE, TYPE_APPEASEMENT.

Constructor Summary

This class does not have a constructor, so you cannot create it directly.

Method Summary

account() : boolean

The invoice will be accounted.

addCaptureTransaction(instrument : OrderPaymentInstrument, capturedAmount : Money) : PaymentTransaction

Calling this method registers an amount captured for a given order payment instrument.

addRefundTransaction(instrument : OrderPaymentInstrument, refundedAmount : Money) : PaymentTransaction

Calling this method registers an amount refunded for a given order payment instrument.

getCapturedAmount() : Money

Returns the sum of the captured amounts.

getInvoiceNumber() : String

Returns the invoice number.

getItems() : FilteringCollection

Access the collection of InvoiceItems.

getPaymentTransactions() : FilteringCollection

Returns the payment transactions belonging to this Invoice.

getRefundedAmount() : Money

Returns the sum of the refunded amounts.

getStatus() : EnumValue

Returns the invoice status.
The possible values are STATUS_NOT_PAID, STATUS_MANUAL, STATUS_PAID, STATUS_FAILED.

getType() : EnumValue

Returns the invoice type.
The possible values are TYPE_SHIPPING, TYPE_RETURN, TYPE_RETURN_CASE, TYPE_APPEASEMENT.

setStatus(status : String) : void

Sets the invoice status.
The possible values are STATUS_NOT_PAID, STATUS_MANUAL, STATUS_PAID, STATUS_FAILED.

Methods inherited from class AbstractItemCtnr

getCreatedBy, getCreationDate, getGrandTotal, getItems, getLastModified, getModifiedBy, getOrder, getProductSubtotal, getServiceSubtotal

Methods inherited from class Extensible

describe, getCustom

Methods inherited from class Object

assign, create, create, defineProperties, defineProperty, entries, freeze, fromEntries, getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols, getPrototypeOf, hasOwnProperty, is, isExtensible, isFrozen, isPrototypeOf, isSealed, keys, preventExtensions, propertyIsEnumerable, seal, setPrototypeOf, toLocaleString, toString, valueOf, values

Method Detail

account

account() : boolean

The invoice will be accounted.

It will be captured in case of a shipping invoice and it will be refunded in case of an appeasement, return case or return invoice.

The accounting will be handled in the payment hooks PaymentHooks.capture(Invoice) or PaymentHooks.refund(Invoice). The implementing script could add payment transactions to the invoice. The accompanying business logic will set the status to PAID or FAILED.

The accounting will fail when the invoice state is different to STATUS_NOT_PAID or STATUS_FAILED.

The method implements its own transaction handling. The method must not be called inside a transaction.

Returns:

true when the accounting was successful, otherwise false.

addCaptureTransaction

addCaptureTransaction(instrument : OrderPaymentInstrument, capturedAmount : Money) : PaymentTransaction

Calling this method registers an amount captured for a given order payment instrument. The authorization for the capture is associated with the payment transaction belonging to the instrument. Calling this method allows the Invoice, the OrderPaymentInstrument and the Order to return their captured amount as a sum calculated on the fly. The method may be called multiple times for the same instrument (multiple capture for one authorization) or for different instruments (invoice settlement using multiple payments).

Parameters:

instrument - the order payment instrument

capturedAmount - amount to register as captured

Returns:

the created capture transaction


addRefundTransaction

addRefundTransaction(instrument : OrderPaymentInstrument, refundedAmount : Money) : PaymentTransaction

Calling this method registers an amount refunded for a given order payment instrument. Calling this method allows the Invoice, the OrderPaymentInstrument and the Order to return their refunded amount as a sum calculated on the fly. The method may be called multiple times for the same instrument (multiple refunds of one payment) or for different instruments (invoice settlement using multiple payments).

Parameters:

instrument - the order payment instrument

refundedAmount - amount to register as refunded

Returns:

the created refund transaction


getCapturedAmount

getCapturedAmount() : Money

Returns the sum of the captured amounts. The captured amounts are calculated on the fly.
Associate a payment capture for a OrderPaymentInstrument with an Invoice using addCaptureTransaction(OrderPaymentInstrument, Money).

Returns:

sum of captured amounts


getInvoiceNumber

getInvoiceNumber() : String

Returns the invoice number.

Returns:

the invoice number


getItems

getItems() : FilteringCollection

Access the collection of InvoiceItems.

This FilteringCollection can be sorted / filtered using:

Returns:

the invoice items


getPaymentTransactions

getPaymentTransactions() : FilteringCollection

Returns the payment transactions belonging to this Invoice.

This FilteringCollection can be sorted / filtered using:

Returns:

the payment transactions.

See Also:

PaymentTransaction


getRefundedAmount

getRefundedAmount() : Money

Returns the sum of the refunded amounts. The refunded amounts are calculated on the fly.
Associate a payment capture for a OrderPaymentInstrument with an Invoice using addRefundTransaction(OrderPaymentInstrument, Money).

Returns:

sum of refunded amounts


getStatus

getStatus() : EnumValue

Returns the invoice status.
The possible values are STATUS_NOT_PAID, STATUS_MANUAL, STATUS_PAID, STATUS_FAILED.

Returns:

the invoice status


getType

getType() : EnumValue

Returns the invoice type.
The possible values are TYPE_SHIPPING, TYPE_RETURN, TYPE_RETURN_CASE, TYPE_APPEASEMENT.

Returns:

the invoice type


setStatus

setStatus(status : String) : void

Sets the invoice status.
The possible values are STATUS_NOT_PAID, STATUS_MANUAL, STATUS_PAID, STATUS_FAILED.

Parameters:

status - the invoice status to set