|
|
@@ -103,7 +103,83 @@ class CommissionHandler
|
|
|
|
|
|
function getAllCommission($allUsersString, $currency, $from, $to, $allComissionInvoicesOfUserInTheGroupFromUserInvoice)
|
|
|
{
|
|
|
+ //print $allComissionInvoicesOfUserInTheGroupFromUserInvoice;
|
|
|
+ if($to == null){
|
|
|
+ $to = date('Y-m-d H:i:s', dol_now());
|
|
|
+ }
|
|
|
+ $crossShoppingFacturesString = '';
|
|
|
+
|
|
|
+ $sqlForCrossShoppingFactures = "SELECT f.ref
|
|
|
+ FROM llx_facture as f
|
|
|
+ INNER JOIN llx_facture_extrafields as fe ON fe.fk_object = f.rowid
|
|
|
+ LEFT JOIN llx_bbus_bbticket as bbt ON bbt.fk_facture = f.rowid WHERE";
|
|
|
+ if (!empty($allComissionInvoicesOfUserInTheGroupFromUserInvoice)) {
|
|
|
+ $sqlForCrossShoppingFactures .= " f.rowid NOT IN({$allComissionInvoicesOfUserInTheGroupFromUserInvoice}) AND";
|
|
|
+ }
|
|
|
+ $sqlForCrossShoppingFactures .= " (SELECT a.rowid FROM llx_facture as a WHERE a.fk_facture_source = f.rowid AND fk_user_closing IN ({$allUsersString})) Is NULL AND
|
|
|
+ fk_user_closing IN ({$allUsersString})
|
|
|
+ AND multicurrency_code = '{$currency}'
|
|
|
+ AND date_closing BETWEEN '{$from}' AND '{$to}'";
|
|
|
+ $resultForCrossShoppingFactures = $this->db->query($sqlForCrossShoppingFactures);
|
|
|
+ if ($this->db->num_rows($resultForCrossShoppingFactures) > 0) {
|
|
|
+ while ($factureCSRow = pg_fetch_assoc($resultForCrossShoppingFactures)) {
|
|
|
+ if ($crossShoppingFacturesString == "") {
|
|
|
+ $crossShoppingFacturesString .= "'" . $factureCSRow['ref'] . "'";
|
|
|
+ } else {
|
|
|
+ $crossShoppingFacturesString .= ",'" . $factureCSRow['ref'] . "'";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $params = ["from" => $from, "to" => $to, "factures" => $crossShoppingFacturesString];
|
|
|
+ $postFields = json_encode($params);
|
|
|
+ $crossShoppingFactures = $this->curlRunner('bookingapi/getPrintedFacturesRefs', $postFields, 'POST', true);
|
|
|
+ global $db;
|
|
|
$commissions = 0;
|
|
|
+ $sql = "SELECT f.rowid, f.total_ttc, fe.commission, f.ref, f.date_closing
|
|
|
+ FROM llx_facture as f
|
|
|
+ INNER JOIN llx_facture_extrafields as fe ON fe.fk_object = f.rowid
|
|
|
+ INNER JOIN llx_bbus_bbticketinvoiceprinting as bbtip ON bbtip.invoice_number = f.ref WHERE ";
|
|
|
+ if ($crossShoppingFactures != '') {
|
|
|
+ $sql .= " f.ref not in ({$crossShoppingFactures}) AND";
|
|
|
+ }
|
|
|
+ if (!empty($allComissionInvoicesOfUserInTheGroupFromUserInvoice)) {
|
|
|
+ $sql .= " f.rowid NOT IN({$allComissionInvoicesOfUserInTheGroupFromUserInvoice}) AND";
|
|
|
+ }
|
|
|
+ $sql .= "
|
|
|
+ fk_user_closing IN ({$allUsersString})
|
|
|
+ AND multicurrency_code = '{$currency}'
|
|
|
+ AND fe.commission_deduction is NULL
|
|
|
+ AND date_closing BETWEEN '{$from}' AND '{$to}'
|
|
|
+ GROUP BY f.rowid, f.total_ttc, fe.commission, f.ref";
|
|
|
+ //print $sql;
|
|
|
+ $result = $db->query($sql);
|
|
|
+ if ($db->num_rows($result) != 0) {
|
|
|
+ while ($row = pg_fetch_assoc($result)) {
|
|
|
+ $commissions += $this->getAmountOfCommission($row);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($crossShoppingFactures != '') {
|
|
|
+ $sqlCS = "SELECT f.rowid, f.total_ttc, fe.commission, f.ref
|
|
|
+ FROM llx_facture as f
|
|
|
+ INNER JOIN llx_facture_extrafields as fe ON fe.fk_object = f.rowid WHERE f.ref in ({$crossShoppingFactures}) AND";
|
|
|
+ if (!empty($allComissionInvoicesOfUserInTheGroupFromUserInvoice)) {
|
|
|
+ $sqlCS .= " f.rowid NOT IN({$allComissionInvoicesOfUserInTheGroupFromUserInvoice}) AND";
|
|
|
+ }
|
|
|
+ $sqlCS .= "
|
|
|
+ fk_user_closing IN ({$allUsersString})
|
|
|
+ AND multicurrency_code = '{$currency}'
|
|
|
+ AND fe.commission_deduction is NULL
|
|
|
+ AND date_closing BETWEEN '{$from}' AND '{$to}'";
|
|
|
+ //print $sqlCS;
|
|
|
+ $resultCS = $db->query($sqlCS);
|
|
|
+ if ($db->num_rows($resultCS) != 0) {
|
|
|
+ while ($rowCS = pg_fetch_assoc($resultCS)) {
|
|
|
+ $commissions += $this->getAmountOfCommission($rowCS);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $commissions;
|
|
|
+ /* $commissions = 0;
|
|
|
$sql = "SELECT f.rowid, f.total_ttc, fe.commission FROM llx_facture as f
|
|
|
INNER JOIN llx_facture_extrafields as fe ON fe.fk_object = f.rowid
|
|
|
WHERE f.fk_user_closing IN ({$allUsersString})
|
|
|
@@ -121,24 +197,48 @@ class CommissionHandler
|
|
|
while ($row = pg_fetch_assoc($result)) {
|
|
|
$commissions += $this->getAmountOfCommission($row);
|
|
|
}
|
|
|
- return $commissions;
|
|
|
+ return $commissions; */
|
|
|
}
|
|
|
|
|
|
function getCommisonByUserId($user_id, $currency, $from, $to, $allComissionInvoicesOfUserInTheGroupFromUserInvoice)
|
|
|
{
|
|
|
- $to = date('Y-m-d H:i:s', dol_now());
|
|
|
- $crossShoppingFacturesString = "'MrNSTR2409-001003'";
|
|
|
+ //print $allComissionInvoicesOfUserInTheGroupFromUserInvoice;
|
|
|
+ if($to == null){
|
|
|
+ $to = date('Y-m-d H:i:s', dol_now());
|
|
|
+ }
|
|
|
+ $crossShoppingFacturesString = '';
|
|
|
|
|
|
+ $sqlForCrossShoppingFactures = "SELECT f.ref
|
|
|
+ FROM llx_facture as f
|
|
|
+ INNER JOIN llx_facture_extrafields as fe ON fe.fk_object = f.rowid
|
|
|
+ LEFT JOIN llx_bbus_bbticket as bbt ON bbt.fk_facture = f.rowid WHERE";
|
|
|
+ if (!empty($allComissionInvoicesOfUserInTheGroupFromUserInvoice)) {
|
|
|
+ $sqlForCrossShoppingFactures .= " f.rowid NOT IN({$allComissionInvoicesOfUserInTheGroupFromUserInvoice}) AND";
|
|
|
+ }
|
|
|
+ $sqlForCrossShoppingFactures .= " (SELECT a.rowid FROM llx_facture as a WHERE a.fk_facture_source = f.rowid AND fk_user_closing = {$user_id}) Is NULL AND
|
|
|
+ fk_user_closing = {$user_id}
|
|
|
+ AND multicurrency_code = '{$currency}'
|
|
|
+ AND date_closing BETWEEN '{$from}' AND '{$to}'";
|
|
|
+ //print $sqlForCrossShoppingFactures . '<br>';
|
|
|
+ $resultForCrossShoppingFactures = $this->db->query($sqlForCrossShoppingFactures);
|
|
|
+ if ($this->db->num_rows($resultForCrossShoppingFactures) > 0) {
|
|
|
+ while ($factureCSRow = pg_fetch_assoc($resultForCrossShoppingFactures)) {
|
|
|
+ if ($crossShoppingFacturesString == "") {
|
|
|
+ $crossShoppingFacturesString .= "'" . $factureCSRow['ref'] . "'";
|
|
|
+ } else {
|
|
|
+ $crossShoppingFacturesString .= ",'" . $factureCSRow['ref'] . "'";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
$params = ["from" => $from, "to" => $to, "factures" => $crossShoppingFacturesString];
|
|
|
$postFields = json_encode($params);
|
|
|
$crossShoppingFactures = $this->curlRunner('bookingapi/getPrintedFacturesRefs', $postFields, 'POST', true);
|
|
|
global $db;
|
|
|
$commissions = 0;
|
|
|
- $sql = "SELECT f.rowid, f.total_ttc, fe.commission, f.ref, bbt.rowid as bbt_rowid, bbtip.rowid as bbtip_rowid
|
|
|
+ $sql = "SELECT f.rowid, f.total_ttc, fe.commission, f.ref, f.date_closing
|
|
|
FROM llx_facture as f
|
|
|
INNER JOIN llx_facture_extrafields as fe ON fe.fk_object = f.rowid
|
|
|
- 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 ";
|
|
|
+ INNER JOIN llx_bbus_bbticketinvoiceprinting as bbtip ON bbtip.invoice_number = f.ref WHERE ";
|
|
|
if ($crossShoppingFactures != '') {
|
|
|
$sql .= " f.ref not in ({$crossShoppingFactures}) AND";
|
|
|
}
|
|
|
@@ -149,16 +249,15 @@ class CommissionHandler
|
|
|
fk_user_closing = {$user_id}
|
|
|
AND multicurrency_code = '{$currency}'
|
|
|
AND fe.commission_deduction is NULL
|
|
|
- AND date_closing BETWEEN '{$from}' AND '{$to}'";
|
|
|
+ AND date_closing BETWEEN '{$from}' AND '{$to}'
|
|
|
+ GROUP BY f.rowid, f.total_ttc, fe.commission, f.ref";
|
|
|
//print $sql;
|
|
|
$result = $db->query($sql);
|
|
|
if ($db->num_rows($result) != 0) {
|
|
|
while ($row = pg_fetch_assoc($result)) {
|
|
|
- if (is_null($row['bbt_rowid']) || !is_null($row['bbtip_rowid'])) {
|
|
|
- $commissions += $this->getAmountOfCommission($row);
|
|
|
+ $commissions += $this->getAmountOfCommission($row);
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
if ($crossShoppingFactures != '') {
|
|
|
$sqlCS = "SELECT f.rowid, f.total_ttc, fe.commission, f.ref
|
|
|
FROM llx_facture as f
|