
var pType=Runner.pages.constants.PAGE_ADD;Runner.pages.PageSettings.addPageEvent("ranking_clientes_total",pType,"afterPageReady",function(pageObj,proxy,pageid,inlineRow,inlineObject){var limpiar=function(v){if(!v)return 0;return parseInt(v.toString().replace(/\./g,"").replace(/\D/g,""))||0;};var fMil=function(n){return n.toString().replace(/\D/g,"").replace(/\B(?=(\d{3})+(?!\d))/g,".");};setInterval(function(){var totalV=0;$("[id^='value_cantidad_']").each(function(){var id=this.id.split('_').pop();var c=limpiar($("#value_cantidad_"+id).val());var p=limpiar($("#value_precio_"+id).val());var i=limpiar($("#value_importe_"+id).val());var sub=c*(i>0?i:p);var $fSub=$("#value_subtotal_"+id);if($fSub.length&&$fSub.val()!==fMil(sub)){$fSub.val(fMil(sub));}
totalV+=sub;});$("[id*='total_venta']").val(fMil(totalV));var totalC=0;$("[id*='importe_cobro']").each(function(){totalC+=limpiar($(this).val());});$("[id*='total_cobro']").val(fMil(totalC));},500);$(document).off('click','a.runner-button').on('click','a.runner-button',function(e){if($(this).text().toLowerCase().indexOf("guardar")===-1)return true;var totalVenta=limpiar($("[id*='total_venta']").val());var totalCobro=limpiar($("[id*='total_cobro']").val());if($(".runner-error:visible").length>0)return true;if(totalVenta<=0){alert("⚠️ ¡RESTRICCIÓN!\n\nDebe cargar artículos en el Detalle!");e.preventDefault();e.stopImmediatePropagation();return false;}
if(totalCobro<=0){alert("⚠️ ¡RESTRICCIÓN!\n\nDebe indicar el importe en la sección de Cobros!");e.preventDefault();e.stopImmediatePropagation();return false;}
return true;});;});var pType=Runner.pages.constants.PAGE_LIST;Runner.pages.PageSettings.addPageEvent("ranking_clientes_total",pType,"afterPageReady",function(pageObj,proxy,pageid){pageObj.buttonNames[pageObj.buttonNames.length]='New_Button15';if(!pageObj.buttonEventBefore['New_Button15']){pageObj.buttonEventBefore['New_Button15']=function(params,ctrl,pageObj,proxy,pageid,rowData){params["txt"]="Hello";ctrl.setMessage("Sending request to server...");}}
if(!pageObj.buttonEventAfter['New_Button15']){pageObj.buttonEventAfter['New_Button15']=function(result,ctrl,pageObj,proxy,pageid,rowData){var where=result["where"];var order=result["order"];var tabla=result["tabla"];window.open('generar_portrait.php?tabla='+tabla+'&where='+where+'&order='+order,'_blank');}}
$('a[id=New_Button15]').each(function(){if(!$(this).closest('tr.gridRowAdd').length){var newId="New_Button15"+"_"+Runner.genId();this.id=newId;var button_New_Button15=new Runner.form.Button({id:newId,btnName:"New_Button15"});button_New_Button15.init({args:[pageObj,proxy,pageid]});}});});