This topic is locked
[SOLVED]

 Currency credit in red

11/29/2011 6:46:28 AM
PHPRunner General questions
V
vettold author

In phprunner I am trying to make US currency appear in red when there is a credit. Many of my customers have credit balances and I would like it to be highlighted in red color. I understand that in the visual editor I would go to view as and use custom. I need it to stay as currency and do not know how to customize it.
Thanks

C
cgphp 11/29/2011

In the "List page: After record processed" event enter this code:

$record["fieldname_style"].='style="color:red"';



where fieldname is the name of currecy field.

V
vettold author 11/29/2011

I only want it red if the balance is a credit or a negative amount.

C
cgphp 11/29/2011
if($data['balance'] < 0)

{

$record["fieldname_style"].='style="color:red"';

}
V
vettold author 11/29/2011

Will this retain its currency code? I need ($200.00)

C
cgphp 11/29/2011

Try it.

V
vettold author 11/29/2011

I tried before and after event with code below and neither puts the credit balance in red.
if($data['balance'] < 0)

{

$record["fieldname_style"].='style="color:red"';

}

*****
Then I tried this code in before and after event. I changed "fieldname_style" to "balance_style"
if($data['balance'] < 0)

{

$record["balance_style"].='style="color:red"';

}
The after events makes all balances red. The before event does nothing.

Now all balances are in red including the positive balances when the above code is used in after event.

C
cgphp 11/29/2011

I said the List page: After record processed event.



if($data['fieldname'] < 0)

{

$record["fieldname_style"].='style="color:red"';

}



Replace fieldname with the name of the balance field.

V
vettold author 11/29/2011

This is the code I am using:
if($data['balance'] < 0)

{

$record["balance_style"].='style="color:red"';

}

*****
It is in List page: after record processed.

balance is the name of the fieldname and as you can see I replaced fieldname with "balance"

"balance" is the name of the field in the table.

C
cgphp 11/29/2011

What is the type of the balance field in the database ?

V
vettold author 11/29/2011

varchar(255)

C
cgphp 11/29/2011

It should be a float to check if it is < 0

7542 11/29/2011

I would go to the visual editor, choose custom field and add the following code
if($value < 0)
{

$value = "<font color=red>$".$value."</font>";

}

else

{

$value = "$".$value."";

}

V
vettold author 11/29/2011

just tried and phpmyadmin says :
Error

SQL query:
ALTER TABLE DET BAL ANAL CHANGE balance balance FLOAT( 255 ) NULL DEFAULT NULL
MySQL said:

1063 - Incorrect column specifier for column 'balance'

7542 11/29/2011

I tried the code before I posted
did you apply the code to the custom field on the visual editor?

V
vettold author 11/29/2011

you did it! Now is it possible to limit it to 2 decimal places?
Your patience is admirable. This forum keeps many people who do not fully understand code from committing suicide!

C
cgphp 11/29/2011

In phpmyadmin set the length of the balance field to 10,2 not 255.

V
vettold author 11/29/2011

this is the error i get in phpmyadmin
**
Error

SQL query:
ALTER TABLE DET BAL ANAL CHANGE balance balance VARCHAR( 10, 2 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL
MySQL said:

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '2) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL' at line 1

7542 11/29/2011

Try this
$formatted_number = number_format($value, 2);
if($value < 0)

{

$value = "<font color=red>$".$formatted_number."</font>";

}

else

{

$value = "$".$formatted_number."";

}

C
cgphp 11/29/2011

Not varchar but float(10,2)

V
vettold author 11/29/2011

great it works. some users were confused when they saw (248.22) instead of -242.22
Thanks again this is solved.