Okay, this is what I’ve done:
echo CHtml::textField('InvLn_Unit_Qty['.$autoLine->InvALn_ID.']', $model->lineUnits($autoLine->InvALn_ID), array(
'id'=>'InvLn_Unit_Qty_'.$autoLine->InvALn_ID,
'size'=>5,
'style'=>'text-align:right;',
'ajax'=>array(
'type'=>'POST',
'dataType'=>'json',
'url'=>CController::createUrl('totals&id='.$autoLine->InvALn_ID),
'success'=>'updateFields',
)
));
Yii::app()->clientScript->registerScript('updateFields',"
function updateFields(data){
$('#InvLn_Unit_Total_'+data.id).val(data.itemTot);
$('#InvLn_Unit_Comm_'+data.id).val(data.com);
$('#Inv_SL_Sub_Total').val(data.invClSub);
$('#Inv_SL_GST').val(data.clGst);
$('#Inv_SL_Total').val(data.clTot);
$('#Inv_PL_Sub_Total').val(data.plSub);
$('#Inv_PL_GST').val(data.plGst);
$('#Inv_PL_Total').val(data.plTot);
$('#Inv_Com_Amt').val(data.cdcsSub);
$('#Inv_Com_GST').val(data.cdcsGst);
$('#Inv_Com_Total').val(data.cdcsTot);
}
", CClientScript::POS_READY);
And in my controller:
public function actionTotals($id){
$auto = InvoiceLinesAuto::model()->findByPk($id);
$total = $_POST['InvLn_Unit_Qty'][$id]*$_POST['InvLn_Unit_Price'][$id];
$com=$auto->InvALn_Comm_Percent*$total;
$_POST['InvLn_Unit_Total'][$id]=$total;
$_POST['InvLn_Unit_Comm'][$id]=$com;
$invCl=0;
$cdcsSub=0;
foreach($_POST['InvLn_Unit_Total'] as $aId=>$unit){
$invCl+=$unit;
$cdcsSub+=$_POST['InvLn_Unit_Comm'][$aId];
}
$clGst=$auto->InvALn_Tax1*$invCl;
$clTot=$invCl+$clGst-$_POST['Inv_PL_Deductible'];
$plSub=$invCl-$cdcsSub;
$plGst=$auto->InvALn_Tax1*$plSub;
$plTot=$plSub+$plGst-$_POST['Inv_PL_Deductible'];
$cdcsGst=$auto->InvALn_Tax1*$cdcsSub;
$cdcsTot=$cdcsSub+$cdcsGst;
echo CJSON::encode(array(
'id' => $id,
'itemTot' => sprintf('%01.2f', round($total,2)),
'com' => sprintf('%01.2f', round($com,2)),
'invClSub' => sprintf('%01.2f', round($invCl,2)),
'clGst' => sprintf('%01.2f', round($clGst,2)),
'clTot' => sprintf('%01.2f', round($clTot,2)),
'plSub' => sprintf('%01.2f', round($plSub,2)),
'plGst' => sprintf('%01.2f', round($plGst,2)),
'plTot' => sprintf('%01.2f', round($plTot,2)),
'cdcsSub' => sprintf('%01.2f', $cdcsSub),
'cdcsGst' => sprintf('%01.2f', $cdcsGst),
'cdcsTot' => sprintf('%01.2f', $cdcsTot),
));
}
It works. I’m not sure how ‘correct’ it is, but it works.
However, I have a new function where, if I click on a checkbox it will toggle the tax:
<?php echo $form->checkBox($model,'Inv_No_Invoicee_GST', array(
'id'=>'Invoices_Inv_No_Invoicee_GST',
'ajax'=>array(
'type'=>'POST',
'url'=>CController::createUrl('noGst'),
'dataType'=>'json',
'success'=>'noGst',
)
)); ?>
<?php Yii::app()->clientScript->registerScript('noGst',"
function noGst(data){
$('#Invoices_Inv_No_Invoicee_GST').attr('checked', data.inv);
$('#Invoices_Inv_No_Fran_GST').attr('checked', data.fran);
$('#Inv_SL_Total').val(data.clTot);
$('#Inv_SL_GST').val(data.clGst);
$('#Inv_PL_Total').val(data.plTot);
$('#Inv_PL_GST').val(data.plGst);
}
", CClientScript::POS_READY); ?>
And in the controller:
public function actionNoGst(){
$clTot=$_POST['Inv_SL_Total'];
$clGst=$_POST['Inv_SL_GST'];
$plTot=$_POST['Inv_PL_Total'];
$plGst=$_POST['Inv_PL_GST'];
if($_POST['Invoices']['Inv_No_Invoicee_GST']==1){
$clTot=$_POST['Inv_SL_Sub_Total'];
$clGst='0.0';
}
elseif($_POST['Invoices']['Inv_No_Invoicee_GST']==0){
$clGst=round($_POST['Inv_SL_Sub_Total']*Invoices::model()->gstRate,2);
$clTot=round($_POST['Inv_SL_Sub_Total']+$clGst,2);
}
if($_POST['Invoices']['Inv_No_Fran_GST']==1){
$plTot=$_POST['Inv_PL_Sub_Total'];
$plGst='0.0';
}
elseif($_POST['Invoices']['Inv_No_Fran_GST']==0){
$plGst=round($_POST['Inv_PL_Sub_Total']*Invoices::model()->gstRate,2);
$plTot=round($_POST['Inv_PL_Sub_Total']+$plGst,2);
}
echo CJSON::encode(array(
'inv' => $_POST['Invoices']['Inv_No_Invoicee_GST']==1?true:false,
'fran' => $_POST['Invoices']['Inv_No_Fran_GST']==1?true:false,
'clTot'=> sprintf('%01.2f', $clTot),
'clGst'=> sprintf('%01.2f', $clGst),
'plTot'=> sprintf('%01.2f', $plTot),
'plGst'=> sprintf('%01.2f', $plGst),
));
}
And this works perfect in FF/Chrome/Safari, but ie won’t do anything when I check the box. Does anybody know anything about this? My users (for some stupid reason) only use IE.