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.

52 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. 'cond_reglement_id' => 2
  14. ]);
  15. }
  16. public function addInvoiceLine(int $idInvoice, int $idProduct)
  17. {
  18. $productArray = $this->getProduct($idProduct);
  19. return $this->post(self::RESOURCE_INVOICES . '/' . $idInvoice . '/lines', [
  20. 'fk_product' => $idProduct,
  21. 'subprice' => $productArray['price'],
  22. 'qty' => 1,
  23. 'desc' => $productArray['description']
  24. ]);
  25. }
  26. public function validateInvoice(int $idInvoice)
  27. {
  28. return $this->post(self::RESOURCE_INVOICES . '/' . $idInvoice . '/validate', [], false);
  29. }
  30. public function generateInvoicePdf(string $reference)
  31. {
  32. return $this->put(self::RESOURCE_DOCUMENTS . '/builddoc', [
  33. 'modulepart' => 'invoice',
  34. 'doctemplate' => 'crabe',
  35. 'langcode' => 'fr_FR',
  36. 'original_file' => $reference.'/'.$reference.'.pdf'
  37. ]);
  38. }
  39. public function getProduct(int $idProduct)
  40. {
  41. return $this->get(self::RESOURCE_PRODUCTS . '/' . $idProduct);
  42. }
  43. }