Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix credit note allocation error #911

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions src/XeroPHP/Models/Accounting/CreditNote.php
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,12 @@ public function setRemainingCredit($value)
*/
public function getAllocations()
{
return $this->_data['Allocations'];
return new Remote\Collection(
array_merge(
isset($this->_data['Allocations']) ? $this->_data['Allocations']->getArrayCopy(): [],
isset($this->_data['New_Allocations']) ? $this->_data['New_Allocations']->getArrayCopy(): []
)
);
}

/**
Expand All @@ -647,11 +652,10 @@ public function getAllocations()
public function addAllocation(Allocation $value)
{
$this->propertyUpdated('Allocations', $value);
if (! isset($this->_data['Allocations'])) {
$this->_data['Allocations'] = new Remote\Collection();
if (!isset($this->_data['New_Allocations'])) {
$this->_data['New_Allocations'] = new Remote\Collection();
}
$this->_data['Allocations'][] = $value;

$this->_data['New_Allocations'][] = $value;
return $this;
}

Expand Down Expand Up @@ -700,4 +704,26 @@ public function getHasAttachments()
public function setHasAttachment($value)
{
}

/**
* save credit note to override sending the old allocations
*
* @return void
*/
public function save() {
if (isset($this->_data['New_Allocations'])) {
$this->_data['Old_Allocations'] = $this->_data['Allocations'];
$this->_data['Allocations'] = $this->_data['New_Allocations'];
unset($this->_data['New_Allocations']);
$return_value = parent::save();
$this->_data['Allocations'] = new Remote\Collection(
array_merge(
$this->_data['Allocations']->getArrayCopy(),
isset($this->_data['Old_Allocations']) ? $this->_data['Old_Allocations']->getArrayCopy(): []
)
);
return $return_value;
}
return parent::save();
}
}