<?php

$page_security = 'SA_SETUPDISPLAY'; 

include_once($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/includes/ui.inc");
include_once($path_to_root . "/gl/includes/db/gl_db_trans.inc");

include_once("kvcodes.inc");
//display_error(json_encode($_SESSION['wa_current_user']));
if(kv_get_option('hide_dashboard') == 0){ 
	$sql_cust_count = "SELECT COUNT(*) FROM `".TB_PREF."debtors_master`" ;
	$sql_cust_count_result = db_query($sql_cust_count, "could not get sales type");
	$cust_coubt = db_fetch_row($sql_cust_count_result);
	$sql_supp_count = "SELECT COUNT(*) FROM `".TB_PREF."suppliers`" ;
	$sql_supp_count_result = db_query($sql_supp_count, "could not get sales type");
	$sup_count= db_fetch_row($sql_supp_count_result);
	$class_balances = class_balances();
	if(kv_get_option('color_scheme') == 'dark' ){
		$color_scheme = '#ffffff'; 
	}else{
		$color_scheme= '#000000';
	}
	
	$receivables = get_gl_trans_from_to('', Today(), get_company_pref('debtors_act'));  //get_gl_balance_from_to
	$payables = get_gl_trans_from_to('', Today(), get_company_pref('creditors_act'));

	$ShowReceivables = price_format( empty($receivables) ? 0 : round2($receivables, user_price_dec()));
	$ShowPayables = number_format2( empty($payables) ? 0 : round2($payables, user_price_dec()));
?>

<link rel="stylesheet" href='<?php echo $path_to_root."/themes/".user_theme()."/css/morris.css"; ?>'>
<!-- <link rel="stylesheet" href='<?php //echo $path_to_root."/themes/".user_theme()."/css/grid.css"; ?>'> -->
<script src='<?php echo $path_to_root."/themes/".user_theme()."/js/jquery.min.js"; ?>'></script>
<script src="<?php echo $path_to_root."/themes/".user_theme()."/js/raphael-min.js"; ?>"></script>
<script src="<?php echo $path_to_root."/themes/".user_theme()."/js/morris.min.js"; ?>"></script>

 <!-- Main content -->
    <section class="content">
      <!-- Info boxes -->
      <div class="row">

  <?php   	    if($_SESSION["wa_current_user"]->can_access('SA_SHOW_CUSTOMER')==1)	 { ?>
        <div class="col-md-4 col-sm-6 col-xs-12">
          <div class="info-box">
            <span class="info-box-icon bg-aqua"><i class="ion ion-ios-gear-outline"></i></span>

            <div class="info-box-content">
              <span class="info-box-text"><?php echo _("Customers"); ?></span>
              <span class="info-box-number"><?php echo $cust_coubt[0]; ?></span>
            </div>
            <!-- /.info-box-content -->
          </div>
          <!-- /.info-box -->
        </div>

  <?php   } ?>

    <?php  if($_SESSION["wa_current_user"]->can_access('SA_SHOW_CURR_BALANCE')==1)	 { ?>

        <!-- /.col -->
        <div class="col-md-4 col-sm-6 col-xs-12">
          <div class="info-box">
            <span class="info-box-icon bg-red"><i class="fa fa-bank"></i></span>

            <div class="info-box-content">
              <span class="info-box-text"><?php echo _("Current Balance"); ?></span>
              <span class="info-box-number"><?php echo kv_get_current_balance(); ?></span>
            </div>
            <!-- /.info-box-content -->
          </div>
          <!-- /.info-box -->
        </div>

          <?php   } ?>
        <!-- /.col -->

        <!-- fix for small devices only -->
        <div class="clearfix visible-sm-block"></div>

          <?php  if($_SESSION["wa_current_user"]->can_access('SA_SHOW_SUPPLIERS')==1)	 { ?>

        <div class="col-md-4 col-sm-6 col-xs-12">
          <div class="info-box">
            <span class="info-box-icon bg-green"><i class="ion ion-ios-people-outline"></i></span>

            <div class="info-box-content">
              <span class="info-box-text"><?php echo _("Suppliers"); ?></span>
              <span class="info-box-number"><?php echo $sup_count[0]; ?></span>
            </div>
            <!-- /.info-box-content -->
          </div>
          <!-- /.info-box -->
        </div>
          <?php   } ?>

        <!-- /.col -->
		</div> <!-- / row -->
		<div class="row" > 
			  <?php  if($_SESSION["wa_current_user"]->can_access('SA_SHOW_ITEMS')==1)	 { ?>
			<div class="col-md-4 col-sm-6 col-xs-12">
			  <div class="info-box">
				<span class="info-box-icon bg-yellow"><i class="fa fa-database"></i></span>

				<div class="info-box-content">
				  <span class="info-box-text"><?php echo _("Items and Inventory"); ?></span>
				  <span class="info-box-number"><?php 

						$sql_count_items = "SELECT COUNT(*) FROM `".TB_PREF."item_codes`"; 
						$sql_items_count_result = db_query($sql_count_items, "could not get sales type");

						$items_count= db_fetch_row($sql_items_count_result);
						echo $items_count[0];?></span>
				</div>
				<!-- /.info-box-content -->
			  </div>
			  <!-- /.info-box -->
			</div> <!-- /.col -->

			    <?php   } ?>
			

			 <?php  if($_SESSION["wa_current_user"]->can_access('SA_SHOW_PAYBLES')==1)	 { ?>
			<div class="col-md-4 col-sm-6 col-xs-12">
			  <div class="info-box">
				<span class="info-box-icon bg-purple"><i class="fa fa-mail-forward"></i></span>

				<div class="info-box-content">
				  <span class="info-box-text"><?php echo _("Payables"); ?></span>
				  <span class="info-box-number"><?php echo $ShowPayables;?></span>
				</div>
				<!-- /.info-box-content -->
			  </div>
			  <!-- /.info-box -->
			</div> <!-- /.col -->
			   <?php   } ?>
			
				 <?php  if($_SESSION["wa_current_user"]->can_access('SA_RECEIVABLE')==1)	 { ?>
			<div class="col-md-4 col-sm-6 col-xs-12">
			  <div class="info-box">
				<span class="info-box-icon bg-orange"><i class="fa fa-mail-reply"></i></span>

				<div class="info-box-content">
				  <span class="info-box-text"><?php echo _("Receivables"); ?></span>
				  <span class="info-box-number"><?php echo $ShowReceivables;?></span>
				</div>
				<!-- /.info-box-content -->
			  </div>
			  <!-- /.info-box -->
			</div> <!-- /.col -->
			   <?php   } ?>
      </div> <!-- /.row -->

      	<div class="row" > 

        <?php  if($_SESSION["wa_current_user"]->can_access('SA_SALES_ORDER_PENDING')==1)	 { ?>
			<div class="col-md-4 col-sm-6 col-xs-12">
			  <div class="info-box">
				<span class="info-box-icon bg-yellow"><i class="fa fa-database"></i></span>

				<div class="info-box-content">
				  <span class="info-box-text"><?php echo _("Pending Quotation"); ?></span>
				  <span class="info-box-number"> <a href="<?php echo $path_to_root ;?>/sales/inquiry/sales_orders_view.php?type=32 " target="_blank"><?php 

												// $sql_count_items = "SELECT sales.order_no, SUM(line.qty_sent) , sum(line.quantity) FROM ".TB_PREF."sales_orders as sales , ".TB_PREF."sales_order_details as line WHERE sales.order_no=line.order_no AND sales.trans_type=32 AND line.qty_sent=0 AND sales.delivery_date <= '". date2sql(Today())."' AND line.qty_sent=0 GROUP BY sales.order_no"; 

           $sql_count_items = "SELECT sales.order_no, SUM(line.qty_sent) , sum(line.quantity) FROM ".TB_PREF."sales_orders as sales , ".TB_PREF."sales_order_details as line WHERE sales.order_no=line.order_no AND sales.trans_type=line.trans_type AND sales.trans_type=32  GROUP BY sales.order_no"; //AND line.qty_sent<line.quantity 
						// echo $sql_count_items;
						$sql_items_count_result = db_query($sql_count_items, "could not get sales Order");
						$items_count= db_num_rows($sql_items_count_result);
						echo $items_count;?></a></span>
				</div>
				<!-- /.info-box-content -->
			  </div>
			  <!-- /.info-box -->
			</div> <!-- /.col -->
	    <?php   } ?>



	    <?php  if($_SESSION["wa_current_user"]->can_access('SA_DELIVERY_NOTE_PENDING')==1)	 { ?>
			<div class="col-md-4 col-sm-6 col-xs-12">
			  <div class="info-box">
				<span class="info-box-icon bg-purple"><i class="fa fa-mail-forward"></i></span>

				<div class="info-box-content">
				  <span class="info-box-text"><?php echo _("PENDING SALES ORDER"); ?></span>
				  <span class="info-box-number"><a href="<?php echo $path_to_root ;?>/sales/inquiry/sales_orders_view.php?OutstandingOnly=1" target="_blank"><?php 

                    $sql_count_items = "SELECT sales.order_no, SUM(line.qty_sent) , sum(line.quantity) FROM ".TB_PREF."sales_orders as sales , ".TB_PREF."sales_order_details as line WHERE sales.order_no=line.order_no AND sales.trans_type=line.trans_type AND sales.trans_type=30 AND line.qty_sent<line.quantity GROUP BY sales.order_no;"; 

                   
						$sql_items_count_result = db_query($sql_count_items, "could not get delivery note");
						$items_count= db_num_rows($sql_items_count_result);
						echo $items_count;?></a></span>
                        <?php   //  echo  $sql_count_items ; ?>
				</div>
				<!-- /.info-box-content -->
			  </div>
			  <!-- /.info-box -->
			</div> <!-- /.col -->
		<?php   } ?>	
			

		 <?php  if($_SESSION["wa_current_user"]->can_access('SA_PENDING_SALES_INVOICE')==1)	 { ?>
		 	
			<div class="col-md-4 col-sm-6 col-xs-12">
			  <div class="info-box">
				<span class="info-box-icon bg-orange"><i class="fa fa-mail-reply"></i></span>

				<div class="info-box-content">
				  <span class="info-box-text"><?php echo _("Pending Sales Invoices"); ?></span>
				  <span class="info-box-number"><a href="<?php echo $path_to_root ;?>/sales/inquiry/sales_deliveries_view.php?OutstandingOnly=1" target="_blank"><?php 

                    $sql_count_items = "SELECT trans.trans_no, debtor.name, branch.branch_code, branch.br_name, sorder.deliver_to, trans.reference, sorder.customer_ref, trans.tran_date, trans.due_date, (ov_amount+ov_gst+ov_freight+ov_freight_tax) AS DeliveryValue, debtor.curr_code, Sum(line.quantity-line.qty_done) AND sorder.prep_amount=0 AS Outstanding, Sum(line.qty_done) AS Done FROM ".TB_PREF."sales_orders as sorder, ".TB_PREF."debtor_trans as trans, ".TB_PREF."debtor_trans_details as line, ".TB_PREF."debtors_master as debtor, ".TB_PREF."cust_branch as branch WHERE sorder.order_no = trans.order_ AND trans.debtor_no = debtor.debtor_no AND trans.type = 13 AND line.debtor_trans_no = trans.trans_no AND line.debtor_trans_type = trans.type AND trans.branch_code = branch.branch_code AND trans.debtor_no = branch.debtor_no AND line.qty_done < line.quantity GROUP BY trans.trans_no"; 
                    // display_error($sql_count_items);
                     
						$sql_items_count_result = db_query($sql_count_items, "could not get Sale Invoice count");
						$items_count= db_num_rows($sql_items_count_result);
						echo $items_count;?></a></span>

				</div>
				<!-- /.info-box-content -->
			  </div>
			  <!-- /.info-box -->
			</div> <!-- /.col -->

			<?php   } ?>	






  <?php   	    if($_SESSION["wa_current_user"]->can_access('SA_PENDING_RQUISITION')==1)	 { ?>
  <!-- # Purchase Requsition -->
			<div class="col-md-4 col-sm-6 col-xs-12">
			  <div class="info-box">
				<span class="info-box-icon bg-orange"><i class="fa fa-mail-reply"></i></span>

				<div class="info-box-content">
				  <span class="info-box-text"><?php echo _("Pending Requisition"); ?></span>
				  <span class="info-box-number"><a href="<?php echo $path_to_root ;?>/purchasing/inquiry/rq_search_completed.php?show_purch_req=0" target="_blank"><?php 
                       //AND line.quantity_ordered >line.quantity_received 
                  $sql_count_items = "SELECT porder.order_no, porder.reference, supplier.supp_name, location.location_name, porder.requisition_no, porder.ord_date, supplier.curr_code, Sum(line.unit_price*line.quantity_ordered) AS OrderValue, Sum(line.delivery_date < '". date2sql(Today()) ."' AND (line.quantity_ordered > line.quantity_received)) As OverDue, porder.into_stock_location, chk.isopen,porder.is_complete,porder.is_purchase_request,chk.issue FROM ".TB_PREF."req_orders as porder LEFT JOIN ( SELECT order_no,SUM(quantity_received+qty_delivered) as issue, round(SUM(quantity_ordered-quantity_received-qty_delivered),4) isopen FROM ".TB_PREF."req_order_details GROUP BY order_no ) chk ON chk.order_no=porder.order_no,".TB_PREF."req_order_details as line, ".TB_PREF."suppliers as supplier, ".TB_PREF."locations as location WHERE porder.order_no = line.order_no AND porder.supplier_id = supplier.supplier_id AND location.loc_code = porder.into_stock_location  AND porder.is_purchase_request = '0' AND isopen>0 AND is_closed=0 GROUP BY porder.order_no; "; 
                   
						$sql_items_count_result = db_query($sql_count_items, "could not get Sale Invoice count");
						// $items_count= db_fetch_row($sql_items_count_result);
						echo db_num_rows($sql_items_count_result);//$items_count[0];?></a></span>

				</div>
				<!-- /.info-box-content -->
			  </div>
			  <!-- /.info-box -->
			</div> <!-- /.col -->
  <?php   } ?>


  <?php   	    if($_SESSION["wa_current_user"]->can_access('SA_PURCHASEORDER')==1)	 { ?>
  <!-- # Purchase Requsition -->
			<div class="col-md-4 col-sm-6 col-xs-12">
			  <div class="info-box">
				<span class="info-box-icon bg-orange"><i class="fa fa-mail-reply"></i></span>

				<div class="info-box-content">
				  <span class="info-box-text"><?php echo _("Pending Purchase Order <br>Request"); ?></span>
				  <span class="info-box-number"><a href="<?php echo $path_to_root ;?>/purchasing/inquiry/rq_search_completed.php?show_purch_req=1" target="_blank"><?php 
                       //AND line.quantity_ordered >line.quantity_received 
                    $sql_count_items = "SELECT porder.order_no, porder.reference, supplier.supp_name, location.location_name, porder.requisition_no, porder.ord_date, supplier.curr_code, Sum(line.unit_price*line.quantity_ordered) AS OrderValue, Sum(line.delivery_date < '2023-08-22' AND (line.quantity_ordered > line.quantity_received)) As OverDue, porder.into_stock_location, chk.isopen,porder.is_complete,porder.is_purchase_request,chk.issue FROM ".TB_PREF."req_orders as porder LEFT JOIN ( SELECT order_no,SUM(quantity_received+qty_delivered) as issue, SUM(quantity_ordered-quantity_received-qty_delivered) isopen FROM ".TB_PREF."req_order_details GROUP BY order_no ) chk ON chk.order_no=porder.order_no,".TB_PREF."req_order_details as line, ".TB_PREF."suppliers as supplier, ".TB_PREF."locations as location WHERE porder.order_no = line.order_no AND porder.supplier_id = supplier.supplier_id AND location.loc_code = porder.into_stock_location  AND  ( porder.request_location IN (".$_SESSION["wa_current_user"]->location.") OR porder.into_stock_location IN (".$_SESSION["wa_current_user"]->location.") ) AND porder.ord_date >= '2000-08-01' AND porder.ord_date <= '2050-08-22' AND porder.is_purchase_request >0 AND isopen AND is_closed=0 GROUP BY porder.order_no"; 
                      // echo  $sql_count_items ;
                       // display_error($sql_count_items) ;
						$sql_items_count_result = db_query($sql_count_items, "could not get Sale Invoice count");
						// $items_count= db_fetch_row($sql_items_count_result);
						echo db_num_rows($sql_items_count_result);//$items_count[0];?></a></span>

				</div>
				<!-- /.info-box-content -->
			  </div>
			  <!-- /.info-box -->
			</div> <!-- /.col -->
  <?php   } ?>


    <?php 
             // print_r($_SESSION["wa_current_user"]);
      	    if($_SESSION["wa_current_user"]->can_access('SA_PENDING_STORE_REQUEST')==1 && $_SESSION["wa_current_user"]->location!='')	 { ?>
  <!-- # Purchase Requsition -->
			<div class="col-md-4 col-sm-6 col-xs-12">
			  <div class="info-box">
				<span class="info-box-icon bg-orange"><i class="fa fa-mail-reply"></i></span>

				<div class="info-box-content">
				  <span class="info-box-text"><?php echo _("Pending Store Request"); ?></span>
				  <span class="info-box-number"><a href="<?php echo $path_to_root ;?>/purchasing/inquiry/rq_store_search_completed.php?" target="_blank"><?php 
                       //AND line.quantity_ordered >line.quantity_received 
                     $sql_count_items = " SELECT porder.order_no, porder.reference, supplier.supp_name, porder.ord_date, location.location_name, porder.request_location,  porder.into_stock_location, chk.isopen,porder.is_complete,porder.is_purchase_request,chk.issue FROM ".TB_PREF."req_orders as porder LEFT JOIN ( SELECT order_no,SUM(quantity_received+qty_delivered) as issue, SUM(ROUND(quantity_ordered,5) -quantity_received-qty_delivered) isopen FROM ".TB_PREF."req_order_details GROUP BY order_no ) chk ON chk.order_no=porder.order_no,".TB_PREF."req_order_details as line, ".TB_PREF."suppliers as supplier, ".TB_PREF."locations as location WHERE porder.order_no = line.order_no AND porder.supplier_id = supplier.supplier_id AND location.loc_code = porder.into_stock_location  AND  ( porder.request_location IN (".$_SESSION["wa_current_user"]->location.") OR porder.into_stock_location IN (".$_SESSION["wa_current_user"]->location.") )   AND isopen>0  AND is_complete=0  AND is_closed=0 GROUP BY porder.order_no "; 
                      // echo  $sql_count_items ;
						$sql_items_count_result = db_query($sql_count_items, "could not get Sale Invoice count");
						// $items_count= db_fetch_row($sql_items_count_result);
						echo db_num_rows($sql_items_count_result);//$items_count[0];?></a></span>

				</div>
				<!-- /.info-box-content -->
			  </div>
			  <!-- /.info-box -->
			</div> <!-- /.col -->
  <?php   } ?>



    <?php    if($_SESSION["wa_current_user"]->can_access('SA_PENDING_QC_ORDER')==1)	 { ?>
  <!-- # Purchase QC notificaton -->
			<div class="col-md-4 col-sm-6 col-xs-12">
			  <div class="info-box">
				<span class="info-box-icon bg-orange"><i class="fa fa-mail-reply"></i></span>

				<div class="info-box-content">
				  <span class="info-box-text"><?php echo _("Pending INWARD/QC Order "); ?></span>
				  <span class="info-box-number"><a href="<?php echo $path_to_root ;?>/purchasing/inquiry/po_search.php?link=qc_" target="_blank"><?php 

                    $sql_count_items = "SELECT porder.order_no, porder.reference, supplier.supp_name, location.location_name, porder.requisition_no, porder.ord_date, supplier.curr_code, Sum(line.unit_price*line.quantity_ordered) AS OrderValue, Sum(line.delivery_date < '2023-08-23' AND (line.quantity_ordered > line.quantity_received)) As OverDue , porder.is_qc_complete , porder.is_close, SUM(line.in_ward_qty) as in_ward_qty, SUM(line.out_ward_qty) as out_ward_qty, SUM(line.qc_qty) as qc_qty, SUM(line.quantity_ordered) as quantity_ordered, SUM(line.quantity_received) as quantity_received FROM ".TB_PREF."purch_orders as porder,".TB_PREF."purch_order_details as line, ".TB_PREF."suppliers as supplier, ".TB_PREF."locations as location WHERE porder.order_no = line.order_no AND porder.supplier_id = supplier.supplier_id AND location.loc_code = porder.into_stock_location AND (line.quantity_ordered > line.quantity_received) AND is_close=0 AND ( porder.into_stock_location IN (".$_SESSION["wa_current_user"]->qc_location.") OR porder.into_stock_location IN (".$_SESSION["wa_current_user"]->qc_location.") )  AND porder.is_qc_complete=0 GROUP BY porder.order_no "; 
                      // echo  $sql_count_items ;
						$sql_items_count_result = db_query($sql_count_items, "could not get Sale Invoice count");
						// $items_count= db_fetch_row($sql_items_count_result);
						//echo $items_count[0];
						echo db_num_rows($sql_items_count_result);?></a></span>

				</div>
				<!-- /.info-box-content -->
			  </div>
			  <!-- /.info-box -->
			</div> <!-- /.col -->
  <?php   } ?>


    <?php    if($_SESSION["wa_current_user"]->can_access('SA_PENDING_PURCHASE_ORDER_REC')==1)	 { ?>
             <!-- # Purchase notificaton -->
			<div class="col-md-4 col-sm-6 col-xs-12">
			  <div class="info-box">
				<span class="info-box-icon bg-orange"><i class="fa fa-mail-reply"></i></span>

				<div class="info-box-content">
				  <span class="info-box-text"><?php echo _("Pending  GRN"); ?></span>
				  <span class="info-box-number"><a href="<?php echo $path_to_root ;?>/purchasing/inquiry/po_search.php?" target="_blank"><?php 

                         $sql_count_items = "SELECT porder.order_no, porder.reference, supplier.supp_name, location.location_name, porder.requisition_no, porder.ord_date, supplier.curr_code, Sum(line.unit_price*line.quantity_ordered) AS OrderValue, Sum(line.delivery_date < '2023-08-23' AND (line.quantity_ordered > line.quantity_received)) As OverDue , porder.is_qc_complete , porder.is_close, SUM(line.in_ward_qty) as in_ward_qty, SUM(line.out_ward_qty) as out_ward_qty, SUM(line.qc_qty) as qc_qty, SUM(line.quantity_ordered) as quantity_ordered, SUM(line.quantity_received) as quantity_received FROM ".TB_PREF."purch_orders as porder,".TB_PREF."purch_order_details as line, ".TB_PREF."suppliers as supplier, ".TB_PREF."locations as location WHERE porder.order_no = line.order_no AND porder.supplier_id = supplier.supplier_id AND location.loc_code = porder.into_stock_location AND (line.quantity_ordered > line.quantity_received) AND is_close=0 AND ( porder.into_stock_location IN (".$_SESSION["wa_current_user"]->qc_location.") OR porder.into_stock_location IN (".$_SESSION["wa_current_user"]->qc_location.") )  AND porder.is_qc_complete=0 GROUP BY porder.order_no "; 
                      // echo  $sql_count_items ;
							$sql_items_count_result = db_query($sql_count_items, "could not get Sale Invoice count");
						// $items_count= db_fetch_row($sql_items_count_result);
						//echo $items_count[0];
						echo db_num_rows($sql_items_count_result);?></a></span>

				</div>
				<!-- /.info-box-content -->
			  </div>
			  <!-- /.info-box -->
			</div> <!-- /.col -->

   <?php   } ?>



    <?php    if($_SESSION["wa_current_user"]->can_access('SA_PENDING_PURCHASE_INV')==1)	 { ?>

		  <div class="col-md-4 col-sm-6 col-xs-12">
			  <div class="info-box">
				<span class="info-box-icon bg-orange"><i class="fa fa-mail-reply"></i></span>

				<div class="info-box-content">
				  <span class="info-box-text"><?php echo _("Pending Purchase Invoice"); ?></span>
                   <?php
                    $sql_count_items = "SELECT COUNT(*) as count , grn_item.grn_batch_id FROM ".TB_PREF."grn_items   as grn_item  WHERE grn_item.qty_recd - grn_item.quantity_inv > 0   GROUP BY grn_item.grn_batch_id"; 
                      // echo  $sql_count_items ;
						$sql_items_count_result = db_query($sql_count_items, "could not get Sale Invoice count");
						$items_count= db_fetch($sql_items_count_result);
					  $sql=" SELECT * FROM ".TB_PREF."grn_batch WHERE id=".$items_count['grn_batch_id'];
					  // echo $sql;
					  $res=db_query($sql);
					  $row=db_fetch($res);

                    ?>

				  <span class="info-box-number"><a href="<?php echo $path_to_root ;?>/purchasing/supplier_invoice.php?New=1&&supp=<?php echo $row['supplier_id']; ?>" target="_blank"><?php 

                   
						echo $items_count['count'];?></a></span>

				</div>
				<!-- /.info-box-content -->
			  </div>
			  <!-- /.info-box -->
			</div> <!-- /.col -->



      <?php   } ?>		



    <?php    if($_SESSION["wa_current_user"]->can_access('SA_PENDING_WORK_ORDER')==1)	 { ?>

		 <div class="col-md-4 col-sm-6 col-xs-12">
			  <div class="info-box">
				<span class="info-box-icon bg-orange"><i class="fa fa-mail-reply"></i></span>

				<div class="info-box-content">
				  <span class="info-box-text"><?php echo _("Pending Work Order"); ?></span>
				  <span class="info-box-number"><a href="<?php echo $path_to_root ;?>/manufacturing/search_work_orders.php?outstanding_only=1" target="_blank"><?php 

                    $sql_count_items = "SELECT COUNT(*) FROM ".TB_PREF."workorders   as workorder  WHERE  workorder.closed=0"; 
                      // echo  $sql_count_items ;
						$sql_items_count_result = db_query($sql_count_items, "could not get Sale Invoice count");
						$items_count= db_fetch_row($sql_items_count_result);
						echo $items_count[0];?></a></span>

				</div>
				<!-- /.info-box-content -->
			  </div>
			  <!-- /.info-box -->
			</div> <!-- /.col -->
    <?php   } ?>	
      </div> 





	  <?php   	    if($_SESSION["wa_current_user"]->can_access('SA_SHOW_PRODUCTON_PLANR')==1)	 { ?>


	<div class="col-md-12 col-sm-12">
							<div class="box box-info">
								<div class="box-header with-border">
								  <h3 class="box-title"><?php echo _("Production Plane"); ?></h3>
								  <div class="box-tools pull-right">
									<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
									</button>
								  </div>
								</div>
								<div class="box-body chart-responsive">
									<?php  as_production_plan(); 	?>
								</div>
								<!-- /.box-body -->
							</div>								
						</div>
  <?php   } ?>





	  	<div class="row"> 

	  <?php   	    if($_SESSION["wa_current_user"]->can_access('SA_SHOW_CLASS_BALANCE')==1)	 { ?>
		<div class="col-md-6">
			<div class="box box-info">
				<div class="box-header with-border">
				  <h3 class="box-title"><?php echo _("Class Balances"); ?> </h3>

				  <div class="box-tools pull-right">
					<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
					</button>
					<!-- <button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button> -->
				  </div>
				</div>
				<div class="box-body chart-responsive">
					<?php echo '<div class="row" ><div class="col-md-4"> </div><div class="col-md-8" > <select id="ClassPeriods" class="form-control"> <option value="Till Now">'._("Till Now").'</option><option value="Last Week">'._("Last Week").'</option><option value="Last Month">'._("Last Month").'</option> <option value="This Month">'._("This Month").'</option> <option value="Last Quarter Year">'._("Last Quarter Year").'</option></select></div> </div> '; ?>
				  <div class="chart" id="Class_Balance_chart" style="height: 300px; position: relative;"></div>
				</div>
				<!-- /.box-body -->
			</div>
		</div>

		  <?php   } ?>
		
		  <?php   	    if($_SESSION["wa_current_user"]->can_access('SA_SALES_GRAPH')==1)	 { ?>

		<div class="col-md-6">
			<div class="box box-success">
				<div class="box-header with-border">
				  <h3 class="box-title"><?php echo _("Sales"); ?> </h3>
				  <div class="box-tools pull-right">
					<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
					</button>
				  </div>
				</div>
				<div class="box-body chart-responsive">
					<?php echo '<div class="row" ><div class="col-md-4"> </div><div class="col-md-8" > <select id="SalesPeriods" class="form-control"> <option value="Till Now">'._('Till Now').'</option><option value="Last Week">'._('Last Week').'</option><option value="Last Month">'._('Last Month').'</option> <option value="This Month">'._('This Month').'</option> <option value="Last Quarter Year">'._('Last Quarter Year').'</option></select></div> </div> '; ?>
				  <div class="chart" id="Area_chart" style="height: 300px; position: relative;"></div>
				</div>
				<!-- /.box-body -->
			</div>
		</div>
      
       <?php   } ?>

	</div>
	

 	
	<div class="row"> 

				  <?php   	    if($_SESSION["wa_current_user"]->can_access('SA_SHOW_CUSTOMER_PAI_CHART')==1)	 { ?>

		<div class="col-md-6">
			<div class="box box-info">
				<div class="box-header with-border">
				  <h3 class="box-title"><?php echo _("Customers"); ?> </h3>

				  <div class="box-tools pull-right">
					<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
					</button>
					<!-- <button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button> -->
				  </div>
				</div>
				<div class="box-body chart-responsive">
					<?php echo '<div class="row" ><div class="col-md-4"> </div><div class="col-md-8" > <select id="CustomerPeriods" class="form-control"> <option value="Till Now">'._('Till Now').'</option><option value="Last Week">'._('Last Week').'</option><option value="Last Month">'._('Last Month').'</option> <option value="This Month">'._('This Month').'</option> <option value="Last Quarter Year">'._('Last Quarter Year').'</option></select></div> </div> '; ?>
				  <div class="chart" id="donut-customer" style="height: 300px; position: relative;"></div>
				</div>
				<!-- /.box-body -->
			</div>
		</div>

		    <?php   } ?>
		

		  <?php   	    if($_SESSION["wa_current_user"]->can_access('SA_SHOW_SUPPLIER_PAI_CHART')==1)	 { ?>

		<div class="col-md-6">
			<div class="box box-info">
				<div class="box-header with-border">
				  <h3 class="box-title"><?php echo _("Suppliers"); ?> </h3>
				  <div class="box-tools pull-right">
					<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
					</button>
				  </div>
				</div>
				<div class="box-body chart-responsive">
					<?php echo '<div class="row" ><div class="col-md-4"> </div><div class="col-md-8" > <select id="SupplierPeriods" class="form-control"> <option value="Till Now">'._('Till Now').'</option><option value="Last Week">'._('Last Week').'</option><option value="Last Month">'._('Last Month').'</option> <option value="This Month">'._('This Month').'</option> <option value="Last Quarter Year">'._('Last Quarter Year').'</option></select></div> </div> '; ?>
				  <div class="chart" id="donut-supplier" style="height: 300px; position: relative;"></div>
				</div>
				<!-- /.box-body -->
			</div>
		</div>

	    <?php   } ?>

	</div>
	
	<div class="row"> 

	 <?php   	    if($_SESSION["wa_current_user"]->can_access('SA_SHOW_EXPENSE_GRAPH')==1)	 { ?>

		<div class="col-md-6">
			<div class="box box-danger">
				<div class="box-header with-border">
				  <h3 class="box-title"><?php echo _("Expenses"); ?> </h3>

				  <div class="box-tools pull-right">
					<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
					</button>
					<!-- <button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button> -->
				  </div>
				</div>
				<div class="box-body chart-responsive">
					<?php echo '<div class="row" ><div class="col-md-4"> </div><div class="col-md-8" > <select id="ExpensesPeriods" class="form-control"> <option value="Till Now">'._('Till Now').'</option><option value="Last Week">'._('Last Week').'</option><option value="Last Month">'._('Last Month').'</option> <option value="This Month">'._('This Month').'</option> <option value="Last Quarter Year">'._('Last Quarter Year').'</option></select></div> </div> '; ?>
				  <div class="chart" id="expenses_chart" style="height: 300px; position: relative;"></div>
				</div>
				<!-- /.box-body -->
			</div>
		</div>

		    <?php   } ?>
	
	    <?php   	    if($_SESSION["wa_current_user"]->can_access('SA_SHOW_TAX_GRAPH')==1)	 { ?>

		<div class="col-md-6">
			<div class="box box-danger">
				<div class="box-header with-border">
				  <h3 class="box-title"><?php echo _("Taxes"); ?> </h3>
				  <div class="box-tools pull-right">
					<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
					</button>
				  </div>
				</div>
				<div class="box-body chart-responsive">
					<?php echo '<div class="row" ><div class="col-md-4"> </div><div class="col-md-8" > <select id="TaxPeriods" class="form-control"> <option value="Till Now">'._('Till Now').'</option><option value="Last Week">'._('Last Week').'</option><option value="Last Month">'._('Last Month').'</option> <option value="This Month">'._('This Month').'</option> <option value="Last Quarter Year">'._('Last Quarter Year').'</option></select></div> </div> '; ?>
				  <div class="chart" id="donut-Taxes" style="height: 300px; position: relative;"></div>
				</div>
				<!-- /.box-body -->
			</div>
		</div>

		  <?php   } ?>
	</div><!-- /.row -->
	
	
	<?php 
	 if($_SESSION["wa_current_user"]->can_access('SA_SHOW_PAYMENT')==1)	 {
	// Payments
		 $Sales_payment_5 = Top_five_invoices(12); 
		 $payment_lines= '';
		 foreach($Sales_payment_5 as $payment){
$payment_lines .='<tr><th scope="row">'. viewer_link($payment['reference'] ,'gl/view/gl_payment_view.php?trans_no='.$payment['trans_no']).'</th> <td>'.$payment['name'].'</td> <td><span class="label-info" style="padding:0 5px;">'.$payment['curr_code'].'</span></td> <td style="text-align: right">'.price_format($payment['TotalAmount'], user_price_dec()).'</td> </tr>'; 		 }
		echo'<div class="col-sm-6" id="item-16"><div class="box box-primary"> <div class="box-header with-border" data-background-color="orange"><h3 class="box-title">'._('Payments').'</h3><div class="box-tools pull-right">
									<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
									</button>
								  </div></div><div class="box-body table-responsive"> <table class="table "><thead> <tr> <th>#</th><th>'._('Name').'</th> <th>'._('Currency').'</th> <th>'._('Total Amount').'</th></tr> </thead><tbody>'.$payment_lines.'</tbody></table></div></div></div> '; 
								}




			 if($_SESSION["wa_current_user"]->can_access('SA_SHOW_SALES_INVOICES')==1)	 {						
		//Sales Invoice
		$Sales_invoice_5 = Top_five_invoices(); 
		$invoice_lines = ''; 
		foreach($Sales_invoice_5 as $invoice){
	$invoice_lines .= '<tr><th scope="row">'.viewer_link($invoice['reference'] ,'sales/view/view_invoice.php?trans_no='.$invoice['trans_no']."&trans_type=".ST_SALESINVOICE).'</th> <td>'.$invoice['name'].'</td> <td><span class="label-info" style="padding:0 5px;">'.$invoice['curr_code'].'</span></td> <td style="text-align: right;">'.price_format($invoice['TotalAmount'], user_price_dec()).'</td> </tr>';		}
		echo'<div class="col-sm-6" id="item-16"><div class="box box-success"> <div class="box-header with-border" data-background-color="orange"><h3 class="box-title">'._('Sales Invoices').'</h3><div class="box-tools pull-right">
									<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
									</button>
								  </div></div><div class="box-body table-responsive"><table class="table "><thead> <tr> <th>#</th><th>'._('Name').'</th> <th>'._('Currency').'</th> <th>'._('Total Amount').'</th></tr> </thead><tbody>'.$invoice_lines.'</tbody></table></div></div></div>';
               }								  
		 ?>
					<!--<div class="row"> -->

	    <?php   	    if($_SESSION["wa_current_user"]->can_access('SA_SHOW_DUE_SALES_INVOICE')==1)	 { ?>

						<div class="col-md-6 col-sm-12">
							
							<div class="box box-danger">
								<div class="box-header with-border">
								  <h3 class="box-title"><?php echo _("Overdue Sales Invoices"); ?> </h3>
								  <div class="box-tools pull-right">
									<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
									</button>
								  </div>
								</div>
								<div class="box-body chart-responsive">
									<?php  kv_customer_trans(); 	?>
								</div>
								<!-- /.box-body -->
							</div>
						</div>
                     
		           <?php   } ?>

		             <?php    if($_SESSION["wa_current_user"]->can_access('SA_SHOW_BANK_ACC_BAL')==1)	{ ?>  
						<div class="col-md-6 col-sm-12">
							<div class="box box-info">
								<div class="box-header with-border">
								  <h3 class="box-title"><?php echo _("Bank Account Balances"); ?></h3>
								  <div class="box-tools pull-right">
									<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
									</button>
								  </div>
								</div>
								<div class="box-body chart-responsive">
									<?php  kv_bank_balance(); 	?>
								</div>
								<!-- /.box-body -->
							</div>
						</div>
		           <?php   } ?>

					<!--</div>

					<div class="row">-->
				   <?php    if($_SESSION["wa_current_user"]->can_access('SA_SHOW_OVERDUE_RECURRENT_SALES_INV')==1)	{ ?>  	
						<div class="col-md-6 col-sm-12">
							<div class="box box-danger">
								<div class="box-header with-border">
								  <h3 class="box-title"><?php echo _("Overdue Recurrent Sales Invoices"); ?></h3>
								  <div class="box-tools pull-right">
									<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
									</button>
								  </div>
								</div>
								<div class="box-body chart-responsive">
									<?php  kv_customer_recurrent_invoices(); 	?>
								</div>
								<!-- /.box-body -->
							</div>
						</div>
				   <?php   } ?>		

				   <?php    if($_SESSION["wa_current_user"]->can_access('SA_SHOW_AVG_DAILY_SALES')==1)	{ ?>  	

						<div class="col-md-6 col-sm-12">
							<div class="box box-success">
								<div class="box-header with-border">
								  <h3 class="box-title"><?php echo _("Average Daily Sales"); ?></h3>
								  <div class="box-tools pull-right">
									<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
									</button>
								  </div>
								</div>
								<div class="box-body chart-responsive">
									<?php  kv_weekly_sales(); 	?>
								</div>
								<!-- /.box-body -->
							</div>
						</div>
					 <?php   } ?>		
					<!--</div>

					<div class="row"> -->
						
					 <?php    if($_SESSION["wa_current_user"]->can_access('SA_SHOW_DUE_PURCH_INV')==1)	{ ?>  			
						<div class="col-md-6 col-sm-12">
							<div class="box box-danger">
								<div class="box-header with-border">
								  <h3 class="box-title"><?php echo _("Overdue Purchase Invoices"); ?></h3>
								  <div class="box-tools pull-right">
									<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
									</button>
								  </div>
								</div>
								<div class="box-body chart-responsive">
									<?php  kv_supplier_trans(); 	?>
								</div>
								<!-- /.box-body -->
							</div>							
						</div>

					 <?php   } ?>	

				 <?php    if($_SESSION["wa_current_user"]->can_access('SA_SHOW_TOP_TEN_INV_ITEM')==1)	{ ?>  			
				 
						<div class="col-md-6 col-sm-12">
							<div class="box box-info">
								<div class="box-header with-border">
								  <h3 class="box-title"><?php echo _("Top 10 Selling Items and Inventory"); ?></h3>
								  <div class="box-tools pull-right">
									<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
									</button>
								  </div>
								</div>
								<div class="box-body chart-responsive">
									<?php  kv_stock_top(); 	?>
								</div>
								<!-- /.box-body -->
							</div>								
						</div>
					 <?php   } ?>		
						

				 <?php    if($_SESSION["wa_current_user"]->can_access('SA_SHOW_MOST_STAGANT_ITEM')==1)	{ ?>  			
		
						<div class="col-md-6 col-sm-12">
							<div class="box box-info">
								<div class="box-header with-border">
								  <h3 class="box-title"><?php echo _("Most Stagnant Items"); ?></h3>
								  <div class="box-tools pull-right">
									<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
									</button>
								  </div>
								</div>
								<div class="box-body chart-responsive">
									<?php $th = array(_("Item Code"), _("Description"),_("Stock"), _("Sales Qty"), _("Last Sale"));

									start_table(TABLESTYLE, "width='100%'");
									table_header($th);
									$stagnants = most_stagnant_items(Today()); 
									if(count($stagnants)>0){
										foreach($stagnants as $single) {
											echo '<tr><td>'.$single[0].'</td><td>'.$single[1].'</td> <td> '.$single[2].'</td><td>'.$single[3].'</td><td> '.sql2date($single[4]).'</td></tr>';
										}
									} else {
										start_row();
										echo '<td colspan="5"> No Stagnant items </td>';
										end_row();
									}
									end_table(); ?>
								</div>
								<!-- /.box-body -->
							</div>								
						</div>
					 <?php   } ?>			
					<!-- </div>

					<div class="row"> -->
				 <?php    if($_SESSION["wa_current_user"]->can_access('SA_SHOW_CLASS_BALANCE_SUM')==1)	{ ?>  			
						<div class="col-md-6 col-sm-12">
							<div class="box box-success">
								<div class="box-header with-border">
								  <h3 class="box-title"><?php echo _("Class Balances"); ?> </h3>
								  <div class="box-tools pull-right">
									<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
									</button>
								  </div>
								</div>
								<div class="box-body chart-responsive">
									<?php  kv_gl_top(); 	?>
								</div>
								<!-- /.box-body -->
							</div>								
						</div>
				 <?php   } ?>		
						


							<!-- Arrival Status -->

							<div class="col-md-6 col-sm-12">
							<div class="box box-info">
								<div class="box-header with-border">
								  <h3 class="box-title"><?php echo _("Arrival Status"); ?></h3>
								  <div class="box-tools pull-right">
									<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
									</button>
								  </div>
								</div>
								<div class="box-body chart-responsive">
									<?php  get_delivery_date_arrival(); 	?>
								</div>
								<!-- /.box-body -->
							</div>
						</div>


							<!-- Arrived Status -->

						<div class="col-md-6 col-sm-12">
						<div class="box box-info">
							<div class="box-header with-border">
							  <h3 class="box-title"><?php echo _("Arrived Status"); ?></h3>
							  <div class="box-tools pull-right">
								<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
								</button>
							  </div>
							</div>
							<div class="box-body chart-responsive">
								<?php  get_delivery_date_arrived(); 	?>
							</div>
							<!-- /.box-body -->
						</div>
					</div>

						<div class="col-md-6 col-sm-12">
							<!--<div class="card">
	                            <div class="card-header" data-background-color="orange">
	                                <h4 class="title">Top 10 Selling Items and Inventory</h4>
	                            </div>
	                            <div class="card-content table-responsive">
	                            	<?php  //kv_stock_top(); 	?>
	                            </div>
	                        </div> -->
						</div>
						</div>
			<!-- </div> -->
			
			
    </section>

<?php 

$protocol = $protocol = $_SERVER['REQUEST_SCHEME'] . '://'; //stripos($_SERVER['SERVER_PROTOCOL'],'https') === true ? 'https://' : 'http://';
$actual_link = $protocol.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];

$actual_link =  strtok($actual_link, '?');
$actual_link = str_replace("index.php", "", $actual_link);
 ?>

<script>

if($("#donut-Taxes").length){ //  #################  
  var Tax_Donut_Chart = Morris.Donut({
    element: 'donut-Taxes',
    behaveLikeLine: true,
    parseTime : false,
    data: [{"value":"","label":"", labelColor: '<?php echo $color_scheme; ?>'}],  
    colors: [ '#f26c4f', '#00a651', '#00bff3', '#0072bc','#ff6264', '#455064',  '#707f9b', '#b92527',  '#242d3c', '#d13c3e', '#d13c3e',  '#ff6264', '#ffaaab', '#b92527'],
    redraw: true,
  });
  $("#TaxPeriods").on("change", function(){
       var option = $(this).val(); 
       $.ajax({
          type: "POST",
          url: "<?php echo $actual_link; ?>themes/LTE/includes/ajax.php?Tax_chart="+option,
          data: 0,
          dataType: 'json',
          success: function(taxdata){      
        		//var grandtotal = data.grandtotal;	 // delete data.grandtotal;	  //delete data[4];
        		console.log(taxdata);
            Tax_Donut_Chart.setData(taxdata);
        		// var arr = $.parseJSON(data);  //alert(data.grandtotal);	  //$("#GrandTaxTotal").html(grandtotal);
            /* setCookie('numbers',data,3); $('.flash').show(); $('.flash').html("Template Updated")*/
          }
    });
  }); 
 }

 if($("#expenses_chart").length){ //   ######### 
	 var Expenses_Bar_Chart = Morris.Bar({
	  element: 'expenses_chart',
	  behaveLikeLine: true,
	  parseTime : false,
	  data: [{ "y": "Nothing" , "a" : "0", "labelColor": '<?php echo $color_scheme; ?>'} ],
	  xkey: 'y',
	  ykeys: ['a'],
	  labels: ['Expenses' ],
	  barColors: ['#f26c4f', '#00a651', '#00bff3', '#0072bc', '#707f9b', '#455064', '#242d3c', '#b92527', '#d13c3e', '#ff6264', '#ffaaab'],
	  redraw: true
	});
	 $("#ExpensesPeriods").on("change", function(){
		 var option = $(this).val(); 
		 $.ajax({
				type: "POST",
				url: "<?php echo $actual_link; ?>themes/LTE/includes/ajax.php?Expense_chart="+option,
				data: 0,
				dataType: 'json',
				success: function(data){
				  console.log(data);
				  Expenses_Bar_Chart.setData(data);
				   /* setCookie('numbers',data,3); $('.flash').show(); $('.flash').html("Template Updated")*/
				}
		  });
	  }); 
  }

    //  ##########################################
   if($("#Class_Balance_chart").length){
      var Line_Chart = Morris.Bar({
        element: 'Class_Balance_chart',
        behaveLikeLine: true,
        parseTime : false,
        data: [ <?php foreach($class_balances as $balance) { echo " { class: '".$balance['class_name']."', value: ".abs($balance['total'])." }," ; } ?> ],    
        xkey: 'class',
        ykeys: ['value'],
        labels: ['Value'],
        lineColors: ['#f26c4f', '#00a651', '#00bff3', '#0072bc', '#707f9b', '#455064', '#242d3c', '#b92527', '#d13c3e', '#ff6264', '#ffaaab'],
        redraw: true,
        pointFillColors: ['#455064']
      });

      $("#ClassPeriods").on("change", function(){
         var type = $(this).val(); 
         $.ajax({
            type: "POST",
            url: "<?php echo $actual_link; ?>themes/LTE/includes/ajax.php?Line_chart="+type,
            data: 0,
            dataType: 'json',
            success: function(data){    console.log(data);
              Line_Chart.setData(data);
              /* setCookie('numbers',data,3); $('.flash').show(); $('.flash').html("Template Updated")*/
            }
        });
      }); 
   }	

if($("#Area_chart").length){//  ################   
    var Area_chart = Morris.Area({
      element: 'Area_chart',  
      behaveLikeLine: true,
      parseTime : false, 
      data: [ ],
      xkey: 'y',
      ykeys: ['a', 'b'],
      labels: ['Sales', 'Cost'],
      pointFillColors: ['#707f9b'],
      pointStrokeColors: ['#ffaaab'],
      lineColors: ['#f26c4f', '#00a651', '#00bff3'],
      redraw: true      
    });

    $("#SalesPeriods").on("change", function(){
     var selected_user_ID = $(this).val(); 
     $.ajax({
            type: "POST",
            url: "<?php echo $actual_link; ?>themes/LTE/includes/ajax.php?Area_chart="+selected_user_ID,
            data: 0,
            dataType: 'json',
            success: function(data){
              console.log(data);
              Area_chart.setData(data);
            }
          });
  }); 
}

if($("#donut-customer").length){//  #################  
    var Customer_Donut_Chart = Morris.Donut({
      element: 'donut-customer',
      behaveLikeLine: true,
      parseTime : false,
      data: [{"value":"","label":"", "labelColor": '<?php echo $color_scheme; ?>'}],
      colors: ['#f26c4f', '#00a651', '#00bff3', '#0072bc', '#707f9b', '#455064', '#242d3c', '#b92527', '#d13c3e', '#ff6264', '#ffaaab'],
      redraw: true,
    });
    $("#CustomerPeriods").on("change", function(){
         var option = $(this).val(); 
         $.ajax({
            type: "POST",
            url: "<?php echo $actual_link; ?>themes/LTE/includes/ajax.php?Customer_chart="+option,
            data: 0,
            dataType: 'json',
            success: function(data){
             console.log(data);
              Customer_Donut_Chart.setData(data);
              /* setCookie('numbers',data,3); $('.flash').show(); $('.flash').html("Template Updated")*/
            }
        });
    });
}

if($("#donut-supplier").length){ //  #################  
var Supplier_Donut_Chart = Morris.Donut({
  element: 'donut-supplier',
  behaveLikeLine: true,
  parseTime : false,
  data: [{"value":"","label":"", "labelColor": '<?php echo $color_scheme; ?>'}],  
  colors: [  '#ff6264', '#455064', '#d13c3e', '#d13c3e',  '#ff6264', '#ffaaab', '#f26c4f', '#00a651', '#00bff3', '#0072bc', '#b92527', '#707f9b', '#b92527',  '#242d3c'],
  redraw: true,
});
$("#SupplierPeriods").on("change", function(){
     var option = $(this).val(); 
     $.ajax({
        type: "POST",
        url: "<?php echo $actual_link; ?>themes/LTE/includes/ajax.php?Supplier_chart="+option,
        data: 0,
        dataType: 'json',        
        success: function(data){
          console.log(data);
          Supplier_Donut_Chart.setData(data);
          /* setCookie('numbers',data,3); $('.flash').show(); $('.flash').html("Template Updated")*/
        }
      });
  }); 
 }

 // $(document).ready(function(e){
	 
      $("#SalesPeriods").trigger("change");
      $("#CustomerPeriods").trigger("change");
      $("#SupplierPeriods").trigger("change");
      $("#ExpensesPeriods").trigger("change");
      $("#TaxPeriods").trigger("change");
 // }); 
 </script>
 <div style="clear:both;" > </div>
<?php } else { 

echo '<div style="line-height:200px; text-align:center;font-size:24px; vertical-align:middle;" > '._('Page not found').' </div>'; 

} ?>