I am trying to create ItemReceipt which is created from PurchaseOrder. I am adding my inventory items manually in purchase order during its creation. When I am receiving this order NetSuite web service is throwing following error:
Adding new line to sublist item is not allowed.
while i have tried replaceAll attribute for ItemReceiptItemList as well.
Here is my code:
$tranDate = new \DateTime();
$tranDate = $tranDate->format('Y-m-d\TH:i:s');
$nsInventoryDetail = new InventoryDetail();
$nsInventoryAssignmentList = new InventoryAssignmentList();
$nsInventoryAssignmentList->replaceAll = true;
$nsInventoryAssignment[0] = new InventoryAssignment();
$nsInventoryAssignment[0]->receiptInventoryNumber = 3310; //NS inventory item id
$nsInventoryAssignment[0]->quantity = 1;
$nsInventoryAssignmentList->inventoryAssignment = $nsInventoryAssignment;
$nsInventoryDetail->inventoryAssignmentList = $nsInventoryAssignmentList;
$nsItemReceiptItem = new ItemReceiptItem();
$nsItemReceiptItem->item = new RecordRef();
$nsItemReceiptItem->item->internalId = 3310;
$nsItemReceiptItem->location = new RecordRef();
$nsItemReceiptItem->location->internalId = 1; // NS inventory location id
$nsItemReceiptItem->itemReceive = true;
$nsItemReceiptItem->rate = $purchasePrice->getAmount();
$nsItemReceiptItem->currency = $purchasePrice->getCurrency();
$nsItemReceiptItem->inventoryDetail = $nsInventoryDetail;
$itemList = new ItemReceiptItemList();
$itemList->item = [$nsItemReceiptItem];
$itemList->replaceAll = true;
$nsItemReceipt = new ItemReceipt();
$nsItemReceipt->createdFrom = new RecordRef();
$nsItemReceipt->createdFrom->internalId = 1223; // NS purchase order id
$nsItemReceipt->tranDate = $tranDate;
$nsItemReceipt->itemList = $itemList;
print_r($nsItemReceipt);
$nsItemReceipt = $this->itemReceiptService->create($nsItemReceipt);
Throws the following: Adding new line to sublist item is not allowed.
Following is my ItemReceipt object being sent:
NetSuite\Sdk\ItemReceipt Object
(
[createdDate] =>
[lastModifiedDate] =>
[customForm] =>
[exchangeRate] =>
[entity] =>
[currencyName] =>
[subsidiary] =>
[createdFrom] => NetSuite\Sdk\RecordRef Object
(
[internalId] => 1223
[externalId] =>
[type] => purchaseOrder
[name] =>
)
[tranDate] => 2020-01-02T13:45:36
[partner] =>
[postingPeriod] =>
[tranId] =>
[inboundShipment] =>
[memo] =>
[itemFulfillment] =>
[currency] =>
[landedCostMethod] =>
[landedCostPerLine] =>
[itemList] => NetSuite\Sdk\ItemReceiptItemList Object
(
[item] => Array
(
[0] => NetSuite\Sdk\ItemReceiptItem Object
(
[itemReceive] => 1
[jobName] =>
[item] => NetSuite\Sdk\RecordRef Object
(
[internalId] => 3310
[externalId] =>
[type] => inventoryItem
[name] =>
)
[orderLine] =>
[line] =>
[itemName] =>
[description] =>
[location] => NetSuite\Sdk\RecordRef Object
(
[internalId] => 3
[externalId] =>
[type] => location
[name] =>
)
[onHand] =>
[quantityRemaining] =>
[quantity] =>
[unitsDisplay] =>
[unitCostOverride] =>
[inventoryDetail] => NetSuite\Sdk\InventoryDetail Object
(
[inventoryAssignmentList] => NetSuite\Sdk\InventoryAssignmentList Object
(
[inventoryAssignment] => Array
(
[0] => NetSuite\Sdk\InventoryAssignment Object
(
[internalId] =>
[issueInventoryNumber] =>
[receiptInventoryNumber] =>
[binNumber] =>
[toBinNumber] =>
[quantity] => 1
[expirationDate] =>
[quantityAvailable] =>
)
)
[replaceAll] => 1
)
[customForm] =>
[nullFieldList] =>
)
[serialNumbers] =>
[binNumbers] =>
[expirationDate] =>
[rate] => 7900
[currency] => AED
[restock] =>
[billVarianceStatus] =>
[isDropShipment] =>
[options] =>
[landedCost] =>
[customFieldList] =>
)
)
[replaceAll] => 1
)
[expenseList] =>
[landedCostsList] =>
[accountingBookDetailList] =>
[customFieldList] =>
[internalId] =>
[externalId] =>
[nullFieldList] =>
)
Any help will be much appreciated.
I found this working example here
https://www.reddit.com/r/Netsuite/comments/ewlen8/suitetalk_issue_creating_itemreceipt/
-soap:Body
-
-
<q1:createdFrom internalId="35023" type="purchaseOrder"/>
-<q1:itemList>
-<q1:item>
<q1:itemReceive>true</q1:itemReceive>
<q1:item internalId="1528"/>
<q1:orderLine>1</q1:orderLine>
<q1:quantity>100</q1:quantity>
</q1:item>
</q1:itemList>
</soap:Body>
All I had to do was change $item->line to $item->orderLine and that fixed the issue - looks like you need to reference the original purchase order line number
Related
This is the Array I want to loop Into Events Index and get all the context print out of it how can i do this
Here is the Array Code Which i am trying to loop
[1] => stdClass Object
(
[id] => RPDNLNYO6U
[active] =>
[events] => Array
(
[0] => stdClass Object
(
[id] => RPDNLNYO6U_1
[created_at] => 2023-02-06T10:55:42.501003Z
[visibility] => all
[text] => Hi
[author_id] => 170bdd03-a163-49e9-4295-11fae376ff0e
)
[1] => stdClass Object
(
[id] => RPDNLNYO6U_2
[created_at] => 2023-02-06T10:55:44.102000Z
[visibility] => all
[text] => I need help
[author_id] => 170bdd03-a163-49e9-4295-11fae376ff0e
)
[2] => stdClass Object
(
[id] => RPDNLNYO6U_3
[created_at] => 2023-02-06T11:06:11.002000Z
[visibility] => agents
[type] => system_message
[text] => Chat is idle due to 10 minutes of inactivity
[system_message_type] => routing.idle
[text_vars] => stdClass Object
(
[duration] => 10
)
)
[3] => stdClass Object
(
[id] => RPDNLNYO6U_4
[created_at] => 2023-02-06T11:11:14.002000Z
[visibility] => all
[type] => system_message
[text] => Chat archived due to 15 minutes of inactivity
[system_message_type] => routing.archived_inactive
[text_vars] => stdClass Object
(
[duration] => 15
)
)
)
)
You can use a foreach loop in PHP to loop through the array and get all the context you need.
$array = [1 => (object) [
'id' => 'RPDNLNYO6U',
'active' => '',
'events' => [
(object) [
'id' => 'RPDNLNYO6U_1',
'created_at' => '2023-02-06T10:55:42.501003Z',
'visibility' => 'all',
'text' => 'Hi',
'author_id' => '170bdd03-a163-49e9-4295-11fae376ff0e'
]
]
]];
foreach ($array as $object) {
$id = $object->id;
$active = $object->active;
foreach ($object->events as $event) {
$event_id = $event->id;
$created_at = $event->created_at;
$visibility = $event->visibility;
$text = $event->text;
$author_id = $event->author_id;
echo "Event ID: $event_id, Created At: $created_at, Visibility: $visibility, Text: $text, Author ID: $author_id\n";
}
}
This will loop through the outer array and print out all the context for each event.
I have an array below. What i need to do is unset one array inside "Urunler" than updating a new array. Very crucial one is how can push new array by keeping same key value which is same deleted one.
stdClass Object
(
[Urun] => Array
(
[0] => stdClass Object
(
[Id] => 1384
[Urun_kodu] => UKy74GhoD1LZ
[Urun_adi] => Bizim Ayçiçek Yağı Teneke 5 Lt
[Urun_resim] => uploads/urunler_v/UKy74GhoD1LZ/637b4-bizim-aycicek-yagi-tenekelxwbmlgpdh.jpg
[Esas_tutar] => 27.00
[Esas_tutar_kdvsiz] => 25.00
[Kdv_tutar] => 2.00
[Kdv_tutar_adetli] => 6.00
[Adetli_tutar] => 81.00
[Adetli_tutar_kdvsiz] => 75.00
[Urun_adeti] => 3
[Urun_kuru] => TRY
[Urun_ds] => 100
)
[1] => stdClass Object
(
[Id] => 4518
[Urun_kodu] => UK6FfrWzDPLE
[Urun_adi] => Besler Ton Balığı 2x160 Gr
[Urun_resim] => uploads/urunler_v/UK6FfrWzDPLE/bfeec-besler-ton-baligi-2x160-grqrgy6fl2hv.jpg
[Esas_tutar] => 10.80
[Esas_tutar_kdvsiz] => 10.00
[Kdv_tutar] => 0.80
[Kdv_tutar_adetli] => 2.40
[Adetli_tutar] => 32.40
[Adetli_tutar_kdvsiz] => 30.00
[Urun_adeti] => 3
[Urun_kuru] => TRY
[Urun_ds] => 32
)
[2] => stdClass Object
(
[Id] => 4518
[Urun_kodu] => UK6FfrWzDPLE
[Urun_adi] => Besler Ton Balığı 2x160 Gr
[Urun_resim] => uploads/urunler_v/UK6FfrWzDPLE/bfeec-besler-ton-baligi-2x160-grqrgy6fl2hv.jpg
[Esas_tutar] => 10.80
[Esas_tutar_kdvsiz] => 10.00
[Kdv_tutar] => 0.80
[Kdv_tutar_adetli] => 2.40
[Adetli_tutar] => 32.40
[Adetli_tutar_kdvsiz] => 30.00
[Urun_adeti] => 3
[Urun_kuru] => TRY
[Urun_ds] => 32
)
)
)
Below, you can see my steps when pushing new array
$Urun = $SepetBilgisi->Urun;
$MevcutUrunSayisi=count($Urun);
$YeniUrun=[];
foreach($Urun as $Key => $Value)
{
if($Value->Id== $UrunId){ // My target is $UrunId=4518 that means $Urun[Urun][1] one
unset($Urun[$Key]);
if(count($Urun)< $MevcutUrunSayisi){
//Şimdi Yeni Array Buraya Ekleyelim
$YeniUrun[$Key]=[
"Id"=> $Value->Id,
"Urun_kodu" => $Value->Urun_kodu,
"Urun_resim" => $Value->Urun_resim,
"Esas_tutar" => $Value->Esas_tutar,
"Esas_tutar_kdvsiz" => $Value->Esas_tutar_kdvsiz,
"Kdv_tutar" => $Value->Kdv_tutar,
"Kdv_tutar_adetli" => $Value->Kdv_tutar_adetli,
"Adetli_tutar" => $Value->Adetli_tutar,
"Adetli_tutar_kdvsiz" => $Value->Adetli_tutar_kdvsiz,
"Urun_adeti" => $YeniAdet,
"Urun_kuru" => $Value->Urun_kuru,
"Urun_ds" => $Value->Urun_ds
];
array_push($Urun , $YeniUrun);
}else{
return false;
}
}
}
Using 'array_push' only put new array end of main array as you know.
You want to replace the key, not push to the end of the array:
$Urun = $SepetBilgisi->Urun;
$MevcutUrunSayisi=count($Urun);
$YeniUrun=[];
foreach($Urun as $Key => $Value)
{
if($Value->Id== $UrunId){ // My target is $UrunId=4518 that means $Urun[Urun][1] one
if(count($Urun)< $MevcutUrunSayisi){
//Şimdi Yeni Array Buraya Ekleyelim
$replace=[
"Id"=> $Value->Id,
"Urun_kodu" => $Value->Urun_kodu,
"Urun_resim" => $Value->Urun_resim,
"Esas_tutar" => $Value->Esas_tutar,
"Esas_tutar_kdvsiz" => $Value->Esas_tutar_kdvsiz,
"Kdv_tutar" => $Value->Kdv_tutar,
"Kdv_tutar_adetli" => $Value->Kdv_tutar_adetli,
"Adetli_tutar" => $Value->Adetli_tutar,
"Adetli_tutar_kdvsiz" => $Value->Adetli_tutar_kdvsiz,
"Urun_adeti" => $YeniAdet,
"Urun_kuru" => $Value->Urun_kuru,
"Urun_ds" => $Value->Urun_ds
];
$Urun[$Key] = $replace;
}else{
return false;
}
}
}
This is the response when I call the login method from twinfield API. It given the session id and cluster namespace, but the problem is how to get the value from it.
$customerApiConnector = new \PhpTwinfield\ApiConnectors\CustomerApiConnector($login);
print_r($customerApiConnector);die;
Output:
PhpTwinfield\ApiConnectors\CustomerApiConnector Object
(
[service:protected] => PhpTwinfield\Services\ProcessXmlService Object
(
[trace] => 1
[compression] => 32
[_stream_context] => Resource id #153
[_soap_version] => 1
[sdl] => Resource id #154
[__default_headers] => Array
(
[0] => SoapHeader Object
(
[namespace] => http://www.twinfield.com/
[name] => Header
[data] => Array
(
[SessionID] => f7b4c213-1a01-4c7c-87cb-7de80b1583fe
)
[mustUnderstand] =>
)
)
)
)
This is the other object.
Array
(
[1] => PhpTwinfield\CustomerAddress Object
(
[ID:PhpTwinfield\CustomerAddress:private] => 1
[type:PhpTwinfield\CustomerAddress:private] => invoice
[default:PhpTwinfield\CustomerAddress:private] => true
[name:PhpTwinfield\CustomerAddress:private] => Anand
[contact:PhpTwinfield\CustomerAddress:private] =>
[country:PhpTwinfield\CustomerAddress:private] => IN
[city:PhpTwinfield\CustomerAddress:private] => Indore
[postcode:PhpTwinfield\CustomerAddress:private] => 452001
[telephone:PhpTwinfield\CustomerAddress:private] =>
[fax:PhpTwinfield\CustomerAddress:private] =>
[email:PhpTwinfield\CustomerAddress:private] => anand#comfisoft.com
[field1:PhpTwinfield\CustomerAddress:private] =>
[field2:PhpTwinfield\CustomerAddress:private] => lig
[field4:PhpTwinfield\CustomerAddress:private] =>
[field5:PhpTwinfield\CustomerAddress:private] =>
[field6:PhpTwinfield\CustomerAddress:private] =>
)
)
Try this it will work ;)
function accessProtectedProperty($obj, $prop)
{
$reflection = new \ReflectionClass($obj);
$property = $reflection->getProperty($prop);
$property->setAccessible(true);
return json_decode($property->getValue($obj));
}
Cleeng_Entity_Collection Object
(
[entityType:protected] => Cleeng_Entity_SubscriptionOffer
[items:protected] => Array
(
[0] => Cleeng_Entity_SubscriptionOffer Object
(
[id:protected] => S955494970_US
[publisherEmail:protected] => vidya+mtc#ooyala.com
[url:protected] =>
[title:protected] => Annual subscription
[description:protected] =>
[period:protected] => year
[price:protected] => 49.99
[applicableTaxRate:protected] => 0
[currency:protected] => USD
[accessToTags:protected] => Array
(
[0] => d962607d3d4c4e3c98a343c7bcb64027
)
[active:protected] => 1
[createdAt:protected] => 1473681112
[updatedAt:protected] => 1473858745
[geoRestrictionEnabled:protected] =>
[geoRestrictionType:protected] =>
[geoRestrictionCountries:protected] => Array
(
)
[pending:protected] =>
[country] => US
[socialCommissionRate] => 0
[averageRating] => 4
[contentType] =>
[freePeriods] => 0
[freeDays] => 0
[expiresAt] =>
)
)
[totalItemCount:protected] => 5
[pending:protected] =>
)
All you need to do is just convert the Collection to a Regular Array and then json_encode() the Result like so:
<?php
$entityCollection = "???"; // THIS IS THE DATA FROM Cleeng_Entity_Collection Object
$entityArray = $entityCollection->toArray();
$entityJSON = json_encode($entityArray);
I am very new to PHP World and stuck with this problem from last three days.
Array
(
[0] => stdClass Object
(
[sim_id] => 15
[Tarrif_code] => D34
[rental] => USD 345
[service_provider] => Vodafone
[incoming_calls] => 3.2 /sec
[local_outgoing] => 3.2 /sec
[international_call] => 3.2 /sec
[company_name] => Airtel
[local_text] =>
[international_text] =>
[data] => 2G
[sim_type_id] => 1
[offer_short_descrption] =>
[validity] =>
[dialing_instruction] =>
[recharge_instruction] =>
[usage_warning] =>
[country_id] => 1
[type] => Prepaid
)
)
and the result should be
Array
(
[0] => stdClass Object
(
[sim_id] => 15
[Tarrif_code] => D34
[company_name] => Airtel
[rental] => USD 345
[service_provider] => Vodafone
[country_id] => 1
[type] => Prepaid
[1] => stdClass Object
(
[international_call] => 3.2 /sec
[incoming_calls] => 3.2 /sec
[local_outgoing] => 3.2 /sec)
[local_text] =>
[international_text] =>
[data] => 2G
[sim_type_id] => 1
[offer_short_descrption] =>
[validity] =>
[dialing_instruction] =>
[recharge_instruction] =>
[usage_warning] =>
)
)
Regarding data provided in question:
$arr[0] = new stdClass;
$arr[0]->id = 1;
$arr[0]->name = 2;
$arr[0]->state = 3;
$arr[0]->land = 4;
$arr2[0] = new stdClass;
foreach($arr[0] as $k => $v)
{
if (!in_array($k, array('id', 'land')))// array of keys for first object
{
$arr2[0]->{$k} = $v;
unset($arr[0]->{$k});
}
}
var_dump($arr[0]);
echo "<br>";
var_dump($arr2[0]);
exit;