| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343 |
- <?php
- class DailyClosing
- {
- public function getChecked($deviceArray, $device)
- {
- return $this->isChecked($deviceArray, $device) ? 'checked' : '';
- }
- public function getDeviceWHChk($deviceArray, $device)
- {
- return $this->isChecked($deviceArray, $device) ? 'display:none' : 'display:inline-block';
- }
- public function getDeviceAmount($amountArray, $device)
- {
- return $this->isValidAmountArray($amountArray, $device) ? $amountArray['d' . $device['device_id'] . '_amount'] : '';
- }
- private function isChecked($deviceArray, $device)
- {
- return isset($deviceArray) && $deviceArray['d' . $device['device_id']] != 'x';
- }
- private function isValidAmountArray($amountArray, $device)
- {
- return isset($amountArray) && $amountArray['d' . $device['device_id'] . '_amount'] != '';
- }
- private function isCheckedForDailyIncomeHUF($deviceArray)
- {
- return isset($deviceArray) && $deviceArray['_daily_HUF'] != 'x';
- }
- private function isCheckedForDailyIncomeEUR($deviceArray)
- {
- return isset($deviceArray) && $deviceArray['_daily_EUR'] != 'x';
- }
- public function getCheckedDailyIncomeHUF($deviceArray)
- {
- return $this->isCheckedForDailyIncomeHUF($deviceArray) ? 'checked' : '';
- }
- public function getDailyAmountHUFChk($deviceArray)
- {
- return $this->isCheckedForDailyIncomeHUF($deviceArray) ? 'display:none' : 'display:inline-block';
- }
- public function getCheckedDailyIncomeEUR($deviceArray)
- {
- return $this->isCheckedForDailyIncomeEUR($deviceArray) ? 'checked' : '';
- }
- public function getDailyAmountEURChk($deviceArray)
- {
- return $this->isCheckedForDailyIncomeEUR($deviceArray) ? 'display:none' : 'display:inline-block';
- }
- public function getJSONArray($array)
- {
- $jsonArray = [];
- foreach ($_REQUEST['withholding'] as $whgroup) {
- foreach ($whgroup as $dkey => $dvalue) {
- if (stripos($dkey, '_amount') == false) {
- $OK = $dvalue == '1' ? 'OK' : '';
- $jsonArray[$dkey] = $OK;
- } else {
- $value = $dvalue != '' ? $dvalue : '';
- $jsonArray[$dkey] = $value;
- }
- }
- }
- return $jsonArray;
- }
- public function getDeviceArray($PackageHistoryClosed)
- {
- $deviceArray = [];
- $dataArray = json_decode($PackageHistoryClosed->note_public);
- foreach ($dataArray as $key => $value) {
- if (strpos($key, '_amount') == false) {
- $deviceArray[$key] = $value == 'OK' ? 1 : 'x';
- }
- }
- return $deviceArray;
- }
- public function getAmountArray($PackageHistoryClosed)
- {
- $amountArray = [];
- $dataArray = json_decode($PackageHistoryClosed->note_public);
- foreach ($dataArray as $key => $value) {
- if (strpos($key, '_amount') == true) {
- $amountArray[$key] = $value != '' ? $value : '';
- }
- }
- return $amountArray;
- }
- public function getHeader($object, $user_id, $idmenu)
- {
- global $db, $langs, $conf;
- $langs->load("settlements@settlements");
- $h = 0;
- $head = array();
- $head[$h][0] = dol_buildpath("/settlements/dailyclosing_card.php", 1) . '?user_id=' . $user_id . '&idmenu=' . $idmenu . '&mainmenu=settlements&leftmenu=';
- $head[$h][1] = $langs->trans("DailyClosing");
- $head[$h][2] = 'card';
- $h++;
- $head[$h][0] = dol_buildpath("/settlements/dailyclosing_list.php", 1) . '?user_id=' . $user_id . '&idmenu=' . $idmenu . '&mainmenu=settlements&leftmenu=';
- $head[$h][1] = $langs->trans("DailyClosingHistory");
- $head[$h][2] = 'list';
- $h++;
- complete_head_from_modules($conf, $langs, $object, $head, $h, 'group@settlements');
- return $head;
- }
- public function getAllHistoryRecords($sql)
- {
- global $db;
- $historyRecords = [];
- $result = $db->query($sql);
- while ($row = pg_fetch_assoc($result)) {
- $historyRecords[] = $row;
- }
- return $historyRecords;
- }
- function setRowColor($rownum)
- {
- return $rownum % 2 == 0 ? '#b0c4de' : 'white';
- }
- private function setStatus($status)
- {
- return $status ? '<font color="red">Closed</font>' : '<font color="green">Open</font>';
- }
- function tableDrawerForDailyClosing($allHistoryRecords, $idmenu)
- {
- $rownum = 0;
- foreach ($allHistoryRecords as $record) {
- $url = '/custom/settlements/dailyclosinghistory_card.php?id=' . $record['rowid'] . '&user_id=' . $record['user_id'] . '&idmenu=' . $idmenu . '&mainmenu=settlements&leftmenu=';
- $bgcolor = $this->setRowColor($rownum);
- print '<tr style="height:30px; background-color: ' . $bgcolor . '">
- <td><a style="display: block; width: 100%; height: 100%;" href="' . $url . '">' . $record['rowid'] . '</a></td>';
- print '<td style="text-align: center;">' . $record['date_creation'] . '</td>';
- print '<td style="text-align: center;">' . $record['lastname'] . ' ' . $record['firstname'] . '</td>';
- print '<td style="text-align: center;">' . $this->setStatus($record['status']) . '</td>';
- print '</tr>';
- $rownum++;
- }
- }
- function get1stBlocHistorykDataOpen($id)
- {
- global $db;
- $packageHistoryRecordObj = new PackageHistory($db);
- $packageHistoryRecordObj->fetch($id);
- /* $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
- INNER JOIN llx_settlements_package as pack ON pack.rowid=ph.package_id
- INNER JOIN llx_settlements_grouptools as gt ON gt.rowid = ph.fk_group_id
- INNER JOIN llx_settlements_groupusers as gu ON gu.fk_user = ph.user_id
- INNER JOIN llx_settlements_group as gr ON gr.rowid=gu.fk_settlements_group
- WHERE ph.rowid = {$id}";
- $data = $db->query($sql);
- $packageHistoryObj = pg_fetch_object($data);
- return $packageHistoryObj;*/
- return $packageHistoryRecordObj;
- }
- function get1stBlocHistorykData($id)
- {
- global $db;
- $packageHistoryObj = new PackageHistory($db);
- $packageHistoryObj->fetch($id);
- return $packageHistoryObj;
- }
- function get1stBlocHistorykDataClosed($id)
- {
- global $db;
- $packageHistoryObj = new PackageHistory($db);
- $packageHistoryObj->fetch($id);
- return $packageHistoryObj;
- }
- function getStatus($rowid)
- {
- global $db;
- $packageHistoryObj = new PackageHistory($db);
- $result = $packageHistoryObj->fetch($rowid);
- return $packageHistoryObj->status;
- }
- function closeRecord($id)
- {
- global $db, $user;
- $packageHistoryObj = new PackageHistory($db);
- $packageHistoryObj->fetch($id);
- $packageHistoryObj->status = 1;
- return $packageHistoryObj->update($user);
- }
- function getWithholdingRecords($withholdingArray)
- {
- foreach ($withholdingArray as $key => $value) {
- $device_id = $this->getDeviceIdFromString($key);
- $withholdingRecords[$device_id] = $value;
- }
- return $withholdingRecords;
- }
- function getDevicesList($devicesArray, $withholdingRecords)
- {
- foreach ($devicesArray as $devicevalue) {
- $withholding = isset($withholdingRecords[$devicevalue['device_id']]) ? $withholdingRecords[$devicevalue['device_id']] : '';
- $block2ndArray[] = ["rowid" => $devicevalue['rowid'], "device_id" => $devicevalue['device_id'], "title" => $devicevalue['title'], "ref" => $devicevalue["ref"], "status" => $devicevalue['status'], "withholding" => $withholding];
- }
- return $block2ndArray;
- }
- function getDailyIncomes($changes)
- {
- $block3rdArray = [];
- if ($changes) {
- foreach ($changes as $change) {
- $tmpArray = explode('_', $change['ref']);
- $block3rdArray[$tmpArray[1]] = $change['title'];
- }
- }
- return $block3rdArray;
- }
- private function getDeviceIdFromString($key)
- {
- return substr($key, 1);
- }
- function unprintedFActures($group_id, $user_id, $from)
- {
- global $db, $langs;
- $to = date("Y-m-d H:i:s", dol_now());
- $sql = "SELECT f.rowid, f.ref, e.label, f.datec, f.total_ttc, f.multicurrency_code, f.fk_statut
- FROM llx_facture AS f
- INNER JOIN llx_entity AS e ON e.rowid = f.entity
- WHERE
- f.fk_user_author = {$user_id} AND
- 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
- /*AND date_trunc('day', un.date_creation) = CURRENT_DATE*/ ORDER BY un.rowid LIMIT 1) AND f.datec BETWEEN '{$from}' AND '{$to}'
- AND NOT EXISTS (SELECT 1 FROM llx_bbus_bbticketinvoiceprinting AS b WHERE b.fk_facture = f.rowid)
- ORDER BY f.rowid DESC;";
- //print $sql;
- $data = $db->query($sql);
- $result = pg_fetch_all($data);
- print '<table id="unprintedfactureslist" style="display:none; width:100%;">';
- print '<tr class="center unprintedfacturetr">
- <td style="width:15%;">' . $langs->trans('Invoice') . '</td>
- <td style="width:20%;">' . $langs->trans('Company') . '</td>
- <td style="width:20%;">' . $langs->trans('Date creation') . '</td>
- <td style="width:20%;">' . $langs->trans('Amount') . '</td>
- <td style="width:10%;">' . $langs->trans('Currency') . '</td>
- <td>' . $langs->trans('Status') . '</td>
- </tr>';
- if (!empty($result)) {
- foreach ($result as $record) {
- print '<tr class="center">
- <td><a href="/compta/facture/card.php?facid=' . $record['rowid'] . '&save_lastsearch_values=1">' . $record['ref'] . '</a></td>
- <td>' . $record['label'] . '</td>
- <td>' . $record['datec'] . '</td>
- <td>' . $record['total_ttc'] . '</td>
- <td>' . $record['multicurrency_code'] . '</td>
- <td>' . $this->setStatut($record['fk_statut']) . '</td>
- </tr>';
- }
- } else {
- print '<tr><td style="color:red; text-align:center;" colspan="5">' . $langs->trans('Empty') . '</td></tr>';
- }
- print '</table>';
- }
- function printedFactures($group_id, $user_id)
- {
- global $db, $langs;
- $now = date("Y-m-d H:i:s", dol_now());
- $array = [];
- $sql = "SELECT f.rowid
- FROM llx_facture AS f
- INNER JOIN llx_entity AS e ON e.rowid = f.entity
- WHERE
- f.fk_user_author = {$user_id} AND
- 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
- ORDER BY un.rowid LIMIT 1) AND f.datec <= '{$now}'
- AND EXISTS (SELECT 1 FROM llx_bbus_bbticketinvoiceprinting AS b WHERE b.fk_facture = f.rowid)
- ORDER BY f.rowid DESC;";
- //print $sql;
- $data = $db->query($sql);
- while ($row = pg_fetch_assoc($data)) {
- $array[] = $row['rowid'];
- }
- return $array;
- }
- function setStatut($statut)
- {
- switch ($statut) {
- case '0':
- return '<span class="badge badge-status0 badge-status">Tervezet</span>';
- break;
- case '2':
- return '<span class="badge badge-status6 badge-status">Fizetve</span>';
- break;
- case '1':
- return '<span class="badge badge-status1 badge-status">Nem fizetett</span>';
- break;
- }
- }
- function getTheNumberOfPrints($facture_id)
- {
- global $db;
- $array = [];
- $number = 0;
- $sql = "SELECT tip.fk_facture, tip.product_id, count(tip.product_id) FROM llx_bbus_bbticketinvoiceprinting as tip
- WHERE tip.fk_facture = {$facture_id}
- GROUP BY tip.fk_facture, tip.product_id";
- $data = $db->query($sql);
- while ($row = $db->fetch_object($data)) {
- $array[$row->fk_facture][$row->product_id] = $row->count;
- }
- $firstKey = array_key_first($array);
- $firstValue = $array[$firstKey];
- $number = reset($firstValue);
- return $number > 1 ? '<div style="color:red;">' . $number . '</div>' : '<div>' . $number . '</div>';
- }
- }
|