Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

DolibarrApi.php 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace common\components;
  3. class DolibarrApi extends AbstractApi
  4. {
  5. const RESOURCE_INVOICES = 'invoices';
  6. const RESOURCE_PRODUCTS = 'products';
  7. const RESOURCE_DOCUMENTS = 'documents';
  8. public function getInvoicesByThirParty(int $idThirdParty)
  9. {
  10. return $this->get(self::RESOURCE_INVOICES, [
  11. 'sortfield' => 't.rowid',
  12. 'sortorder' => 'DESC',
  13. 'thirdparty_ids' => $idThirdParty,
  14. 'limit' => 24
  15. ]);
  16. }
  17. public function getInvoice(int $idInvoice)
  18. {
  19. return $this->get(self::RESOURCE_INVOICES.'/'.$idInvoice, [
  20. 'contact_list' => 1
  21. ]);
  22. }
  23. public function downloadInvoice(string $idInvoice)
  24. {
  25. $invoice = $this->getInvoice($idInvoice);
  26. if($invoice && isset($invoice['last_main_doc'])) {
  27. $originalFilename = str_replace('facture/', '', $invoice['last_main_doc']);
  28. return $this->get(self::RESOURCE_DOCUMENTS.'/download', [
  29. 'modulepart' => 'facture',
  30. 'original_file' => $originalFilename
  31. ]);
  32. }
  33. return null;
  34. }
  35. public function createInvoice(int $idUser)
  36. {
  37. return $this->post(self::RESOURCE_INVOICES, [
  38. 'socid' => $idUser,
  39. 'cond_reglement_id' => 2
  40. ]);
  41. }
  42. public function addInvoiceLine(int $idInvoice, int $idProduct)
  43. {
  44. $productArray = $this->getProduct($idProduct);
  45. return $this->post(self::RESOURCE_INVOICES . '/' . $idInvoice . '/lines', [
  46. 'fk_product' => $idProduct,
  47. 'subprice' => $productArray['price'],
  48. 'qty' => 1,
  49. 'desc' => $productArray['description']
  50. ]);
  51. }
  52. public function validateInvoice(int $idInvoice)
  53. {
  54. return $this->post(self::RESOURCE_INVOICES . '/' . $idInvoice . '/validate', [], false);
  55. }
  56. public function generateInvoicePdf(string $reference)
  57. {
  58. return $this->put(self::RESOURCE_DOCUMENTS . '/builddoc', [
  59. 'modulepart' => 'invoice',
  60. 'doctemplate' => 'crabe',
  61. 'langcode' => 'fr_FR',
  62. 'original_file' => $reference.'/'.$reference.'.pdf'
  63. ]);
  64. }
  65. public function getProduct(int $idProduct)
  66. {
  67. return $this->get(self::RESOURCE_PRODUCTS . '/' . $idProduct);
  68. }
  69. }