protected function private_core() { $this->ppage = $this->page->get('compras_albaranes'); $this->agente = FALSE; $albaran = new albaran_proveedor(); $this->albaran = FALSE; $this->divisa = new divisa(); $this->ejercicio = new ejercicio(); $this->fabricante = new fabricante(); $this->familia = new familia(); $this->forma_pago = new forma_pago(); $this->impuesto = new impuesto(); $this->proveedor = new proveedor(); $this->proveedor_s = FALSE; $this->serie = new serie(); /// ¿El usuario tiene permiso para eliminar en esta página? $this->allow_delete = $this->user->allow_delete_on(__CLASS__); /// comprobamos si el usuario tiene acceso a nueva_compra $this->nuevo_albaran_url = FALSE; if ($this->user->have_access_to('nueva_compra', FALSE)) { $nuevoalbp = $this->page->get('nueva_compra'); if ($nuevoalbp) { $this->nuevo_albaran_url = $nuevoalbp->url(); } } if (isset($_POST['idalbaran'])) { $this->albaran = $albaran->get($_POST['idalbaran']); $this->modificar(); } else { if (isset($_GET['id'])) { $this->albaran = $albaran->get($_GET['id']); } } if ($this->albaran) { $this->page->title = $this->albaran->codigo; /// cargamos el agente if (!is_null($this->albaran->codagente)) { $agente = new agente(); $this->agente = $agente->get($this->albaran->codagente); } /// cargamos el proveedor $this->proveedor_s = $this->proveedor->get($this->albaran->codproveedor); /// comprobamos el albarán $this->albaran->full_test(); if (isset($_GET['facturar']) and isset($_GET['petid']) and $this->albaran->ptefactura) { if ($this->duplicated_petition($_GET['petid'])) { $this->new_error_msg('Petición duplicada. Evita hacer doble clic sobre los botones.'); } else { $this->generar_factura(); } } else { if (isset($_GET['forze_fecha'])) { $this->forzar_fecha(); } } } else { $this->new_error_msg("¡" . FS_ALBARAN . " de proveedor no encontrado!"); } }
protected function process() { $this->ppage = $this->page->get('compras_albaranes'); $this->agente = FALSE; /// desactivamos la barra de botones $this->show_fs_toolbar = FALSE; $albaran = new albaran_proveedor(); $this->albaran = FALSE; $this->ejercicio = new ejercicio(); $this->familia = new familia(); $this->impuesto = new impuesto(); $this->proveedor = new proveedor(); $this->proveedor_s = FALSE; $this->serie = new serie(); /// comprobamos si el usuario tiene acceso a nueva_compra $this->nuevo_albaran_url = FALSE; if ($this->user->have_access_to('nueva_compra', FALSE)) { $nuevoalbp = $this->page->get('nueva_compra'); if ($nuevoalbp) { $this->nuevo_albaran_url = $nuevoalbp->url(); } } if (isset($_POST['idalbaran'])) { $this->albaran = $albaran->get($_POST['idalbaran']); $this->modificar(); } else { if (isset($_GET['id'])) { $this->albaran = $albaran->get($_GET['id']); } } if ($this->albaran) { $this->page->title = $this->albaran->codigo; /// cargamos el agente if (!is_null($this->albaran->codagente)) { $agente = new agente(); $this->agente = $agente->get($this->albaran->codagente); } /// cargamos el proveedor $this->proveedor_s = $this->proveedor->get($this->albaran->codproveedor); /// comprobamos el albarán if ($this->albaran->full_test()) { if (isset($_GET['facturar']) and isset($_GET['petid']) and $this->albaran->ptefactura) { if ($this->duplicated_petition($_GET['petid'])) { $this->new_error_msg('Petición duplicada. Evita hacer doble clic sobre los botones.'); } else { $this->generar_factura(); } } if (isset($_POST['actualizar_precios'])) { $this->actualizar_precios(); } } } else { $this->new_error_msg("¡" . FS_ALBARAN . " de proveedor no encontrado!"); } }
protected function process() { $this->albaran = FALSE; $this->articulo_proveedor = new articulo_proveedor(); $this->proveedor = FALSE; $this->factura = FALSE; $this->impuesto = new impuesto(); if (isset($_REQUEST['albaran']) and isset($_REQUEST['id'])) { $alb = new albaran_proveedor(); $this->albaran = $alb->get($_REQUEST['id']); if ($this->albaran) { $proveedor = new proveedor(); $this->proveedor = $proveedor->get($this->albaran->codproveedor); } if (isset($_POST['email'])) { $this->enviar_email('albaran'); } else { $this->generar_pdf_albaran(); } } else { if (isset($_REQUEST['factura']) and isset($_REQUEST['id'])) { $fac = new factura_proveedor(); $this->factura = $fac->get($_REQUEST['id']); if ($this->factura) { $proveedor = new proveedor(); $this->proveedor = $proveedor->get($this->factura->codproveedor); } $this->generar_pdf_factura(); } } $this->share_extensions(); }
protected function process() { $this->albaran = FALSE; $this->articulo_proveedor = new articulo_proveedor(); $this->proveedor = FALSE; $this->factura = FALSE; $this->impuesto = new impuesto(); $this->fecha_hoy = Date('d-m-Y'); if (isset($_REQUEST['albaran']) and isset($_REQUEST['id'])) { $alb = new albaran_proveedor(); $this->albaran = $alb->get($_REQUEST['id']); if ($this->albaran) { $proveedor = new proveedor(); $this->proveedor = $proveedor->get($this->albaran->codproveedor); } if (isset($_POST['email'])) { $this->enviar_email('albaran'); } else { $this->generar_pdf_albaran(); } } else { if (isset($_REQUEST['factura']) and isset($_REQUEST['id'])) { $fac = new factura_proveedor(); $this->factura = $fac->get($_REQUEST['id']); if ($this->factura) { $proveedor = new proveedor(); $this->proveedor = $proveedor->get($this->factura->codproveedor); } $this->generar_pdf_factura(); } else { if (isset($_REQUEST['ordenes'])) { if ($_GET['forma'] == '1') { $desde = $_GET['desde']; $hasta = $_GET['hasta']; $proveedor = $_GET['proveedor']; $codproveedor = $_GET['codproveedor']; $this->imprimir_ordenes($desde, $hasta, $proveedor, $codproveedor); } else { if (isset($_GET['forma']) == 2) { $idorden = $_GET['idorden']; $this->imprimir_ordenes_indiv($idorden); } } } else { if (isset($_REQUEST['anticipos'])) { $idanticipo = $_GET['idanticipo']; $this->imprimir_anticipo($idanticipo); } } } } $this->share_extensions(); }
protected function private_core() { $this->albaran = FALSE; $this->articulo_proveedor = new articulo_proveedor(); $this->proveedor = FALSE; $this->factura = FALSE; $this->impuesto = new impuesto(); /// obtenemos los datos de configuración de impresión $this->impresion = array('print_ref' => '1', 'print_dto' => '1', 'print_alb' => '0'); $fsvar = new fs_var(); $this->impresion = $fsvar->array_get($this->impresion, FALSE); $this->logo = FALSE; if (file_exists('tmp/' . FS_TMP_NAME . 'logo.png')) { $this->logo = 'tmp/' . FS_TMP_NAME . 'logo.png'; } else { if (file_exists('tmp/' . FS_TMP_NAME . 'logo.jpg')) { $this->logo = 'tmp/' . FS_TMP_NAME . 'logo.jpg'; } } if (isset($_REQUEST['albaran']) and isset($_REQUEST['id'])) { $alb = new albaran_proveedor(); $this->albaran = $alb->get($_REQUEST['id']); if ($this->albaran) { $proveedor = new proveedor(); $this->proveedor = $proveedor->get($this->albaran->codproveedor); } if (isset($_POST['email'])) { $this->enviar_email('albaran'); } else { $this->generar_pdf_albaran(); } } else { if (isset($_REQUEST['factura']) and isset($_REQUEST['id'])) { $fac = new factura_proveedor(); $this->factura = $fac->get($_REQUEST['id']); if ($this->factura) { $proveedor = new proveedor(); $this->proveedor = $proveedor->get($this->factura->codproveedor); } $this->generar_pdf_factura(); } } $this->share_extensions(); }
private function delete_albaran() { $alb = new albaran_proveedor(); $alb1 = $alb->get($_POST['delete']); if ($alb1) { /// ¿Actualizamos el stock de los artículos? if (isset($_POST['stock'])) { $articulo = new articulo(); foreach ($alb1->get_lineas() as $linea) { $art0 = $articulo->get($linea->referencia); if ($art0) { $art0->sum_stock($alb1->codalmacen, 0 - $linea->cantidad); $art0->save(); } } } if ($alb1->delete()) { $this->new_message(FS_ALBARAN . " " . $alb1->codigo . " borrado correctamente."); } else { $this->new_error_msg("¡Imposible borrar el " . FS_ALBARAN . "!"); } } else { $this->new_error_msg("¡" . FS_ALBARAN . " no encontrado!"); } }
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_PEDIDO . " incorrecto. Valor correcto: " . $neto); $status = FALSE; } else { if (!$this->floatcmp($this->totaliva, $iva, FS_NF0, TRUE)) { $this->new_error_msg("Valor totaliva de " . FS_PEDIDO . " incorrecto. Valor correcto: " . $iva); $status = FALSE; } else { if (!$this->floatcmp($this->totalirpf, $irpf, FS_NF0, TRUE)) { $this->new_error_msg("Valor totalirpf de " . FS_PEDIDO . " incorrecto. Valor correcto: " . $irpf); $status = FALSE; } else { if (!$this->floatcmp($this->totalrecargo, $recargo, FS_NF0, TRUE)) { $this->new_error_msg("Valor totalrecargo de " . FS_PEDIDO . " incorrecto. Valor correcto: " . $recargo); $status = FALSE; } else { if (!$this->floatcmp($this->total, $total, FS_NF0, TRUE)) { $this->new_error_msg("Valor total de " . FS_PEDIDO . " incorrecto. Valor correcto: " . $total); $status = FALSE; } } } } } if ($this->idalbaran) { $alb0 = new \albaran_proveedor(); $albaran = $alb0->get($this->idalbaran); if (!$albaran) { $this->idalbaran = NULL; $this->save(); } } return $status; }
protected function private_core() { // // $this->ppage_r = $this->page->get('compras_albaranes'); if (isset($_REQUEST['autorizar_factura'])) { $this->autorizar_factura = $_REQUEST['autorizar_factura']; } if ($this->autorizar_factura == 1) { $this->ppage = $this->page->get('compras_facturas'); } else { $this->ppage = $this->page->get('compras_albaranes'); } $this->agente = FALSE; $this->empresa = new empresa(); $albaran = new albaran_proveedor(); $this->albaran = FALSE; $this->divisa = new divisa(); $this->ejercicio = new ejercicio(); $this->fabricante = new fabricante(); $this->familia = new familia(); $this->forma_pago = new forma_pago(); $this->impuesto = new impuesto(); $this->proveedor = new proveedor(); $this->proveedor_s = FALSE; $this->serie = new serie(); $factura = new factura_proveedor(); $this->verif_factura = $factura->all_sin_anular(); $this->subcuentas = new subcuenta(); $this->view_subcuen = $this->subcuentas->subcoenta_compras($this->empresa->codejercicio); $this->view_subcuen_dev = $this->subcuentas->subcoenta_compras_credito($this->empresa->codejercicio); $this->list_subcuen = $this->subcuentas->subcoenta_compras($this->empresa->codejercicio); /// ¿El usuario tiene permiso para eliminar en esta página? $this->allow_delete = $this->user->allow_delete_on(__CLASS__); /// comprobamos si el usuario tiene acceso a nueva_compra $this->nuevo_albaran_url = FALSE; if ($this->user->have_access_to('nueva_compra', FALSE)) { $nuevoalbp = $this->page->get('nueva_compra'); if ($nuevoalbp) { $this->nuevo_albaran_url = $nuevoalbp->url(); } } if (isset($_POST['idalbaran'])) { if ($_POST['facturar'] == 'TRUE') { $this->albaran = $albaran->get($_POST['idalbaran']); $this->modificar(); $this->generar_factura(); header('Location: ' . $this->url_retorno()); } else { $this->albaran = $albaran->get($_POST['idalbaran']); $this->modificar(); } } else { if (isset($_GET['id'])) { $this->albaran = $albaran->get($_GET['id']); } } if ($this->albaran) { $this->page->title = $this->albaran->codigo; /// cargamos el agente if (!is_null($this->albaran->codagente)) { $agente = new agente(); $this->agente = $agente->get($this->albaran->codagente); } /// cargamos el proveedor $this->proveedor_s = $this->proveedor->get($this->albaran->codproveedor); $this->cai = $this->proveedor_s->cai; $this->caivence = $this->proveedor_s->caivence; /// comprobamos el albarán $this->albaran->full_test(); if (isset($_POST['facturar']) and isset($_GET['petid']) and $this->albaran->ptefactura) { if ($this->duplicated_petition($_GET['petid'])) { $this->new_error_msg('Petición duplicada. Evita hacer doble clic sobre los botones.'); } else { $this->generar_factura(); } if ($this->autorizar_factura == 1) { header('Location: ' . $this->url_retorno()); } else { header('Location: ' . $this->url_albaran()); } } else { if (isset($_GET['forze_fecha'])) { $this->forzar_fecha(); } } } else { $this->new_error_msg("¡" . FS_ALBARAN . " de proveedor no encontrado!"); } }
protected function private_core() { $this->pagado = FALSE; $this->pago = new pago(); $this->pagos = array(); $this->pendiente = 0; if (isset($_GET['delete'])) { $pago = $this->pago->get($_GET['delete']); if ($pago) { if ($pago->delete()) { $this->new_message('Pago eliminado correctamente.'); if (!is_null($pago->idfactura)) { $fact0 = new factura_proveedor(); $factura = $fact0->get($pago->idfactura); if ($factura) { if ($factura->pagada) { $factura->pagada = FALSE; $factura->save(); } } } } else { $this->new_error_msg('Error al eliminar el pago.'); } } else { $this->new_error_msg('Pago no encontrado.'); } } else { if (isset($_POST['idpago'])) { $pago = $this->pago->get($_POST['idpago']); if ($pago) { $pago->fecha = $_POST['fecha']; $pago->importe = floatval($_POST['importe']); $pago->nota = $_POST['nota']; if ($pago->save()) { $this->new_message('Pago modificado correctamente.'); } else { $this->new_error_msg('Error al modificar el pago.'); } } else { $this->new_error_msg('Pago no encontrado.'); } } else { if (isset($_POST['importe'])) { if (isset($_REQUEST['factura'])) { $this->pago->fase = 'Factura'; $this->pago->idfactura = $_REQUEST['id']; } else { if (isset($_REQUEST['albaran'])) { $this->pago->fase = ucfirst(FS_ALBARAN); $this->pago->idalbaran = $_REQUEST['id']; } else { if (isset($_REQUEST['pedido'])) { $this->pago->fase = ucfirst(FS_PEDIDO); $this->pago->idpedido = $_REQUEST['id']; } } } $this->pago->fecha = $_POST['fecha']; $this->pago->importe = floatval($_POST['importe']); $this->pago->nota = $_POST['nota']; if ($this->pago->save()) { $this->new_message('Pago guardado correctamente.'); } else { $this->new_error_msg('Error al guardar el pago.'); } } } } if (isset($_REQUEST['factura'])) { /// esto es la fase de factura $fact0 = new factura_proveedor(); $factura = $fact0->get($_REQUEST['id']); if ($factura) { /// buscamos pagos de la fase albarán /// una factura puede ser una agrupación de muchos albaranes $idalbaran = NULL; foreach ($factura->get_lineas() as $linea) { /// el idalbaran lo tienes en las lineas de la factura if ($linea->idalbaran != $idalbaran) { $idalbaran = $linea->idalbaran; $this->db->exec("UPDATE pagos SET idfactura = " . $fact0->var2str($_REQUEST['id']) . " WHERE idalbaran = " . $fact0->var2str($idalbaran) . ";"); } } $this->pagos = $this->pago->all_from_factura($_REQUEST['id']); $this->pendiente = $factura->total; foreach ($this->pagos as $i => $value) { $this->pendiente -= $value->importe; $this->pagos[$i]->pendiente = $this->pendiente; } /// si nos han pagado el total, marcamos la factura como pagada if (!$factura->pagada and abs($this->pendiente) < 0.1) { $factura->pagada = TRUE; $factura->save(); } $this->pagado = $factura->pagada; } } else { if (isset($_REQUEST['albaran'])) { /// fase de albarán $this->pagos = $this->pago->all_from_albaran($_REQUEST['id']); /** * Falta poner el idalbaran a los pagos de los pedidos que forman este * albarán. Si es que hay. * Copia esto de la fase de factura. */ $alb0 = new albaran_proveedor(); $albaran = $alb0->get($_REQUEST['id']); if ($albaran) { $this->pendiente = $albaran->total; foreach ($this->pagos as $i => $value) { $this->pendiente -= $value->importe; $this->pagos[$i]->pendiente = $this->pendiente; } if (abs($this->pendiente) < 0.1) { $this->pagado = TRUE; } } } else { if (isset($_REQUEST['pedido'])) { /// fose de pedido $this->pagos = $this->pago->all_from_pedido($_REQUEST['id']); $ped0 = new pedido_proveedor(); $pedido = $ped0->get($_REQUEST['id']); if ($pedido) { $this->pendiente = $pedido->total; foreach ($this->pagos as $i => $value) { $this->pendiente -= $value->importe; $this->pagos[$i]->pendiente = $this->pendiente; } if (abs($this->pendiente) < 0.1) { $this->pagado = TRUE; } } } } } $this->share_extensions(); }
public function delete() { if ($this->db->exec("DELETE FROM " . $this->table_name . " WHERE idpedido = " . $this->var2str($this->idpedido) . ";")) { if ($this->idalbaran) { /** * Delegamos la eliminación en la clase correspondiente, * que tendrá que hacer más cosas. */ $albaran = new albaran_proveedor(); $alb0 = $albaran->get($this->idalbaran); if ($alb0) { $alb0->delete(); } } /// modificamos el presupuesto relacionado $this->db->exec("UPDATE presupuestosprov SET idpedido = NULL, editable = TRUE WHERE idpedido = " . $this->var2str($this->idpedido) . ";"); return TRUE; } else { return FALSE; } }
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.'); } }
public function delete() { if ($this->db->exec("DELETE FROM " . $this->table_name . " WHERE idpedido = " . $this->var2str($this->idpedido) . ";")) { if ($this->idalbaran) { /** * Delegamos la eliminación en la clase correspondiente, * que tendrá que hacer más cosas. */ $albaran = new albaran_proveedor(); $alb0 = $albaran->get($this->idalbaran); if ($alb0) { $alb0->delete(); } } return TRUE; } else { return FALSE; } }