# Stock Transfer

## Stock Transfer's Database

<table><thead><tr><th>UI Name</th><th>Database</th><th>Type</th><th>Remarks</th></tr></thead><tbody><tr><td>Stock Transfer No</td><td><pre><code>docNo
</code></pre></td><td><strong><code>String</code></strong></td><td>Avoid using the same <strong><code>Stock Transfer No</code></strong> to prevent overwrite.<br><br>E.g.: <code>STC00001</code></td></tr><tr><td>Description</td><td><pre><code>description
</code></pre></td><td><strong><code>String</code></strong></td><td>E.g.: <code>STOCK TRANSFER</code></td></tr><tr><td>Date</td><td><pre><code>docDate
</code></pre></td><td><strong><code>String</code></strong></td><td>E.g.: <code>2024-11-27T00:00:00+08:00</code></td></tr><tr><td>From Location</td><td><pre><code>FromLocation
</code></pre></td><td><strong><code>String</code></strong></td><td><p>Must have existing <strong><code>FromLocation</code></strong> in the accounting system.</p><p></p><p>E.g.: <code>HQ</code></p></td></tr><tr><td>To Location</td><td><pre><code>ToLocation
</code></pre></td><td><strong><code>String</code></strong></td><td><p>Must have existing <strong><code>ToLocation</code></strong> in the accounting system.</p><p></p><p>E.g.: <code>CUST</code></p></td></tr><tr><td>Table Item</td><td><pre><code>details
</code></pre></td><td><strong><code>Array</code></strong></td><td><a href="#stock-transfers-table-item">Refer Below</a></td></tr></tbody></table>

## Stock Transfer's Table Item

<table><thead><tr><th>UI Name</th><th>Database</th><th>Type</th><th>Remarks</th></tr></thead><tbody><tr><td>Item Code</td><td><pre><code>itemCode
</code></pre></td><td><strong><code>String</code></strong></td><td>E.g.: <code>A001</code></td></tr><tr><td>Description</td><td><pre><code>description
</code></pre></td><td><strong><code>String</code></strong></td><td>E.g.: <code>PRODUCT - CL14</code></td></tr><tr><td>UOM</td><td><pre><code>uom
</code></pre></td><td><strong><code>String</code></strong></td><td>E.g.: <code>UNIT</code></td></tr><tr><td>Qty</td><td><pre><code>qty
</code></pre></td><td><strong><code>Decimal</code></strong></td><td><p>Value must be <strong>number</strong>, and value <strong>cannot</strong> be <strong>zero</strong> or <strong>negative.</strong></p><p></p><p>E.g.: <code>10.0</code></p></td></tr><tr><td>Unit Price</td><td><pre><code>unitPrice
</code></pre></td><td><strong><code>Decimal</code></strong></td><td><p>Value must be <strong>number</strong>, and value <strong>cannot</strong> be <strong>negative.</strong></p><p></p><p>E.g.: <code>10.0</code></p></td></tr></tbody></table>

## Stock Transfer's Sample Code

{% hint style="warning" %}
Remember to change to the **correct field** before proceeding to run **ANY** script.
{% endhint %}

{% tabs %}
{% tab title="Logic Script" %}
{% hint style="info" %}
To find `{fieldName}`, you are required to have access to **Alpha** or use **Network** in Developer Tools `[F12]`.
{% endhint %}

{% code fullWidth="true" %}
```python
import clr

clr.AddReference("Newtonsoft.Json")
clr.AddReference("System.Net")
clr.AddReference("System.IO")

from System.Text import *
from Newtonsoft.Json import *
from Newtonsoft.Json.Linq import *
from System import *

clr.AddReference("System.Drawing")
from System.Drawing import Bitmap, Image
from System.Drawing.Imaging import ImageFormat
from System.IO import MemoryStream, StreamWriter
from System.Net import WebClient
import binascii
from System import BitConverter

# search
documentList = Module("{YOUR-MODULE-NAME}").findAll(
    {
        "Audit.UpdatedDate": {"$gt": Inputs["lastSync"]},
        "Audit.UpdatedBy": {"$ne": "External"},
    }
)
debug("documentList", documentList)

resultList = []

def prepareRow(x):
    row = JObject()
    row["itemCode"] = x["{YOUR-ITEM-CODE}"]
    row["description"] = x["{YOUR-DESCRIPTION}"].ToString()
    row["uom"] = x["{YOUR-UOM}"]
    row["qty"] = x["{YOUR-QTY}"]
    row["unitPrice"] = x["{YOUR-UNIT-PRICE}"]
    return row


def preparePayload(data):
    payloadData = JObject()
    payloadData["type"] = "ST"
    payloadData["payload"] = JObject()

    # payloadData["payload"]["docNo"] = None if data['{YOUR-DOC-NO}'] == "" or data['{YOUR-DOC-NO}'] is None else data['{YOUR-DOC-NO}']
    payloadData["payload"]["docNo"] = data.DocumentId

    payloadData["payload"]["description"] = "STOCK TRANSFER"
    payloadData["payload"]["docDate"] = data["{YOUR-DOC-DATE}"]
    payloadData["payload"]["FromLocation"] = data["{YOUR-FROM-LOCATION}"]
    payloadData["payload"]["ToLocation"] = data["{YOUR-TO-LOCATION}"]

    payloadData["payload"]["details"] = JArray.FromObject(
        data["{YOUR-TABLE}"].Select(lambda x: prepareRow(x))
    )

    payloadData["LastModified"] = data.UpdatedDate
    return payloadData


# end of added
for entry in documentList:
    payloadData = preparePayload(entry)
    resultList.append(payloadData)
    # debug('payloadData', payloadData)

# debug('done', resultList)
outputs["results"] = JArray.FromObject(resultList)
debug("result", resultList)
```
{% endcode %}
{% endtab %}
{% endtabs %}

a
