<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <div style="padding:0px;overflow:auto;width:auto;height:583px;border:0px solid grey" >   
        <input type="hidden" name="hdn_begin_date" id="hdn_begin_date"/>
        <input type="hidden" name="hdn_end_date" id="hdn_end_date"/>
        
        <div style="padding:2px">
            <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-print'" onClick="link_print('report/index_financial_statement/print_profit_loss_report/<?php $BeginDate ?>/<?php $EndDate ?>');">Print</a>
        </div><br />
		
        <table width="40%" border="0" cellspacing="0" cellpadding="0" style="margin-left:350px; margin-top:10px;margin-bottom:10px;" >
            <tr><td colspan="4" class="s2"><?= $branch->CompanyName; ?></td></tr>
            <tr><td colspan="4" class="s2"><?= $branch->BranchName; ?></td></tr>
            <tr><td colspan="4" class="s1">Profit & Loss Report</td></tr>
            <tr><td colspan="4" class="s2">From : <?= $BeginDate ?>  s/d  <?= $EndDate ?></td></tr>
            <tr><td>&nbsp;</td></tr>
        </table>

        <table width="40%" border="0" cellspacing="1" cellpadding="1" data-options="fit:true" style="margin-left:350px;margin-top:10px;" style="size:auto;width:auto;margin:auto;">
            <tr>
                <td width="40" align='center' class="s4">Description</td>
                <td width="10" align='center' class="s4">Saldo Amount</td>
                
                <td width="10" align='center' class="s4" hidden>Trans Number</td>
                <td width="10" align='center' class="s4" hidden>Account Number</td>
                <td width="10" align='center' class="s4" hidden>Trans Type</td>
            </tr>

            <tr>
                <td width="40"  align='left' class="s5"><span><b>OPERATING REVENUE</b></span></td>
            </tr>

            <!-- REVENUE -->
            <?php
            $total_revenue = 0;
            
            foreach($Revenue as $row){
                if($row->Total_Debet > 0){
                    $saldo_amount = $row->Total_Debet * ($row->Sign_Status == 0 ? 1 : -1);
                }
                else{
                    $saldo_amount = $row->Total_Credit * ($row->Sign_Status == 0 ? 1 : -1);
                }
                
                $total_revenue = $total_revenue + $saldo_amount;
                ?>

                <tr>
                    <td class="s5" align='Left' style='padding-left:15px'><?= $row->Branch_Account ?></td>
                    <td class="s5" align='right' style='padding-left:15px'>
                        <a href='#' onClick="view_journal('<?= $row->Journal_Number ?>', '<?= $row->Account_Number ?>', '<?= $row->Trans_Type ?>');" style="<?= ($saldo_amount < 0)? 'color:#FF6666' : '' ?>"> <?= formatRp_acc($saldo_amount,"2",",",".")?></a>
                    </td>
                    <td class="s5" align='Left' style='padding-left:15px' hidden><?= $row->Journal_Number ?></td>
                    <td class="s5" align='Left' style='padding-left:15px' hidden><?= $row->Account_Number ?></td>
                    <td class="s5" align='Left' style='padding-left:15px' hidden><?= $row->Trans_Type ?></td>
                </tr>
            <?php } ?>

            <tr>
                <td></td>
                <td><hr/></td>
            </tr>
            
            <tr>
                <td class="s5" align='Left'><b>Total Operating Revenue</b></td>
                <td class="s5" align='right'><b><?= number_format($total_revenue,"2",",",".")?></b></td>
            </tr>

            <tr height='15'><td></td></tr>

            <tr>
                <td width="40"  align='left' class="s3"><span><b>COGM / COGS (Cost of Goods Made)</b></span></td>
            </tr>
            
            <!-- COGM/COGS -->
            <?php 
            $total_cogm = 0;
            
            foreach($COGM as $row){
                if($row->Total_Debet > 0){
                    $saldo_amount = $row->Total_Debet * ($row->Sign_Status == 0 ? 1 : -1);
                }
                else{
                    $saldo_amount = $row->Total_Credit * ($row->Sign_Status == 0 ? 1 : -1);
                }
                
                $total_cogm = $total_cogm + $saldo_amount;
                ?>
            
                <tr>
                    <td class="s5" align='Left' style='padding-left:15px'><?= $row->Branch_Account; ?></td>
                    <td class="s5" align='right' style='padding-left:15px'>
                        <a href='#' onClick="view_journal('<?= $row->Journal_Number ?>', '<?= $row->Account_Number ?>', '<?= $row->Trans_Type ?>');" style="<?= ($saldo_amount < 0)? 'color:#FF6666' : '' ?>"> <?= formatRp_acc($saldo_amount,"2",",",".")?></a>
                    </td>
                    <td class="s5" align='Left' style='padding-left:15px' hidden><?= $row->Journal_Number ?></td>
                    <td class="s5" align='Left' style='padding-left:15px' hidden><?= $row->Account_Number ?></td>
                    <td class="s5" align='Left' style='padding-left:15px' hidden><?= $row->Trans_Type ?></td>
                </tr>
            <?php } ?>

            <tr>
                <td></td>
                <td><hr/></td>
            </tr>
            
            <tr>
                <td class="s5" align='Left'><b>Total COGM/COGS</b></td>
                <td class="s5" align='right'><b><?= number_format($total_cogm,"2",",",".")?></b></td>
            </tr>
            
            <tr height='15'><td></td></tr>

            <!-- Expneses -->
            <tr>
                <td width="40"  align='left' class="s5"><span><b>OPERATING EXPENSES</b></span></td>
            </tr>

            <?php 
            $total_expense = 0;
            
            foreach($Expense as $row){
                if($row->Total_Debet > 0){
                    $saldo_amount = $row->Total_Debet * ($row->Sign_Status == 0 ? 1 : -1);
                }
                else{
                    $saldo_amount = $row->Total_Credit * ($row->Sign_Status == 0 ? 1 : -1);
                }
                
                $total_expense = $total_expense + $saldo_amount;
                ?>
            
                <tr>
                    <td class="s5" align='Left' style='padding-left:15px'><?= $row->Account_Name; ?></td>
                    <td class="s5" align='right' style='padding-left:15px'>
                        <a href='#' onClick="view_journal('<?= $row->Journal_Number ?>', '<?= $row->Account_Number ?>', '<?= $row->Trans_Type ?>');" style="<?= ($saldo_amount < 0)? 'color:#FF6666' : '' ?>"> <?= formatRp_acc($saldo_amount,"2",",",".")?></a>
                    </td>
                    <td class="s5" align='Left' style='padding-left:15px' hidden><?= $row->Journal_Number ?></td>
                    <td class="s5" align='Left' style='padding-left:15px' hidden><?= $row->Account_Number ?></td>
                    <td class="s5" align='Left' style='padding-left:15px' hidden><?= $row->Trans_Type ?></td>
                </tr>
            <?php } ?>

            <tr>
                <td></td>
                <td><hr/></td>
            </tr>
            
            <tr>
                <td class="s5" align='Left'><b>Total Operating Expenses</b></td>
                <td class="s5" align='right'><b><?= number_format($total_expense,"2",",",".")?></b></td>
            </tr>
            
            <tr height='15'><td></td></tr>
            
            <!-- Other Revenue -->
            <tr>
                <td width="40"  align='left' class="s5"><span><b>OPERATING OTHER REVENUE</b></span></td>
            </tr>

            <?php 
            $total_other_revenue = 0;
            
            foreach($OtherRevenue as $row){
                if($row->Total_Debet > 0){
                    $saldo_amount = $row->Total_Debet * ($row->Sign_Status == 0 ? 1 : -1);
                }
                else{
                    $saldo_amount = $row->Total_Credit * ($row->Sign_Status == 0 ? 1 : -1);
                }
                
                $total_other_revenue = $total_other_revenue + $saldo_amount;
                ?>
            
                <tr>
                    <td class="s5" align='Left' style='padding-left:15px'><?= $row->Account_Name; ?></td>
                    <td class="s5" align='right' style='padding-left:15px'>
                        <a href='#' onClick="view_journal('<?= $row->Journal_Number ?>', '<?= $row->Account_Number ?>', '<?= $row->Trans_Type ?>');" style="<?= ($saldo_amount < 0)? 'color:#FF6666' : '' ?>"> <?= formatRp_acc($saldo_amount,"2",",",".")?></a>
                    </td>
                    <td class="s5" align='Left' style='padding-left:15px' hidden><?= $row->Journal_Number ?></td>
                    <td class="s5" align='Left' style='padding-left:15px' hidden><?= $row->Account_Number ?></td>
                    <td class="s5" align='Left' style='padding-left:15px' hidden><?= $row->Trans_Type ?></td>
                </tr>
            <?php } ?>

            <tr>
                <td></td>
                <td><hr/></td>
            </tr>
            
            <tr>
                <td class="s5" align='Left'><b>Total Operating Other Revenue</b></td>
                <td class="s5" align='right'><b><?= number_format($total_other_revenue,"2",",",".")?></b></td>
            </tr>
            
            <tr height='15'><td></td></tr>
        
            <!-- Other Expense -->
            <tr>
                <td width="40"  align='left' class="s5"><span><b>OPERATING OTHER EXPENSES</b></span></td>
            </tr>

            <?php 
            $total_other_expense = 0;
                    
            foreach($OtherExpense as $row){
                if($row->Total_Debet > 0){
                    $saldo_amount = $row->Total_Debet * ($row->Sign_Status == 0 ? 1 : -1);
                }
                else{
                    $saldo_amount = $row->Total_Credit * ($row->Sign_Status == 0 ? 1 : -1);
                }
                
                $total_other_expense = $total_other_expense + $saldo_amount;
                ?>
            
                <tr>
                    <td class="s5" align='Left' style='padding-left:15px'><?= $row->Account_Name; ?></td>
                    <td class="s5" align='right' style='padding-left:15px'>
                        <a href='#' onClick="view_journal('<?= $row->Journal_Number ?>', '<?= $row->Account_Number ?>', '<?= $row->Trans_Type ?>');" style="<?= ($saldo_amount < 0)? 'color:#FF6666' : '' ?>"><?= formatRp_acc($saldo_amount,"2",",",".")?></a>
                    </td>
                    <td class="s5" align='Left' style='padding-left:15px' hidden><?= $row->Journal_Number ?></td>
                    <td class="s5" align='Left' style='padding-left:15px' hidden><?= $row->Account_Number ?></td>
                    <td class="s5" align='Left' style='padding-left:15px' hidden><?= $row->Trans_Type ?></td>
                </tr>
            <?php } ?>
                
            <tr>
                <td></td>
                <td><hr/></td>
            </tr>
            
            <tr>
                <td class="s5" align='Left'><b>Total Operating Other Expenses</b></td>
                <td class="s5" align='right'><b><?= number_format($total_other_expense,"2",",",".")?></b></td>
            </tr>

            <tr height='15'><td></td></tr>
            
            <tr>
                <?php $net_profit_loss = $total_revenue - $total_cogm - $total_expense + $total_other_revenue - $total_other_expense; ?>

                <td class="s4" align='Left'><b>NET PROFIT / LOSS</b></td>
                <td class="s4" align='right' style="<?= ($net_profit_loss < 0)? 'color:#FF6666' : '' ?>"><span><b><?= formatRp_acc($net_profit_loss) ?></b></span></td>
            </tr>
 
            <tr height='50'><td></td></tr>
        </table>
    </div>
    
    <script type="text/javascript">
        $('#hdn_begin_date').val('<?= $BeginDate ?>');    
        $('#hdn_end_date').val('<?= $EndDate ?>');

        function view_journal(journal_number, account_number, $trans_type){
            journal_number  = journal_number.replace(/[/]/g, '~');
            date_begin      = $('#hdn_begin_date').val();
            date_end        = $('#hdn_end_date').val();

            parent.tab_add('Journal Index Report', '<?= "report/index_financial_statement/journal_profit_loss_report/" ?>' + journal_number + '/' + account_number + '/' + $trans_type + '/' + date_begin + '/' + date_end,'icon-add');
        }            
    </script>
</html>
