|
@@ -1,4 +1,5 @@
|
|
|
<?php
|
|
<?php
|
|
|
|
|
+
|
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
|
|
use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
|
use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
|
@@ -9,10 +10,14 @@ require_once DOL_DOCUMENT_ROOT . '/custom/settlements/class/usernaplo.class.php'
|
|
|
require_once DOL_DOCUMENT_ROOT . '/custom/settlements/class/hotel.class.php';
|
|
require_once DOL_DOCUMENT_ROOT . '/custom/settlements/class/hotel.class.php';
|
|
|
require_once DOL_DOCUMENT_ROOT . '/custom/settlements/class/group.class.php';
|
|
require_once DOL_DOCUMENT_ROOT . '/custom/settlements/class/group.class.php';
|
|
|
require_once DOL_DOCUMENT_ROOT . '/custom/bbus/class/commissionhandler.class.php';
|
|
require_once DOL_DOCUMENT_ROOT . '/custom/bbus/class/commissionhandler.class.php';
|
|
|
|
|
+require_once DOL_DOCUMENT_ROOT . '/custom/bbus/class/api_curl.class.php';
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
class HelperUserInvoice
|
|
class HelperUserInvoice
|
|
|
{
|
|
{
|
|
|
|
|
+ use CurlApi;
|
|
|
|
|
+
|
|
|
public $db;
|
|
public $db;
|
|
|
|
|
|
|
|
public function __construct(DoliDB $db)
|
|
public function __construct(DoliDB $db)
|
|
@@ -102,7 +107,7 @@ class HelperUserInvoice
|
|
|
{
|
|
{
|
|
|
$salesUsers = [];
|
|
$salesUsers = [];
|
|
|
$result = $this->db->query($sql);
|
|
$result = $this->db->query($sql);
|
|
|
- if($this->db->num_rows($result) > 0){
|
|
|
|
|
|
|
+ if ($this->db->num_rows($result) > 0) {
|
|
|
while ($row = pg_fetch_assoc($result)) {
|
|
while ($row = pg_fetch_assoc($result)) {
|
|
|
$salesUsers[] = $row;
|
|
$salesUsers[] = $row;
|
|
|
}
|
|
}
|
|
@@ -956,7 +961,6 @@ class HelperUserInvoice
|
|
|
while ($row = pg_fetch_assoc($data)) {
|
|
while ($row = pg_fetch_assoc($data)) {
|
|
|
$usersOfGroup[] = $row;
|
|
$usersOfGroup[] = $row;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
return $usersOfGroup;
|
|
return $usersOfGroup;
|
|
|
}
|
|
}
|
|
@@ -1193,7 +1197,7 @@ class HelperUserInvoice
|
|
|
$userObj = new User($this->db);
|
|
$userObj = new User($this->db);
|
|
|
$sql = "SELECT * FROM llx_user as u INNER JOIN llx_user_extrafields as ue ON ue.fk_object = u.rowid WHERE u.rowid = {$user_id}";
|
|
$sql = "SELECT * FROM llx_user as u INNER JOIN llx_user_extrafields as ue ON ue.fk_object = u.rowid WHERE u.rowid = {$user_id}";
|
|
|
$result = $db->query($sql);
|
|
$result = $db->query($sql);
|
|
|
- while($row = $db->fetch_object($result)){
|
|
|
|
|
|
|
+ while ($row = $db->fetch_object($result)) {
|
|
|
$minimum_monthly_commission = $row->minimum_monthly_commission;
|
|
$minimum_monthly_commission = $row->minimum_monthly_commission;
|
|
|
}
|
|
}
|
|
|
if (!$result) {
|
|
if (!$result) {
|
|
@@ -1335,7 +1339,7 @@ class HelperUserInvoice
|
|
|
foreach ($userDataArray as $key => $period) {
|
|
foreach ($userDataArray as $key => $period) {
|
|
|
$from = $period['login'];
|
|
$from = $period['login'];
|
|
|
$to = isset($period['logout']) ? $period['logout'] : (isset($deletedUsersArray[$userOfGroups['user_id']]) ? $deletedUsersArray[$userOfGroups['user_id']] : date('Y-m-d', dol_now()) . ' 23:59:59');
|
|
$to = isset($period['logout']) ? $period['logout'] : (isset($deletedUsersArray[$userOfGroups['user_id']]) ? $deletedUsersArray[$userOfGroups['user_id']] : date('Y-m-d', dol_now()) . ' 23:59:59');
|
|
|
- print $from . ' - ' . $to . '<br>';
|
|
|
|
|
|
|
+ //print $from . ' - ' . $to . '<br>';
|
|
|
if (isset($from)) {
|
|
if (isset($from)) {
|
|
|
$commission_HUF = $commmissionhandler->getOccassionOfThisPeriodByDateAndUserId_HUF($userOfGroups['user_id'], $from, $to);
|
|
$commission_HUF = $commmissionhandler->getOccassionOfThisPeriodByDateAndUserId_HUF($userOfGroups['user_id'], $from, $to);
|
|
|
$commission_EURToHUF = $commmissionhandler->getOccassionOfThisPeriodByDateAndUserId_EURToHUF($userOfGroups['user_id'], $from, $to);
|
|
$commission_EURToHUF = $commmissionhandler->getOccassionOfThisPeriodByDateAndUserId_EURToHUF($userOfGroups['user_id'], $from, $to);
|
|
@@ -1354,14 +1358,32 @@ class HelperUserInvoice
|
|
|
return $amount;
|
|
return $amount;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ function getAllFacturesOfThisUser($user_id, $from, $to)
|
|
|
|
|
+ {
|
|
|
|
|
+ $crossShoppingFacturesString = '';
|
|
|
|
|
+ $sql = "SELECT ref
|
|
|
|
|
+ FROM llx_facture AS f
|
|
|
|
|
+ WHERE fk_user_closing = {$user_id}
|
|
|
|
|
+ AND date_closing BETWEEN '{$from}' AND '{$to}'";
|
|
|
|
|
+ $result = $this->db->query($sql);
|
|
|
|
|
+ if ($this->db->num_rows($result) > 0) {
|
|
|
|
|
+ while ($row = $this->db->fetch_object($result)) {
|
|
|
|
|
+ if ($crossShoppingFacturesString == "") {
|
|
|
|
|
+ $crossShoppingFacturesString .= "'" . $row->ref . "'";
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $crossShoppingFacturesString .= ",'" . $row->ref . "'";
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return $crossShoppingFacturesString;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
function getInvoicesRowidFromFacture($user_id, $from, $to)
|
|
function getInvoicesRowidFromFacture($user_id, $from, $to)
|
|
|
{
|
|
{
|
|
|
$invocesRowidArray = [];
|
|
$invocesRowidArray = [];
|
|
|
$sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "facture AS f WHERE fk_user_closing = {$user_id}
|
|
$sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "facture AS f WHERE fk_user_closing = {$user_id}
|
|
|
AND EXISTS (SELECT * FROM " . MAIN_DB_PREFIX . "bbus_bbticketinvoiceprinting as bbip WHERE bbip.fk_facture = f.rowid ORDER BY bbip.rowid DESC LIMIT 1)
|
|
AND EXISTS (SELECT * FROM " . MAIN_DB_PREFIX . "bbus_bbticketinvoiceprinting as bbip WHERE bbip.fk_facture = f.rowid ORDER BY bbip.rowid DESC LIMIT 1)
|
|
|
AND date_closing BETWEEN '{$from}' AND '{$to}'";
|
|
AND date_closing BETWEEN '{$from}' AND '{$to}'";
|
|
|
- //print $sql;
|
|
|
|
|
- //exit;
|
|
|
|
|
$resultInvoicesData = $this->db->query($sql);
|
|
$resultInvoicesData = $this->db->query($sql);
|
|
|
if ($this->db->num_rows($resultInvoicesData) != 0) {
|
|
if ($this->db->num_rows($resultInvoicesData) != 0) {
|
|
|
$result = pg_fetch_all($resultInvoicesData);
|
|
$result = pg_fetch_all($resultInvoicesData);
|
|
@@ -1371,15 +1393,35 @@ class HelperUserInvoice
|
|
|
$invocesRowidString = implode(',', $invocesRowidArray);
|
|
$invocesRowidString = implode(',', $invocesRowidArray);
|
|
|
}
|
|
}
|
|
|
$readyInvoices = $this->getAllComissionInvoicesOfUserInTheGroupFromUserInvoice($user_id, $from, $to);
|
|
$readyInvoices = $this->getAllComissionInvoicesOfUserInTheGroupFromUserInvoice($user_id, $from, $to);
|
|
|
- //print $readyInvoices . '<br>';
|
|
|
|
|
- //print $invocesRowidString . '<br>';
|
|
|
|
|
|
|
+
|
|
|
if (!empty($readyInvoices)) {
|
|
if (!empty($readyInvoices)) {
|
|
|
$invocesRowidString = $this->giveMeTheDifferenceInString($readyInvoices, $invocesRowidString);
|
|
$invocesRowidString = $this->giveMeTheDifferenceInString($readyInvoices, $invocesRowidString);
|
|
|
}
|
|
}
|
|
|
- //print $invocesRowidString . '<br>';
|
|
|
|
|
return $invocesRowidString;
|
|
return $invocesRowidString;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ function getCrossShoppingInvoicesRowidFromFacture($allFactures, $from, $to)
|
|
|
|
|
+ {
|
|
|
|
|
+ $facturesRowids = '';
|
|
|
|
|
+ $params = ["from" => $from, "to" => $to, "factures" => $allFactures];
|
|
|
|
|
+ $postFields = json_encode($params);
|
|
|
|
|
+ $crossShoppingFactures = $this->curlRunner('bookingapi/getPrintedFacturesRefs', $postFields, 'POST', true);
|
|
|
|
|
+ if ($crossShoppingFactures !== '') {
|
|
|
|
|
+ $sql = "SELECT rowid FROM llx_facture WHERE ref IN ($crossShoppingFactures)";
|
|
|
|
|
+ $result = $this->db->query($sql);
|
|
|
|
|
+ if ($this->db->num_rows($result) > 0) {
|
|
|
|
|
+ while ($row = $this->db->fetch_object($result)) {
|
|
|
|
|
+ if ($facturesRowids == "") {
|
|
|
|
|
+ $facturesRowids .= $row->rowid;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $facturesRowids .= "," . $row->rowid;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return $facturesRowids;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
function getInvoicesRowidFromFactureInAnIntervalByEveryUser($users, $from, $to, $exception)
|
|
function getInvoicesRowidFromFactureInAnIntervalByEveryUser($users, $from, $to, $exception)
|
|
|
{
|
|
{
|
|
|
$invocesRowidArray = [];
|
|
$invocesRowidArray = [];
|
|
@@ -1401,6 +1443,29 @@ class HelperUserInvoice
|
|
|
return $invocesRowidString;
|
|
return $invocesRowidString;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ function getInvoicesRowidFromFactureInAnIntervalByEveryUserWithoutInvoicePrinting($users, $from, $to, $exception)
|
|
|
|
|
+ {
|
|
|
|
|
+ $crossShoppingFacturesString = '';
|
|
|
|
|
+ $sql = "SELECT f.ref FROM " . MAIN_DB_PREFIX . "facture as f WHERE fk_user_closing IN({$users})";
|
|
|
|
|
+ if ($exception != '') {
|
|
|
|
|
+ $sql .= " AND rowid NOT IN({$exception})";
|
|
|
|
|
+ }
|
|
|
|
|
+ $sql .= " AND date_closing BETWEEN '{$from}' AND '{$to}'";
|
|
|
|
|
+ //print $sql . "\r\n";
|
|
|
|
|
+ $resultInvoicesData = $this->db->query($sql);
|
|
|
|
|
+ if ($this->db->num_rows($resultInvoicesData) > 0) {
|
|
|
|
|
+ while ($row = $this->db->fetch_object($resultInvoicesData)) {
|
|
|
|
|
+ if ($crossShoppingFacturesString == "") {
|
|
|
|
|
+ $crossShoppingFacturesString .= "'" . $row->ref . "'";
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $crossShoppingFacturesString .= ",'" . $row->ref . "'";
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return $crossShoppingFacturesString;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
function getAllComissionInvoicesOfUserInTheGroupFromUserInvoice($user_id, $from, $to)
|
|
function getAllComissionInvoicesOfUserInTheGroupFromUserInvoice($user_id, $from, $to)
|
|
|
{
|
|
{
|
|
|
$arraytmp = [];
|
|
$arraytmp = [];
|
|
@@ -1414,6 +1479,7 @@ class HelperUserInvoice
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
$invocesRowidString = implode(',', $arraytmp);
|
|
$invocesRowidString = implode(',', $arraytmp);
|
|
|
|
|
+ //print $invocesRowidString;
|
|
|
return $invocesRowidString;
|
|
return $invocesRowidString;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1443,7 +1509,6 @@ class HelperUserInvoice
|
|
|
return $string;
|
|
return $string;
|
|
|
}
|
|
}
|
|
|
return $string;
|
|
return $string;
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function getHtmlForConfirmWindow($commission)
|
|
function getHtmlForConfirmWindow($commission)
|
|
@@ -1902,7 +1967,6 @@ class HelperUserInvoice
|
|
|
return $array;
|
|
return $array;
|
|
|
}
|
|
}
|
|
|
return [];
|
|
return [];
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function getAllEntities()
|
|
function getAllEntities()
|
|
@@ -1926,4 +1990,4 @@ class HelperUserInvoice
|
|
|
$popoupBox .= '" class="classfortooltip"><div onclick="popupboxClick(' . $id . ')" class="groupColumn2ndLine">' . $numberOfUsers . '</div>';
|
|
$popoupBox .= '" class="classfortooltip"><div onclick="popupboxClick(' . $id . ')" class="groupColumn2ndLine">' . $numberOfUsers . '</div>';
|
|
|
return $popoupBox;
|
|
return $popoupBox;
|
|
|
}
|
|
}
|
|
|
-}
|
|
|
|
|
|
|
+}
|