> For the complete documentation index, see [llms.txt](https://inistate.gitbook.io/home/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://inistate.gitbook.io/home/advanced/integration/accounting-1/stock-item.md).

# Stock Item

## Stock Item's Database

<table><thead><tr><th>UI Name</th><th width="211.22216796875">Database</th><th width="154.1112060546875">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>Item-Code-01</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>Rate</td><td><pre><code>Rate
</code></pre></td><td><strong><code>Integer</code></strong></td><td>E.g.: <code>1</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>Description</code></td></tr><tr><td>Description 2</td><td><pre><code>Desc2
</code></pre></td><td><strong><code>String</code></strong></td><td>E.g.: <code>Description2</code></td></tr><tr><td>Item Group</td><td><pre><code>ItemGroup
</code></pre></td><td><strong><code>String</code></strong></td><td>E.g.: <code>ItemGroup</code></td></tr><tr><td>Item Type</td><td><pre><code>ItemType
</code></pre></td><td><strong><code>String</code></strong></td><td>E.g.: <code>ItemType</code></td></tr><tr><td>Lead Time</td><td><pre><code>LeadTime
</code></pre></td><td><strong><code>String</code></strong></td><td>E.g.: <code>LeadTime</code></td></tr><tr><td>Duty Rate</td><td><pre><code>Duty Rate
</code></pre></td><td><strong><code>String</code></strong></td><td>E.g.: <code>Duty Rate</code></td></tr><tr><td>Supply Tax Code</td><td><pre><code>TaxCode
</code></pre></td><td><strong><code>String</code></strong></td><td>E.g.: <code>Tax Code</code></td></tr><tr><td>Purchase Tax Code</td><td><pre><code>PurchaseTaxCode
</code></pre></td><td><strong><code>String</code></strong></td><td>E.g.: <code>PurchaseTaxCode</code></td></tr><tr><td>Tariff Code</td><td><pre><code>Tariff Code
</code></pre></td><td><strong><code>String</code></strong></td><td>E.g.: <code>Tariff Code</code></td></tr><tr><td>Shelf</td><td><pre><code>Shelf
</code></pre></td><td><strong><code>String</code></strong></td><td>E.g.: <code>Shelf</code></td></tr><tr><td>Price 1</td><td><pre><code>Price
</code></pre></td><td><strong><code>Decimal</code></strong></td><td>E.g.: <code>1.00</code></td></tr><tr><td>Price 2</td><td><pre><code>Price2
</code></pre></td><td><strong><code>Decimal</code></strong></td><td>E.g.: <code>1.00</code></td></tr><tr><td>Price3</td><td><pre><code>Price3
</code></pre></td><td><strong><code>Decimal</code></strong></td><td>E.g.: <code>1.00</code></td></tr><tr><td>Price 4</td><td><pre><code>Price4
</code></pre></td><td><strong><code>Decimal</code></strong></td><td>E.g.: <code>1.00</code></td></tr><tr><td>Price 5</td><td><pre><code>Price5
</code></pre></td><td><strong><code>Decimal</code></strong></td><td>E.g.: <code>1.00</code></td></tr><tr><td>Price 6</td><td><pre><code>Price6
</code></pre></td><td><strong><code>Decimal</code></strong></td><td>E.g.: <code>1.00</code></td></tr><tr><td>Standard Cost</td><td><pre><code>Cost
</code></pre></td><td><strong><code>Integer</code></strong></td><td>E.g.: <code>1.8</code></td></tr><tr><td>Min. Selling Price</td><td><pre><code>MinSalePrice
</code></pre></td><td><strong><code>Decimal</code></strong></td><td>E.g.: <code>1.00</code></td></tr><tr><td>Max. Selling Price</td><td><pre><code>MaxSalePrice
</code></pre></td><td><strong><code>Decimal</code></strong></td><td>E.g.: <code>1.00</code></td></tr><tr><td>Min. Purchase Price</td><td><pre><code>MinPurchasePrice
</code></pre></td><td><strong><code>Decimal</code></strong></td><td>E.g.: <code>1.00</code></td></tr><tr><td>Max. Purchase Price</td><td><pre><code>MaxPurchasePrice
</code></pre></td><td><strong><code>Decimal</code></strong></td><td>E.g.: <code>1.00</code></td></tr><tr><td>Balance Qty</td><td><pre><code>BalQty
</code></pre></td><td><strong><code>Integer</code></strong></td><td>E.g.: <code>100</code></td></tr><tr><td>Min. Qty</td><td><pre><code>MinQty
</code></pre></td><td><strong><code>Decimal</code></strong></td><td>E.g.: <code>1.00</code></td></tr><tr><td>Max. Qty</td><td><pre><code>MaxQty
</code></pre></td><td><strong><code>Decimal</code></strong></td><td>E.g.: <code>1.00</code></td></tr><tr><td>Normal Level</td><td><pre><code>NormalLevel
</code></pre></td><td><strong><code>Decimal</code></strong></td><td>E.g.: <code>1.00</code></td></tr><tr><td>Re-order Level</td><td><pre><code>ReOLevel
</code></pre></td><td><strong><code>Decimal</code></strong></td><td>E.g.: <code>1.00</code></td></tr><tr><td>Re-order Qty</td><td><pre><code>ReOQty
</code></pre></td><td><strong><code>Decimal</code></strong></td><td>E.g.: <code>1.00</code></td></tr></tbody></table>

## Stock Item'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
debug("test")
moduleName = "{YOUR-MODULE-NAME}"
inistateKeyField = "DocumentId"
keyField = "Doc"
modifiedDateField = "LastModified"
fields = [["DocumentId", "Doc"], ["LastModified", "LastModified"]]
inistateFields = []


result = list(inputs["list"]).ToList()
for item in result:
    entry = Module(moduleName).find({
        "$and": [
            {"Dynamic.Extension.{fieldName}": item["{YOUR-ITEM-CODE}"],
            {"Dynamic.Extension.{fieldName}": item["{YOUR-UOM}"]
        ]
    })
    debug('entry' + item['ItemCode'].ToString(),entry)
    form = Module(moduleName).execute("sync", entry)
    debug('form',form)
    form["Item Code"] = item["{YOUR-ITEM-CODE}"]
    form["UOM"] = item["{YOUR-UOM}"]
    form["Rate"] = item["{YOUR-RATE}"]
    form["Description"] = item["{YOUR-DESCRIPTION}"]
    form["Description 2"] = item["{YOUR-DESCRIPTION-2}"]
    form["Item Group"] = item["{YOUR-ITEM-GROUP}"]
    form["Item Type"] = item["{YOUR-ITEM-TYPE}"]
    form["Lead Time"] = item["{YOUR-LEAD-TIME}"]
    form["Duty Rate"] = item["{YOUR-DUTY-RATE}"]
    form["Supply Tax Code"] = item["{YOUR-SUPPLY-TAX-CODE}"]
    form["Purchase Tax Code"] = item["{YOUR-PURCHASE-TAX-CODE}"]
    form["Tariff Code"] = item["{YOUR-TARIFF-CODE}"]
    form["Shelf"] = item["{YOUR-SHELF}"]
    form["Price 1"] = item["{YOUR-PRICE-1}"]
    form["Price 2"] = item["{YOUR-PRICE-2}"]
    form["Price 3"] = item["{YOUR-PRICE-3}"]
    form["Price 4"] = item["{YOUR-PRICE-4}"]
    form["Price 5"] = item["{YOUR-PRICE-5}"]
    form["Price 6"] = item["{YOUR-PRICE-6}"]
    form["Standard Cost"] = item["{YOUR-STANDARD-COST}"]
    form["Min. Selling Price"] = item["{YOUR-MIN-SELLING-PRICE}"]
    form["Max. Selling Price"] = item["{YOUR-MAX-SELLING-PRICE}"]
    form["Min. Purchase Price"] = item["{YOUR-MIN-PURCHASE-PRICE}"]
    form["Max. Purchase Price"] = item["{YOUR-MAX-PURCHASE-PRICE}"]
    form["Balance Qty"] = item["{YOUR-BALANCE-QTY}"]
    form["Min. Qty"] = item["{YOUR-MIN-QTY}"]
    form["Max. Qty"] = item["{YOUR-MAX-QTY}"]
    form["Normal Level"] = item["{YOUR-NORMAL-LEVEL}"]
    form["Re-order Level"] = item["{YOUR-REORDER-LEVEL}"]
    form["Re-order Qty"] = item["{YOUR-REORDER-QTY}"]

    debug("form "+ item['ItemCode'].ToString(), form)
    Module(moduleName).submit(entry, form)

```

{% endcode %}
{% endtab %}

{% tab title="SQL Script" %}
{% hint style="danger" %}
This is a sample SQL, may not be as same as your database.\
\*DECLARE @date DATETIME = '2025-01-01 00:00:00';
{% endhint %}

```sql

;WITH TopItems AS (
    SELECT TOP (10) 
        i.ItemCode 
    FROM Item AS i 
    WHERE i.LastModified > @date 
    ORDER BY i.LastModified ASC
)
SELECT 
    i.DocKey, 
    i.ItemCode, 
    u.UOM, 
    u.Rate, 
    i.Description, 
    i.Desc2, 
    i.ItemGroup, 
    i.ItemType, 
    i.LeadTime, 
    i.DutyRate, 
    i.TaxCode, 
    i.PurchaseTaxCode, 
    i.TariffCode, 
    u.Shelf, 
    u.Price, 
    u.Price2, 
    u.Price3, 
    u.Price4, 
    u.Price5, 
    u.Price6, 
    u.Cost, 
    u.MinSalePrice, 
    u.MaxSalePrice, 
    u.MinPurchasePrice, 
    u.MaxPurchasePrice, 
    b.BalQty, 
    u.MinQty, 
    u.MaxQty, 
    u.NormalLevel, 
    u.ReOLevel, 
    u.ReOQty, 
    i.LastModified 
FROM Item AS i 
INNER JOIN itemUOM AS u 
    ON i.ItemCode = u.ItemCode 
LEFT JOIN ItemBatchBalQty AS b 
    ON i.ItemCode = b.ItemCode 
    AND u.UOM = b.UOM 
INNER JOIN TopItems AS t 
    ON i.ItemCode = t.ItemCode 
ORDER BY i.LastModified DESC;
```

{% endtab %}

{% tab title="jobs.json" %}
{% hint style="warning" %}
In order to sync, you must include **`LastModified`** in **`SELECT`**
{% endhint %}

```json
"SQLSync": [
   {
      "name": "SyncBackStockItem",
      "enabled": true,
      "connectionString": "Data Source={YOUR-SERVER-NAME};Initial Catalog={YOUR-DATABASE-NAME};User Id=sa2;Password=sa2;",
      "hook": "https://api.inistate.com/api/automationHook/hook/{MODULE-ID}-{LOGIC-NAME}",
      "sql": ";WITH TopItems AS ( SELECT TOP(10) i.ItemCode FROM Item AS i WHERE i.LastModified > @date ORDER BY i.LastModified ASC ) SELECT i.DocKey, i.ItemCode, u.UOM, u.Rate, i.Description, i.Desc2, i.ItemGroup, i.ItemType, i.LeadTime, i.DutyRate, i.TaxCode, i.PurchaseTaxCode, i.TariffCode, u.Shelf, u.Price, u.Price2, u.Price3, u.Price4, u.Price5, u.Price6, u.Cost, u.MinSalePrice, u.MaxSalePrice, u.MinPurchasePrice, u.MaxPurchasePrice, b.BalQty, u.MinQty, u.MaxQty, u.NormalLevel, u.ReOLevel, u.ReOQty, i.LastModified FROM Item AS i INNER JOIN itemUOM AS u ON i.ItemCode = u.ItemCode LEFT  JOIN ItemBatchBalQty AS b ON i.ItemCode = b.ItemCode AND u.UOM = b.UOM INNER JOIN TopItems t ON i.ItemCode = t.ItemCode ORDER BY i.LastModified DESC;",
      "debug": false,
      "lastSync": "{LAST-SYNC-DATE-TIME}",
      "start": null
  }
]
```

{% endtab %}
{% endtabs %}
