Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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");
- // master grid
- $mastergrid = new jqgrid();
- //ID DE LA VENTA
- $col = array();
- $col["title"] = "Id";
- $col["name"] = "id";
- $col["width"] = "4";
- $col["editable"] = false;
- $col["editrules"] = array("edithidden"=>true);
- $cols[] = $col;
- //ID DE L'EMPRESA
- $col = array();
- $col["title"] = "EmpresaId";
- $col["name"] = "idempresa";
- $col["width"] = "4";
- $col["editable"] = true;
- $col["hidden"] = false;
- $col["editoptions"]=array("defaultValue"=>$_SESSION["empresaactiva"],"readonly"=>"readonly");
- $cols[] = $col;
- //ID SEGMENTO
- $col = array();
- $col["title"] = "SegmentoId";
- $col["name"] = "idsegmento";
- $col["width"] = "12";
- $col["editable"] = true;
- $col["edittype"]= "select";
- $str = $mastergrid->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 CLIENTE
- $col = array();
- $col["title"] = "Cliente";
- $col["name"] = "idcliente";
- $col["width"] = "50";
- $col["editable"] = true;
- $col["edittype"]= "select";
- $col["editoptions"] = array("size"=>60);
- $str = $mastergrid->get_dropdown_values("select distinct id as k, concat(apellidos,' ',nombre) as v from clientes order by concat(apellidos,' ',nombre)");
- $col["editoptions"] = array("value"=>":;".$str);
- $col["formatter"] = "select";
- $cols[] = $col;
- //FECHA
- $col = array();
- $col["title"] = "Fecha";
- $col["name"] = "fecha";
- $col["width"] = "17";
- $col["editable"] = true;
- $col["formatter"] = "date";
- $col["formatoptions"] = array("srcformat"=>'Y-m-d',"newformat"=>'d/m/Y');
- $cols[] = $col;
- //CONCEPTO
- $col = array();
- $col["title"] = "Concepto";
- $col["name"] = "concepto";
- $col["width"] = "20";
- $col["editoptions"] = array("size"=>150);
- $col["editable"] = true;
- $cols[] = $col;
- //BASE
- $col = array();
- $col["title"] = "Base";
- $col["name"] = "base";
- $col["width"] = "14";
- $col["editable"] = true;
- $col["formatter"] = "number";
- $col["editoptions"] = array("size"=>12);
- $col["formatoptions"] = array("thousandsSeparator" =>".","decimalSeparator"=>",","decimalPlaces"=>2);
- $col["align"] = "right";
- $cols[] = $col;
- //cuotaiva
- $col = array();
- $col["title"] = "Cuota";
- $col["name"] = "cuota";
- $col["width"] = "14";
- $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";
- $col["name"] = "total";
- $col["width"] = "14";
- $col["editable"] = true;
- $col["formatter"] = "number";
- $col["editoptions"] = array("size"=>12);
- $col["formatoptions"] = array("thousandsSeparator" =>".","decimalSeparator"=>",","decimalPlaces"=>2);
- $col["align"] = "right";
- $cols[] = $col;
- // file upload column
- $col = array();
- $col["title"] = "Fichero";
- $col["name"] = "fichero1";
- $col["width"] = "40";
- $col["editable"] = true;
- $col["edittype"] = "file"; // render as file
- $col["upload_dir"] = "img_ventas"; // upload here
- $col["show"] = array("list"=>false,"edit"=>true,"add"=>true); // only show in add/edit dialog
- $cols[] = $col;
- // get upload folder url for display in grid -- change it as per your upload path
- $upload_url = explode("/",$_SERVER["REQUEST_URI"]);
- array_pop($upload_url);
- $upload_url = implode("/",$upload_url)."/";
- $col = array();
- $col["title"] = "Image";
- $col["name"] = "imagen";
- $col["width"] = "200";
- $col["editable"] = true;
- $col["condition"] = array('$row["fichero1"] == ""', "", "<a href='$upload_url/{fichero1}' target='_blank'><img height=100 src='$upload_url/{fichero1}'></a>");
- $col["show"] = array("list"=>true,"edit"=>true,"add"=>false); // only show in listing
- $col["editoptions"]["dataInit"] = "function(o){jQuery(o).parent().html(o.value);}";
- $cols[] = $col;
- //VALIDA
- $col = array();
- $col["title"] = "VALIDA";
- $col["name"] = "valida";
- $col["width"] = "6";
- $col["editable"] = true;
- $col["edittype"]="checkbox";
- $col["editoptions"]=array("value"=>"1:0");
- $col["formatter"] = "checkbox";
- if ($_SESSION["usuario"]->getValue("permisos")=='admin') {
- $col["editable"] = true;
- }else{
- $col["editable"] = false;
- }
- $cols[] = $col;
- //ENVIADA
- $col = array();
- $col["title"] = "ENVIADA";
- $col["name"] = "enviada";
- $col["width"] = "6";
- $col["editable"] = true;
- $col["edittype"]="checkbox";
- $col["editoptions"]=array("value"=>"1:0");
- $col["formatter"] = "checkbox";
- $col["editable"] = false;
- $cols[] = $col;
- $masteropt["caption"] = "VENTAS";
- //definim l'ID del grid de detall
- $masteropt["detail_grid_id"] = "list2";
- $masteropt["altRows"]=true;
- $masteropt["altclass"]="myAltRowClass";
- $masteropt["autowidth"]=true;
- $masteropt["toolbar"] = "both";
- $masteropt["add_options"] = array('width'=>'650');
- $masteropt["edit_options"] = array('width'=>'650');
- $masteropt["add_options"] ["success_msg"] = "Registro añadido con éxito!";
- $masteropt["edit_options"] ["success_msg"] = "Registro actualizado con éxto!";
- $masteropt["delete_options"] ["success_msg"] = "Registro eliminado con éxito!";
- $masteropt["form"]["nav"] = true;
- $masteropt["height"] = "300";
- $masteropt["sortorder"] = "desc";
- $masteropt["multiselect"] = false;
- // refresh detail grid on master edit
- $masteropt["edit_options"]["afterSubmit"] = "function(){ jQuery('#list2').trigger('reloadGrid', [{current:true}]); return [true,'']; jQuery('#list1').setSelection(jQuery('#list1').jqGrid('getGridParam','selrow')); }";
- $mastergrid->set_options($masteropt);
- if ($_SESSION["usuario"]->getValue("permisos")=='admin') {
- $mastergrid->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,
- "refresh"=>false
- )
- );
- $mastergrid->select_command = "SELECT v.id, v.idempresa, v.idsegmento, v.idcliente, v.fecha, v.concepto, v.base, v.cuota,
- v.total , v.valida, v.enviada, v.fichero1, c.nombre as clientenombre
- from ventas as v left join segmentos as sg on v.idsegmento=sg.id
- left join clientes as c on v.idcliente=c.id
- where v.idempresa=" . $_SESSION["empresaactiva"];
- }else{
- $mastergrid->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,
- "refresh"=>false
- )
- );
- $mastergrid->select_command = "SELECT v.id, v.idempresa, v.idsegmento, v.idcliente, v.fecha, v.concepto, v.base, v.cuota,
- v.total , v.valida, v.enviada, v.fichero1, c.nombre as clientenombre
- from ventas as v left join segmentos as sg on v.idsegmento=sg.id
- left join clientes as c on v.idcliente=c.id
- where v.idempresa=" . $_SESSION["empresaactiva"] . " and v.valida=0 or v.valida is null";
- }
- // set database table for CRUD operations
- $mastergrid->table = "ventas";
- // use events if you need custom logic for upload
- $ev["on_update"] = array("update_venta", null, true);
- $ev["on_delete"] = array("delete_venta", null, true);
- $mastergrid->set_events($ev);
- // callback for update
- function update_venta($data)
- {
- $upload_file_path = $data["params"]["fichero1"];
- $file_content = file_get_contents($upload_file_path);
- // your custom upload code goes here e.g. File DB insertion
- }
- function delete_venta($data)
- {
- $rs = mysql_fetch_assoc(mysql_query("SELECT fichero1 FROM ventas WHERE id = {$data[id]}"));
- unlink(realpath($rs["fichero1"]));
- }
- // pass the cooked columns to grid
- $mastergrid->set_columns($cols);
- // render grid and get html/js output
- $out_master = $mastergrid->render("list1");
- //GRID DETALL --------------------------------------------------------------
- //GRID DETALL --------------------------------------------------------------
- //GRID DETALL --------------------------------------------------------------
- //GRID DETALL --------------------------------------------------------------
- $detailgrid = new jqgrid();
- $detailopt = array();
- $detailopt["height"] = ""; // autofit height of subgrid
- $detailopt["caption"] = "Detalle Venta"; // caption of grid
- $detailopt["toolbar"] = "both";
- $detailopt["add_options"] = array('width'=>'600');
- $detailopt["edit_options"] = array('width'=>'600');
- $detailopt["add_options"]["afterSubmit"] = "function(){jQuery('#list1').trigger('reloadGrid',[{current:true}]); return [true, ''];}";
- $detailopt["edit_options"]["afterSubmit"] = "function(){jQuery('#list1').trigger('reloadGrid',[{current:true}]); return [true, ''];}";
- $detailopt["delete_options"]["afterSubmit"] = "function(){jQuery('#list1').trigger('reloadGrid',[{current:true}]); return [true, ''];}";
- $detailopt["onAfterSave"] = "function(){ var selr = jQuery('#list1').jqGrid('getGridParam','selrow'); jQuery('#list1').trigger('reloadGrid',[{jqgrid_page:1}]); setTimeout( function(){jQuery('#list1').setSelection(selr,true);},500 ); }";
- $detailgrid->set_options($detailopt);
- $detailgrid->set_actions(array(
- "add"=>true, // allow/disallow add
- "edit"=>true, // allow/disallow edit
- "delete"=>true, // allow/disallow delete
- "rowactions"=>false, // show/hide row wise edit/del/save option
- "export"=>false, // show/hide export to excel option
- "autofilter" => true, // show/hide autofilter for search
- "search" => "advance" // show single/multi field search condition (e.g. simple or advance)
- )
- );
- // receive id, selected row of parent grid
- $id = intval($_GET["rowid"]);
- // and use in sql for filteration
- $detailgrid->select_command = "SELECT * FROM detventa WHERE idventa = $id";
- // this db table will be used for add,edit,delete
- $detailgrid->table = "detventa";
- //ID DE LA VENTA
- $col = array();
- $col["title"] = "Linea";
- $col["name"] = "id";
- $col["width"] = "4";
- $col["editable"] = false;
- $col["editrules"] = array("edithidden"=>true);
- $cols_detail[] = $col;
- //ID DE LA VENTA
- $col = array();
- $col["title"] = "IdVenta";
- $col["name"] = "idventa";
- $col["width"] = "4";
- $col["editable"] = false;
- $col["editrules"] = array("edithidden"=>true);
- $cols_detail[] = $col;
- //ID ARTICULO
- $col = array();
- $col["title"] = "Articulo";
- $col["name"] = "idarticulo";
- $col["width"] = "50";
- $col["editable"] = true;
- $col["edittype"]= "select";
- $col["editoptions"] = array("size"=>60);
- $str = $detailgrid->get_dropdown_values("select distinct id as k, descripcion as v from articulos order by descripcion");
- $col["editoptions"] = array("value"=>":;".$str);
- $col["formatter"] = "select";
- $cols_detail[] = $col;
- //CONCEPTO
- $col = array();
- $col["title"] = "Concepto";
- $col["name"] = "concepto";
- $col["width"] = "4";
- $col["editable"] = true;
- $col["editoptions"] = array("size"=>100);
- //$col["editrules"] = array("edithidden"=>true);
- $cols_detail[] = $col;
- //UNIDADES
- $col = array();
- $col["title"] = "Uds";
- $col["name"] = "uds";
- $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_detail[] = $col;
- //PRECIO
- $col = array();
- $col["title"] = "Precio";
- $col["name"] = "precio";
- $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_detail[] = $col;
- //TIPOIVA
- $col = array();
- $col["title"] = "TipoIva"; // 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["formatter"] = "number";
- $col["editoptions"] = array("size"=>6);
- $col["formatoptions"] = array("thousandsSeparator" =>".","decimalSeparator"=>",","decimalPlaces"=>2);
- $col["align"] = "right";
- $cols_detail[] = $col;
- $detailgrid->set_columns($cols_detail);
- // evento, com el tercer parametre està a TRUE : 1er) funció "add_det_venta" 2on) inserta en BBDD
- $e["on_insert"] = array("add_det_venta", null, true);
- $e["on_after_insert"] = array("fnActualizaVenta",null, false);
- $e["on_after_update"] = array("fnActualizaVenta",null, false);
- $e["on_after_delete"] = array("fnActualizaVenta",null, false);
- $detailgrid->set_events($e);
- function add_det_venta(&$data)
- {
- $id = intval($_GET["rowid"]);
- $data["params"]["idventa"] = $id;
- }
- function fnActualizaVenta(&$data)
- {
- $id = intval($_GET["rowid"]);
- mysql_query("UPDATE ventas set base = (select sum(totbases) from (select round(sum(uds*precio),2) as totbases from detventa where idventa='{$id}' group by tipoiva) as temp) where id='{$id}'");
- mysql_query("UPDATE ventas set cuota = (select sum(totcuotas) from (select round(round(sum(uds*precio),2)*tipoiva/100,2) as totcuotas from detventa where idventa='{$id}' group by tipoiva) as temp) where id='{$id}'");
- mysql_query("UPDATE ventas set total = base+cuota where id='{$id}'");
- }
- // generate grid output, with unique grid name as 'list1'
- $out_detail = $detailgrid->render("list2");
- fnAsignarEncabezado("VENTAS"); //carga encabezado
- fnMenuPrincipal();
- ?>
- <!-- display grid here -->
- <?php echo $out_master?>
- <br>
- <?php echo $out_detail?>
- <!-- display grid here -->
- <?php
- fnCerrarPagina(); //cierra el contenido, el body y el html
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement