Exemplo n.º 1
0
 public function generaMailEntrada($idEntrada, $idS = 1)
 {
     $OM = new OptionsModel();
     $TEXT = $OM->getOption('BODY_MAIL_ENTRADES', $idS);
     $EM = new EntradesModel();
     $OE = $EM->getEntradaById($idEntrada);
     $OA = $EM->getActivitatById($OE['idEspectacle']);
     $TEXT = str_replace('{{NUM_ENTRADES}}', $OE['num_entrades'], $TEXT);
     $TEXT = str_replace('{{ACTIVITAT}}', $OA['Nom'], $TEXT);
     $TEXT = str_replace('{{DIA}}', $OA['Dia'], $TEXT);
     $TEXT = str_replace('{{HORA}}', $OA['Hora'], $TEXT);
     $TEXT = str_replace('{{NOM_COMPRA}}', $OE['nom_reserva'], $TEXT);
     \Helpers\MyHelpers\Pdf::generateEntrada($EM->EntradaObject($OE, true));
     $URL = self::$URL_ENTRADES . $OE['idEntrada'] . '.pdf';
     $this->enviaMail('*****@*****.**', '*****@*****.**', 'Entrada per a un espectacle', $TEXT, $URL);
     return $this->enviaMail('*****@*****.**', $OE['email_reserva'], 'Entrada per a un espectacle', $TEXT, $URL);
 }
Exemplo n.º 2
0
 public static function generateEntrada($OE)
 {
     $inici = '9099921002998';
     $entitat = '0330056';
     $idM = $OE['idEntrada'];
     $codiClient = $OE['usuari_id'] > 0 ? $OE['usuari_id'] : "-";
     $dataFactura = D::ConvertData(explode(" ", $OE['data'])[0], false);
     $tipusPagament = $OE['tipus_pagament'];
     $usuari_nom = $OE['nom_reserva'];
     $usuari_email = $OE['email_reserva'];
     $usuari_telefon = $OE['telefon_reserva'];
     if ($OE['usuari_id'] > 0) {
         $UM = new UsuarisModel();
         $OU = $UM->getUsuariById($OE['usuari_id']);
         $usuari_email = $OU[0]['Email'];
         $usuari_telefon = $OU[0]['Mobil'];
         $usuari_nom = $OU[0]['Nom'] . ', ' . $OU[0]['Cog1'] . ' ' . $OU[0]['Cog2'];
     }
     $EM = new EntradesModel();
     $OA = $EM->getActivitatById($OE['idEspectacle']);
     $nom_espectacle = $OA['Nom'];
     $entrades = json_decode($OE['entrades'], true);
     $num_entrades_normal = $entrades[0]['quantitat'];
     $num_entrades_descompte = $entrades[1]['quantitat'];
     $preu_normal = $OA['Preus'][0]['Preu'] * $entrades[0]['quantitat'];
     $preu_descompte = $OA['Preus'][1]['Preu'] * $entrades[1]['quantitat'];
     $referencia = str_pad(strval($idM), 11, '0', STR_PAD_LEFT);
     //Càlcul de valor de check
     $ponderacions = array(10 => 2, 9 => 3, 8 => 4, 7 => 5, 6 => 6, 5 => 7, 4 => 8, 3 => 9, 2 => 2, 1 => 3, 0 => 4);
     $tot = 0;
     for ($i = 10; $i >= 0; $i--) {
         $tot += $referencia[$i] * $ponderacions[$i];
     }
     $cc = $tot % 11;
     if ($cc == 10) {
         $cc = 0;
     }
     //Afegim el valor de check a la referència i seguim.
     $referencia .= $cc;
     $import = str_pad(strval($OE['pagat'] * 100), 10, '0', STR_PAD_LEFT);
     $codi = $inici . $entitat . $referencia . $import;
     $barcodeobj = new \Helpers\Tcpdf\TCPDFBarcode($codi, 'C128');
     $barcodepng = $barcodeobj->getBarcodePNGData(1, 40, array(0, 0, 0));
     file_put_contents(self::$URL_ENTRADES . $idM . '.png', $barcodepng);
     $p = new tcpdf(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
     // set document information
     $p->SetCreator(PDF_CREATOR);
     $p->SetAuthor('Casa de Cultura de Girona');
     $p->SetTitle('CCG');
     $p->SetSubject('CCG');
     $p->SetKeywords('CCG');
     //$p->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
     $p->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
     $p->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
     $p->setImageScale(PDF_IMAGE_SCALE_RATIO);
     $p->SetFont('dejavusans', '', 10);
     $p->AddPage();
     $html = '
                 <table style="width:100%">
                     <tr>
                         <td style="width:30%; text-align:center;">
                             <img src="' . self::$URL_HOSPICI . 'images/front/logo_ccg.jpg" />
                             <div style="font-size:7px;">
                                 Plaça de l\'hospital, 6 – 17001 Girona<br />
                                 TELÈFON 972 20 20 13 FAX 972 21 37 72<br />
                                 HORARI DE SECRETARIA de 9 a 14h i de 16 a 20h<br />
                                 A/E secretaria@casadecultura.org<br />WEB www.casadecultura.org
                             </div>
                         </td>
                         <td style="width:70%; text-align:center;">
                             <div style="font-size:10px;">Si pagueu amb codi de barres, podeu anar a un caixer de <b>CaixaBank</b>, entreu la targeta, cliqueu la icona "Codi de Barres" i seguiu les instruccions per pantalla.</div>
                             <div><img src="' . self::$URL_HOSPICI . 'documents/entrades/' . $idM . '.png" /></div>
                             <div>' . $codi . '<br />
                                 ENTITAT: ' . $entitat . ' REFERÈNCIA: ' . $referencia . ' IMPORT: ' . $OE['pagat'] . '€
                             </div>
                         </td>
                     </tr>
                 </table>
                 <br /><br />
                 <div style="background-color: #ffece5; height:1px; width:100%"></div>
                 <br />
                 <h1 style="color: #cc3300">DADES FACTURA</h1>
                 <table style="width:100%">
                     <tr>
                         <td>Núm factura: E-' . $idM . '</td>
                         <td>Codi client: ' . $codiClient . '</td>
                         <td>Data factura: ' . $dataFactura . '</td>        
                     </tr>
                     <tr>
                         <td>Tipus pagament: ' . $tipusPagament . '</td>
                     </tr>
                 </table>
                 <br /><br />
                 <h1 style="color: #cc3300">DADES USUARI</h1>
                 <table style="width:100%">
                     <tr>
                         <td>Nom: ' . $usuari_nom . '</td>
                         <td>Telèfon: ' . $usuari_telefon . '</td>
                         <td>Email: ' . $usuari_email . '</td>        
                     </tr>    
                 </table>
                 <br /><br />
                 <h1 style="color: #cc3300">DETALL</h1>
                 <table style="border:1px solid #cc3300; border-collapse:collapse;">
                     <tr>
                         <td style="width:55%; color:white; background-color: #cc3300">Descripció</td>
                         <td style="width:15%; color:white; background-color: #cc3300">Preu</td>
                         <td style="width:15%; color:white; background-color: #cc3300">Quantitat</td>
                         <td style="width:15%; color:white; background-color: #cc3300">Import</td>        
                     </tr>
                     <tr>
                         <td style="height:70px; border:1px solid #cc3300;">' . $nom_espectacle . '<br /><i>Data: ' . $OA['Dia'] . ' ' . $OA['Hora'] . '</i></td>
                         <td style="border:1px solid #cc3300;">' . $OA['Preus'][0]['Preu'] . '€</td>
                         <td style="border:1px solid #cc3300;">' . $num_entrades_normal . '</td>
                         <td style="border:1px solid #cc3300;">' . $preu_normal . '€</td>        
                     </tr>';
     if ($num_entrades_descompte > 0) {
         $html .= '
                     <tr>
                         <td style="height:70px; border:1px solid #cc3300;">Entrades amb descompte<br /></td>
                         <td style="border:1px solid #cc3300;">' . $OA['Preus'][1]['Preu'] . '€</td>
                         <td style="border:1px solid #cc3300;">' . $num_entrades_descompte . '</td>
                         <td style="border:1px solid #cc3300;">' . $preu_descompte . '€</td>        
                     </tr>';
     }
     $html .= '
                     <tr>
                         <td></td>
                         <td></td>
                         <td style="border-left:1px solid #cc3300;">Subtotal</td>
                         <td>' . $OE['pagat'] . '€</td>        
                     </tr>
                     <tr>
                         <td></td>
                         <td></td>
                         <td style="border-left:1px solid #cc3300;">IVA</td>
                         <td>0€</td>        
                     </tr>
                     <tr>
                         <td></td>
                         <td></td>
                         <td style="border-left:1px solid #cc3300;">Total</td>
                         <td>' . $OE['pagat'] . '€</td>        
                     </tr>
                 </table>
                 <br /><br /><br />
                 <div>FUNDACIÓ CASA DE CULTURA DE GIRONA, CIF G-17759887<br />Registre de Fundacions de la Generalitat de Catalunya, núm. 2020</div>
     ';
     $p->writeHTML($html);
     $p->lastPage();
     $p->Output('/var/www/hospici_cultural/web/documents/entrades/' . $idM . '.pdf', 'F');
 }
 public function doPagament()
 {
     $postdata = file_get_contents("php://input");
     $request = json_decode($postdata, true);
     //Comprovem que existeix l'espectacle
     $OE = $request['entrada'];
     $EM = new EntradesModel();
     $OA = $EM->getActivitatById($OE['idEspectacle']);
     if ($OA['id'] == 0) {
         throw new MyException("L'espectacle " . $OA['id'] . " escollit no existiex. Contacti amb la Casa de Cultura si us plau.");
     }
     $OE['tipus_pagament'] = 'targeta';
     $OE['estat'] = 'PRE';
     $OE = $EM->EntradaObject($OE, true);
     $idEntrada = $EM->saveEntrada($OE);
     //Passo a fer el pagament
     $OM = new OptionsModel();
     $MerchantCode = $OM->getOption('TPV_Ds_Merchant_MerchantCode');
     $Password = $OM->getOption('TPV_ENT_PASSWORD');
     $idReserva = $idEntrada;
     $amount = intval($OE['pagat']) * 100;
     $Order = 'E-' . str_pad(strval($idEntrada), 8, "0", STR_PAD_LEFT);
     //E-IdMatrícula
     $Currency = '978';
     $terminal = '1';
     $TransactionType = '0';
     $DsMerchantURLOK = $OM->getOption('TPV_ENT_Ds_Merchant_UrlOK');
     $DsMerchantURLKO = $OM->getOption('TPV_ENT_Ds_Merchant_UrlKO');
     $DsMerchantURL = $OM->getOption('TPV_ENT_Merchant_Merchant');
     $ProductDescription = 'Entrada';
     $Titular = "Nom que compra entrada";
     $MerchantName = $OM->getOption('TPV_MerchantName');
     $MerchantData = $Order;
     $URLTPV = $OM->getOption('TPV_ENT_URL');
     //Preparem dades per enviar i signar
     $RedSys = new RS();
     $RedSys->setParameter('Ds_Merchant_Amount', $amount);
     $RedSys->setParameter('Ds_Merchant_Order', $Order);
     $RedSys->setParameter('Ds_Merchant_MerchantCode', $MerchantCode);
     $RedSys->setParameter('Ds_Merchant_Currency', $Currency);
     $RedSys->setParameter('Ds_Merchant_TransactionType', $TransactionType);
     $RedSys->setParameter('Ds_Merchant_Terminal', $terminal);
     $RedSys->setParameter('Ds_Merchant_MerchantURL', $DsMerchantURL);
     $RedSys->setParameter('Ds_Merchant_UrlOK', $DsMerchantURLOK);
     $RedSys->setParameter('Ds_Merchant_UrlKO', $DsMerchantURLKO);
     $RedSys->setParameter('Ds_Merchant_ProductDescription', $ProductDescription);
     $RedSys->setParameter('Ds_Merchant_Titular', $Titular);
     $RedSys->setParameter('Ds_Merchant_MerchantName', $MerchantName);
     $RedSys->setParameter('Ds_Merchant_MerchantData', $MerchantData);
     $TPV = array();
     $TPV['TPV']['Ds_SignatureVersion'] = 'HMAC_SHA256_V1';
     $TPV['TPV']['Ds_MerchantParameters'] = $RedSys->createMerchantParameters();
     $TPV['TPV']['Ds_Signature'] = $RedSys->createMerchantSignature($Password);
     $TPV['URL'] = $URLTPV;
     echo json_encode($TPV);
 }