Example #1
0
 function getComandesEstadistiques($idSessio, $TipusPagament = '-', $TipusComanda = '-', $Totals = 'S', $LlocCompra = '-', $Mesi = array(), $Mesf = array())
 {
     $W = array();
     $SQL = array();
     $SQL[] = "SELECT c.*, l.*, e.*, s.* \n                   FROM comandes c \n                  INNER JOIN localitats l on l.l_idComanda = c.co_idComanda\n                  INNER JOIN sessions s on l.l_idSessio = s.s_id\n                  INNER JOIN espectacles e on e.e_id = s.s_idEspectacle\n                 WHERE c.co_estat in ('P')";
     if ($idSessio > 0) {
         $W['idSessio'] = filter_var($idSessio, FILTER_SANITIZE_NUMBER_INT);
         $SQL[] = "   AND l.l_idSessio = :idSessio";
     }
     if ($TipusPagament != '-') {
         $W['TipusPagament'] = $TipusPagament;
         $SQL[] = "   AND c.co_TipusPagament = :TipusPagament";
     }
     if ($TipusComanda != '-') {
         $W['TipusComanda'] = $TipusComanda;
         $SQL[] = "   AND c.co_TipusComanda = :TipusComanda";
     }
     if ($LlocCompra != '-') {
         $W['LlocCompra'] = $LlocCompra;
         $SQL[] = "   AND c.co_LlocCompra = :LlocCompra";
     }
     if (!$Mesi->isEmpty()) {
         $W['Datai'] = $Mesi->getUnixTimestamp(true);
         $SQL[] = "   AND s.s_DataHora >= :Datai";
     }
     if (!$Mesf->isEmpty()) {
         $W['Dataf'] = $Mesf->getUnixTimestamp(false);
         $SQL[] = "   AND s.s_DataHora <= :Dataf";
     }
     $SQL[] = " ORDER BY c.co_data desc";
     //Surt per espectacle, quantes n'hi ha de cada...
     $LlistatComandesSeients = $this->db->select(implode(" ", $SQL), $W);
     $Detall = array();
     $Totals = array();
     $TotalDia = array();
     //Si no vull totals, només vull un llistat de totes les compres que hi ha hagut últimament
     foreach ($LlistatComandesSeients as $ComandaSeient) {
         //************** Càlcul de detall **********************
         $CTO = new ComandaTableObject($ComandaSeient, ComandaTableObject::FROM_BDD);
         $LTO = new LocalitatTableObject($ComandaSeient, LocalitatTableObject::FROM_BDD);
         $STO = new SessioTableObject($ComandaSeient, SessioTableObject::FROM_BDD);
         $ETO = new EspectacleTableObject($ComandaSeient, EspectacleTableObject::FROM_BDD);
         $idC = $ComandaSeient['co_idComanda'];
         $idS = $ComandaSeient['l_idSessio'];
         $OP = $LTO->getPreu();
         if (!isset($Detall[$idC])) {
             $Detall[$idC]['Comanda'] = $CTO;
         }
         $Detall[$idC]['Localitats'][] = $LTO;
         if (!isset($Detall[$idC]['Sessions'][$idS])) {
             $Detall[$idC]['Sessions'][$idS] = array('sessio' => $STO, 'espectacle' => $ETO);
         }
         //************** Càlcul de totals **********************
         $Dia = date('d-m-Y', $CTO->comanda['co_data']);
         if (!isset($TotalDia[$Dia])) {
             $TotalDia[$Dia] = array('dia' => $Dia, 'TS' => array());
         }
         if (!isset($TotalDia[$Dia]['TS'][$idS])) {
             $TotalDia[$Dia]['TS'][$idS] = array('sessio' => $STO, 'espectacle' => $ETO, 'co_TipusComanda' => array(), 'co_TipusPagament' => array(), 'co_LlocCompra' => array(), 'l_idPreu' => array('Total' => array('nom' => 'Total', 'quantitat' => 0, 'import' => 0)));
         }
         if (!isset($Totals[$idS])) {
             $Totals[$idS] = array('sessio' => $STO, 'espectacle' => $ETO, 'co_TipusComanda' => array(), 'co_TipusPagament' => array(), 'co_LlocCompra' => array(), 'l_idPreu' => array('Total' => array('nom' => 'Total', 'quantitat' => 0, 'import' => 0)));
         }
         $name = "co_TipusComanda";
         $valor = $ComandaSeient[$name];
         if (!isset($Totals[$idS][$name][$valor])) {
             $Totals[$idS][$name][$valor] = array('text' => $CTO->getTipusComandaString(), 'total' => 0);
         }
         if (!isset($TotalDia[$Dia]['TS'][$idS][$name][$valor])) {
             $TotalDia[$Dia]['TS'][$idS][$name][$valor] = array('text' => $CTO->getTipusComandaString(), 'total' => 0);
         }
         $Totals[$idS][$name][$valor]['total']++;
         $TotalDia[$Dia]['TS'][$idS][$name][$valor]['total']++;
         if ($LTO->localitat['l_estat'] == LocalitatTableObject::ESTAT_OCUPADA) {
             $name = "co_LlocCompra";
             $valor = $ComandaSeient[$name];
             if (!isset($Totals[$idS][$name][$valor])) {
                 $Totals[$idS][$name][$valor] = array('text' => $CTO->getTipusLlocCompraString(), 'total' => 0);
             }
             if (!isset($TotalDia[$Dia]['TS'][$idS][$name][$valor])) {
                 $TotalDia[$Dia]['TS'][$idS][$name][$valor] = array('text' => $CTO->getTipusLlocCompraString(), 'total' => 0);
             }
             $Totals[$idS][$name][$valor]['total']++;
             $TotalDia[$Dia]['TS'][$idS][$name][$valor]['total']++;
             $name = "co_TipusPagament";
             $valor = $ComandaSeient[$name];
             if (!isset($Totals[$idS][$name][$valor])) {
                 $Totals[$idS][$name][$valor] = array('text' => $CTO->getTipusPagamentString(), 'total' => 0);
             }
             if (!isset($TotalDia[$Dia]['TS'][$idS][$name][$valor])) {
                 $TotalDia[$Dia]['TS'][$idS][$name][$valor] = array('text' => $CTO->getTipusPagamentString(), 'total' => 0);
             }
             $Totals[$idS][$name][$valor]['total']++;
             $TotalDia[$Dia]['TS'][$idS][$name][$valor]['total']++;
             $name = "l_idPreu";
             $valor = $OP->preu['nom'];
             if (!isset($Totals[$idS][$name][$valor])) {
                 $Totals[$idS][$name][$valor] = array('nom' => $OP->preu['nom'], 'quantitat' => 0, 'import' => 0);
             }
             if (!isset($TotalDia[$Dia]['TS'][$idS][$name][$valor])) {
                 $TotalDia[$Dia]['TS'][$idS][$name][$valor] = array('nom' => $OP->preu['nom'], 'quantitat' => 0, 'import' => 0);
             }
             $Totals[$idS][$name][$valor]['import'] += $OP->preu['import'];
             $Totals[$idS][$name][$valor]['quantitat']++;
             $Totals[$idS][$name]['Total']['import'] += $OP->preu['import'];
             $Totals[$idS][$name]['Total']['quantitat']++;
             $TotalDia[$Dia]['TS'][$idS][$name][$valor]['import'] += $OP->preu['import'];
             $TotalDia[$Dia]['TS'][$idS][$name][$valor]['quantitat']++;
             $TotalDia[$Dia]['TS'][$idS][$name]['Total']['import'] += $OP->preu['import'];
             $TotalDia[$Dia]['TS'][$idS][$name]['Total']['quantitat']++;
         }
     }
     $RET = array('Detall' => $Detall, 'Totals' => $Totals, 'TotalDia' => $TotalDia);
     return $RET;
 }