Skip to content

Commit 657127d

Browse files
authored
Merge pull request #167 from wotta/master
Added pause and resume workflow for invoices.
2 parents 9b8a3f8 + c896b0f commit 657127d

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

src/Picqer/Financials/Moneybird/Entities/SalesInvoice.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,4 +231,48 @@ public function addAttachment($filename, $contents)
231231

232232
return $this;
233233
}
234+
235+
/**
236+
* Pauses the sales invoice. The automatic workflow steps will not be executed while the sales invoice is paused.
237+
*
238+
* @return bool
239+
*
240+
* @throws \Picqer\Financials\Moneybird\Exceptions\ApiException
241+
*/
242+
public function pauseWorkflow()
243+
{
244+
try {
245+
$this->connection()->post($this->endpoint . '/' . $this->id . '/pause', json_encode([]));
246+
} catch (ApiException $exception) {
247+
if (strpos($exception->getMessage(), "The sales_invoice is already paused") !== false) {
248+
return true; // Everything is fine since the sales invoice was already paused we don't need an error.
249+
}
250+
251+
throw $exception;
252+
}
253+
254+
return true;
255+
}
256+
257+
/**
258+
* Resumes the sales invoice. The automatic workflow steps will execute again after resuming.
259+
*
260+
* @return bool
261+
*
262+
* @throws \Picqer\Financials\Moneybird\Exceptions\ApiException
263+
*/
264+
public function resumeWorkflow()
265+
{
266+
try {
267+
$this->connection()->post($this->endpoint . '/' . $this->id . '/resume', json_encode([]));
268+
} catch (ApiException $exception) {
269+
if (strpos($exception->getMessage(), "The sales_invoice isn't paused") !== false) {
270+
return true; // Everything is fine since the sales invoice wasn't paused we don't need an error.
271+
}
272+
273+
throw $exception;
274+
}
275+
276+
return true;
277+
}
234278
}

0 commit comments

Comments
 (0)