<?php
/*-------------------------------------------------------+
| LTE Theme for FrontAccounting
| http://www.kvcodes.com/
+--------------------------------------------------------+
| Author: Kvvaradha  
| Email: admin@kvcodes.com
+--------------------------------------------------------+*/

class show_notification {

    function get_overdue_invoices() {
        global $path_to_root ;
        $today = date2sql(Today());

        $sql = "SELECT COUNT(debtor.debtor_no) AS Icount FROM ".TB_PREF."debtor_trans as trans, ".TB_PREF."debtors_master as debtor, ".TB_PREF."cust_branch as branch WHERE debtor.debtor_no = trans.debtor_no AND trans.branch_code = branch.branch_code AND trans.type = ".ST_SALESINVOICE." AND (trans.ov_amount + trans.ov_gst + trans.ov_freight + trans.ov_freight_tax + trans.ov_discount - trans.alloc) > ".FLOAT_COMP_DELTA." AND trans.due_date<'".$today."' ORDER BY due_date DESC ";

        $result = db_query($sql, "could not get sales type");
        $row = db_fetch_row($result);
        
        echo '<li class="dropdown messages-menu">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown">
              <i class="fa fa-credit-card"></i>
              <span class="label label-success">'.$row[0].'</span>
            </a>
            <ul class="dropdown-menu">
              <li class="header">You have '.$row[0].' Overdue Payments </li>';
                if($row[0] > 0) {
            $sql = "SELECT  trans.due_date, debtor.debtor_no, debtor.name,(trans.ov_amount + trans.ov_gst + trans.ov_freight + trans.ov_freight_tax + trans.ov_discount) AS total FROM ".TB_PREF."debtor_trans as trans, ".TB_PREF."debtors_master as debtor,".TB_PREF."cust_branch as branch WHERE debtor.debtor_no = trans.debtor_no AND trans.branch_code = branch.branch_code AND trans.type = ".ST_SALESINVOICE." AND (trans.ov_amount + trans.ov_gst + trans.ov_freight + trans.ov_freight_tax + trans.ov_discount - trans.alloc) > ".FLOAT_COMP_DELTA." AND trans.due_date<'".$today."' ORDER BY due_date DESC LIMIT 10";
            $result = db_query($sql);
            echo '<li>
                <!-- inner menu: contains the actual data -->
                <ul class="menu">';
                 while ($myrow = db_fetch($result)) {
                  echo '<li><!-- start message -->
                    <a href="'.$path_to_root.'/sales/customer_payments.php?customer_id='.$myrow['debtor_no'].'">                      
                      <h4>
                       '.$myrow['name'].'
                        <small> '.price_format($myrow['total']).'</small>
                      </h4>
                    </a>
                  </li>';
              }
               echo '  <!-- end message -->                   
                </ul>
              </li>
              <li class="footer"><a href="'.$path_to_root.'/sales/inquiry/customer_inquiry.php?filterType=3">See All Payments</a></li>';             
            
          }
            echo '</ul>
          </li>';

        
    }

    function get_inventory_reorder() {
        global $path_to_root;
        include_once($path_to_root . "/includes/session.inc");
        include_once($path_to_root . "/includes/date_functions.inc");
        include($path_to_root . "/includes/ui.inc");

        $sql = "SELECT reorder.* FROM (SELECT ".TB_PREF."stock_master.stock_id, ".TB_PREF."stock_master.description, SUM(IF(".TB_PREF."stock_moves.stock_id IS NULL,0,".TB_PREF."stock_moves.qty)) AS QtyOnHand ,".TB_PREF."loc_stock.reorder_level, ".TB_PREF."stock_moves.loc_code FROM (".TB_PREF."stock_master, ".TB_PREF."stock_category,".TB_PREF."loc_stock) LEFT JOIN ".TB_PREF."stock_moves ON (".TB_PREF."stock_master.stock_id=".TB_PREF."stock_moves.stock_id) WHERE ".TB_PREF."stock_master.category_id=".TB_PREF."stock_category.category_id AND ".TB_PREF."stock_master.stock_id=".TB_PREF."loc_stock.stock_id AND (".TB_PREF."stock_master.mb_flag='B' OR ".TB_PREF."stock_master.mb_flag='M') AND ".TB_PREF."loc_stock.reorder_level!=0  AND ".TB_PREF."stock_moves.loc_code=".TB_PREF."loc_stock.loc_code GROUP BY ".TB_PREF."stock_master.category_id, ".TB_PREF."stock_category.description, ".TB_PREF."stock_master.stock_id, ".TB_PREF."stock_master.description ,".TB_PREF."stock_moves.loc_code ORDER BY QtyOnHand DESC LIMIT 10) reorder WHERE reorder.QtyOnHand < reorder.reorder_level";
        $result = db_query($sql, _('Could not get Items details'));
        // display_error($sql);
        echo '<li class="dropdown notifications-menu">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown">
              <i class="fa fa-refresh"></i>
              <span class="label label-warning">'.db_num_rows($result).'</span>
            </a>
            <ul class="dropdown-menu">
              <li class="header">You have '.db_num_rows($result).' reorders</li>
              <li>
                <!-- inner menu: contains the actual data -->
                <ul class="menu">';
                while ($row=db_fetch($result)) {
                  // print_r($row);
                    echo '<li> <a href="'.$path_to_root.'/inventory/inquiry/stock_status.php?stock_id='.$row["stock_id"].'" > '. $row["description"] .' - '. price_format($row['QtyOnHand']) .'in Hand For loc "'.$row["loc_code"].'" </a>  </li> ';
                   
                } 
                echo'                  
                </ul>
              </li>
              <li class="footer"><a href="'.$path_to_root.'/inventory/inquiry/stock_status.php">View all</a></li>
            </ul>
          </li>';
    }

 function get_post_date_cheque() {
        global $path_to_root;
        include_once($path_to_root . "/includes/session.inc");
        include_once($path_to_root . "/includes/date_functions.inc");
        include($path_to_root . "/includes/ui.inc");
        $today = date2sql(Today());
        global $systypes_array;

            $sql = "SELECT 
          pct.trans_no,
          pct.type,
          pct.date_,
          pct.bank_id,
          pct.cheque_no,
          pct.post_date,
          pct.total_amount,
          pct.comments,
          ptd.invocie_type,
          ptd.invocie_trans_no,
          pct.person_id
        FROM ".TB_PREF."post_cheque_trans pct , ".TB_PREF."post_trans_detail 
        ptd WHERE pct.trans_no=ptd.trans_no AND pct.is_posted_status=0 AND pct.post_date='".$today."'" ;

          $sql .= " GROUP BY pct.trans_no";


        $result = db_query($sql, _('Could not get Items details'));
        // display_error($sql);
        echo '<li class="dropdown notifications-menu">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown">
              <i class="fa fa-cc"></i>
              <span class="label label-warning">'.db_num_rows($result).'</span>
            </a>
            <ul class="dropdown-menu">
              <li class="header">You have '.db_num_rows($result).' Post Dated Cheque</li>
              <li>
                <!-- inner menu: contains the actual data -->
                <ul class="menu">';
                while ($row=db_fetch($result)) {
                  // print_r($row);

                  if($row['type']==ST_SUPPAYMENT)
                  echo '<li> <a href="'.$path_to_root.'/purchasing/supplier_payment.php?New=1&post_check_trans_no='.$row["trans_no"].'" > <b>  Trans Type : </b> '.$systypes_array[$row['type']].' - <b> Cheque No : </b>  '. $row["cheque_no"] .' - <b>Post Date : </b> '. sql2date($row['post_date']) .' - <b>Total Amount : </b> '.$row["total_amount"].' </a>  </li> ';
                  else
                  echo '<li> <a href="'.$path_to_root.'/gl/gl_bank.php?NewPayment=Yes&post_check_trans_no='.$row["trans_no"].'" > <b>  Trans Type : </b> '.$systypes_array[$row['type']].' - <b>Cheque No : </b>  '. $row["cheque_no"] .' - <b>Post Date : </b> '. sql2date($row['post_date']) .' - <b>Total Amount : </b> '.$row["total_amount"].'</a>  </li> ';

                  // return pager_link(_("Payment"), "/purchasing/supplier_payment.php?New=1&post_check_trans_no=".$row["trans_no"], ICON_RECEIVE);
                  // return pager_link(_("Payment"), "/gl/gl_bank.php?NewPayment=Yes&post_check_trans_no=".$row["trans_no"], ICON_RECEIVE);
                   
                } 
                echo'                  
                </ul>
              </li>
              <li class="footer"><a href="'.$path_to_root.'/gl/inquiry/post_date_inquiry.php?">View all</a></li>
            </ul>
          </li>';
    }

  function get_supplier_payments() {
        
        global $path_to_root ;
        $today = date2sql(Today());
        $sql1 = "SELECT COUNT(s.supplier_id) AS Bcount FROM ".TB_PREF."supp_trans as trans, ".TB_PREF."suppliers as s WHERE s.supplier_id = trans.supplier_id AND trans.type = ".ST_SUPPINVOICE." AND due_date>=".$today." AND (ABS(trans.ov_amount + trans.ov_gst + trans.ov_discount) - trans.alloc) > ".FLOAT_COMP_DELTA." "; 
        $sql1 .= " AND DATEDIFF('$today', trans.due_date) > 0  "; 
        $result1 = db_query($sql1); 
        $row = db_fetch_row($result1);

        // $next = date("Y/m/d", mktime(0, 0, 0, date("m")+1 , date("d"),date("Y")));
        // $month=date2sql($next);
        $sql1 = "SELECT   trans.tran_date, trans.due_date,s.supp_name,s.supplier_id,(trans.ov_amount + trans.ov_gst + trans.ov_discount) AS total FROM ".TB_PREF."supp_trans as trans, ".TB_PREF."suppliers as s WHERE s.supplier_id = trans.supplier_id AND trans.type = ".ST_SUPPINVOICE." AND due_date>=".$today." AND (ABS(trans.ov_amount + trans.ov_gst + trans.ov_discount) - trans.alloc) > ".FLOAT_COMP_DELTA."";
        $sql1 .= " AND DATEDIFF('$today', trans.due_date) > 0 ORDER BY total DESC LIMIT 10";
        $result1 = db_query($sql1);

        /*    echo "<li>";
                while ($myrow1 = db_fetch($result1)) {
                    echo "<a href = '$path_to_root/purchasing/supplier_payment.php?supplier_id=".$myrow1['supplier_id']."' class='dropdown_content'><span class = 'pull-left'>".$myrow1['supp_name']. "</span><span class='pull-right'>".price_format($myrow1['total'])."</span></a>";
                }
            echo "</li>";*/


        echo '<li class="dropdown messages-menu">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown">
              <i class="fa fa-send"></i>
              <span class="label label-danger">'.$row[0].'</span>
            </a>
            <ul class="dropdown-menu">
              <li class="header">You have '.$row[0].' Supplier Payment</li>
             <li> <ul class="menu" > ';

              while($myrow1 = db_fetch($result1)) {
              echo '<li><!-- start message -->
                    <a href="'.$path_to_root.'/purchasing/supplier_payment.php?supplier_id='.$myrow1['supplier_id'].'">                      
                      <h4>'.$myrow1['supp_name'].'<small> '.price_format($myrow1['total']).'</small>
                      </h4>
                    </a>
                  </li>';
                }                  
               echo '</ul> </li> <li class="footer">  <a href="'.$path_to_root.'/purchasing/supplier_payment.php">View All</a> </li>
            </ul>
          </li>'; 
    }
    
function dollar_booking_receiving()
{
    global $path_to_root;

   $sql = "SELECT * FROM ".TB_PREF."dollar_booking receiving_status WHERE receiving_status != 1 ";

    $result = db_query($sql, _('Could not get Items details'));

    echo '<li class="dropdown notifications-menu">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown">
              <i class="fa fa-bell"></i>
              <span class="label label-warning">'.db_num_rows($result).'</span>
            </a>
            <ul class="dropdown-menu">
              <li class="header">You have '.db_num_rows($result).' Receiving Journal Entry </li>
              <li>
                <!-- inner menu: contains the actual data -->
                <ul class="menu">';
    while ($row = db_fetch($result)) {
        echo '<li><a href="'.$path_to_root.'/gl/gl_journal.php?NewJournal=Yes&dollar_booking_id='.$row["id"].'">'. get_customer_name($row["customer"]) . ' - '. sql2date($row["receiving_date"]). '</a></li>';
    } 
    echo '</ul>
          </li>
          <li class="footer"><a href="'.$path_to_root.'/gl/inquiry/dollar_booking_inquiry.php?">View all</a></li>
        </ul>
      </li>';
}

function dollar_booking_due_date_receiving()
{
    global $path_to_root;

   $sql = "SELECT * FROM ".TB_PREF."dollar_booking receiving_status WHERE receiving_status = 1 AND due_date_receiving_status != 1";

    $result = db_query($sql, _('Could not get Items details'));

    echo '<li class="dropdown notifications-menu">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown">
              <i class="fa fa-bell"></i>
              <span class="label label-warning">'.db_num_rows($result).'</span>
            </a>
            <ul class="dropdown-menu">
              <li class="header">You have '.db_num_rows($result).' Due Date Journal Entry </li>
              <li>
                <!-- inner menu: contains the actual data -->
                <ul class="menu">';
    while ($row = db_fetch($result)) {
        echo '<li><a href="'.$path_to_root.'/gl/gl_journal.php?NewJournal=Yes&due_dollar_booking_id='.$row["id"].'">'. get_customer_name($row["customer"]) . ' - '. sql2date($row["due_date"]). '</a></li>';
    } 
    echo '</ul>
          </li>
          <li class="footer"><a href="'.$path_to_root.'/gl/inquiry/dollar_booking_inquiry.php?">View all</a></li>
        </ul>
      </li>';
}
    
}