Exemplo n.º 1
0
 public function FemitidasLineas()
 {
     $nItems = 0;
     $nErrores = 0;
     $dbLink = mysql_connect("localhost", "root", "albatronic");
     $query = "TRUNCATE {$this->dbDestino}.ErpFemitidasLineas";
     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 c.Fecha, l.* from {$this->dbOrigen}.femitidas_cab as c LEFT JOIN {$this->dbOrigen}.femitidas_lineas as l ON c.IDFactura=l.IDFactura where l.IDFactura>0";
     $result = mysql_query($query, $dbLink);
     while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
         $c = new FemitidasLineas();
         $c->setIDFactura($row['IDFactura']);
         $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->setIDAlbaran($row['IDAlbaran']);
         if ($row['Fecha'] >= '2012-09-01') {
             $c->setIva($this->correspondenciaIva[$row['Iva']]);
         } else {
             $c->setIva($row['Iva']);
         }
         $c->setIDAgente(2);
         $c->setIDComercial(2);
         $c->setPrimaryKeyMD5(md5($row['IDLinea']));
         if (!$c->create()) {
             $errores[] = $c->getErrores();
             $nErrores++;
         } else {
             $nItems++;
         }
     }
     //mysql_close($dbLink);
     echo "Líneas Factura emitidas {$nItems}<br/>";
     if (count($errores)) {
         echo "<pre>";
         print_r($errores);
         echo "</pre>";
     }
 }