sellproduct.class.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  3. class SellProduct
  4. {
  5. private $user;
  6. private $db;
  7. public function __construct()
  8. {
  9. global $db, $user;
  10. $this->db = $db;
  11. $this->user = $user;
  12. }
  13. /**
  14. *
  15. */
  16. public function getProductByBarcode(string $barcode): ?Product
  17. {
  18. $result = null;
  19. $product = new Product($this->db);
  20. if ($product->fetch('', '', '', $barcode, 0, 0, 1) > 0) {
  21. $result = $product;
  22. }
  23. return $result;
  24. }
  25. /**
  26. *
  27. */
  28. public function getProductLot(int $productId, string $batchNumber): ?Productlot
  29. {
  30. $result = null;
  31. $productLot = new Productlot($this->db);
  32. if ($productLot->fetch(0, $productId, $batchNumber) > 0) {
  33. $result = $productLot;
  34. }
  35. return $result;
  36. }
  37. /**
  38. *
  39. */
  40. public function sellProductLot(Productlot $productLot): void
  41. {
  42. $productLot->array_options['options_usedat'] = time();
  43. $productLot->update($this->user);
  44. }
  45. }