Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Invice - Total price as text


Guest

Recommended Posts

Greetings folks!

 

 

In my country i have order forms where the Total price need to be in numbers and text.

 

Example:

 

Total price: 10.30 LVL

Price as text: Ten Lats 30 Santims

 

or

 

Total price: 100.30 LVL

Price as text: One Thousand Lats 30 Santims

 

and so on, and so on

 

actually the changing part is this One Thousand and this 30

 

I know it`s possible, but is it hard to make a script who changes numbers to text?

 

p.s. Recently i had some problems with date to be displayed in every language i had, but with some huge help it`s done and running. I thinks this must be something similar!

 

Can someone give me a push in this?

Link to comment
Share on other sites

  • Replies 54
  • Created
  • Last Reply

Greetings folks!

 

 

In my country i have order forms where the Total price need to be in numbers and text.

 

Example:

 

Total price: 10.30 LVL

Price as text: Ten Lats 30 Santims

 

or

 

Total price: 100.30 LVL

Price as text: One Thousand Lats 30 Santims

 

and so on, and so on

 

actually the changing part is this One Thousand and this 30

 

I know it`s possible, but is it hard to make a script who changes numbers to text?

 

p.s. Recently i had some problems with date to be displayed in every language i had, but with some huge help it`s done and running. I thinks this must be something similar!

 

Can someone give me a push in this?

I've done this is perl and it is not all that difficult. A quick search on Google for 'php currency to text' gives you a couple of samples. Of course they will have to be modified to fit your currency denominations and added into the code where you need the text to appear.

Community Bootstrap Edition, Edge

 

Avoid the most asked question. See How to Secure My Site and How do I...?

Link to comment
Share on other sites

Almost got it, but only can`t figure it out how to get the Total price from DB in Table orders_total -> value

 

here is my starting code for getting the number

 

<?php

for ($i = 0, $n = sizeof($order->totals); $i < $n; $i++) {
  echo '         <tr>' . "\n" .
       '          <td align="right" class="smallText">Cena vardiem: ' . number_format($order->totals['value'],2,'.','') . '</td>' . "\n" .
       '         </tr>' . "\n";
}

?>

 

i only get four lines of 0.00

 

 

help!

Link to comment
Share on other sites

Looks like the 'value' is not part of the sql statement in admin/includes/classes/orders.php

 

You will need to add 'value' to the sql statement, and 'value' => $totals['value'], to the totals[] array.

Community Bootstrap Edition, Edge

 

Avoid the most asked question. See How to Secure My Site and How do I...?

Link to comment
Share on other sites

Looks like the 'value' is not part of the sql statement in admin/includes/classes/orders.php

 

You will need to add 'value' to the sql statement, and 'value' => $totals['value'], to the totals[] array.

 

 

Thanks in advice, but this is not working :(

Link to comment
Share on other sites

Sorry my bad!

 

needed to change this:

 

$totals_query = tep_db_query("select title, text from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . (int)$order_id . "' order by sort_order");

 

in to this:

 

$totals_query = tep_db_query("select title, text, value from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . (int)$order_id . "' order by sort_order");

 

 

and replace this:

 

$this->totals[] = array('title' => $totals['title'],
'text' => $totals['text']);

 

into this:

 

$this->totals[] = array('title' => $totals['title'],
'text' => $totals['text'],
'value' => $totals['value']);

 

 

but now i need to display only sort_order - 4

 

at he moment i have all the values in that column...

Link to comment
Share on other sites

What you have now is the ability to do this...

 

   for ($i = 0, $n = sizeof($order->totals); $i < $n; $i++) {
// get value of this total and convert to words
$amount_numbers = $order->totals[$i]['value'];
$amount_words = numbers2words($amount_numbers);
echo $amount_words;
// now check for title = 'Total' and put the words where you want them.
     echo '              <tr>' . "\n" .
          '                <td align="right" class="smallText">' . $order->totals[$i]['title'] . '</td>' . "\n" .
          '                <td align="right" class="smallText">' . $order->totals[$i]['text'] . '</td>' . "\n" .
          '              </tr>' . "\n";
   }

Community Bootstrap Edition, Edge

 

Avoid the most asked question. See How to Secure My Site and How do I...?

Link to comment
Share on other sites

Seems to work some how, but the problem remains:

 

In my invoice i have this fields printed:

Price: 108.90LVL

Delivery: 0.00LVL

TAX - PVN 21%: 18.90LVL

Sum to pay: 108.90LVL - i need to get this number from Table -> orders_total and column - values (only value with sort_order - 4)

 

and i need to be: Sum to pay: 108.90 is displayed as words.

 

Example:

 

if Sum to pay: - 108.90

 

Sum in word: one hundred and eight Lats 90/100 santims

 

or if if Sum to pay: - 101.90

 

Sum in word: one hundred and one Lat 90/100 santims

 

 

At the moment i have all the values from

$order->totals[$i]['text']

and the function numbers2words is displaying 4x times - Invalid characters in input because this field is the number with currency inside + with HTML formatting such as <'b'>101.90<'/b'>!

 

 

The function is doing this, but it can`t understand the LVL word attached with number.

 

Do i need to make a new function in admin/includes/classes/orders.php only for value with sort_order - 4 to get 101.90 and be displayed from

 

Table: orders_total

Column: value

with: sort_order ID 4

 

i don`t need all the row`s from table value only the row with sort_order ID 4

 

 

p.s. i`m not so strong in PHP as u mdtaylorlrim, but just learning... ;) and i`m really appreciate your help and time u spend for helping me

Link to comment
Share on other sites

That's because you need to use:

 

$order->totals[$i]['value']

 

as the input to the numbers2text function.

 

You should probably have something like this..

 

for ($i = 0, $n = sizeof($order->totals); $i < $n; $i++) {
     echo '              <tr>' . "\n" .
          '                <td align="right" class="smallText">' . $order->totals[$i]['title'] . '</td>' . "\n" .

if ($order->totals[$i]['title'] == 'Total') {
'                <td align="right" class="smallText">' . numbers2words($order->totals[$i]['value']) . '</td>' . "\n" .
} else {
          '                <td align="right" class="smallText">' . $order->totals[$i]['text'] . '</td>' . "\n" .
}
          '              </tr>' . "\n";
   }

 

(You might have to use the echo statement on the lines inside the {}.. not sure.)

 

Of course, if you needed ALL the lines converted to text it would be easier.

for ($i = 0, $n = sizeof($order->totals); $i < $n; $i++) {
     echo '  <tr>' . "\n" .
          '  <td align="right" class="smallText">' . $order->totals[$i]['title'] . '</td>' . "\n" .
          '  <td align="right" class="smallText">' . numbers2text($order->totals[$i]['text']) . '</td>' . "\n" .
          '  </tr>' . "\n";
   }

Community Bootstrap Edition, Edge

 

Avoid the most asked question. See How to Secure My Site and How do I...?

Link to comment
Share on other sites

Thanks for the replay, but i need a seperate line for the number2text

 

example -

 

in original invoice i have this:

_________________________________________

 

Total: 108.90LVL

Delivery: 0.00LVL

Tax - PVN 21%: 18.90LVL

Total to pay: 108.90LVL

_________________________________________

 

But what i need and try to do:

_________________________________________

 

Total: 108.90LVL

Delivery: 0.00LVL

Tax - PVN 21%: 18.90LVL

Total to pay: 108.90LVL

--------------------------

Total to pay in words: one hundred and eght Lats 90/100 santims

--------------------------

_________________________________________

 

I don`t need all the fields to be converted to text.

 

but take a value from Table orders_total, Column value with sort_order ID 4

 

After that this 108.90 number from column sort_order with ID 4

 

is inserted in code, from which is generated - numbers2word

 

Hope this makes sense :)

Link to comment
Share on other sites

Ok, then what you are wanting is something like this.

for ($i = 0, $n = sizeof($order->totals); $i < $n; $i++) {
// get the total words
if ($order->totals[$i]['title'] == 'Total') {
$total_words = numbers2words($order->totals[$i]['value'])
}
// end
     echo '              <tr>' . "\n" .
          '                <td align="right" class="smallText">' . $order->totals[$i]['title'] . '</td>' . "\n" .
          '                <td align="right" class="smallText">' . $order->totals[$i]['text'] . '</td>' . "\n" .
          '              </tr>' . "\n";
   }
     echo '              <tr>' . "\n" .
          '                <td> align="right" class="smallText">' . $total_words . '</td>' . "\n" .
          '              </tr>' . "\n";           

 

You will have to adjust the left-right positioning of the words on your page, which means that that last <TR> block may have to be moved down into a completely different table structure.

Community Bootstrap Edition, Edge

 

Avoid the most asked question. See How to Secure My Site and How do I...?

Link to comment
Share on other sites

Ok, then what you are wanting is something like this.

for ($i = 0, $n = sizeof($order->totals); $i < $n; $i++) {
// get the total words
if ($order->totals[$i]['title'] == 'Total') {
$total_words = numbers2words($order->totals[$i]['value'])
}
// end
     echo '              <tr>' . "\n" .
          '                <td align="right" class="smallText">' . $order->totals[$i]['title'] . '</td>' . "\n" .
          '                <td align="right" class="smallText">' . $order->totals[$i]['text'] . '</td>' . "\n" .
          '              </tr>' . "\n";
   }
     echo '              <tr>' . "\n" .
          '                <td> align="right" class="smallText">' . $total_words . '</td>' . "\n" .
          '              </tr>' . "\n";           

 

You will have to adjust the left-right positioning of the words on your page, which means that that last <TR> block may have to be moved down into a completely different table structure.

 

 

I`m getting an Parse error: syntax error, unexpected '}'

Link to comment
Share on other sites

I`m getting an Parse error: syntax error, unexpected '}'

Nothing wrong with this code. Does it give you a line number? The error is outside of this code block, unless I'm blind (and I'm not, I'm deaf.)

Community Bootstrap Edition, Edge

 

Avoid the most asked question. See How to Secure My Site and How do I...?

Link to comment
Share on other sites

Nothing wrong with this code. Does it give you a line number? The error is outside of this code block, unless I'm blind (and I'm not, I'm deaf.)

 

 

Sorry but i getting blank page with the error i told you about... damn >_< this drives me crazy

 

lines from 195 till 213

 

error: Parse error: syntax error, unexpected '}' in /var/www/sapnis/panelis/invoice.php on line 201

 


<?php

for ($i = 0, $n = sizeof($order->totals); $i < $n; $i++) {
// get the total words
if ($order->totals[$i]['title'] == 'Total') {
$total_words = numbers2words($order->totals[$i]['value'])
}
// end
     echo '              <tr>' . "\n" .
          '                <td align="right" class="smallText">' . $order->totals[$i]['title'] . '</td>' . "\n" .
          '                <td align="right" class="smallText">' . $order->totals[$i]['text'] . '</td>' . "\n" .
          '              </tr>' . "\n";
   }
     echo '              <tr>' . "\n" .
          '                <td> align="right" class="smallText">' . $total_words . '</td>' . "\n" .
          '              </tr>' . "\n"; 


?>

 

i was trying to solve this, but nothing...

Link to comment
Share on other sites

It's missing a ; after...

 

$total_words = numbers2words($order->totals[$i]['value'])

 

 

Now the error is gone, but i don`t get numbers to word..

 

 

is this function correct (for converting) what i have placed in admin/includes/aplication_top.php

 

require_once 'cip_txt.php';

function numbers2words($total_words){

$t2w = new TextualNumber();

   /* Catch 'out of range' and 'invalid character' exceptions */
   try {
       echo $t2w->GetText('$total_words');
   }
   catch(Exception $e) {
       echo $e->getMessage();
   }
}

Link to comment
Share on other sites

Now the error is gone, but i don`t get numbers to word..

 

 

is this function correct (for converting) what i have placed in admin/includes/aplication_top.php

 

 

First, it requires a page (cip_txt.php) that I am not familiar with, and second, why in application_top.php?

Community Bootstrap Edition, Edge

 

Avoid the most asked question. See How to Secure My Site and How do I...?

Link to comment
Share on other sites

First, it requires a page (cip_txt.php) that I am not familiar with, and second, why in application_top.php?

 

cip_txt.php - is the script what converts numbers to words!

 

 

 

i have test it without osC

 

 

look at in your PM`s i have sent you an address where are the files located so u can download them if u need!

Link to comment
Share on other sites

Well first thing is that I gave you a line that is not exactly right.

 

if ($order->totals[$i]['title'] == 'Total') {

should be:

if ($order->totals[$i]['title'] == 'Total:') {

 

 

If you look in the database you need to trap when it is processing a total line and the value has to match the database title value exact. The word Total has a colon after it in the database, so that has to appear in your code exactly.

 

And then I am really confused why you use a function to call another function. That just seems really useless to me. And the function needs to send the number that you want to convert to words.

 

Try this...

 

 

<?php

for ($i = 0, $n = sizeof($order->totals); $i < $n; $i++) {
// get the total words
if ($order->totals[$i]['title'] == 'Total:') {
$total_words = GetCurrency($order->totals[$i]['value']);
}
// end
     echo '              <tr>' . "\n" .
          '                <td align="right" class="smallText">' . $order->totals[$i]['title'] . '</td>' . "\n" .
          '                <td align="right" class="smallText">' . $order->totals[$i]['text'] . '</td>' . "\n" .
          '              </tr>' . "\n";
   }
     echo '              <tr>' . "\n" .
          '                <td align="right" class="smallText"> ' . $total_words . '</td>' . "\n" .
          '              </tr>' . "\n"; 

       echo $total_words;

?>

 

 

Using this you should be able to eliminate that garbage in application_top.php

Community Bootstrap Edition, Edge

 

Avoid the most asked question. See How to Secure My Site and How do I...?

Link to comment
Share on other sites

Ok i have removed that crap i made in aplication_top.php

 

 

But still i can`t figure it out.. the number form row value is not displeyed!

Link to comment
Share on other sites

Ok i have removed that crap i made in aplication_top.php

 

 

But still i can`t figure it out.. the number form row value is not displeyed!

Ok, give me the afternoon. I'll install it on my test shop and see if it works.

Community Bootstrap Edition, Edge

 

Avoid the most asked question. See How to Secure My Site and How do I...?

Link to comment
Share on other sites

Ok, give me the afternoon. I'll install it on my test shop and see if it works.

 

 

Thank you this would be great!

 

 

Maybe u can also try to convert numbers2word?

Link to comment
Share on other sites

Ok, try this. (I had to find the source web page and read the documentation that came with it.)

 

<?php
 for ($i = 0, $n = sizeof($order->totals); $i < $n; $i++) {
 if ($order->totals[$i]['title'] == "Total:") {
 $total_amt = $order->totals[$i]['value'];
 }
   echo '          <tr>' . "\n" .
        '            <td align="right" class="smallText">' . $order->totals[$i]['title'] . '</td>' . "\n" .
        '            <td align="right" class="smallText">' . $order->totals[$i]['text'] . '</td>' . "\n" .
        '          </tr>' . "\n";
 }
echo '<tr><td>Please pay the sum of ' . TextualNumber::GetCurrency($total_amt, "Dollar", "Cent") . '</td></tr>';
?>

 

Change your dollars and cents to your currency and do translation for "Please pay the sum of ".

Community Bootstrap Edition, Edge

 

Avoid the most asked question. See How to Secure My Site and How do I...?

Link to comment
Share on other sites

Ok, try this. (I had to find the source web page and read the documentation that came with it.)

 

<?php
 for ($i = 0, $n = sizeof($order->totals); $i < $n; $i++) {
 if ($order->totals[$i]['title'] == "Total:") {
 $total_amt = $order->totals[$i]['value'];
 }
   echo '          <tr>' . "\n" .
        '            <td align="right" class="smallText">' . $order->totals[$i]['title'] . '</td>' . "\n" .
        '            <td align="right" class="smallText">' . $order->totals[$i]['text'] . '</td>' . "\n" .
        '          </tr>' . "\n";
 }
echo '<tr><td>Please pay the sum of ' . TextualNumber::GetCurrency($total_amt, "Dollar", "Cent") . '</td></tr>';
?>

 

Change your dollars and cents to your currency and do translation for "Please pay the sum of ".

 

 

I`m one unlucky guy...

 

With a lot of errors today!

 

Fatal error: Uncaught exception 'Exception' with message 'Invalid characters in input' in /var/www/sapnis/panelis/cip_txt.php:46 Stack trace: #0 /var/www/sapnis/panelis/cip_txt.php(186): TextualNumber::ToString(NULL) #1 /var/www/sapnis/panelis/cip_txt.php(224): TextualNumber::GetText(NULL) #2 /var/www/sapnis/panelis/invoice.php(207): TextualNumber::GetCurrency(NULL, 'Dollar', 'Cent') #3 {main} thrown in /var/www/sapnis/panelis/cip_txt.php on line 46

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...