Esempio n. 1
0
 /**
  * add item to invoice
  * @param array $item
  * @return int fiit_id
  */
 public function insertInvoiceItem($item)
 {
     $fiit = new FiitInvoiceItem();
     $fiit->attributes = $item;
     $fiit->fiit_finv_id = $this->finv_id;
     try {
         if (!$fiit->save()) {
             $this->fiit[] = $fiit;
             return FALSE;
         }
         $this->fiit[] = $fiit;
     } catch (Exception $e) {
         $fiit->addError('fiit_id', $e->getMessage());
         $this->fiit[] = $fiit;
         return FALSE;
     }
     return $fiit->fiit_id;
 }
            ');
}
if (!$ajax || $ajax == 'fiit-invoice-item-grid') {
    Yii::beginProfile('fiit_fqnt_id.view.grid');
    ?>

<h3 class="rel_grid">    
    <?php 
    echo Yii::t('D2finvModule.model', 'Fiit Invoice Item');
    ?>
    <?php 
    $this->widget('bootstrap.widgets.TbButton', array('buttonType' => 'ajaxButton', 'type' => 'primary', 'size' => 'mini', 'icon' => 'icon-plus', 'url' => array('//d2finv/fiitInvoiceItem/ajaxCreate', 'field' => 'fiit_fqnt_id', 'value' => $modelMain->primaryKey, 'ajax' => 'fiit-invoice-item-grid'), 'ajaxOptions' => array('success' => 'function(html) {$.fn.yiiGridView.update(\'fiit-invoice-item-grid\');}'), 'htmlOptions' => array('title' => Yii::t('D2finvModule.crud_static', 'Add new record'), 'data-toggle' => 'tooltip')));
    ?>
</h3> 
 
<?php 
    if (empty($modelMain->fiitInvoiceItems)) {
        $model = new FiitInvoiceItem();
        $model->fiit_fqnt_id = $modelMain->primaryKey;
        $model->save();
        unset($model);
    }
    $model = new FiitInvoiceItem();
    $model->fiit_fqnt_id = $modelMain->primaryKey;
    // render grid view
    $this->widget('TbGridView', array('id' => 'fiit-invoice-item-grid', 'dataProvider' => $model->search(), 'template' => '{summary}{items}', 'summaryText' => '&nbsp;', 'htmlOptions' => array('class' => 'rel-grid-view'), 'columns' => array(array('class' => 'editable.EditableColumn', 'name' => 'fiit_finv_id', 'editable' => array('type' => 'select', 'url' => $this->createUrl('//d2finv/fiitInvoiceItem/editableSaver'), 'source' => CHtml::listData(FinvInvoice::model()->findAll(array('limit' => 1000)), 'finv_id', 'itemLabel'))), array('class' => 'editable.EditableColumn', 'name' => 'fiit_desc', 'editable' => array('type' => 'textarea', 'url' => $this->createUrl('//d2finv/fiitInvoiceItem/editableSaver'))), array('class' => 'editable.EditableColumn', 'name' => 'fiit_debet_facn_code', 'editable' => array('url' => $this->createUrl('//d2finv/fiitInvoiceItem/editableSaver'))), array('class' => 'editable.EditableColumn', 'name' => 'fiit_credit_facn_code', 'editable' => array('url' => $this->createUrl('//d2finv/fiitInvoiceItem/editableSaver'))), array('class' => 'editable.EditableColumn', 'name' => 'fiit_fprc_id', 'editable' => array('type' => 'select', 'url' => $this->createUrl('//d2finv/fiitInvoiceItem/editableSaver'), 'source' => CHtml::listData(FprcProductCategory::model()->findAll(array('limit' => 1000)), 'fprc_id', 'itemLabel'))), array('class' => 'editable.EditableColumn', 'name' => 'fiit_quantity', 'editable' => array('url' => $this->createUrl('//d2finv/fiitInvoiceItem/editableSaver'))), array('class' => 'editable.EditableColumn', 'name' => 'fiit_price', 'editable' => array('url' => $this->createUrl('//d2finv/fiitInvoiceItem/editableSaver'))), array('class' => 'editable.EditableColumn', 'name' => 'fiit_amt', 'editable' => array('url' => $this->createUrl('//d2finv/fiitInvoiceItem/editableSaver'))), array('class' => 'TbButtonColumn', 'buttons' => array('view' => array('visible' => 'FALSE'), 'update' => array('visible' => 'FALSE'), 'delete' => array('visible' => 'Yii::app()->user->checkAccess("D2finv.FqntQuantity.DeletefiitInvoiceItems")')), 'deleteButtonUrl' => 'Yii::app()->controller->createUrl("/d2finv/fiitInvoiceItem/delete", array("fiit_id" => $data->fiit_id))', 'deleteButtonOptions' => array('data-toggle' => 'tooltip')))));
    ?>

<?php 
    Yii::endProfile('FiitInvoiceItem.view.grid');
}
 public function actionAjaxCreate($field, $value)
 {
     $model = new FiitInvoiceItem();
     $model->{$field} = $value;
     try {
         if ($model->save()) {
             return TRUE;
         } else {
             return var_export($model->getErrors());
         }
     } catch (Exception $e) {
         throw new CHttpException(500, $e->getMessage());
     }
 }