You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As I have spend some time to figure this out I want to share this with the rest of the world;
In my app I create SalesInvoices for a service provided. If a new service is provided on the same day I only want to apply the travel expense once on the SalesInvoice (at the last row of the SalesInvoice).
To accompolish this I created a new $salesInvoiceDetailsArray[] with
Old SalesInvoiceDetail that need to be removed $detail->_destroy = true
New lines
Thereafter I add it to $salesInvoice->details.
Perhaps it would be an idea to highlight the _destroy attribute in the docs?
private function updateSalesInvoice(SalesInvoice $salesInvoice, $newSalesInvoiceDetails)
{
$newPeriod = $newSalesInvoiceDetails[0]->period;
$salesInvoiceDetailsArray = [];
/**
* Check old invoice and set _destroy true for lines that match same period and are travel expenses.
*/
foreach ($salesInvoice->details as $detail) {
if (($detail->period == $newPeriod) and ($detail->product_id == XXXX)) {
$detail->_destroy = true;
$salesInvoiceDetailsArray[] = $detail;
}
}
/**
* Add the new lines
*/
foreach ($newSalesInvoiceDetails as $newSalesInvoiceDetail) {
$salesInvoiceDetailsArray[] = $newSalesInvoiceDetail;
}
$salesInvoice->details = $salesInvoiceDetailsArray;
$salesInvoice->save();
}
The text was updated successfully, but these errors were encountered:
As I have spend some time to figure this out I want to share this with the rest of the world;
In my app I create SalesInvoices for a service provided. If a new service is provided on the same day I only want to apply the travel expense once on the SalesInvoice (at the last row of the SalesInvoice).
To accompolish this I created a new
$salesInvoiceDetailsArray[]
with$detail->_destroy = true
Thereafter I add it to
$salesInvoice->details
.Perhaps it would be an idea to highlight the _destroy attribute in the docs?
The text was updated successfully, but these errors were encountered: