|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <?php
-
- namespace common\components;
-
- use Psr\Http\Message\ResponseInterface;
-
- class DolibarrApi extends AbstractApi
- {
- const RESOURCE_INVOICES = 'invoices';
- const RESOURCE_PRODUCTS = 'products';
- const RESOURCE_DOCUMENTS = 'documents';
-
- public function createInvoice(int $idUser)
- {
- return $this->post(self::RESOURCE_INVOICES, [
- 'socid' => $idUser
- ]);
- }
-
- public function addInvoiceLine(int $idInvoice, int $idProduct)
- {
- $productArray = $this->getProduct($idProduct);
-
- return $this->post(self::RESOURCE_INVOICES . '/' . $idInvoice . '/lines', [
- 'fk_product' => $idProduct,
- 'subprice' => $productArray['price'],
- 'qty' => 1,
- 'desc' => $productArray['description']
- ]);
- }
-
- public function validateInvoice(int $idInvoice)
- {
- return $this->post(self::RESOURCE_INVOICES . '/' . $idInvoice . '/validate', [], false);
- }
-
- public function generateInvoicePdf(string $reference)
- {
- return $this->put(self::RESOURCE_DOCUMENTS . '/builddoc', [
- 'modulepart' => 'invoice',
- 'doctemplate' => 'crabe',
- 'langcode' => 'fr_FR',
- 'original_file' => $reference.'/'.$reference.'.pdf'
- ]);
- }
-
- public function getProduct(int $idProduct)
- {
- return $this->get(self::RESOURCE_PRODUCTS . '/' . $idProduct);
- }
- }
|