column and row wise total calculation with array in php or joomla custom component with jQuery

IN Html section

<script src=”http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js&#8221; type=”text/javascript” charset=”utf-8″></script>
<script>

$(document).ready(function() {

$(“input”).click(function(event) {

var id = $(this).closest(‘td’).attr(‘id’);
// alert(id);
var menuid = id.replace(“menu_”,””);
updateTotal(menuid);
});

//    multiplyer
$(“input[name=’multiplyer[]’]”).blur(function(event) {
var value = $(this).val();
//alert(value);
var textid = $(this).attr(‘id’);
var multiplyerid = textid.replace(“multiplyer_”,””);
var parentpriece =  $(‘#parentprice_’+multiplyerid).val();
var ttto = parentpriece*value;
var id = $(this).closest(‘td’).attr(‘id’);
// alert(id);
var menuid = id.replace(“menu_”,””);
//$(‘#totalprice’+menuid).val(ttto.toFixed(2));
$(‘#docfile’+multiplyerid).val(multiplyerid+’_’+ttto+’_’+value);
$(“#”+textid).click();
});

$(“input[name=’multiplyer[]’]”).click(function(event) {
var value = $(this).val();
//alert(value);
var textid = $(this).attr(‘id’);
var multiplyerid = textid.replace(“multiplyer_”,””);
var parentpriece =  $(‘#parentprice_’+multiplyerid).val();
var ttto = parentpriece*value;
var id = $(this).closest(‘td’).attr(‘id’);
// alert(id);
var menuid = id.replace(“menu_”,””);
//$(‘#totalprice’+menuid).val(ttto.toFixed(2));
$(‘#docfile’+multiplyerid).val(multiplyerid+’_’+ttto+’_’+value);
$(‘#multi_’+multiplyerid).text(ttto);
//select_price(multiplyerid,value);
$(“#”+textid).focus();
});

});

function updateTotal(id) {
//alert(id);
var total = 0;
var url = ”;
var multi = ”;
var nnn= 0;
$(“#menu_”+id+” input:checked”).each(function() {
var mainval = this.value;
var priceval = mainval.split(“_”);;
//alert(priceval[2]*priceval[1]);
//alert(priceval[1]);
total += parseFloat(priceval[1]);
url = url + ‘&’ + priceval[0];
multi = multi + ‘&’ + priceval[2];
// var mtot = parseFloat(priceval[1] * priceval[2]);
//alert(mtot);
//nnn = nnn + ‘&’ +( priceval[2]*priceval[1]);
});

//url string
$(‘#docdetailid’+id).val(url);
//total
$(‘#totalprice’+id).val(total.toFixed(2));
// multiplyer
$(‘#docmultiprice’+id).val(multi);
//indivisual total
//$(‘#indprice’+id).val(nnn.toFixed(2));
}

$(document).ready(function () {
$(‘#myLink’).click(function () {
$(“input[id^=’priceid’]”).attr(‘checked’, $(‘#myLink’).is(‘:checked’));
});
});

$(document).ready(function () {
$(‘#sendinvoice’).click(function () {
if (!$(‘input[name=”priceid[]”]’).is(‘:checked’)) {
$(“#invoiceerror”).fadeIn().text(“You must check at least one option.”);
return false;
}

});

});

</script>

<form name=”docf” id=”docf” method=”post” action=”<?php echo JRoute::_(‘index.php?option=com_support&task=file.savaprice’); ?>”>

<table width=”100%” border=”1″ cellspacing=”2″ cellpadding=”2″>

<tr>

<td><input type=”checkbox” id=”myLink”  /></td>

<td><strong>Tax File No </strong></td>

<td>files</td>

<td>Price</td>

</tr>

<?php foreach ($this->items as $i => $item) :?>

<tr>

<td><input type=”checkbox” name=”priceid[]” value=”<?php print $item->id?>” id=”priceid” /></td>

<td><a href=”<?php echo JRoute::_(‘index.php?option=com_support&view=file&id=’ . (int)$item->id); ?>”><b><?php echo $item->wintaxno; ?></b></a>

<input type=”hidden”  value=”<?php echo $item->wintaxno; ?>” name=”wintaxno[]”   />

<input type=”hidden”  value=”<?php echo $taxyear; ?>” name=”taxyear[]”   />

</td>

<td id=”menu_<?php print $item->id?>”>

<?php

$db =& JFactory::getDBO();

$sql = “SELECT * FROM #__support_docdetail where parent_id=0 order by id,parent_id asc”;

//print $sql;

$db->setQuery($sql);

$db->query();

$docdetail = $db->loadObjectList();

foreach($docdetail as $doc):

if($doc->is_parent==”N”):

?>

<input name=”docfile[]” type=”checkbox” value=”<?php print $doc->id ?>_<?php print $doc->price ?>_1″ />

<?php print $doc->doclabel ?>&nbsp;&nbsp;$(<?php print $doc->price ?>)<br />

<?php else:?>

<input name=”docfile[]” type=”checkbox” disabled=”disabled” checked=”checked” value=”<?php print $doc->id ?>_<?php print $doc->price ?>_1″ />

<?php print $doc->doclabel ?><br />

<?php

$db =& JFactory::getDBO();

$sql = “SELECT * FROM #__support_docdetail where parent_id=”.$doc->id;

//print $sql;

$db->setQuery($sql);

$db->query();

$docdetailparent = $db->loadObjectList();

foreach($docdetailparent as $docparent):

?>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input name=”docfile[]” type=”checkbox” value=”<?php print $docparent->id ?>_<?php print $docparent->price ?>_0″ id=”docfile<?php print $docparent->id ?>” />

<?php print $docparent->doclabel ?>&nbsp;&nbsp;$(<?php print $docparent->price ?>)&nbsp;&nbsp;x&nbsp;&nbsp;

<input type=”hidden” name=”parent_price[]” id=”parentprice_<?php print $docparent->id ?>” value=”<?php print $docparent->price ?>” />

<input type=”text” name=”multiplyer[]” id=”multiplyer_<?php print $docparent->id ?>” size=”5″ value=”1″ style=”width:30px; text-align:right” /> = <span id=”multi_<?php print $docparent->id ?>”><?php print $docparent->price ?></span><br />

<?php  endforeach; ?>

<?php endif; ?>

<?php endforeach; ?>

<input type=”hidden”  value=”” name=”docdetailid[]” id=”docdetailid<?php print $item->id?>”  />

<input type=”hidden”  value=”” name=”docmultiprice[]” id=”docmultiprice<?php print $item->id?>”  />

<input type=”text”  value=”” name=”indprice[]” id=”indprice<?php print $item->id?>”  />

</td>

<td><input type=”text” readonly=”readonly” value=”” name=”totalprice[]” id=”totalprice<?php print $item->id?>” size=”10″ style=”width:50px;” /></td>

</tr>

<?php endforeach; ?>

<tr><td colspan=”4″ align=”right”><input type=”submit” id=”sendinvoice” value=”Send Invoice” name=”submit” /></td></tr>

</table>

<input type=”hidden” name=”option” value=”com_support” />

<input type=”hidden” name=”task” value=”file.savaprice” />

<?php echo JHtml::_(‘form.token’); ?>

</form>

IN php with save record

public function savaprice()

{
JSession::checkToken() or jexit(JText::_(‘JINVALID_TOKEN’));
//print_r($_REQUEST);

foreach ($_POST[‘doc_id’] as $row=>$id)
{
$id = $id;
$totalprice = $_POST[‘totalprice’][$row];
$multiplyer = $_POST[‘multiplyer’][$row];

$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->insert(‘#__support_docprice’);
$query->set(“file_id='”.$id.”‘, docfile='”.$docfile.”‘,price='”.$totalprice.”‘,multiplyer='”.$multiplyer.”‘,wintaxno='”.$_REQUEST[‘wintaxno’].”‘,taxyear='”.$_REQUEST[‘taxyear’].”‘,federalposition='”.$_REQUEST[‘federalposition’].”‘,stateposition='”.$_REQUEST[‘stateposition’].”‘,taxtotal='”.$_REQUEST[‘taxtotal’].”‘,sut='”.$_REQUEST[‘sut’].”‘,pt='”.$_REQUEST[‘pt’].”‘,mat='”.$_REQUEST[‘mat’].”‘,withfederalposition='”.$_REQUEST[‘withfederalposition’].”‘,withstateposition='”.$_REQUEST[‘withstateposition’].”‘,cityposition='”.$_REQUEST[‘cityposition’].”‘,withcityposition='”.$_REQUEST[‘withcityposition’].”‘ “);
//print $query;
$db->setQuery($query);
$db->query();
}$this->setMessage(JText::_(‘Item saved successfully’));

$this->setRedirect(JRoute::_(‘index.php?com_support&view=files&layout=userlist’, false));

}

 

Advertisements

One thought on “column and row wise total calculation with array in php or joomla custom component with jQuery

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s