Example #1
0
 public function __construct(&$db)
 {
     $alb_cli = new albaran_cliente();
     echo "Ejecutando tareas para los " . FS_ALBARANES . " de cliente...\n";
     $alb_cli->cron_job();
     $alb_pro = new albaran_proveedor();
     echo "Ejecutando tareas para los " . FS_ALBARANES . " de proveedor...\n";
     $alb_pro->cron_job();
     $articulo = new articulo();
     echo "Ejecutando tareas para los artículos...";
     $articulo->cron_job();
     $asiento = new asiento();
     echo "\nEjecutando tareas para los asientos...\n";
     $asiento->cron_job();
     if (FS_LIBROS_CONTABLES) {
         $libro = new libro_mayor();
         echo "Generamos el libro mayor para cada subcuenta y el libro diario para cada ejercicio...";
         $libro->cron_job();
         $inventarios_balances = new inventarios_balances();
         echo "\nGeneramos el libro de inventarios y balances para cada ejercicio...";
         $inventarios_balances->cron_job();
     } else {
         $libro = new libro_mayor();
         echo "Comprobamos algunas subcuentas...";
         $libro->cron_job();
     }
 }
 protected function process()
 {
     $this->show_fs_toolbar = FALSE;
     $this->cliente = new cliente();
     $this->ejercicio = new ejercicio();
     $this->proveedor = new proveedor();
     $this->regularizacion = new regularizacion_iva();
     $this->opciones = array('ventas' => TRUE, 'compras' => TRUE, 'fecha' => 'hoy');
     if (isset($_REQUEST['fecha'])) {
         $this->opciones['fecha'] = $_REQUEST['fecha'];
         $this->total = 0;
         if (isset($_REQUEST['ventas'])) {
             $albaran_cli = new albaran_cliente();
             foreach ($albaran_cli->all_ptefactura(0, 'ASC') as $alb) {
                 $this->generar_factura_cliente(array($alb));
             }
             $this->new_message($this->total . ' ' . FS_ALBARANES . ' de cliente facturados.');
         } else {
             $this->opciones['ventas'] = FALSE;
         }
         $this->total = 0;
         if (isset($_REQUEST['compras'])) {
             $albaran_pro = new albaran_proveedor();
             foreach ($albaran_pro->all_ptefactura(0, 'ASC') as $alb) {
                 $this->generar_factura_proveedor(array($alb));
             }
             $this->new_message($this->total . ' ' . FS_ALBARANES . ' de proveedor facturados.');
         } else {
             $this->opciones['compras'] = FALSE;
         }
     }
 }
Example #3
0
 protected function process()
 {
     /// declaramos los objetos sólo para asegurarnos de que existen las tablas
     $albaran_cli = new albaran_cliente();
     $albaran_pro = new albaran_proveedor();
     $this->mostrar = 'stats';
     if (isset($_REQUEST['mostrar'])) {
         $this->mostrar = $_REQUEST['mostrar'];
     }
     $this->tipo = 'ventas';
     if (isset($_REQUEST['tipo'])) {
         $this->tipo = $_REQUEST['tipo'];
     }
     if ($this->mostrar == 'listado') {
         $this->desde = Date('1-m-Y');
         $this->hasta = Date('d-m-Y', mktime(0, 0, 0, date("m") + 1, date("1") - 1, date("Y")));
         if (isset($_POST['desde'])) {
             $this->desde = $_POST['desde'];
             $this->hasta = $_POST['hasta'];
         }
         if ($this->tipo == 'ventas') {
             $this->resultados = $albaran_cli->all_desde($this->desde, $this->hasta);
         } else {
             $this->resultados = $albaran_pro->all_desde($this->desde, $this->hasta);
         }
     }
 }
Example #4
0
 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 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();
     $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();
 }
 protected function private_core()
 {
     $this->cliente = new cliente();
     $this->ejercicio = new ejercicio();
     $this->forma_pago = new forma_pago();
     $this->proveedor = new proveedor();
     $this->regularizacion = new regularizacion_iva();
     $serie = new serie();
     $this->series = $serie->all();
     $this->opciones = array('ventas' => TRUE, 'compras' => TRUE, 'fecha' => 'hoy');
     $this->codserie = FALSE;
     if (isset($_REQUEST['codserie'])) {
         $this->codserie = $_REQUEST['codserie'];
     }
     if (isset($_REQUEST['fecha'])) {
         $this->opciones['fecha'] = $_REQUEST['fecha'];
         $this->total = 0;
         if (isset($_REQUEST['ventas'])) {
             $albaran_cli = new albaran_cliente();
             foreach ($albaran_cli->all_ptefactura(0, 'fecha ASC', $this->codserie) as $alb) {
                 $this->generar_factura_cliente(array($alb));
             }
             $this->new_message($this->total . ' ' . FS_ALBARANES . ' de cliente facturados.');
         } else {
             $this->opciones['ventas'] = FALSE;
         }
         $this->total = 0;
         if (isset($_REQUEST['compras'])) {
             $albaran_pro = new albaran_proveedor();
             foreach ($albaran_pro->all_ptefactura(0, 'fecha ASC', $this->codserie) as $alb) {
                 $this->generar_factura_proveedor(array($alb));
             }
             $this->new_message($this->total . ' ' . FS_ALBARANES . ' de proveedor facturados.');
         } else {
             $this->opciones['compras'] = FALSE;
         }
     }
 }
 protected function process()
 {
     $albaran = new albaran_proveedor();
     /// desactivamos la barra de botones
     $this->show_fs_toolbar = FALSE;
     $this->offset = 0;
     if (isset($_GET['offset'])) {
         $this->offset = intval($_GET['offset']);
     }
     if (isset($_POST['buscar_lineas'])) {
         $this->buscar_lineas();
     } else {
         if (isset($_GET['codagente'])) {
             $this->template = 'extension/compras_albaranes_agente';
             $agente = new agente();
             $this->agente = $agente->get($_GET['codagente']);
             $this->resultados = $albaran->all_from_agente($_GET['codagente'], $this->offset);
         } else {
             if (isset($_GET['codproveedor'])) {
                 $this->template = 'extension/compras_albaranes_proveedor';
                 $proveedor = new proveedor();
                 $this->proveedor = $proveedor->get($_GET['codproveedor']);
                 $this->resultados = $albaran->all_from_proveedor($_GET['codproveedor'], $this->offset);
             } else {
                 if (isset($_GET['ref'])) {
                     $this->template = 'extension/compras_albaranes_articulo';
                     $articulo = new articulo();
                     $this->articulo = $articulo->get($_GET['ref']);
                     $linea = new linea_albaran_proveedor();
                     $this->resultados = $linea->all_from_articulo($_GET['ref'], $this->offset);
                 } else {
                     $this->share_extension();
                     if (isset($_POST['delete'])) {
                         $this->delete_albaran();
                     }
                     if ($this->query != '') {
                         $this->resultados = $albaran->search($this->query, $this->offset);
                     } else {
                         if (isset($_GET['ptefactura'])) {
                             $this->resultados = $albaran->all_ptefactura($this->offset);
                         } else {
                             $this->resultados = $albaran->all($this->offset);
                         }
                     }
                 }
             }
         }
     }
 }
 private function test_models()
 {
     $last_errores = array();
     switch ($this->informe['model']) {
         default:
             /// tablas
             $this->test_tablas();
             break;
         case 'asiento':
             $asiento = new asiento();
             $asientos = $asiento->all($this->informe['offset']);
             if ($asientos) {
                 if ($this->informe['offset'] == 0) {
                     foreach ($this->check_partidas_erroneas() as $err) {
                         $last_errores[] = $err;
                     }
                 }
                 foreach ($asientos as $asi) {
                     if ($asi->codejercicio == $this->informe['ejercicio']) {
                         if ($this->informe['all']) {
                             $this->informe['model'] = 'factura cliente';
                         } else {
                             $this->informe['model'] = 'fin';
                         }
                         $this->informe['offset'] = 0;
                         break;
                     } else {
                         if (!$asi->full_test($this->informe['duplicados'])) {
                             $last_errores[] = array('error' => 'Fallo en full_test()', 'model' => $this->informe['model'], 'ejercicio' => $asi->codejercicio, 'id' => $asi->numero, 'url' => $asi->url(), 'fecha' => $asi->fecha, 'fix' => $asi->fix());
                         }
                     }
                 }
                 $this->informe['offset'] += FS_ITEM_LIMIT;
             } else {
                 if ($this->informe['all']) {
                     $this->informe['model'] = 'factura cliente';
                     $this->informe['offset'] = 0;
                 } else {
                     $this->informe['model'] = 'fin';
                     $this->informe['offset'] = 0;
                 }
             }
             break;
         case 'factura cliente':
             $factura = new factura_cliente();
             $facturas = $factura->all($this->informe['offset']);
             if ($facturas) {
                 foreach ($facturas as $fac) {
                     if ($fac->codejercicio == $this->informe['ejercicio']) {
                         if ($this->informe['all']) {
                             $this->informe['model'] = 'factura proveedor';
                         } else {
                             $this->informe['model'] = 'fin';
                         }
                         $this->informe['offset'] = 0;
                         break;
                     } else {
                         if (!$fac->full_test($this->informe['duplicados'])) {
                             $last_errores[] = array('error' => 'Fallo en full_test()', 'model' => $this->informe['model'], 'ejercicio' => $fac->codejercicio, 'id' => $fac->codigo, 'url' => $fac->url(), 'fecha' => $fac->fecha, 'fix' => FALSE);
                         }
                     }
                 }
                 $this->informe['offset'] += FS_ITEM_LIMIT;
             } else {
                 if ($this->informe['all']) {
                     $this->informe['model'] = 'factura proveedor';
                     $this->informe['offset'] = 0;
                 } else {
                     $this->informe['model'] = 'fin';
                     $this->informe['offset'] = 0;
                 }
             }
             break;
         case 'factura proveedor':
             $factura = new factura_proveedor();
             $facturas = $factura->all($this->informe['offset']);
             if ($facturas) {
                 foreach ($facturas as $fac) {
                     if ($fac->codejercicio == $this->informe['ejercicio']) {
                         if ($this->informe['all']) {
                             $this->informe['model'] = 'albaran cliente';
                         } else {
                             $this->informe['model'] = 'fin';
                         }
                         $this->informe['offset'] = 0;
                         break;
                     } else {
                         if (!$fac->full_test($this->informe['duplicados'])) {
                             $last_errores[] = array('error' => 'Fallo en full_test()', 'model' => $this->informe['model'], 'ejercicio' => $fac->codejercicio, 'id' => $fac->codigo, 'url' => $fac->url(), 'fecha' => $fac->fecha, 'fix' => FALSE);
                         }
                     }
                 }
                 $this->informe['offset'] += FS_ITEM_LIMIT;
             } else {
                 if ($this->informe['all']) {
                     $this->informe['model'] = 'albaran cliente';
                     $this->informe['offset'] = 0;
                 } else {
                     $this->informe['model'] = 'fin';
                     $this->informe['offset'] = 0;
                 }
             }
             break;
         case 'albaran cliente':
             $albaran = new albaran_cliente();
             $albaranes = $albaran->all($this->informe['offset']);
             if ($albaranes) {
                 foreach ($albaranes as $alb) {
                     if ($alb->codejercicio == $this->informe['ejercicio']) {
                         if ($this->informe['all']) {
                             $this->informe['model'] = 'albaran proveedor';
                         } else {
                             $this->informe['model'] = 'fin';
                         }
                         $this->informe['offset'] = 0;
                         break;
                     } else {
                         if (!$alb->full_test($this->informe['duplicados'])) {
                             $last_errores[] = array('error' => 'Fallo en full_test()', 'model' => $this->informe['model'], 'ejercicio' => $alb->codejercicio, 'id' => $alb->codigo, 'url' => $alb->url(), 'fecha' => $alb->fecha, 'fix' => FALSE);
                         }
                     }
                 }
                 $this->informe['offset'] += FS_ITEM_LIMIT;
             } else {
                 if ($this->informe['all']) {
                     $this->informe['model'] = 'albaran proveedor';
                     $this->informe['offset'] = 0;
                 } else {
                     $this->informe['model'] = 'fin';
                     $this->informe['offset'] = 0;
                 }
             }
             break;
         case 'albaran proveedor':
             $albaran = new albaran_proveedor();
             $albaranes = $albaran->all($this->informe['offset']);
             if ($albaranes) {
                 foreach ($albaranes as $alb) {
                     if ($alb->codejercicio == $this->informe['ejercicio']) {
                         $this->informe['model'] = 'fin';
                         $this->informe['offset'] = 0;
                         break;
                     } else {
                         if (!$alb->full_test($this->informe['duplicados'])) {
                             $last_errores[] = array('error' => 'Fallo en full_test()', 'model' => $this->informe['model'], 'ejercicio' => $alb->codejercicio, 'id' => $alb->codigo, 'url' => $alb->url(), 'fecha' => $alb->fecha, 'fix' => FALSE);
                         }
                     }
                 }
                 $this->informe['offset'] += FS_ITEM_LIMIT;
             } else {
                 $this->informe['model'] = 'dirclientes';
                 $this->informe['offset'] = 0;
             }
             break;
         case 'dirclientes':
             $dircli0 = new direccion_cliente();
             $direcciones = $dircli0->all($this->informe['offset']);
             if ($direcciones) {
                 foreach ($direcciones as $dir) {
                     /// simplemente guardamos para que se eliminen espacios de ciudades, provincias, etc...
                     $dir->save();
                 }
                 $this->informe['offset'] += FS_ITEM_LIMIT;
             } else {
                 $this->informe['model'] = 'fin';
                 $this->informe['offset'] = 0;
             }
             break;
         case 'fin':
             break;
     }
     return $last_errores;
 }
Example #12
0
 private function test_models()
 {
     $mpp = 100;
     $last_errores = array();
     switch ($this->informe['model']) {
         default:
             /// tablas
             $this->test_tablas();
             break;
         case 'asiento':
             $asiento = new asiento();
             $asientos = $asiento->all($this->informe['offset'], $mpp);
             if ($asientos) {
                 if ($this->informe['offset'] == 0) {
                     foreach ($this->check_partidas_erroneas() as $err) {
                         $last_errores[] = $err;
                     }
                 }
                 foreach ($asientos as $asi) {
                     if ($asi->codejercicio == $this->informe['ejercicio']) {
                         if ($this->informe['all']) {
                             $this->informe['model'] = 'factura cliente';
                         } else {
                             $this->informe['model'] = 'fin';
                         }
                         $this->informe['offset'] = 0;
                         break;
                     } else {
                         if (!$asi->full_test($this->informe['duplicados'])) {
                             $last_errores[] = array('error' => 'Fallo en full_test()', 'model' => $this->informe['model'], 'ejercicio' => $asi->codejercicio, 'id' => $asi->numero, 'url' => $asi->url(), 'fecha' => $asi->fecha, 'fix' => $asi->fix());
                         }
                     }
                 }
                 $this->informe['offset'] += $mpp;
             } else {
                 if ($this->informe['all']) {
                     $this->informe['model'] = 'factura cliente';
                     $this->informe['offset'] = 0;
                 } else {
                     $this->informe['model'] = 'fin';
                     $this->informe['offset'] = 0;
                 }
             }
             break;
         case 'factura cliente':
             $factura = new factura_cliente();
             $facturas = $factura->all($this->informe['offset'], $mpp);
             if ($facturas) {
                 foreach ($facturas as $fac) {
                     if ($fac->codejercicio == $this->informe['ejercicio']) {
                         if ($this->informe['all']) {
                             $this->informe['model'] = 'factura proveedor';
                         } else {
                             $this->informe['model'] = 'fin';
                         }
                         $this->informe['offset'] = 0;
                         break;
                     } else {
                         if (!$fac->full_test($this->informe['duplicados'])) {
                             $last_errores[] = array('error' => 'Fallo en full_test()', 'model' => $this->informe['model'], 'ejercicio' => $fac->codejercicio, 'id' => $fac->codigo, 'url' => $fac->url(), 'fecha' => $fac->fecha, 'fix' => FALSE);
                         }
                     }
                 }
                 $this->informe['offset'] += $mpp;
             } else {
                 if ($this->informe['all']) {
                     $this->informe['model'] = 'factura proveedor';
                     $this->informe['offset'] = 0;
                 } else {
                     $this->informe['model'] = 'fin';
                     $this->informe['offset'] = 0;
                 }
             }
             break;
         case 'factura proveedor':
             $factura = new factura_proveedor();
             $facturas = $factura->all($this->informe['offset'], $mpp);
             if ($facturas) {
                 foreach ($facturas as $fac) {
                     if ($fac->codejercicio == $this->informe['ejercicio']) {
                         if ($this->informe['all']) {
                             $this->informe['model'] = 'albaran cliente';
                         } else {
                             $this->informe['model'] = 'fin';
                         }
                         $this->informe['offset'] = 0;
                         break;
                     } else {
                         if (!$fac->full_test($this->informe['duplicados'])) {
                             $last_errores[] = array('error' => 'Fallo en full_test()', 'model' => $this->informe['model'], 'ejercicio' => $fac->codejercicio, 'id' => $fac->codigo, 'url' => $fac->url(), 'fecha' => $fac->fecha, 'fix' => FALSE);
                         }
                     }
                 }
                 $this->informe['offset'] += $mpp;
             } else {
                 if ($this->informe['all']) {
                     $this->informe['model'] = 'albaran cliente';
                     $this->informe['offset'] = 0;
                 } else {
                     $this->informe['model'] = 'fin';
                     $this->informe['offset'] = 0;
                 }
             }
             break;
         case 'albaran cliente':
             $albaran = new albaran_cliente();
             $albaranes = $albaran->all($this->informe['offset'], $mpp);
             if ($albaranes) {
                 foreach ($albaranes as $alb) {
                     if ($alb->codejercicio == $this->informe['ejercicio']) {
                         if ($this->informe['all']) {
                             $this->informe['model'] = 'albaran proveedor';
                         } else {
                             $this->informe['model'] = 'fin';
                         }
                         $this->informe['offset'] = 0;
                         break;
                     } else {
                         if (!$alb->full_test($this->informe['duplicados'])) {
                             $last_errores[] = array('error' => 'Fallo en full_test()', 'model' => $this->informe['model'], 'ejercicio' => $alb->codejercicio, 'id' => $alb->codigo, 'url' => $alb->url(), 'fecha' => $alb->fecha, 'fix' => FALSE);
                         }
                     }
                 }
                 $this->informe['offset'] += $mpp;
             } else {
                 if ($this->informe['all']) {
                     $this->informe['model'] = 'albaran proveedor';
                     $this->informe['offset'] = 0;
                 } else {
                     $this->informe['model'] = 'fin';
                     $this->informe['offset'] = 0;
                 }
             }
             break;
         case 'albaran proveedor':
             $albaran = new albaran_proveedor();
             $albaranes = $albaran->all($this->informe['offset'], $mpp);
             if ($albaranes) {
                 foreach ($albaranes as $alb) {
                     if ($alb->codejercicio == $this->informe['ejercicio']) {
                         $this->informe['model'] = 'fin';
                         $this->informe['offset'] = 0;
                         break;
                     } else {
                         if (!$alb->full_test($this->informe['duplicados'])) {
                             $last_errores[] = array('error' => 'Fallo en full_test()', 'model' => $this->informe['model'], 'ejercicio' => $alb->codejercicio, 'id' => $alb->codigo, 'url' => $alb->url(), 'fecha' => $alb->fecha, 'fix' => FALSE);
                         }
                     }
                 }
                 $this->informe['offset'] += $mpp;
             } else {
                 $this->informe['model'] = 'fin';
                 $this->informe['offset'] = 0;
             }
             break;
         case 'fin':
             break;
     }
     return $last_errores;
 }
Example #13
0
 private function nuevo_albaran_proveedor()
 {
     $continuar = TRUE;
     $proveedor = $this->proveedor->get($_POST['proveedor']);
     if (!$proveedor) {
         $this->new_error_msg('Proveedor no encontrado.');
         $continuar = FALSE;
     }
     $almacen = $this->almacen->get($_POST['almacen']);
     if ($almacen) {
         $this->save_codalmacen($_POST['almacen']);
     } else {
         $this->new_error_msg('Almacén no encontrado.');
         $continuar = FALSE;
     }
     $eje0 = new ejercicio();
     $ejercicio = $eje0->get_by_fecha($_POST['fecha'], FALSE);
     if (!$ejercicio) {
         $this->new_error_msg('Ejercicio no encontrado.');
         $continuar = FALSE;
     }
     $serie = $this->serie->get($_POST['serie']);
     if (!$serie) {
         $this->new_error_msg('Serie no encontrada.');
         $continuar = FALSE;
     }
     $forma_pago = $this->forma_pago->get($_POST['forma_pago']);
     if ($forma_pago) {
         $this->save_codpago($_POST['forma_pago']);
     } else {
         $this->new_error_msg('Forma de pago no encontrada.');
         $continuar = FALSE;
     }
     $divisa = $this->divisa->get($_POST['divisa']);
     if (!$divisa) {
         $this->new_error_msg('Divisa no encontrada.');
         $continuar = FALSE;
     }
     $albaran = new albaran_proveedor();
     if ($this->duplicated_petition($_POST['petition_id'])) {
         $this->new_error_msg('Petición duplicada. Has hecho doble clic sobre el botón guardar
            y se han enviado dos peticiones. Mira en <a href="' . $albaran->url() . '">' . FS_ALBARANES . '</a>
            para ver si el ' . FS_ALBARAN . ' se ha guardado correctamente.');
         $continuar = FALSE;
     }
     if ($continuar) {
         $albaran->fecha = $_POST['fecha'];
         $albaran->hora = $_POST['hora'];
         $albaran->codproveedor = $proveedor->codproveedor;
         $albaran->nombre = $_POST['nombre'];
         $albaran->cifnif = $_POST['cifnif'];
         $albaran->codalmacen = $almacen->codalmacen;
         $albaran->codejercicio = $ejercicio->codejercicio;
         $albaran->codserie = $serie->codserie;
         $albaran->codpago = $forma_pago->codpago;
         $albaran->coddivisa = $divisa->coddivisa;
         $albaran->tasaconv = $divisa->tasaconv_compra;
         if ($_POST['tasaconv'] != '') {
             $albaran->tasaconv = floatval($_POST['tasaconv']);
         }
         $albaran->codagente = $this->agente->codagente;
         $albaran->numproveedor = $_POST['numproveedor'];
         $albaran->observaciones = $_POST['observaciones'];
         if ($albaran->save()) {
             $art0 = new articulo();
             $n = floatval($_POST['numlineas']);
             for ($i = 0; $i < $n; $i++) {
                 if (isset($_POST['referencia_' . $i])) {
                     $linea = new linea_albaran_proveedor();
                     $linea->idalbaran = $albaran->idalbaran;
                     $linea->descripcion = $_POST['desc_' . $i];
                     if (!$serie->siniva and $proveedor->regimeniva != 'Exento') {
                         $imp0 = $this->impuesto->get_by_iva($_POST['iva_' . $i]);
                         if ($imp0) {
                             $linea->codimpuesto = $imp0->codimpuesto;
                             $linea->iva = floatval($_POST['iva_' . $i]);
                             $linea->recargo = floatval($_POST['recargo_' . $i]);
                         } else {
                             $linea->iva = floatval($_POST['iva_' . $i]);
                             $linea->recargo = floatval($_POST['recargo_' . $i]);
                         }
                     }
                     $linea->irpf = floatval($_POST['irpf_' . $i]);
                     $linea->pvpunitario = floatval($_POST['pvp_' . $i]);
                     $linea->cantidad = floatval($_POST['cantidad_' . $i]);
                     $linea->dtopor = floatval($_POST['dto_' . $i]);
                     $linea->pvpsindto = $linea->pvpunitario * $linea->cantidad;
                     $linea->pvptotal = floatval($_POST['neto_' . $i]);
                     $articulo = $art0->get($_POST['referencia_' . $i]);
                     if ($articulo) {
                         $linea->referencia = $articulo->referencia;
                     }
                     if ($linea->save()) {
                         if ($articulo) {
                             if (isset($_POST['stock'])) {
                                 $articulo->sum_stock($albaran->codalmacen, $linea->cantidad, isset($_POST['costemedio']));
                             } else {
                                 if (isset($_POST['costemedio'])) {
                                     $articulo->stockfis += $linea->cantidad;
                                     $articulo->costemedio = $articulo->get_costemedio();
                                     $articulo->stockfis -= $linea->cantidad;
                                     $articulo->save();
                                 }
                             }
                             if (isset($_POST['costemedio'])) {
                                 $this->actualizar_precio_proveedor($albaran->codproveedor, $linea);
                             }
                         }
                         $albaran->neto += $linea->pvptotal;
                         $albaran->totaliva += $linea->pvptotal * $linea->iva / 100;
                         $albaran->totalirpf += $linea->pvptotal * $linea->irpf / 100;
                         $albaran->totalrecargo += $linea->pvptotal * $linea->recargo / 100;
                         if ($linea->irpf > $albaran->irpf) {
                             $albaran->irpf = $linea->irpf;
                         }
                     } else {
                         $this->new_error_msg("¡Imposible guardar la linea con referencia: " . $linea->referencia);
                         $continuar = FALSE;
                     }
                 }
             }
             if ($continuar) {
                 /// redondeamos
                 $albaran->neto = round($albaran->neto, FS_NF0);
                 $albaran->totaliva = round($albaran->totaliva, FS_NF0);
                 $albaran->totalirpf = round($albaran->totalirpf, FS_NF0);
                 $albaran->totalrecargo = round($albaran->totalrecargo, FS_NF0);
                 $albaran->total = $albaran->neto + $albaran->totaliva - $albaran->totalirpf + $albaran->totalrecargo;
                 if (abs(floatval($_POST['atotal']) - $albaran->total) >= 0.02) {
                     $this->new_error_msg("El total difiere entre la vista y el controlador (" . $_POST['atotal'] . " frente a " . $albaran->total . "). Debes informar del error.");
                     $albaran->delete();
                 } else {
                     if ($albaran->save()) {
                         $this->new_message("<a href='" . $albaran->url() . "'>" . ucfirst(FS_ALBARAN) . "</a> guardado correctamente.");
                         $this->new_change(ucfirst(FS_ALBARAN) . ' Proveedor ' . $albaran->codigo, $albaran->url(), TRUE);
                         if ($_POST['redir'] == 'TRUE') {
                             header('Location: ' . $albaran->url());
                         }
                     } else {
                         $this->new_error_msg("¡Imposible actualizar el <a href='" . $albaran->url() . "'>" . FS_ALBARAN . "</a>!");
                     }
                 }
             } else {
                 if ($albaran->delete()) {
                     $this->new_message(FS_ALBARAN . " eliminado correctamente.");
                 } else {
                     $this->new_error_msg("¡Imposible eliminar el <a href='" . $albaran->url() . "'>" . FS_ALBARAN . "</a>!");
                 }
             }
         } else {
             $this->new_error_msg("¡Imposible guardar el " . FS_ALBARAN . "!");
         }
     }
 }
 private function agrupar_pedidos()
 {
     $continuar = TRUE;
     $albaran = new albaran_proveedor();
     $albaran_rellenado = FALSE;
     $art0 = new articulo();
     $num = 0;
     foreach ($this->resultados as $ped) {
         foreach ($ped->get_lineas() as $lin) {
             if (!isset($_POST['idl_' . $num]) or !$continuar) {
             } else {
                 if ($lin->idlinea == intval($_POST['idl_' . $num])) {
                     if (!$albaran_rellenado) {
                         $albaran->codagente = $this->user->codagente;
                         $albaran->codalmacen = $ped->codalmacen;
                         $albaran->coddivisa = $ped->coddivisa;
                         $albaran->tasaconv = $ped->tasaconv;
                         $albaran->codejercicio = $ped->codejercicio;
                         $albaran->codpago = $ped->codpago;
                         $albaran->codserie = $ped->codserie;
                         $albaran->irpf = $ped->irpf;
                         $albaran->nombre = $this->proveedor->nombre;
                         if (!$albaran->save()) {
                             $continuar = FALSE;
                             $this->new_error_msg('Error al agrupar el pedido.');
                         }
                         $albaran_rellenado = TRUE;
                     }
                     $linea = new linea_albaran_proveedor();
                     $linea->idalbaran = $albaran->idalbaran;
                     $linea->idpedido = $ped->idpedido;
                     $linea->idlineapedido = $lin->idlinea;
                     $linea->referencia = $lin->referencia;
                     $linea->descripcion = $lin->descripcion;
                     $linea->cantidad = floatval($_POST['cantidad_' . $num]);
                     $linea->pvpunitario = $lin->pvpunitario;
                     $linea->codimpuesto = $lin->codimpuesto;
                     $linea->dtopor = $lin->dtopor;
                     $linea->irpf = $lin->irpf;
                     $linea->iva = $lin->iva;
                     $linea->recargo = $lin->recargo;
                     $linea->pvpsindto = $linea->pvpunitario * $linea->cantidad;
                     $linea->pvptotal = $linea->pvpunitario * $linea->cantidad * (100 - $linea->dtopor) / 100;
                     if ($linea->save()) {
                         /// añadimos al stock
                         $articulo = $art0->get($linea->referencia);
                         if ($articulo) {
                             $articulo->sum_stock($albaran->codalmacen, $linea->cantidad, TRUE);
                         }
                         $albaran->neto += $linea->pvptotal;
                         $albaran->totaliva += $linea->pvptotal * $linea->iva / 100;
                         $albaran->totalirpf += $linea->pvptotal * $linea->irpf / 100;
                         $albaran->totalrecargo += $linea->pvptotal * $linea->recargo / 100;
                     } else {
                         $this->new_error_msg("¡Imposible guardar la linea con referencia: " . $linea->referencia);
                         $continuar = FALSE;
                     }
                 }
             }
             $num++;
         }
         if (isset($_POST['aprobado'])) {
             if (in_array($ped->idpedido, $_POST['aprobado'])) {
                 $ped->editable = FALSE;
                 $ped->idalbaran = $albaran->idalbaran;
                 $ped->save();
             }
         }
     }
     if ($continuar) {
         /// redondeamos
         $albaran->neto = round($albaran->neto, FS_NF0);
         $albaran->totaliva = round($albaran->totaliva, FS_NF0);
         $albaran->totalirpf = round($albaran->totalirpf, FS_NF0);
         $albaran->totalrecargo = round($albaran->totalrecargo, FS_NF0);
         $albaran->total = $albaran->neto + $albaran->totaliva - $albaran->totalirpf + $albaran->totalrecargo;
         if ($albaran->save()) {
             $this->new_message('<a href="' . $albaran->url() . '">' . ucfirst(FS_ALBARAN) . '</a> generado correctamente.');
         } else {
             $this->new_error_msg('Error al generar el ' . FS_ALBARAN);
             $albaran->delete();
         }
     } else {
         if (!is_null($albaran->idalbaran)) {
             $albaran->delete();
         }
     }
 }
 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();
             }
         }
         /// 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;
     }
 }
 $cron_vars['cron_exists'] = 'TRUE';
 /// guardamos las variables
 $fsvar->array_save($cron_vars);
 /// establecemos los elementos por defecto
 $fs_default_items = new fs_default_items();
 $empresa = new empresa();
 $fs_default_items->set_codalmacen($empresa->codalmacen);
 $fs_default_items->set_coddivisa($empresa->coddivisa);
 $fs_default_items->set_codejercicio($empresa->codejercicio);
 $fs_default_items->set_codpago($empresa->codpago);
 $fs_default_items->set_codpais($empresa->codpais);
 $fs_default_items->set_codserie($empresa->codserie);
 $alb_cli = new albaran_cliente();
 echo "Ejecutando tareas para los " . FS_ALBARANES . " de cliente...\n";
 $alb_cli->cron_job();
 $alb_pro = new albaran_proveedor();
 echo "Ejecutando tareas para los " . FS_ALBARANES . " de proveedor...\n";
 $alb_pro->cron_job();
 $articulo = new articulo();
 echo "Ejecutando tareas para los artículos...";
 $articulo->cron_job();
 $asiento = new asiento();
 echo "\nEjecutando tareas para los asientos...\n";
 $asiento->cron_job();
 $libro = new libro_mayor();
 echo "Generamos el libro mayor para cada subcuenta y el libro diario para cada ejercicio...";
 $libro->cron_job();
 $inventarios_balances = new inventarios_balances();
 echo "\nGeneramos el libro de inventarios y balances para cada ejercicio...";
 $inventarios_balances->cron_job();
 /*
 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!");
     }
 }
Example #19
0
 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();
 }
Example #20
0
 private function generar_albaran()
 {
     $albaran = new albaran_proveedor();
     $albaran->cifnif = $this->pedido->cifnif;
     $albaran->codagente = $this->pedido->codagente;
     $albaran->codalmacen = $this->pedido->codalmacen;
     $albaran->codproveedor = $this->pedido->codproveedor;
     $albaran->coddivisa = $this->pedido->coddivisa;
     $albaran->tasaconv = $this->pedido->tasaconv;
     $albaran->codpago = $this->pedido->codpago;
     $albaran->codserie = $this->pedido->codserie;
     $albaran->neto = $this->pedido->neto;
     $albaran->nombre = $this->pedido->nombre;
     $albaran->observaciones = $this->pedido->observaciones;
     $albaran->total = $this->pedido->total;
     $albaran->totaliva = $this->pedido->totaliva;
     $albaran->numproveedor = $this->pedido->numproveedor;
     $albaran->irpf = $this->pedido->irpf;
     $albaran->totalirpf = $this->pedido->totalirpf;
     $albaran->totalrecargo = $this->pedido->totalrecargo;
     /**
      * Obtenemos el ejercicio para la fecha de hoy (puede que
      * no sea el mismo ejercicio que el del pedido, por ejemplo
      * si hemos cambiado de año)
      */
     $eje0 = $this->ejercicio->get_by_fecha($albaran->fecha);
     $albaran->codejercicio = $eje0->codejercicio;
     $regularizacion = new regularizacion_iva();
     if (!$eje0->abierto()) {
         $this->new_error_msg("El ejercicio está cerrado.");
     } else {
         if ($regularizacion->get_fecha_inside($albaran->fecha)) {
             $this->new_error_msg("El IVA de ese periodo ya ha sido regularizado. No se pueden añadir más " . FS_ALBARANES . " en esa fecha.");
         } else {
             if ($albaran->save()) {
                 $continuar = TRUE;
                 $art0 = new articulo();
                 foreach ($this->pedido->get_lineas() as $l) {
                     $n = new linea_albaran_proveedor();
                     $n->idlineapedido = $l->idlinea;
                     $n->idpedido = $l->idpedido;
                     $n->idalbaran = $albaran->idalbaran;
                     $n->cantidad = $l->cantidad;
                     $n->codimpuesto = $l->codimpuesto;
                     $n->descripcion = $l->descripcion;
                     $n->dtopor = $l->dtopor;
                     $n->irpf = $l->irpf;
                     $n->iva = $l->iva;
                     $n->pvpsindto = $l->pvpsindto;
                     $n->pvptotal = $l->pvptotal;
                     $n->pvpunitario = $l->pvpunitario;
                     $n->recargo = $l->recargo;
                     $n->referencia = $l->referencia;
                     if ($n->save()) {
                         /// añadimos al stock
                         if (!is_null($n->referencia)) {
                             $articulo = $art0->get($n->referencia);
                             if ($articulo) {
                                 $articulo->sum_stock($albaran->codalmacen, $l->cantidad);
                             }
                         }
                     } else {
                         $continuar = FALSE;
                         $this->new_error_msg("¡Imposible guardar la línea el artículo " . $n->referencia . "! ");
                         break;
                     }
                 }
                 if ($continuar) {
                     $this->pedido->idalbaran = $albaran->idalbaran;
                     $this->pedido->editable = FALSE;
                     if ($this->pedido->save()) {
                         $this->new_message("<a href='" . $albaran->url() . "'>" . ucfirst(FS_ALBARAN) . '</a> generado correctamente.');
                     } else {
                         $this->new_error_msg("¡Imposible vincular el " . FS_PEDIDO . " con el nuevo " . FS_ALBARAN . "!");
                         if ($albaran->delete()) {
                             $this->new_error_msg("El " . FS_ALBARAN . " se ha borrado.");
                         } else {
                             $this->new_error_msg("¡Imposible borrar el " . FS_ALBARAN . "!");
                         }
                     }
                 } else {
                     if ($albaran->delete()) {
                         $this->new_error_msg("El " . FS_ALBARAN . " se ha borrado.");
                     } else {
                         $this->new_error_msg("¡Imposible borrar el " . FS_ALBARAN . "!");
                     }
                 }
             } else {
                 $this->new_error_msg("¡Imposible guardar el " . FS_ALBARAN . "!");
             }
         }
     }
 }
 private function generar_albaran()
 {
     $albaran = new albaran_proveedor();
     $albaran->cifnif = $this->pedido->cifnif;
     $albaran->codagente = $this->pedido->codagente;
     $albaran->codalmacen = $this->pedido->codalmacen;
     $albaran->codproveedor = $this->pedido->codproveedor;
     $albaran->coddivisa = $this->pedido->coddivisa;
     $albaran->tasaconv = $this->pedido->tasaconv;
     $albaran->codpago = $this->pedido->codpago;
     $albaran->codserie = $this->pedido->codserie;
     $albaran->neto = $this->pedido->neto;
     $albaran->nombre = $this->pedido->nombre;
     $albaran->observaciones = $this->pedido->observaciones;
     $albaran->total = $this->pedido->total;
     $albaran->totaliva = $this->pedido->totaliva;
     $albaran->numproveedor = $this->pedido->numproveedor;
     $albaran->irpf = $this->pedido->irpf;
     $albaran->totalirpf = $this->pedido->totalirpf;
     $albaran->totalrecargo = $this->pedido->totalrecargo;
     /**
      * Obtenemos el ejercicio para la fecha seleccionada.
      */
     $eje0 = $this->ejercicio->get_by_fecha($_POST['aprobar'], FALSE);
     if ($eje0) {
         $albaran->fecha = $_POST['aprobar'];
         $albaran->codejercicio = $eje0->codejercicio;
     }
     if (!$eje0) {
         $this->new_error_msg("Ejercicio no encontrado o está cerrado.");
     } else {
         if (!$eje0->abierto()) {
             $this->new_error_msg("El ejercicio está cerrado.");
         } else {
             if ($albaran->save()) {
                 $continuar = TRUE;
                 $art0 = new articulo();
                 foreach ($this->pedido->get_lineas() as $l) {
                     $n = new linea_albaran_proveedor();
                     $n->idlineapedido = $l->idlinea;
                     $n->idpedido = $l->idpedido;
                     $n->idalbaran = $albaran->idalbaran;
                     $n->cantidad = $l->cantidad;
                     $n->codimpuesto = $l->codimpuesto;
                     $n->descripcion = $l->descripcion;
                     $n->dtopor = $l->dtopor;
                     $n->irpf = $l->irpf;
                     $n->iva = $l->iva;
                     $n->pvpsindto = $l->pvpsindto;
                     $n->pvptotal = $l->pvptotal;
                     $n->pvpunitario = $l->pvpunitario;
                     $n->recargo = $l->recargo;
                     $n->referencia = $l->referencia;
                     if ($n->save()) {
                         /// añadimos al stock
                         if (!is_null($n->referencia)) {
                             $articulo = $art0->get($n->referencia);
                             if ($articulo) {
                                 $articulo->sum_stock($albaran->codalmacen, $l->cantidad, isset($_POST['costemedio']));
                             }
                         }
                     } else {
                         $continuar = FALSE;
                         $this->new_error_msg("¡Imposible guardar la línea el artículo " . $n->referencia . "! ");
                         break;
                     }
                 }
                 if ($continuar) {
                     $this->pedido->idalbaran = $albaran->idalbaran;
                     $this->pedido->editable = FALSE;
                     if ($this->pedido->save()) {
                         $this->new_message("<a href='" . $albaran->url() . "'>" . ucfirst(FS_ALBARAN) . '</a> generado correctamente.');
                     } else {
                         $this->new_error_msg("¡Imposible vincular el " . FS_PEDIDO . " con el nuevo " . FS_ALBARAN . "!");
                         if ($albaran->delete()) {
                             $this->new_error_msg("El " . FS_ALBARAN . " se ha borrado.");
                         } else {
                             $this->new_error_msg("¡Imposible borrar el " . FS_ALBARAN . "!");
                         }
                     }
                 } else {
                     if ($albaran->delete()) {
                         $this->new_error_msg("El " . FS_ALBARAN . " se ha borrado.");
                     } else {
                         $this->new_error_msg("¡Imposible borrar el " . FS_ALBARAN . "!");
                     }
                 }
             } else {
                 $this->new_error_msg("¡Imposible guardar el " . FS_ALBARAN . "!");
             }
         }
     }
 }
 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!");
     }
 }
 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;
 }
Example #24
0
 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;
     }
 }