Herramienta para implementar campos calculados

Buenas noches, trabajo con la versión libre de SuiteCrm lo he implementado sin ningún problema , pero ahora necesito hacer que dos campos realicen un calculo y que el resultado se almacene en un tercer campo.

mi pregunta es que herramientas tengo que usar para aventurarme a modificar el código de suitecrm.

que elementos necesitaría para empezar ha desarrollar.

Gracias de antemano por la atención.

Jamiro.

Hola Jamiro, te recomiendo 2 opciones para conseguir lo que deseas:

  1. Usar Loogic hooks

  2. Usar Javascript en la vista de edición

Personalmente me gusta usar la 2da opción

Saludos

Hola, estoy probando con Javascript pero no logro resultados , como puedo hacerle un test

este es mi codigo para el modulo de Opportunities

creado en “custom/modules/opportunities/views/view.edit.php”

<?php
     require_once('include/MVC/View/views/view.edit.php');
     class OpportunitiesViewEdit extends ViewEdit {
     function OpportunitiesViewEdit(){
            parent::ViewEdit();
     }
  
    function display() {
    ?><script src='http://code.jquery.com/jquery-latest.js'></script><?php    
        echo "<script type='text/javascript'>";                                               
    $javascript = file_get_contents('custom/modules/Opportunities/customJavascript.js');    
    echo $javascript;     
    echo "</script>";      
     parent::display();

  }
}
?>
  • y este es mi javascript

creado en “custom/modules/Opportunities/customJavascript.js”

$(document).ready(function(){
	$("#precio_caja_c").click(function(){  
		if($("#cantidad_c").attr('value') != 0){
			var total = Number($("#amount").attr('value')) / Number($("#cantidad_c").attr('value'));
		}else{
			var total = 0;
		}
		$("#precio_caja_c").val( total );	
	});

});

como dato adicional los campos " amount,precio_caja_c,cantidad_c" se crearon mediantte studio como tipo moneda

este codigo esta basado en un ejemplo de sugarcrm , funciona igual para suitecrm?

Hola, bueno yo lo hago un poco diferente, por ejemplo:

  1. Agregar el javascript en “custom/modules/Opportunities/metadata/editviewdefs.php” si no existe que es poco probable se puede copiar del mismo módulo

'includes' => 
      array (
        0 => 
        array (
          'file' => 'custom/modules/Opportunities/js/calculos.js',
        ),
      ),

y


'javascript' => '
        {literal}
        <script type="text/javascript">
        jQuery(function(){
          //calculos
          calculos();
        });
        </script>
        {/literal}
	  ',

el archivo JS tiene por ejemplo:


function calculos() {
$("#variable2_c").attr('onBlur','sumar();');
}
function sumar(){
	var variable1=document.getElementById("variable1_c").value;
	var variable2=document.getElementById("variable2_c").value;
	var total = Number(variable1) + Number(variable2);
	document.getElementById("total_c").value=total;
}

Que cuando se quita el focus del campo variable2_c ejecuta la funcion sumar()

Saludos

hola dampudia, trato de usar tu código pero no funciona , en que parte del editviewdefs.php se tiene que ubicar el código que sugieres.

  • el archivo se ubica en “custom/modules/Opportunities/metadata/editviewdefs.php”.
  • el JS esta en ‘custom/modules/Opportunities/js/calculos.js’ (el directorio js no existía lo he creado.)

te muestro el código de editviewdefs.php , me parece que no funciona por que no lo he puesto en el lugar correcto. al final esta el JS espero me puedas ayudar , gracias de antemano.


<?php
$viewdefs ['Opportunities'] = 
array (
  'EditView' => 
  array (
    'templateMeta' => 
    array (
      'maxColumns' => '2',
      'widths' => 
      array (
        0 => 
        array (
          'label' => '10',
          'field' => '30',
        ),
        1 => 
        array (
          'label' => '10',
          'field' => '30',
        ),
      ),
      'javascript' => '{$PROBABILITY_SCRIPT}',
      'useTabs' => true,
      'tabDefs' => 
      array (
        'DEFAULT' => 
        array (
          'newTab' => true,
          'panelDefault' => 'expanded',
        ),
        'LBL_PANEL_ASSIGNMENT' => 
        array (
          'newTab' => true,
          'panelDefault' => 'expanded',
        ),
        'LBL_EDITVIEW_PANEL1' => 
        array (
          'newTab' => false,
          'panelDefault' => 'expanded',
        ),
        'LBL_EDITVIEW_PANEL2' => 
        array (
          'newTab' => false,
          'panelDefault' => 'expanded',
        ),
        'LBL_EDITVIEW_PANEL3' => 
        array (
          'newTab' => true,
          'panelDefault' => 'expanded',
        ),
      ),
      'syncDetailEditViews' => true,
    ),
    'panels' => 
    array (
      'default' => 
      array (
        0 => 
        array (
          0 => 
          array (
            'name' => 'name',
          ),
          1 => 'account_name',
        ),
        1 => 
        array (
          0 => 
          array (
            'name' => 'ccanal_c',
            'studio' => 'visible',
            'label' => 'LBL_CCANAL',
          ),
          1 => '',
        ),
        2 => 
        array (
          0 => 
          array (
            'name' => 'currency_id',
            'label' => 'LBL_CURRENCY',
          ),
          1 => 
          array (
            'name' => 'date_closed',
          ),
        ),
        3 => 
        array (
          0 => 'opportunity_type',
          1 => 
          array (
            'name' => 'tipo_servicio_c',
            'studio' => 'visible',
            'label' => 'LBL_TIPO_SERVICIO',
          ),
        ),
        4 => 
        array (
          0 => 
          array (
            'name' => 'estado_c',
            'studio' => 'visible',
            'label' => 'LBL_ESTADO',
          ),
          1 => 
          array (
            'name' => 'lista_pre_c',
            'studio' => 'visible',
            'label' => 'LBL_LISTA_PRE',
          ),
        ),
        5 => 
        array (
          0 => 
          array (
            'name' => 'cmotivo_anulacion_c',
            'studio' => 'visible',
            'label' => 'LBL_CMOTIVO_ANULACION',
          ),
          1 => '',
        ),
      ),
      'LBL_PANEL_ASSIGNMENT' => 
      array (
        0 => 
        array (
          0 => 
          array (
            'name' => 'op_producto_rel_c',
            'studio' => 'visible',
            'label' => 'LBL_OP_PRODUCTO_REL',
          ),
          1 => 
          array (
            'name' => 'op_tipo_doc_vta_c',
            'studio' => 'visible',
            'label' => 'LBL_OP_TIPO_DOC_VTA',
          ),
        ),
        1 => 
        array (
          0 => 
          array (
            'name' => 'op_farmacia_c',
            'studio' => 'visible',
            'label' => 'LBL_OP_FARMACIA',
          ),
          1 => 
          array (
            'name' => 'ruc_c',
            'label' => 'LBL_RUC',
          ),
        ),
        2 => 
        array (
          0 => 
          array (
            'name' => 'cpais_c',
            'studio' => 'visible',
            'label' => 'LBL_CPAIS',
          ),
          1 => 
          array (
            'name' => 'razonsocial_c',
            'label' => 'LBL_RAZONSOCIAL',
          ),
        ),
        3 => 
        array (
          0 => 
          array (
            'name' => 'cdepartamento_c',
            'studio' => 'visible',
            'label' => 'LBL_CDEPARTAMENTO',
          ),
          1 => 
          array (
            'name' => 'op_forma_pago_c',
            'studio' => 'visible',
            'label' => 'LBL_OP_FORMA_PAGO',
          ),
        ),
        4 => 
        array (
          0 => 
          array (
            'name' => 'cprovincia_c',
            'studio' => 'visible',
            'label' => 'LBL_CPROVINCIA',
          ),
          1 => 
          array (
            'name' => 'op_modalidad_pago_c',
            'studio' => 'visible',
            'label' => 'LBL_OP_MODALIDAD_PAGO',
          ),
        ),
        5 => 
        array (
          0 => 
          array (
            'name' => 'cdistrito_c',
            'studio' => 'visible',
            'label' => 'LBL_CDISTRITO',
          ),
          1 => '',
        ),
        6 => 
        array (
          0 => 
          array (
            'name' => 'precio_unitario_c',
            'label' => 'LBL_PRECIO_UNITARIO',
          ),
          1 => 
          array (
            'name' => 'nro_tarjeta_c',
            'label' => 'LBL_NRO_TARJETA',
          ),
        ),
        7 => 
        array (
          0 => 
          array (
            'name' => 'precio_caja_c',
            'label' => 'LBL_PRECIO_CAJA',
          ),
          1 => 
          array (
            'name' => 'nro_verificacion_c',
            'label' => 'LBL_NRO_VERIFICACION',
          ),
        ),
        8 => 
        array (
          0 => 
          array (
            'name' => 'cantidad_c',
            'label' => 'LBL_CANTIDAD',
          ),
          1 => 
          array (
            'name' => 'f_expiracion_c',
            'label' => 'LBL_F_EXPIRACION',
          ),
        ),
        9 => 
        array (
          0 => 
          array (
            'name' => 'amount',
          ),
          1 => 
          array (
            'name' => 'dias_credito_c',
            'label' => 'LBL_DIAS_CREDITO',
          ),
        ),
        10 => 
        array (
          0 => '',
          1 => 
          array (
            'name' => 'banco_c',
            'label' => 'LBL_BANCO',
          ),
        ),
        11 => 
        array (
          0 => '',
          1 => 
          array (
            'name' => 'nro_operacion_c',
            'label' => 'LBL_NRO_OPERACION',
          ),
        ),
		
		
	// aqui el codigo sujerido ------------------------------------------------------------------------	
		
		
		'includes' => 
			array (
			0 => 
				array (
					'file' => 'custom/modules/Opportunities/js/calculos.js',
				),
        ),
		
		'javascript' => '
        {literal}
			<script type="text/javascript">
				jQuery(function(){
					
					calculos();
					
				});
			</script>
        {/literal}',
		
		),
		
	//  hasta aqui  el codigo ------------------------------------------------------------------------------------------	
		
      
      'lbl_editview_panel1' => 
      array (
        0 => 
        array (
          0 => 
          array (
            'name' => 'fecha_compra_far_c',
            'label' => 'LBL_FECHA_COMPRA_FAR',
          ),
          1 => 
          array (
            'name' => 'numero_boletas_c',
            'label' => 'LBL_NUMERO_BOLETAS',
          ),
        ),
        1 => 
        array (
          0 => 'description',
        ),
      ),
      'lbl_editview_panel2' => 
      array (
        0 => 
        array (
          0 => 
          array (
            'name' => 'jjwg_maps_address_c',
            'label' => 'LBL_JJWG_MAPS_ADDRESS',
          ),
        ),
      ),
      'lbl_editview_panel3' => 
      array (
        0 => 
        array (
          0 => 
          array (
            'name' => 'modo_entrega_c',
            'studio' => 'visible',
            'label' => 'LBL_MODO_ENTREGA',
          ),
          1 => 
          array (
            'name' => 'considera_hora_c',
            'studio' => 'visible',
            'label' => 'LBL_CONSIDERA_HORA',
          ),
        ),
        1 => 
        array (
          0 => 
          array (
            'name' => 'fecha_entrega_c',
            'label' => 'LBL_FECHA_ENTREGA',
          ),
          1 => 
          array (
            'name' => 'detalles_entrega_c',
            'studio' => 'visible',
            'label' => 'LBL_DETALLES_ENTREGA',
          ),
        ),
        2 => 
        array (
          0 => 
          array (
            'name' => 'ccourier_c',
            'studio' => 'visible',
            'label' => 'LBL_CCOURIER',
          ),
          1 => '',
        ),
        3 => 
        array (
          0 => 
          array (
            'name' => 'detalle_entrega_c',
            'studio' => 'visible',
            'label' => 'LBL_DETALLE_ENTREGA',
          ),
        ),
      ),
    ),
  ),
);
?>

aqui el Javascript:

function calculos() {
$("#cantidad_c").attr('onBlur','sumar();');
}
function sumar(){
	var variable1=document.getElementById("amount").value;
	var variable2=document.getElementById("cantidad_c").value;
	if(Number(variable2)!=0){
		var total = Number(variable1) / Number(variable2);
	}else{
		var total = 0;
	}
	document.getElementById("precio_caja_c").value=total;
}

Hola, por supuesto que la carpeta js no existe y la tienes que crear y el editviewdefs.php debe quedar así:


<?php
$viewdefs ['Opportunities'] = 
array (
  'EditView' => 
  array (
    'templateMeta' => 
    array (
      'maxColumns' => '2',
      'widths' => 
      array (
        0 => 
        array (
          'label' => '10',
          'field' => '30',
        ),
        1 => 
        array (
          'label' => '10',
          'field' => '30',
        ),
      ),
      'javascript' => '
        {literal}
        <script type="text/javascript">
        jQuery(function(){
          //calculos
          calculos();
        });
        </script>
        {/literal}
	  ',
	  'includes' => 
      array (
        0 => 
        array (
          'file' => 'custom/modules/Opportunities/js/calculos.js',
        ),
      ),
      'useTabs' => false,
      'tabDefs' => 
      array (
        'DEFAULT' => 
        array (
          'newTab' => false,
          'panelDefault' => 'expanded',
        ),
        'LBL_EDITVIEW_PANEL1' => 
        array (
          'newTab' => false,
          'panelDefault' => 'expanded',
        ),
        'LBL_PANEL_ASSIGNMENT' => 
        array (
          'newTab' => false,
          'panelDefault' => 'expanded',
        ),
      ),
      'syncDetailEditViews' => true,
    ),
    'panels' => 
    array (
      'default' => 
      array (
        0 => 
        array (
          0 => 
          array (
            'name' => 'name',
          ),
          1 => 'account_name',
        ),
        1 => 
        array (
          0 => 
          array (
            'name' => 'currency_id',
            'label' => 'LBL_CURRENCY',
          ),
          1 => 
          array (
            'name' => 'date_closed',
          ),
        ),
        2 => 
        array (
          0 => 
          array (
            'name' => 'amount',
          ),
          1 => 'opportunity_type',
        ),
        3 => 
        array (
          0 => 'sales_stage',
          1 => 'lead_source',
        ),
        4 => 
        array (
          0 => 'probability',
          1 => 'campaign_name',
        ),
        5 => 
        array (
          0 => 'next_step',
        ),
        6 => 
        array (
          0 => 'description',
        ),
      ),
      'lbl_editview_panel1' => 
      array (
        0 => 
        array (
          0 => 
          array (
            'name' => 'variable1_c',
            'label' => 'LBL_VARIABLE1',
          ),
          1 => 
          array (
            'name' => 'variable2_c',
            'label' => 'LBL_VARIABLE2',
          ),
        ),
        1 => 
        array (
          0 => 
          array (
            'name' => 'total_c',
            'label' => 'LBL_TOTAL',
          ),
        ),
      ),
      'LBL_PANEL_ASSIGNMENT' => 
      array (
        0 => 
        array (
          0 => 'assigned_user_name',
        ),
      ),
    ),
  ),
);
?>

SALUDOS

PD: agrégale esta linea al js para que te quede perfecto:

$("#amount").attr(‘onBlur’,‘sumar();’);

despues de:

$("#cantidad_c").attr(‘onBlur’,‘sumar();’);

:wink:

1 Like

Hola como andas la verdad no he logrado que sume esa vaina, necesito sumar 3 campos dentro de cuentas pero se me ha hecho imposible, cree o recree el mismo ejemplo que enviaste con las correcciones y nada tengo la versión, 7.8.8 de suite y no toma nada…

no se si me puedas hecha una mano de como lo podría lograr .

modules/Accounts/metadata

<?php /********************************************************************************* * SugarCRM Community Edition is a customer relationship management program developed by * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc. * SuiteCRM is an extension to SugarCRM Community Edition developed by Salesagility Ltd. * Copyright (C) 2011 - 2014 Salesagility Ltd. * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU Affero General Public License version 3 as published by the * Free Software Foundation with the addition of the following permission added * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more * details. * * You should have received a copy of the GNU Affero General Public License along with * this program; if not, see http://www.gnu.org/licenses or write to the Free * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301 USA. * * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road, * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com. * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU Affero General Public License version 3. * * In accordance with Section 7(b) of the GNU Affero General Public License version 3, * these Appropriate Legal Notices must retain the display of the "Powered by * SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not * reasonably feasible for technical reasons, the Appropriate Legal Notices must * display the words "Powered by SugarCRM" and "Supercharged by SuiteCRM". ********************************************************************************/ $viewdefs ['Accounts'] = array ( 'EditView' => array ( 'templateMeta' => array ( 'form' => array ( 'buttons' => array ( 0 => 'SAVE', 1 => 'CANCEL', ), ), 'maxColumns' => '2', 'widths' => array ( 0 => array ( 'label' => '10', 'field' => '30', ), 1 => array ( 'label' => '10', 'field' => '30', ), ), 'includes' => array ( 0 => array ( 'file' => 'modules/Accounts/Account.js', ), ), 'useTabs' => false, 'tabDefs' => array ( 'LBL_ACCOUNT_INFORMATION' => array ( 'newTab' => false, 'panelDefault' => 'expanded', ), 'LBL_PANEL_ADVANCED' => array ( 'newTab' => false, 'panelDefault' => 'expanded', ), ), ), 'panels' => array ( 'lbl_account_information' => array ( 0 => array ( 0 => array ( 'name' => 'name', 'label' => 'LBL_NAME', 'displayParams' => array ( 'required' => true, ), ), 1 => array ( 'name' => 'phone_office', 'label' => 'LBL_PHONE_OFFICE', ), ), 1 => array ( 0 => array ( 'name' => 'website', 'type' => 'link', 'label' => 'LBL_WEBSITE', ), 1 => array ( 'name' => 'phone_fax', 'label' => 'LBL_FAX', ), ), 2 => array ( 0 => array ( 'name' => 'email1', 'studio' => 'false', 'label' => 'LBL_EMAIL', ), ), 3 => array ( 0 => array ( 'name' => 'billing_address_street', 'hideLabel' => true, 'type' => 'address', 'displayParams' => array ( 'key' => 'billing', 'rows' => 2, 'cols' => 30, 'maxlength' => 150, ), ), 1 => array ( 'name' => 'shipping_address_street', 'hideLabel' => true, 'type' => 'address', 'displayParams' => array ( 'key' => 'shipping', 'copy' => 'billing', 'rows' => 2, 'cols' => 30, 'maxlength' => 150, ), ), ), 4 => array ( 0 => array ( 'name' => 'description', 'label' => 'LBL_DESCRIPTION', ), ), 5 => array ( 0 => array ( 'name' => 'assigned_user_name', 'label' => 'LBL_ASSIGNED_TO', ), ), ), 'LBL_PANEL_ADVANCED' => array ( 0 => array ( 0 => 'account_type', 1 => 'industry', ), 1 => array ( 0 => 'annual_revenue', 1 => 'employees', ), 2 => array ( 0 => 'parent_name', ), 3 => array ( 0 => 'campaign_name', ), ), ), ), ); ?>

quiero ingresar el ejemplo que envías para hacer la prueba js.

function calculos() {
$("#variable2_c").attr(‘onBlur’,‘sumar();’);
$("#amount").attr(‘onBlur’,‘sumar();’);
}
function sumar(){
var variable1=document.getElementById(“variable1_c”).value;
var variable2=document.getElementById(“variable2_c”).value;
var total = Number(variable1) + Number(variable2);
document.getElementById(“total_c”).value=total;
}

Hola, te faltaría invocar a la función calculos

‘javascript’ => ’
{literal}

jQuery(function(){

				calculos();
				
			});
		</script>
    {/literal}',

Por otro lado, en el ejemplo usé javascript porque permite realizar el cálculo en tiempo real de no ser el caso lo más recomendable es usar un logic hook.

Salu2

Buenas noches

Gracias por la respuesta --> ese código es para adicionar dentro de cuentas o oportunidades correcto.

si uno ingresa para el calculo en tiempo real… si se cargan los datos desde afuera quedan almacenados dentro de esa variable cargada verdad. o cuando dices tiempo real los datos no quedan almacenados.

Gracias

Este el el código dentro de oportunidades tal como lo designas y tampoco funciona. no suma nunca.

<?php $viewdefs ['Opportunities'] = array ( 'EditView' => array ( 'templateMeta' => array ( 'maxColumns' => '2', 'widths' => array ( 0 => array ( 'label' => '10', 'field' => '30', ), 1 => array ( 'label' => '10', 'field' => '30', ), ), 'javascript' => ' {literal} {/literal} ', 'includes' => array ( 0 => array ( 'file' => 'custom/modules/Opportunities/js/calculos.js', ), ), 'useTabs' => false, 'tabDefs' => array ( 'DEFAULT' => array ( 'newTab' => false, 'panelDefault' => 'expanded', ), 'LBL_EDITVIEW_PANEL1' => array ( 'newTab' => false, 'panelDefault' => 'expanded', ), 'LBL_PANEL_ASSIGNMENT' => array ( 'newTab' => false, 'panelDefault' => 'expanded', ), ), 'syncDetailEditViews' => true, ), 'panels' => array ( 'default' => array ( 0 => array ( 0 => array ( 'name' => 'name', ), 1 => 'account_name', ), 1 => array ( 0 => array ( 'name' => 'currency_id', 'label' => 'LBL_CURRENCY', ), 1 => array ( 'name' => 'date_closed', ), ), 2 => array ( 0 => array ( 'name' => 'amount', ), 1 => 'opportunity_type', ), 3 => array ( 0 => 'sales_stage', 1 => 'lead_source', ), 4 => array ( 0 => 'probability', 1 => 'campaign_name', ), 5 => array ( 0 => 'next_step', ), 6 => array ( 0 => 'description', ), ), 'lbl_editview_panel1' => array ( 0 => array ( 0 => array ( 'name' => 'variable1_c', 'label' => 'LBL_VARIABLE1', ), 1 => array ( 'name' => 'variable2_c', 'label' => 'LBL_VARIABLE2', ), ), 1 => array ( 0 => array ( 'name' => 'total_c', 'label' => 'LBL_TOTAL', ), ), ), 'LBL_PANEL_ASSIGNMENT' => array ( 0 => array ( 0 => 'assigned_user_name', ), ), ), ), ); ?>

https://cdn.pbrd.co/images/GZ2pglj.png

IMAGEN DE APOYO

Hola, si quieres ingresar datos desde fuera te recomiendo usar logic hook, en el ejemplo que muestro menciono tiempo real porque puedes ver automáticamente el cálculo después de ingresar las dos variables a sumar y eso no funcionaría para datos que ingresan de fuera porque javascript funciona en el cliente (navegador).

Con logic hook:

1 . crear un before_save

  1. en el código se tendría algo así:

class_nombre(){
function_nombre(&$bean, $event, $arguments){

$bean->total = $bean->var1 + $bean->var2;

}
}

Saludos

1 Like

Buenas tardes

Agradeciéndote por la ayuda este código en donde lo puedo ingresar para probadar dentro del metadata o dentro de algún argumento de php donde lo vaya a utilizar.

Gracias

Como estas, y porque no utilizas la funcionalidad de los Workflow de campos calculados, no lo calcula en tiempo real, pero ves reflejado el resultado en la vista de detalle, https://suitecrm.com/wiki/index.php/Userguide#Calculate_Fields

Buenas tardes

Ya lo realice pero quiero sumas tres valores y solo suma dos, tienes alguna respuesta para esto.

{add ({P0};{P1};{P2})}

aca solo suma p0+p1 pero el p2 lo deja por fuera…

???

Gracias

Buenas noches,

Creo que por el momento solo se pueden realizar operaciones con 2 parámetros, entonces tienes que hacer 2 sumas, la primera suma de P0 y P1 y la segunda el resultado de la suma de (P0+P1) + P2. Prueba con la siguiente sintaxis.

{add({add({P0};{P1})};{P2})}

1 Like

Hola! he conseguido que esto funcione restando valores. El tema es que cuando entro al registro de nuevo ya no me hace la formula, tengo que volver a rellenar todos los campos de nuevo para que haga la resta, si no me aparece en el total un “NaN”. Imagino que no leerá los campos que ya estén rellenos. Os pego el código js por si podéis ayudarme. Gracias.

function calculos() { $("#cantidar_restante_pago_c").attr('onBlur','restar();');
$("#pago_1_c").attr('onBlur','restar();');
$("#pago_2_c").attr('onBlur','restar();');
$("#pago_3_c").attr('onBlur','restar();');
$("#pago_4_c").attr('onBlur','restar();');
$("#pago_5_c").attr('onBlur','restar();'); } function restar(){
var variable1=document.getElementById("precio_del_producto_c").value;
var variable2=document.getElementById("pago_1_c").value;
var variable3=document.getElementById("pago_2_c").value;
var variable4=document.getElementById("pago_3_c").value;
var variable5=document.getElementById("pago_4_c").value;
var variable6=document.getElementById("pago_5_c").value;
var total = Number(variable1) - Number(variable2) - Number(variable3) - Number(variable4) - Number(variable5) - Number(variable6);
document.getElementById("cantidar_restante_pago_c").value=total; }