示例#1
0
function generarFactura($reserva, $hotel, $negativo = false)
{
    try {
        global $template_dir;
        global $template_url;
        global $app_dir;
        global $smarty;
        $campania = getCampania($hotel->campaniaId);
        $reserva->id = decryptId($reserva->id);
        if ($negativo) {
            $factura = getFacturaByIdReserva($reserva->id);
            if ($factura) {
                $negativo = $factura->id;
                $numeroFactura = 'R-' . $factura->numero;
            } else {
                return false;
            }
        } else {
            $count = DAOFactory::getFacturaDAO()->countByYear(intval(date('Y')), $campania->localizador);
            $count = '' . $count[0][0];
            $count++;
            while (strlen($count) < 4) {
                $count = '0' . $count;
            }
            $numeroFactura = $count . '-' . $campania->localizador . '-' . date('Y');
        }
        insertFactura($hotel->id, array($reserva->id), "cobrado", $negativo);
        $smarty->assign('numero', $numeroFactura);
        $smarty->assign('reserva', $reserva);
        $smarty->assign('hotel', $hotel);
        $smarty->assign('negativo', $negativo);
        $content = $smarty->fetch('reserva_factura.tpl');
        $filename = $app_dir . '/cache/factura_' . time() . '.pdf';
        Html2PdfWriter::write($content, $filename);
        return $filename;
    } catch (Exception $e) {
        print_r($e);
        return false;
    }
}
示例#2
0
function cambiarEstadoFactura($id, $estado)
{
    try {
        $factura = DAOFactory::getFacturaDAO()->prepare(array('estado' => $estado), $id);
        DAOFactory::getFacturaDAO()->update($factura);
        return true;
    } catch (Exception $e) {
        var_dump($e);
        return false;
    }
}