Sunday, October 28, 2018

Create an Inventory Adjustment record with PHP via Web Services

 

The code snippet below shows how to create an Inventory Adjustment record using PHP. On this sample, we will adjust the inventory of an item in a specific location with a specific quantity. The adjustment would be recorded to an Account.

 

 

require_once 'PHPtoolkit.php';
require_once 'login_info.php';
global $myNSclient;

// create array of fields for Inventory Adjustment record
$invAdjustmentFields = array
(
  'memo' => 'Created via PHP WS',
  'account' => array ('internalId'=>'124'), //Account for the inventory adjustment
  'inventoryList' => array (
        'inventory' => array (
              'item' => array ('internalId'=> '8'), //References internalId of the item 
              'adjustQtyBy' => '32',
              'location' => array ('internalId'=>'4'),
   )
));

// create inventoryAdjustment record
$inventoryAdj = new nsComplexObject('InventoryAdjustment');

// set fields
$inventoryAdj->setFields($invAdjustmentFields);


// this will create a inventoryAdjust with 1 line item
$addResponse = $myNSclient->add($inventoryAdj);

if ($addResponse->isSuccess)
{
    echo ("Add Inventory Adjustment Successful");
}
else
{
    echo '<br><br>Add Add Inventory Adjustment NOT Successful<br><br>';
    var_dump($addResponse);
}

No comments:

Post a Comment