intuit / QuickBooks-V3-PHP-SDK

Official PHP SDK for QuickBooks REST API v3.0: https://developer.intuit.com/
Apache License 2.0
246 stars 246 forks source link

EntityRef not getting updated in the ui for Journal Entry #510

Open hyphen81 opened 8 months ago

hyphen81 commented 8 months ago

Having some difficulty getting the Journal Entry to attach an EntityRef to the line item. I've tried manually creating the EntityRef array and passing it to the Line::create method. I've also tried creating the IPPEntityRef object beforehand and adding that to the line.

I can't seem to get it to work.

 $entityTypeEnum = new IPPEntityTypeEnum(['value' => 'Customer']);

        $entityRef = new IPPReferenceType(['name' => $this->entityRef[0]->DisplayName, 'value' => $this->entityRef[0]->Id]);

        Log::debug(collect($entityRef)->toArray());

        $this->linesArray[] = Line::create([
            'JournalEntryLineDetail' => [
                'PostingType' => $postingType,
                'AccountRef' => [
                    'value' => $accountRef['Id'],
                    'name' => $accountRef['Name']
                ],
                //neither of these work.
                // 'Entity' => $this->entityRef, //getting this value by selecting the customer in a query earlier in this class.
                'Entity' => [
                    'Type' => $entityTypeEnum,
                    'EntityRef' => $entityRef,
                ],
            ],
            'DetailType' => 'JournalEntryLineDetail',
            'Amount' => $amount / 100,
            'Description' => $description
        ]);

        Log::debug($this->linesArray);

I've also tried this to create the EntityRef beforehand based on what I'm seeing in the source code. When I do this I don't get an error, but it still doesn't work.

 $refType = new IPPReferenceType(['name' => $this->entityRef[0]->DisplayName, 'value' => $this->entityRef[0]->Id]);

        $entityRef = new IPPEntityTypeRef(['Type' => 'Customer', 'EntityRef' => $refType]);

  $line = Line::create([
            'JournalEntryLineDetail' => [
                'PostingType' => $postingType,
                'AccountRef' => [
                    'value' => $accountRef['Id'],
                    'name' => $accountRef['Name']
                ],
            ],
            'DetailType' => 'JournalEntryLineDetail',
            'Amount' => $amount / 100,
            'Description' => $description
        ]);
        $line->Entity = $entityRef;

The above seems to come the closest to matching the object structure detailed in the QBO API docs for the journal entry, and it's not erroring out, just not understanding why it's also not populating the "Name" field when I view the Journal Entry.

I've also tried adding the Name field manually to a Journal Entry in the UI, then pulling it from the API and looking at how it's stored. It's coming back like this:

 \QuickBooksOnline\API\Data\IPPEntityTypeRef::__set_state(array(
             'Type' => 'Customer',
             'EntityRef' => '58',
          )),

I then tried to mimic that structure. Again, it didn't fail, but didn't update the Name field.

Has anyone successfully created a Journal Entry with the "Name" field filled in using this EntityRef parameter? Can someone explain what I'm missing here? I've been beating my head against the wall on this for too long.

Twin245 commented 1 week ago

Hi! Did you solve this? I have the same problem.