PHP and Smarty

Discussion in 'PHP' started by RNK Concepts, May 1, 2008.

  1. #1
    Hey all,

    I have a CRM system that I am using and I would like to know if someone could help me with a small issue ...

    In the attached files, you will see the screen as it is now (Summary-Current.jpg) nd how I would like it to look (Summary-Preferred.jpg).

    I have the new layout done, with everything in place, but I can't get the Total Carry-Over ASSET Plan hours to calculate.

    I made some changes in the profile_timecharges.php file which now looks like this:
    <?php
        
        if( !($year = getNData('year') ) )
            $year = date( "Y" );                
                    
        if( !($month = getNData('month') ) )
            $month = date( "m" );        
        
                
        $c = Customer::factory( Engine::userLoggedIn() );
        $s = $c->getTimechargeSummary( $year . "-" . $month );
        
    ?>
    <style type="text/css">
    fieldset.tc{
        -moz-border-radius:5px;
        border:1px solid #CCCCCC;
        color:#267DDC;
        margin:5px;
        padding:10px;
    }
    
    .ntext{    
        color:#000000;
    }
    
    .total {
        color: #0000FF; 
        font-weight: bold;
    }
    </style>
    <script type="text/javascript">
    
        function updateQuery(){
            profile_panel.body.load({
                url: 'index.php',
                method: 'post',
                scripts: true,
                params: { tsrc: 'profile_area', subsection: 'profile_timecharges', year: Ext.get( 'year' ).getValue(), month: Ext.get( 'month' ).getValue() },
                callback: function( oElement, bSuccess, oResponse ){
                    if( !bSuccess )
                        updateQuery();            
                }                     
            });    
        }
    
    </script>
    <div id="content-panel">
        <div id="content" style="padding-top:15px;padding-right:10px;">
            <div class="text">
                <div style="margin:5px;vertical-align:middle;" class="text">
                        View report for
                        <label>
                        <input name="year" type="text" id="year" size="4" maxlength="4" value="<?= $year ?>">
                        </label>
                        /
                        <label>
                        <input name="month" type="text" id="month" size="2" maxlength="2" value="<?= $month ?>">
                        </label>
                        <input name="submit" type="submit" onclick="updateQuery();">
                    <hr>
                    <h2>Time charges for <?= date( "F Y", strtotime( "$year-$month-01 00:00:00" ) ); ?></h2>
                    <? 
                        if( $s['work'] ):
                            foreach( $s['work'] as $w ):
                    ?>
                    <table width="550" border="0" cellpadding="5" align="center" style="padding:5px;margin-top:10px;">
                        <tr>
                            <td width="65%" valign="top"><h3><?= $w->subject ?></h3>
                                <? if( $w->topic_id ): ?>
                                (ref ticket #<a class="text" href="index.php?linkact=st&amp;i=<?= $w->topic_id ?>" target="_blank"><?= $w->topic_id ?></a>)<br>
                                <? endif; ?>
                                <? if( $w->out_of_plan ): ?>
                                <i>not covered by support plan</i><br>
                                <? endif; ?>
                                <? if( $w->type == 2 ): ?>
                                <i><span style="color:#00DD00;">credit</span></i><br>
                                <? endif; ?> 
                            </td>
                            <td width="27%" valign="top" style="color:#0000FF;"><h3><?= $w->type_string ?></h3></td>
                            <td width="8%" valign="top">
                                <h3 align="right" style="color:<? if( $w->type == 2 ): ?>#00DD00<? else: ?>#000000<? endif; ?>;"><?= $w->hours ?></h3>
                            </td>
                        </tr>
                        <tr>
                            <td style="color:#006699;"><?= $w->admin_name ?> - <?= $w->verbose_date ?></td>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                        </tr>
                        <tr>
                            <td colspan="3"><?= $w->comment ?></td>
                        </tr>
                    </table>
                    <?        endforeach;
                        else:
                    ?>
                    <table width="550" border="0" cellpadding="5" align="center" style="padding:5px;margin-top:10px;">
                        <tr>
                            <td>No tasks are recorded for this time period</td>
                        </tr>
                    </table>
                    <? endif; ?> 
                    <br>
                    <hr>
                    <h2>Summary</h2>
                    <? if( $s['plan'] ): ?>
                    <fieldset class="tc">
                        <legend>Support-Plan Report </legend>
                        <table width="550" border="0" cellpadding="5">
                            <tr>
                                <td width="425"><div align="right">Hours rolled over from previous <?= $s['plan']['max_rollover_months'] ?> month(s)</div></td>
                                <td><div align="right"><?= $s['rollover'] ?></div></td>
                            </tr>
                            <tr>
                                <td><div align="right">Support plan hours</div></td>
                                <td><div align="right"><?= $s['plan']['initial_hours'] ?></div></td>
                            </tr>
                            <tr>
                                <td colspan="2"><hr></td>
                            </tr>
                            <tr>
                                <td class="ntext"><div align="right">Manual adjustments (credited hours)</div></td>
                                <td class="ntext"><div align="right">- <?= $s['credit_hours'] ?></div></td>
                            </tr>
                            <tr>
                            <tr>
                                <td class="ntext"><div align="right"><b>Total work hours</b></div></td>
                                <td class="ntext"><div align="right"><b><?= $s['total_hours'] ?></b></div></td>
                            </tr>
                            <tr>
                                <td class="ntext"><div align="right">Total non-billable hours this month</div></td>
                                <td class="ntext"><div align="right"><?= $s['nonbillable_hours'] ?></div></td>
                            </tr>
                            <tr>
                                <td class="ntext"><div align="right"><b>Total Supplemental Support Hours</b></div></td>
                                <td class="ntext"><div align="right"><?= $s['supplemental_hours'] ?></div></td>
                            </tr>
                            <tr>
                                <td class="ntext"><div align="right"><b>Total Carry-Over Asset Plan Credits</b></div></td>
                                <td class="ntext"><div align="right"><?php $billable_hours = ($rollover + $plan_hours + $credit_hours); $result = ($asset_hours - $billable_hours); if ($billable_hours < $asset_hours) { echo "$result"; } else { echo "0.00"; ?></div></td>
                            </tr>
                        </table>
                    </fieldset>
                    <? endif; ?>
                    <fieldset class="tc">
                        <legend>Standard Time Charges</legend>
                        <table width="550" border="0" cellpadding="5">
                            
                            <?     
                                if( $s['individual_charges'] ):
                                    foreach( $s['individual_charges'] as $i ): 
                            ?>
                            <tr>
                                <td width="425" valign="top" class="ntext">
                                    <div align="right">
                                        <?= $i['subject'] ?><br>
                                        <i><?= $i['hours'] ?> x $ <?= $i['rate'] ?></i>
                                    </div>
                                </td>
                                <td valign="top" class="ntext"><div align="right">$ <?= $i['total'] ?></div></td>
                            </tr>
                            <?
                                    endforeach;
                                else:
                            ?>
                            <tr>
                                <td width="425" class="ntext"><div align="right"><i>No individual charges to report for this period</i></div></td>
                                <td>&nbsp;</td>
                            </tr>                        
                            <? endif; ?>
                            <tr>
                                <td colspan="2"><hr></td>
                            </tr>
                            <tr>
                                <td width="425" class="ntext"><div align="right">Total Out-of-Plan Work Hours</div></td>
                                <td class="ntext"><div align="right"><b><?= $s['oop_hours'] ?></b></div></td>
                            </tr>
                            <tr>
                                <td><div align="right" class="total">Total charges</div></td>
                                <td><div align="right" class="total">$ <?= $s['oop_fees'] ?></div></td>
                            </tr>
                        </table>                           
                    </fieldset>
                    <fieldset class="tc">
                        <legend><b>Total Due for Selected Period</b></legend>
                        <table width="550" border="0" cellpadding="5">
                            <? if( $s['plan'] ): ?>
                            <tr>
                                <td><div align="right">Total Supplemental Support Fees</div></td>
                                <td><div align="right">$ <?= $s['total_fees'] ?></div></td>
                            </tr>
                            <? endif; ?>
                            
                            <tr>
                                <td><div align="right">Standard Time Charges</div></td>
                                <td><div align="right">$ <?= $s['oop_fees'] ?></div></td>
                            </tr>
                            <tr>
                                <td><div align="right" class="total">Total to be Invoiced</div></td>
                                <td><div align="right" class="total">$ <?= $s['grand_total'] ?></div></td>
                            </tr>
                        </table>
                    </fieldset>
                </div>
            </div>
        </div>
    </div>
    Code (markup):
    And here is the profile_timecharges.tpl file:
    <style type="text/css">
    fieldset.tc{ldelim}
        -moz-border-radius:5px;
        border:1px solid #CCCCCC;
        color:#267DDC;
        margin:5px;
        padding:10px;
    {rdelim}
    
    .ntext{ldelim}    
        color:#000000;
    {rdelim}
    
    .total {ldelim}    
        color: #0000FF; 
        font-weight: bold;
    {rdelim}
    </style>
    <div id="content-panel">
        <div id="content" style="padding-top:15px;padding-right:10px;">
            <div class="text">
                <div style="margin:5px;vertical-align:middle;" class="text">
                    <form name="treport" method="post" action="?tsrc=profile&amp;sub=profile_timecharges">
                        View report for
                        <label>
                        <input name="year" type="text" id="year" size="4" maxlength="4" value="{$yval}">
                        </label>
                        /
                        <label>
                        <input name="month" type="text" id="month" size="2" maxlength="2" value="{$mval}">
                        </label>
                        <input name="submit" type="submit">
                    </form>
                    <hr>
                    <h2>Time charges for {$date_string}</h2>
                    {foreach from=$work item=w}
                    <table width="550" border="0" cellpadding="5" align="center" style="padding:5px;margin-top:10px;">
                        <tr>
                            <td width="65%" valign="top"><h3>{$w->subject}</h3>
                                {if $w->topic_id}
                                (ref ticket #<a class="text" href="index.php?linkact=st&amp;i={$w->topic_id}" target="_blank">{$w->topic_id}</a>)<br>
                                {/if} 
                                {if $w->out_of_plan}
                                <i>not covered by support plan</i><br>
                                {/if} 
                                {if $w->type == 2}
                                <i><span style="color:#00DD00;">credit</span></i><br>
                                {/if} 
                            </td>
                            <td width="27%" valign="top" style="color:#0000FF;"><h3>{$w->type_string}</h3></td>
                            <td width="8%" valign="top">
                                <h3 align="right" style="color:{if $w->type == 2}#00DD00{else}#000000{/if};">{$w->hours}</h3>
                            </td>
                        </tr>
                        <tr>
                            <td style="color:#006699;">{$w->admin_name} - {$w->verbose_date}</td>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                        </tr>
                        <tr>
                            <td colspan="3">{$w->comment}</td>
                        </tr>
                    </table>
                    {foreachelse}
                    <table width="550" border="0" cellpadding="5" align="center" style="padding:5px;margin-top:10px;">
                        <tr>
                            <td>No tasks are recorded for this time period</td>
                        </tr>
                    </table>
                    {/foreach} 
                    <br>
                    <hr>
                    <h2>Summary</h2>
                    
                    {if isset( $plan_id )}
                    <fieldset class="tc">
                        <legend>Support-Plan Report</legend>
                                                    
                        <table width="550" border="0" cellpadding="5">
                            <tr>
                                <td width="425"><div align="right">Hours rolled over from previous {$rmonths} month(s)</div></td>
                                <td><div align="right">{$rollover}</div></td>
                            </tr>
                            <tr>
                                <td><div align="right">Support plan hours</div></td>
                                <td><div align="right">{$plan_hours}</div></td>
                            </tr>
                            <tr>
                                <td colspan="2"><hr></td>
                            </tr>
                            <tr>
                                <td class="ntext"><div align="right">Manual adjustments (credited hours)</div></td>
                                <td class="ntext"><div align="right">- {$credit_hours}</div></td>
                            </tr>
                            <tr>
                                <td class="ntext"><div align="right"><b>Total Work Hours</b></div></td>
                                <td class="ntext"><div align="right"><b>{$total_hours}</b></div></td>
                            </tr>
                            <tr>
                                <td class="ntext"><div align="right">Total non-billable hours this month</div></td>
                                <td class="ntext"><div align="right">{$nonbillable_hours}</div></td>
                            </tr>
                            <tr>
                                <td class="ntext"><div align="right"><b>Total Supplemental Support Hours</b></div></td>
                                <td class="ntext"><div align="right">{$rollover + $plan_hours}</div></td>
                            </tr>
                            tr>
                                <td class="ntext"><div align="right"><b>Total Carry-Over ASSET Plan Credits</b></div></td>
                                <td class="ntext"><div align="right">{$rollover + $plan_hours + $credit_hours}</div></td>
                            </tr>
                        </table>
                    </fieldset>
                    {/if}
                    
                    <fieldset class="tc">
                        <legend>Standard Time Charges</legend>
                        <table width="550" border="0" cellpadding="5">
                            {foreach from=$individual_charges item=i}
                            <tr>
                                <td width="425" valign="top" class="ntext">
                                    <div align="right">
                                        {$i.subject}<br>
                                        <i>{$i.hours} x $ {$i.rate}</i>
                                    </div>
                                </td>
                                <td valign="top" class="ntext"><div align="right">$ {$i.total}</div></td>
                            </tr>
                            {foreachelse}
                            <tr>
                                <td width="425" class="ntext"><div align="right"><i>No individual charges to report for this period</i></div></td>
                                <td>&nbsp;</td>
                            </tr>                        
                            {/foreach}
                            <tr>
                                <td colspan="2"><hr></td>
                            </tr>
                            <tr>
                                <td width="425" class="ntext"><div align="right">Total Out-of-Plan work hours</div></td>
                                <td class="ntext"><div align="right"><b>{$oop_hours}</b></div></td>
                            </tr>
                            <tr>
                                <td><div align="right" class="total">Total charges</div></td>
                                <td><div align="right" class="total">$ {$oop_fees}</div></td>
                            </tr>
                        </table>                           
                    </fieldset>
                    
                    <fieldset class="tc">
                        <legend><b>Total Due for Selected Period</b></legend>
                        <table width="550" border="0" cellpadding="5">
                            {if isset( $plan_id )}
                            <tr>
                                <td><div align="right">Total Supplemental Support Fees</div></td>
                                <td><div align="right">$ {$total_fees}</div></td>
                            </tr>
                            {/if}
                            <tr>
                                <td><div align="right">Standard Time Charges</div></td>
                                <td><div align="right">$ {$oop_fees}</div></td>
                            </tr>
                            <tr>
                                <td><div align="right" class="total">Total Due to be Invoiced</div></td>
                                <td><div align="right" class="total">$ {$grand_total}</div></td>
                            </tr>
                        </table>
                    </fieldset>
                         
                </div>
            </div>
        </div>
    </div>
    Code (markup):
    I have this code in the Asset Hours area, just to see if I could get anything other than an error:
                            <tr>
                                <td class="ntext"><div align="right"><b>Total Carry-Over ASSET Plan Credits</b></div></td>
                                <td class="ntext"><div align="right">{$rollover + $plan_hours + $credit_hours}</div></td>
                            </tr>
    Code (markup):
    However, all I get is 0.00 in the layout when there should be some thing being calculated.

    I am not very familiar with SMARTY, so I think I'm just missing a variable somewhere ... but I would appreciate if somebody could point me in the right direction on this. The ASSET hours should be calculated something like this:
    if $total_billable_hours < $asset_hours ... else 0.00
    Code (markup):
    I hope you can understand what I'm talking about ... probably not, but please ask if you have any questions.

    I appreciate the help!
     

    Attached Files:

    RNK Concepts, May 1, 2008 IP