<?php
require('../../_lib/vr_updcol.php');

class vrupdt0
{
var $idreturn;
	function vrupdt0($tabla,$codigo)
	{
// 		session_start();
		require('../cfg/cfg.php');
		require('../cfg/res.php');

// 		require('../../_lib/vr_updcol.php');

		$tabla0=$tabla.'0';
		echo "\n";
		echo "\n";
		echo strtoupper($tabla0).' --> '.$codigo;

		mysql_query('create table '.$tabla0.' ('.$tabla.'_codigo char('.$codigo.')not null)engine=innodb',$link_vcrx);
		mysql_query('alter table '.$tabla0.' engine=innodb, default character set=latin1 collate=latin1_spanish_ci',$link_vcrx);

		$upd0=new vrupdcol($tabla0,$tabla.'_codigo','char('.$codigo.')','','');
		mysql_query('alter table '.$tabla0.' drop primary key',$link_vcrx);
		mysql_query('alter table '.$tabla0.' add primary key('.$tabla.'_codigo)',$link_vcrx);
		
		$upd0=new vrupdcol($tabla0,$tabla.'_descri','varchar(60)',$upd0->colafter,'');
		$upd0=new vrupdcol($tabla0,$tabla.'_tipo','varchar(4)',$upd0->colafter,'');
		$upd0=new vrupdcol($tabla0,$tabla.'_status','char(1)',$upd0->colafter,'-');
		$upd0=new vrupdcol($tabla0,$tabla.'_iuser','char(10)',$upd0->colafter,'');
		$upd0=new vrupdcol($tabla0,$tabla.'_idate','datetime',$upd0->colafter,'');
		$upd0=new vrupdcol($tabla0,$tabla.'_lused','datetime',$upd0->colafter,'');

		if (mb_stristr('fpag',$tabla)){echo '*** fpag';}
		
		
		if (mb_stristr('empr',$tabla)){
			$upd0=new vrupdcol($tabla0,$tabla.'_ruc','varchar(13)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_numid','varchar(13)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_dnrdp','varchar(7)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_ruclegal','varchar(13)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_ruccontador','varchar(13)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_regcontador','varchar(10)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_lguia','int',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_vcupo','char(1)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_bcupo','char(1)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_fweek','smallint',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_fdow','smallint',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_linx','smallint',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_modi','smallint',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_anul','smallint',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_elim','smallint',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_fcont','date',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_fcaja','date',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_fbcos','date',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_finve','date',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_fcxco','date',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_fcxpa','date',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_ambice','char(1)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_ambientece','X',$upd0->colafter,'');
// 			$upd0=new vrupdcol($tabla0,$tabla.'_pru1','X',$upd0->colafter,'');
		}

		if (mb_stristr('user.usrt',$tabla)){
			$upd0=new vrupdcol($tabla0,$tabla.'_cedula','varchar(13)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_empresa','varchar(13)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_nickname','varchar(20)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_email','varchar(50)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_telefono','varchar(15)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_solicita','char(1)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_clave','varchar(50)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_captcha','varchar(10)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_cargo','varchar(20)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_caduca','date',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_apuni','char(1)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_adcto','char(1)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_apvp','char(1)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_ptov','varchar(4)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_caja','varchar(4)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_bode','varchar(4)',$upd0->colafter,'');
		
			mysql_query('alter table '.$tabla0.' change column '.$tabla.'_codigo '.$tabla.'_codigo int not null auto_increment first',$link_vcrx);
// 			mysql_query('alter table usrt0 change column usrt_codigo int not null auto_increment first',$link_vcrx);

			mysql_query('alter table '.$tabla0.' alter column '.$tabla.'_status drop default',$link_vcrx);
// 			mysql_query('alter table usrt0 alter column usrt_status drop default',$link_vcrx);

// 			mysql_query('alter table '.$tabla0.' alter column '.$tabla.'_status set default "1"',$link_vcrx);
			mysql_query('alter table user0 alter column user_status set default "1"',$link_vcrx);
			mysql_query('alter table usrt0 alter column usrt_status set default "0"',$link_vcrx);


			mysql_query('alter table '.$tabla0.' alter column '.$tabla.'_tipo drop default',$link_vcrx);
// 			mysql_query('alter table usrt0 alter column usrt_tipo drop default',$link_vcrx);

			mysql_query('alter table '.$tabla0.' alter column '.$tabla.'_tipo set default "clie"',$link_vcrx);
// 			mysql_query('alter table usrt0 alter column usrt_tipo set default "clie"',$link_vcrx);
		}		
		
		if (mb_stristr('docu',$tabla)){
			$upd0=new vrupdcol($tabla0,$tabla.'_tabla','varchar(4)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_codnum','varchar(4)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_ptoe','varchar(6)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_numero','int(9)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_autonum','char(1)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_autofec','char(1)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_desde','date',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_hasta','date',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_maxdeta','smallint(3)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_bakdeta','tinyint(1)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_copia','tinyint(1)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_doble','tinyint(1)',$upd0->colafter,'');

			$upd0=new vrupdcol($tabla0,$tabla.'_apuni','char(1)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_adcto','char(1)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_apvp','char(1)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_vstock','char(1)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_bstock','char(1)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_vreser','char(1)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_breser','char(1)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_dreser','smallint',$upd0->colafter,'');
		
			$upd0=new vrupdcol($tabla0,$tabla.'_rescont','char(1)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_ctadeb','varchar(13)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_ctacre','varchar(13)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_ctadcto','varchar(13)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_ctaice','varchar(13)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_ctaiva','varchar(13)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_ctairbp','varchar(13)',$upd0->colafter,'');

			$upd0=new vrupdcol($tabla0,$tabla.'_tico','varchar(2)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_suco','varchar(2)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_at_a','varchar(4)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_at02','varchar(4)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_at03','varchar(2)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_tice','varchar(2)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_fpag','varchar(2)',$upd0->colafter,'');

			$upd0=new vrupdcol($tabla0,$tabla.'_modi','smallint(3)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_anul','smallint(3)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_elim','smallint(3)',$upd0->colafter,'');
}
		
		if (mb_stristr('ctas',$tabla)){
 			$upd0=new vrupdcol($tabla0,$tabla.'_signo','smallint(2)',$upd0->colafter,'');
// 			$upd0=new vrupdcol($tabla0,$tabla.'_info','smallint(1)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_codigoc','varchar(12)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_cair','varchar(5)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_nec','varchar(12)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_niif','varchar(12)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_sri01','smallint(3)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_sri101','smallint(3)',$upd0->colafter,'');

			
		}

		if (mb_stristr('enti',$tabla)){
			$upd0=new vrupdcol($tabla0,$tabla.'_struc','char(1)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_cedularuc','varchar(13)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_pasaporte','varchar(20)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_conadis','varchar(13)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_dnrdp','varchar(7)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_dndrp','X','','');
			$upd0=new vrupdcol($tabla0,$tabla.'_razsoc','varchar(60)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_nomcom','varchar(50)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_fechaini','date',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_ape1','varchar(50)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_ape2','varchar(50)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_nom1','varchar(50)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_nom2','varchar(50)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_fechanac','date',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_sexo','char(1)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_stcivil','char(1)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_referidox','varchar(10)',$upd0->colafter,'');

			// ELIMINAR
			$upd0=new vrupdcol($tabla0,$tabla.'_calle1','varchar(30)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_calle2','varchar(30)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_calle3','varchar(30)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_callen','varchar(3)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_telefono','varchar(15)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_email','varchar(30)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_contacto','varchar(30)',$upd0->colafter,'');
			
			$upd0=new vrupdcol($tabla0,$tabla.'_adrs','int(9)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_zsub','varchar(9)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_vndd','varchar(10)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_rcdd','varchar(10)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_csub','varchar(9)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_cargo','varchar(20)',$upd0->colafter,'');

			$upd0=new vrupdcol($tabla0,$tabla.'_tpro','varchar(4)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_coesp','char(1)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_obcon','char(1)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_rise','char(1)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_pcesp','varchar(1)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_pcont','varchar(1)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_prise','varchar(1)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_fp90','varchar(1)',$upd0->colafter,'');

			$upd0=new vrupdcol($tabla0,$tabla.'_direccion','varchar(250)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_pais','varchar(4)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_cdad','varchar(6)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_origing','char(1)',$upd0->colafter,'');

			$upd0=new vrupdcol($tabla0,$tabla.'_dcto','decimal(6,2)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_comi','decimal(6,2)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_cupo','decimal(9,2)',$upd0->colafter,'');

			$upd0=new vrupdcol($tabla0,$tabla.'_tipoctab','char(1)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_numectab','varchar(10)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_bcosctab','varchar(4)',$upd0->colafter,'');

			$upd0=new vrupdcol($tabla0,$tabla.'_ctaxcob','varchar(12)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_ctaxpag','varchar(12)',$upd0->colafter,'');
			
			$upd0=new vrupdcol($tabla0,$tabla.'_saldo','X',$upd0->colafter,'');
			
			$index='cedularuc';	mysql_query('drop index '.$cedularuc.' on '.$tabla0);	mysql_query('create index '.$cedularuc.' on '.$tabla0.'('.$tabla.'_'.$index.')');
			
		}

		if (mb_stristr('item',$tabla)){

			$upd0=new vrupdcol($tabla0,$tabla.'_puni','decimal(11,4)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_dcto','decimal(4,2)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_ice','decimal(4,2)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_iva','decimal(4,2)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_irbp','decimal(4,2)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_pvp1','decimal(11,4)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_pcp1','decimal(11,4)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_duni','char(1)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_dval','char(1)',$upd0->colafter,'');

			$upd0=new vrupdcol($tabla0,$tabla.'_ean','varchar(13)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_codigov','varchar(20)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_codigoc','varchar(13)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_codigop','varchar(13)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_numpart','varchar(20)',$upd0->colafter,'');

// 			$upd0=new vrupdcol($tabla0,$tabla.'_envase','varchar(13)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_codxunid','varchar(13)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_unixpack','mediumint(6)',$upd0->colafter,'');
// 			$upd0=new vrupdcol($tabla0,$tabla.'_uxpack','mediumint(6)',$upd0->colafter,'');

			$upd0=new vrupdcol($tabla0,$tabla.'_ubik','varchar(4)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_umdd','varchar(4)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_mdda','varchar(4)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_medida','varchar(20)',$upd0->colafter,'');

			$upd0=new vrupdcol($tabla0,$tabla.'_lado','varchar(2)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_tlla','varchar(4)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_clor','varchar(4)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_kldd','varchar(4)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_tmno','varchar(4)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_dmtr','varchar(10)',$upd0->colafter,'');

			$upd0=new vrupdcol($tabla0,$tabla.'_lsub','varchar(9)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_mrca','varchar(4)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_mdlo','varchar(10)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_pais','varchar(4)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_provee','varchar(13)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_modelo','varchar(20)',$upd0->colafter,'');

			$upd0=new vrupdcol($tabla0,$tabla.'_clie','char(1)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_prov','char(1)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_empl','char(1)',$upd0->colafter,'');

			$upd0=new vrupdcol($tabla0,$tabla.'_cret','varchar(3)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_bser','varchar(2)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_cair','varchar(5)',$upd0->colafter,'');

			$upd0=new vrupdcol($tabla0,$tabla.'_at04','varchar(3)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_at06','varchar(3)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'ice04','varchar(4)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'ice05','varchar(2)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'ice06','varchar(6)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'ice07','varchar(3)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'ice08','varchar(6)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'ice09','varchar(2)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'ice10','varchar(3)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'ice11','varchar(6)',$upd0->colafter,'');

			$upd0=new vrupdcol($tabla0,$tabla.'_ctavtas','varchar(13)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_ctacomp','varchar(13)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_ctainve','varchar(13)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_ctanomi','varchar(13)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_ctadcto','varchar(13)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_ctaice','varchar(13)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_ctaiva','varchar(13)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_ctairbp','varchar(13)',$upd0->colafter,'');

			$upd0=new vrupdcol($tabla0,$tabla.'_nctlg','smallint(4)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_pctlg','smallint(4)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_hoja','char(1)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_carr','char(1)',$upd0->colafter,'');

// 	mysql_query('alter table item0 alter column item_lsub set default "GENE-GENE"',$link_vcrx);
	mysql_query('insert into '.$tabla0.'('.$tabla.'_codigo,'.$tabla.'_descri)value("100000","ITEMS")',$link_vcrx);

			$upd0=new vrupdcol($tabla0,'lado','char(1)',$upd0->colafter,'');
			if(mb_stristr('rcsa',$_SESSION['user_vcrx_empr']))
			{
			$upd0=new vrupdcol($tabla0,'fr','char(1)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,'re','char(1)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,'rh','char(1)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,'lh','char(1)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,'orig','char(1)',$upd0->colafter,'');
			}
		}
		

		if (mb_stristr('nvdd',$tabla)){
			$upd0=new vrupdcol($tabla0,$tabla.'_abrev','varchar(10)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_posi','tinyint(3)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_puni','decimal(11,4)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_ctacont','varchar(13)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_codigon','varchar(13)',$upd0->colafter,'');
			mysql_query('insert into '.$tabla0.'('.$tabla.'_codigo,'.$tabla.'_descri)value("90000","NOVEDADES")',$link_vcrx);
		}
		
		
		
		if (mb_stristr('cair',$tabla)){
			$upd0=new vrupdcol($tabla0,$tabla.'_porc', 'decimal(5,2)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_bser', 'varchar(4)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_ctacont', 'varchar(13)',$upd0->colafter,'');
		//	$upd0=new vrupdcol($tabla0,$tabla.'_rrta', 'decimal(5,2)',$upd0->colafter,'');
		//	$upd0=new vrupdcol($tabla0,$tabla.'_riva', 'decimal(5,2)',$upd0->colafter,'');
		}

		if (mb_stristr('caja',$tabla)){
			$upd0=new vrupdcol($tabla0,$tabla.'_ptoe', 'varchar(6)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_ptov', 'varchar(6)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_ctacont', 'varchar(13)',$upd0->colafter,'');
		}

		if (mb_stristr('ptov',$tabla)){
			$upd0=new vrupdcol($tabla0,$tabla.'_ptoe', 'varchar(6)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_caja', 'varchar(4)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_bode', 'varchar(4)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_ctacont', 'varchar(13)',$upd0->colafter,'');
		}

		if (mb_stristr('bode',$tabla)){
			$upd0=new vrupdcol($tabla0,$tabla.'_ptoe', 'varchar(6)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_ptov', 'varchar(6)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_ctacont', 'varchar(13)',$upd0->colafter,'');
		}

		if (mb_stristr('ctab',$tabla)){
			$upd0=new vrupdcol($tabla0,$tabla.'_ptoe', 'varchar(6)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_bcos', 'varchar(4)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_ctacont', 'varchar(13)',$upd0->colafter,'');
		}

		if (mb_stristr('pais',$tabla)){
			$upd0=new vrupdcol($tabla0,$tabla.'_ats', 'varchar(4)',$upd0->colafter,'');
		}

		if (mb_stristr('atrz',$tabla)){
			$upd0=new vrupdcol($tabla0,$tabla.'_entidad', 'varchar(13)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_docu', 'varchar(2)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_ptoe', 'varchar(6)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_serie', 'varchar(6)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_srie', 'varchar(6)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_desde', 'int(9)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_hasta', 'int(9)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_enti', 'varchar(13)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_caduca', 'date',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_claveacc', 'varchar(49)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_atrznume', 'varchar(49)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_atrzfech', 'varchar(16)',$upd0->colafter,'');
		}

		if (mb_stristr('atrd',$tabla)){
// 			$upd0=new vrupdcol($tabla0,$tabla.'_entidad', 'varchar(13)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_atrz', 'varchar(10)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_docu', 'varchar(2)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_ptoe', 'varchar(6)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_desde', 'int(9)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_hasta', 'int(9)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_caduca', 'date',$upd0->colafter,'');

			mysql_query('delete from '.$tabla0.' where '.$tabla.'_codigo=0',$link_vcrx);
			mysql_query('alter table '.$tabla0.' change column '.$tabla.'_codigo int not null auto_increment first',$link_vcrx);
		}

		if (mb_stristr('zsub',$tabla)){
			$upd0=new vrupdcol($tabla0,$tabla.'_vndd', 'varchar(10)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_rcdd', 'varchar(10)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_ctaxcob', 'varchar(12)',$upd0->colafter,'');
		}

		if (mb_stristr('tpro',$tabla)){
			$upd0=new vrupdcol($tabla0,$tabla.'_ctaxpag', 'varchar(12)',$upd0->colafter,'');
		}

		if (mb_stristr('lsub',$tabla)){
			$upd0=new vrupdcol($tabla0,$tabla.'_ctavtas', 'varchar(12)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_ctainve', 'varchar(12)',$upd0->colafter,'');
		}

		if (mb_stristr('lote',$tabla)){
			$upd0=new vrupdcol($tabla0,$tabla.'_fabric', 'date',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_caduca', 'date',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_costo', 'decimal(13,4)',$upd0->colafter,'');
		}

		if (mb_stristr('port',$tabla)){
			$upd0=new vrupdcol($tabla0,$tabla.'_pais', 'varchar(4)',$upd0->colafter,'');
		}

		if (mb_stristr('cntn',$tabla)){
			$upd0=new vrupdcol($tabla0,$tabla.'_factory', 'varchar(20)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_customer', 'varchar(20)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_fecfact', 'date',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_idweb', 'date',$upd0->colafter,'');
		}

		if (mb_stristr('bldn',$tabla)){
			$upd0=new vrupdcol($tabla0,$tabla.'_master', 'varchar(20)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_house', 'varchar(20)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_job', 'varchar(10)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_booking', 'varchar(20)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_cntn', 'varchar(11)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_consigna', 'varchar(13)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_manifiesto', 'varchar(20)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_agnt', 'varchar(13)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_vndd', 'varchar(10)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_nave1', 'varchar(6)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_nave2', 'varchar(6)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_viaje', 'varchar(10)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_port1', 'varchar(9)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_port2', 'varchar(9)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_fecha1', 'date',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_fecha2', 'date',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_peso', 'decimal(13,2)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_carga', 'varchar(30)',$upd0->colafter,'');

			$upd0=new vrupdcol($tabla0,$tabla.'_idweb', 'date',$upd0->colafter,'');

		}

		if (mb_stristr('vhcl',$tabla)){
			$upd0=new vrupdcol($tabla0,$tabla.'_placa', 'varchar(8)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_vinn', 'varchar(17)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_motor', 'varchar(20)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_cilindro', 'smallint(4)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_pais', 'varchar(4)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_clase', 'varchar(4)',$upd0->colafter,'');

			$upd0=new vrupdcol($tabla0,$tabla.'_mrca', 'varchar(4)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_mdlo', 'varchar(10)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_anio', 'smallint(4)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_clor', 'varchar(4)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_clor2', 'varchar(4)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_conductor', 'varchar(30)',$upd0->colafter,'');

			$upd0=new vrupdcol($tabla0,$tabla.'_idweb', 'date',$upd0->colafter,'');

		}

		if (mb_stristr('sntr',$tabla)){
			$upd0=new vrupdcol($tabla0,$tabla.'_numero', 'varchar(15)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_seguro', 'varchar(13)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_poliza', 'varchar(7)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_vhcl', 'varchar(7)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_entrega', 'varchar(30)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_ejecutivo', 'varchar(30)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_asegurado', 'varchar(30)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_lugar', 'varchar(30)',$upd0->colafter,'');
		}

		if (mb_stristr('imgi',$tabla)){
			$upd0=new vrupdcol($tabla0,$tabla.'_codigo','int(9)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_defa','char(1)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_item', 'varchar(13)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_file', 'varchar(30)',$upd0->colafter,'');
// 			$upd0=new vrupdcol($tabla0,$tabla.'_fileo', 'varchar(20)',$upd0->colafter,'');

			mysql_query('delete from '.$tabla0.' where '.$tabla.'_codigo=0',$link_vcrx);
			mysql_query('alter table '.$tabla0.' change column '.$tabla.'_codigo int not null auto_increment first',$link_vcrx);
		}

		if (mb_stristr('imge',$tabla)){
			$upd0=new vrupdcol($tabla0,$tabla.'_codigo','int(9)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_defa','char(1)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_enti', 'varchar(13)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_file', 'varchar(30)',$upd0->colafter,'');

			mysql_query('delete from '.$tabla0.' where '.$tabla.'_codigo=0',$link_vcrx);
			mysql_query('alter table '.$tabla0.' change column '.$tabla.'_codigo int not null auto_increment first',$link_vcrx);
		}


		if (mb_stristr('adrs',$tabla)){
			$upd0=new vrupdcol($tabla0,$tabla.'_codigo','int(9)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_defa','char(1)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_enti', 'varchar(13)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_sucu','varchar(3)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_area', 'varchar(4)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_tlfn', 'varchar(10)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_ext', 'varchar(5)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_nombre', 'varchar(30)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_contacto', 'varchar(30)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_direccion', 'varchar(100)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_opera', 'varchar(4)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_ciudad', 'varchar(20)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_pais', 'varchar(6)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_cdad', 'varchar(6)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_cpostal', 'varchar(10)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_calle1', 'varchar(50)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_calle2', 'varchar(50)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_callen', 'varchar(50)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_calle3', 'varchar(50)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_email', 'varchar(50)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_gps1', 'decimal(15,10)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_gps2', 'decimal(15,10)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_cntnombre', 'varchar(50)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_cntdirecc', 'varchar(50)',$upd0->colafter,'');

			$upd0=new vrupdcol($tabla0,$tabla.'_idweb', 'date',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_suc','X');
			$upd0=new vrupdcol($tabla0,$tabla.'_sucursal','X');

			mysql_query('delete from '.$tabla0.' where '.$tabla.'_codigo=0',$link_vcrx);
			mysql_query('alter table '.$tabla0.' change column '.$tabla.'_codigo int not null auto_increment first',$link_vcrx);
		}

		
		if (mb_stristr('suel',$tabla)){
		$upd0=new vrupdcol($tabla0,$tabla.'_codigo','int(9)',$upd0->colafter,'');
		$upd0=new vrupdcol($tabla0,$tabla.'_cargo','varchar(20)',$upd2->colafter,'');
		$upd0=new vrupdcol($tabla0,$tabla.'_fecha','date',$upd2->colafter,'');
		$upd0=new vrupdcol($tabla0,$tabla.'_sueldo','decimal(9,2)',$upd2->colafter,'');
		$upd0=new vrupdcol($tabla0,$tabla.'_poranti','decimal(5,2)',$upd2->colafter,'');
		$upd0=new vrupdcol($tabla0,$tabla.'_valanti','decimal(9,2)',$upd2->colafter,'');
		$upd0=new vrupdcol($tabla0,$tabla.'_iess','varchar(1)',$upd2->colafter,'');
		$upd0=new vrupdcol($tabla0,$tabla.'_reloj','varchar(1)',$upd2->colafter,'');
		$upd0=new vrupdcol($tabla0,$tabla.'_atraso','varchar(1)',$upd2->colafter,'');
		$upd0=new vrupdcol($tabla0,$tabla.'_falta','varchar(1)',$upd2->colafter,'');
		$upd0=new vrupdcol($tabla0,$tabla.'_h025','varchar(1)',$upd2->colafter,'');
		$upd0=new vrupdcol($tabla0,$tabla.'_h050','varchar(1)',$upd2->colafter,'');
		$upd0=new vrupdcol($tabla0,$tabla.'_h100','varchar(1)',$upd2->colafter,'');
		$upd0=new vrupdcol($tabla0,$tabla.'_de13','varchar(1)',$upd2->colafter,'');
		$upd0=new vrupdcol($tabla0,$tabla.'_de14','varchar(1)',$upd2->colafter,'');
		$upd0=new vrupdcol($tabla0,$tabla.'_fres','varchar(1)',$upd2->colafter,'');

		mysql_query('delete from '.$tabla0.' where '.$tabla.'_codigo=0',$link_vcrx);
		mysql_query('alter table '.$tabla0.' change column '.$tabla.'_codigo int not null auto_increment first',$link_vcrx);
		}		
		
		if (mb_stristr('tlfn',$tabla)){
			$upd0=new vrupdcol($tabla0,$tabla.'_codigo','int(15)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_adrs','int(9)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_defa','char(1)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_enti', 'varchar(13)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_suc','varchar(3)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_area', 'varchar(4)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_tlfn', 'varchar(10)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_ext', 'varchar(4)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_nombre', 'varchar(50)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_contacto', 'varchar(30)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_direccion', 'varchar(100)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_opera', 'varchar(4)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_ciudad', 'varchar(20)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_pais', 'varchar(6)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_cdad', 'varchar(6)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_cpostal', 'varchar(10)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_calle1', 'varchar(15)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_calle2', 'varchar(15)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_callen', 'varchar(15)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_calle3', 'varchar(15)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_email', 'varchar(50)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_cntnombre', 'varchar(50)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_cntdirecc', 'varchar(50)',$upd0->colafter,'');

			$upd0=new vrupdcol($tabla0,$tabla.'_idweb', 'date',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_sucursal','X');

			mysql_query('alter table '.$tabla0.' change column '.$tabla.'_codigo int not null auto_increment first',$link_vcrx);

		}

		if (mb_stristr('mrca',$tabla)){
			$upd0=new vrupdcol($tabla0,$tabla.'_enti', 'varchar(13)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_mrca', 'varchar(4)',$upd0->colafter,'');
		}

		if (mb_stristr('mdlo',$tabla)){
			$upd0=new vrupdcol($tabla0,$tabla.'_enti', 'varchar(13)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_mrca', 'varchar(4)',$upd0->colafter,'');
			$upd0=new vrupdcol($tabla0,$tabla.'_anio', 'varchar(4)',$upd0->colafter,'');
		}
		
		
		// INDICES
		mysql_query('drop index codigo on '.$tabla0,$link_vcrx);
		mysql_query('create unique index codigo on '.$tabla0.'('.$tabla.'_codigo)',$link_vcrx);
		
		mysql_query('drop index descri on '.$tabla0,$link_vcrx);
		mysql_query('create 	index descri on '.$tabla0.'('.$tabla.'_descri,'.$tabla.'_codigo)',$link_vcrx);
	
			
		// ASIGNA VALORES
		if (mb_stristr('user.usrt',$tabla)){
			mysql_query('insert into '.$tabla.'('.$tabla.'_codigo,'.$tabla.'_descri) value("-","NUEVO")',$link_vcrx);
		}

		if (mb_stristr('empr',$tabla)){
			mysql_query('insert into '.$tabla.'0('.$tabla.'_codigo,'.$tabla.'_descri) value("'.strtoupper($_SESSION['user_vcrx_empr']).'","'.strtoupper($_SESSION['user_vcrx_empr']).'")',$link_vcrx);
		}
	
		if (mb_stristr('enti',$tabla)){
			mysql_query('insert into '.$tabla.'0('.$tabla.'_codigo,'.$tabla.'_descri)value("9999999999999","CONSUMIDOR FINAL")',$link_vcrx);
		}
	
		if (mb_stristr('item',$tabla)){
			mysql_query('insert into '.$tabla.'0('.$tabla.'_codigo,'.$tabla.'_descri)value("100000","ITEMS")',$link_vcrx);
		}
	
		if (mb_stristr('lado',$tabla)){
			mysql_query('insert into '.$tabla.'0('.$tabla.'_codigo,'.$tabla.'_descri)value("0","NO DEFINIDO")',$link_vcrx);
			mysql_query('insert into '.$tabla.'0('.$tabla.'_codigo,'.$tabla.'_descri)value("FR","ANTERIOR)',$link_vcrx);
			mysql_query('insert into '.$tabla.'0('.$tabla.'_codigo,'.$tabla.'_descri)value("RE","POSTERIOR")',$link_vcrx);
			mysql_query('insert into '.$tabla.'0('.$tabla.'_codigo,'.$tabla.'_descri)value("RH","DERECHO")',$link_vcrx);
			mysql_query('insert into '.$tabla.'0('.$tabla.'_codigo,'.$tabla.'_descri)value("LH","IZQUIERDO")',$link_vcrx);
			mysql_query('insert into '.$tabla.'0('.$tabla.'_codigo,'.$tabla.'_descri)value("UP","SUPERIOR")',$link_vcrx);
			mysql_query('insert into '.$tabla.'0('.$tabla.'_codigo,'.$tabla.'_descri)value("DO","INFERIOR")',$link_vcrx);
			mysql_query('insert into '.$tabla.'0('.$tabla.'_codigo,'.$tabla.'_descri)value("IN","INTERNO")',$link_vcrx);
			mysql_query('insert into '.$tabla.'0('.$tabla.'_codigo,'.$tabla.'_descri)value("EX","EXTERNO")',$link_vcrx);
		}
	
	
	}
}

class vrupdt1
{
	function vrupdt1($tabla)
	{
// 		session_start();
		require('../cfg/cfg.php');
		require('../cfg/res.php');

// 		require('../../_lib/vr_updcol.php');

		$tabla1=$tabla.'1';
		$tabla2=$tabla.'2';
		echo "\n";
		echo strtoupper($tabla1).' --> '.$tabla2;
		echo "\n";

		mysql_query('create table '.$tabla1.'(idnum1 int not null primary key auto_increment) engine=innodb',$link_vcrx);
		mysql_query('create table '.$tabla2.'(idnum2 int not null) engine=innodb',$link_vcrx);
		mysql_query('create table '.$tabla3.'(idnum3 int not null) engine=innodb',$link_vcrx);
	
		mysql_query('alter table '.$tabla1.' engine=innodb, default character set=latin1 collate=latin1_spanish_ci',$link_vcrx);
		mysql_query('alter table '.$tabla2.' engine=innodb, default character set=latin1 collate=latin1_spanish_ci',$link_vcrx);
		mysql_query('alter table '.$tabla3.' engine=innodb, default character set=latin1 collate=latin1_spanish_ci',$link_vcrx);

	
		// TABLA 1
		$upd1=new vrupdcol($tabla1,'empr','varchar(4)','idnum1','');

		$upd1=new vrupdcol($tabla1,'docu','varchar(4)',$upd1->colafter,'');
		$upd1=new vrupdcol($tabla1,'ptoe','varchar(6)',$upd1->colafter,'001001');
		$upd1=new vrupdcol($tabla1,'numero','varchar(9)',$upd1->colafter,'');
		$upd1=new vrupdcol($tabla1,'fecha','date',$upd1->colafter,'');
		$upd1=new vrupdcol($tabla1,'plazo','smallint(3)',$upd1->colafter,'0');
		$upd1=new vrupdcol($tabla1,'enti','varchar(13)',$upd1->colafter,'');
		$upd1=new vrupdcol($tabla1,'ptov','varchar(4)',$upd1->colafter,'');
		$upd1=new vrupdcol($tabla1,'bode','varchar(4)',$upd1->colafter,'');
		$upd1=new vrupdcol($tabla1,'caja','varchar(4)',$upd1->colafter,'');
		$upd1=new vrupdcol($tabla1,'ctab','varchar(4)',$upd1->colafter,'');

		$upd1=new vrupdcol($tabla1,'concepto','varchar(250)',$upd1->colafter,'');

		$upd1=new vrupdcol($tabla1,'zsub','varchar(9)',$upd1->colafter,'');
		$upd1=new vrupdcol($tabla1,'csub1','varchar(9)',$upd1->colafter,'');
		$upd1=new vrupdcol($tabla1,'ctas1','varchar(9)',$upd1->colafter,'');
		$upd1=new vrupdcol($tabla1,'item1','varchar(13)',$upd1->colafter,'');

		$upd1=new vrupdcol($tabla1,'stfin','char(1)',$upd1->colafter,'0');
		$upd1=new vrupdcol($tabla1,'status','char(1)',$upd1->colafter,'-');

		$upd1=new vrupdcol($tabla1,'iuser','varchar(10)',$upd1->colafter,'');
		$upd1=new vrupdcol($tabla1,'idate','datetime',$upd1->colafter,'');
		$upd1=new vrupdcol($tabla1,'ouser','varchar(10)',$upd1->colafter,'');
		$upd1=new vrupdcol($tabla1,'odate','datetime',$upd1->colafter,'');
		$upd1=new vrupdcol($tabla1,'xuser','varchar(10)',$upd1->colafter,'');
		$upd1=new vrupdcol($tabla1,'xdate','datetime',$upd1->colafter,'');
		$upd1=new vrupdcol($tabla1,'idfrom','int(9)',$upd1->colafter,'');
		$upd1=new vrupdcol($tabla1,'mdfrom','varchar(4)',$upd1->colafter,'');
		

		$upd1=new vrupdcol($tabla1,'srie','varchar(6)',$upd1->colafter,'');
		$upd1=new vrupdcol($tabla1,'serie','varchar(6)',$upd1->colafter,'');

		$upd1=new vrupdcol($tabla1,'idsec','varchar(7)',$upd1->colafter,'');
		$upd1=new vrupdcol($tabla1,'idfox','varchar(7)',$upd1->colafter,'');

		if(mb_stristr('vtas.clie.clte.comp',$tabla))
		{
			$upd1=new vrupdcol($tabla1,'fpag','varchar(2)',$upd1->colafter,'');
		}
		
		if(mb_stristr('vtas.clie.clte.comp.caja.bcos.inve.cele',$tabla))
		{
			$upd1=new vrupdcol($tabla1,'todocu','varchar(4)',$upd1->colafter,'');
			$upd1=new vrupdcol($tabla1,'toptoe','varchar(6)',$upd1->colafter,'');
			$upd1=new vrupdcol($tabla1,'tonume','varchar(9)',$upd1->colafter,'');
		}		
		if(mb_stristr('bcos',$tabla))
		{
			$upd1=new vrupdcol($tabla1,'benefic','varchar(30)',$upd1->colafter,'');
		}		

		if(mb_stristr('vtas.clie.clte.call',$tabla))
		{
			$upd1=new vrupdcol($tabla1,'toenti','varchar(13)',$upd1->colafter,'');
			$upd1=new vrupdcol($tabla1,'vndd','varchar(10)',$upd1->colafter,'');
			$upd1=new vrupdcol($tabla1,'rcdd','varchar(10)',$upd1->colafter,'');
			$upd1=new vrupdcol($tabla1,'adrs','int(9)',$upd1->colafter,'');
// 			$upd1=new vrupdcol($tabla1,'fpag','varchar(2)',$upd1->colafter,'');
// 			$upd1=new vrupdcol($tabla1,'fpag','X','','');
		}		
		
		if(mb_stristr('inve.prod',$tabla))
		{
			$upd1=new vrupdcol($tabla1,'tobode','varchar(4)',$upd1->colafter,'');
		}		
		
		if(mb_stristr('caja.bcos.cjte',$tabla))
		{
			$upd1=new vrupdcol($tabla1,'tocaja','varchar(4)',$upd1->colafter,'');
			$upd1=new vrupdcol($tabla1,'toctab','varchar(4)',$upd1->colafter,'');
		}		
		
		if(mb_stristr('bcos',$tabla))
		{
			$upd1=new vrupdcol($tabla1,'fentrega','date',$upd1->colafter,'');
			$upd1=new vrupdcol($tabla1,'fcobro','date',$upd1->colafter,'');
		}		
		
		if(mb_stristr('vtas.comp.guia.retp.retc.cele',$tabla))
		{
			$upd1=new vrupdcol($tabla1,'atrz','varchar(10)',$upd1->colafter,'');
			$upd1=new vrupdcol($tabla1,'claveacc','varchar(49)',$upd1->colafter,'');
// 			$upd1=new vrupdcol($tabla1,'atrznume','varchar(37)',$upd1->colafter,'');
			$upd1=new vrupdcol($tabla1,'atrznume','varchar(49)',$upd1->colafter,'');
		}		
		if(mb_stristr('vtas.comp.guia.retp.retc.cele',$tabla))
		{	
			$upd1=new vrupdcol($tabla1,'firmante','varchar(13)',$upd1->colafter,'');
		}

		if(mb_stristr('cont.comp.prov.cele',$tabla))
		{
			$upd1=new vrupdcol($tabla1,'suco','varchar(2)',$upd1->colafter,'');
			$upd1=new vrupdcol($tabla1,'at03','varchar(2)',$upd1->colafter,'');
		}		
		
		
		if(mb_stristr('retc.retp',$tabla))
		{
			$upd1=new vrupdcol($tabla1,'codret','varchar(4)',$upd1->colafter,'');
			$upd1=new vrupdcol($tabla1,'cret','varchar(4)',$upd1->colafter,'');
		}		

		if(mb_stristr('comp.bcos.caja.cele',$tabla))
		{
			$upd1=new vrupdcol($tabla1,'fpag','varchar(2)',$upd1->colafter,'');
		}		

		if(mb_stristr('nomi',$tabla))
		{
			$upd1=new vrupdcol($tabla1,'fechasale','date',$upd1->colafter,'');
		}		

		
		if(mb_stristr('apri.emar.emun',$_SESSION['user_vcrx_empr']))
			{
			$upd1=new vrupdcol($tabla1,'bldn','varchar(40)',$upd1->colafter,'');
			}
		
		if(mb_stristr('gnya',$_SESSION['user_vcrx_empr']))
			{
			$upd1=new vrupdcol($tabla1,'drtr','varchar(13)',$upd1->colafter,'');
			}
		
		if(mb_stristr('rcsa',$_SESSION['user_vcrx_empr']))
			{
			$upd1=new vrupdcol($tabla1,'vhcl','varchar(7)',$upd1->colafter,'');
			$upd1=new vrupdcol($tabla1,'sntr','varchar(7)',$upd1->colafter,'');
			}
		
		$upd1=new vrupdcol($tabla1,'PRUT1','X','','');
		$upd1=new vrupdcol($tabla1,'cair','X','','');

		/////////////////////////////////////////////////////////
		/////////////////////////////////////////////////////////
		// TABLA 2
		/////////////////////////////////////////////////////////
		/////////////////////////////////////////////////////////
		$upd2=new vrupdcol($tabla2,'iddet','smallint(4)','idnum2','');

// 		if(mb_stristr('cont',$tabla))
// 		{
// 		$upd2=new vrupdcol($tabla2,'item','varchar(13)',$upd2->colafter,'');
// 		$upd2=new vrupdcol($tabla2,'enti2','varchar(13)',$upd2->colafter,'');
// 		}
		
		if(mb_stristr('cont.vtas.clie.clte.comp.prov.inve.prod.carr',$tabla))
		{
		$upd2=new vrupdcol($tabla2,'item','varchar(13)',$upd2->colafter,'');
		$upd2=new vrupdcol($tabla2,'numserie','varchar(15)',$upd2->colafter,'');
		$upd2=new vrupdcol($tabla2,'lote','varchar(4)',$upd2->colafter,'');
		}

		if(mb_stristr('comp.cele',$tabla))
		{
		$upd2=new vrupdcol($tabla2,'itemce','varchar(13)',$upd2->colafter,'');
		}

		if(mb_stristr('cont.inve.prod',$tabla))
		{
		$upd2=new vrupdcol($tabla2,'item','varchar(13)',$upd2->colafter,'');
		$upd2=new vrupdcol($tabla2,'numserie','smallint(4)',$upd2->colafter,'');
		}

		if(mb_stristr('cont',$tabla))
		{
			$upd2=new vrupdcol($tabla2,'lsub','varchar(9)',$upd2->colafter,'');
		}

		if(mb_stristr('cont.caja.bcos.cjte.retc.retp',$tabla))
		{
		$upd2=new vrupdcol($tabla2,'docum','varchar(4)',$upd2->colafter,'');
		$upd2=new vrupdcol($tabla2,'ptoem','varchar(6)',$upd2->colafter,'001001');
		$upd2=new vrupdcol($tabla2,'numer','varchar(9)',$upd2->colafter,'');
		}

		if(mb_stristr('caja.bcos',$tabla))
		{
		$upd2=new vrupdcol($tabla2,'caja2','varchar(4)',$upd2->colafter,'');
// 		$upd2=new vrupdcol($tabla2,'ctab2','varchar(4)',$upd2->colafter,'');
		$upd2=new vrupdcol($tabla2,'ctab2','X',$upd2->colafter,'');
		$upd2=new vrupdcol($tabla2,'bcos2','X',$upd2->colafter,'');
		}
		
		if(mb_stristr('cont.nomi.rolp',$tabla))
		{
		$upd2=new vrupdcol($tabla2,'enti2','varchar(10)',$upd2->colafter,'');
		$upd2=new vrupdcol($tabla2,'nvdd','varchar(5)',$upd2->colafter,'');
		$upd2=new vrupdcol($tabla2,'csub','varchar(9)',$upd2->colafter,'');
		}
		

		

		if(mb_stristr('nomi',$tabla))
		{
// 		$upd2=new vrupdcol($tabla2,'cargo','varchar(20)',$upd2->colafter,'');
		$upd2=new vrupdcol($tabla2,'fecha2','date',$upd2->colafter,'');
// 		$upd2=new vrupdcol($tabla2,'salario','decimal(9,2)',$upd2->colafter,'');
		$upd2=new vrupdcol($tabla2,'sueldo','decimal(9,2)',$upd2->colafter,'');
		$upd2=new vrupdcol($tabla2,'valanti','decimal(9,2)',$upd2->colafter,'');
		$upd2=new vrupdcol($tabla2,'poranti','decimal(5,2)',$upd2->colafter,'');
		$upd2=new vrupdcol($tabla2,'iess','varchar(1)',$upd2->colafter,'');
		$upd2=new vrupdcol($tabla2,'reloj','varchar(1)',$upd2->colafter,'');
		$upd2=new vrupdcol($tabla2,'atraso','varchar(1)',$upd2->colafter,'');
		$upd2=new vrupdcol($tabla2,'falta','varchar(1)',$upd2->colafter,'');
		$upd2=new vrupdcol($tabla2,'h025','varchar(1)',$upd2->colafter,'');
		$upd2=new vrupdcol($tabla2,'h050','varchar(1)',$upd2->colafter,'');
		$upd2=new vrupdcol($tabla2,'h100','varchar(1)',$upd2->colafter,'');
		$upd2=new vrupdcol($tabla2,'de13','varchar(1)',$upd2->colafter,'');
		$upd2=new vrupdcol($tabla2,'de14','varchar(1)',$upd2->colafter,'');
		$upd2=new vrupdcol($tabla2,'fres','varchar(1)',$upd2->colafter,'');
		$upd2=new vrupdcol($tabla2,'fonres','X',$upd2->colafter,'');
		}
		

		if(mb_stristr('cont',$tabla))
			{$upd2=new vrupdcol($tabla2,'cant','decimal(13,4)',$upd2->colafter,'');}
		else
			{$upd2=new vrupdcol($tabla2,'cant','decimal(13,2)',$upd2->colafter,'');}
			
		$upd2=new vrupdcol($tabla2,'puni','decimal(13,4)',$upd2->colafter,'');

		if(mb_stristr('vtas.clie.clte.comp.prov.carr',$tabla))
		{
			$upd2=new vrupdcol($tabla2,'dcto','decimal(4,2)',$upd2->colafter,'');
			$upd2=new vrupdcol($tabla2,'ice','decimal(4,2)',$upd2->colafter,'');
			$upd2=new vrupdcol($tabla2,'iva','decimal(4,2)',$upd2->colafter,'');
			$upd2=new vrupdcol($tabla2,'irbp','decimal(4,2)',$upd2->colafter,'');
			$upd2=new vrupdcol($tabla2,'pvp1','decimal(13,4)',$upd2->colafter,'');

			$upd2=new vrupdcol($tabla2,'cair','varchar(5)',$upd2->colafter,'');
			$upd2=new vrupdcol($tabla2,'rrta','decimal(5,2)',$upd2->colafter,'');
			$upd2=new vrupdcol($tabla2,'riva','decimal(5,2)',$upd2->colafter,'');

			// ELIMINARLOS
			$upd2=new vrupdcol($tabla2,'docum','varchar(4)',$upd2->colafter,'');
			$upd2=new vrupdcol($tabla2,'ptoem','varchar(6)',$upd2->colafter,'001001');
			$upd2=new vrupdcol($tabla2,'numer','varchar(9)',$upd2->colafter,'');
		}

		$upd2=new vrupdcol($tabla2,'ctas','varchar(13)',$upd2->colafter,'');
		$upd2=new vrupdcol($tabla2,'detalle','varchar(150)',$upd2->colafter,'');
			
		if(mb_stristr('inve.prod',$tabla))
		{
			$upd2=new vrupdcol($tabla2,'cambio','varchar(13)',$upd2->colafter,'');
		}		
		
		if(mb_stristr('clie.clte.carr',$tabla))
		{
			$upd2=new vrupdcol($tabla2,'cantio','decimal(13,2)',$upd2->colafter,'');
		}		

		if(mb_stristr('clie.clte.vtas',$tabla))
		{
			$upd2=new vrupdcol($tabla2,'comi','decimal(5,2)',$upd2->colafter,'');
		}		
		
		if(mb_stristr('comp.prov.cele',$tabla))
		{
			$upd2=new vrupdcol($tabla2,'cair','varchar(5)',$upd2->colafter,'');
			$upd2=new vrupdcol($tabla2,'at10','varchar(4)',$upd2->colafter,'');
			$upd2=new vrupdcol($tabla2,'cret','varchar(4)',$upd2->colafter,'');
			$upd2=new vrupdcol($tabla2,'codret','varchar(4)',$upd2->colafter,'');
		}		
		
		if(mb_stristr('cont.caja.bcos',$tabla))
		{
			$upd2=new vrupdcol($tabla2,'cair','varchar(5)',$upd2->colafter,'');
		}


		if(mb_stristr('retc.retp',$tabla))
		{
			$upd2=new vrupdcol($tabla2,'cair','varchar(5)',$upd2->colafter,'');
			$upd2=new vrupdcol($tabla2,'base','decimal(10,2)',$upd2->colafter,'');
			$upd2=new vrupdcol($tabla2,'porc','decimal(5,2)',$upd2->colafter,'');
		}		
		
		if(mb_stristr('vtas.clie',$tabla))
		{
		if(mb_stristr('rcsa',$_SESSION['user_vcrx_empr']))
			{
			$upd2=new vrupdcol($tabla2,'puni_o','varchar(13,4)',$upd2->colafter,'');
			$upd2=new vrupdcol($tabla2,'puni_a','varchar(13,4)',$upd2->colafter,'');
			$upd2=new vrupdcol($tabla2,'impo','char(1)',$upd2->colafter,'');
			}
		}

// 		if(mb_stristr('vtas.clie.comp.prov',$tabla))
		{
		if(mb_stristr('pcs1.prs1.idm1.idmt',$_SESSION['user_vcrx_empr']))
			{
			$upd2=new vrupdcol($tabla2,'cntn','varchar(11)',$upd2->colafter,'');
			$upd2=new vrupdcol($tabla2,'cntnf1','date',$upd2->colafter,'');
			$upd2=new vrupdcol($tabla2,'cntnf2','date',$upd2->colafter,'');
			$upd2=new vrupdcol($tabla2,'serie1','varchar(20)',$upd2->colafter,'');
			$upd2=new vrupdcol($tabla2,'serie2','varchar(20)',$upd2->colafter,'');
			$upd2=new vrupdcol($tabla2,'serie3','varchar(20)',$upd2->colafter,'');
			$upd2=new vrupdcol($tabla2,'eirout','int',$upd2->colafter,'');
			$upd2=new vrupdcol($tabla2,'eirin','int',$upd2->colafter,'');
			}
		}

	$upd2=new vrupdcol($tabla2,'PRUT2','X',$upd2->colafter,'');

			// INDICES
		mysql_query('alter table '.$tabla1.' drop primary key',$link_vcrx);
		mysql_query('alter table '.$tabla1.' add primary key(idnum1)',$link_vcrx);

		mysql_query('alter table '.$tabla2.' drop primary key',$link_vcrx);
		mysql_query('alter table '.$tabla2.' add primary key(idnum2,iddet)',$link_vcrx);

		mysql_query('drop   index docu on '.$tabla1,$link_vcrx);
		mysql_query('create index docu on '.$tabla1.'(docu)',$link_vcrx);
		
		mysql_query('drop   index docum on '.$tabla2,$link_vcrx);
		mysql_query('create index docu on '.$tabla2.'(docu)',$link_vcrx);
		
		mysql_query('alter table '.$tabla1.' alter column plazo drop default',$link_vcrx);
// 		mysql_query('alter table '.$tabla1.' alter column plazo set default 0',$link_vcrx);

			
	}
}	

class vrupdtg
{
	function vrupdtg()
	{
		require('../cfg/cfg.php');
		require('../cfg/res.php');
// 		require('../../_lib/vr_updcol.php');
	
		$tablag='usrdoc';		
		$tablag='usrdoc1';		
		mysql_query('create table '.$tablag.' (user varchar(10) not null) engine=innodb',$link_vcrx);
		mysql_query('alter table '.$tablag.' engine=innodb, default character set=latin1 collate=latin1_spanish_ci',$link_vcrx);


		$updg=new vrupdcol($tablag,'user','varchar(10)',$updg->colafter,'');
		$updg=new vrupdcol($tablag,'cedula','varchar(10)',$updg->colafter,'');
		$updg=new vrupdcol($tablag,'docu', 'char(4)',$updg->colafter,'');

		$updg=new vrupdcol($tablag,'nuev','char(1)',$updg->colafter,'');
		$updg=new vrupdcol($tablag,'modi','char(1)',$updg->colafter,'');
		$updg=new vrupdcol($tablag,'apro','char(1)',$updg->colafter,'');

		$updg=new vrupdcol($tablag,'proc','char(1)',$updg->colafter,'');
		$updg=new vrupdcol($tablag,'anul','char(1)',$updg->colafter,'');
		$updg=new vrupdcol($tablag,'elim','char(1)',$updg->colafter,'');

		$updg=new vrupdcol($tablag,'cons','char(1)',$updg->colafter,'');
		$updg=new vrupdcol($tablag,'info','char(1)',$updg->colafter,'');
		$updg=new vrupdcol($tablag,'espe','char(1)',$updg->colafter,'');

		mysql_query('alter table ' .$tablag.' drop primary key');
		mysql_query('alter table ' .$tablag.' add primary key(user,docu)');

	
	
	}	
				
}

class vrupdv0
{
	function vrupdv0()
	{
		require('../cfg/cfg.php');
		require('../cfg/res.php');

		$fini1= date('2000-01-01');
		$sql_fini1='select * from empr0';
		$res_fini1=mysql_query($sql_fini1,$link_vcrx);
		$feccont=mysql_result($res_fini1,0,'empr_fcont');
		$fecinve=mysql_result($res_fini1,0,'empr_finve');
		$feccxco=mysql_result($res_fini1,0,'empr_fcxco');
		$feccxpa=mysql_result($res_fini1,0,'empr_fcxpa');

		$sql_upd2='drop view empr1';
		$res_upd2=mysql_query($sql_upd2,$link_vcrx);
		
		$view0='empr1';	mysql_query('drop view '.$view0,$link_vcrx); echo '==>'.mysql_error();
		$xstr= 'create view '.$view0.' as ';
		$xstr.= 'select * from empr0 left join enti0 on empr_ruc=enti_codigo limit 1';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error(); }

		$view0='codenti';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
		$xstr.='select ';
			$xstr.='concat("20",mid(enti_codigo,3,2)) as anio, ';
			$xstr.='mid(enti_codigo,5,2) as mes, ';
			$xstr.='(mid(enti_codigo,7,3)) as numero ';
		$xstr.='from enti0 ';
		$xstr.='where enti_codigo like "99%" ';
		$xstr.='group by mid(enti_codigo,3,2) ';
		$xstr.='order by anio desc, mes desc, numero desc ';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}


		$view0='coditem';mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
		$xstr.='select ';
			 $xstr.='max(left(item_codigo,5)) as numero ';
		 $xstr.='from item0 ';
		 $xstr.='where length(item_codigo)=6';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}
		 
		$view0='user00';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
		 $xstr.='select *';
		 $xstr.=' from user0,enti0';
		 $xstr.=' where ';
		 $xstr.=' user_cedula=enti_codigo ';
		 $xstr.=' order by enti_descri';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}

		$view0='cdad00';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
		 $xstr.='select cdad0.*, prvc_descri ';
		 $xstr.=' from cdad0 left join prvc0 ';
		 $xstr.=' on left(cdad_codigo,2)=prvc_codigo';
		 $xstr.=' order by prvc_descri,cdad_descri';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}


		$view0='ctas00';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
		$xstr.='select ctas0.*,';
		$xstr.='case ';
			 $xstr.='when ctas_status="X" or ctas_status="I" then 0 ';
			 $xstr.='when length(ctas_codigo)=1 or length(ctas_codigo)=2 then 1 ';
			 $xstr.='when length(ctas_codigo)=3 or length(ctas_codigo)=4 then 2 ';
			 $xstr.='when length(ctas_codigo)=5 or length(ctas_codigo)=6 then 3 ';
			 $xstr.='when length(ctas_codigo)=7 or length(ctas_codigo)=8 then 4 ';
			 $xstr.='when length(ctas_codigo)=9 or length(ctas_codigo)=10 then 5 ';
			 $xstr.='when length(ctas_codigo)>=11 then 5 ';
			 $xstr.='else 0 ';
			 $xstr.='end as ctas_nivel';
		 $xstr.=' from ctas0';
		 $xstr.=' order by ctas_codigo';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}

		$view0='ctan1';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
		 $xstr.='select * ';
		 $xstr.=' from ctas00 where ctas_nivel=1 ';
		 $xstr.=' order by ctas_codigo';
// 		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}

		$view0='ctan2';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
		 $xstr.='select * ';
		 $xstr.=' from ctas00 where ctas_nivel=2 ';
		 $xstr.=' order by ctas_codigo';
// 		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}

		$view0='ctan3';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
		 $xstr.='select * ';
		 $xstr.=' from ctas00 where ctas_nivel=3 ';
		 $xstr.=' order by ctas_codigo';
// 		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}

		$view0='ctan4';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
		 $xstr.='select * ';
		 $xstr.=' from ctas00 where ctas_nivel=4 ';
		 $xstr.=' order by ctas_codigo';
// 		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}

		$view0='ctan5';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
				 $xstr.='select * ';
				 $xstr.=' from ctas00 where ctas_nivel=5 ';
				 $xstr.=' order by ctas_codigo';
// 		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}

//		 $xstr.='when left(enti_codigo,2)!="99" and length(enti_codigo)=10 then "C" ';
// 		$view0='enti00';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
// 				 $xstr.='select enti0.*,';
// 				 $xstr.='case ';
// 					 $xstr.='when left(enti_codigo,2)>="01" and left(enti_codigo,2)<="24" and length(enti_codigo)=10 then "C" ';
// 					 $xstr.='when left(enti_codigo,2)>="01" and left(enti_codigo,2)<="24" and length(enti_codigo)=13 then "R" ';
// 					 $xstr.='when left(enti_codigo,2)="99" and length(enti_pasaporte)>0 then "P" ';
// 					 $xstr.='when left(enti_codigo,2)="99" and length(enti_pasaporte)=0 then "F" ';
// 					 $xstr.='else "-" end as enti_tipoid,';
// 				 $xstr.='case ';
// 					 $xstr.='when left(enti_codigo,2)>="01" and left(enti_codigo,2)<="24" and substr(enti_codigo,3,1)<="5" then "N" ';
// 					 $xstr.='when left(enti_codigo,2)>="01" and left(enti_codigo,2)<="24" and substr(enti_codigo,3,1)="6" then "P" ';
// 					 $xstr.='when left(enti_codigo,2)>="01" and left(enti_codigo,2)<="24" and substr(enti_codigo,3,1)="9" then "J" ';
// 					 $xstr.='else "-" end as enti_tiporuc,';
// 				 $xstr.='zsub_descri, tpro_descri,cdad_descri, prvc_descri ';
// 				 $xstr.=' from enti0 ';
// 				 $xstr.=' left join zsub0 on enti_zsub=zsub_codigo ';
// 				 $xstr.=' left join tpro0 on enti_tpro=tpro_codigo ';
// 				 $xstr.=' left join cdad00 on enti_cdad=cdad_codigo ';
// 				 $xstr.=' order by zsub_descri,enti_descri';
// 		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}

		//
		$view0='adrs00';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
				 $xstr.='select adrs0.*,';
				 $xstr.='enti_descri, ';
				 $xstr.='enti_razsoc, ';
				 $xstr.='enti_nomcom, ';
				 $xstr.='enti_nom1, ';
				 $xstr.='enti_nom2, ';
				 $xstr.='enti_ape1, ';
				 $xstr.='enti_ape2, ';
				 $xstr.='prvc_descri,';
				 $xstr.='cdad_descri ';
				 $xstr.=' from adrs0 ';
				 $xstr.=' left join enti0 on adrs_enti=enti_codigo ';
				 $xstr.=' left join cdad00 on adrs_cdad=cdad_codigo ';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}
		//susp

		$view0='suel00';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
				 $xstr.='select suel0.*,';
				 $xstr.='enti_descri, ';
				 $xstr.='enti_nom1, ';
				 $xstr.='enti_nom2, ';
				 $xstr.='enti_ape1, ';
				 $xstr.='enti_ape2 ';
// 				 $xstr.='prvc_descri,';
// 				 $xstr.='cdad_descri ';
				 $xstr.=' from suel0 ';
				 $xstr.=' left join enti0 on suel_enti=enti_codigo ';
				 $xstr.=' left join csub0 on suel_csub=csub_codigo ';
// 				 $xstr.=' left join cdad00 on suel_cdad=cdad_codigo ';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}
		//susp

		$view0='atrd00';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
				 $xstr.='select atrd0.*, ';
				 $xstr.=' docu_descri ';
				 $xstr.=' from atrd0 ';
				 $xstr.=' left join docu0 on atrd_docu=docu_codigo ';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}

		$view0='atrz00';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
				 $xstr.='select atrz0.*, ';
				 $xstr.=' atrd00.*, ';
				 $xstr.=' enti_descri ';
				 $xstr.=' from atrz0 ';
				 $xstr.=' left join enti0 on atrz_enti=enti_codigo ';
				 $xstr.=' left join atrd00 on atrz_codigo=atrd_atrz ';
				 $xstr.=' order by atrz_codigo desc ';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}

		//
		$view0='enti00';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
				 $xstr.='select enti0.*,';
				 $xstr.='case ';
					 $xstr.='when left(enti_codigo,2)>="01" and left(enti_codigo,2)<="24" and length(trim(enti_codigo))=10 then "C" ';
					 $xstr.='when left(enti_codigo,2)>="01" and left(enti_codigo,2)<="24" and length(trim(enti_codigo))=13 then "R" ';
					 $xstr.='when length(trim(enti_codigo))!=10 and length(trim(enti_codigo))!=13 and length(trim(enti_pasaporte))!=0 then "P" ';
					 $xstr.='when left(enti_codigo,2)="99" and length(trim(enti_pasaporte))>0 then "P" ';
					 $xstr.='when left(enti_codigo,2)="99" and length(trim(enti_pasaporte))=0 then "F" ';
					 $xstr.='when left(enti_codigo,1)="1"  and length(trim(enti_codigo))=6 then "P" ';
					 $xstr.='else "-" end as enti_tipoid,';
				 $xstr.='case ';
					 $xstr.='when left(enti_codigo,2)>="01" and left(enti_codigo,2)<="24" and substr(enti_codigo,3,1)<="5" then "N" ';
					 $xstr.='when left(enti_codigo,2)>="01" and left(enti_codigo,2)<="24" and substr(enti_codigo,3,1)="6" then "P" ';
					 $xstr.='when left(enti_codigo,2)>="01" and left(enti_codigo,2)<="24" and substr(enti_codigo,3,1)="9" then "J" ';
					 $xstr.='else "-" end as enti_tiporuc,';
				 $xstr.='zsub_descri,csub_descri,tpro_descri,pais_descri,cdad_descri,prvc_descri,zsub_ctaxcob,tpro_ctaxpag,pais_ats ';
				 $xstr.=' from enti0 ';
				 $xstr.=' left join zsub0 on enti_zsub=zsub_codigo ';
				 $xstr.=' left join csub0 on enti_csub=csub_codigo ';
				 $xstr.=' left join tpro0 on enti_tpro=tpro_codigo ';
				 $xstr.=' left join pais0 on enti_pais=pais_codigo ';
				 $xstr.=' left join cdad00 on enti_cdad=cdad_codigo ';
				 $xstr.=' order by zsub_descri,enti_descri';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}



		$dreser=4;
		$view0='item0s';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
				 $xstr.='select item,docu,fecha,status,';
				 $xstr.='case when docu like "IB%" then cant else cant//-1 end as saldo,';
				 $xstr.='0.0000 as reser,';
				 $xstr.='case when docu like "IB%" then cant else cant//-1 end as dispo ';
				 $xstr.='from inve1,inve2 ';
				 $xstr.='where ';
				 $xstr.='idnum1=idnum2 ';
				 $xstr.='and fecha>="' .$fecinve.'" ';
				 $xstr.='and status!="O" ';
				 $xstr.='and status!="X" ';
				 $xstr.='union ';
				 $xstr.='select item,docu,fecha,status,';
				 $xstr.='0.0000 as saldo,';
				 $xstr.='cant as reser,';
				 $xstr.='cant//-1 as dispo ';
				 $xstr.='from clie1,clie2 ';
				 $xstr.='where ';
				 $xstr.='idnum1=idnum2 ';
				 $xstr.='and fecha>=date(now())-'.$dreser.' ';
				 $xstr.='and status="-" ';
		
		// dias reserva
		
		////xsqlstr		
// 		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}


		$xstrean = '';
			 $xstrean.='concat(';
			 $xstrean.='char(substr(item_ean,1,1)+35),';
			 $xstrean.='"!",';
			 $xstrean.='char(substr(item_ean,2,1)+48),';
			 $xstrean.='case ';
				 $xstrean.='when locate(left(item_ean,1),"0123")!=0 ';
				 $xstrean.='then char(substr(item_ean,3,1)+48) ';
				 $xstrean.='else char(substr(item_ean,3,1)+65) ';
				 $xstrean.='end, ';
			 $xstrean.='case ';
				 $xstrean.='when locate(left(item_ean,1),"0478")!=0 ';
				 $xstrean.='then char(substr(item_ean,4,1)+48) ';
				 $xstrean.='else char(substr(item_ean,4,1)+65) ';
				 $xstrean.='end, ';
			 $xstrean.='case ';
				 $xstrean.='when locate(left(item_ean,1),"0145")!=0 ';
				 $xstrean.='then char(substr(item_ean,5,1)+48) ';
				 $xstrean.='else char(substr(item_ean,5,1)+65) ';
				 $xstrean.='end, ';
			 $xstrean.='case ';
				 $xstrean.='when locate(left(item_ean,1),"02567")!=0 ';
				 $xstrean.='then char(substr(item_ean,6,1)+48) ';
				 $xstrean.='else char(substr(item_ean,6,1)+65) ';
				 $xstrean.='end, ';
			 $xstrean.='case ';
				 $xstrean.='when locate(left(item_ean,1),"03689")!=0 ';
				 $xstrean.='then char(substr(item_ean,7,1)+48) ';
				 $xstrean.='else char(substr(item_ean,7,1)+65) ';
				 $xstrean.='end, ';
			 $xstrean.='"-",';
			 $xstrean.='char(substr(item_ean,8,1)+97,substr(item_ean,9,1)+97,substr(item_ean,10,1)+97,substr(item_ean,11,1)+97,substr(item_ean,12,1)+97,substr(item_ean,13,1)+97),"!")';
			 $xstrean.=' as bc_ean13, ';

		$xstrean00 = '';
			 $xstr.='concat(';
			 $xstr.='char(substr(item_ean,1,1)+35),';
			 $xstr.='"!",';
			 $xstr.='char(substr(item_ean,2,1)+48),';
			 $xstr.='case ';
				 $xstr.='when locate(left(item_ean,1),"0123")!=0 ';
				 $xstr.='then char(substr(item_ean,3,1)+48) ';
				 $xstr.='else char(substr(item_ean,3,1)+65) ';
				 $xstr.='end, ';
			 $xstr.='case ';
				 $xstr.='when locate(left(item_ean,1),"0478")!=0 ';
				 $xstr.='then char(substr(item_ean,4,1)+48) ';
				 $xstr.='else char(substr(item_ean,4,1)+65) ';
				 $xstr.='end, ';
			 $xstr.='case ';
				 $xstr.='when locate(left(item_ean,1),"0145")!=0 ';
				 $xstr.='then char(substr(item_ean,5,1)+48) ';
				 $xstr.='else char(substr(item_ean,5,1)+65) ';
				 $xstr.='end, ';
			 $xstr.='case ';
				 $xstr.='when locate(left(item_ean,1),"02567")!=0 ';
				 $xstr.='then char(substr(item_ean,6,1)+48) ';
				 $xstr.='else char(substr(item_ean,6,1)+65) ';
				 $xstr.='end, ';
			 $xstr.='case ';
				 $xstr.='when locate(left(item_ean,1),"03689")!=0 ';
				 $xstr.='then char(substr(item_ean,7,1)+48) ';
				 $xstr.='else char(substr(item_ean,7,1)+65) ';
				 $xstr.='end, ';
			 $xstr.='"-",';
			 $xstr.='char(substr(item_ean,8,1)+97,substr(item_ean,9,1)+97,substr(item_ean,10,1)+97,substr(item_ean,11,1)+97,substr(item_ean,12,1)+97,substr(item_ean,13,1)+97),"!")';
			 $xstr.=' as bc_ean1300, ';

		//xstrean=''

		//		 $xstr.='0 as saldo,0 as reser, 0 as dispo ';


		//round(sum(cant//puni*(1-dcto/100)*(1+ice/100)*(1+iva/100)+(cant//irbp))//-1,//xrnd) end as total,


		////
		//$view0='item00'
		////	sqle(xcnx,'drop view item00')
		//	$xstr='create view item00 as ';
				 $xstr.='select item0.*,';
				 $xstr.='item_puni*(1-item_dcto/100)*(1+item_ice/100)*(1+item_iva/100)+item_irbp as item_pvp0,';
				 $xstr.=$xstrean;
				 $xstr.='lsub_descri,';
				 $xstr.='cair_descri ';
				 $xstr.=' from item0,lsub0,cair0';
				 $xstr.=' where item_lsub=lsub_codigo';
				 $xstr.=' and item_cair=cair_codigo';
				 $xstr.=' order by lsub_descri,item_descri';
// 		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}

		//
		$view0='item00';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
				 $xstr.='select item0.*,';
				 $xstr.='item_puni*(1-item_dcto/100)*(1+item_ice/100)*(1+item_iva/100)+item_irbp as item_pvp0,';
				 $xstr.=$xstrean;
				 $xstr.='lsub_descri,';
				 $xstr.='lsub_ctavtas,';
				 $xstr.='lsub_ctainve,';
				 $xstr.='cair_descri ';
				 $xstr.=' from item0';
				 $xstr.=' left join lsub0 on item_lsub=lsub_codigo';
				 $xstr.=' left join cair0 on item_cair=cair_codigo';
				 $xstr.=' order by lsub_descri,item_descri';
// 		echo '-------'.$xstr;
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}

		//
		$view0='ipro0';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
				 $xstr.='select * ';
				 $xstr.=' from item0 ';
				 $xstr.=' where item_codigo in ';
				 $xstr.=' (select item from inve1,inve2 where idnum1=idnum2 and inve1.status!="X" and inve1.status!="O")';
				 $xstr.=' order by item_codigo,item_descri';
		////xsqlstr		
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}


		//
		$view0='iser0';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
				 $xstr.='select * ';
				 $xstr.=' from item0 ';
				 $xstr.=' where item_codigo not in ';
				 $xstr.=' (select item from inve1,inve2 where idnum1=idnum2 and status!="X" and status!="O")';
				 $xstr.=' order by item_codigo,item_descri';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}

		$view0='enti0b';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
				 $xstr.='select enti0.*,';
				 $xstr.='concat(';
				 $xstr.='enti_codigo,"/",';
				 $xstr.='if(enti_descri is null,"",enti_descri),"/",';
				 $xstr.='if(enti_razsoc is null,"",enti_razsoc),"/",';
				 $xstr.='if(enti_nomcom is null,"",enti_nomcom),"/",';
				 $xstr.='if(enti_nom1 is null,"",enti_nom1),"/",';
				 $xstr.='if(enti_nom2 is null,"",enti_nom2),"/",';
				 $xstr.='if(enti_ape1 is null,"",enti_ape1),"/",';
				 $xstr.='if(enti_ape2 is null,"",enti_ape2),"/",';
				 $xstr.='if(enti_codigoc is null,"",enti_codigoc),"/",';
				 $xstr.='if(enti_codigop is null,"",enti_codigop),"/",';
				 $xstr.='if(enti_codigoe is null,"",enti_codigoe),"/",';
				 $xstr.='if(enti_telefono is null,"",enti_telefono),"/",';
				 $xstr.='if(enti_email is null,"",enti_email),"/",';
				 $xstr.='if(enti_nickname is null,"",enti_nickname),"/",';
				 $xstr.='""';
				 $xstr.=') as enti_buscar ';
				 $xstr.=' from enti0';
				 $xstr.=' order by enti_codigo';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}


		//
		$view0='item0b';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
				 $xstr.='select item0.*,';
				 $xstr.='concat(';
				 $xstr.='item_codigo,"/",';
				 $xstr.='if(item_descri is null,"",item_descri),"/",';
				 $xstr.='if(item_ean is null,"",item_ean),"/",';
				 $xstr.='if(item_modelo is null,"",item_modelo),"/",';
				 $xstr.='if(item_numpart is null,"",item_numpart),"/",';
				 $xstr.='if(item_codigov is null,"",item_codigov),"/",';
				 $xstr.='if(item_cair is null,"",item_cair),"/",';
				 $xstr.='"") as item_buscar ';
				 $xstr.=' from item0';
				 $xstr.=' order by item_codigo';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}

		//
		$view0='ctas0b';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
				 $xstr.='select ctas0.*,';
				 $xstr.='concat(';
				 $xstr.='ctas_codigo,"/",';
				 $xstr.='if(ctas_descri is null,"",ctas_descri),"/",';
				 $xstr.='if(ctas_codigoc is null,"",ctas_codigoc),"/",';
				 $xstr.='"") as ctas_buscar ';
				 $xstr.=' from ctas0';
				 $xstr.=' order by ctas_codigo';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}

		$view0='nvdd0b';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
				 $xstr.='select nvdd0.*,';
				 $xstr.='concat(';
				 $xstr.='nvdd_codigo,"/",';
				 $xstr.='if(nvdd_descri is null,"",nvdd_descri),"/",';
				 $xstr.='if(nvdd_abrev is null,"",nvdd_abrev),"/",';
				 $xstr.='"") as nvdd_buscar ';
				 $xstr.=' from nvdd0';
				 $xstr.=' order by nvdd_codigo';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}


		//
		$view0='ctab00';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
				 $xstr.='select ctab0.*, bcos0.bcos_descri ';
				 $xstr.=' from ctab0 left join bcos0 ';
				 $xstr.=' on ctab_bcos=bcos_codigo ';
				 $xstr.=' order by ctab_descri';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}


		//
		$view0='ctab0b';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
				 $xstr.='select ctab00.*,';
				 $xstr.='concat(';
				 $xstr.='ctab_codigo,"/",';
				 $xstr.='if(ctab_descri is null,"",ctab_descri),"/",';
				 $xstr.='if(bcos_descri is null,"",bcos_descri),"/",';
				 $xstr.='"") as ctab_buscar ';
				 $xstr.=' from ctab00';
				 $xstr.=' order by ctab_descri';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}

		//
		$view0='ptov0b';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
				 $xstr.='select ptov0.*,';
				 $xstr.='concat(';
				 $xstr.='ptov_codigo,"/",';
				 $xstr.='if(ptov_descri is null,"",ptov_descri),"/",';
				 $xstr.='if(ptov_ptoe is null,"",ptov_ptoe),"/",';
				 $xstr.='"") as ptov_buscar ';
				 $xstr.=' from ptov0';
				 $xstr.=' order by ptov_descri';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}


		//
		$view0='docu0b';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
				 $xstr.='select docu0.*,';
				 $xstr.='concat(';
				 $xstr.='docu_codigo,"/",';
				 $xstr.='if(docu_descri is null,"",docu_descri),"/",';
				 $xstr.='"") as docu_buscar ';
				 $xstr.=' from docu0';
				 $xstr.=' order by docu_codigo';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}

		//
		$view0='zsub0b';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
				 $xstr.='select zsub0.*,';
				 $xstr.='concat(';
				 $xstr.='zsub_codigo,"/",';
				 $xstr.='if(zsub_descri is null,"",zsub_descri),"/",';
				 $xstr.='"") as zsub_buscar ';
				 $xstr.=' from zsub0';
				 $xstr.=' order by zsub_codigo';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}

		$view0='user0b';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
				 $xstr.='select user0.*,';
				 $xstr.='concat(';
				 $xstr.='user_codigo,"/",';
				 $xstr.='if(user_descri is null,"",user_descri),"/",';
				 $xstr.='if(user_cedula is null,"",user_cedula),"/",';
				 $xstr.='if(user_email is null,"",user_email),"/",';
				 $xstr.='if(user_nickname is null,"",user_nickname),"/",';
				 $xstr.='"") as user_buscar ';
				 $xstr.=' from user0';
				 $xstr.=' order by user_codigo';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}


		$view0='usrd0b';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
				 $xstr.='select user0.*,';
				 $xstr.='concat(';
				 $xstr.='user_codigo,"/",';
				 $xstr.='if(user_descri is null,"",user_descri),"/",';
				 $xstr.='if(user_cedula is null,"",user_cedula),"/",';
				 $xstr.='if(user_email is null,"",user_email),"/",';
				 $xstr.='if(user_nickname is null,"",user_nickname),"/",';
				 $xstr.='"") as user_buscar ';
				 $xstr.=' from user0';
				 $xstr.=' where user_tipo like "sist" or user_tipo like "admi" or user_tipo like "oper"';
				 $xstr.=' order by user_codigo';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}


		$view0='usrdoc0';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
				 $xstr.='select user_codigo, user_cedula,user_email,user_nickname,user_descri,user_tipo,docu_codigo, docu_tipo, docu_tabla ';
				 $xstr.=' from user0,docu0 ';
				 $xstr.=' where user_tipo="admi" or user_tipo="sist" or user_tipo="supe" or user_tipo="oper"';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}

		$view0='usrdoc11';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
				 $xstr.='select usrdoc1.*, user_codigo, user_cedula,user_email,user_nickname,user_descri,user_tipo,docu_descri, docu_tipo, docu_tabla, modu_descri from usrdoc1 ';
				 $xstr.=' join user0 on user=user_cedula ';
				 $xstr.=' join docu0 on docu=docu_codigo ';
				 $xstr.=' join modu0 on docu_tipo=modu_codigo ';
				 $xstr.=' where docu_tipo not like ""';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}

		//
		$view0='ktlg00';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
				 $xstr.='select distinct item_nctlg as ktlg';
				 $xstr.=' from item0';
				 $xstr.=' where item_nctlg is not null and item_nctlg>0 and item_pvp1>0';
				 $xstr.=' order by item_nctlg desc limit 2';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}

		//
		$view0='ktlg0';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
				 $xstr.='select ';
				 $xstr.=' substring(item_codigo,1,6) as fcodigo,';
				 $xstr.=' case when substring(item_codigo,7,2) like "9%" then concat("1",substring(item_codigo,7,2)) else concat("2",substring(item_codigo,7,2)) end as ftalla,';
				 $xstr.=' item0.* ';
				 $xstr.=' from item0, ktlg00';
				 $xstr.=' where item_nctlg is not null and item_nctlg>0 and item_pvp1>0 and item_nctlg=ktlg';
				 $xstr.=' order by fcodigo,ftalla';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}


		//
		$view0='clie0';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
				 $xstr.='select enti00.* ';
				 $xstr.='from enti00 ';
				 $xstr.='where ';
					 $xstr.='enti_clie=1 ';
					 $xstr.='or enti_codigo in (select distinct enti from vtas1 where status!="X" and status!="O" union select distinct enti from clie1 where status!="X" and status!="O")';
				 $xstr.='order by enti_ape1,enti_ape2,enti_nom1,enti_nom2,enti_razsoc ';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}


		//
		$view0='prov0';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
				 $xstr.='select enti00.* ';
				 $xstr.='from enti00 ';
				 $xstr.='where ';
					 $xstr.='enti_prov=1 ';
					 $xstr.='or enti_codigo in (select distinct enti from comp1 where status!="X" and status!="O" union select distinct enti from prov1 where status!="X" and status!="O")';
				 $xstr.='order by enti_ape1,enti_ape2,enti_nom1,enti_nom2,enti_razsoc ';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}


		//
		$view0='empl0';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
				 $xstr.='select enti00.* ';
				 $xstr.='from enti00 ';
				 $xstr.='where ';
					 $xstr.='enti_empl=1 ';
					 $xstr.='or enti_codigo in (select distinct enti from nomi1 where status!="X" and status!="O")';
				 $xstr.='order by enti_ape1,enti_ape2,enti_nom1,enti_nom2,enti_razsoc ';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}

		//
		$view0='item1';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
				 $xstr.='select distinct item ';
				 $xstr.='from inve1 left join inve2 on idnum1=idnum2 ';
				 $xstr.='where left(docu,2)="IB" and item is not null and status!="X" and status!="O"';
				 $xstr.='order by item ';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}

		//
		$view0='prod0';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
				 $xstr.='select * ';
				 $xstr.='from item00 ';
				 $xstr.='where ';
					 $xstr.=' item_codigo in (select item from inve2 union select item from prod2) ';		
				 $xstr.='order by item_lsub, item_descri, item_mrca, item_modelo ';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}

		//
		$view0='bien0';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
				 $xstr.='select * ';
				 $xstr.='from item00 ';
				 $xstr.='where item_bser="1"';
				 $xstr.='order by item_lsub, item_descri, item_mrca, item_modelo ';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}


		//
		$view0='serv0';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
				 $xstr.='select * ';
				 $xstr.='from item00 ';
				 $xstr.='where item_bser!="1"';
				 $xstr.='order by item_lsub, item_descri, item_mrca, item_modelo ';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}

		//
		$view0='sntr00';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
				 $xstr.='select * ';
				 $xstr.='from sntr0 left join enti00 ';
				 $xstr.='on ';
					 $xstr.=' sntr_seguro=enti_codigo ';		
				 $xstr.='order by sntr_codigo desc ';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}


		//
		$view0='sntr0b';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
				 $xstr.='select sntr00.*,';
				 $xstr.='concat(';
				 $xstr.='sntr_codigo,"/",';
				 $xstr.='if(sntr_descri is null,"",sntr_descri),"/",';
				 $xstr.='if(sntr_numero is null,"",sntr_numero),"/",';
				 $xstr.='if(sntr_poliza is null,"",sntr_poliza),"/",';
				 $xstr.='if(sntr_vhcl is null,"",sntr_vhcl),"/",';
				 $xstr.='"") as sntr_buscar ';
				 $xstr.=' from sntr00';
				 $xstr.=' order by sntr_codigo';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}


		$view0='vhcl00';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
				 $xstr.='select * ';
				 $xstr.='from vhcl0 left join mrca0 ';
				 $xstr.='on ';
					 $xstr.=' vhcl_mrca=mrca_codigo ';		
				 $xstr.='order by vhcl_codigo desc ';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}


		//
		$view0='vhcl0b';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
				 $xstr.='select vhcl00.*,';
				 $xstr.='concat(';
				 $xstr.='vhcl_codigo,"/",';
				 $xstr.='if(vhcl_motor is null,"",vhcl_motor),"/",';
				 $xstr.='if(vhcl_vinn is null,"",vhcl_vinn),"/",';
				 $xstr.='"") as vhcl_buscar ';
				 $xstr.=' from vhcl00';
				 $xstr.=' order by vhcl_codigo';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}


		//
		$view0='bldn00';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
				 $xstr.='select *, ';
				 $xstr.='case when bldn_fecha1 is not null then date_format(bldn_fecha1,"%d/%b/%y") end as fecha1dmy,';
				 $xstr.='case when bldn_fecha2 is not null then date_format(bldn_fecha2,"%d/%b/%y") end as fecha2dmy ';
				 $xstr.='from bldn0 ';
				 $xstr.='left join enti00 on bldn_consigna=enti_codigo ';		
				 $xstr.='left join port0 on bldn_port1=port_codigo ';		
				 $xstr.='left join nave0 on bldn_nave1=nave_codigo ';		
				 $xstr.=' ';
				 $xstr.='order by bldn_fecha1 desc ';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}

		//
		$view0='bldn0b';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
				 $xstr.='select bldn00.*,';
				 $xstr.='concat(';
				 $xstr.='bldn_codigo,"/",';
				 $xstr.='if(bldn_descri is null,"",bldn_descri),"/",';
				 $xstr.='if(bldn_master is null,"",bldn_master),"/",';
				 $xstr.='if(bldn_house is null,"",bldn_house),"/",';
				 $xstr.='if(bldn_manifiesto is null,"",bldn_manifiesto),"/",';
				 $xstr.='"") as bldn_buscar ';
				 $xstr.=' from bldn00';
				 $xstr.=' order by bldn_codigo';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}


		$view0='drtr0';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
				 $xstr.='select * ';
				 $xstr.=' from enti0 ';
				 $xstr.=' where enti_drtr="1" or enti_codigo in (select drtr from vtas1 where drtr is not null and drtr>"")';
				 $xstr.=' order by enti_descri';
			//xsqlstr
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}

		//$view0='dirigidos'
		////	sqle(xcnx,'drop view drgd0')
		//	$xstr='create view drgd0 as ';
// 				 $xstr.='select * ';
// 				 $xstr.=' from enti00 left join user0 on (enti_codigo=user_cedula)';
// 				 $xstr.=' order by enti_descri'
		//	//xsqlstr
// 		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}


		$view0='drgd1'; mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
					 $xstr.='select distinct enti, drtr from vtas1 where drtr>"" ';
					 $xstr.='union ';
					 $xstr.='select distinct enti, drtr from clie1 where drtr>"" ';
					 $xstr.='order by drtr,enti';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}


		$view0='drgd0';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
				 $xstr.='select * ';
				 $xstr.=' from enti00 left join user0 on (enti_codigo=user_cedula) left join drgd1 on(enti_codigo=enti)';
				 $xstr.=' order by enti_descri';
			//xsqlstr
// 		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}



		//	sqle(xcnx,'drop view usrdoc0')
		$view0='usrdoc0';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
				 $xstr.='select user_codigo, user_cedula,user_descri, docu_codigo from user0,docu0 where user_tipo like "admi"';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}


		//$view0='dirigidos'
		////	sqle(xcnx,'drop view drgd1')
		$view0='drgd1';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
				 $xstr.='select drgd0.*,clie1.enti,clie1.drtr ';
				 $xstr.='from drgd0 left join clie1 on (enti_codigo=enti)';
				 $xstr.=' order by enti_descri';
		//	//xsqlstr
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}

		
		
		
		
	}	
				
}
			
class vrupdv1
{
	function vrupdv1($tabla)
	{
		require('../cfg/cfg.php');
		require('../cfg/res.php');

	echo "\n";echo $tabla;
	$tabla1=$tabla.'1';$tabla2=$tabla.'2';
		
	$calfec='';
		$calfec.='case when fecha is not null then date_format(fecha,"%d/%b/%y") end as fechadmy,';
		$calfec.='case when fecha is not null then date_format(fecha,"%Y-%m-%d") end as fechaymd,';
		$calfec.='date_format(fecha,"%Y") as fanio,';
		$calfec.='date_format(fecha,"%m") as fmes,';
		$calfec.='date_format(fecha,"%d") as fdia,';
		$calfec.='upper(date_format(fecha,"%b")) as fmesn,';
		$calfec.='upper(date_format(fecha,"%a")) as fdian,';
		$calfec.='date_format(fecha,"%v") as fsema,';
		$calfec.='date_format(fecha,"%j") as fdoy,';
		$calfec.='date_format(idate,"%T") as fhora ';

	$calfep='';
		$calfep.='case when plazo is null or plazo=0 then 0 else 1 end pagocredi,';
		$calfep.='case when plazo is not null then adddate(fecha,plazo) else fecha end as vence,';
		$calfep.='case when plazo is not null then date_format(adddate(fecha,plazo),"%d/%b/%y") else date_format(fecha,"%d/%b/%y") end as vencedmy,';
		
		
// xstrclave='select idnum1,docu, numero,fecha,claveacc,';
// 			+'concat(date_format(fecha,"%d%m%Y"),';
// 			+'docu_tice,';
// 			+'empr_ruc,empr_ambientece,ptoe,numero,';
// 			+'"12345678","1")';
// 			+'as clave ';
// 	+'from vtas1,empr0,docu0 where docu=docu_codigo'
		
		
		
	$entides='';
		$entides.='enti_pasaporte,';
		$entides.='enti_descri,';
		$entides.='enti_razsoc,';
		$entides.='enti_nomcom,';
		$entides.='enti_nom1,';
		$entides.='enti_nom2,';
		$entides.='enti_ape1,';
		$entides.='enti_ape2,';
		$entides.='enti_cdad,';
		$entides.='enti_adrs,';
		$entides.='enti_email,';
		$entides.='enti_zsub,';
		$entides.='enti_tpro,';
		$entides.='enti_coesp,';
		$entides.='enti_rise,';
		$entides.='enti_tipoid,';
		$entides.='enti_tiporuc,';
		$entides.='enti_struc,';
		$entides.='enti_dnrdp,';
		$entides.='enti_referidox,';


	$itemdes='';
		$itemdes.='item_lsub,';
		$itemdes.='lsub_descri,';
		$itemdes.='item_descri,';
		$itemdes.='item_puni,';
		$itemdes.='item_ice,';
		$itemdes.='item_iva,';
		$itemdes.='item_irbp,';
		$itemdes.='(item_puni*(1+item_ice/100))*(1+item_iva/100) as item_pvp,';
//  		$itemdes.='(item_puni*(1+item_ice/100))*(1+item_iva/100)+item_irbp as item_pvp,';
		$itemdes.='(item_puni*(1+item_ice/100))*(1+item_iva/100)*cant as valpvp,';
		$itemdes.='item_duni,';
		$itemdes.='item_dval,';
		$itemdes.='item_umdd,';
		$itemdes.='item_mrca,';
		$itemdes.='item_modelo,';
		$itemdes.='item_ean,';
		$itemdes.='item_cair,';
		$itemdes.='item_bser,';
		$itemdes.='item_codigov,';
		$itemdes.='item_codigoc,';
		$itemdes.='item_codigop,';
		$itemdes.='item_provee,';
		$itemdes.='item_ubik,';
		$itemdes.='item_nctlg,';
		$itemdes.='item_pctlg,';
		$itemdes.='item_hoja,';
		$itemdes.='item_carr,';
		
// 		+'(item_puni*(1+item_ice/100))*(1+item_iva/100) as item_pvp,';
// 		+'(item_puni*(1+item_ice/100))*(1+item_iva/100)*'+t_tran2 +'.cant as valpvp,';
		
			
	$calsum1 = '';
		$calsum1.='round(sum(case when status="X" or status="O" then 0 else abs(cant) end),xrnd) as total, ';
		$calsum1.='round(sum(case when status="X" or status="O" then 0 else cant end),xrnd) as tcant, ';
		$calsum1.='round(sum(case when status="X" or status="O" then 0 when cant>0 then abs(cant) else 0 end),xrnd) as tdebito, ';
		$calsum1.='round(sum(case when status="X" or status="O" then 0 when cant<0 then abs(cant) else 0 end),xrnd) as tcredito, ';
		$calsum1.='round(sum(case when status="X" or status="O" then 0 else cant end),xrnd) as diferencia, ';

	$calsum1=str_replace('xrnd','2',$calsum1);
	$calsum2=str_replace('sum(','(',$calsum1);
		
	
		if(mb_stristr('cont',$tabla))
		{
		$view0=$tabla.'11';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
			$xstr.='select '.$tabla1.'.*, '.$tabla2.'.* ,count(iddet) as cdeta,max(iddet) as mdeta,concat(ptoe,"-",numero) as ptonumero,';
			$xstr.='docu_descri,docu_tico,';
			$xstr.=$calsum1;
			$xstr.=$entides;
			$xstr.='zsub_descri,';
			$xstr.='tpro_descri,';
			$xstr.='cdad_descri,';
			$xstr.='stat_descri,';
			$xstr.=$calfec;
			$xstr.='from '.$tabla1.' ';
			$xstr.='left join '.$tabla2.' on idnum1=idnum2 ';
			$xstr.='left join docu0 on docu=docu_codigo ';
			$xstr.='left join enti00 on enti=enti_codigo ';
			$xstr.='left join stat0 on status=stat_codigo ';
			$xstr.='where status!="X" ';
			$xstr.='group by idnum1 ';
			$xstr.='order by idnum1 desc';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}
		
		$view0=$tabla.'12';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
			$xstr.='select '.$tabla1.'.*, '.$tabla2.'.* ,concat(ptoe,"-",numero) as ptonumero,concat(ptoem,"-",numer) as ptonumer,';
			$xstr.='docu_descri,docu_tico,';
			$xstr.=$calsum2;
			$xstr.=$entides;
			$xstr.='zsub_descri,';
			$xstr.='tpro_descri,';
			$xstr.='cdad_descri,';
			$xstr.='stat_descri,';
			$xstr.='left(ctas,1) as ctan1,';
			$xstr.='left(ctas,3) as ctan2,';
			$xstr.='left(ctas,5) as ctan3,';
			$xstr.='left(ctas,7) as ctan4,';
			$xstr.='ctas as ctan5,';
			$xstr.='ctan1.ctas_descri as descri1,';
			$xstr.='ctan2.ctas_descri as descri2,';
			$xstr.='ctan3.ctas_descri as descri3,';
			$xstr.='ctan4.ctas_descri as descri4,';
			$xstr.='ctas00.ctas_descri as descri5,';
			$xstr.=$calfec;
			$xstr.='from '.$tabla1.' ';
			$xstr.='left join '.$tabla2.' on idnum1=idnum2 ';
			$xstr.='left join docu0 on docu=docu_codigo ';
			$xstr.='left join enti00 on enti=enti_codigo ';
			$xstr.='left join item00 on item=item_codigo ';
			$xstr.='left join ctas00 on ctas=ctas_codigo ';
			$xstr.='left join cair0 on cair=cair_codigo ';
			$xstr.='left join ctas0 ctan1 on left(ctas,1)=ctan1.ctas_codigo ';
			$xstr.='left join ctas0 ctan2 on left(ctas,3)=ctan2.ctas_codigo ';
			$xstr.='left join ctas0 ctan3 on left(ctas,5)=ctan3.ctas_codigo ';
			$xstr.='left join ctas0 ctan4 on left(ctas,7)=ctan4.ctas_codigo ';
			$xstr.='left join stat0 on status=stat_codigo ';
			$xstr.='where status!="X" ';
			$xstr.='group by idnum1,iddet ';
			$xstr.='order by idnum1 desc,iddet';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}
		}

	$calsum1 = '';
		$calsum1.='sum(case ';
			$calsum1.='when status="X" or status="O" then 0 ';
			$calsum1.='when docu not like "NC%" ';
			$calsum1.='then cant ';
			$calsum1.='else cant*-1 end) as tcant,';
		$calsum1.='sum(case ';
			$calsum1.='when status="X" or status="O" then 0 ';
			$calsum1.='when item_bser=1 then cant ';
			$calsum1.='else 0 end) as tbien,';
		$calsum1.='sum(case ';
			$calsum1.='when status="X" or status="O" then 0 ';
			$calsum1.='when docu not like "NC%" ';
			$calsum1.='then round(cant*puni,xrnd) ';
			$calsum1.='else round(cant*puni*-1,xrnd) end) as tsubt,';
		$calsum1.='sum(case ';
			$calsum1.='when status="X" or status="O" then 0 ';
			$calsum1.='when docu not like "NC%" ';
			$calsum1.='then round(cant*puni*dcto/100,xrnd) ';
			$calsum1.='else round(cant*puni*dcto/100*-1,xrnd) end) as tdcto,';
		$calsum1.='sum(case ';
			$calsum1.='when status="X" or status="O" then 0 ';
			$calsum1.='when docu not like "NC%" and ice>0 ';
			$calsum1.='then round(cant*puni*(1-dcto/100)*if(ice>0,1,0),xrnd) ';
			$calsum1.='when docu     like "NC%" and ice>0 ';
			$calsum1.='then round(cant*puni*(1-dcto/100)*if(ice>0,1,0)*-1,xrnd) ';
			$calsum1.='else 0 end) as tsubtice,';
		$calsum1.='sum(case ';
			$calsum1.='when status="X" or status="O" then 0 ';
			$calsum1.='when docu not like "NC%" ';
			$calsum1.='then round(cant*puni*(1-dcto/100)*(ice/100),xrnd) ';
			$calsum1.='else round(cant*puni*(1-dcto/100)*(ice/100)*-1,xrnd) end) as tice,';
		$calsum1.='sum(case ';
			$calsum1.='when status="X" or status="O" then 0 ';
			$calsum1.='when docu not like "NC%" ';
			$calsum1.='then round(cant*puni*(1-dcto/100)*(1+ice/100)*if(iva=0,1,0),xrnd) ';
			$calsum1.='when docu     like "NC%" ';
			$calsum1.='then round(cant*puni*(1-dcto/100)*(1+ice/100)*if(iva=0,1,0)*-1,xrnd) ';
			$calsum1.='else 0 end) as tsubtiva0,';
		$calsum1.='sum(case ';
			$calsum1.='when status="X" or status="O" then 0 ';
			$calsum1.='when docu not like "NC%" ';
			$calsum1.='then round(cant*puni*(1-dcto/100)*(1+ice/100)*if(iva>0,1,0),xrnd) ';
			$calsum1.='when docu     like "NC%" ';
			$calsum1.='then round(cant*puni*(1-dcto/100)*(1+ice/100)*if(iva>0,1,0)*-1,xrnd) ';
			$calsum1.='else 0 end) as tsubtiva,';
		$calsum1.='sum(case ';
			$calsum1.='when status="X" or status="O" then 0 ';
			$calsum1.='when docu not like "NC%" ';
			$calsum1.='then round(cant*puni*(1-dcto/100)*(1+ice/100)*(iva/100),xrnd) ';
			$calsum1.='else round(cant*puni*(1-dcto/100)*(1+ice/100)*(iva/100)*-1,xrnd) end) as tiva,';
		$calsum1.='sum(case ';
			$calsum1.='when status="X" or status="O" then 0 ';
			$calsum1.='when docu not like "NC%" ';
			$calsum1.='then round(cant*irbp,xrnd)';
			$calsum1.='else round(cant*irbp*-1,xrnd) ';
			$calsum1.='end) as tirbp,';
		$calsum1.='sum(case ';
			$calsum1.='when status="X" or status="O" then 0 ';
			$calsum1.='when docu not like "NC%" ';
			$calsum1.='then round(cant*puni*(1-dcto/100)*(1+ice/100)*(1+iva/100)+(cant*irbp),xrnd) ';
			$calsum1.='else round(cant*puni*(1-dcto/100)*(1+ice/100)*(1+iva/100)+(cant*irbp)*-1,xrnd) end) as pvp, ';
		$calsum1.='sum(case ';
			$calsum1.='when status="X" or status="O" then 0 ';
			$calsum1.='when docu not like "NC%" ';
			$calsum1.='then round(cant*puni*(1-dcto/100)*(1+ice/100)*(1+iva/100)+(cant*irbp),xrnd) ';
			$calsum1.='else round(cant*puni*(1-dcto/100)*(1+ice/100)*(1+iva/100)+(cant*irbp)*-1,xrnd) end) as total, ';
		$calsum1.='sum(case ';
			$calsum1.='when status="X" or status="O" then 0 ';
			$calsum1.='when docu like "NC%" then 0 ';
			$calsum1.='else round(cant*puni*(1-dcto/100)*(rrta/100),xrnd) end) as trrta,';
		$calsum1.='sum(case ';
			$calsum1.='when status="X" or status="O" then 0 ';
			$calsum1.='when docu like "NC%" then 0 ';
			$calsum1.='else round(cant*puni*(1-dcto/100)*(1+ice/100)*(iva/100)*(riva/100),xrnd) end) as triva,';

	$calsum1=str_replace('xrnd','2',$calsum1);
	$calsum2=str_replace('sum(','(',$calsum1);
		
	$calcom1 = '';
		$calcom1.='sum(case ';
			$calcom1.='when status="X" or status="O" then 0 ';
			$calcom1.='when docu not like "NC%" and comi>0 ';
			$calcom1.='then round(cant*puni*(1-dcto/100)*if(comi>0,1,0),xrnd) ';
			$calcom1.='when docu     like "NC%" and comi>0 ';
			$calcom1.='then round(cant*puni*(1-dcto/100)*if(comi>0,1,0)*-1,xrnd) ';
			$calcom1.='else 0 end) as tsubtcomi,';
		$calcom1.='sum(case ';
			$calcom1.='when status="X" or status="O" then 0 ';
			$calcom1.='when docu not like "NC%" ';
			$calcom1.='then round(cant*puni*(1-dcto/100)*(comi/100),xrnd) ';
			$calcom1.='else round(cant*puni*(1-dcto/100)*(comi/100)*-1,xrnd) end) as tcomi,';
		
	$calcom1=str_replace('xrnd','2',$calcom1);
	$calcom2=str_replace('sum(','(',$calcom1);
		
		if(mb_stristr('comp.prov.cele',$tabla))
		{
			$calsum1=str_replace('NC%','NP%',$calsum1);
			$calsum2=str_replace('NC%','NP%',$calsum2);
		} 

		if(mb_stristr('vtas.clie.clte',$tabla))
		{
		$view0=$tabla.'11';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
			$xstr.='select '.$tabla1.'.*, '.$tabla2.'.* ,count(iddet) as cdeta,max(iddet) as mdeta,concat(ptoe,"-",numero) as ptonumero,';
			$xstr.='docu_descri,docu_tico,';
			$xstr.='max(dcto) as pdcto,max(ice) as pice,max(iva)as piva,max(irbp)as pirbp,';
			$xstr.=$calsum1;
			$xstr.=$entides;
			$xstr.='zsub_descri,';
			$xstr.='tpro_descri,';
			$xstr.='cdad_descri,';
			$xstr.='ptov_descri,';
			$xstr.='vndd_descri,';
			$xstr.='stat_descri,';
			$xstr.=$calcom1;
			$xstr.=$calfep;
			$xstr.=$calfec;
			$xstr.='from '.$tabla1.' ';
			$xstr.='left join '.$tabla2.' on idnum1=idnum2 ';
			$xstr.='left join docu0 on docu=docu_codigo ';
			$xstr.='left join enti00 on enti=enti_codigo ';
			$xstr.='left join item0 on item=item_codigo ';
			$xstr.='left join ptov0 on ptov=ptov_codigo ';
			$xstr.='left join vndd0 on vndd=vndd_codigo ';
			$xstr.='left join stat0 on status=stat_codigo ';
			$xstr.='where status!="X" ';
			$xstr.='group by idnum1 ';
			$xstr.='order by idnum1 desc';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}
		
		$view0=$tabla.'12';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
			$xstr.='select '.$tabla1.'.*, '.$tabla2.'.* ,concat(ptoe,"-",numero) as ptonumero,concat(ptoem,"-",numer) as ptonumer,';
			$xstr.='docu_descri,docu_tico,';
			$xstr.=$calsum2;
			$xstr.=$entides;
			$xstr.='zsub_descri,';
			$xstr.='tpro_descri,';
			$xstr.='cdad_descri,';
			$xstr.='ptov_descri,';
			$xstr.='vndd_descri,';
			$xstr.='stat_descri,';
// 			$xstr.='(item_puni*(1+item_ice/100))*(1+item_iva/100)+irbp as pvp0,';
			$xstr.=$itemdes;
			$xstr.=$calcom2;
			$xstr.=$calfep;
			$xstr.=$calfec;
			$xstr.='from '.$tabla1.' ';
			$xstr.='left join '.$tabla2.' on idnum1=idnum2 ';
			$xstr.='left join docu0 on docu=docu_codigo ';
			$xstr.='left join enti00 on enti=enti_codigo ';
			$xstr.='left join item00 on item=item_codigo ';
			$xstr.='left join ptov0 on ptov=ptov_codigo ';
			$xstr.='left join vndd0 on vndd=vndd_codigo ';
			$xstr.='left join stat0 on status=stat_codigo ';
			$xstr.='where status!="X" ';
			$xstr.='group by idnum1,iddet ';
			$xstr.='order by idnum1 desc,iddet';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}
		}
		

		if(mb_stristr('comp.prov.cele',$tabla))
		{
		$view0=$tabla.'11';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
			$xstr.='select '.$tabla1.'.*, '.$tabla2.'.* ,count(iddet) as cdeta,max(iddet) as mdeta,concat(ptoe,"-",numero) as ptonumero,';
			$xstr.='docu_descri,docu_tico,';
			$xstr.='max(dcto) as pdcto,max(ice) as pice,max(iva)as piva,max(irbp)as pirbp,';
			$xstr.=$calsum1;
			$xstr.=$entides;
// 			$xstr.='zsub_descri,';
			$xstr.='tpro_descri,';
			$xstr.='cdad_descri,';
			$xstr.='suco0.suco_descri,';
			$xstr.='cair0.cair_descri,';
			$xstr.='ctas0.ctas_descri,';
			$xstr.='stat_descri,';
// 			$xstr.=$calcom1;
			$xstr.=$calfep;
			$xstr.=$calfec;
			$xstr.='from '.$tabla1.' ';
			$xstr.='left join '.$tabla2.' on idnum1=idnum2 ';
			$xstr.='left join docu0 on docu=docu_codigo ';
			$xstr.='left join enti00 on enti=enti_codigo ';
			$xstr.='left join item00 on item=item_codigo ';
			$xstr.='left join suco0 on suco=suco_codigo ';
			$xstr.='left join cair0 on cair=cair_codigo ';
			$xstr.='left join ctas0 on ctas=ctas_codigo ';
			$xstr.='left join stat0 on status=stat_codigo ';
			$xstr.='where status!="X" ';
			$xstr.='group by idnum1 ';
			$xstr.='order by idnum1 desc';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}
		
			$xstr3= substr($xstr,strpos($xstr,'select'),strlen($xstr));
// 			$xstr3=str_replace(',iddet',' ',$xstr3);
			$xstr3=str_replace('group by idnum1 desc','group by idnum1 desc,cair',$xstr3);

		$view0=$tabla.'12';	mysql_query('drop view '.$view0,$link_vcrx); $xstr='create view '.$view0.' as ';
			$xstr.='select '.$tabla1.'.*, '.$tabla2.'.* ,concat(ptoe,"-",numero) as ptonumero,concat(ptoem,"-",numer) as ptonumer,';
			$xstr.='docu_descri,docu_tico,';
			$xstr.=$calsum2;
			$xstr.=$entides;
			$xstr.='zsub_descri,';
			$xstr.='tpro_descri,';
			$xstr.='cdad_descri,';
			$xstr.='suco0.suco_descri,';
			$xstr.='cair0.cair_descri,';
			$xstr.='ctas0.ctas_descri,';
			$xstr.='stat_descri,';
// 			$xstr.='(item_puni*(1+item_ice/100))*(1+item_iva/100)+irbp as pvp0,';
			$xstr.=$itemdes;
// 			$xstr.=$calcom2;
			$xstr.=$calfep;
			$xstr.=$calfec;
			$xstr.='from '.$tabla1.' ';
			$xstr.='left join '.$tabla2.' on idnum1=idnum2 ';
			$xstr.='left join docu0 on docu=docu_codigo ';
			$xstr.='left join enti00 on enti=enti_codigo ';
			$xstr.='left join item00 on item=item_codigo ';
			$xstr.='left join suco0 on suco=suco_codigo ';
			$xstr.='left join cair0 on cair=cair_codigo ';
			$xstr.='left join ctas0 on ctas=ctas_codigo ';
			$xstr.='left join stat0 on status=stat_codigo ';
			$xstr.='where status!="X" ';
			$xstr.='group by idnum1,iddet ';
			$xstr.='order by idnum1 desc,iddet';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}

		$view0=$tabla.'13';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
			$xstr.=$xstr3;
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}
		}
		
		

		
	$calsum1 = '';
		$calsum1.='sum(case ';
			$calsum1.='when status="X" or status="O" then 0 ';
			$calsum1.='when docu like "I%" ';
			$calsum1.='then cant*puni ';
			$calsum1.='else cant*puni*-1 ';
			$calsum1.='end) as total,';
		$calsum1.='sum(case ';
			$calsum1.='when status="X" or status="O" then 0 ';
			$calsum1.='when docu like "I%" ';
			$calsum1.='then cant ';
			$calsum1.='else cant*-1 ';
			$calsum1.='end) as tcant,';
		$calsum1.='sum(case ';
			$calsum1.='when status="X" or status="O" then 0 ';
			$calsum1.='when docu like "I%" ';
			$calsum1.='then cant ';
			$calsum1.='else 0 ';
			$calsum1.='end) as tingreso,';
		$calsum1.='sum(case ';
			$calsum1.='when status="X" or status="O" then 0 ';
			$calsum1.='when docu like "E%" ';
			$calsum1.='then cant ';
			$calsum1.='else 0 ';
			$calsum1.='end) as tegreso,';
		$calsum1.='sum(case ';
			$calsum1.='when status="X" or status="O" then 0 ';
			$calsum1.='when docu like "I%" ';
			$calsum1.='then round(cant*puni,xrnd) ';
			$calsum1.='else round(cant*puni*-1,xrnd) end) as tsubt,';
		$calsum1.='sum(case ';
			$calsum1.='when status="X" or status="O" then 0 ';
			$calsum1.='when docu like "I%" ';
			$calsum1.='then 1 ';
			$calsum1.='else -1 ';
			$calsum1.='end) as signo,';
		$calsum1.=' 0 as tdcto, 0 as tice, 0 as tiva, 0 as tirbp,';
		
	$calsum1=str_replace('xrnd','2',$calsum1);
	$calsum2=str_replace('sum(','(',$calsum1);

		if(mb_stristr('inve.prod',$tabla))
		{
		$view0=$tabla.'11';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
			$xstr.='select '.$tabla1.'.*, '.$tabla2.'.* ,count(iddet) as cdeta,max(iddet) as mdeta,concat(ptoe,"-",numero) as ptonumero,';
			$xstr.='docu_descri,docu_tico,';
			$xstr.=$calsum1;
			$xstr.=$entides;
// 			$xstr.='zsub_descri,';
			$xstr.='bode0.bode_descri,';
			$xstr.='bode2.bode_descri as tobode_descri,';
			$xstr.='tpro_descri,';
			$xstr.='cdad_descri,';
			$xstr.='stat_descri,';
// 			$xstr.=$calcom1;
// 			$xstr.=$calfep;
			$xstr.=$calfec;
			$xstr.='from '.$tabla1.' ';
			$xstr.='left join '.$tabla2.' on idnum1=idnum2 ';
			$xstr.='left join docu0 on docu=docu_codigo ';
			$xstr.='left join enti00 on enti=enti_codigo ';
			$xstr.='left join item00 on item=item_codigo ';
			$xstr.='left join bode0 on bode=bode0.bode_codigo ';
			$xstr.='left join bode0 bode2 on tobode=bode2.bode_codigo ';
			$xstr.='left join stat0 on status=stat_codigo ';
			$xstr.='where status!="X" ';
			$xstr.='group by idnum1 ';
			$xstr.='order by idnum1 desc';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}

			
		$view0=$tabla.'12';	mysql_query('drop view '.$view0,$link_vcrx); $xstr='create view '.$view0.' as ';
			$xstr.='select '.$tabla1.'.*, '.$tabla2.'.* ,concat(ptoe,"-",numero) as ptonumero,concat(ptoem,"-",numer) as ptonumer,';
			$xstr.='docu_descri,docu_tico,';
			$xstr.=$calsum2;
			$xstr.=$entides;
			$xstr.='bode0.bode_descri,';
			$xstr.='bode2.bode_descri as tobode_descri,';
			$xstr.='tpro_descri,';
			$xstr.='cdad_descri,';
			$xstr.='stat_descri,';
// 			$xstr.='(item_puni*(1+item_ice/100))*(1+item_iva/100)+irbp as pvp0,';
			$xstr.=$itemdes;
// 			$xstr.=$calcom2;
			$xstr.=$calfec;
			$xstr.='from '.$tabla1.' ';
			$xstr.='left join '.$tabla2.' on idnum1=idnum2 ';
			$xstr.='left join docu0 on docu=docu_codigo ';
			$xstr.='left join enti00 on enti=enti_codigo ';
			$xstr.='left join item00 on item=item_codigo ';
			$xstr.='left join bode0 on bode=bode0.bode_codigo ';
			$xstr.='left join bode0 bode2 on tobode=bode2.bode_codigo ';
			$xstr.='left join stat0 on status=stat_codigo ';
			$xstr.='where status!="X" ';
			$xstr.='group by idnum1,iddet ';
			$xstr.='order by idnum1 desc,iddet';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}

		}
		
	$calsum1 = '';
		$calsum1.='sum(case ';
			$calsum1.='when status="X" or status="O" then 0 ';
			$calsum1.='when docu like "I%" ';
			$calsum1.='then 0 ';
			$calsum1.='else 0*-1 ';
			$calsum1.='end) as tsubt,';
		$calsum1.='sum(case ';
			$calsum1.='when status="X" or status="O" then 0 ';
			$calsum1.='when docu like "I%" ';
			$calsum1.='then cant ';
			$calsum1.='else cant*-1 ';
			$calsum1.='end) as total,';
		$calsum1.='sum(case ';
			$calsum1.='when status="X" or status="O" then 0 ';
			$calsum1.='when docu like "I%" ';
			$calsum1.='then cant ';
			$calsum1.='else cant*-1 ';
			$calsum1.='end) as tcant,';
		$calsum1.='sum(case ';
			$calsum1.='when status="X" or status="O" then 0 ';
			$calsum1.='when docu like "I%" ';
			$calsum1.='then cant ';
			$calsum1.='else 0 ';
			$calsum1.='end) as tingreso,';
		$calsum1.='sum(case ';
			$calsum1.='when status="X" or status="O" then 0 ';
			$calsum1.='when docu like "E%"  ';
			$calsum1.='then cant ';
			$calsum1.='else 0 ';
			$calsum1.='end) as tegreso,';
		
		if(mb_stristr('caja',$tabla))
		{
		$view0=$tabla.'11';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
			$xstr.='select '.$tabla1.'.*, '.$tabla2.'.* ,count(iddet) as cdeta,max(iddet) as mdeta,concat(ptoe,"-",numero) as ptonumero,';
			$xstr.='docu_descri,docu_tico,';
			$xstr.=$calsum1;
			$xstr.=$entides;
			$xstr.='caja_descri,';
			$xstr.='caja_ctacont,';
			$xstr.='zsub_descri,';
			$xstr.='tpro_descri,';
			$xstr.='cdad_descri,';
			$xstr.='stat_descri,';
// 			$xstr.=$calfep;
			$xstr.=$calfec;
			$xstr.='from '.$tabla1.' ';
			$xstr.='left join '.$tabla2.' on idnum1=idnum2 ';
			$xstr.='left join docu0 on docu=docu_codigo ';
			$xstr.='left join enti00 on enti=enti_codigo ';
			$xstr.='left join caja0 on caja=caja_codigo ';
			$xstr.='left join stat0 on status=stat_codigo ';
			$xstr.='where status!="X" ';
			$xstr.='group by idnum1 ';
			$xstr.='order by idnum1 desc';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}

			
		$view0=$tabla.'12';	mysql_query('drop view '.$view0,$link_vcrx); $xstr='create view '.$view0.' as ';
			$xstr.='select '.$tabla1.'.*, '.$tabla2.'.* ,concat(ptoe,"-",numero) as ptonumero,concat(ptoem,"-",numer) as ptonumer,';
			$xstr.='docu_descri,docu_tico,';
			$xstr.=$calsum2;
			$xstr.=$entides;
			$xstr.='caja_descri,';
			$xstr.='caja_ctacont,';
			$xstr.='zsub_descri,';
			$xstr.='tpro_descri,';
			$xstr.='cdad_descri,';
			$xstr.='stat_descri,';
// 			$xstr.=$calfep;
			$xstr.=$calfec;
			$xstr.='from '.$tabla1.' ';
			$xstr.='left join '.$tabla2.' on idnum1=idnum2 ';
			$xstr.='left join docu0 on docu=docu_codigo ';
			$xstr.='left join enti00 on enti=enti_codigo ';
			$xstr.='left join caja0 on caja=caja_codigo ';
			$xstr.='left join stat0 on status=stat_codigo ';
			$xstr.='where status!="X" ';
			$xstr.='group by idnum1,iddet ';
			$xstr.='order by idnum1 desc,iddet';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}

		}
		
	$calsum1 = '';
		$calsum1.='sum(case ';
			$calsum1.='when status="X" or status="O" then 0 ';
			$calsum1.='when docu like "DC%" or docu like "DB%"  or docu like "DK%"  ';
			$calsum1.='then 0 ';
			$calsum1.='else 0*-1 ';
			$calsum1.='end) as tsubt,';
		$calsum1.='sum(case ';
			$calsum1.='when status="X" or status="O" then 0 ';
			$calsum1.='when docu like "DC%" or docu like "DB%"  or docu like "DK%"  ';
			$calsum1.='then cant ';
			$calsum1.='else cant*-1 ';
			$calsum1.='end) as total,';
		$calsum1.='sum(case ';
			$calsum1.='when status="X" or status="O" then 0 ';
			$calsum1.='when docu like "DC%" or docu like "DB%"  or docu like "DK%"  ';
			$calsum1.='then cant ';
			$calsum1.='else cant*-1 ';
			$calsum1.='end) as tcant,';
		$calsum1.='sum(case ';
			$calsum1.='when status="X" or status="O" then 0 ';
			$calsum1.='when docu like "DC%" or docu like "DB%"  or docu like "DK%"  ';
			$calsum1.='then cant ';
			$calsum1.='else 0 ';
			$calsum1.='end) as tingreso,';
		$calsum1.='sum(case ';
			$calsum1.='when status="X" or status="O" then 0 ';
			$calsum1.='when docu not like "DC%" and docu not like "DB%" and docu not like "DK%"  ';
			$calsum1.='then cant ';
			$calsum1.='else 0 ';
			$calsum1.='end) as tegreso,';
		
		if(mb_stristr('bcos.cjte',$tabla))
		{
		$view0=$tabla.'11';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
			$xstr.='select '.$tabla1.'.*, '.$tabla2.'.* ,count(iddet) as cdeta,max(iddet) as mdeta,concat(ptoe,"-",numero) as ptonumero,';
			$xstr.='docu_descri,docu_tico,';
			$xstr.=$calsum1;
			$xstr.=$entides;
			$xstr.='ctab_descri,';
			$xstr.='ctab_ctacont,';
			$xstr.='zsub_descri,';
			$xstr.='tpro_descri,';
			$xstr.='cdad_descri,';
			$xstr.='stat_descri,';
// 			$xstr.=$calfep;
			$xstr.=$calfec;
			$xstr.='from '.$tabla1.' ';
			$xstr.='left join '.$tabla2.' on idnum1=idnum2 ';
			$xstr.='left join docu0 on docu=docu_codigo ';
			$xstr.='left join enti00 on enti=enti_codigo ';
			$xstr.='left join ctab0 on ctab=ctab_codigo ';
			$xstr.='left join stat0 on status=stat_codigo ';
			$xstr.='where status!="X" ';
			$xstr.='group by idnum1 ';
			$xstr.='order by idnum1 desc';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}

			
		$view0=$tabla.'12';	mysql_query('drop view '.$view0,$link_vcrx); $xstr='create view '.$view0.' as ';
			$xstr.='select '.$tabla1.'.*, '.$tabla2.'.* ,concat(ptoe,"-",numero) as ptonumero,concat(ptoem,"-",numer) as ptonumer,';
			$xstr.='docu_descri,docu_tico,';
			$xstr.=$calsum2;
			$xstr.=$entides;
			$xstr.='caja_descri,';
			$xstr.='caja_ctacont,';
			$xstr.='zsub_descri,';
			$xstr.='tpro_descri,';
			$xstr.='cdad_descri,';
			$xstr.='stat_descri,';
// 			$xstr.=$calfep;
			$xstr.=$calfec;
			$xstr.='from '.$tabla1.' ';
			$xstr.='left join '.$tabla2.' on idnum1=idnum2 ';
			$xstr.='left join docu0 on docu=docu_codigo ';
			$xstr.='left join enti00 on enti=enti_codigo ';
			$xstr.='left join caja0 on caja=caja_codigo ';
			$xstr.='left join stat0 on status=stat_codigo ';
			$xstr.='where status!="X" ';
			$xstr.='group by idnum1,iddet ';
			$xstr.='order by idnum1 desc,iddet';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}

		}
		
	$calsum1 = '';
		$calsum1.='sum(case ';
			$calsum1.='when status="X" or status="O" then 0 ';
			$calsum1.='else cant*puni/100*-1 ';
			$calsum1.='end) as tsubt,';
		$calsum1.='sum(case ';
			$calsum1.='when status="X" or status="O" then 0 ';
			$calsum1.='else cant*puni/100*-1 ';
			$calsum1.='end) as total,';
		$calsum1.='sum(case ';
			$calsum1.='when status="X" or status="O" then 0 ';
			$calsum1.='else 0 ';
			$calsum1.='end) as tcant,';
		$calsum1.='sum(case ';
			$calsum1.='when status="X" or status="O" then 0 ';
			$calsum1.='else cant ';
			$calsum1.='end) as valbase,';
		$calsum1.='sum(case ';
			$calsum1.='when status="X" or status="O" then 0 ';
			$calsum1.='when cair="-" or cair ="" or cair is null then cant ';
			$calsum1.='else 0 ';
			$calsum1.='end) as biva,';
		$calsum1.='max(case ';
			$calsum1.='when status="X" or status="O" then 0 ';
			$calsum1.='when cair="-" or cair ="" or cair is null then puni ';
			$calsum1.='else 0 ';
			$calsum1.='end) as piva,';
		$calsum1.='sum(case ';
			$calsum1.='when status="X" or status="O" then 0 ';
			$calsum1.='when cair="-" or cair ="" or cair is null then cant*puni/100 ';
			$calsum1.='else 0 ';
			$calsum1.='end) as riva,';
		$calsum1.='sum(case ';
			$calsum1.='when status="X" or status="O" then 0 ';
			$calsum1.='when cair!="-" and cair !="" and cair is not null then cant ';
			$calsum1.='else 0 ';
			$calsum1.='end) as brta,';
		$calsum1.='max(case ';
			$calsum1.='when status="X" or status="O" then 0 ';
			$calsum1.='when cair!="-" and cair !="" and cair is not null then puni ';
			$calsum1.='else 0 ';
			$calsum1.='end) as prta,';
		$calsum1.='sum(case ';
			$calsum1.='when status="X" or status="O" then 0 ';
			$calsum1.='when cair!="-" and cair !="" and cair is not null then cant *puni/100 ';
			$calsum1.='else 0 ';
			$calsum1.='end) as rrta,';
		$calsum1.='sum(case ';
			$calsum1.='when status="X" or status="O" then 0 ';
			$calsum1.='when docu like "RC%" then cant*puni/100 ';
			$calsum1.='else 0 ';
			$calsum1.='end) as tingreso,';
		$calsum1.='sum(case ';
			$calsum1.='when status="X" or status="O" then 0 ';
			$calsum1.='when docu like "RP%" then cant*puni/100 ';
			$calsum1.='else 0 ';
			$calsum1.='end) as tegreso,';
		
		if(mb_stristr('retc.retp',$tabla))
		{
		$view0=$tabla.'11';	mysql_query('drop view '.$view0,$link_vcrx); $xstr= 'create view '.$view0.' as ';
			$xstr.='select '.$tabla1.'.*, '.$tabla2.'.* ,count(iddet) as cdeta,max(iddet) as mdeta,concat(ptoe,"-",numero) as ptonumero,';
			$xstr.='docu_descri,docu_tico,';
			$xstr.=$calsum1;
			$xstr.=$entides;
			$xstr.='cair_descri,';
			$xstr.='zsub_descri,';
			$xstr.='tpro_descri,';
			$xstr.='cdad_descri,';
			$xstr.='stat_descri,';
// 			$xstr.=$calfep;
			$xstr.=$calfec;
			$xstr.='from '.$tabla1.' ';
			$xstr.='left join '.$tabla2.' on idnum1=idnum2 ';
			$xstr.='left join docu0 on docu=docu_codigo ';
			$xstr.='left join enti00 on enti=enti_codigo ';
			$xstr.='left join cair0 on cair=cair_codigo ';
			$xstr.='left join stat0 on status=stat_codigo ';
			$xstr.='where status!="X" ';
			$xstr.='group by idnum1 ';
			$xstr.='order by idnum1 desc';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}

			
		$view0=$tabla.'12';	mysql_query('drop view '.$view0,$link_vcrx); $xstr='create view '.$view0.' as ';
			$xstr.='select '.$tabla1.'.*, '.$tabla2.'.* ,concat(ptoe,"-",numero) as ptonumero,concat(ptoem,"-",numer) as ptonumer,';
			$xstr.='docu_descri,docu_tico,';
			$xstr.=$calsum2;
			$xstr.=$entides;
			$xstr.='cair_descri,';
			$xstr.='zsub_descri,';
			$xstr.='tpro_descri,';
			$xstr.='cdad_descri,';
			$xstr.='stat_descri,';
// 			$xstr.=$calfep;
			$xstr.=$calfec;
			$xstr.='from '.$tabla1.' ';
			$xstr.='left join '.$tabla2.' on idnum1=idnum2 ';
			$xstr.='left join docu0 on docu=docu_codigo ';
			$xstr.='left join enti00 on enti=enti_codigo ';
			$xstr.='left join cair0 on cair=cair_codigo ';
			$xstr.='left join stat0 on status=stat_codigo ';
			$xstr.='where status!="X" ';
			$xstr.='group by idnum1,iddet ';
			$xstr.='order by idnum1 desc,iddet';
		if (mysql_query($xstr,$link_vcrx)!=1){echo "\n";echo ' *** ERROR *** '.$xstr;echo ' ==>'.mysql_error();}

		}
		

	}	
				
}
			
?>