<?php
session_start();
//echo $_POST['cobidnu'];
//echo $_POST['cobdocu'];
require('../cfg/res.php');
require('../../_lib/vrdocu0.php');
$docu_cobr=new vrdocu0('../cfg/res.php',$_POST['cobdocu']);

$sql_cobr='select *from '.strtolower($docu_cobr->tabla).'11 where idnum1='.$_POST['cobidnu'].' and status="-"';
//echo $sql_cobr;
$res_cobr=mysql_query($sql_cobr,$link_vcrx);
if(mysql_num_rows($res_cobr)==0)
{
	echo 'Error:cbr';
}
else
{
	$enti_caja1=mysql_result($res_cobr,0,'enti');
	$docu_caja1=mysql_result($res_cobr,0,'docu');
	$ptoe_caja1=mysql_result($res_cobr,0,'ptoe');
	$numer_caja1=mysql_result($res_cobr,0,'numero');
	$total_caja1=mysql_result($res_cobr,0,'total');
	$nume_caja1=new vrdocu0('../cfg/res.php','IE10');
	$numero_caja1=$nume_caja1->numero;
	$numero_caja1++;
	$sql_caja1='insert into caja1(
	docu,
	ptoe,
	numero,
	fecha,
	enti,
	status,
	concepto,
	iuser,
	idate
	)
	values(
	"IE10",
	"001001",
	'.$numero_caja1.',
	now(),
	"'.$enti_caja1.'",
	"-",
	"PAGO EN EFECTIVO",
	"'.$_SESSION['user_vcrx_id'].'",
	now()
	)';
	if(mysql_query($sql_caja1))
	{
		$nume_caja1->vrdocu_setplus();
		$sql_idnum='select max(idnum1)as idnumcaja from caja1 where iuser="'.$_SESSION['user_vcrx_id'].'" and enti="'.$enti_caja1.'"';
		$res_idnum=mysql_query($sql_idnum,$link_vcrx);
		$idnum_idnum=mysql_result($res_idnum,0,'idnumcaja');
		$sql_caja2='insert into caja2(
		idnum2,
		iddet,
		docum,
		ptoem,
		numer,
		cant
		)
		values(
		'.$idnum_idnum.',
		1,
		"'.$docu_caja1.'",
		"'.$ptoe_caja1.'",
		"'.$numer_caja1.'",
		'.$total_caja1.'
		)';
		mysql_query($sql_caja2,$link_vcrx);
		$sql_cobrup='update '.strtolower($docu_cobr->tabla).'1 set status="C" where idnum1='.$_POST['cobidnu'];
		mysql_query($sql_cobrup,$link_vcrx);
		
	}
	else
	{
		echo 'error:5001';
	}
}
?>