예제 #1
0
 public function full_test($duplicados = TRUE)
 {
     $status = TRUE;
     /// comprobamos las líneas
     $neto = 0;
     $iva = 0;
     $irpf = 0;
     $recargo = 0;
     foreach ($this->get_lineas() as $l) {
         if (!$l->test()) {
             $status = FALSE;
         }
         $neto += $l->pvptotal;
         $iva += $l->pvptotal * $l->iva / 100;
         $irpf += $l->pvptotal * $l->irpf / 100;
         $recargo += $l->pvptotal * $l->recargo / 100;
     }
     $neto = round($neto, FS_NF0);
     $iva = round($iva, FS_NF0);
     $irpf = round($irpf, FS_NF0);
     $recargo = round($recargo, FS_NF0);
     $total = $neto + $iva - $irpf + $recargo;
     if (!$this->floatcmp($this->neto, $neto, FS_NF0, TRUE)) {
         $this->new_error_msg("Valor neto de " . FS_ALBARAN . " incorrecto. Valor correcto: " . $neto);
         $status = FALSE;
     } else {
         if (!$this->floatcmp($this->totaliva, $iva, FS_NF0, TRUE)) {
             $this->new_error_msg("Valor totaliva de " . FS_ALBARAN . " incorrecto. Valor correcto: " . $iva);
             $status = FALSE;
         } else {
             if (!$this->floatcmp($this->totalirpf, $irpf, FS_NF0, TRUE)) {
                 $this->new_error_msg("Valor totalirpf de " . FS_ALBARAN . " incorrecto. Valor correcto: " . $irpf);
                 $status = FALSE;
             } else {
                 if (!$this->floatcmp($this->totalrecargo, $recargo, FS_NF0, TRUE)) {
                     $this->new_error_msg("Valor totalrecargo de " . FS_ALBARAN . " incorrecto. Valor correcto: " . $recargo);
                     $status = FALSE;
                 } else {
                     if (!$this->floatcmp($this->total, $total, FS_NF0, TRUE)) {
                         $this->new_error_msg("Valor total de " . FS_ALBARAN . " incorrecto. Valor correcto: " . $total);
                         $status = FALSE;
                     } else {
                         if (!$this->floatcmp($this->totaleuros, $this->total * $this->tasaconv, FS_NF0, TRUE)) {
                             $this->new_error_msg("Valor totaleuros de " . FS_ALBARAN . " incorrecto.\n            Valor correcto: " . round($this->total * $this->tasaconv, FS_NF0));
                             $status = FALSE;
                         }
                     }
                 }
             }
         }
     }
     if ($this->total != 0) {
         /// comprobamos las facturas asociadas
         $linea_factura = new linea_factura_cliente();
         $facturas = $linea_factura->facturas_from_albaran($this->idalbaran);
         if ($facturas) {
             if (count($facturas) > 1) {
                 $msg = "Este " . FS_ALBARAN . " esta asociado a las siguientes facturas (y no debería):";
                 foreach ($facturas as $f) {
                     $msg .= " <a href='" . $f->url() . "'>" . $f->codigo . "</a>";
                 }
                 $this->new_error_msg($msg);
                 $status = FALSE;
             } else {
                 if ($facturas[0]->idfactura != $this->idfactura) {
                     $this->new_error_msg("Este " . FS_ALBARAN . " esta asociado a una <a href='" . $this->factura_url() . "'>factura</a> incorrecta. La correcta es <a href='" . $facturas[0]->url() . "'>esta</a>.");
                     $status = FALSE;
                 }
             }
         } else {
             if (isset($this->idfactura)) {
                 $this->new_error_msg("Este " . FS_ALBARAN . " esta asociado a una <a href='" . $this->factura_url() . "'>factura</a> incorrecta.");
                 $status = FALSE;
             }
         }
     }
     if ($status and $duplicados) {
         /// comprobamos si es un duplicado
         $albaranes = $this->db->select("SELECT * FROM " . $this->table_name . " WHERE fecha = " . $this->var2str($this->fecha) . "\n            AND codcliente = " . $this->var2str($this->codcliente) . " AND total = " . $this->var2str($this->total) . "\n            AND codagente = " . $this->var2str($this->codagente) . " AND numero2 = " . $this->var2str($this->numero2) . "\n            AND observaciones = " . $this->var2str($this->observaciones) . " AND idalbaran != " . $this->var2str($this->idalbaran) . ";");
         if ($albaranes) {
             foreach ($albaranes as $alb) {
                 /// comprobamos las líneas
                 $aux = $this->db->select("SELECT referencia FROM lineasalbaranescli WHERE\n                  idalbaran = " . $this->var2str($this->idalbaran) . "\n                  AND referencia NOT IN (SELECT referencia FROM lineasalbaranescli\n                  WHERE idalbaran = " . $this->var2str($alb['idalbaran']) . ");");
                 if (!$aux) {
                     $this->new_error_msg("Este " . FS_ALBARAN . " es un posible duplicado de\n                     <a href='index.php?page=ventas_albaran&id=" . $alb['idalbaran'] . "'>este otro</a>.\n                     Si no lo es, para evitar este mensaje, simplemente modifica las observaciones.");
                     $status = FALSE;
                 }
             }
         }
     }
     return $status;
 }