Skip to content

Instantly share code, notes, and snippets.

@mpsistemes
Created June 24, 2024 09:01
Show Gist options
  • Save mpsistemes/641dee3e99c294c90916c0ac8674c910 to your computer and use it in GitHub Desktop.
Save mpsistemes/641dee3e99c294c90916c0ac8674c910 to your computer and use it in GitHub Desktop.
Code date conversion fails
<?php
ob_start();
require_once("plantilla.php");
checkLogin();
displayForm();
function displayForm() {
//mysql_connect(DB_DSN_GRID,DB_USER_GRID ,DB_PASS_GRID);
//mysql_select_db(DB_DB_GRID);
include("../lib/inc/jqgrid_dist.php");
$db_conf = array(
"type" => "mysql",
"server" => DB_DSN_GRID,
"user" => DB_USER_GRID,
"password" => DB_PASS_GRID,
"database" => DB_DB_GRID
);
$g = new jqgrid($db_conf);
//ID COMPRAS
$col = array();
$col["title"] = "ID"; // caption of column
$col["name"] = "id"; // grid column name, must be exactly same as returned column-name from sql (tablefield or field-alias)
$col["width"] = "4";
$col["editable"] = false;
//$col["hidden"] = false;
$col["editrules"] = array("edithidden"=>true);
$cols[] = $col;
//ID DE L'EMPRESA
$col = array();
$col["title"] = "EmpresaId"; // caption of column
$col["name"] = "idempresa"; // grid column name, must be exactly same as returned column-name from sql (tablefield or field-alias)
$col["width"] = "4";
$col["editable"] = true;
$col["hidden"] = false;
$col["editoptions"]=array("defaultValue"=>$_SESSION["empresaactiva"],"readonly"=>"readonly");
$cols[] = $col;
//ID TIPOGASTO
$col = array();
$col["title"] = "TipogastoId"; // caption of column
$col["name"] = "idtipogasto"; // grid column name, must be exactly same as returned column-name from sql (tablefield or field-alias)
$col["width"] = "10";
$col["editable"] = true;
$col["edittype"]= "select";
$col["editoptions"] = array("size"=>40);
$str = $g->get_dropdown_values("select distinct id as k, descripcion as v from tiposgasto");
$col["editoptions"] = array("value"=>":;".$str);
$col["formatter"] = "select";
$cols[] = $col;
//ID SEGMENTO
$col = array();
$col["title"] = "SegmentoId"; // caption of column
$col["name"] = "idsegmento"; // grid column name, must be exactly same as returned column-name from sql (tablefield or field-alias)
$col["width"] = "12";
$col["editable"] = true;
$col["edittype"]= "select";
$col["editoptions"] = array("size"=>40);
$str = $g->get_dropdown_values("select distinct id as k, descripcion as v from segmentos where idempresa=" . $_SESSION["empresaactiva"]);
$col["editoptions"] = array("value"=>":;".$str);
$col["formatter"] = "select";
$cols[] = $col;
//ID PROVEEDOR
$col = array();
$col["title"] = "Proveedor"; // caption of column
$col["name"] = "idproveedor"; // grid column name, must be exactly same as returned column-name from sql (tablefield or field-alias)
$col["width"] = "15";
$col["editable"] = true;
$col["edittype"]= "select";
$col["editoptions"] = array("size"=>60);
$str = $g->get_dropdown_values("select distinct id as k, nombre as v from proveedores order by nombre");
$col["editoptions"] = array("value"=>":;".$str);
$col["formatter"] = "select";
$cols[] = $col;
//FECHA
$col = array();
$col["title"] = "Fecha"; // caption of column
$col["name"] = "fecha"; // grid column name, must be exactly same as returned column-name from sql (tablefield or field-alias)
$col["width"] = "9";
$col["editable"] = true;
$col["formatter"] = "date";
$col["formatoptions"] = array("srcformat"=>'Y-m-d',"newformat"=>'d/m/Y');
$cols[] = $col;
//NUMDOC
$col = array();
$col["title"] = "NumDoc"; // caption of column
$col["name"] = "numdoc"; // grid column name, must be exactly same as returned column-name from sql (tablefield or field-alias)
$col["width"] = "15";
$col["editoptions"] = array("size"=>25);
$col["editable"] = true;
$cols[] = $col;
//CONCEPTO
$col = array();
$col["title"] = "Concepto"; // caption of column
$col["name"] = "concepto"; //grid column name, must be exactly same as returned column-name from sql (tablefield or field-alias)
$col["width"] = "20";
$col["editoptions"] = array("size"=>90);
$col["editable"] = true;
$cols[] = $col;
//BASE
$col = array();
$col["title"] = "BASE"; // caption of column
$col["name"] = "base"; //grid column name, must be exactly same as returned column-name from sql (tablefield or field-alias)
$col["width"] = "9";
$col["editable"] = true;
$col["editoptions"] = array("size"=>12);
$col["formatter"] = "number";
$col["formatoptions"] = array("thousandsSeparator" =>".","decimalSeparator"=>",","decimalPlaces"=>2);
$col["align"] = "right";
$cols[] = $col;
//tipoiva
$col = array();
$col["title"] = "T.IVA"; // caption of column
$col["name"] = "tipoiva"; //grid column name, must be exactly same as returned column-name from sql (tablefield or field-alias)
$col["width"] = "5";
$col["editable"] = true;
$col["editoptions"] = array("size"=>6);
$col["formatter"] = "number";
$col["formatoptions"] = array("thousandsSeparator" =>".","decimalSeparator"=>",","decimalPlaces"=>2);
$col["align"] = "right";
$col["formatter"]="function(cellval,options,rowdata){ return cellval+'%';}";
$col["unformat"]="function(cellval, options, cell){ return cellval.replace('%','');}";
$cols[] = $col;
//cuotaiva
$col = array();
$col["title"] = "CUOTA"; // caption of column
$col["name"] = "cuotaiva"; //grid column name, must be exactly same as returned column-name from sql (tablefield or field-alias)
$col["width"] = "9";
$col["editable"] = true;
$col["formatter"] = "number";
$col["editoptions"] = array("size"=>12);
$col["formatoptions"] = array("thousandsSeparator" =>".","decimalSeparator"=>",","decimalPlaces"=>2);
$col["align"] = "right";
$cols[] = $col;
//tiporet
$col = array();
$col["title"] = "T.RET"; // caption of column
$col["name"] = "tiporet"; //grid column name, must be exactly same as returned column-name from sql (tablefield or field-alias)
$col["width"] = "5";
$col["editable"] = true;
$col["formatter"] = "number";
$col["editoptions"] = array("size"=>6);
$col["formatoptions"] = array("thousandsSeparator" =>".","decimalSeparator"=>",","decimalPlaces"=>2);
$col["align"] = "right";
$col["formatter"]="function(cellval,options,rowdata){ return cellval+'%';}";
$col["unformat"]="function(cellval, options, cell){ return cellval.replace('%','');}";
$cols[] = $col;
//cuotaret
$col = array();
$col["title"] = "CUOTARET"; // caption of column
$col["name"] = "cuotaret"; //grid column name, must be exactly same as returned column-name from sql (tablefield or field-alias)
$col["width"] = "9";
$col["editable"] = true;
$col["formatter"] = "number";
$col["editoptions"] = array("size"=>12);
$col["formatoptions"] = array("thousandsSeparator" =>".","decimalSeparator"=>",","decimalPlaces"=>2);
$col["align"] = "right";
$cols[] = $col;
//TOTAL
$col = array();
$col["title"] = "TOTAL"; // caption of column
$col["name"] = "total"; //grid column name, must be exactly same as returned column-name from sql (tablefield or field-alias)
$col["width"] = "9";
$col["editable"] = true;
$col["formatter"] = "number";
$col["editoptions"] = array("size"=>12);
$col["formatoptions"] = array("thousandsSeparator" =>".","decimalSeparator"=>",","decimalPlaces"=>2);
$col["align"] = "right";
$cols[] = $col;
// set few params
$grid["caption"] = "COMPRAS";
$grid["altRows"]=true;
$grid["altclass"]="myAltRowClass";
$grid["autowidth"]=true;
$grid["toolbar"] = "both";
$grid["add_options"] = array('width'=>'680');
$grid["edit_options"] = array('width'=>'680');
$grid["add_options"] ["success_msg"] = "Registro añadido con éxito!";
$grid["edit_options"] ["success_msg"] = "Registro actualizado con éxto!";
$grid["delete_options"] ["success_msg"] = "Registro eliminado con éxito!";
$grid["form"]["nav"] = true;
$g->set_options($grid);
//KKKK 16/06/2024 if ($_SESSION["usuario"]->getValue("permisos")=='admin') {//
if (strstr($_SESSION["permisosusuario"],'A')) {
$g->set_actions(array(
"add"=>true, // allow/disallow add
"edit"=>true, // allow/disallow edit
"delete"=>true, // allow/disallow delete
"clone"=>false, // allow/disallow clone
"rowactions"=>true, // show/hide row wise edit/del/save option
"autofilter" => true, // show/hide autofilter for search
"search" => "advance", // show single/multi field search condition (e.g. simple or advance)
"showhidecolumns" => false
)
);
}else{
$g->set_actions(array(
"add"=>true, // allow/disallow add
"edit"=>false, // allow/disallow edit
"delete"=>false, // allow/disallow delete
"clone"=>false, // allow/disallow clone
"rowactions"=>true, // show/hide row wise edit/del/save option
"autofilter" => true, // show/hide autofilter for search
"search" => "advance", // show single/multi field search condition (e.g. simple or advance)
"showhidecolumns" => false
)
);
}
// set database table for CRUD operations
$g->select_command = "SELECT c.id, c.idempresa, c.idtipogasto, c.idsegmento, c.idproveedor, c.fecha, c.numdoc, c.concepto, c.base, c.tipoiva, c.cuotaiva, c.tiporet,
c.cuotaret, c.total , p.nombre as proveedornombre
from compras as c left join tiposgasto as tg on c.idtipogasto=tg.id
left join segmentos as sg on c.idsegmento=sg.id
left join proveedores as p on c.idproveedor=p.id
where c.idempresa=" . $_SESSION["empresaactiva"];
// set database table for CRUD operations
$g->table = "compras";
// pass the cooked columns to grid
$g->set_columns($cols);
// render grid and get html/js output
$out = $g->render("list1");
fnAsignarEncabezado("COMPRAS"); //carga encabezado
fnMenuPrincipal();
?>
<!-- display grid here -->
<?php echo $out?>
<!-- display grid here -->
<?php
fnCerrarPagina(); //cierra el contenido, el body y el html
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment