$arrc = $ciu->Select2($cuidadP);
    $rowciudad = mysql_fetch_array($arrc);
    $telefonoP = $_POST['telefonoP'];
    $ContactoP = $_POST['contactoP'];
    $idciudad = $rowciudad['ID_CIUDAD'];
    $prov = new proveedor();
    $row = $prov->Select($rut);
    $action = mysql_fetch_array($row);
    if ($action == null) {
        $prov->Add($rut, $idciudad, $nombreP, $direccionP, $ContactoP, $telefonoP);
    }
    include 'IngresarOCBD.php';
    $arr = $_SESSION["list"];
    $size = $_SESSION["size"];
    $fecha = time();
    $fechaactual = date("Y-m-d h:m:s", $fecha);
    $cont = new contiene();
    for ($i = 0; $i < $size; $i++) {
        $n = "c" . $i;
        $cont->Add($_POST["{$n}"], $_POST['NumOC'], "0", $rut, "0", 0, $arr[$i][1], 0, 0, $arr[$i][2], $fechaactual);
    }
    header("Location: paso.php?c=1");
    //header ("Location: IngresarOCBD.php");
    /*if($r==null){
    	$fecha= time();
    	$fechaactual=date("Y-m-d",$fecha);
    	$estado="pendiente";
    	$oc->Add($numero,0,$fechaoc,$fechatope,$fechaactual,$solicitante,$observacion,$estado,0,0);
    	header ("Location: paso.php?c=0");
    }*/
}
    header("Location: paso.php?c=5");
} else {
    //NOTA:FALTA DESCONTAR DE STOCK SI EL ID DE OBRA ES 0;
    $stock = new stock();
    $idobra = $_POST["obras"];
    if ($idobra == "Ninguna") {
        $idobra = 0;
    }
    $folio = $_SESSION["folio"];
    $fecha = time();
    $fechaactual = date("Y-m-d h:m:s", $fecha);
    $arr = $_SESSION["lista1"];
    $ejecuta = new ejecuta();
    $stock = new stock();
    //ingresar retiro
    $contiene = new contiene();
    $retiro = new retiro();
    $retiro->Add($_POST["nombreD"], $_POST["motivo"], 0);
    $sretiro = $retiro->Select2($_POST["nombreD"], $_POST["motivo"], 0);
    $rowretiro = mysql_fetch_array($sretiro);
    //ingresar ejecuta
    for ($i = 0; $i < count($arr); $i++) {
        $n = "cantidad" . $i;
        $ejecuta->Add($rowretiro["ID_RETIRO"], $arr[$i][0], $_POST["unidadp"], $folio, $fechaactual, $_POST["{$n}"]);
        $contiene->Update($_POST["{$n}"], $arr[$i][0], $idobra);
        if ($idobra == 0) {
            //descontar de stock si es que se saca de bodega general osea el id de obra es 0
            $stock->UpdateRC($arr[$i][0], $_POST["{$n}"]);
        }
    }
    //$contiene->Update();
<?php

include "../ReglasNegocio/documento.php";
include "../ReglasNegocio/contiene.php";
$rutp1 = $_POST["rutp1"];
$rutp2 = $_POST["rutp2"];
$rut = $rutp1 . '-' . $rutp2;
$ndoc = $_POST["NDocumento"];
$tipod = $_POST["tipod"];
$fechad = $_POST["fecha_reclamo"];
$obra = $_POST["obras"];
$observ = $_POST["ObservacionDoc"];
$size = $_SESSION["size"];
$cont = new contiene();
$doc = new documento();
$arr = $_SESSION["lista"];
$docs = $doc->Select($ndoc);
$selectdoc = mysql_fetch_array($docs);
if ($selectdoc == null) {
    $doc->Add($ndoc, $tipod, $fechad, $observ);
    for ($i = 0; $i < $size; $i++) {
        $n = "cantidadr" . $i;
        $bod = $arr[$i][3] + $_POST["{$n}"];
        $numoc = $_SESSION['oc'];
        $cont->Add($arr[$i][0], $_SESSION['oc'], $ndoc, $rut, $arr[$i][2], $arr[$i][3], $bod, $_POST["{$n}"], 0);
        $sql = "update contiene set CANTIDADBODEGA_CONTIENE=" . $bod . " where ID_MATERIAL=" . $arr[$i][0] . "and NUMERO_OC=" . "'{$numoc}'" . " and ID_DOCUMENTO='0' AND RUT_PROVEEDOR=" . "'{$rut}'";
        $accion = mysql_query($sql);
    }
}
<?php

session_start();
$boton = "verifica()";
$boton2 = "verifica2()";
include "../AccesoDatos/Controller.php";
include "../ReglasNegocio/contiene.php";
include "../ReglasNegocio/obra.php";
$contiene = new contiene();
$obra = new obra();
$folio = $contiene->GetMayor() + 1;
?>
<script LANGUAGE="JavaScript">

function verifica()
{
	if (document.miform.NumOC.value.length==0)
   {
		alert("Debe ingresar un Codigo");
		document.miform.NumOC.focus();
      	return 0;
	}
	document.miform.submit();
	
}
function verifica2()
{
	if(document.miform.NDocumento.value.length==0){
		alert("Debe ingresar numero de la factura o guia");
		document.form.NDocumento.focus();
      	return 0;
 //nombre de la obra
 $idobra = 0;
 $obra = $_POST["obras"];
 //objeto obra para obtener el id de la obra
 if ($obra == "Ninguna") {
     $idobra = 0;
 } else {
     $idobra = $obra;
 }
 //$obra1=new obra();
 //$rowobra=$obra1->Select($obra);
 //$idobra=mysql_fetch_array($rowobra);
 //observacion
 $observ = $_POST["ObservacionDoc"];
 //objeto clase contiene
 $cont = new contiene();
 //objeto clase documento
 $doc = new documento();
 //objeto clase stock
 $stock = new stock();
 //lista de materiales
 $arr = $_SESSION["lista1"];
 //buscar documento
 $docs = $doc->Select($ndoc);
 //if($docs==null){
 //validar cantidades
 $a = 0;
 for ($i = 0; $i < count($arr); $i++) {
     $n = "cantidadr" . $i;
     if ($_POST["{$n}"] > $arr[$i][2] - $arr[$i][3]) {
         $a = $i + 1;