<?php include("../includes/config.php");
$title = "Welcome";

isAdminLoggedIn();

include('../includes/header.php');
?>

<div class="page-content-wrap">  
	<div class="row">
        <br>
    </div>  
   
   		 <!-- START BREADCRUMB -->
       
        <!-- END BREADCRUMB -->                       
        
        <!-- PAGE CONTENT WRAPPER -->
        <div class="page-content-wrap">  
                         
            <div class="row">
                <div class="col-md-12">
                    <?php
                        $company_qry = "select * from np_company where is_delete ='0' and status='1'  ORDER BY name ASC";
                        $company_info = $db->selectAll($company_qry);
                        $maincompanybalance=0;                       
                        if(!empty($company_info)){                      
                            foreach ($company_info as $key => $company_info) {
                                $totalcompanybalance=0;
                                $maincompanybalance=($maincompanybalance+$totalcompanybalance);
                                echo '<div class="col-md-12">';
                                    echo '<div class="panel panel-warning">';
                                        echo '<div class="panel-heading" style="background-color:#dff0d8;">';
                                            echo '<h3 class="panel-title" style="font-weight: bold;">'.strtoupper($company_info['name']).'</h3>';
                                            echo '<ul class="panel-controls"><li><a href="#" class="panel-collapse" style="border: 2px solid #000000;"><span class="fa fa-angle-down"></span></a></li></ul>';
                                        echo '</div>';
                                        echo '<div class="panel-body panel-body-table">';
                                            echo '<div class="table-responsive">';
                                                echo '<table class="table table-bordered table-striped table-actions">';
                                                    echo '<thead>';
                                                        echo '<tr>';
                                                             echo '<th class="text-center">NAME</th>';
                                                             echo '<th class="text-center">BANK NAME</th>';
                                                             echo '<th class="text-center">BALANCE</th>';
                                                             echo '<th class="text-center">LAST UPDATE DATE</th>';
                                                         echo '</tr>';
                                                    echo '</thead>';
                                                    echo '<tbody>';
                                                        $company_acc_qry = "select cwan.id,cwan.name,cwan.bankaccno,bank.name as bankname,current.cbalance,current.last_update_datetime FROM np_company_wise_account_name as cwan LEFT JOIN np_bank as bank ON bank.id=cwan.bankidfk LEFT JOIN np_currentbalance as current ON current.bankaccno=cwan.bankaccno where cwan.is_delete ='0' and cwan.status='1' and cwan.company_fk='".$company_info['id']."' ORDER BY name ASC";
                                                        $company_acc_info = $db->selectAll($company_acc_qry); 
                                                        if(!empty($company_acc_info)){                      
                                                            foreach ($company_acc_info as $company_acc_infokey => $company_acc_info) { 
                                                                $totalcompanybalance = ($totalcompanybalance+$company_acc_info['cbalance']);                                       
                                                                echo '<tr id="trow_1">';
                                                                    echo '<td class="text-center">'.$company_acc_info['name'].'</td>';
                                                                    echo '<td class="text-center">'.$company_acc_info['bankname'].'</td>';
                                                                    if($company_acc_info['cbalance']!=''){
                                                                        echo '<td><span class="label label-success">'.number_format($company_acc_info['cbalance'], 2, '.', '').'</span></td>';
                                                                    }else{ echo '<td class="text-center">--</td>';  }
                                                                    if($company_acc_info['last_update_datetime']!=''){
                                                                        echo '<td class="text-center">'.date('d-m-Y',strtotime($company_acc_info['last_update_datetime'])).'</td>';
                                                                    }else{ echo '<td class="text-center">--</td>'; }
                                                                echo '</tr>';
                                                            }
                                                            echo '<tr class="success" id="trow_1">';
                                                                    echo '<td class="text-center" colspan="2">TOTAL</td>';
                                                                    echo '<td class="text-center"><h2><b>'.number_format($totalcompanybalance, 2, '.', '').'</b></h2></td>';
                                                                    echo '<td class="text-center"></td>';
                                                            echo '</tr>';
                                                            $maincompanybalance=($maincompanybalance+$totalcompanybalance);
                                                        }
                                                    echo '</tbody>';
                                                echo '</table>';
                                            echo '</div>';
                                        echo '</div>';
                                    echo '</div>';
                                echo '</div>';
                            }
                        }
                        echo '<div class="col-md-12">';
                                echo '<div class="widget widget-info widget-item-icon" style="min-height:auto">';
                                    echo '<div class="widget-int num-count">ALL COMPANY TOTAL BALANCE</div>';
                                    echo '<div class="widget-title">'.number_format($maincompanybalance, 2, '.', '').'</div>';

                                echo '</div>';
                        echo '</div>';
                    ?>
                </div>
                
                <?php
                    $personal_info = "SELECT current.cbalance as totalbalance,personal.name,bank.name as bankname FROM np_currentbalance as current LEFT JOIN np_accounts as acc ON acc.id=current.accid LEFT JOIN np_bank as bank ON bank.id=acc.bankname LEFT JOIN np_personal as personal ON personal.id=acc.accname WHERE  current.cbalance!='' and acc.atype='Personal' Order by bank.name,personal.name ASC";
                    $personal_info = $db->selectAll($personal_info);
                     $totalpersonalbalance=0;
                    foreach ($personal_info as $key => $personal_info) {
                        $totalpersonalbalance = ($totalpersonalbalance+$personal_info['totalbalance']);
                        echo '<div class="col-md-2">';
                            echo '<div class="widget widget-info widget-item-icon" style="min-height:auto">';
                                echo '<div class="widget-int num-count">'.number_format($personal_info['totalbalance'], 2, '.', '').'</div>';
                                echo '<div class="widget-title">'.strtoupper($personal_info['name']).'</div>';
                                echo '<div class="widget-subtitle">'.strtoupper($personal_info['bankname']).'</div>';

                            echo '</div>';
                        echo '</div>';
                    }
                    echo '<div class="col-md-12">';
                            echo '<div class="widget widget-info widget-item-icon" style="min-height:auto">';
                                echo '<div class="widget-int num-count">PERSONAL TOTAL</div>';
                                echo '<div class="widget-title">'.number_format($totalpersonalbalance, 2, '.', '').'</div>';

                            echo '</div>';
                    echo '</div>';
                    
                ?>
            </div>
            
           
            
        </div>
        <!-- END PAGE CONTENT WRAPPER -->   
   
    
</div>
<?php include('../includes/footer.php');?>