public function actionUpdate($id) { Yii::import('ext.multimodelform.MultiModelForm'); $model = $this->loadModel($id, 'OrdenTrabajo'); $detalle = new DetallesOt(); $detallesValidados = array(); if (isset($_POST['OrdenTrabajo'])) { $model->setAttributes($_POST['OrdenTrabajo']); $masterValues = array('id_ot' => $model->id); if (MultiModelForm::save($detalle, $detallesValidados, $detallesBorrados, $masterValues) && $model->save()) { $factura = $this->loadModel($model->id_rf, 'RegistroFactura'); $iva = Ivas::model()->findBySql('SELECT valor_iva FROM ivas ORDER BY fecha DESC'); $suma_bruto = $factura->sumarNeto() * ($iva['valor_iva'] / 100 + 1); $factura->setAttributes(array('total_neto' => $factura->sumarNeto(), 'total_bruto' => round($suma_bruto))); if ($factura->save()) { $oDbConnection = Yii::app()->db; $presid = Presupuesto::model()->findBySql('SELECT id FROM presupuesto where ano = :an ORDER BY modificado DESC', array(':an' => date("Y", strtotime($factura->fecha)))); $presupuesto = $this->loadModel($presid->id, 'Presupuesto'); $gastado = $oDbConnection->createCommand('select sum(detalles_ot.subtotal) as gasto from detalles_ot INNER JOIN orden_trabajo on orden_trabajo.id = detalles_ot.id_ot where YEAR(orden_trabajo.fecha) = :fec'); $gastado->bindParam(':fec', date("Y", strtotime($model->fecha))); $gas = $gastado->queryRow(); $presupuesto->setAttributes(array('ppto_disponible' => $presupuesto->ppto_anual - $gas['gasto'])); if ($presupuesto->save()) { $this->redirect(array('registrofactura/view', 'id' => $factura->id)); } } } } $this->render('update', array('model' => $model, 'detalle' => $detalle, 'detallesValidados' => $detallesValidados)); }
public function actionUpdate($id) { Yii::import('ext.multimodelform.MultiModelForm'); $model = $this->loadModel($id, 'FacturaCombustible'); $detalle = new DetFacturaCombustible(); $detallesValidados = array(); if (isset($_POST['FacturaCombustible'])) { $model->setAttributes($_POST['FacturaCombustible']); $masterValues = array('id_factura_combustible' => $model->id); if (MultiModelForm::save($detalle, $detallesValidados, $detallesBorrados, $masterValues) && $model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('update', array('model' => $model, 'detalle' => $detalle, 'detallesValidados' => $detallesValidados)); }
public function actionCreate() { Yii::import('ext.multimodelform.MultiModelForm'); $model = new Compra(); $member = new Detallecompra(); $producto = new Productos(); $proveedor = new Proveedor(); $forma = new Formapago(); $validatedMembers = array(); //ensure an empty array if (isset($_POST['Compra'])) { $model->attributes = $_POST['Compra']; if (MultiModelForm::validate($member, $validatedMembers, $deleteItems) && $model->save()) { $masterValues = array('NumCompra' => $model->NumCompra); if (MultiModelForm::save($member, $validatedMembers, $deleteMembers, $masterValues)) { // $this->redirect(array('view','id'=>$model->Id)); $usuario = $_POST['Compra']['Usuario']; $numdocumento = $_POST['Compra']['NumCompra']; $forpago = $_POST['Compra']['ForPago']; $rut = $_POST['Compra']['CodProveedor']; $codigo = $_POST['Detallecompra']['CodProducto']; $descripcion = $_POST['Detallecompra']['Descripcion']; $cantidad = $_POST['Detallecompra']['Cantidad']; $saldoanterior = $_POST['Detallecompra']['Saldo']; $precio = $_POST['Detallecompra']['Precio']; $subtotal = $_POST['Detallecompra']['Subtotal']; $iva = $_POST['Detallecompra']['Iva']; $medida = $_POST['Detallecompra']['UniMedida']; for ($i = 0; $i < count($codigo); $i++) { $saldoactual[$i] = $saldoanterior[$i] + $cantidad[$i]; // Yii::app()->db->createCommand('update productos set CanExistencia = (CanExistencia + '.$cantidad[$i].'),PreCompra where CodProducto = "'.$codigo[$i].'"')->query(); Yii::app()->db->createCommand('update productos set CanExistencia = (CanExistencia + ' . $cantidad[$i] . '),PreCompra=' . $precio[$i] . ',Iva=' . $iva[$i] . ' where CodProducto = "' . $codigo[$i] . '"')->query(); yii::app()->db->createCommand('insert into kardex (Rut,ForPago,NumDocumento, CodProducto,Descripcion,UniMedida, TipoMovimiento, Cantidad, SaldoAnterior, SaldoActual, Precio,Iva, Subtotal,Usuario)' . ' Values("' . $rut . '",' . $forpago . ',' . $numdocumento . ',"' . $codigo[$i] . '","' . $descripcion[$i] . '","' . $medida[$i] . '","compra",' . $cantidad[$i] . ',' . $saldoanterior[$i] . ',' . $saldoactual[$i] . ',' . $precio[$i] . ',' . $iva[$i] . ',' . $subtotal[$i] . ',"' . $usuario . '")')->query(); // // yii::app()->db->createCommand('insert into kardex (Fecha,NumDocumento, CodProducto, TipoMovimiento, Cantidad, SaldoAnterior, SaldoActual, Precio, Subtotal)' // . ' Values(today,'.$numdocumento.','.$codigo[$i].',"compra",'.$cantidad[$i].','.$saldoanterior[$i].','.$saldoactual[$i].','.$precio[$i].','.$subtotal[$i].')')->query(); // } // $this->redirect(array('view','id'=>$model->NumCompra)); // $this->redirect(array('view','NumCompra'=>$model->NumCompra)); // $this->render('admin',array('model'=>$model,)); $this->redirect(array('view', 'id' => $model->Id)); } } } $this->render('create', array('model' => $model, 'member' => $member, 'producto' => $producto, 'proveedor' => $proveedor, 'forma' => $forma, 'validatedMembers' => $validatedMembers)); }
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { Yii::import('ext.multimodelform.MultiModelForm'); $model = $this->loadModel($id); //the Group model $member = new Member(); $validatedMembers = array(); //ensure an empty array if (isset($_POST['Group'])) { $model->attributes = $_POST['Group']; //the value for the foreign key 'groupid' $masterValues = array('groupid' => $model->id); if (MultiModelForm::save($member, $validatedMembers, $deleteMembers, $masterValues) && $model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('update', array('model' => $model, 'member' => $member, 'validatedMembers' => $validatedMembers)); }
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { Yii::import('ext.multimodelform.MultiModelForm'); $model = $this->loadModel($id); $socioG = new SocioG(); $validatedMembers = array(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Gruposocio'])) { $model->attributes = $_POST['Gruposocio']; $masterValues = array('grupo_id' => $model->id); if (MultiModelForm::save($socioG, $validatedMembers, $deleteMembers, $masterValues) && $model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('update', array('model' => $model, 'socioG' => $socioG, 'validatedMembers' => $validatedMembers)); $this->renderPartial('/site/buscarsalida'); }
public function actionCreate() { Yii::import('ext.multimodelform.MultiModelForm'); $model = new Venta(); $member = new Detalleventa(); $producto = new Producto(); $cliente = new Cliente(); $validatedMembers = array(); //ensure an empty array if (isset($_POST['Venta'])) { $model->attributes = $_POST['Venta']; if (MultiModelForm::validate($member, $validatedMembers, $deleteItems) && $model->save()) { //the value for the foreign key 'groupid' $masterValues = array('NumVenta' => $model->NumVenta); if (MultiModelForm::save($member, $validatedMembers, $deleteMembers, $masterValues)) { $usuario = Yii::app()->user->name; $numdocumento = $_POST['Venta']['NumVenta']; $forpago = $_POST['Venta']['ForPago']; $rut = $_POST['Venta']['CodCliente']; $descripcion = $_POST['Detalleventa']['Descripcion']; $codigo = $_POST['Detalleventa']['CodProducto']; $cantidad = $_POST['Detalleventa']['Cantidad']; $saldoanterior = $_POST['Detalleventa']['Saldo']; $precio = $_POST['Detalleventa']['Precio']; $subtotal = $_POST['Detalleventa']['Subtotal']; $iva = $_POST['Detalleventa']['Iva']; $unidad = $_POST['Detalleventa']['UniMedida']; for ($i = 0; $i < count($codigo); $i++) { $saldoactual[$i] = $saldoanterior[$i] - $cantidad[$i]; Yii::app()->db->createCommand('update productos set CanExistencia = (CanExistencia - ' . $cantidad[$i] . '),PreCompra=' . $precio[$i] . ',Iva=' . $iva[$i] . ' where CodProducto = "' . $codigo[$i] . '"')->query(); Yii::app()->db->createCommand('insert into kardex (Rut,ForPago,NumDocumento, Descripcion, CodProducto, UniMedida, TipoMovimiento, Cantidad, SaldoAnterior, SaldoActual, Precio,Iva, Subtotal,Usuario)' . ' Values("' . $rut . '",' . $forpago . ',' . $numdocumento . ',"' . $descripcion[$i] . '","' . $codigo[$i] . '","' . $unidad[$i] . '","Venta",' . $cantidad[$i] . ',' . $saldoanterior[$i] . ',' . $saldoactual[$i] . ',' . $precio[$i] . ',' . $iva[$i] . ',' . $subtotal[$i] . ',"' . $usuario . '")')->query(); // } $this->redirect(array('view', 'id' => $model->Id)); } } } $this->render('create', array('model' => $model, 'member' => $member, 'validatedMembers' => $validatedMembers, 'cliente' => $cliente)); }
public function actionIndex() { Yii::app()->getComponent("bootstrap"); Yii::import('ext.multimodelform.MultiModelForm'); $sede = ""; if (isset($_GET['sede']) && $_GET['sede'] != "") { $sede = CatSedes::model()->find("codigo_dane_sede=" . $_GET['sede']); $model = Acta::model()->find("CODIGO_DANE_SEDE='" . $_GET['sede'] . "'"); if ($model == null) { $model = new Acta(); } $participante = new Participante(); $validatedMembers = array(); //ensure an empty array $deleteMembers = array(); if (isset($_POST['Acta'])) { $model->attributes = $_POST['Acta']; $imageData = $_POST['imageData']; $imageDecoded = base64_decode($imageData); $fileName = $model->CODIGO_DANE_ESTABLEDUCATIVO . "_" . $model->CODIGO_DANE_SEDE . "_" . date('Y-m-d-H-i-s') . ".png"; $resultImageSaveProcess = file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/men19/uploads/" . $fileName, $imageDecoded); if ($resultImageSaveProcess) { $model->FIRMA = $fileName; } $model->LLAVE = md5($model->CODIGO_DANE_SEDE . "-" . $model->FECHA_INICIAL . "-" . Parametro::model()->findByPk(1)->NO_CONTRATO); $model->FECHA_ACTUALIZACION = date("Y-m-d H:i:s"); if (MultiModelForm::validate($participante, $validatedMembers, $deleteMembers) && $model->save()) { //the value for the foreign key 'groupid' $masterValues = array('ACTA_ID' => $model->IDACTA); if (MultiModelForm::save($participante, $validatedMembers, $deleteMembers, $masterValues)) { //Yii::app()->db->createCommand("CALL aud_procedimiento_desempate()")->execute(); $this->redirect(array('acta', 'id' => $model->IDACTA)); } } } $this->render('index', array('model' => $model, 'participante' => $participante, 'validatedMembers' => $validatedMembers, 'sede' => $sede)); } }
/** * 批量编辑课程下的全部课时 * @param unknown_type $courseId */ public function actionEditByCourse($courseId = 0) { Yii::import('ext.multimodelform.MultiModelForm'); $course = Course::model()->findByPk($courseId); $lesson = new Lesson(); $validatedLessons = array(); if (isset($_POST['Lesson'])) { // $model->attributes=$_POST['Group']; //the value for the foreign key 'groupid' $masterValues = array('courseId' => $course->courseId); //Save the master model after saving valid members if (MultiModelForm::save($lesson, $validatedLessons, $deleteLessons, $masterValues)) { $this->redirect(array('course/view', 'id' => $course->courseId)); } } $this->render('editByCourse', array('course' => $course, 'lesson' => $lesson, 'validatedLessons' => $validatedLessons)); }
?> <?php echo $form->dropDownList($model, 'ForPago', array('Debito', 'Credito', 'Efectivo', 'Cheque', 'Vale')); ?> <?php echo $form->error($model, 'ForPago'); ?> </th> </div> <?php // see http://www.yiiframework.com/doc/guide/1.1/en/form.table // Note: Can be a route to a config file too, // or create a method 'getMultiModelForm()' in the member model $memberFormConfig = array('elements' => array('CodProducto' => array('type' => 'text', 'maxlength' => 80, 'class' => 'CodProducto', 'style' => 'WIDTH:90px'), 'Descripcion' => array('type' => 'zii.widgets.jui.CJuiAutoComplete', 'source' => $this->createUrl('venta/autocomplete'), 'options' => array('showAnim' => 'fold', 'size' => '80', 'minLength' => '2', 'select' => "js:function(event, ui) { \n var nomobj_texto = this.id; //El identificador del campo en mi caso #Detallecompra_Descripcion \n var indexid = nomobj_texto.substring(24,nomobj_texto.length); \n \$('#Detalleventa_CodProducto'+indexid).val(ui.item.id); // HTML-Id del campo\n \$('#Detalleventa_Precio'+indexid).val(ui.item.precio);\n \$('#Detalleventa_Saldo'+indexid).val(ui.item.saldo);\n \$('#Detalleventa_UniMedida'+indexid).val(ui.item.unidad); \n \$('#Detalleventa_Exento'+indexid).val(0); \n \$('#Detalleventa_Descuento'+indexid).val(0); \n \$('#contador').html(indexid);\n \n }"), 'htmlOptions' => array('size' => 120, 'placeholder' => 'Buscar ...', 'title' => 'Indique el producto.')), 'Cantidad' => array('type' => 'text', 'maxlength' => 120, 'class' => 'Cantidad', 'style' => 'WIDTH:60px'), 'Precio' => array('type' => 'text', 'maxlength' => 120, 'class' => 'Precio', 'style' => 'WIDTH:80px'), 'UniMedida' => array('type' => 'text', 'maxlength' => 8, 'class' => 'UniMedida', 'size' => 8, 'style' => 'WIDTH:55px', 'readonly' => true), 'Saldo' => array('type' => 'text', 'maxlength' => 10, 'class' => 'Saldo', 'size' => 8, 'style' => 'WIDTH:80px', 'readonly' => true, 'hide' => true), 'Iva' => array('type' => 'text', 'maxlength' => 8, 'size' => 8, 'style' => 'WIDTH:55px', 'class' => 'Iva'), 'Descuento' => array('type' => 'text', 'maxlength' => 8, 'size' => 8, 'class' => 'Descuento', 'style' => 'WIDTH:80px', 'value' => 0), 'Exento' => array('type' => 'text', 'maxlength' => 10, 'class' => 'Exento', 'size' => 8, 'style' => 'WIDTH:80px', 'value' => 0), 'Subtotal' => array('type' => 'text', 'maxlength' => 10, 'class' => 'Subtotal', 'size' => 8, 'style' => 'WIDTH:80px'))); $this->widget('ext.multimodelform.MultiModelForm', array('id' => 'id_member', 'formConfig' => $memberFormConfig, 'model' => $member, 'tableView' => true, 'validatedItems' => $validatedMembers, 'jsAfterNewId' => MultiModelForm::afterNewIdAutoComplete($memberFormConfig['elements']['Descripcion']), 'addItemText' => 'Agregar', 'removeText' => 'Quitar', 'removeConfirm' => 'Desea quitar la fila seleccionada', 'data' => $member->findAll('NumVenta=:groupId', array(':groupId' => $model->NumVenta)))); ?> <th> <div class="required"> <?php echo $form->labelEx($model, 'TotExento'); ?> <?php echo $form->textField($model, 'TotExento'); ?> <?php echo $form->error($model, 'TotExento'); ?> </div>
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { Yii::import('ext.multimodelform.MultiModelForm'); $model = $this->loadModel($id); //the Group model $quiz = $model->quiz; $choice = new Answer(); $validatedChoices = array(); //ensure an empty array if (isset($_POST['Question'])) { $model->attributes = $_POST['Question']; //the value for the foreign key 'groupid' $masterValues = array('questionId' => $model->id); if (MultiModelForm::save($choice, $validatedChoices, $deleteMembers, $masterValues) && $model->save()) { $this->redirect(array('quiz/view', 'id' => $quiz->id)); } } $this->render('update', array('model' => $model, 'choice' => $choice, 'validatedChoices' => $validatedChoices, 'lesson' => $quiz->lesson, 'quiz' => $quiz, 'course' => $quiz->lesson->course)); }
/** * Validates submitted formdata * If a record is not valid, the invalid model will be set to $model * to display error summary * * @param mixed $model * @param array $validatedItems returns the array of validated records * @param array $deleteItems returns the array of model for deleting * @param array $masterValues attributes to assign before saving * @param array $formData (default = $_POST) * @return boolean */ public static function validate($model, &$validatedItems, &$deleteItems = array(), $masterValues = array(), $formData = null) { $widget = new MultiModelForm(); $widget->model = $model; $widget->checkModel(); if (!$widget->initItems($validatedItems, $deleteItems, $masterValues, $formData)) { return false; } else { return true; } }
/** * Validates submitted formdata * If a record is not valid, the invalid model will be set to $model * to display error summary * * @param mixed $model * @param array $validatedItems returns the array of validated records * @param array $deleteItems returns the array of model for deleting * @param array $masterValues attributes to assign before saving * @param array $formData (default = $_POST) * @param null $masterModel the instance of the mastermodel will be submitted to the mmfCallbacks (fileupload, ...) * @param array $initAttributes assign virtual attributes, which are not part of attributenames and will not be assigned by setAttributes * @return bool */ public static function validate($model, &$validatedItems, &$deleteItems = array(), $masterValues = array(), $formData = null, $masterModel = null, $initAttributes = array()) { $widget = new MultiModelForm(); $widget->model = $model; $widget->masterModel = $masterModel; $widget->checkModel(); if (!$widget->initItems($validatedItems, $deleteItems, $masterValues, $formData, $initAttributes)) { $widget->saveUploadedFiles(); //saves files only if the fileattribute has no errors return false; //at least one item is not valid } else { return $widget->saveUploadedFiles(); } }
?> </th> <th> <label>Sin iva</label> <input type="checkbox" id="iva"/> </th> </table> <div class="table-responsive"> <table class="table"> <?php echo CHtml::script('function alertIds(newElem,sourceElem) {alert(newElem.attr("id"));}'); $memberFormConfig = array('elements' => array('CodProducto' => array('type' => 'text', 'size' => '10', 'maxlength' => 10, 'style' => 'WIDTH:100px', 'readonly' => TRUE, 'class' => 'CodProducto'), 'Descripcion' => array('type' => 'zii.widgets.jui.CJuiAutoComplete', 'source' => $this->createUrl('compra/autocomplete'), 'options' => array('showAnim' => 'fold', 'common_id_string' => 'Descripcion', 'size' => '120', 'minLength' => '2', 'select' => "js:function(event, ui) { \n var nomobj_texto = this.id; //El identificador del campo en mi caso #Detallecompra_Descripcion \n var indexid = nomobj_texto.substring(25,nomobj_texto.length); \n \$('#Detallecompra_CodProducto'+indexid).val(ui.item.id); \n \$('#Detallecompra_Precio'+indexid).val(ui.item.Precio); \n \$('#Detallecompra_UniMedida'+indexid).val(ui.item.UniMedida);\n \$('#Detallecompra_Saldo'+indexid).val(ui.item.Saldo); \n \$('#Detallecompra_Descuento'+indexid).val(0);\n \$('#Detallecompra_Exento'+indexid).val(0);\n \$('#contador').html(indexid);\n }"), 'htmlOptions' => array('size' => 30, 'onFocus' => "init(this.id)", 'placeholder' => 'Buscar ...', 'title' => 'Indique el producto.')), 'Cantidad' => array('type' => 'text', 'maxlength' => 8, 'size' => 8, 'style' => 'WIDTH:70px', 'class' => 'Cantidad'), 'Precio' => array('type' => 'text', 'maxlength' => 8, 'size' => 8, 'style' => 'WIDTH:70px', 'class' => 'Precio'), 'UniMedida' => array('type' => 'text', 'maxlength' => 8, 'size' => 8, 'style' => 'WIDTH:70px', 'readonly' => TRUE, 'class' => 'UniMedida'), 'Iva' => array('type' => 'text', 'maxlength' => 8, 'size' => 8, 'style' => 'WIDTH:70px', 'class' => 'Iva'), 'Descuento' => array('type' => 'text', 'maxlength' => 8, 'size' => 8, 'style' => 'WIDTH:70px', 'class' => 'Descuento'), 'Exento' => array('type' => 'text', 'maxlength' => 10, 'size' => 8, 'style' => 'WIDTH:70px', 'class' => 'Exento'), 'Subtotal' => array('type' => 'text', 'maxlength' => 10, 'size' => 8, 'style' => 'WIDTH:70px', 'class' => 'Subtotal', 'readonly' => true), 'Saldo' => array('type' => 'text', 'maxlength' => 10, 'size' => 8, 'style' => 'WIDTH:70px', 'readonly' => true, 'class' => 'Saldo'))); $this->widget('ext.multimodelform.MultiModelForm', array('id' => 'id_member', 'formConfig' => $memberFormConfig, 'model' => $member, 'tableView' => true, 'validatedItems' => $validatedMembers, 'jsAfterNewId' => MultiModelForm::afterNewIdAutoComplete($memberFormConfig['elements']['Descripcion']), 'data' => $member->findAll('NumCompra=:groupId', array(':groupId' => $model->NumCompra)), 'showAddItemOnError' => false, 'addItemText' => 'Agregar', 'removeText' => 'Eliminar', 'removeConfirm' => '¿ Eliminar el producto seleccionado ?')); ?> </table> </div> <div class="table-responsive"> <table class="table"> <tr> <?php echo $form->labelEx($model, 'TotIva'); ?> <?php echo $form->textField($model, 'TotIva', array('size' => 10, 'maxlength' => 10)); ?>