Thanks Steve for your help...
seems that 1.3.2 3355 does not support updating multiple tables during the save.
So... let's php this problem and be done with it...
So here's the the method via php and sql...
I have a table named payments, tables/payments/payments.php
There are records in the invoice record that need to be updated at the same time...
I need to be able to make a payment without having to view all "related CRAP"
Just want to make a payment and update fields in two tables... simple nuff...here ya go
tables/payments/payments.php - be sure to clean out your templates_c folder... This set me back a whole day...
- Code: Select all
<?php
//include('money_format.php'); //this is only used on my dev box... server 2008 - xampp
function after_action_new($params=array()){
$record =& $params['record'];
$a = $record->val('invoiceid');
$c = $record->val('amount');
header('Location:update.php?id='.$a.'&amount='.$c);
exit;
}
function __sql__(){
$query = $_GET["action"];
if ( $query == 'partial') {
//return "select * FROM invoice WHERE total > payment1";
}
else {
//return "SELECT i.*,if(i.total>i.payment1,1,0) as balance FROM `invoice` i ORDER BY id DESC";
}
}
function amount__display($record){
return money_format('$%i', $record->val('amount'));
}
function tax__display($record){
return money_format('$%i', $record->val('tax'));
}
function block__before_left_column(){
echo "<div id=\"invoice-sidebar\">
<h4>Tasks</h4><br />";
include('pay_dropdown.php');
echo "</div>";
}
}
There is probably a better Xataface way to do this but... I had to get it done...
update.php Code
- Code: Select all
<?php
include('config.php');
$myid = $_REQUEST[id];
echo 'Invoice No' . $myid;
echo '<br />';
$mydate = date("Y-m-d");
echo 'Invoice Date' . $mydate;
echo '<br />';
$amt = $_REQUEST[amount];
echo 'Invoice Amount' . $amt;
echo '<br />';
$con = mysql_connect($myserver,$username,$password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db($database, $con);
$sql="UPDATE invoice SET payment1='$amt',paymentdate1='$mydate' WHERE id='$myid'";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
mysql_close($con)
?>
<a href="index.php?-table=invoice">Continue</a>
Just in case others have their dev environment on a windows box... here is
the code for money_format: just be sure to comment out for linux-unix host:
- Code: Select all
<?php
function money_format($format, $number) {
$regex = '/%((?:[\^!\-]|\+|\(|\=.)*)([0-9]+)?'.
'(?:#([0-9]+))?(?:\.([0-9]+))?([in%])/';
if (setlocale(LC_MONETARY, 0) == 'C') {
setlocale(LC_MONETARY, '');
}
$locale = localeconv();
preg_match_all($regex, $format, $matches, PREG_SET_ORDER);
foreach ($matches as $fmatch) {
$value = floatval($number);
$flags = array(
'fillchar' => preg_match('/\=(.)/', $fmatch[1], $match) ?
$match[1] : ' ',
'nogroup' => preg_match('/\^/', $fmatch[1]) > 0,
'usesignal' => preg_match('/\+|\(/', $fmatch[1], $match) ?
$match[0] : '+',
'nosimbol' => preg_match('/\!/', $fmatch[1]) > 0,
'isleft' => preg_match('/\-/', $fmatch[1]) > 0
);
$width = trim($fmatch[2]) ? (int)$fmatch[2] : 0;
$left = trim($fmatch[3]) ? (int)$fmatch[3] : 0;
$right = trim($fmatch[4]) ? (int)$fmatch[4] : $locale['int_frac_digits'];
$conversion = $fmatch[5];
$positive = true;
if ($value < 0) {
$positive = false;
$value *= -1;
}
$letter = $positive ? 'p' : 'n';
$prefix = $suffix = $cprefix = $csuffix = $signal = '';
$signal = $positive ? $locale['positive_sign'] : $locale['negative_sign'];
switch (true) {
case $locale["{$letter}_sign_posn"] == 1 && $flags['usesignal'] == '+':
$prefix = $signal;
break;
case $locale["{$letter}_sign_posn"] == 2 && $flags['usesignal'] == '+':
$suffix = $signal;
break;
case $locale["{$letter}_sign_posn"] == 3 && $flags['usesignal'] == '+':
$cprefix = $signal;
break;
case $locale["{$letter}_sign_posn"] == 4 && $flags['usesignal'] == '+':
$csuffix = $signal;
break;
case $flags['usesignal'] == '(':
case $locale["{$letter}_sign_posn"] == 0:
$prefix = '(';
$suffix = ')';
break;
}
if (!$flags['nosimbol']) {
$currency = $cprefix .
($conversion == 'i' ? $locale['int_curr_symbol'] : $locale['currency_symbol']) .
$csuffix;
} else {
$currency = '';
}
$space = $locale["{$letter}_sep_by_space"] ? ' ' : '';
$value = number_format($value, $right, $locale['mon_decimal_point'],
$flags['nogroup'] ? '' : $locale['mon_thousands_sep']);
$value = @explode($locale['mon_decimal_point'], $value);
$n = strlen($prefix) + strlen($currency) + strlen($value[0]);
if ($left > 0 && $left > $n) {
$value[0] = str_repeat($flags['fillchar'], $left - $n) . $value[0];
}
$value = implode($locale['mon_decimal_point'], $value);
if ($locale["{$letter}_cs_precedes"]) {
$value = $prefix . $space . $value . $suffix;
} else {
$value = $prefix . $value . $space . $currency . $suffix;
}
if ($width > 0) {
$value = str_pad($value, $width, $flags['fillchar'], $flags['isleft'] ?
STR_PAD_RIGHT : STR_PAD_LEFT);
}
$format = str_replace($fmatch[0], $value, $format);
}
return $format;
}
?>
Will probably modify the header to automatically return to the needed page.
If you notice there is an include to my connection settings that is in my root...
I will clean up the code and repost the final code...
Thanks for your help
Tim