Exemple #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;
 }
Exemple #2
0
 /**
  * Funció que imprimeix les entrades d'una sessió en una sola comanda. 
  **/
 function printAllEntrades()
 {
     $R = $this->getAjaxData();
     //Carrego la sessió que vull imprimir totes les entrades
     $STO = new SessioTableObject(null, SessioTableObject::FROM_EMPTY);
     $STO->loadById($R['idSessio']);
     //per totes les localitats de la sessió, les marco com ocupades i venudes en metàl·lic.
     //Carrego el teatre
     $TTO = new TeatreTableObject(null, TeatreTableObject::FROM_EMPTY);
     $TTO->loadById($STO->sessio['s_idTeatre']);
     $planol = $TTO->getPlanol();
     foreach ($planol['zones'] as $idZ => $Z) {
         foreach ($Z['files'] as $idF => $F) {
             //Creo una nova comanda i començo a vendre les entrades
             $CTO = new ComandaTableObject(null, ComandaTableObject::FROM_EMPTY);
             $CTO->newComandaId(ComandaTableObject::TIPUS_PAGAMENT_METALIC, ComandaTableObject::TIPUS_LLOCCOMPRA_TAQUILLA, ComandaTableObject::TIPUS_COMANDA_VENTA);
             //Repassem els seients ( si la línia és en blanc, exist serà false )
             $exist = false;
             foreach ($F['seients'] as $idS => $S) {
                 //Per cada seient, faig una venda.
                 $id = $Z['codi'] . '-' . intval($F['num_fila']) . '-' . intval($S['numero']) . '-' . $STO->getSessioId();
                 if ($S['numero'] > 0 && $S['tipus'] == 'planol-cercle') {
                     $LTO = new LocalitatTableObject(null, LocalitatTableObject::FROM_EMPTY);
                     $LTO->loadLocalitatByIdString($id);
                     $LTO->updateLocalitat($CTO, LocalitatTableObject::ESTAT_OCUPADA);
                     $LTO->doSave();
                     $exist = true;
                 }
             }
             //Si la línia no és en blanc i hi ha seients la guardem
             if ($exist) {
                 $CTO->comanda['co_estat'] = ComandaTableObject::TIPUS_ESTAT_PAGAT;
                 $CTO->doMarcarPagatsOK();
                 $CTO->doSave();
                 $CTO->loadComanda();
                 Pdf::generateEntrades($CTO, false);
             }
         }
     }
 }
Exemple #3
0
 public function setNewPreuLocalitat()
 {
     $R = $this->getAjaxData();
     $LTO = new LocalitatTableObject($R['Localitat'], LocalitatTableObject::FROM_JSON);
     $OP = new PreuObject($R['Preu'], PreuObject::FROM_JSON);
     $LTO->setPreu($OP);
     $LTO->doSave();
 }
 /**
  * Aquesta funció es crida quan es carrega una comanda i queda guardada.
  **/
 private function getLocalitats($LlistatLocalitats)
 {
     $SES = array();
     $this->comanda['co_PreuFinal'] = 0;
     //Posem el preu final a 0 abans de sumar els totals
     foreach ($LlistatLocalitats as $L) {
         if (!empty($L['l_idSessio'])) {
             $this->localitats[$L['s_id']]['SessioData'] = new SessioTableObject($L, SessioTableObject::FROM_BDD);
             $LTO = new LocalitatTableObject($L, LocalitatTableObject::FROM_BDD);
             $this->localitats[$L['s_id']]['Localitats'][] = $LTO;
             if (!isset($this->localitats[$L['s_id']]['PreuFinal'])) {
                 $this->localitats[$L['s_id']]['PreuFinal'] = 0;
             }
             $this->localitats[$L['s_id']]['PreuFinal'] += $LTO->getPreuValor();
             $this->comanda['co_PreuFinal'] += $LTO->getPreuValor();
         }
     }
 }
 /**
  * Funció que retorna les localitats
  **/
 public function getLocalitats()
 {
     $OL = $this->db->select('SELECT l.* FROM localitats l WHERE l.l_idSessio = :id', array('id' => $this->getSessioId()));
     $RET = array();
     foreach ($OL as $Row) {
         $LTO = new LocalitatTableObject($Row, LocalitatTableObject::FROM_BDD);
         $RET[$LTO->getLocalitatIdSring()] = $LTO;
     }
     return $RET;
 }