/**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = Facturas::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Esempio n. 2
0
<?php
    foreach(Yii::app()->user->getFlashes() as $key => $message) {
        echo '<div class="flash-' . $key . '">' . $message . "</div>\n";
    }
?>


<p class="help-block">Los campos con <span class="required">*</span> son obligatorios.</p>

<?php echo $form->errorSummary($model); ?>

	<?php //echo $form->textFieldGroup($model,'factura_id',array('widgetOptions'=>array('htmlOptions'=>array('class'=>'span5')))); ?>

	<div class="form-group">
	<?php 	
		$list = CHtml::listData(Facturas::model()->findAllByAttributes(array('ente_organo_id'=>Usuarios::model()->actual()->ente_organo_id, 'cierre_carga'=>false, 'anho' => Yii::app()->params['trimestresFechas'][Yii::app()->session['trimestreSeleccionado']]['anho'])), 'id', function($factura){return $factura->etiquetaFactura();});

		echo CHtml::label('Seleccionar factura', 'Factura');
		echo "<br>";
		$this->widget(
		    'booster.widgets.TbSelect2',
		    array(
		        'asDropDownList' => true,
		        'model' => $model,
		        
		        'attribute' => 'factura_id',
		        //'name' => 'factura_id',
		        'data' => $list,
		        'htmlOptions'=>array('id'=>'Factura',
    			 'ajax' => array(
									'type'=>'POST', //request type
 /**
  * Deletes a particular model.
  * If deletion is successful, the browser will be redirected to the 'admin' page.
  * @param integer $id the ID of the model to be deleted
  */
 public function actionDelete($id)
 {
     if (Yii::app()->request->isPostRequest) {
         // we only allow deletion via POST request
         //$this->loadModel($id)->delete();
         $model = $this->loadModel($id);
         $factura = Facturas::model()->findByPk($model->factura_id);
         if (!($factura->ente_organo_id == Usuarios::model()->actual()->ente_organo_id)) {
             throw new CHttpException(403, "No se puede procesar la solicitud.");
         }
         $model->delete();
         if (!isset($_GET['ajax'])) {
             $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
         } else {
             throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.');
         }
     }
     // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
 }
 public function actionPdf($id)
 {
     $factura = Facturas::model()->findByPk($id);
     if ($factura !== null) {
         $datos = array('factura.idfactura' => $factura->IdFactura, 'factura.fecha' => $factura->Fecha, 'factura.idpaciente' => $factura->IdPaciente, 'factura.numero' => $factura->Numero, 'factura.serie' => $factura->Serie, 'factura.concepto' => $factura->Concepto, 'factura.importe' => $factura->Importe, 'factura.fechacobro' => $factura->FechaCobro, 'factura.notas' => $factura->Notas, 'pacientes.nombre' => CHtml::value($factura, 'paciente.Nombre'), 'pacientes.apellidos' => CHtml::value($factura, 'paciente.Apellidos'), 'pacientes.dni_nif' => CHtml::value($factura, 'paciente.DNI_NIF'), 'pacientes.direccion' => CHtml::value($factura, 'paciente.Direccion'), 'pacientes.codpostal' => CHtml::value($factura, 'paciente.CodPostal'), 'pacientes.localidad' => CHtml::value($factura, 'paciente.Localidad'), 'pacientes.provincia' => CHtml::value($factura, 'paciente.Provincia'), 'pacientes.telfijo' => CHtml::value($factura, 'paciente.TelFijo'));
         plantilla::generarPlantilla('PlantillaFactura', $datos, true);
     } else {
         echo 'Factura no encontrada.';
     }
 }
 function calcularIvaFacturas()
 {
     $sumaIva = 0;
     foreach (Facturas::model()->findAllByAttributes(array('ente_organo_id' => Usuarios::model()->actual()->ente_organo_id)) as $key => $value) {
         foreach ($value->productos as $key => $value) {
             $sumaIva += $value->costo_unitario * $value->cantidad_adquirida * ($value->iva->porcentaje / 100);
         }
     }
     return $sumaIva;
 }