QuickBooks-V3-PHP-SDK icon indicating copy to clipboard operation
QuickBooks-V3-PHP-SDK copied to clipboard

EntityRef not getting updated in the ui for Journal Entry

Open hyphen81 opened this issue 3 months ago • 0 comments

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.

hyphen81 avatar Mar 27 '24 13:03 hyphen81