예제 #1
0
 public static function NombreDocumentoBaseFromId($id)
 {
     $v = DocumentoBaseDAO::getByPK($id);
     if (is_null($v)) {
         return R::NonExistent();
     }
     return $v->getNombre();
 }
예제 #2
0
<?php

define("BYPASS_INSTANCE_CHECK", false);
require_once "../../../server//bootstrap.php";
$page = new GerenciaComponentPage();
$q = DocumentoBaseDAO::getByPK($_GET["dbid"]);
$page->addComponent(new TitleComponent($q->getNombre(), 2));
$q->setJsonImpresion(str_replace("\\n", "", $q->getJsonImpresion()));
$q->setJsonImpresion(str_replace("\\t", "", $q->getJsonImpresion()));
$q->setJsonImpresion(stripslashes($q->getJsonImpresion()));
$q->setJsonImpresion(substr($q->getJsonImpresion(), 1, -1));
$tabla = new DAOFormComponent($q);
$tabla->setEditable(true);
$tabla->renameField(array("id_documento_base" => "id_documento"));
$tabla->hideField(array("id_documento", "ultima_modificacion"));
$tabla->sendHidden("id_documento");
$tabla->setType("json_impresion", "textarea");
$tabla->addApiCall("api/documento/editar", "POST");
$tabla->onApiCallSuccessRedirect("documentos.ver.php?dbid=" . $_GET["dbid"]);
$page->addComponent($tabla);
$page->render();
예제 #3
0
 public static function Documento($id_documento, $preview = FALSE, $params = NULL)
 {
     $dbase = DocumentoBaseDAO::getByPK($id_documento);
     $dbase->setJsonImpresion(str_replace("\\n", "", $dbase->getJsonImpresion()));
     $dbase->setJsonImpresion(str_replace("\\t", "", $dbase->getJsonImpresion()));
     $dbase->setJsonImpresion(stripslashes($dbase->getJsonImpresion()));
     if ("\"" == substr($dbase->getJsonImpresion(), 0, 1)) {
         $dbase->setJsonImpresion(substr($dbase->getJsonImpresion(), 1, -1));
     }
     $decoded_json = json_decode($dbase->getJsonImpresion());
     #echo $dbase->getJsonImpresion(); die;
     if (is_null($decoded_json)) {
         throw new InvalidDataException("json invalido");
     }
     $pdf = new Cezpdf(array(0, 0, $decoded_json->width, $decoded_json->height));
     if (is_file(POS_PATH_TO_SERVER_ROOT . "libs/ezpdf/fonts/Helvetica.afm")) {
         $pdf->selectFont(POS_PATH_TO_SERVER_ROOT . "libs/ezpdf/fonts/Helvetica.afm");
     } else {
         throw new Exception();
     }
     for ($i = 0; $i < sizeof($decoded_json->body); $i++) {
         switch ($decoded_json->body[$i]->type) {
             case "text":
                 if (!$preview) {
                     while (($posI = strpos($decoded_json->body[$i]->value, "{")) !== FALSE) {
                         $posF = strpos($decoded_json->body[$i]->value, "}");
                         $key = substr($decoded_json->body[$i]->value, $posI + 1, $posF - $posI - 1);
                         if (TRUE === array_key_exists($key, $params)) {
                             $decoded_json->body[$i]->value = substr_replace($decoded_json->body[$i]->value, $params[$key], $posI, $posF - $posI + 1);
                         } else {
                             $decoded_json->body[$i]->value = substr_replace($decoded_json->body[$i]->value, "", $posI, $posF - $posI + 1);
                         }
                     }
                 }
                 $pdf->addText($decoded_json->body[$i]->x, $decoded_json->body[$i]->y, $decoded_json->body[$i]->fontSize, utf8_decode($decoded_json->body[$i]->value));
                 break;
             case "round-box":
                 $x = $decoded_json->body[$i]->x;
                 $y = $decoded_json->body[$i]->y;
                 $w = $decoded_json->body[$i]->w;
                 $h = $decoded_json->body[$i]->h;
                 $pdf->setStrokeColor(0.3359375, 0.578125, 0.89453125);
                 $pdf->setLineStyle(1);
                 $pdf->line($x + 2, $y, $x + $w - 2, $y);
                 //arriba
                 $pdf->line($x, $y - 2, $x, $y - $h + 2);
                 //izquierda
                 $pdf->line($x + 2, $y - $h, $x + $w - 2, $y - $h);
                 //abajo
                 $pdf->line($x + $w, $y - 2, $x + $w, $y - $h + 2);
                 //derecha
                 $pdf->partEllipse($x + 3, $y - 3, 90, 180, 3);
                 //top-left
                 $pdf->partEllipse($x + $w - 3, $y - 3, 0, 90, 3);
                 //top-right
                 $pdf->partEllipse($x + $w - 3, $y - $h + 3, 360, 240, 3);
                 //bottom-right
                 $pdf->partEllipse($x + 3, $y - $h + 3, 180, 270, 3);
                 //bottom-left
                 break;
         }
     }
     //margenes de un centimetro para toda la pagina
     $pdf->ezSetMargins($decoded_json->marginTop, $decoded_json->marginBottom, $decoded_json->marginLeft, $decoded_json->marginRight);
     /**************************
      * ENCABEZADO
      ***************************/
     //$pdf->addText( self::puntos_cm(7.1), self::puntos_cm(26.1), 18, utf8_decode($title));
     //$pdf->addText( self::puntos_cm(7.1), self::puntos_cm(25.5), 12, utf8_decode($subtitle));
     $pdf->ezStream();
     exit;
 }
예제 #4
0
$header = array("id_documento" => "Nombre", "id_documento_base" => "Tipo de documento", "fecha" => "Modificacion");
$tableDb = new TableComponent($header, $documentos_base);
$tableDb->addColRender("fecha", "R::FriendlyDateFromUnixTime");
$tableDb->addColRender("id_documento_base", "R::NombreDocumentoBaseFromId");
$tableDb->addColRender("id_documento", "R::NombreDocumentoFromId");
$tableDb->addOnClick("id_documento", "(function(a){ window.location  = 'documentos.ver.php?d=' + a;  })");
$page->addComponent($tableDb);
/**
 *
 *
 *
 **/
$page->nextTab("Nuevo");
$page->addComponent(new TitleComponent("Nueva instancia de documento", 3));
//buscar un documento
$documentos_base = DocumentoBaseDAO::getAll();
$header = array("nombre" => "Nombre", "ultima_modificacion" => "Ultima modificacion");
$tableDb = new TableComponent($header, $documentos_base);
$tableDb->addColRender("ultima_modificacion", "R::FriendlyDateFromUnixTime");
$tableDb->addOnClick("id_documento_base", "(function(a){ window.location  = 'documentos.nuevo.instancia.php?base=' + a;  })");
$page->addComponent($tableDb);
/**
 *
 *
 *
 **/
$page->nextTab("Base");
$page->addComponent(new TitleComponent("Nuevo documento base", 3));
$f = new DAOFormComponent(new DocumentoBase());
$f->addApiCall("api/documento/base/nuevo", "POST");
$f->beforeSend("attachExtraParams");
 public static function Generar2Excel($id_documento)
 {
     $Debug = 0;
     $TEMP = DocumentoDAOBase::getByPK($id_documento);
     $DocBase = DocumentoBaseDAO::getByPK($TEMP->getIdDocumentoBase());
     $DescDoc = DocumentoDAO::getDocumentWithValues($id_documento);
     //Descarga de documento
     $DescDoc = array_reverse($DescDoc);
     $Valores = array();
     $i = 0;
     if ($DocBase->getNombrePlantilla() != null) {
         //Si Se especifica una plantilla
         $arrLlaves = array();
         $arrValores = array();
         foreach ($DescDoc as $Item) {
             $Llave = "#" . $Item["campo"] . "#";
             $Valor = $Item["val"];
             array_push($arrLlaves, $Llave);
             if (json_decode($Valor) != null) {
                 array_push($arrValores, json_decode($Valor));
             } else {
                 array_push($arrValores, $Valor);
             }
         }
         $datos = array_combine($arrLlaves, $arrValores);
         //Establece los datos a usar
         $archivo_plantilla = POS_PATH_TO_SERVER_ROOT . "/../static_content/" . IID . "/plantillas/excel/" . $DocBase->getNombrePlantilla();
         //Establece el archivo de plantilla que se va a usar
     } else {
         //Si no se especifica una plantilla
         foreach ($DescDoc as $parms) {
             if (FormasPreimpresasController::EsCoord($parms["descripcion"])) {
                 //Determina si son coordenadas
                 //FALTA
             } else {
                 //Si no son coordenadas las inserta desde la fila 1 hasta la fila n, en la columna A el nombre del campo y en la B el valor
                 $i++;
                 $Valores["A{$i}"] = array($parms["descripcion"]);
                 $Valores["B{$i}"] = array($parms["val"]);
             }
         }
         //var_dump($Valores);
         $datos = $Valores;
         //Establece los datos a usar
     }
     try {
         if ($datos == null) {
             Logger::error("No hay datos para trabajar");
             //Termina la ejecución
         } else {
             $Datos = $datos;
             //Carga los datos con los que va a trabajar
         }
         if ($archivo_plantilla == null || $archivo_plantilla === "") {
             //Si no se especifica una plantilla
             $ObjSalida = new PHPExcel();
             //Crea el nuevo objeto de saĺida
             $itCol = 0;
             $itFil = 0;
             foreach ($Datos as $key => $value) {
                 if (substr($key, 0, 1) != "#" && substr($key, strlen($key) - 1 != "#", 1)) {
                     //Determina si NO es una palabra clave
                     if (is_object($value) == true) {
                         //Si el elemento que se obtiene es un objeto (incluye formato)
                         $Pos = FormasPreimpresasController::SeparaColFil($key);
                         foreach ($value as $nKey => $Filas) {
                             if (is_array($Filas)) {
                                 //Si hay un arreglo con las columnas para esa fila
                                 foreach ($Filas as $Columnas) {
                                     //Itera entre todas las columnas contenidas en el array
                                     $ObjSalida->getActiveSheet()->getCellByColumnAndRow($Pos->Col + $itCol, $Pos->Fil + $itFil - 1)->setValue($Columnas);
                                     $itCol++;
                                 }
                                 $itCol = 0;
                             }
                             $itFil++;
                         }
                         unset($itCol);
                         unset($itFil);
                     } else {
                         //Si el objeto que se obtiene es un array (solo textos)
                         $ItCol = 0;
                         $ItFil = 0;
                         if (is_array($value) == true) {
                             foreach ($value as $Valinter) {
                                 //itera entre todas las filas recibidas del arreglo
                                 if (is_Array($Valinter)) {
                                     foreach ($Valinter as $ValInterCol) {
                                         $Pos = FormasPreimpresasController::SeparaColFil($key);
                                         $ObjSalida->getActiveSheet()->getCellByColumnAndRow($Pos->Col + $ItCol, $Pos->Fil + $ItFil)->setValue($ValInterCol);
                                         $ItCol++;
                                     }
                                     $ItCol = 0;
                                 } else {
                                     $Pos = FormasPreimpresasController::SeparaColFil($key);
                                     $ObjSalida->getActiveSheet()->getCellByColumnAndRow($Pos->Col + $ItCol, $Pos->Fil)->setValue($Valinter);
                                     $ItCol++;
                                 }
                                 $ItFil++;
                             }
                         } else {
                             $ObjSalida->getActiveSheet()->getCell($key)->setValue($value);
                             //Establece el valor de la celda en base al arreglo obtenido
                         }
                         unset($ItCol);
                         unset($ItFil);
                     }
                 }
             }
             unset($itCol);
             unset($itFil);
             //Libera las variable de la memoria
         } else {
             //Si se especifica una plantilla
             if (file_exists($archivo_plantilla) == 1) {
                 //Comprueba si existe el archivo de plantilla indicado
                 $Extension = strrchr($archivo_plantilla, ".");
                 if ($Extension == ".xlsx") {
                     //Comprueba la extensión de la plantilla
                     $ObjSalida = PHPExcel_IOFactory::load($archivo_plantilla);
                     $HojaPlantilla = $ObjSalida->getActiveSheet();
                     //Carga la hoja de la plantilla al nuevo archivo
                     $itCol = 0;
                     $itFil = 0;
                     foreach ($HojaPlantilla->getRowIterator() as $Fila) {
                         //Iterador de Filas
                         foreach ($Fila->getCellIterator() as $Celda) {
                             //Iterador de Columnas
                             if (array_key_exists((string) $Celda->getValue(), $Datos)) {
                                 //Comprueba si la palabra clave existe dentro del arreglo de datos recibidos
                                 if (is_object($Datos[$Celda->getValue()])) {
                                     //Si se recibe un arreglo de cadenas
                                     foreach ($Datos[$Celda->getValue()] as $Key => $Valor) {
                                         //Itera entre todos los elementos del primer arreglo recibido (el de nivel superior)
                                         if (is_array($Valor)) {
                                             //Si el coontenido del elemento en el primer array es un array también, lo itera.
                                             foreach ($Valor as $Cols) {
                                                 //Iteración entre el contenido de los arrays() del primer array(Filas) para revisar todas las columnas
                                                 $HojaPlantilla->getCellByColumnAndRow(PHPExcel_Cell::columnIndexFromString($Celda->getColumn()) + $itCol - 1, $Celda->getRow() + $itFil - 1)->setValue($Cols);
                                                 $itCol++;
                                             }
                                         }
                                         if ($Key != "Formato") {
                                             //Si solo se manda un arreglo con los datos de las primeras columnas
                                         }
                                         $itFil++;
                                         $itCol = 0;
                                     }
                                     unset($itCol);
                                     unset($itFil);
                                 } else {
                                     if (is_array($Datos[$Celda->getValue()])) {
                                         //Si se recibe un arreglo, se consideran como cabeceras todos sus elementos hacia la derecha
                                         $Fini = $Celda->getRow();
                                         $Cini = PHPExcel_Cell::columnIndexFromString($Celda->getColumn());
                                         $Cini--;
                                         foreach ($Datos[$Celda->getValue()] as $Val) {
                                             if (is_array($Val)) {
                                                 foreach ($Val as $CelCol) {
                                                     $HojaPlantilla->getCellByColumnAndRow($Cini + $itCol, $Fini + $itFil)->setValue($CelCol);
                                                     $itCol++;
                                                 }
                                                 $itFil++;
                                                 $itCol = 0;
                                             } else {
                                                 $HojaPlantilla->getCellByColumnAndRow($Cini, $Fini)->setValue($Val);
                                                 //Pone una fila de datos
                                                 $Cini++;
                                             }
                                         }
                                         unset($Fini);
                                         unset($Cini);
                                         unset($Val);
                                     } else {
                                         $Celda->setValue($Datos[$Celda->getValue()]);
                                         //Cambia el valoren el archivo de plantilla de una sola celda
                                     }
                                 }
                             }
                         }
                     }
                 } else {
                     Logger::error("La extensión de la plantilla no es compatible (" . $Extension . ") con esta función (.xlsx)");
                 }
                 unset($Extension);
                 //Libera la variable
             } else {
                 Logger::error("El archivo de plantilla indicado no existe.");
                 return;
             }
         }
         $objWriter = PHPExcel_IOFactory::createWriter($ObjSalida, 'Excel2007');
         //Devuelve un objeto de escritura
     } catch (Exception $e) {
         Logger::error("Ha ocurrido un error: {$e}");
     }
     if ($Debug === 1) {
         header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
         //Cabeceras de salida
         header("Content-Disposition: attachment;filename=\"Excel.xlsx\"");
         header("Cache-Control: max-age=0");
     }
     $objWriter->save("php://output");
     //Imprime el archivo de salida
 }
예제 #6
0
 /**
  *
  *Crea un nuevo documento.
  *
  * @param id_documento_base int el documento base del cual este documento es instancia
  * @param extra_params json 
  * @param id_empresa int Si pertence a una empresa en especifico, o puede realizarse en cualquier empresa.
  * @param id_sucursal int Si pertenece a una sucursal en especifico o puede realizarse en cualquier sucursal.
  * @return id_documento int Id del nuevo documento
  **/
 public static function Nuevo($id_documento_base, $extra_params = null, $id_empresa = null, $id_sucursal = null)
 {
     $dbase = DocumentoBaseDAO::getByPK($id_documento_base);
     if (is_null($dbase)) {
         throw new InvalidDataException("This base doc does not exist");
     }
     $nDoc = new Documento();
     $nDoc->setIdDocumentoBase($id_documento_base);
     $nDoc->setFolio(0);
     $nDoc->setFecha(time());
     $nDoc->setIdOperacion(0);
     DAO::transBegin();
     try {
         DocumentoDAO::save($nDoc);
     } catch (Exception $e) {
         DAO::transRollback();
         throw InvalidDatabaseOperationException($e);
     }
     //test all extra params in base doc are present in $extra_params
     $pindb = ExtraParamsEstructuraDao::search(new ExtraParamsEstructura(array("tabla" => "documento_base-" . $id_documento_base)));
     foreach ($pindb as $campo) {
         if (!array_key_exists($campo->getCampo(), $extra_params)) {
             //no existe en extra params
             //salir si este parametro es
             //obligatorio
             if ($campo->getObligatorio()) {
                 throw new InvalidDataException("El campo " . $campo->getObligatorio() . " es obligatorio");
             }
         } else {
             $valueToStore = $extra_params->{$campo->getCampo()};
             $valueToStore = is_null($valueToStore) ? "" : $valueToStore;
             $val = new ExtraParamsValores(array("id_extra_params_estructura" => $campo->getIdExtraParamsEstructura(), "id_pk_tabla" => $nDoc->getIdDocumento(), "val" => $valueToStore));
             try {
                 ExtraParamsValoresDAO::save($val);
             } catch (Exception $e) {
                 DAO::transRollback();
                 throw new InvalidDatabaseOperationException($e);
             }
         }
     }
     //foreach
     DAO::transEnd();
 }
예제 #7
0
<?php

define("BYPASS_INSTANCE_CHECK", false);
require_once "../../../server/bootstrap.php";
if (isset($_GET["preview"]) && isset($_GET["d"])) {
    ImpresionesController::Documento($_GET["d"], true);
    exit;
}
$documento = DocumentoDAO::getByPK($_GET["d"]);
$documentoBase = DocumentoBaseDAO::getByPK($documento->getIdDocumentoBase());
$values = DocumentoDAO::getDocumentWithValues($_GET["d"]);
$page = new GerenciaTabPage();
$page->addComponent('<link rel="stylesheet" type="text/css" href="/pos/css/markdown.css" />
        <script type="text/javascript" src="/pos/js/Markdown.Converter.js"></script>
        <script type="text/javascript" src="/pos/js/Markdown.Sanitizer.js"></script>
        <script type="text/javascript" src="/pos/js/Markdown.Editor.js"></script>');
$page->addComponent(new TitleComponent($documentoBase->getNombre(), 3));
$page->addComponent(new TitleComponent(R::NombreDocumentoFromId($_GET["d"])));
//
// $page->addComponent(
//		"<div class='POS Boton' onClick='window.location=\"documentos.editar.php?d=". $_GET["d"] ."\"'>Editar</div> " );
// $page->addComponent( "<div class='POS Boton' onClick='window.location=\"documentos.ver.php?preview=1&d=". $_GET["d"] ."\"'>Vista previa</div> " );
//
//
/**
 *
 *
 **/
$page->nextTab("Doc");
$f = new FormComponent();
for ($i = 0; $i < sizeof($values); $i++) {
예제 #8
0
<?php

define("BYPASS_INSTANCE_CHECK", false);
require_once "../../../server/bootstrap.php";
$movimiento = VentaDAO::getByPK(354)->asArray();
$documento = DocumentoBaseDAO::getByPK(51);
//	var_dump($movimiento);
DocumentosController::Cerrar(51, $movimiento);
//buscar movimiento existente
//buscar documento a realizar
//validar documento
//validar que los parametros del documento esten disponibles
//insertar en documento tabla
//mandar imprimir
<?php

define("BYPASS_INSTANCE_CHECK", false);
require_once "../../../server/bootstrap.php";
$page = new GerenciaComponentPage();
// Validar parametro de base
$DocumentoBase = DocumentoBaseDAO::getByPK($_GET["base"]);
if (is_null($DocumentoBase)) {
    $page->render();
    exit;
} else {
    if ($DocumentoBase->GetActivo() == false) {
        $page->render();
        exit;
    }
}
$page->addComponent(new TitleComponent("Nuevo " . $DocumentoBase->getNombre(), 1));
//Buscar sus parametros extra
$ExtraParamsStructs = ExtraParamsEstructuraDAO::search(new ExtraParamsEstructura(array("tabla" => "documento_base-" . $DocumentoBase->getIdDocumentoBase())));
$f = new FormComponent();
$f->addApiCall("api/documento/nuevo");
for ($i = 0; $i < sizeof($ExtraParamsStructs); $i++) {
    // function addField($id, $caption, $type, $value = "", $name = null) {
    if ($ExtraParamsStructs[$i]->tipo == "enum") {
        $enum_string = explode(",", $ExtraParamsStructs[$i]->enum);
        $enum_array = array();
        for ($k = 0; $k < count($enum_string); $k++) {
            array_push($enum_array, array("caption" => $enum_string[$k], "id" => $enum_string[$k], "selected" => 0));
        }
        $f->addField($ExtraParamsStructs[$i]->campo, $ExtraParamsStructs[$i]->caption, $ExtraParamsStructs[$i]->tipo, $enum_array);
    } else {