function num_to_wordsRS($number, $real_name, $decimal_digit, $decimal_name){
        $res = '';
        $real = 0;
        $decimal = 0;

        if($number == 0)
            return 'Zero'.(($real_name == '')?'':' '.$real_name);
        if($number >= 0){
            $real = floor($number);
            $decimal = round($number - $real, $decimal_digit);
        }else{
            $real = ceil($number) * (-1);
            $number = abs($number);
            $decimal = $number - $real;
        }
        $decimal = (int)str_replace('.','',$decimal);
		$unit_name[0] = '';
        $unit_name[1] = 'thousand';
        $unit_name[2] = 'million';
        $unit_name[3] = 'billion';
        $unit_name[4] = 'trillion';

        $packet = array();	

        $number = strrev($real);
        $packet = str_split($number,3);

        for($i=0;$i<count($packet);$i++){
            $tmp = strrev($packet[$i]);
            $unit = $unit_name[$i];
            if((int)$tmp == 0)
                continue;
            $tmp_res = '';
            if(strlen($tmp) >= 2){
                $tmp_proc = substr($tmp,-2);
                switch($tmp_proc){
                    case '10':
                        $tmp_res = 'ten';
                        break;
                    case '11':
                        $tmp_res = 'eleven';
                        break;
                    case '12':
                        $tmp_res = 'twelve';
                        break;
                    case '13':
                        $tmp_res = 'thirteen';
                        break;
                    case '15':
                        $tmp_res = 'fifteen';
                        break;
                    case '20':
                        $tmp_res = 'twenty';
                        break;
                    case '30':
                        $tmp_res = 'thirty';
                        break;
                    case '40':
                        $tmp_res = 'forty';
                        break;
                    case '50':
                        $tmp_res = 'fifty';
                        break;
                    case '70':
                        $tmp_res = 'seventy';
                        break;
                    case '80':
                        $tmp_res = 'eighty';
                        break;
                    default:
                        $tmp_begin = substr($tmp_proc,0,1);
                        $tmp_end = substr($tmp_proc,1,1);

                        if($tmp_begin == '1')
                            $tmp_res = get_num_name($tmp_end).'teen';
                        elseif($tmp_begin == '0')
                            $tmp_res = get_num_name($tmp_end);
                        elseif($tmp_end == '0')
                            $tmp_res = get_num_name($tmp_begin).'ty';
                        else{
                            if($tmp_begin == '2')
                                $tmp_res = 'twenty';
                            elseif($tmp_begin == '3')
                                $tmp_res = 'thirty';
                            elseif($tmp_begin == '4')
                                $tmp_res = 'forty';
                            elseif($tmp_begin == '5')
                                $tmp_res = 'fifty';
                            elseif($tmp_begin == '6')
                                $tmp_res = 'sixty';
                            elseif($tmp_begin == '7')
                                $tmp_res = 'seventy';
                            elseif($tmp_begin == '8')
                                $tmp_res = 'eighty';
                            elseif($tmp_begin == '9')
                                $tmp_res = 'ninety';

                            $tmp_res = $tmp_res.' '.get_num_name($tmp_end);
                        }
                        break;
                }

                if(strlen($tmp) == 3){
                    $tmp_begin = substr($tmp,0,1);

                    $space = '';
                    if(substr($tmp_res,0,1) != ' ' && $tmp_res != '')
                        $space = ' ';

                    if($tmp_begin != 0){
                        if($tmp_begin != '0'){
                            if($tmp_res != '')
                                $tmp_res = 'and'.$space.$tmp_res;
                        }
                        $tmp_res = get_num_name($tmp_begin).' hundred'.$space.$tmp_res;
                    }
                }
            }else
                $tmp_res = get_num_name($tmp);
            $space = '';
            if(substr($res,0,1) != ' ' && $res != '')
                $space = ' ';
            $res = $tmp_res.' '.$unit.$space.$res;
        }

        $space = '';
        if(substr($res,-1) != ' ' && $res != '')
            $space = ' ';

        $res .= $space.$real_name.(($real > 1 && $real_name != '')?'s':'');

        if($decimal > 0)
            $res .= ' '.num_to_wordsRS($decimal, '', 0, '').' '.$decimal_name.(($decimal > 1 && $decimal_name != '')?'s':'');
        return ucfirst($res);
    }
Beispiel #2
0
         </span>
        </td>
        <td class="print_text" valign="top">ADD CST @ 2.00 %<br/>(SALES AGAINST FROM C )<br/><br/><br/><hr /><b>NET AMOUNT</b></td>
        <td align="right" valign="top"><b>:</b><br/><br/><br/><br/><hr /><b>:</b></td>
        <td align="right" valign="top"><span class="print_text"><?php 
    echo round($total_amount * 0.02);
    ?>
&nbsp;</span><br/><br/><br/><br/><hr /><b><?php 
    $net_amt = $total_amount + round($total_amount * 0.02);
    echo $net_amt;
    ?>
&nbsp;</b></td>
   </tr>
   <tr>
   	   <td colspan="6" class="print_text" style="border-bottom:#000000 solid thin;border-top:#000000 solid thin;"><?php 
    echo num_to_wordsRS($net_amt, 'Rupee', 2, 'Paise');
    ?>
&nbsp;Only</td>
   </tr>
   <tr>
   		<td class="print_text" valign="top" colspan="3">Delivery At :<br/>
        	<span><?php 
    echo $buyeraddress;
    ?>
</span><br/>
            <span><?php 
    echo $buyercountry;
    ?>
</span>
        </td>
        <td colspan="3" align="center"><br/><br/>
    <?php 
if ($report_type == 'exmill') {
    $final_total = $total_amount + $total_amount * 2 / 100 + $FreightCharges;
    echo $final_total;
} else {
    if ($report_type == 'net') {
        $final_total = $FinalNetAmount;
        echo $final_total;
    }
}
?>
</b></span></td>
  </tr>
  <tr>
    <td colspan="7" class="print_text" style="border-bottom:#000000 solid thin;"><b>Rs. <?php 
echo num_to_wordsRS($final_total, 'Rupee', 2, 'Paise');
?>
 Only</b></td>
  </tr>
  <tr>
    <td colspan="6" class="print_text"><b>Delivery at :</b>
    <span></span><br/><br/>
    <span><b>Prepared By</b></span>
    <span style="padding-left:150px;"><b>Checked By</b></span>
    <span style="text-align:right;padding-left:50px;"><b>For MAHIMA PURESPUN</b><br/><b>(A Unit of Mahima Fibers Pvt. Ltd.)</b></span>
  	</td>
  </tr>
  
</table>

</body>