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 ? 'Closed' : 'Open';
}
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 '
| ' . $record['rowid'] . ' | ';
print '' . $record['date_creation'] . ' | ';
print '' . $record['lastname'] . ' ' . $record['firstname'] . ' | ';
print '' . $this->setStatus($record['status']) . ' | ';
print '
';
$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)){
$refs[] = "'".$row->ref . "'";
}
$refs = array_unique($refs);
$refs = array_values($refs);
$refsString = implode(",", $refs);
$params = ["from" => $from, "to" => $to, "factures" => $refsString];
$postFields = json_encode($params);
$crossShoppingFacturesResult = $this->curlRunner('bookingapi/getPrintedFacturesRefsArray', $postFields, 'POST', true);
$crossShoppingFactures = is_null($crossShoppingFacturesResult) ? [] : $crossShoppingFacturesResult;
//print_r($crossShoppingFactures);
print '';
print '
| ' . $langs->trans('CS') . ' |
' . $langs->trans('Invoice') . ' |
' . $langs->trans('Company') . ' |
' . $langs->trans('Date creation') . ' |
' . $langs->trans('Amount') . ' |
' . $langs->trans('Currency') . ' |
' . $langs->trans('Status') . ' |
';
if (!empty($result)) {
foreach ($result as $record) {
$isCS = $this->checkCrossShopping($record['ref']) ? '' : '';
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 '
| ' . $isCS . ' |
' . $record['ref'] . ' |
' . $record['label'] . ' |
' . $record['datec'] . ' |
' . $record['total_ttc'] . ' |
' . $record['multicurrency_code'] . ' |
' . $this->setStatut($record['fk_statut']) . ' |
';
}
}
} else {
print '| ' . $langs->trans('Empty') . ' |
';
}
print '
';
}
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 . '
';
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 'Tervezet';
break;
case '2':
return 'Fizetve';
break;
case '1':
return 'Nem fizetett';
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 ? '' . $number . '
' : '' . $number . '
';
}
}