Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

82 lines
2.3KB

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