/** * 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); } } } }
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; }
/** * Aquesta funció genera una nova comanda còpia de l'actual amb un codi nou per enviar al TPV. **/ public function generaNovaComanda() { //Creo una nova comanda $CTO = new ComandaTableObject(null, ComandaTableObject::FROM_EMPTY); $CTO->newComandaId($this->comanda['co_TipusPagament'], $this->comanda['co_LlocCompra'], $this->comanda['co_TipusComanda']); //Canviem els codis de comanda pel nou codi de comanda i també actualitzo $this->db->update("localitats", array('l_idComanda' => $CTO->getComandaId()), array('l_idComanda' => $this->getComandaId())); $this->comanda['co_idComanda'] = $CTO->getComandaId(); $this->comanda['co_Codi'] = $CTO->comanda['co_Codi']; }
/** * Funció que genera una entrada i ho guarda al pdf amb el codi de comanda * @return $RET['mail','Html','FILE_URL'] **/ public static function generateEntrades(ComandaTableObject $CTO, $WebPrint = false) { $LlistatLocalitats = $CTO->getLlistatLocalitats(); if (sizeof($LlistatLocalitats) > 0) { $RET = self::generaEntradaFromLocalitats($LlistatLocalitats, $CTO); //$RET['Mail']->send(); //Si he demanat impressió web,surto per html if ($WebPrint) { header('Content-Type: application/pdf'); header('Content-Disposition: inline; filename="' . $RET['FILE_URL'] . '"'); header('Content-Transfer-Encoding: binary'); header('Content-Length: ' . filesize($RET['FILE_URL'])); header('Accept-Ranges: bytes'); @readfile($RET['FILE_URL']); } } return $RET; }
public function getComanda() { $R = $this->getAjaxData(); //És una edició i envio la info d'aquesta comanda if (isset($R['idComanda'])) { $CTO = new ComandaTableObject(); $CTO->loadComanda($R['idComanda']); //És una comanda que carrego de la sessió. Pot ser que encara no l'hagi creada, llavors no la carrego. //La Comanda es crea a setLocalitat quan algú clica una localitat. } else { //Carrego les comandes guardades i segueixo $CTO = new ComandaTableObject(); if ($CTO->hasComandaSession()) { $CTO->loadComanda(); } } $Localitats = $CTO->getLlistatLocalitats(); //Ha d'anar separat perquè a dins calculo el total de la comanda $RET = array('Comanda' => $CTO, 'Localitats' => $Localitats); echo json_encode($RET); }
public static function validaPagamentTPV($Ds_SignatureVersion, $Ds_MerchantParameters, $Ds_Signature, $getTPV = false) { //Creem objecte $RedSysTmp = new RS(); //Aquest el creem per carregar les dades inicials $RedSys = new RS(); //Aquest tindrà les dades tant si entrem per tpv com si no hi entrem $Config = Json::loadJsonConfigFile('config.json'); $CTO = new ComandaTableObject(); //Descodifiquem i passem a array els paràmetres $decode = $RedSysTmp->decodeMerchantParameters($Ds_MerchantParameters); $RedSysTmp->stringToArray($decode); //Si entrem sense haver passat pel TPV ( o sigui, metàl·lic o reserva o 0 euros ) $Par = array('Error' => ""); if (isset($RedSysTmp->vars_pay['Ds_Merchant_MerchantData'])) { foreach ($RedSysTmp->vars_pay as $K => $V) { $tmp = str_replace("_Merchant_", "_", $K); $RedSys->setParameter($tmp, $V); } $RedSys->setParameter('Ds_Response', '0000'); $RedSys->setParameter('Ds_Order', '0'); $RedSys->setParameter('Ds_AuthorisationCode', '0'); } else { //No cal fer cap canvi, simplement ho passo tot junt $RedSys = $RedSysTmp; } //Carreguem la id de l'entrada i comencem el procés $tmp = explode('-', $RedSys->getParameter('Ds_MerchantData')); if (!isset($tmp[1])) { $Par['Error'] = "ENTRADA"; } else { $Par['idComanda'] = intval($tmp[1]); $idComanda = $Par['idComanda']; $CTO->loadComanda($tmp[1]); if ($CTO->getComandaId() > 0) { //Generem la signatura $signatura_rebuda = $Ds_Signature; //Només generem la signatura si entrem per TPV sinó la validem automàticament $signatura_generada = $signatura_rebuda; if (!isset($RedSysTmp->vars_pay['Ds_Merchant_MerchantData'])) { $signatura_generada = $RedSys->createMerchantSignatureNotif($Config['TPV_ENT_PASSWORD'], $Ds_MerchantParameters); } //Si la signatura és correcta i no ha donat error, marquem la matrícula com a pagada if ($signatura_rebuda != $signatura_generada) { $Par['Error'] = "SIGNATURA"; } elseif ($RedSys->getParameter('Ds_Response') != '0000') { $Par['Error'] = "RESPONSE"; } else { //Si estem a la crida automàtica del GetTPV fem les tasques que toquen if ($getTPV) { $CTO->comanda['co_estat'] = ComandaTableObject::TIPUS_ESTAT_PAGAT; $CTO->comanda['co_TpvCode'] = $RedSys->getParameter('Ds_AuthorisationCode'); $CTO->comanda['co_TpvOrder'] = $RedSys->getParameter('Ds_Order'); $CTO->doSave(); //Guardem les dades de la targeta $CTO->doMarcarPagatsOK(); //Tots els seients en estat P, passen a O //Actualitzem les places lliures foreach (array_keys($CTO->getLlistatLocalitats()) as $idSessio) { //Carreguem les sessions de la comanda i actualitzem $STO = new SessioTableObject(null, SessioTableObject::FROM_EMPTY); $STO->loadById($idSessio); //Carrego els seients lliures i els guardo $STO->updateLocalitatsLliures(); } //Només enviem el correu amb entrades si és una venda i existeix el correu. self::sendEmailComanda($CTO); } } } else { $Par['Error'] = 'COMANDA'; } } $Par['Ds_Response'] = $RedSys->getParameter('Ds_Response'); $Par['Ds_MerchantData'] = $RedSys->getParameter('Ds_MerchantData'); $Par['CTO'] = $CTO; return $Par; }
public function setLocalitatClick($idLocalitat, $Accio) { //Carreguem la possible comanda on s'haurà de registrar $CTO = new ComandaTableObject(); $CTO->loadComanda(); //Carrego la localitat o en creo una de nova $this->loadLocalitatByIdString($idLocalitat, $CTO->getComandaId()); //Fem l'update $e = $this->localitat['l_estat']; switch ($Accio) { case self::ACCIO_VENTA: if ($e == 'L') { $this->updateLocalitat($CTO, 'P'); } elseif ($e == 'P' && $this->IsModificable($CTO) && $this->inTempsPreCompra()) { $this->updateLocalitat($CTO, 'L'); } elseif ($e == 'P' && !$this->inTempsPreCompra()) { $this->updateLocalitat($CTO, 'P'); } elseif ($e == 'R' && $this->IsModificable($CTO)) { $this->updateLocalitat($CTO, 'P'); } elseif ($e == 'O' && $this->IsModificable($CTO)) { $this->updateLocalitat($CTO, 'L'); } break; case self::ACCIO_RESERVA: if ($e == 'L') { $this->updateLocalitat($CTO, 'P'); } elseif ($e == 'P' && $this->inTempsPreCompra() && $this->IsModificablePreCompra($CTO)) { $this->updateLocalitat($CTO, 'L'); } elseif ($e == 'P' && !$this->inTempsPreCompra()) { $this->updateLocalitat($CTO, 'P'); } elseif ($e == 'R' && $this->IsModificable($CTO)) { $this->updateLocalitat($CTO, 'L'); } elseif ($e == 'O' && $this->IsModificable($CTO)) { $this->updateLocalitat($CTO, 'O'); } break; case self::ACCIO_BAIXA: if ($e == 'L') { $this->updateLocalitat($CTO, 'L'); } elseif ($e == 'P' && $this->IsModificablePreCompra($CTO)) { $this->updateLocalitat($CTO, 'L'); } elseif ($e == 'R' && $this->IsModificable($CTO)) { $this->updateLocalitat($CTO, 'L'); } elseif ($e == 'O' && $this->IsModificable($CTO)) { $this->updateLocalitat($CTO, 'L'); } break; } $this->doSave(); }