daily_closing.class.php.bak 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. <?php
  2. class DailyClosing
  3. {
  4. public function getChecked($deviceArray, $device)
  5. {
  6. return $this->isChecked($deviceArray, $device) ? 'checked' : '';
  7. }
  8. public function getDeviceWHChk($deviceArray, $device)
  9. {
  10. return $this->isChecked($deviceArray, $device) ? 'display:none' : 'display:inline-block';
  11. }
  12. public function getDeviceAmount($amountArray, $device)
  13. {
  14. return $this->isValidAmountArray($amountArray, $device) ? $amountArray['d' . $device['device_id'] . '_amount'] : '';
  15. }
  16. private function isChecked($deviceArray, $device)
  17. {
  18. return isset($deviceArray) && $deviceArray['d' . $device['device_id']] != 'x';
  19. }
  20. private function isValidAmountArray($amountArray, $device)
  21. {
  22. return isset($amountArray) && $amountArray['d' . $device['device_id'] . '_amount'] != '';
  23. }
  24. private function isCheckedForDailyIncomeHUF($deviceArray)
  25. {
  26. return isset($deviceArray) && $deviceArray['_daily_HUF'] != 'x';
  27. }
  28. private function isCheckedForDailyIncomeEUR($deviceArray)
  29. {
  30. return isset($deviceArray) && $deviceArray['_daily_EUR'] != 'x';
  31. }
  32. public function getCheckedDailyIncomeHUF($deviceArray)
  33. {
  34. return $this->isCheckedForDailyIncomeHUF($deviceArray) ? 'checked' : '';
  35. }
  36. public function getDailyAmountHUFChk($deviceArray)
  37. {
  38. return $this->isCheckedForDailyIncomeHUF($deviceArray) ? 'display:none' : 'display:inline-block';
  39. }
  40. public function getCheckedDailyIncomeEUR($deviceArray)
  41. {
  42. return $this->isCheckedForDailyIncomeEUR($deviceArray) ? 'checked' : '';
  43. }
  44. public function getDailyAmountEURChk($deviceArray)
  45. {
  46. return $this->isCheckedForDailyIncomeEUR($deviceArray) ? 'display:none' : 'display:inline-block';
  47. }
  48. public function getJSONArray($array)
  49. {
  50. $jsonArray = [];
  51. foreach ($_REQUEST['withholding'] as $whgroup) {
  52. foreach ($whgroup as $dkey => $dvalue) {
  53. if (stripos($dkey, '_amount') == false) {
  54. $OK = $dvalue == '1' ? 'OK' : '';
  55. $jsonArray[$dkey] = $OK;
  56. } else {
  57. $value = $dvalue != '' ? $dvalue : '';
  58. $jsonArray[$dkey] = $value;
  59. }
  60. }
  61. }
  62. return $jsonArray;
  63. }
  64. public function getDeviceArray($PackageHistoryClosed)
  65. {
  66. $deviceArray = [];
  67. $dataArray = json_decode($PackageHistoryClosed->note_public);
  68. foreach ($dataArray as $key => $value) {
  69. if (strpos($key, '_amount') == false) {
  70. $deviceArray[$key] = $value == 'OK' ? 1 : 'x';
  71. }
  72. }
  73. return $deviceArray;
  74. }
  75. public function getAmountArray($PackageHistoryClosed)
  76. {
  77. $amountArray = [];
  78. $dataArray = json_decode($PackageHistoryClosed->note_public);
  79. foreach ($dataArray as $key => $value) {
  80. if (strpos($key, '_amount') == true) {
  81. $amountArray[$key] = $value != '' ? $value : '';
  82. }
  83. }
  84. return $amountArray;
  85. }
  86. public function getHeader($object, $user_id, $idmenu)
  87. {
  88. global $db, $langs, $conf;
  89. $langs->load("settlements@settlements");
  90. $h = 0;
  91. $head = array();
  92. $head[$h][0] = dol_buildpath("/settlements/dailyclosing_card.php", 1) . '?user_id=' . $user_id . '&idmenu=' . $idmenu . '&mainmenu=settlements&leftmenu=';
  93. $head[$h][1] = $langs->trans("DailyClosing");
  94. $head[$h][2] = 'card';
  95. $h++;
  96. $head[$h][0] = dol_buildpath("/settlements/dailyclosing_list.php", 1) . '?user_id=' . $user_id . '&idmenu=' . $idmenu . '&mainmenu=settlements&leftmenu=';
  97. $head[$h][1] = $langs->trans("DailyClosingHistory");
  98. $head[$h][2] = 'list';
  99. $h++;
  100. complete_head_from_modules($conf, $langs, $object, $head, $h, 'group@settlements');
  101. return $head;
  102. }
  103. public function getAllHistoryRecords($sql)
  104. {
  105. global $db;
  106. $historyRecords = [];
  107. $result = $db->query($sql);
  108. while ($row = pg_fetch_assoc($result)) {
  109. $historyRecords[] = $row;
  110. }
  111. return $historyRecords;
  112. }
  113. function setRowColor($rownum)
  114. {
  115. return $rownum % 2 == 0 ? '#b0c4de' : 'white';
  116. }
  117. private function setStatus($status)
  118. {
  119. return $status ? '<font color="red">Closed</font>' : '<font color="green">Open</font>';
  120. }
  121. function tableDrawerForDailyClosing($allHistoryRecords, $idmenu)
  122. {
  123. $rownum = 0;
  124. foreach ($allHistoryRecords as $record) {
  125. $url = '/custom/settlements/dailyclosinghistory_card.php?id=' . $record['rowid'] . '&user_id=' . $record['user_id'] . '&idmenu=' . $idmenu . '&mainmenu=settlements&leftmenu=';
  126. $bgcolor = $this->setRowColor($rownum);
  127. print '<tr style="height:30px; background-color: ' . $bgcolor . '">
  128. <td><a style="display: block; width: 100%; height: 100%;" href="' . $url . '">' . $record['rowid'] . '</a></td>';
  129. print '<td style="text-align: center;">' . $record['date_creation'] . '</td>';
  130. print '<td style="text-align: center;">' . $record['lastname'] . ' ' . $record['firstname'] . '</td>';
  131. print '<td style="text-align: center;">' . $this->setStatus($record['status']) . '</td>';
  132. print '</tr>';
  133. $rownum++;
  134. }
  135. }
  136. function get1stBlocHistorykDataOpen($id)
  137. {
  138. global $db;
  139. $packageHistoryRecordObj = new PackageHistory($db);
  140. $packageHistoryRecordObj->fetch($id);
  141. /* $sql = "SELECT pack.label as packetlabel, gt.label as grouptool, ph.fk_group_id, ph.user_id, ph.package_id, ph.rowid, gu.fk_settlements_group, gr.ref as usergroup, ph.date_creation FROM public.llx_rollerstorage_packagehistory AS ph
  142. INNER JOIN llx_settlements_package as pack ON pack.rowid=ph.package_id
  143. INNER JOIN llx_settlements_grouptools as gt ON gt.rowid = ph.fk_group_id
  144. INNER JOIN llx_settlements_groupusers as gu ON gu.fk_user = ph.user_id
  145. INNER JOIN llx_settlements_group as gr ON gr.rowid=gu.fk_settlements_group
  146. WHERE ph.rowid = {$id}";
  147. $data = $db->query($sql);
  148. $packageHistoryObj = pg_fetch_object($data);
  149. return $packageHistoryObj;*/
  150. return $packageHistoryRecordObj;
  151. }
  152. function get1stBlocHistorykData($id)
  153. {
  154. global $db;
  155. $packageHistoryObj = new PackageHistory($db);
  156. $packageHistoryObj->fetch($id);
  157. return $packageHistoryObj;
  158. }
  159. function get1stBlocHistorykDataClosed($id)
  160. {
  161. global $db;
  162. $packageHistoryObj = new PackageHistory($db);
  163. $packageHistoryObj->fetch($id);
  164. return $packageHistoryObj;
  165. }
  166. function getStatus($rowid)
  167. {
  168. global $db;
  169. $packageHistoryObj = new PackageHistory($db);
  170. $result = $packageHistoryObj->fetch($rowid);
  171. return $packageHistoryObj->status;
  172. }
  173. function closeRecord($id)
  174. {
  175. global $db, $user;
  176. $packageHistoryObj = new PackageHistory($db);
  177. $packageHistoryObj->fetch($id);
  178. $packageHistoryObj->status = 1;
  179. return $packageHistoryObj->update($user);
  180. }
  181. function getWithholdingRecords($withholdingArray)
  182. {
  183. foreach ($withholdingArray as $key => $value) {
  184. $device_id = $this->getDeviceIdFromString($key);
  185. $withholdingRecords[$device_id] = $value;
  186. }
  187. return $withholdingRecords;
  188. }
  189. function getDevicesList($devicesArray, $withholdingRecords)
  190. {
  191. foreach ($devicesArray as $devicevalue) {
  192. $withholding = isset($withholdingRecords[$devicevalue['device_id']]) ? $withholdingRecords[$devicevalue['device_id']] : '';
  193. $block2ndArray[] = ["rowid" => $devicevalue['rowid'], "device_id" => $devicevalue['device_id'], "title" => $devicevalue['title'], "ref" => $devicevalue["ref"], "status" => $devicevalue['status'], "withholding" => $withholding];
  194. }
  195. return $block2ndArray;
  196. }
  197. function getDailyIncomes($changes)
  198. {
  199. $block3rdArray = [];
  200. if ($changes) {
  201. foreach ($changes as $change) {
  202. $tmpArray = explode('_', $change['ref']);
  203. $block3rdArray[$tmpArray[1]] = $change['title'];
  204. }
  205. }
  206. return $block3rdArray;
  207. }
  208. private function getDeviceIdFromString($key)
  209. {
  210. return substr($key, 1);
  211. }
  212. function unprintedFActures($group_id, $user_id, $from)
  213. {
  214. global $db, $langs;
  215. $to = date("Y-m-d H:i:s", dol_now());
  216. $sql = "SELECT f.rowid, f.ref, e.label, f.datec, f.total_ttc, f.multicurrency_code, f.fk_statut
  217. FROM llx_facture AS f
  218. INNER JOIN llx_entity AS e ON e.rowid = f.entity
  219. WHERE
  220. f.fk_user_author = {$user_id} AND
  221. f.datec >= (SELECT un.date_creation FROM public.llx_settlements_usernaplo AS un WHERE un.user_id = {$user_id} AND un.group_user_id = {$group_id} AND un.status = 1
  222. /*AND date_trunc('day', un.date_creation) = CURRENT_DATE*/ ORDER BY un.rowid LIMIT 1) AND f.datec BETWEEN '{$from}' AND '{$to}'
  223. AND NOT EXISTS (SELECT 1 FROM llx_bbus_bbticketinvoiceprinting AS b WHERE b.fk_facture = f.rowid)
  224. ORDER BY f.rowid DESC;";
  225. //print $sql;
  226. $data = $db->query($sql);
  227. $result = pg_fetch_all($data);
  228. print '<table id="unprintedfactureslist" style="display:none; width:100%;">';
  229. print '<tr class="center unprintedfacturetr">
  230. <td style="width:15%;">' . $langs->trans('Invoice') . '</td>
  231. <td style="width:20%;">' . $langs->trans('Company') . '</td>
  232. <td style="width:20%;">' . $langs->trans('Date creation') . '</td>
  233. <td style="width:20%;">' . $langs->trans('Amount') . '</td>
  234. <td style="width:10%;">' . $langs->trans('Currency') . '</td>
  235. <td>' . $langs->trans('Status') . '</td>
  236. </tr>';
  237. if (!empty($result)) {
  238. foreach ($result as $record) {
  239. print '<tr class="center">
  240. <td><a href="/compta/facture/card.php?facid=' . $record['rowid'] . '&save_lastsearch_values=1">' . $record['ref'] . '</a></td>
  241. <td>' . $record['label'] . '</td>
  242. <td>' . $record['datec'] . '</td>
  243. <td>' . $record['total_ttc'] . '</td>
  244. <td>' . $record['multicurrency_code'] . '</td>
  245. <td>' . $this->setStatut($record['fk_statut']) . '</td>
  246. </tr>';
  247. }
  248. } else {
  249. print '<tr><td style="color:red; text-align:center;" colspan="5">' . $langs->trans('Empty') . '</td></tr>';
  250. }
  251. print '</table>';
  252. }
  253. function printedFactures($group_id, $user_id)
  254. {
  255. global $db, $langs;
  256. $now = date("Y-m-d H:i:s", dol_now());
  257. $array = [];
  258. $sql = "SELECT f.rowid
  259. FROM llx_facture AS f
  260. INNER JOIN llx_entity AS e ON e.rowid = f.entity
  261. WHERE
  262. f.fk_user_author = {$user_id} AND
  263. f.datec >= (SELECT un.date_creation FROM public.llx_settlements_usernaplo AS un WHERE un.user_id = {$user_id} AND un.group_user_id = {$group_id} AND un.status = 1
  264. ORDER BY un.rowid LIMIT 1) AND f.datec <= '{$now}'
  265. AND EXISTS (SELECT 1 FROM llx_bbus_bbticketinvoiceprinting AS b WHERE b.fk_facture = f.rowid)
  266. ORDER BY f.rowid DESC;";
  267. //print $sql;
  268. $data = $db->query($sql);
  269. while ($row = pg_fetch_assoc($data)) {
  270. $array[] = $row['rowid'];
  271. }
  272. return $array;
  273. }
  274. function setStatut($statut)
  275. {
  276. switch ($statut) {
  277. case '0':
  278. return '<span class="badge badge-status0 badge-status">Tervezet</span>';
  279. break;
  280. case '2':
  281. return '<span class="badge badge-status6 badge-status">Fizetve</span>';
  282. break;
  283. case '1':
  284. return '<span class="badge badge-status1 badge-status">Nem fizetett</span>';
  285. break;
  286. }
  287. }
  288. function getTheNumberOfPrints($facture_id)
  289. {
  290. global $db;
  291. $array = [];
  292. $number = 0;
  293. $sql = "SELECT tip.fk_facture, tip.product_id, count(tip.product_id) FROM llx_bbus_bbticketinvoiceprinting as tip
  294. WHERE tip.fk_facture = {$facture_id}
  295. GROUP BY tip.fk_facture, tip.product_id";
  296. $data = $db->query($sql);
  297. while ($row = $db->fetch_object($data)) {
  298. $array[$row->fk_facture][$row->product_id] = $row->count;
  299. }
  300. $firstKey = array_key_first($array);
  301. $firstValue = $array[$firstKey];
  302. $number = reset($firstValue);
  303. return $number > 1 ? '<div style="color:red;">' . $number . '</div>' : '<div>' . $number . '</div>';
  304. }
  305. }