public function PstoLineas() { $nItems = 0; $nErrores = 0; $dbLink = mysql_connect("localhost", "root", "albatronic"); $query = "TRUNCATE {$this->dbDestino}.ErpPstoLineas"; mysql_query($query); $query = "select Codigo,IDArticulo from {$this->dbDestino}.ErpArticulos"; $result = mysql_query($query, $dbLink); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $correspondencia[$row['Codigo']] = $row['IDArticulo']; } $query = "select l.*, c.Estado, c.Fecha from {$this->dbOrigen}.psto_lineas as l LEFT JOIN {$this->dbOrigen}.psto_cab as c ON l.IDPsto=c.IDPsto where c.IDPsto>0"; $result = mysql_query($query, $dbLink); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $c = new PstoLineas(); $c->setIDPsto($row['IDPsto']); $c->setIDLinea($row['IDLinea']); $c->setIDArticulo($correspondencia[$row['IDArticulo']]); $c->setDescripcion($row['Descripcion']); $c->setUnidades($row['Unidades']); $c->setPrecio($row['Precio']); $c->setDescuento($row['Descuento']); $c->setImporte($row['Importe']); $c->setImporteCosto($row['ImporteCosto']); $c->setIDAlmacen(1); if ($row['Fecha'] >= '2012-09-01') { $c->setIva($this->correspondenciaIva[$row['Iva']]); } else { $c->setIva($row['Iva']); } $c->setIDAgente(2); $c->setIDComercial(2); $c->setIDEstado($row['Estado']); $c->setPrimaryKeyMD5(md5($row['IDLinea'])); if (!$c->create()) { $errores[] = $c->getErrores(); $nErrores++; } else { $nItems++; } } //mysql_close($dbLink); echo "Líneas Presupuestos {$nItems}<br/>"; if (count($errores)) { echo "<pre>"; print_r($errores); echo "</pre>"; } }