helper.class.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. class HelperRollerStorage
  3. {
  4. public $db;
  5. public $table_element = 'inventory';
  6. public function __construct(DoliDB $db)
  7. {
  8. $this->db = $db;
  9. }
  10. function getEntities()
  11. {
  12. $entitiesArray = [];
  13. $sql = "SELECT rowid, label FROM " . MAIN_DB_PREFIX . "entity";
  14. $data = $this->db->query($sql);
  15. $dataArray = pg_fetch_all($data);
  16. if (empty($dataArray)) {
  17. dol_syslog("No data found.", LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERR);
  18. return $entitiesArray;
  19. }
  20. foreach ($dataArray as $row) {
  21. $entitiesArray[$row['rowid']] = $row['label'];
  22. }
  23. return $entitiesArray;
  24. }
  25. function getWarehouses()
  26. {
  27. $warehousesObj = [];
  28. $warehouses = new Entrepot($this->db);
  29. $sql = "SELECT rowid, ref FROM " . $this->db->prefix() . $warehouses->table_element . " ORDER BY rowid ASC";
  30. $myWarehousesObj = $this->db->query($sql);
  31. while ($warehouse = pg_fetch_assoc($myWarehousesObj)) {
  32. $warehousesObj[] = $warehouse;
  33. }
  34. return $warehousesObj;
  35. }
  36. function getWarehouseData($inventory_id)
  37. {
  38. $warehouses = new Entrepot($this->db);
  39. $sql = "SELECT rowid, ref, lieu, address, zip, town FROM " . $this->db->prefix() . $warehouses->table_element . " WHERE rowid = " . $inventory_id;
  40. $myWarehousesObj = $this->db->query($sql);
  41. while ($warehouse = pg_fetch_assoc($myWarehousesObj)) {
  42. return $warehouse;
  43. }
  44. }
  45. function getWarehouseStatusAndInventoryData($inventory_id)
  46. {
  47. $data = [];
  48. $sql = "select s.status_id, s.ref, e.ref AS warehouse, count(i.rowid) as numberofstatuses
  49. FROM " . MAIN_DB_PREFIX . "inventory AS i
  50. INNER JOIN " . MAIN_DB_PREFIX . "entrepot AS e ON e.rowid = i.fk_warehouse
  51. INNER JOIN " . MAIN_DB_PREFIX . "rollerstorage_statuses as s ON i.status = s.status_id
  52. WHERE i.fk_warehouse = {$inventory_id}
  53. group by e.rowid, i.status, s.ref, s.status_id
  54. ORDER BY e.ref";
  55. $res = $this->db->query($sql);
  56. while ($result = pg_fetch_assoc($res)) {
  57. $data[] = $result;
  58. }
  59. return $data;
  60. }
  61. function getLibStatus($object)
  62. {
  63. global $stasusesObj;
  64. global $db;
  65. global $langs;
  66. $allapotok = $stasusesObj->getStatusIds($db);
  67. return '<span class="badge badge-status' . $object->status . ' badge-status" title="' . $langs->trans($allapotok[$object->status]) . '">' . $langs->trans($allapotok[$object->status]) . '</span>';
  68. }
  69. function getAssignabelDevices($inventory_id)
  70. {
  71. $devices = [];
  72. $sql = "SELECT i.rowid, i.ref FROM " . MAIN_DB_PREFIX . "inventory AS i
  73. INNER JOIN " . MAIN_DB_PREFIX . "inventory_extrafields as ie ON ie.fk_object = i.rowid
  74. WHERE fk_warehouse = {$inventory_id} AND ie.device_type in ('1', '2') ORDER BY i.ref";
  75. $res = $this->db->query($sql);
  76. $result = pg_fetch_all($res);
  77. if (empty($result)) {
  78. dol_syslog("No data found.", LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERR);
  79. return $devices;
  80. }
  81. foreach ($result as $device) {
  82. $devices[$device['rowid']] = $device['ref'];
  83. }
  84. return $devices;
  85. }
  86. /**
  87. * Output the buttons to submit a creation/edit form
  88. *
  89. * @param string $save_label Alternative label for save button
  90. * @param string $cancel_label Alternative label for cancel button
  91. * @param array $morebuttons Add additional buttons between save and cancel
  92. * @param bool $withoutdiv Option to remove enclosing centered div
  93. * @param string $morecss More CSS
  94. * @param string $dol_openinpopup If the button are shown in a context of a page shown inside a popup, we put here the string name of popup.
  95. * @return string Html code with the buttons
  96. */
  97. public function buttonsSaveCancel($save_label = 'Save', $cancel_label = 'Cancel', $cancelURL = '', $morebuttons = array(), $withoutdiv = 0, $morecss = '', $dol_openinpopup = '')
  98. {
  99. global $langs;
  100. $buttons = array();
  101. $save = array(
  102. 'name' => 'save',
  103. 'label_key' => $save_label,
  104. );
  105. if ($save_label == 'Create' || $save_label == 'Add') {
  106. $save['name'] = 'add';
  107. } elseif ($save_label == 'Modify') {
  108. $save['name'] = 'edit';
  109. }
  110. $cancel = array(
  111. 'name' => 'cancel',
  112. 'label_key' => 'Cancel',
  113. );
  114. !empty($save_label) ? $buttons[] = $save : '';
  115. if (!empty($morebuttons)) {
  116. $buttons[] = $morebuttons;
  117. }
  118. //!empty($cancel_label) ? $buttons[] = $cancel : '';
  119. $retstring = $withoutdiv ? '' : '<div class="center">';
  120. foreach ($buttons as $button) {
  121. $addclass = empty($button['addclass']) ? '' : $button['addclass'];
  122. $retstring .= '<input type="submit" class="button button-' . $button['name'] . ($morecss ? ' ' . $morecss : '') . ' ' . $addclass . '" name="' . $button['name'] . '" value="' . dol_escape_htmltag($langs->trans($button['label_key'])) . '">';
  123. }
  124. if ($cancel_label == "Cancel") {
  125. $retstring .= '<a class="button button-' . $cancel['name'] . '" href="' . dol_buildpath($cancelURL, 1) . /*'?restore_lastsearch_values=1' .*/ (!empty($socid) ? '&socid=' . $socid : '') . '">' . $langs->trans($cancel['label_key']) . '</a>';
  126. }
  127. $retstring .= $withoutdiv ? '' : '</div>';
  128. if ($dol_openinpopup) {
  129. $retstring .= '<!-- buttons are shown into a $dol_openinpopup=' . $dol_openinpopup . ' context, so we enable the close of dialog on cancel -->' . "\n";
  130. $retstring .= '<script>';
  131. $retstring .= 'jQuery(".button-cancel").click(function(e) {
  132. e.preventDefault(); console.log(\'We click on cancel in iframe popup ' . $dol_openinpopup . '\');
  133. window.parent.jQuery(\'#idfordialog' . $dol_openinpopup . '\').dialog(\'close\');
  134. });';
  135. $retstring .= '</script>';
  136. }
  137. return $retstring;
  138. }
  139. }