Skip to content

Order From List of Cards

Description

Allow Users either through the UI or an API call to create an Order (Header and Lines) from a list of KanbanCards.

Requirement

Given a list of KanbanCard Details (given by cards.arda.operations.resources.kanban.business.KanbanCardDetails) implement
a function that creates:

  1. An OrderHeader object (cards.arda.operations.resources.order.business.OrderHeader)
  2. An OrderMetadata object (cards.arda.operations.resources.order.business.OrderMetadata)
  3. A list of Pair<OrderLine, OrderLineMetadata> objects (cards.arda.operations.resources.order.business.OrderLine, cards.arda.operations.resources.order.business.OrderLineMetadata)

Preconditions/Validations

If any of these preconditions are violated, the system will return an error and no changes to the system will be made.

  1. All input KanbanCards are in status KanbanCardStatus.REQUESTING
  2. All Kanban Cards must be for the same Vendor or have no vendor information.

Scenario Overview

  1. The user selects a list of Kanban Cards in status KanbanCardStatus.REQUESTING.
  2. The system then:
    1. Identifies the Cards by their eId and the TimeCoordinates.now() bitemporal coordinates.
    2. Retrieves the KanbanCardDetails and composes an OrderHeader and a list of OrderLines according to the rules below.
    3. Persists the OrderHeader and OrderLines.
    4. Signals the KanbanCards KanbanCardEventType.ACCEPT which causes them to transition to KanbanCardStatus.ORDERED,
      and links them to the created OrderLines.
    5. Returns the newly created OrderHeader and OrderLines for the User (through the UI or API) to review and modify.

PostConditions

  1. The new OrderHeader and OrderLines are persisted and accessible in the system.
  2. The selected KanbanCards are updated to status KanbanCardStatus.ORDERED and linked to the created OrderLines.

Creation of Order Lines

One order line will be created for each group of KanbanCardDetails that share the same values for:

  • item.eId
  • cardQuantity.unit

cardQuantity.unit values include null.

Note

Define $ as the KanbanCardDetails object under consideration.

The fields of the resulting OrderLine are:

Simple OrderLine fields

  1. The eId’s of OrderLine is generated with a Random UUID (UUID.randomUUID())
  2. status set to OrderLineStatus.BLANK
  3. item: set to the item field of the `KanbanCardDetails
  4. received set to 0.0 with the same unit as the quantity field (see below)
  5. notes set to null
    6privateNotes set to null

Quantity field.

Intermediate values
  • Define $.sourceSupply as the object $.itemDetails.primarySupply or $.itemDetails.secondarySupply whose supplier field is equals to header.supplierName (see below how this is determined). This value is null
    if either the header supplierName is null or if neither of the two supplies has a supplier field equal to header.supplierName.
Quantity computation

if the unit value of the group is null, the quantity for the order line is null.

Otherwise:

  • unit set to the shared cardQuantity.unit of the group.
  • amount sets to:
    • The sum of the cardQuantity.amount if the unit field is either different to the $.sourceSupply.orderQuantity.unit or if $.sourceSupply.orderQuantity is null.
    • The maximum of the sum of the cardQuantity.amount and the $.sourceSupply.orderQuantity.amount if the unit field is equal (not null) to the $.sourceSupply.orderQuantity.unit.

Unit Cost field.

  • unitCost is null if R.sourceSupply is null or if $.sourceSupply.orderQuantity.unit is different than $.quantity.unit.
  • Otherwise, unitCost is set to $.sourceSupply.unitCost.

Cost field

  • cost is null if either unitCost or quantity is null.
  • Otherwise, cost is set to unitCost * quantity.amount in the same currency unit as $.unitCost.

Cards Field

The cards field is a list of KanbanCardReference Value objects. They are implemented as a Json field in the OrderLine table for persistence.

This means that the cards field is not accessible through queries at this point. For it to be queryable, a new intersection table will be needed and
may be implemented in a future release.

Creation of Order Header

Simple OrderHeader fields

  1. The eId’s of OrderHeader is generated with a Random UUID (UUID.randomUUID())
  2. Simple OrderHeader fields:
    1. status set to OrderStatus.BLANK
    2. orderNumber: For now, set to a parameter of the function.
    3. orderDate: Set to the current time in the timezone of the system.
    4. allowPartial set to true
    5. deliverBy set to the current time plus 7 days in the timezone of the system.
    6. deliveryAddress set to null.
    7. procurement: set to null
    8. supplierAddress: set to null.
    9. sales: set to null.
    10. taxesAndFees: set to an empty map.
    11. termsAndConditions: set to null.
    12. notes: set to null.
    13. privateNotes: set to null.

supplierName field

Let candidateSuppliers for a KanbanCardDetails be the list of values: itemDetails.primarySupply.supplier, itemDetails.secondarySupply.supplier that are non-null.

  1. If there is a value in all the KanbanCardDetails.candidateSuppliers that is common to all of them, then set supplierName to that value.
  2. If there are no common non-null values shared by all KanbanCardDetails in the list, set supplierName to null.
  3. If there is more than one common non-null value shared by all KanbanCardDetails, pick the one that has the most mentions as itemDetails.primarySupply.supplier across all KanbanCardDetails.

orderMethod field

If the supplierName assigned according to the rules above is non-null, set orderMethod to the value of the first non-null value among the itemDetails.primarySupply.orderMethod in the
order of the list of KanbanCardDetails in the input argument.

Otherwise, set orderMethod to OrderMethod.UNKNOWN.

goodsValue field

Set the goodsValue field to sum(orderLine.cost) for all order lines created from the KanbanCardDetails in the input argument that have non-null cost fields (see above).

Updates to Kanban Cards

Each KanbanCard in the input list will be signalled with a KanbanCardEventType.ACCEPT event that will cause it to transition to status KanbanCardStatus.ORDERED through
the KanbanCardService.

Comments