| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414 |
- <?php
- require_once DOL_DOCUMENT_ROOT . '/custom/bbus/class/api_curl.class.php';
- require_once DOL_DOCUMENT_ROOT . '/custom/bbus/class/api_bbus_log.class.php';
- class DailyClosing
- {
- use CurlApi;
- 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, bbt.rowid as bbt_rowid, bbtip.rowid as bbtip_rowid
- FROM llx_facture AS f
- INNER JOIN llx_entity AS e ON e.rowid = f.entity
- LEFT JOIN llx_bbus_bbticket as bbt ON bbt.fk_facture = f.rowid
- LEFT JOIN llx_bbus_bbticketinvoiceprinting as bbtip ON bbtip.invoice_number = f.ref
- 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 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);
- $refs = "";
- while($row = $db->fetch_object($result)){
- if ($refs == "") {
- $refs .= "'" . $row->ref . "'";
- } else {
- $refs .= ",'" . $row->ref . "'";
- }
- }
- $params = ["from" => $from, "to" => $to, "factures" => $refs];
- $postFields = json_encode($params);
- $crossShoppingFactures = $this->curlRunner('bookingapi/getPrintedFacturesRefsArray', $postFields, 'POST', true);
- //print_r($crossShoppingFactures);
- print '<table id="unprintedfactureslist" style="display:none; width:100%;">';
- print '<tr class="center unprintedfacturetr">
- <td style="width:15%;">' . $langs->trans('CS') . '</td>
- <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) {
- $isCS = $this->checkCrossShopping($record['ref']) ? '<span class="fa fa-check"></span>' : '';
- if (((is_null($record['bbt_rowid']) && is_null($record['bbtip_rowid'])) || (!is_null($record['bbt_rowid']) && is_null($record['bbtip_rowid']))) && !in_array($record['ref'], $crossShoppingFactures)) {
- print '<tr class="center">
- <td>' . $isCS . '</td>
- <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>';
- }
- private function checkCrossShopping($facture_id){
- global $db, $conf;
- $sql = "SELECT bbs.server_host FROM llx_facture as f
- INNER JOIN llx_facturedet as fdet ON fdet.fk_facture = f.rowid
- INNER JOIN llx_product_extrafields as pre ON pre.fk_object = fdet.fk_product
- INNER JOIN llx_bbus_basicservices as bbs ON bbs.rowid = cast(pre.basic_service as integer)
- WHERE f.ref = '{$facture_id}'
- GROUP BY bbs.server_host";
- $result = $db->query($sql);
- if($db->num_rows($result) > 0){
- while($row = $db->fetch_object($result)){
- //print $facture_id . ' -> ' . $row->server_host . ' - ' . $conf->global->CURL_SERVER_HOST . '<br>';
- return $row->server_host == $conf->global->CURL_SERVER_HOST;
- }
- }
- return false;
- }
- function printedFactures($user_id, $date_creation)
- {
- global $db, $langs;
- $startdate = date("Y-m-d H:i:s", $date_creation);
- $now = date("Y-m-d H:i:s", dol_now());
- $array = [];
- $crossShoppingFacturesString = "";
- $sql = "SELECT f.rowid, bbt.rowid as bbt_rowid, bbtip.rowid as bbtip_rowid, f.ref
- FROM llx_facture AS f
- INNER JOIN llx_entity AS e ON e.rowid = f.entity
- LEFT JOIN llx_bbus_bbticket as bbt ON bbt.fk_facture = f.rowid
- LEFT JOIN llx_bbus_bbticketinvoiceprinting as bbtip ON bbtip.invoice_number = f.ref
- WHERE
- f.fk_user_author = {$user_id} AND
- f.datec BETWEEN '{$startdate}' AND '{$now}'
- ORDER BY f.rowid DESC;";
- $data = $db->query($sql);
- while ($row = pg_fetch_assoc($data)) {
- if (!is_null($row['bbt_rowid']) && !is_null($row['bbtip_rowid'])) {
- $array[] = $row['rowid'];
- } else {
- if ($crossShoppingFacturesString == "") {
- $crossShoppingFacturesString .= "'" . $row['ref'] . "'";
- } else {
- $crossShoppingFacturesString .= ",'" . $row['ref'] . "'";
- }
- }
- }
- $params = ["from" => $startdate, "to" => $now, "factures" => $crossShoppingFacturesString];
- $postFields = json_encode($params);
- $crossShoppingFactures = $this->curlRunner('bookingapi/getPrintedFacturesRefsArray', $postFields, 'POST', true);
- if(!is_null($crossShoppingFactures)){
- $data = $db->query($sql);
- while ($row2 = pg_fetch_assoc($data)) {
- if (in_array($row2['ref'], $crossShoppingFactures)) {
- $array[] = $row2['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), invoice_number FROM llx_bbus_bbticketinvoiceprinting as tip
- WHERE tip.fk_facture = {$facture_id}
- GROUP BY tip.fk_facture, tip.product_id, invoice_number";
- $data = $db->query($sql);
- if ($db->num_rows($data) > 0) {
- 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);
- } else {
- $factureObj = new Facture($db);
- $result = $factureObj->fetch($facture_id);
- $invoice_number = $factureObj->ref;
- $params = ["invoice_number" => $invoice_number];
- $postFields = json_encode($params);
- $number = $this->curlRunner('bookingapi/getFacturesNumberOfPrints', $postFields, 'POST', true);
- }
- return $number > 1 ? '<div style="color:red;">' . $number . '</div>' : '<div>' . $number . '</div>';
- }
- }
|