/**
  *
  * @return void
  */
 protected function _validate()
 {
     foreach ($this->_addressBookArray as $iKey => $aAddress) {
         if (!isset($aAddress['isresidential'])) {
             $aAddress['isresidential'] = $this->_isResidential;
         }
         $oAddress = Netsuite_Record::factory()->address($aAddress, $iKey);
         if (!$oAddress->isOk()) {
             $this->logError('Address Book Entry ' . ucfirst($iKey) . ' Has Errors: ' . implode(', ', $oAddress->getErrors()));
             continue;
         } else {
             $this->_addressBookEntries[$iKey] = $oAddress->getAddress();
         }
         if ($oAddress->hasWarnings()) {
             $this->logWarn('Address Book Entry ' . ucfirst($iKey) . ' Has Warnings: ' . implode(', ', $oAddress->getWarnings()));
         }
     }
 }
 protected function _createCustomer()
 {
     $customer = Netsuite_Record::factory()->customer($this->_order['customer']);
     if (!$customer->isOk()) {
         $aJsonReturn['success'] = false;
         $aJsonReturn['error'] = implode(',', $customer->getErrors());
         $aJsonReturn['warn'] = $customer->hasWarnings() ? $customer->getWarnings() : null;
         $this->worker->addData(array('customer' => $aJsonReturn));
         return;
     }
     switch (true) {
         case $customer->custentity_customer_source_id == 'bongo':
             $results = $this->_process('bongocontact', $customer);
             if ($results['success'] === true) {
                 //$customer->entityid = $results['netsuite']['record_id'];
                 $results['message'] = 'Added Contact to Bongo with Id: ' . $customer->entityid;
                 $results['json'] = json_encode($this->_order['customer']);
             }
             // $this->worker->addData( $results );
             break;
         case empty($customer->entityid):
             $results = $this->_process('customer', $customer);
             if ($results['success'] === true) {
                 $model = new Netsuite_Db_Model();
                 $activa = new Netsuite_Db_Activa();
                 $customer->entityid = $results['netsuite']['record_id'];
                 $model->insertCustomer($customer->custentity_customer_source_id, $customer->entityid);
                 $activa->updateCustomer($customer->custentity_customer_source_id, $customer->entityid);
                 $activa = $model = null;
             }
             // $this->worker->addData( $results );
             break;
         default:
             $results['netsuite']['record_id'] = $customer->entityid;
             $results['success'] = true;
             $results['json'] = 'Using Existing Netsuite Id: ' . $customer->entityid;
             //$this->worker->addData( $results );
             break;
     }
     $this->worker->addData(array('customer' => $results));
     // updateAddressBook( $customer );  add this functionality
     $mReturn = $results['success'] !== false ? $customer : false;
     return $mReturn;
 }
 /**
  *
  * @param int $iLocationId -- Order Location InternalId
  * @param string $sItemLocation -- corporate or store
  * @return void
  */
 private function _validate($iLocationId)
 {
     foreach ($this->_itemListArray as $iKey => $aItem) {
         $oItem = Netsuite_Record::factory()->item($aItem, $iLocationId, $this->_activa_id);
         if (!$oItem->isOk()) {
             $this->logError('Item List Entry ' . ($iKey + 1) . ' Has Errors: ' . implode(', ', $oItem->getErrors()));
             continue;
         } else {
             $this->_itemListEntries[] = $oItem->getItem();
             // Check For Discount
             if ($oItem->hasDiscount() && !in_array($oItem->item, $this->_discountExceptions)) {
                 $this->_itemListEntries[] = $oItem->getDiscountItem($oItem->discountitem, $this->_ismultishipto);
             }
         }
         if ($oItem->hasWarnings()) {
             $this->logWarn('Item List Entry ' . ($iKey + 1) . ' Has Warnings: ' . implode(', ', $oItem->getWarnings()));
         }
     }
 }
 public function setGiftCertificates()
 {
     $aCerts = array();
     if (sizeof($this->giftcertificateitem) < 1) {
         return $aCerts;
     }
     foreach ($this->giftcertificateitem as $aCert) {
         $oCert = Netsuite_Record::factory()->giftCertificate($aCert);
         if (!$oCert->isOk()) {
             $aErrors = $oCert->getErrors();
             $this->logError('Could NOT Create Gift Certificate( ' . sizeof($aErrors) . ' Errors): ' . implode(', ', $aErrors));
             return;
         }
         $aCerts['codes'][] = $oCert;
     }
     $aCerts['applied'] = $this->_gcamount;
     $this->giftcertificateitem = $aCerts;
 }
 public function getDiscountItem($sDiscountType = NETSUITE_DEFAULT_DISCOUNT, $ismultishipto)
 {
     $oModel = new Netsuite_Db_Model();
     $aDiscountItem = array('item' => $sDiscountType, 'rate' => $this->discounttotal, 'quantity' => 1, 'istaxable' => true, 'price' => -1);
     if ($ismultishipto) {
         $aAddress = array('attention' => $this->attention, 'addressee' => $this->addressee, 'addr1' => $this->addr1, 'addr2' => $this->addr2, 'addr3' => $this->addr3, 'city' => $this->city, 'state' => $this->state, 'zip' => $this->zip, 'country' => $this->country, 'phone' => $this->phone);
         $aDiscountItem = array_merge($aDiscountItem, $aAddress);
     }
     $oDiscountItem = Netsuite_Record::factory()->discountitem($aDiscountItem, $this->_locationId, $this->_activa_id);
     return $oDiscountItem->_filter->optimizeValues($oDiscountItem->_filter->getRecord());
 }