//<?php
global $modx;
//$id = $modx->documentIdentifier;
$table = 'modx_site_tmplvar_contentvalues';
$query = 'SELECT value from '.$table.' WHERE tmplvarid = 27 AND contentid = '.$id.'';
$rs = $modx->db->query($query);
while( $row = $modx->db->getRow($rs) ) {
if($row['value']!= '') {
$price_without_vat = $row['value'];
$vat = 17.5; // define % vat
$price = ($price_without_vat + ($vat*($price_without_vat/100))); // work out the amount of vat
$price_with_vat = round($price, 2); // round to 2 decimal places
// $output = $price_with_vat; // the final price with VAT added
//echo $output;
// update the with VAT price field in the incVAT tv
$e = &$modx->Event;
switch ($e->name) {
case "OnDocFormSave":
$fields = array('value' => $price_with_vat);
$modx->db->update( $fields, $table, 'tmplvarid = 28', 'contentid = "'.$id.'"' );
//print_r($price_with_vat);
//print_r($fields);
//print_r($id);
break;
default :
return; // stop here - this is very important.
break;
}
} else {
return; // stop
break;
}
}
return; // stop
break;
//?>
//<?php
$table = 'modx_site_tmplvar_contentvalues';
// update the with VAT price field in the incVAT tv
$e = &$modx->Event;
switch ($e->name) {
case "OnDocFormSave":
$query = 'SELECT value from '.$modx->getFullTableName('site_tmplvar_contentvalues').' WHERE tmplvarid = 27 AND contentid = '.$id.'';
$rs = $modx->db->query($query);
if($rs) {
$row = $modx->fetchRow($rs);
$price_without_vat = $row['value'];
$vat = 17.5; // define % vat
$price = ($price_without_vat + ($vat*($price_without_vat/100))); // work out the amount of vat
$price_with_vat = round($price, 2); // round to 2 decimal places
//$output = $price_with_vat; // the final price with VAT added
//echo $output;
$query2 = 'SELECT value from '.$modx->getFullTableName('site_tmplvar_contentvalues').' WHERE tmplvarid = 28 AND contentid = '.$id.'';
$rs2 = $modx->db->query($query2);
if($rs2) {
$row2 = $modx->fetchRow($rs2);
$exists = $row2['value'];
print_r($exists);
if($exists) {
$fields = array('value' => $price_with_vat);
$modx->db->update( $fields, $table, 'tmplvarid = 28', 'contentid = "'.$id.'"' );
} else {
$fields = array('value' => $price_with_vat, 'tmplvarid' => '28', 'contentid' => $id);
$modx->db->insert( $fields, $table);
}
//print_r($price_with_vat);
//print_r($fields);
//print_r($id);
}
break;
default: '';
return; // stop here - this is very important.
}
//?>
//<?php
$table = 'modx_site_tmplvar_contentvalues';
// update the with VAT price field in the incVAT tv
$e = &$modx->Event;
switch ($e->name) {
case "OnDocFormSave":
$query = 'SELECT value from '.$modx->getFullTableName('site_tmplvar_contentvalues').' WHERE tmplvarid = 27 AND contentid = '.$id.'';
$rs = $modx->db->query($query);
if($rs) {
$row = $modx->fetchRow($rs);
$price_without_vat = $row['value'];
$vat = 17.5; // define % vat
$price = ($price_without_vat + ($vat*($price_without_vat/100))); // work out the amount of vat
$price_with_vat = round($price, 2); // round to 2 decimal places
//$output = $price_with_vat; // the final price with VAT added
//echo $output;
$query2 = 'SELECT value from '.$modx->getFullTableName('site_tmplvar_contentvalues').' WHERE tmplvarid = 28 AND contentid = '.$id.'';
$rs2 = $modx->db->query($query2);
if($rs2) {
$row2 = $modx->fetchRow($rs2);
$exists = $row2['value'];
if($exists) {
$fields = array('value' => $price_with_vat);
$modx->db->update( $fields, $table, 'tmplvarid = 28', 'contentid = "'.$id.'"' );
} else {
$fields = array('value' => $price_with_vat, 'tmplvarid' => '28', 'contentid' => $id);
$modx->db->insert( $fields, $table);
}
//print_r($exists);
}else{
break;
default: '';
return; // stop here - this is very important.
}
break;
default: '';
return; // stop here - this is very important.
}
//?>
<?php
// table name
$table = $modx->getFullTableName('site_tmplvar_contentvalues');
// names of the tvs
$tv_no_vat ='price_no_vat';
$tv_w_vat ='price_w_vat';
// id of the price with vat
$tv_w_vat_id ='2';
// tax amount
$vat = 17.5;
$e = &$modx->Event;
switch ($e->name) {
case "OnDocFormSave":
$vat = 17.5;
$tv = $modx->getTemplateVarOutput(array($tv_no_vat, $tv_w_vat), $docid=$id);
if($tv[$tv_no_vat] !=''){
$price = $tv[$tv_no_vat] + ($vat*($tv[$tv_no_vat]/100));
$price_with_vat = round($price, 2);
//$fields = array('value' => $price_with_vat);
if($tv[$tv_w_vat] ==''){
$fields = array('value' => $price_with_vat, 'tmplvarid' => $tv_w_vat_id, 'contentid' => $id);
$modx->db->insert( $fields, $table);
}else{
$fields = array('value' => $price_with_vat);
$modx->db->update( $fields, $table, 'tmplvarid='.$tv_w_vat_id.' AND contentid='.$id );
}
}
break;
default: '';
return; // stop here - this is very important.
}
<?php
// table name
$table = $modx->getFullTableName('site_tmplvar_contentvalues');
// names of the tvs
$tv_no_vat ='price_no_vat';
$tv_w_vat ='price_w_vat';
// id of the price with vat
$tv_w_vat_id ='13';
// tax amount
$vat = 17.5;
$tv = $modx->getTemplateVarOutput(array($tv_no_vat, $tv_w_vat), $docid=$id);
if($tv[$tv_no_vat] !=''){
$price = $tv[$tv_no_vat] + ($vat*($tv[$tv_no_vat]/100));
$price_with_vat = round($price, 2);
//$fields = array('value' => $price_with_vat);
if($tv[$tv_w_vat] ==''){
$fields = array('value' => $price_with_vat, 'tmplvarid' => $tv_w_vat_id, 'contentid' => $id);
$modx->db->insert( $fields, $table);
}else{
$fields = array('value' => $price_with_vat);
$modx->db->update( $fields, $table, 'tmplvarid='.$tv_w_vat_id.' AND contentid='.$id );
}
}[2010-08-27 11:02:18] (ERROR @ /homez.40/ideesimp/pizza-du-lion/core/model/modx/modtemplatevar.class.php : 422) PHP warning: DirectoryIterator::__construct(/homez.40/ideesimp/pizza-du-lion/core/model/modx/processors/element/tv/renders/mgr/output/) [<a href='directoryiterator.--construct'>directoryiterator.--construct</a>]: failed to open dir: No such file or directory [2010-08-27 11:02:18] (ERROR @ /homez.40/ideesimp/pizza-du-lion/core/model/modx/modtemplatevar.class.php : 422) PHP warning: DirectoryIterator::__construct(/homez.40/ideesimp/pizza-du-lion/core/model/modx/processors/element/tv/renders/mgr/output/) [<a href='directoryiterator.--construct'>directoryiterator.--construct</a>]: failed to open dir: No such file or directory