picqer / moneybird-php-client

PHP Client for Moneybird V2
MIT License
82 stars 77 forks source link

Estimate Rules #27

Closed striderxfossility closed 8 years ago

striderxfossility commented 8 years ago

Can you help me how to add rules ("Description")

Here is my code: $estimate = $moneybird->estimate(); $estimate->contact_id = $contact_id; $estimate->contact = $contact; <- This was by the way the error from previous issiue $estimate->workflow_id = $workflow_id; $estimate->document_style_id = $document_style_id;

$details = $moneybird->SalesInvoiceDetail();
$details->tax_rate_id = "134151041448937070";
$details->ledger_account_id = "134151041263339116";
$details->amount = "90.88 m2";
$details->description = "test";
$details->price = "36.75";
$details->row_order = 0;

And i would like to add another detail.

$estimate->details = $details;

$estimate->save();
GertJanFrl commented 8 years ago

I have a similar issue, with adding the details (products) to a invoice, tried creating an normal array and sending that and with the same technique as above..

No luck..

striderxfossility commented 8 years ago

I have tried a few times but cant get it to work, otherwise i give you the solution. :(

I hope stephangroen comes online to fix this :+1:

stephangroen commented 8 years ago

You should create a new SalesInvoiceDetail for every line on the Sales Invoice and add these to an array. You add that array (array of SalesInvoiceDetail objects) to the Sales Invoice.

$salesInvoiceDetailsArray = [];

foreach ($invoiceLines as $invoiceLine) {
   $salesInvoiceDetail = $moneybird->SalesInvoiceDetail();
   $salesInvoiceDetail->price = 34.33;
   ...

   $salesInvoiceDetailsArray[] = $salesInvoiceDetail;
}

$salesInvoice = $moneybird->salesInvoice();
$salesInvoice->details = $salesInvoiceDetails;

Hope this solves it for you. I'll adjust the docs and maybe add a special method to add a SalesInvoiceDetail to a SalesInvoice so this is more clear.

GertJanFrl commented 8 years ago

Thanks!! That was indeed what I needed to use, it's fixed now! Thanks for the support.

striderxfossility commented 8 years ago

It was fixed for me too! Thanks!

stephangroen commented 8 years ago

Thanks! I have updated the README with this code.