Yii 1.1: ejqcalculator

Yii framework extension to support jquery jq-calculator plugin.
6 followers

EJqCalculator

Extensions for the yii framework to support jquery jq-calculator plugin.

  • author Dimitrios Mengidis
  • version 0.1.2

Jquery plugin

  • JQ-Calculator formula track.
  • 2011 Andreas Geissel.

"Sometimes the fields of a form are part of a chain of a calculation. For example, when the price of an order position changes, its price including tax should be recalculated. Then the total price (including other additional costs) should also be updated. This means each input element (text, select box, ...) needs an onChange (or onBlur) function that recalculates the new results and triggers other (dependent) fields to update themselves."

Use

<table>
    <tr>
        <td>
            <input type="text" name='l[0]'/>
        </td>
        <td>
            <input type="text" name='r[0]'/>
        </td>
        <td>
            <input type="text" id='sum0' />
        </td>
    </tr>
    <tr>
        <td>
            <input type="text" name='l[1]'/>
        </td>
        <td>
            <input type="text" name='r[1]' />
        </td>
        <td>
            <input type="text" id='sum1' />
        </td>
    </tr>
    <tr>
        <th colspan='2'>
         Total Sum
        </th>
        <td>
            <input type="text" id='total'/>
        </td>
    </tr>
</table>
 
<?php $this->widget('application.extensions.EJqCalculator.EJqCalculator', array(
   'addFormula'=>array(
       '#sum0'=>'{{l[0]}} * {{r[0]}}',
       '#sum1'=>'{{l[1]}} * {{r[1]}}',
       '#total'=>'{{#sum0}} + {{#sum1}}'
   ),
));?>

For more information on how to use this extension please visit the EJqCalculator demo.

Resources

Changelog

Version 0.1.1

  • Documentation added.
  • Change of the properties passed to widget structure.

Version 0.1

  • Initial release.

Total 1 comment

#10612 report it
Donatus at 2012/11/08 02:30am
Browsers, Firefox, IE, e.t.c

Hi, this extension does not work in the above mentioned browsers firefox, internet explorer, I have not tried with sea-monkey, opera and safari.. but below is my code

<div class="form">
<?php  $form=$this->beginWidget(
       'application.widget.EActiveForm',
    array('id'=>'accountnum-form',
    'enableAjaxValidation'=>false,)
); ?>
 
    <?php echo $form->errorSummary($model); ?> 
    <div class="row">
    <table>
    <tr>
    <td>
    <?php echo $form->labelEx($model,'customerid'); ?>
    <?php $rr = Yii::app()->request->requestUri; ?>
     <?php $rt = CHtml::normalizeUrl(array(Yii::app()->controller->getId().'/'.Yii::app()->controller->getAction()->getId())); ?>
     <?php $cus =  str_replace($rt."/","",$rr); 
           $nam = CustomerDetails::model()->findBySql("SELECT * FROM customerdetails WHERE ContractNo ='$cus'")->FirstName;
           $totdebit = CustomerDetails::model()->findBySql("SELECT * FROM customerdetails WHERE ContractNo ='$cus'")->BalTotalDebit;
           $totcredit = CustomerDetails::model()->findBySql("SELECT * FROM customerdetails WHERE ContractNo ='$cus'")->BalTotalCredit;
           $bal = $totdebit - $totcredit; 
 
     ?> 
    </td>
 
    <td>
    <?php echo $form->labelEx($model,'name'); ?>
    </td>   
    </td>
    <td> 
    <?php echo $form->labelEx($model,'balance'); ?>
    </td>
    </tr>
    <tr>
    <td>
    <?php echo $form->textField($model,'customerid',array('readonly'=>'readonly','value'=>$cus,'size'=>13,'maxlength'=>20,'style'=>'height:24px;width:80px;font-size:0.9em;',)); ?>
    </td>
    <td>
    <?php echo $form->textField($model,'name',array('disabled'=>true,'value'=>$nam,'style'=>'height:24px;width:200px;font-size:0.9em;')); ?>
    </td>
 
    <td>
    <?php  echo $form->textField($model,'balance',array('disabled'=>true,'value'=>number_format($bal,2,".",","),'size'=>16,'maxlength'=>25,'style'=>'height:24px;width:100px;font-size:0.9em;',)); ?>
    &nbsp; &nbsp;
    </td>   
    </tr>
    </table>
    <table>
    <tr>
    <td>
    <?php echo $form->labelEx($model,'amount'); ?>
    </td>
    <td>
    <?php echo $form->labelEx($model,'amountreceived'); ?>
    </td>
    <td>
    <?php echo $form->labelEx($model,'modeopay'); ?>
    </td>
    <td>
    <?php echo $form->labelEx($model,'refnum'); ?>
    </td>   
    </tr>
    <tr>
    <td>
    <?php echo $form->textField($model,'amount',array('id'=>'amount','style'=>'height:24px;width:100px;font-size:0.9em;')); ?>
    </td>
    <td>
    <?php echo $form->textField($model,'amountreceived',array('id'=>'amountreceived','style'=>'height:24px;width:100px;font-size:0.9em;')); ?>
    </td>
    <td>
    <?php 
    $conncc = "TableID = 'MODE'";
    echo $form->dropDownList($model,'modeopay',CHtml::listData(Lookup::model()->findAll(array('condition'=>$conncc,'order' => 'LineLongDefn ASC')),'LineID','LineShortDefn'),array('style'=>'height:24px;width:120px;font-size:1.0em;')); ?>
    </td>
    <td>
    <?php echo $form->textField($model,'refnum',array('style'=>'height:24px;width:100px;font-size:0.9em;')); ?>
    </td>   
    </tr>
        <tr>
    <td>
     <strong>Batch Total</strong><br>
     <?php echo $form->textField($model,'amountt',array('id'=>'amountt','readonly'=>'readonly','style'=>'height:24px;width:100px;font-size:0.9em;')); ?>
 
    </td>
    <td>
     <strong>Change Due </strong><br> 
     <?php echo $form->textField($model,'difff',array('id'=>'difff','readonly'=>'readonly','style'=>'height:24px;width:100px;font-size:0.9em;')); ?>
 
<?php 
$this->widget('application.extensions.EJqCalculator.EJqCalculator', array(
   'addFormula'=>array(
        '#amountt'=>'{{amount}}',
       '#difff'=>'{{amountreceived}} - {{amount}}',
 
   ),
)); 
 
 
 
?>
 
    </td>
    <td>
     <?php echo CHtml::Button('Cancel',array('submit' => array('payments/index'))); ?>
    </td>
    <td>
 
       <?php echo CHtml::submitButton('Update'); ?> 
    </td>   
    </tr>
    </table>
    </div>
<?php $this->endWidget(); 
 
 ?>
</div><!-- form -->

Leave a comment

Please to leave your comment.

Create extension