public function __construct($a = FALSE)
 {
     parent::__construct('articulosprov', 'plugins/facturacion_base/');
     if (!isset(self::$impuestos)) {
         self::$impuestos = array();
     }
     if (!isset(self::$nombres)) {
         self::$nombres = array();
     }
     if ($a) {
         $this->id = $this->intval($a['id']);
         $this->referencia = $a['referencia'];
         $this->codproveedor = $a['codproveedor'];
         $this->refproveedor = $a['refproveedor'];
         $this->descripcion = $a['descripcion'];
         /// En algunos módulos de eneboo se usa coste como precio
         if (is_null($a['precio']) and isset($a['coste'])) {
             $this->precio = floatval($a['coste']);
         } else {
             $this->precio = floatval($a['precio']);
         }
         $this->dto = floatval($a['dto']);
         $this->codimpuesto = $a['codimpuesto'];
         $this->stock = floatval($a['stock']);
         $this->nostock = $this->str2bool($a['nostock']);
         $this->codbarras = $a['codbarras'];
         $this->partnumber = $a['partnumber'];
     } else {
         $this->id = NULL;
         $this->referencia = NULL;
         $this->codproveedor = NULL;
         $this->refproveedor = NULL;
         $this->descripcion = NULL;
         $this->precio = 0;
         $this->dto = 0;
         $this->codimpuesto = NULL;
         $this->stock = 0;
         $this->nostock = TRUE;
         $this->codbarras = NULL;
         $this->partnumber = NULL;
     }
     $this->iva = NULL;
 }
Exemplo n.º 2
0
 public function get_articulo_proveedores()
 {
     $artprov = new articulo_proveedor();
     $alist = $artprov->all_from_ref($this->articulo->referencia);
     /// revismos el impuesto y la descripción
     foreach ($alist as $i => $value) {
         $guardar = FALSE;
         if (is_null($value->codimpuesto)) {
             $alist[$i]->codimpuesto = $this->articulo->codimpuesto;
             $guardar = TRUE;
         }
         if (is_null($value->descripcion)) {
             $alist[$i]->descripcion = $this->articulo->descripcion;
             $guardar = TRUE;
         }
         if ($guardar) {
             $alist[$i]->save();
         }
     }
     return $alist;
 }
Exemplo n.º 3
0
 private function actualizar_precio_proveedor($codproveedor, $linea)
 {
     if (!is_null($linea->referencia)) {
         $artp = $this->articulo_prov->get_by($linea->referencia, $codproveedor);
         if (!$artp) {
             $artp = new articulo_proveedor();
             $artp->codproveedor = $codproveedor;
             $artp->referencia = $linea->referencia;
             $artp->refproveedor = $linea->referencia;
             $artp->codimpuesto = $linea->codimpuesto;
             $artp->descripcion = $linea->descripcion;
         }
         $artp->precio = $linea->pvpunitario;
         $artp->dto = $linea->dtopor;
         $artp->save();
     }
 }
 protected function private_core()
 {
     $this->share_extensions();
     $this->documento = FALSE;
     $this->lineas = array();
     $this->tipodoc = 'Documento';
     if (isset($_REQUEST['doc']) and isset($_REQUEST['id'])) {
         if ($_REQUEST['doc'] == 'pedido') {
             $pedido0 = new pedido_proveedor();
             $this->documento = $pedido0->get($_REQUEST['id']);
             $this->tipodoc = FS_PEDIDO;
         } else {
             $albaran0 = new albaran_proveedor();
             $this->documento = $albaran0->get($_REQUEST['id']);
             $this->tipodoc = FS_ALBARAN;
         }
         if ($this->documento) {
             $this->lineas = $this->documento->get_lineas();
             $art0 = new articulo();
             $ap0 = new articulo_proveedor();
             $cambios = 0;
             foreach ($this->lineas as $i => $value) {
                 $this->lineas[$i]->refproveedor = $value->referencia;
                 $this->lineas[$i]->codbarras = '';
                 $this->lineas[$i]->precio_compra = 0;
                 $this->lineas[$i]->dto_compra = 0;
                 $this->lineas[$i]->precio_venta = 0;
                 $ap = $ap0->get_by($value->referencia, $this->documento->codproveedor);
                 if ($ap) {
                     $this->lineas[$i]->refproveedor = $ap->refproveedor;
                     $this->lineas[$i]->precio_compra = $ap->precio;
                     $this->lineas[$i]->dto_compra = $ap->dto;
                 }
                 $articulo = $art0->get($value->referencia);
                 if ($articulo) {
                     $this->lineas[$i]->codbarras = $articulo->codbarras;
                     $this->lineas[$i]->precio_venta = $articulo->pvp;
                 }
                 /// ¿Tenemos los datos del form?
                 if (isset($_POST['update_' . $value->idlinea])) {
                     /**
                      * Volvemos a buscar el artículos del proveedor, pero esta vez
                      * buscamos también con la referencia del proveedor.
                      */
                     $ap = $ap0->get_by($value->referencia, $this->documento->codproveedor, $_POST['refproveedor_' . $value->idlinea]);
                     if (!$ap) {
                         $ap = new articulo_proveedor();
                         $ap->codproveedor = $this->documento->codproveedor;
                     }
                     $ap->referencia = $value->referencia;
                     $ap->refproveedor = $_POST['refproveedor_' . $value->idlinea];
                     $this->lineas[$i]->refproveedor = $ap->refproveedor;
                     $ap->precio = floatval($_POST['coste_' . $value->idlinea]);
                     $ap->dto = floatval($_POST['dto_' . $value->idlinea]);
                     $ap->save();
                     if ($articulo) {
                         if (isset($_POST['descripciones'])) {
                             $articulo->descripcion = $_POST['descripcion_' . $value->idlinea];
                         }
                         if (isset($_POST['codbarras'])) {
                             $articulo->codbarras = $_POST['codbarras_' . $value->idlinea];
                             $this->lineas[$i]->codbarras = $articulo->codbarras;
                         }
                         if (isset($_POST['pvps'])) {
                             $articulo->set_pvp(floatval($_POST['pvp_' . $value->idlinea]));
                         }
                         /// ¿usamos la referencia de proveedor como equivalencia?
                         if ($_POST['refproveedor_' . $value->idlinea] != '' and $_POST['refproveedor_' . $value->idlinea] != $articulo->referencia) {
                             if (is_null($articulo->equivalencia)) {
                                 $articulo->equivalencia = $_POST['refproveedor_' . $value->idlinea];
                             }
                         }
                         $articulo->save();
                     }
                     $cambios++;
                 }
             }
             if ($cambios > 0) {
                 $this->new_message($cambios . ' cambios realizados.');
             }
         } else {
             $this->new_error_msg('Documento no encontrado.');
         }
     } else {
         $this->new_error_msg('Faltan datos.');
     }
 }