您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

51 行
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. }