<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <title><?php echo $menu_label ?></title>
  <link rel="stylesheet" type="text/css" href="<?php echo base_url()?>assets/custom/css/print_new.css">
</head>
<style type="text/css">
  @media print {
    .noPrint { display: none; }
  }
</style>
<body>
    <div id="form-header" data-options="region:'north',border:false">
          <div id="form-header-wrapper">
              <table cellpadding="0" cellspacing="0" width="100%">
              <tr>
                  <td  valign="middle">
                      <a href="#" class="easyui-linkbutton noPrint" data-options="plain:true,iconCls:'icon-print'" onClick="print_detail()">Print</a>
                   </td>
              </tr>
              </table>  
          </div>      
      </div>

	<div id="list-print-container">
        <?php

            $count_date = count($arr_date) + 2;

        ?>
        <table class="header-pp">
            <tr><td colspan="<?=($count_date);?>" class="s2 text-center"><?= $branch->CompanyName; ?></td></tr>
            <tr><td colspan="<?=($count_date);?>" class="s2 text-center"><?= $branch->BranchName; ?></td></tr>
            <tr><td colspan="<?=($count_date);?>" class="s1 text-center">Profit &amp; Loss Report</td></tr>
            <tr><td colspan="<?=($count_date);?>" class="s2 text-center">From : <?= $month_begin.' '.$year_begin; ?>  s/d  <?= $month_end.' '.$year_end; ?></td></tr>
            <tr><td colspan="<?=($count_date);?>">&nbsp;</td></tr>
        </table>

        <table class="content-pp">
            <tr>
                <th class="s4 text-left" align="left" width="250">Description</th>
                <?php for($x=0;$x<$count_date - 2;$x++):?>
                <th class="s4 text-right" align="right">
                    <?php echo change_month_indonesia(abs($arr_date[$x]['month'])).' '.$arr_date[$x]['year'];?>
                </th>
                <?php endfor;?>
                <th class="s4" align="right">Total</th>
            </tr>

             <!-- REVENUE -->
            <tr>
                <td align='left' class="s5 text-left" colspan="6"><span><b>OPERATING REVENUE</b></span></td>
            </tr>
    
            <?php for($x=0;$x<count($arr_revenue);$x++):?>
            <?php
                $subtotal   = 0; 
            ?>
            <tr class="over_report">
                <?php for($n=0;$n<count($arr_date);$n++):?>
                    <?php
                        if($n==0){ 
                            $BeginDate              = date('Y-m-d',strtotime($arr_date[$n]['year'].'-'.$arr_date[$n]['month'].'-01'));
                        }else if(($n+1) == count($arr_date)){
                            $day_month              = date('t', strtotime($arr_date[$n]['year'].'-'.$arr_date[$n]['month']));
                            $EndDate                = date('Y-m-d',strtotime($arr_date[$n]['year'].'-'.$arr_date[$n]['month'].'-'.$day_month));
                        }
                    ?>
                <?php endfor;?>
                <td class="s5 text-left" align='Left' width="250"><a href="#" class="easyui-linkbutton" id="preview-linkbutton" data-options="plain:true" onClick="parent.tab_add('View Journal Profit & Loss','<?php echo 'report/index_financial_statement/open_journal_transaction/'.$arr_revenue[$x]['Account_Number'].'/'.$BeginDate.'/'.$EndDate;?>','icon-journal')"><?php echo $arr_revenue[$x]['Account_Name'];?></a></td>
                <?php for($n=0;$n<count($arr_date);$n++):?>
                    <td class="s5 text-right" align='right' style="<?= ($arr_revenue[$x]['balance'.$n] < 0)? 'color:#FF6666' : '' ?>"><?= formatRp_acc($arr_revenue[$x]['balance'.$n])?></td>
                    <?php $subtotal += $arr_revenue[$x]['balance'.$n];?>
                <?php endfor;?>
                <td class="s5 text-right" align='right' style="<?= ($subtotal < 0)? 'color:#FF6666' : '' ?>"><?= formatRp_acc($subtotal)?></td>
            </tr>
            <?php endfor;?>

            <tr>
                <td colspan="1"></td>
                <td colspan="<?=($count_date+1);?>"><hr/></td>
            </tr>

            <tr class="over_report">
                <td class="s5 text-left" align='Left'><b>Total Operating Revenue</b></td>
                <?php $total      = 0;?>
                <?php for($n=0;$n<count($revenue_group);$n++):?>
                <td class="s5 text-right" align='right' style="<?= ($revenue_group[$n] < 0)? 'color:#FF6666' : '' ?>"><b><?= formatRp_acc($revenue_group[$n])?></b></td>
                <?php $total += $revenue_group[$n];?>
                <?php endfor;?>
                <td class="s5 text-right" align='right' style="<?= ($total < 0)? 'color:#FF6666' : '' ?>"><b><?= formatRp_acc($total)?></b></td>
            </tr>

            <tr height='15'><td colspan="<?=($count_date)+2;?>"></td></tr>

            <tr>
                <td width="100"  align='left' class="s3 text-left"><span><b>COGM / COGS (Cost of Goods Made)</b></span></td>
            </tr>
            
            <!-- COGM -->
            <?php for($x=0;$x<count($arr_cogm);$x++):?>
            <?php
                $subtotal   = 0; 
            ?>
            <tr class="over_report">
                <?php for($n=0;$n<count($arr_date);$n++):?>
                    <?php
                        if($n==0){ 
                            $BeginDate              = date('Y-m-d',strtotime($arr_date[$n]['year'].'-'.$arr_date[$n]['month'].'-01'));
                        }else if(($n+1) == count($arr_date)){
                            $day_month              = date('t', strtotime($arr_date[$n]['year'].'-'.$arr_date[$n]['month']));
                            $EndDate                = date('Y-m-d',strtotime($arr_date[$n]['year'].'-'.$arr_date[$n]['month'].'-'.$day_month));
                        }
                    ?>
                <?php endfor;?>
                <td class="s5 text-left" align='Left' width="250"><a href="#" class="easyui-linkbutton" id="preview-linkbutton" data-options="plain:true" onClick="parent.tab_add('View Journal Profit & Loss','<?php echo 'report/index_financial_statement/open_journal_transaction/'.$arr_cogm[$x]['Account_Number'].'/'.$BeginDate.'/'.$EndDate;?>','icon-journal')"><?php echo $arr_cogm[$x]['Account_Name'];?></a></td>
                <?php for($n=0;$n<count($arr_date);$n++):?>
                    <td class="s5 text-right" align='right' style="<?= ($arr_cogm[$x]['balance'.$n] < 0)? 'color:#FF6666' : '' ?>"><?= formatRp_acc($arr_cogm[$x]['balance'.$n])?></td>
                    <?php $subtotal += $arr_cogm[$x]['balance'.$n];?>
                <?php endfor;?>
                <td class="s5 text-right" align='right' style="<?= ($subtotal < 0)? 'color:#FF6666' : '' ?>"><?= formatRp_acc($subtotal)?></td>
            </tr>
            <?php endfor;?>

            <tr>
                <td colspan="1"></td>
                <td colspan="<?=($count_date+1);?>"><hr/></td>
            </tr>

            <tr class="over_report">
                <td class="s5 text-left" align='Left'><b>Total Operating Cogm</b></td>
                <?php $total      = 0;?>
                <?php for($n=0;$n<count($cogm_group);$n++):?>
                <td class="s5 text-right" align='right' style="<?= ($cogm_group[$n] < 0)? 'color:#FF6666' : '' ?>"><b><?= formatRp_acc($cogm_group[$n])?></b></td>
                <?php $total += $cogm_group[$n];?>
                <?php endfor;?>
                <td class="s5 text-right" align='right' style="<?= ($total < 0)? 'color:#FF6666' : '' ?>"><b><?= formatRp_acc($total)?></b></td>
            </tr>

            <tr height='15'><td colspan="<?=($count_date)+2;?>"></td></tr>

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

            <?php for($x=0;$x<count($arr_expense);$x++):?>
            <?php
                $subtotal   = 0; 
            ?>
            <tr class="over_report">
                <?php for($n=0;$n<count($arr_date);$n++):?>
                    <?php
                        if($n==0){ 
                            $BeginDate              = date('Y-m-d',strtotime($arr_date[$n]['year'].'-'.$arr_date[$n]['month'].'-01'));
                        }else if(($n+1) == count($arr_date)){
                            $day_month              = date('t', strtotime($arr_date[$n]['year'].'-'.$arr_date[$n]['month']));
                            $EndDate                = date('Y-m-d',strtotime($arr_date[$n]['year'].'-'.$arr_date[$n]['month'].'-'.$day_month));
                        }
                    ?>
                <?php endfor;?>
                <td class="s5 text-left" align='Left' width="250"><a href="#" class="easyui-linkbutton" id="preview-linkbutton" data-options="plain:true" onClick="parent.tab_add('View Journal Profit & Loss','<?php echo 'report/index_financial_statement/open_journal_transaction/'.$arr_expense[$x]['Account_Number'].'/'.$BeginDate.'/'.$EndDate;?>','icon-journal')"><?php echo $arr_expense[$x]['Account_Name'];?></a></td>
                <?php for($n=0;$n<count($arr_date);$n++):?>
                    <td class="s5 text-right" align='right' style="<?= ($arr_expense[$x]['balance'.$n] < 0)? 'color:#FF6666' : '' ?>"><?= formatRp_acc($arr_expense[$x]['balance'.$n])?></td>
                    <?php $subtotal += $arr_expense[$x]['balance'.$n];?>
                <?php endfor;?>
                <td class="s5 text-right" align='right' style="<?= ($subtotal < 0)? 'color:#FF6666' : '' ?>"><?= formatRp_acc($subtotal)?></td>
            </tr>
            <?php endfor;?>

            <tr>
                <td colspan="1"></td>
                <td colspan="<?=($count_date+1);?>"><hr/></td>
            </tr>

            <tr class="over_report">
                <td class="s5 text-left" align='Left'><b>Total Operating Expense</b></td>
                <?php $total      = 0;?>
                <?php for($n=0;$n<count($expense_group);$n++):?>
                <td class="s5 text-right" align='right' style="<?= ($expense_group[$n] < 0)? 'color:#FF6666' : '' ?>"><b><?= formatRp_acc($expense_group[$n])?></b></td>
                <?php $total += $expense_group[$n];?>
                <?php endfor;?>
                <td class="s5 text-right" align='right' style="<?= ($total < 0)? 'color:#FF6666' : '' ?>"><b><?= formatRp_acc($total)?></b></td>
            </tr>

            <tr height='15'><td colspan="<?=($count_date)+2;?>"></td></tr>


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

            <?php for($x=0;$x<count($arr_other_revenue);$x++):?>
            <?php
                $subtotal   = 0; 
            ?>
            <tr class="over_report">
                <?php for($n=0;$n<count($arr_date);$n++):?>
                    <?php
                        if($n==0){ 
                            $BeginDate              = date('Y-m-d',strtotime($arr_date[$n]['year'].'-'.$arr_date[$n]['month'].'-01'));
                        }else if(($n+1) == count($arr_date)){
                            $day_month              = date('t', strtotime($arr_date[$n]['year'].'-'.$arr_date[$n]['month']));
                            $EndDate                = date('Y-m-d',strtotime($arr_date[$n]['year'].'-'.$arr_date[$n]['month'].'-'.$day_month));
                        }
                    ?>
                <?php endfor;?>
                <td class="s5 text-left" align='Left' width="250"><a href="#" class="easyui-linkbutton" id="preview-linkbutton" data-options="plain:true" onClick="parent.tab_add('View Journal Profit & Loss','<?php echo 'report/index_financial_statement/open_journal_transaction/'.$arr_other_revenue[$x]['Account_Number'].'/'.$BeginDate.'/'.$EndDate;?>','icon-journal')"><?php echo $arr_other_revenue[$x]['Account_Name'];?></a></td>
                <?php for($n=0;$n<count($arr_date);$n++):?>
                    <td class="s5 text-right" align='right' style="<?= ($arr_other_revenue[$x]['balance'.$n] < 0)? 'color:#FF6666' : '' ?>"><?= formatRp_acc($arr_other_revenue[$x]['balance'.$n])?></td>
                    <?php $subtotal += $arr_other_revenue[$x]['balance'.$n];?>
                <?php endfor;?>
                <td class="s5 text-right" align='right' style="<?= ($subtotal < 0)? 'color:#FF6666' : '' ?>"><?= formatRp_acc($subtotal)?></td>
            </tr>
            <?php endfor;?>

            <tr>
                <td colspan="1"></td>
                <td colspan="<?=($count_date+1);?>"><hr/></td>
            </tr>

            <tr class="over_report">
                <td class="s5 text-left" align='Left'><b>Total Operating Other Revenue</b></td>
                <?php $total      = 0;?>
                <?php for($n=0;$n<count($other_revenue_group);$n++):?>
                <td class="s5 text-right" align='right' style="<?= ($other_revenue_group[$n] < 0)? 'color:#FF6666' : '' ?>"><b><?= formatRp_acc($other_revenue_group[$n])?></b></td>
                <?php $total += $other_revenue_group[$n];?>
                <?php endfor;?>
                <td class="s5 text-right" align='right' style="<?= ($total < 0)? 'color:#FF6666' : '' ?>"><b><?= formatRp_acc($total)?></b></td>
            </tr>

            <tr height='15'><td colspan="<?=($count_date)+2;?>"></td></tr>

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

            <?php
                $total      = 0;
            ?>
            <?php for($x=0;$x<count($arr_other_expense);$x++):?>
            <?php
                $subtotal   = 0; 
            ?>
            <tr class="over_report">
                <?php for($n=0;$n<count($arr_date);$n++):?>
                    <?php
                        if($n==0){ 
                            $BeginDate              = date('Y-m-d',strtotime($arr_date[$n]['year'].'-'.$arr_date[$n]['month'].'-01'));
                        }else if(($n+1) == count($arr_date)){
                            $day_month              = date('t', strtotime($arr_date[$n]['year'].'-'.$arr_date[$n]['month']));
                            $EndDate                = date('Y-m-d',strtotime($arr_date[$n]['year'].'-'.$arr_date[$n]['month'].'-'.$day_month));
                        }
                    ?>
                <?php endfor;?>
                <td class="s5 text-left" align='Left' width="250"><a href="#" class="easyui-linkbutton" id="preview-linkbutton" data-options="plain:true" onClick="parent.tab_add('View Journal Profit & Loss','<?php echo 'report/index_financial_statement/open_journal_transaction/'.$arr_other_expense[$x]['Account_Number'].'/'.$BeginDate.'/'.$EndDate;?>','icon-journal')"><?php echo $arr_other_expense[$x]['Account_Name'];?></a></td>
                <?php for($n=0;$n<count($arr_date);$n++):?>
                    <td class="s5 text-right" align='right' style="<?= ($arr_other_expense[$x]['balance'.$n] < 0)? 'color:#FF6666' : '' ?>"><?= formatRp_acc($arr_other_expense[$x]['balance'.$n])?></td>
                    <?php $subtotal += $arr_other_expense[$x]['balance'.$n];?>
                <?php endfor;?>
                <?php $total    += $subtotal;?>
                <td class="s5 text-right" align='right' style="<?= ($subtotal < 0)? 'color:#FF6666' : '' ?>"><?= formatRp_acc($subtotal)?></td>
            </tr>
            <?php endfor;?>

            <tr>
                <td colspan="1"></td>
                <td colspan="<?=($count_date+1);?>"><hr/></td>
            </tr>

            <tr class="over_report">
                <td class="s5 text-left" align='Left'><b>Total Operating Other Expense</b></td>
                <?php $total      = 0;?>
                <?php for($n=0;$n<count($other_expense_group);$n++):?>
                <td class="s5 text-right" align='right' style="<?= ($other_expense_group[$n] < 0)? 'color:#FF6666' : '' ?>"><b><?= formatRp_acc($other_expense_group[$n])?></b></td>
                <?php $total += $other_expense_group[$n];?>
                <?php endfor;?>
                <td class="s5 text-right" align='right' style="<?= ($total < 0)? 'color:#FF6666' : '' ?>"><b><?= formatRp_acc($total)?></b></td>
            </tr>

            <tr height='30'><td colspan="<?=($count_date)+2;?>"></td></tr>

            <tr>
                <td colspan="1"></td>
                <td colspan="<?=($count_date+1);?>"><hr/></td>
            </tr>

            <tr class="over_report">
                <td class="s4 text-left" align='Left'><b>NET PROFIT / LOSS</b></td>
                <?php $total_pl = 0;?>
                <?php for($x=0;$x<count($arr_PL);$x++):?>
                    <td class="s4 text-right" align='right' style="<?= ($arr_PL[$x] < 0)? 'color:#FF6666' : '' ?>"><span><b><?= formatRp_acc($arr_PL[$x]) ?></b></span></td>
                    <?php $total_pl += $arr_PL[$x];?>
                <?php endfor;?>
                <td class="s4 text-right" align='right' style="<?= ($total_pl < 0)? 'color:#FF6666' : '' ?>"><span><b><?= formatRp_acc($total_pl) ?></b></span></td>
            </tr>
 
            <tr height='50'><td colspan="<?=($count_date)+2;?>"></td></tr>
            
        </table>
    </div>
    
    <script type="text/javascript">
       function print_detail(){
          //var opt_print   = $("input[type='radio'][name='opt_print']:checked").val();
          var data_print  = $("#list-print-container").html();
          Popup(data_print);
          
        }

        function Popup(data) 
        {
            var mywindow = window.open('', 'list-print-container', 'height=528,width=700');
            var css = css_print_lama();
            mywindow.document.write('<html><head><title>Print Detail</title>');
            mywindow.document.write(css);
            mywindow.document.write('</head><body >');
            mywindow.document.write(data);
            mywindow.document.write('</body></html>');

            mywindow.document.close(); // necessary for IE >= 10
            mywindow.focus(); // necessary for IE >= 10

            mywindow.print();
            mywindow.close();

            return true;
        }
    </script>
</body>
</html>
