Парни помогите переменную вывести

Статус
В этой теме нельзя размещать новые ответы.

d4a1

Новичок
всем привет.
Без Вас никак. :) Кароче есть код формы бланка-счета.
всё нармально работает. За исключением того, что в конце в строке где выводится сумма счёта прописью - пишет Столько то рублей 00копеек. (копейки прописью выводит 00копеек), а должно писать , например 70копеек. А в суммах цифрами всё правильно выводит (копейки).



сумма прописью генерируется в этой строке, в самом конце скрипта.
Парни помогите переменную правильно вывести , чтоб копейки заработали.

PHP:
echo substr_replace (trim($m), $afm, 0, 2);
Будьте добры взгляньте


PHP:
<?php    class num2str
{
    var $nums = array(
        1 => array( 'один', 'одна' ),
        2 => array( 'два', 'две' ),
        3 => 'три',
        4 => 'четыре',
        5 => 'пять',
        6 => 'шесть',
        7 => 'семь',
        8 => 'восемь',
        9 => 'девять',
        10 => 'десять',
        11 => 'одиннадцать',
        12 => 'двенадцать',
        13 => 'тринадцать',
        14 => 'четырнадцать',
        15 => 'пятнадцать',
        16 => 'шестнадцать',
        17 => 'семнадцать',
        18 => 'восемнадцать',
        19 => 'девятнадцать',
        20 => 'двадцать', 
        30 => 'тридцать', 
        40 => 'сорок', 
        50 => 'пятьдесят', 
        60 => 'шестьдесят', 
        70 => 'семьдесят', 
        80 => 'восемьдесят', 
        90 => 'девяносто', 
        100 => 'сто', 
        200 => 'двести', 
        300 => 'триста', 
        400 => 'четыреста', 
        500 => 'пятьсот', 
        600 => 'шестьсот', 
        700 => 'семьсот', 
        800 => 'восемьсот', 
        900 => 'девятьсот', 
    );
    var $names = array(
        1000 => array( 'тысяча', 'тысячи', 'тысяч', '', 'sem' => 1 ),
        1000000 => array( 'миллион', 'миллиона', 'миллионов', '', 'sem' => 0 ), 
        1000000000 => array( 'миллиард', 'миллиарда', 'миллиардов', '', 'sem' => 0 )
    );
    var $out = array();
    function semantic( $num, $words )
    {
        $des = false;
        $num = $num % 100;
        if( $num > 20 )
        {
            $num = $num % 10;
            if( !$num ){
                $des= true;
            }
        }
        if ( 1 == $num ){
            return $words[0];
        }elseif( $des ){
            return $words[2];
        }elseif( !$num ){
            return $words[3];
        }elseif( $num <= 4  ){
            return $words[1];
        }else{
           return $words[2];
        }
    }
    function small_nums( $num, $sem )
    {
        if( $num < 21 )
        {   
            if( $num <= 2 )
            {
                $this->out[] =  $this->nums[$num][$sem];
            }else{
                $this->out[] =  $this->nums[$num];
            }
        }else{
            $this->out[] = $this->nums[$num - ( $num % 10 )];
            if( ( $num % 10 ) <= 2 )
            {
                $this->out[] = $this->nums[$num % 10][$sem];
            }else{
                $this->out[] =  $this->nums[$num % 10];
            }
        }
    }
    function work( $num, $all_sem )
    {
        foreach( array( 1000000000, 1000000, 1000 ) as $order )
        {
            $temp = floor( $num / $order );
            if( ( $temp - ( $temp % 100 ) ) > 0 ){
                $this->out[] = $this->nums[$temp - ( $temp % 100 )];
            }
            $this->small_nums( $temp % 100, $this->names[$order]['sem'] );
            $this->out[] = $this->semantic( $temp, $this->names[$order] );
            $num -= $temp * $order;
        }
        $temp = $num;
        if( ( $temp - ( $temp % 100 ) ) > 0 ){
            $this->out[] = $this->nums[$temp - ( $temp % 100 )];
        }
        $this->small_nums( $temp % 100, $all_sem );
        $temp = implode( ' ', $this->out );
        $this->out = array();
        return $temp;
    }
}
class money2str
{
    var $names = array(
        1 => array( 'рубль', 'рубля', 'рублей', 'рублей', 'sem' => 0 ),
        2 => array( 'копейка', 'копейки', 'копеек', 'копеек', 'sem' => 1 )
    );
    var $out = array();
    function money2str()
    {
        $this->num2str = new num2str();
    }
    function work( $money, $kopnum = false )
    {
        $kop = substr( $money, -2 );
        $rub = substr( $money, 0, -3 );
        if( !$rub )
        {
            $this->out[] = 'ноль';
        }else{
            $this->out[] = $this->num2str->work( $rub, $this->names[1]['sem'] );
        }
        $this->out[] = $this->num2str->semantic( $rub, $this->names[1] );
        if( !$kopnum )
        {
            if( !$kop )
            {
                $this->out[] = 'ноль';
            }else{
                $this->out[] = $this->num2str->work( $kop, $this->names[2]['sem'] );
            }
        }else{
            $this->out[] = $kop;
        }
        $this->out[] = $this->num2str->semantic( $kop, $this->names[2] );
        $temp = implode( ' ', $this->out );
        $this->out = array();
        return $temp;
    }
}
?>
<?php 
$name=fsch_name;
$KPP=fsch_KPP;
$INN=fsch_INN;
$Rch=fsch_Rch;
$Rch_v=fsch_Rch_v;
$BIK=fsch_BIK;
$Kch=fsch_Kch;
$IND=fsch_IND;
$obl=fsch_obl;
$gor=fsch_gor;
$ul=fsch_ul;
$dom=fsch_dom;
$office=fsch_office;
$tel=fsch_tel;
$fax=fsch_fax;
$url_img=fsch_url;
$width_img=fsch_width;
$height_img=fsch_height;
?>

<table height="40" width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td style="border-bottom:2px solid #000000;"><p style="font-size:16px;"><strong>Счет на оплату № <?php printf("%04d", $db->f("order_id")); ?> от <?php echo vmFormatDate($db->f("cdate"), "%d.%m.%Y");?>г.</strong></p>
</td>
</tr>
</table>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tr>
<td align="center"><p style="font-size:12px;"><strong>№</strong></p></td>
<td align="center"><p style="font-size:12px;"><strong>Товары (услуги, работы)</strong></p></td>
<td align="center"><p style="font-size:12px;"><strong>Кол-во</strong></p></td>
<td align="center"><p style="font-size:12px;"><strong>Ед.</strong></p></td>
<td align="center"><p style="font-size:12px;"><strong>Цена</strong></p></td>
<td align="center"><p style="font-size:12px;"><strong>Сумма</strong></p></td>
</tr>
<?php 
$dbcart = new ps_DB;
$q  = "SELECT * FROM #__vm_order_item ";
$q .= "WHERE #__vm_order_item.order_id='$order_id' ";
$dbcart->query($q);
$subtotal = 0;
$dbi = new ps_DB;
$dbdel = new ps_DB;
while ($dbcart->next_record()) {
?>
<tr>
<td align="center"><?php $nomer=$nomer+1; echo $nomer;?></td>
<td>
<p style="font-size:12px; line-height:12px; margin:0px; padding:0px; padding-left:2px; padding-right:2px;">
<?php $dbcart->p("order_item_name");?></p>
<p style="font-size:10px; line-height:11px; margin:0px; padding:0px; padding-left:10px;">
<?php echo $dbcart->f("product_attribute");?></p>
</td>
<td align="right"><p style="font-size:11px; padding-right:5px;">
<?php $dbcart->p("product_quantity");?></p></td>
<td align="center">шт.</td>
<td align="right"><p style="font-size:11px; padding-right:5px;">
<?php if( $auth["show_price_including_tax"] ){
				$item_price = $dbcart->f("product_final_price");
			}
			else {
				$item_price = $dbcart->f("product_item_price");
			}
	$cena2=$dbcart->f("product_final_price");
	echo number_format($cena2, 2, '.', ' ');
	           ?></p></td>
<td align="right"><p style="font-size:11px; padding-right:5px;">
<?php $total = $dbcart->f("product_quantity") * $item_price; echo number_format($total, 2, '.', ' ');?></p>
</td>
</tr><?php } ?>
<?php $details = explode( "|", $db->f("ship_method_id"));
$dostavka=$details[3]; 
if ($dostavka!=0) {
?>
<tr> 
<td align="center"><?php $nomer=$nomer+1; echo $nomer;?></td>
<td><p style="font-size:12px; padding-left:2px;">Вариант доставки:<br>
<?php echo $details[1];?></p></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td align="right"><p style="font-size:12px; padding-right:5px;"><?php echo number_format($dostavka, 2, '.', ' ');?></p></td>
<td align="right"><p style="font-size:12px; padding-right:5px;"><?php echo number_format($dostavka, 2, '.', ' ');?></p></td>
</tr>
<?php }?>
</table></td>
</tr>
<tr>
<td>
<table width="100%" height="50" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="100">&nbsp;</td>
<td width="360" height="20" align="right" valign="bottom">
<p style="font-size:12px; padding-right:5px;"><strong>Итого:</strong></p></td>
<td width="100" align="right" valign="bottom">
<p style="font-size:12px; padding-right:5px;"><strong><?php $total_sum = $db->f("order_total");
echo number_format($total_sum, 2, '.', ' ');?></strong></p>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td height="20" align="right">
<p style="font-size:12px; padding-right:5px;">В том числе НДС:</p></td>
<td align="right">
<p style="font-size:12px; padding-right:5px;"><?php $tax_total = $db->f("order_tax") + $db->f("order_shipping_tax"); echo number_format($tax_total, 2, '.', ' ');?></p></td>
</tr>
<tr>
<td>&nbsp;</td>
<td height="20" align="right">
<p style="font-size:12px; padding-right:5px;">Без налога (НДС):</p></td>
<td align="right">
<p style="font-size:12px; padding-right:5px;">
<?php $summa_bez_nalogov=$total_sum-$tax_total;
echo number_format($summa_bez_nalogov, 2, '.', ' ');?></p></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="40" style="border-bottom:2px solid #000000;">
<p style="font-size:12px; padding-left:10px;">Всего наименований <strong><?php echo $nomer;?></strong>, на сумму <strong><?php echo number_format($total_sum, 2, '.', ' ');?> руб.<br>
<?php
$m = new money2str();
$m = $m->work( $total_sum, true );
$afm = mb_substr(trim($m),0,1,'UTF-8' ) ;
switch ($afm) {
case 'о':
$afm = 'О';
break;
case 'д':
$afm = 'Д';
break;
case 'т':
$afm = 'Т';
break;
case 'ч':
$afm = 'Ч';
break;
case 'п':
$afm = 'П';
break;
case 'ш':
$afm = 'Ш';
break;
case 'с':
$afm = 'С';
break;
case 'в':
$afm = 'В';
break;
case 'м':
$afm = 'М';
break;
default:
$afm = '';
}
echo substr_replace (trim($m), $afm, 0, 2);
?>
 

tz-lom

Продвинутый новичок
один маленький вопрос
и это даже не "какого опять логика и HTML смешаны"

зачем вы вывалили ВЕСЬ код а не его проблемную часть?
 

HraKK

Мудак
Команда форума
Никто за тебя работу тут делать не будет.
 
Статус
В этой теме нельзя размещать новые ответы.
Сверху