コード例 #1
0
 private function pagar_facturas()
 {
     $num = 0;
     /// ¿Generamos el asiento de pago?
     $asientop = NULL;
     if ($this->empresa->contintegrada) {
         /// ¿Cuanto es el total?
         $coddivisa = NULL;
         $importe = 0;
         $tasaconv = 1;
         $rec0 = new recibo_proveedor();
         foreach ($_POST['idfactura'] as $id) {
             $recibos = $rec0->all_from_factura($id);
             foreach ($recibos as $recibo) {
                 if ($recibo->estado != 'Pagado') {
                     $coddivisa = $recibo->coddivisa;
                     $importe += $recibo->importe;
                     $tasaconv = $recibo->tasaconv;
                 }
             }
         }
         $asientop = $this->nuevo_asiento_pago($importe, $coddivisa, $tasaconv);
     }
     $fac0 = new factura_proveedor();
     foreach ($_POST['idfactura'] as $id) {
         $error = FALSE;
         $recibos = $rec0->all_from_factura($id);
         foreach ($recibos as $recibo) {
             if ($recibo->estado != 'Pagado') {
                 $pago = new pago_recibo_proveedor();
                 $pago->idrecibo = $recibo->idrecibo;
                 if ($asientop) {
                     $pago->idasiento = $asientop->idasiento;
                 }
                 if ($pago->save()) {
                     $recibo->estado = 'Pagado';
                     if (!$recibo->save()) {
                         $error = TRUE;
                     }
                 }
             }
         }
         if (!$error) {
             /// marcamos la factura como pagada
             $factura = $fac0->get($id);
             if ($factura) {
                 $factura->pagada = TRUE;
                 if ($factura->save()) {
                     $num++;
                 }
             }
         }
     }
     $this->new_message($num . ' facturas marcadas como pagadas, estas son las siguientes.');
 }
コード例 #2
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();
             }
         }
     }
 }