Monday, November 26, 2018

Create a Vendor Bill record with PHP via Web Services

 

The code snippet below shows how to add a Vendor Bill record using PHP. On this sample, we populate the Expense list.

 require_once 'PHPtoolkit.php';
 require_once 'login_info.php';
 
 global $myNSclient;
 //$myNSclient = new nsClient( nsHost:: live );
 
  
 # NEW VENDOR BILL
 # ===================

 // create array of Vendor Bill fields

 $vendorBillFields = array('entity'        => array('internalId'=>3929),
                    'account'       => array('internalId'=>272),
      'exchangeRate'    => 1,
                           'expenseList'   => array('expense' => array(array('account'    => array('internalId' => 637),
                                                                             'amount'     => 500,
                                                                             'taxCode'    => array('internalId'=>76),
                                                                             'isBillable' => true
                                                                             )
                                                                       )
                                                    )
                  );
 
 // create Vendor Bill record
 $myBill = new nsComplexObject('VendorBill');
 
 // set fields
 $myBill->setFields($vendorBillFields);
 
 // perform add operation and store nsWriteResponse object in $addResponse variable
 $addResponse = $myNSclient->add($myBill);
 
 // handle add response
 if (!$addResponse->isSuccess) {
  
  echo "<font color='red'><b>" . $addResponse->statusDetail[0]->message . "</b></font>";  

 } else {
  
  echo "<font color='green'><b>SUCCESS!!!</b></font>";
  
 }
}

No comments:

Post a Comment