r

Update Monthly Billing Orders

The function Update_Open_Monthly_Billing_Json allows you to set up new Standing Orders for monthly billing.
This function is safe to use, it got input Quality Tests and work procedures to prevent malfunctions.
Before you continue reading, it is recommended to get familiar with the
[hyp_Client Monthly Billing for Services]
table.

Function Input

{
  "Modify":[
    {
      "Client":500002,
      "Product":"open basic",
      "FromDate":"2024-01-01"
    },
    {
      "Client":500007,
      "Product":"open silver",
      "FromDate":"2024-02-01"
    }
  ],
  "Parallel_Catalogic_Contain":"open"
}

The "Modify" array is mandatory. Each item should contain 3 fields (names are not case sensitive):
Field Description
Client An exist Client entity in hyper. Stored in the current
[hyp_Clients]
table (Archive and Deleted clients cannot be updated here).
Product Full product catalogic number. Stored in
[hyp_Product Header]
table, and the
[Block Sales]
field value must be False.
IF you set an Empty string value ("") or null, you ask hyper to END THE CURRENT SUBSCRIPTION.
FromDate The billing order will start on this Day. IF the client have a parallel order it will be closed until the day before.
You can back update orders, up to 40 days (before Today UTC).
Quantity Default value is 1 (one) in case that this object is missing or null or empty ("").

About the "Parallel_Catalogic_Contain" object

This parameter is Critical! Without it you can only add new Standing Orders, but you cannot end the previous ones or switch between plans.
The idea is to keep every plan with the same key words inside the catalogic number field (string type).
It can be the same prefix, as in the example above, or in the middle / end of the string.
When you pass this parameter, then Hyper query the
[hyp_Client Monthly Billing for Services].[Catalogic Number]
field as "contain string".

Function Output

Here is an example, according to the input block above.
{
  "FunctionName":"Update_Open_Monthly_Billing_Json",
  "Response":[
    {
      "Client":"500002",
      "Modified":True
    },
    {
      "Client":"500222",
      "Note":"Client number is wrong.",
      "Modified":False
    }
  ]
}

Because the input is based on an Array object ("Modify"), The "Response" object is also an Array, keeping the same items order !
Each response item contain a "Client" number from the input, and a Boolean "Modified" status.
In case of an error, a "Note" object will be included (before the "Modified" object).

Description of Operations

The following actions taking place when posting data to this function.
For EVERY ITEM of the "Modify" array - The process will stop on a failure, returning a message in the "Response" array, keeping the same items order.

For each client (from "Modify" array), do this list:
  1. Check that client number is legal and exist in the Current Clients table ("Normal Storage").
  2. IF "Parallel_Catalogic_Contain" object was sent, then query for rows where
    [hyp_Client Monthly Billing for Services].[Catalogic Number]
    field contain that string (in any position).
    Otherwise, you can only append a new order.
  3. Verify that "FromDate" is Greater then (Today - 40 days). You can use any future date (no limitation).
  4. IF "product" is Null and the "Parallel_Catalogic_Contain" object was sent, Then search and close current Standing Order.
  5. Search "product" in the
    [hyp_Product Header]
    table and Verify that it's Enabled.
  6. Check if Subscription is already exist (with the same quantity). IF it does, then Exit (stop here) with "Modified":True and a proper note.
  7. IF it reach to this point, then End (close) current Standing Order and Create a New Order as requested.