コード例 #1
0
 protected function private_core()
 {
     $this->share_extenstion();
     $recibo = new recibo_proveedor();
     $this->check_vencimiento = FALSE;
     $this->desde = '';
     $this->estado = '';
     $this->hasta = '';
     $this->num_pendientes = 0;
     $this->num_resultados = 0;
     $this->num_vencidos = 0;
     $this->proveedor = FALSE;
     $this->total_resultados = 0;
     $this->total_resultados_txt = '';
     $this->vencimiento = Date('d-m-Y', strtotime('+1month'));
     if (isset($_REQUEST['buscar_proveedor'])) {
         $this->buscar_proveedor();
     } else {
         if (isset($_POST['fecha'])) {
             $this->nuevo_recibo();
         } else {
             if (isset($_REQUEST['id'])) {
                 /// pestaña recibos de una factura
                 $this->template = 'tab_factura_proveedor';
                 $factura = new factura_proveedor();
                 $this->factura = $factura->get($_REQUEST['id']);
                 if ($this->factura) {
                     $this->resultados = $recibo->all_from_factura($_REQUEST['id']);
                     if (isset($_GET['regenerar'])) {
                         foreach ($this->resultados as $res) {
                             $res->delete();
                         }
                         $this->factura->pagada = FALSE;
                         $this->factura->save();
                         $this->sync_factura(TRUE);
                     }
                     $this->pagada_previamente = FALSE;
                     if ($this->factura->pagada and count($this->resultados) == 0) {
                         $this->pagada_previamente = TRUE;
                     } else {
                         $this->sync_factura(TRUE);
                     }
                 }
             } else {
                 $this->mostrar = 'todo';
                 if (isset($_GET['mostrar'])) {
                     $this->mostrar = $_GET['mostrar'];
                 }
                 $this->offset = 0;
                 if (isset($_GET['offset'])) {
                     $this->offset = intval($_GET['offset']);
                 }
                 if (isset($_GET['delete'])) {
                     $recibo2 = $recibo->get($_GET['delete']);
                     if ($recibo2) {
                         if ($recibo2->delete()) {
                             $this->new_message('Recibo eliminado correctamente.');
                         } else {
                             $this->new_message('Error al eliminar el recibo.');
                         }
                     } else {
                         $this->new_message('Recibo no encontrado.');
                     }
                 } else {
                     if (!isset($_GET['mostrar']) and isset($_REQUEST['codproveedor'])) {
                         $this->mostrar = 'buscar';
                     }
                 }
                 if (isset($_REQUEST['codproveedor'])) {
                     if ($_REQUEST['codproveedor'] != '') {
                         $pro0 = new proveedor();
                         $this->proveedor = $pro0->get($_REQUEST['codproveedor']);
                     }
                 }
                 if (isset($_REQUEST['desde'])) {
                     $this->desde = $_REQUEST['desde'];
                     $this->estado = $_REQUEST['estado'];
                     $this->hasta = $_REQUEST['hasta'];
                     $this->check_vencimiento = isset($_REQUEST['vencimiento']);
                 }
                 $this->order = 'fecha DESC';
                 if (isset($_GET['order'])) {
                     if ($_GET['order'] == 'fecha_desc') {
                         $this->order = 'fecha DESC';
                     } else {
                         if ($_GET['order'] == 'fecha_asc') {
                             $this->order = 'fecha ASC';
                         } else {
                             if ($_GET['order'] == 'fechav_desc') {
                                 $this->order = 'fechav DESC';
                             } else {
                                 if ($_GET['order'] == 'fechav_asc') {
                                     $this->order = 'fechav ASC';
                                 } else {
                                     if ($_GET['order'] == 'codigo_desc') {
                                         $this->order = 'codigo DESC';
                                     } else {
                                         if ($_GET['order'] == 'codigo_asc') {
                                             $this->order = 'codigo ASC';
                                         }
                                     }
                                 }
                             }
                         }
                     }
                     setcookie('compras_recibos_order', $this->order, time() + FS_COOKIES_EXPIRE);
                 } else {
                     if (isset($_COOKIE['compras_recibos_order'])) {
                         $this->order = $_COOKIE['compras_recibos_order'];
                     }
                 }
                 $this->cron_job();
                 $this->buscar();
             }
         }
     }
 }
コード例 #2
0
 protected function private_core()
 {
     /// ¿El usuario tiene permiso para eliminar en esta página?
     $this->allow_delete = $this->user->allow_delete_on(__CLASS__);
     $recibo = new recibo_proveedor();
     $this->recibo = FALSE;
     if (isset($_REQUEST['id'])) {
         $this->recibo = $recibo->get($_REQUEST['id']);
     }
     if ($this->recibo) {
         if (isset($_POST['fechav'])) {
             $this->recibo->importe = floatval($_POST['importe']);
             $this->recibo->fecha = $_POST['emitido'];
             $this->recibo->fechav = $_POST['fechav'];
             $this->recibo->iban = $_POST['iban'];
             $this->recibo->swift = $_POST['swift'];
             if ($this->recibo->save()) {
                 $this->new_message('Datos guardados correctamente.');
             } else {
                 $this->new_error_msg('Error al guardar los datos.');
             }
         }
         $this->page->title = 'Recibo ' . $this->recibo->codigo;
         $fact = new factura_proveedor();
         $this->factura = $fact->get($this->recibo->idfactura);
         $this->check_recibo();
         $this->get_subcuentas();
         $pago = new pago_recibo_proveedor();
         if (isset($_POST['nuevopago'])) {
             $pago->idrecibo = $this->recibo->idrecibo;
             $pago->fecha = $_POST['fecha'];
             $pago->tipo = $_POST['tipo'];
             foreach ($this->subcuentas_pago as $sc) {
                 if ($sc->codsubcuenta == $_POST['codsubcuenta']) {
                     $pago->idsubcuenta = $sc->idsubcuenta;
                     $pago->codsubcuenta = $sc->codsubcuenta;
                 }
             }
             if ($pago->tipo == 'Pago') {
                 if ($this->empresa->contintegrada and isset($_POST['generarasiento'])) {
                     $pago->idasiento = $this->nuevo_asiento_pago($pago, $this->ejercicio);
                 }
                 $this->recibo->estado = 'Pagado';
                 $this->recibo->fechap = $_POST['fecha'];
             } else {
                 if ($this->empresa->contintegrada and isset($_POST['generarasiento'])) {
                     $pago->idasiento = $this->nuevo_asiento_devolucion($pago, $this->ejercicio);
                 }
                 $this->recibo->estado = 'Devuelto';
             }
             if ($pago->save()) {
                 $this->new_message('Pago guardado correctamente.');
                 $this->recibo->save();
             } else {
                 $this->new_error_msg('Error al guardar los pagos.');
             }
         } else {
             if (isset($_GET['deletep'])) {
                 foreach ($pago->all_from_recibo($this->recibo->idrecibo) as $pg) {
                     if ($pg->idpagodevol == intval($_GET['deletep'])) {
                         if ($pg->delete()) {
                             $this->new_message($pg->tipo . ' eliminado correctamente');
                             $this->recibo->estado = 'Emitido';
                             $this->recibo->save();
                         } else {
                             $this->new_error_msg('Error al eliminar el ' . $pg->tipo);
                         }
                         break;
                     }
                 }
             }
         }
         $this->pagos = $pago->all_from_recibo($this->recibo->idrecibo);
         $this->recibos = $this->recibo->all_from_factura($this->recibo->idfactura);
         $this->sync_factura();
     } else {
         $this->new_error_msg('Recibo no encontrado.');
     }
 }