public function imprimir_ordenes_indiv($idorden)
 {
     $orden_prov = new orden_prov();
     $orden = $orden_prov->get($idorden);
     $recibo_prov = new recibo_proveedor();
     $recibo = $recibo_prov->get_por_idorden($idorden);
     $valor = new valores();
     $valores = $valor->get_por_idorden($idorden);
     $factura_prov = new factura_proveedor();
     $pdf_doc = new fs_pdf();
     $cant_lineas_orden = count($orden);
     $lineas_total = 0;
     $cant_lineas = 25;
     $linea_actual = 0;
     $pagina = 1;
     $total_facturado = 0;
     $total_valor = 0;
     /////  Primer encabezado
     $pdf_doc->pdf->ezText("Página " . $pagina, 9, array('justification' => 'right'));
     $pdf_doc->pdf->ezText("<b>" . $this->empresa->nombre . "</b>", 10, array('justification' => 'left'));
     $pdf_doc->pdf->ezText("Fecha: " . $orden->fecha . "                ", 9, array('justification' => 'right'));
     $pdf_doc->pdf->ezText("Orden de Pago Nº: " . $orden->idorden . "          ", 12, array('justification' => 'right'));
     $pdf_doc->pdf->ezText($this->empresa->direccion, 10, array('justification' => 'left'));
     $pdf_doc->pdf->ezText("\n", 10);
     $pdf_doc->pdf->ezText("<b>Órdenes de pago</b>", 16, array('justification' => 'left'));
     $pdf_doc->pdf->ezText("\n", 10);
     $pdf_doc->pdf->ezText("\n", 10);
     $pdf_doc->pdf->ezText("<b>Proveedor:  " . $orden->provorden . "</b>", 10, array('justification' => 'left'));
     $pdf_doc->pdf->ezText("<b> Concepto:  " . $orden->conceptoorden . "</b>", 10, array('justification' => 'left'));
     $pdf_doc->pdf->ezText("\n", 10);
     $pdf_doc->pdf->ezText("<b>Facturas</b>", 12, array('justification' => 'left'));
     $pdf_doc->new_table();
     $pdf_doc->add_table_header(array('fecha' => '<b>Fecha Fact.</b>', 'facdoc' => '<b>Documento</b>', 'factnum' => '<b>Número</b>', 'recargo' => '<b>Recargo</b>', 'factimp' => '<b>Importe Fact.</b>', 'total' => '<b>Total</b>'));
     $sub_t = 0;
     foreach ($recibo as $p) {
         $factura = $factura_prov->get_by_codigo($p->codigo);
         if (substr($p->factprov, 0, 1) == 'C' || substr($p->factprov, 0, 1) == 'Q') {
             $sub_t = $p->importe * -1;
         } else {
             $sub_t = $p->importe;
         }
         if (substr($p->factprov, 0, 1) == 'B') {
             $comp_doc = 'FACTURA B';
         }
         if (substr($p->factprov, 0, 1) == 'F') {
             $comp_doc = 'FACTURA C';
         }
         if (substr($p->factprov, 0, 1) == 'T') {
             $comp_doc = 'TICKET FACTURA';
         }
         if (substr($p->factprov, 0, 1) == 'Q') {
             $comp_doc = 'TICKET CRÉDITO';
         }
         if (substr($p->factprov, 0, 1) == 'C') {
             $comp_doc = 'NOTA DE CRÉDITO';
         }
         if (substr($p->factprov, 0, 1) == 'D') {
             $comp_doc = 'NOTA DE DÉBITO';
         }
         $numcompr = substr($p->factprov, 2);
         $pdf_doc->add_table_row(array('fecha' => $p->fecha, 'facdoc' => $comp_doc, 'factnum' => $numcompr, 'recargo' => $p->recargo, 'factimp' => $sub_t, 'total' => $sub_t + $p->recargo, 'valor' => $factura->observaciones, 'importe' => $sub_t));
         $total_facturado += $sub_t + $p->recargo;
     }
     $pdf_doc->save_table(array('cols' => array('campo1' => array('justification' => 'left'), 'dato1' => array('justification' => 'left'), 'campo2' => array('justification' => 'left'), 'dato2' => array('justification' => 'left')), 'showLines' => 3, 'width' => 520, 'shaded' => 1));
     $pdf_doc->pdf->ezText("\n", 10);
     $pdf_doc->pdf->ezText("<b>Valores Entregados</b>", 12, array('justification' => 'left'));
     $pdf_doc->new_table();
     $pdf_doc->add_table_header(array('fecha' => '<b>Fecha </b>', 'banco' => '<b>Banco</b>', 'numero' => '<b>Número</b>', 'importe' => '<b>Importe</b>'));
     foreach ($valores as $p) {
         $pdf_doc->add_table_row(array('fecha' => $p->fecha, 'banco' => $p->banco, 'numero' => $p->numero, 'importe' => $p->importe));
         $total_valor += $p->importe;
     }
     $pdf_doc->save_table(array('cols' => array('campo1' => array('justification' => 'left'), 'dato1' => array('justification' => 'left'), 'campo2' => array('justification' => 'left'), 'dato2' => array('justification' => 'left')), 'showLines' => 3, 'width' => 520, 'shaded' => 1));
     $pdf_doc->pdf->ezText("\n", 14);
     $pdf_doc->pdf->ezText("<b>Total Facturado:   " . $total_facturado . "</b>", 11, array('justification' => 'left'));
     $pdf_doc->pdf->ezText("\n", 6);
     $pdf_doc->pdf->ezText("<b>Total Entregado:  " . $total_valor . "</b>", 11, array('justification' => 'left'));
     $pdf_doc->set_y(140);
     $pdf_doc->pdf->ezText('FIRMA :  _________________________________________________  DNI: _________________________', 8, array('justification' => 'left'));
     $pdf_doc->pdf->ezText("\n", 10);
     $pdf_doc->pdf->ezText('ACLARACIÓN :  _________________________________________________ ', 8, array('justification' => 'left'));
     $pdf_doc->pdf->ezText("\n", 10);
     $pdf_doc->pdf->ezText('DOMICILIO :  ___________________________________________________ ', 8, array('justification' => 'left'));
     $pdf_doc->show();
 }
 public function asiento_pago_compra($id)
 {
     $varorden = new orden_prov();
     $orden = $varorden->get($id);
     $varanticipo = new anticipos_proveedor();
     //	  $anticipo =  $varanticipo->get($id);
     $this->importe_anticipo = 0;
     foreach ($varanticipo->get_anticipo_idorden($id) as $valant) {
         $this->importe_anticipo += $valant->importe;
         $this->idsubc_antic = $valant->idsubcuenta;
     }
     $ok = FALSE;
     $this->asiento = FALSE;
     $proveedor0 = new proveedor();
     $subcuenta_prov = FALSE;
     $proveedor = $proveedor0->get($orden->codprovorden);
     if ($proveedor) {
         $subcuenta_prov = $proveedor->get_subcuenta($orden->codejercicio);
     }
     if (!$subcuenta_prov) {
         $eje0 = $this->ejercicio->get($orden->codejercicio);
         $this->new_message("No se ha podido generar una subcuenta para el proveedor ");
         if (!$this->soloasiento) {
             $this->new_message("Aun así la <a href='" . $orden->url() . "'>factura</a> se ha generado correctamente,\n          pero sin asiento contable.");
         }
     } else {
         $asiento = new asiento();
         $asiento->codejercicio = $orden->codejercicio;
         //         $asiento->concepto = "Orden de pago ".$orden->codigo." - ".$orden->nombre;
         //         $asiento->documento = $orden->codigo;
         $asiento->concepto = "Orden de pago " . $orden->fecha . " - " . $orden->provorden;
         $asiento->documento = $orden->fecha;
         $asiento->concepto = "Orden de pago  - " . $orden->provorden;
         $asiento->editable = TRUE;
         $asiento->fecha = $orden->fecha;
         $asiento->importe = $orden->importepagar - $this->importe_anticipo;
         $asiento->tipodocumento = "Egreso proveedor";
         if ($asiento->save()) {
             $asiento_correcto = TRUE;
             $subcuenta = new subcuenta();
             $partida0 = new partida();
             $partida0->idasiento = $asiento->idasiento;
             $partida0->concepto = $asiento->concepto;
             $partida0->idsubcuenta = $subcuenta_prov->idsubcuenta;
             $partida0->codsubcuenta = $subcuenta_prov->codsubcuenta;
             ///////////  Proveedor  debe			/////////
             $partida0->debe = $orden->importepagar;
             $partida0->coddivisa = 0;
             $partida0->tasaconv = 0;
             $partida0->codserie = 0;
             if (!$partida0->save()) {
                 $asiento_correcto = FALSE;
                 $this->new_error_msg("¡Imposible generar la partida para la subcuenta " . $partida0->codsubcuenta . "!");
             }
             if (!$this->importe_anticipo == 0) {
                 $subcuenta_anticipo = $subcuenta->get($this->idsubc_antic);
             }
             if ($this->importe_anticipo and $asiento_correcto) {
                 $partida2 = new partida();
                 $partida2->idasiento = $asiento->idasiento;
                 $partida2->concepto = $asiento->concepto;
                 $partida2->idsubcuenta = $subcuenta_anticipo->idsubcuenta;
                 $partida2->codsubcuenta = $subcuenta_anticipo->codsubcuenta;
                 ///////// Proveedor compra haber  ////////////////////////
                 $partida2->haber = $this->importe_anticipo;
                 $partida2->coddivisa = 0;
                 $partida2->tasaconv = 0;
                 $partida2->codserie = 0;
                 if (!$partida2->save()) {
                     $asiento_correcto = FALSE;
                     $this->new_error_msg("¡Imposible generar la partida para la subcuenta " . $partida2->codsubcuenta . "!");
                 }
             }
             $subcuenta_compras = $subcuenta->get_cuentaesp('CAJA', $asiento->codejercicio);
             if ($subcuenta_compras and $asiento_correcto) {
                 $partida3 = new partida();
                 $partida3->idasiento = $asiento->idasiento;
                 $partida3->concepto = $asiento->concepto;
                 $partida3->idsubcuenta = $subcuenta_compras->idsubcuenta;
                 $partida3->codsubcuenta = $subcuenta_compras->codsubcuenta;
                 ///////// Proveedor compra haber  ////////////////////////
                 $partida3->haber = $orden->importepagar - $this->importe_anticipo;
                 $partida3->coddivisa = 0;
                 $partida3->tasaconv = 0;
                 $partida3->codserie = 0;
                 if (!$partida3->save()) {
                     $asiento_correcto = FALSE;
                     $this->new_error_msg("¡Imposible generar la partida para la subcuenta " . $partida2->codsubcuenta . "!");
                 }
             }
             if ($asiento_correcto) {
                 $orden->idasiento = $asiento->idasiento;
                 if ($orden->save()) {
                     $ok = TRUE;
                     $this->asiento = $asiento;
                 } else {
                     $this->new_error_msg("¡Imposible añadir el asiento a la factura!");
                 }
             } else {
                 if ($asiento->delete()) {
                     $this->new_message("El asiento se ha borrado.");
                 } else {
                     $this->new_error_msg("¡Imposible borrar el asiento!");
                 }
             }
         }
     }
     return $ok;
 }
 public function delete()
 {
     /// desvinculamos la factura
     $fac = $this->get_factura();
     if ($fac) {
         if ($fac->idasiento == $this->idasiento) {
             $fac->idasiento = NULL;
             $fac->save();
         }
     }
     /////////  pone en "0" pagada en factura
     $fact_prov = new factura_proveedor();
     $recibo = new recibo_proveedor();
     $orden = new orden_prov();
     $valor = new valores();
     $data = $recibo->get_por_idasiento($this->idasiento);
     /////  pone en proceso la orden
     foreach ($data as $d) {
         //				$fact_data = $fact_prov->get($d->idfactura);
         //				$fact_data->pagada = 0;
         //				$fact_data->save();
         $idorden = $d->idorden;
         $orden->cambio_estado($idorden, 'Proceso');
         /// pone idasiento en recibos
         $recibo->guardar_asiento_idorden($idorden, NULL);
         /// pone idasiento en valores
         $valor->guardar_asiento_idorden($idorden, NULL);
     }
     ///////////////////////////////////////////
     /////////elimina los recibos según el idasiento
     //		if(!$recibo->delete_recibo_idasiento($this->idasiento))  $this->new_error_msg("Error - No se borraron los recibos");
     //////// elimina la orden según el idasiento
     //		$orden->cambio_estado($orden->idorden,'Proceso');
     //		if(!$orden->delete_orden_idasiento($this->idasiento)) $this->new_error_msg("Error - No se borraron las ordenes");
     /// eliminamos las partidas una a una para forzar la actualización de las subcuentas asociadas
     foreach ($this->get_partidas() as $p) {
         $p->delete();
     }
     return $this->db->exec("DELETE FROM " . $this->table_name . " WHERE idasiento = " . $this->var2str($this->idasiento) . ";");
 }
 private function nuevo_asiento_devolucion()
 {
     $anular = new factura_proveedor();
     $orden = new orden_prov();
     $facturadev = new asiento_factura();
     if ($facturadev->nuevo_asiento_devolucion_prov($_REQUEST['id'])) {
         $anular->boton_anular($_REQUEST['id']);
     }
     $factura = new factura_proveedor();
     $var_idpagodevol = $factura->get($_GET['id']);
     // Dá el valor al botón
     $this->factura_anulada = $var_idpagodevol->idpagodevol;
     foreach ($orden->ultimovalor_orden_prov($var_idpagodevol->codproveedor) as $f) {
     }
     //		$dif_importe = $f->importe - $var_idpagodevol->total;
     //		$orden->nuevoimporte_orden($f->idorden,$dif_importe);
 }