You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.4KB

  1. <?php
  2. namespace common\components;
  3. use Psr\Http\Message\ResponseInterface;
  4. class DolibarrApi extends AbstractApi
  5. {
  6. const RESOURCE_INVOICES = 'invoices';
  7. const RESOURCE_PRODUCTS = 'products';
  8. const RESOURCE_DOCUMENTS = 'documents';
  9. public function createInvoice(int $idUser)
  10. {
  11. return $this->post(self::RESOURCE_INVOICES, [
  12. 'socid' => $idUser
  13. ]);
  14. }
  15. public function addInvoiceLine(int $idInvoice, int $idProduct)
  16. {
  17. $productArray = $this->getProduct($idProduct);
  18. return $this->post(self::RESOURCE_INVOICES . '/' . $idInvoice . '/lines', [
  19. 'fk_product' => $idProduct,
  20. 'subprice' => $productArray['price'],
  21. 'qty' => 1,
  22. 'desc' => $productArray['description']
  23. ]);
  24. }
  25. public function validateInvoice(int $idInvoice)
  26. {
  27. return $this->post(self::RESOURCE_INVOICES . '/' . $idInvoice . '/validate', [], false);
  28. }
  29. public function generateInvoicePdf(string $reference)
  30. {
  31. return $this->put(self::RESOURCE_DOCUMENTS . '/builddoc', [
  32. 'modulepart' => 'invoice',
  33. 'doctemplate' => 'crabe',
  34. 'langcode' => 'fr_FR',
  35. 'original_file' => $reference.'/'.$reference.'.pdf'
  36. ]);
  37. }
  38. public function getProduct(int $idProduct)
  39. {
  40. return $this->get(self::RESOURCE_PRODUCTS . '/' . $idProduct);
  41. }
  42. }