<?php 
$startdate=date("Y-m-d");

///.....................Daily  Production.................................//
$prevWee = time() - (7 * 24 * 60 * 60);
$prevWeek = date('Y-m-d', $prevWee);


$query="SELECT SUM(total) FROM ".$prefix."sales_orders WHERE ord_date BETWEEN '$startdate' AND '$startdate'";
$resultTotal=mysqli_query($linkid,$query);
$getTotalDaily=mysqli_fetch_row($resultTotal);

$query="SELECT SUM(ov_amount) FROM ".$prefix."debtor_trans WHERE tran_date BETWEEN '$startdate' AND '$startdate' AND  reference LIKE 'INV%'";
$result=mysqli_query($linkid,$query);
$getTodayInvoice=mysqli_fetch_row($result);



///.....................Weekly Production.................................//
$prevWee = time() - (7 * 24 * 60 * 60);
$prevWeek = date('Y-m-d', $prevWee);

$prevMon = time() - (30 * 24 * 60 * 60);
$prevMonth= date('Y-m-d', $prevMon);

$query="SELECT SUM(total) FROM ".$prefix."sales_orders WHERE ord_date BETWEEN '$prevMonth' AND '$startdate'";
$resultTotal=mysqli_query($linkid,$query);
$getTotalWeekly=mysqli_fetch_row($resultTotal);


$query="SELECT SUM(paid) FROM ".$prefix2."order_payment WHERE trans_date BETWEEN '$startdate' AND '$startdate'";
$resultTotal=mysqli_query($linkid,$query);
$getTotalWeeklyRecv=mysqli_fetch_row($resultTotal);


///.....................Monthly Production.................................//

$query="SELECT SUM(paid) FROM ".$prefix2."order_payment WHERE trans_date BETWEEN '$prevMonth' AND '$startdate'";
$resultTotal=mysqli_query($linkid,$query);
$getTotalMonthly=mysqli_fetch_row($resultTotal);


$query="SELECT SUM(ov_amount) FROM ".$prefix."debtor_trans WHERE tran_date BETWEEN '$prevMonth' AND '$startdate' AND  reference LIKE 'INV%'";
$result=mysqli_query($linkid,$query);
$getMonthInvoice=mysqli_fetch_row($result);

$query="SELECT order_no,reference,ord_date,contact_email,deliver_to,delivery_date,total,b.debtor_no,b.debtor_ref AS phone,b.name,b.address FROM ".$prefix."sales_orders AS a,".$prefix."debtors_master AS b WHERE a.debtor_no=b.debtor_no ORDER BY order_no desc LIMIT 0,10";
$resultType=mysqli_query($linkid,$query);
//To calculate the VAT CHALLAN 

$query="SELECT  id,money_receipt_no,paid,trans_date,b.debtor_no,b.debtor_ref,b.name,b.address FROM ".$prefix2."order_payment AS a,".$prefix."debtors_master AS b WHERE a.debtor_no=b.debtor_no ORDER BY money_receipt_no desc LIMIT 0,10";
$resultType2=mysqli_query($linkid,$query);
?>
<div id="contentwrapper">
  <div class="main_content">
    <div class="row-fluid">
      <div class="span12 tac">
	   <?php

			if($userroll!='1')

			{

			?>
       <ul class="ov_boxes">
		<li>
            <div class="p_line_down p_canvas"><span style="display: none;">20,16,14,18,15,14,14,13,12,10,10,8</span>
              <canvas width="50" height="32"></canvas>
            </div>
            <div class="ov_text"> <strong>৳ <?php echo number_format($getTotalDaily[0],2);?></strong>Today Order</div>
          </li>
          <li>
            <div class="p_bar_up p_canvas"><span style="display: none;">2,4,9,7,12,8,16</span>
              <canvas width="50" height="32"></canvas>
            </div>
            <div class="ov_text"> <strong>৳ <?php echo number_format($getTotalWeekly[0],2);?></strong> Monthly Order </div>
          </li>
          <li>
            <div class="p_bar_down p_canvas"><span style="display: none;">20,15,18,14,10,13,9,7</span>
              <canvas width="50" height="32"></canvas>
            </div>
            <div class="ov_text"> <strong>৳ <?php echo number_format($getTotalWeeklyRecv[0],2);?></strong> Today Received </div>
          </li>
          <li>
            <div class="p_line_up p_canvas"><span style="display: none;">3,5,9,7,12,8,16</span>
              <canvas width="50" height="32"></canvas>
            </div>
            <div class="ov_text"> <strong>৳ <?php echo number_format($getTotalMonthly[0],2);?></strong> Monthly Received </div>
          </li>
		  
		  <li>
            <div class="p_bar_up p_canvas"><span style="display: none;">20,15,18,14,10,13,9,7</span>
              <canvas width="50" height="32"></canvas>
            </div>
            <div class="ov_text"> <strong>৳ <?php echo number_format($getTodayInvoice[0],2);?></strong> Today Invoice </div>
          </li>
          <li>
            <div class="p_line_up p_canvas"><span style="display: none;">3,5,9,7,12,8,16</span>
              <canvas width="50" height="32"></canvas>
            </div>
            <div class="ov_text"> <strong>৳ <?php echo number_format($getMonthInvoice[0],2);?></strong> Monthly Invoice </div>
          </li>
		  	  
		   <li>
            <div class="p_bar_up p_canvas"><span style="display: none;">20,15,18,14,10,13,9,7</span>
              <canvas width="50" height="32"></canvas>
            </div>
            <div class="ov_text"> <strong>৳ <?php echo number_format($getTodayVAT[0],2);?></strong> Today VAT(F) </div>
          </li>
          <li>
            <div class="p_line_up p_canvas"><span style="display: none;">3,5,9,7,12,8,16</span>
              <canvas width="50" height="32"></canvas>
            </div>
            <div class="ov_text"> <strong>৳ <?php echo number_format($getMonthlyVAT[0],2);?></strong> Monthly VAT(F)</div>
          </li>
		  
	 <li>
            <div class="p_bar_up p_canvas"><span style="display: none;">20,15,18,14,10,13,9,7</span>
              <canvas width="50" height="32"></canvas>
            </div>
            <div class="ov_text"> <strong>৳ <?php echo number_format($getTodayVATBack[0],2);?></strong> Today VAT(R) </div>
          </li>
          <li>
            <div class="p_line_up p_canvas"><span style="display: none;">3,5,9,7,12,8,16</span>
              <canvas width="50" height="32"></canvas>
            </div>
            <div class="ov_text"> <strong>৳ <?php echo number_format($getMonthlyVATBack[0],2);?></strong> Monthly VAT(R)</div>
          </li>
        </ul>
 <?php

			}

			?>
      </div>
    </div>
    <div class="row-fluid">
      <div class="span12">
        <ul class="dshb_icoNav tac">
          <?php

								//1 for administrator
								//2 for Admission
								//3 for Accountants
								//4 for IT Manager	
								if($userroll=='1' || $userroll=='2')
								{
								?>
          <!--<li><a href="index.php?tab=creditvoucher" style="background-image: url(img/gCons/multi-agents.png)"><span class="label label-info">+<?php echo $getpatients;?></span> Total Patients</a></li>-->
          <?php								  



								  }



								?>
          <?php



								if($userroll=='1' || $userroll=='2')



								{



								?>
          <!--<li><a href="index.php?tab=daily-production" style="background-image: url(img/gCons/add-item.png)"> New Production</a></li>
          <li><a href="index.php?tab=new-hourly-production" style="background-image: url(img/gCons/add-item.png)">Hourly Production</a></li>
          <li><a href="index.php?tab=buyer" style="background-image: url(img/gCons/add-item.png)"> New Buyer</a></li>
          <li><a href="index.php?tab=style" style="background-image: url(img/gCons/add-item.png)"> New Style</a></li>-->
          <?php								  



								  }



								?>
        </ul>
      </div>
    </div>
	<div class="row-fluid">
      <div class="span12">
           <h3 class="heading">Last 10 Sales Orders</h3>
        <table class="table table-striped table-bordered dTableR" id="dt_a">
          <thead>
            <tr>
              <th> Order #</th>
              <th> Order Ref</th>
              <th> Order Date </th>
              <th> Customer </th>
              <th> Phone </th>
              <th> Required By </th>
              <th> Order Total(BDT)</th>
              <th width="15%">Action</th>
            </tr>
          </thead>
          <tbody>
            <?php 

			  if($resultType)

				{

				while($mydata = mysqli_fetch_assoc($resultType))
				{
				$dateval=explode("-",$mydata['ord_date']);
			    $monthval=date("d-m-Y",mktime(0,0,0,$dateval[1],$dateval[2],$dateval[0]));
				
				$dateval=explode("-",$mydata['delivery_date']);
			    $deliverydate=date("d-m-Y",mktime(0,0,0,$dateval[1],$dateval[2],$dateval[0]));
				
				$orderid=$mydata['order_no'];
			  ?>
            <tr  class="bar<?php echo $mydata['order_no']?>">
              <td><?php echo $mydata['order_no'];?></td>
              <td><?php echo $mydata['reference']?></td>
              <td><?php echo $monthval;?></td>
              <td><?php echo $mydata['name']?></td>
              <td><img src="img/phn.png" width="16" />&nbsp;<?php echo $mydata['phone'];?></td>
              <td><?php echo $deliverydate;?></td>
              <td><?php echo number_format($mydata['total'],2)?></td>
              <td><table width="100%" border="0">
                  <tr>
           <!--<   <td class="center">
				<?php
				if($paid > $mydata['total'])
				{
				echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
				}
				else
				{
				?>
				  <div class="row-fluid">
                        <div class="span10"> <a target="_blank" href="index.php?tab=cust-payment&orderno=<?php echo $mydata['order_no']; ?>">
                          <button class="btn btn-gebo">P</button>
                          </a></div>
                 </div>
				<?php
				}
				?>
				
                  </td>
                  td>
				  <?php
				if($paid > $mydata['total'])
				{
				echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
				}
				else
				{
				?>
				  
				  <a href="../sales/sales_order_entry.php?ModifyOrderNumber=<?php echo $mydata['order_no'];?>"  target="_blank" title="Edit"><i class="icon-edit"></i></a>
				 <?php
				}
				?> 
				  </td>
-->                  <td><a href="sales_order.php?orderno=<?php echo $mydata['order_no'];?>" target="_blank"  title="Print Order"> <button class="btn btn-gebo">PRINT</button></a></td>
                  </tr>
                </table></td>
            </tr>
            <?php 
			     // }
				 }
				} 
?>
          </tbody>
        </table>
		 <h3 class="heading">Last 10 Money Receipts</h3>
     
	 <table class="table table-striped table-bordered dTableR" id="dt_b">
          <thead>
            <tr>
                <th> MR No.</th>
			  <th> Date</th>
              <th> Name </th>
			  <th> Phone </th>
			  <th> Amount </th>
			  <th> Action </th>
            </tr>
          </thead>
          <tbody>
           <?php 

			  if($resultType2)

				{

				while($mydata = mysqli_fetch_assoc($resultType2))

				{
				$dateval=explode("-",$mydata['trans_date']);
			    $monthval=date("d M-Y",mktime(0,0,0,$dateval[1],$dateval[2],$dateval[0]));

			  ?>
            <tr class="bar<?php echo $mydata['money_receipt_no']?>" >
              <td><?php echo $mydata['money_receipt_no']?></td>
			  <td><?php echo $mydata['trans_date']?></td>
              <td><?php echo $mydata['name']?></td>
			  <td><?php echo $mydata['debtor_ref']?></td>
              <td><?php echo $mydata['paid']?></td>
              <td><table width="80%" border="0">
                  <tr>
                    <td><a href="money-receipt-payment.php?mid=<?php echo $mydata['money_receipt_no']?>" target="_blank" title="Print"><i class="icon-print"></i></a></td>
					<?php
					/*if($name=='Administrator')
					{
					?><td><a href="javascript:void(0);" onclick="delMR('<?php echo $mydata['id']?>')" title="Delete"><i class="icon-trash"></i></a></td>
					<?php
					}*/
					?>
                  </tr>
                </table></td>
            </tr>
            <?php 

				 }

				 } 

?>
          </tbody>
        </table>
	  </div>
    </div>
    <div class="row-fluid" style="display:none">
      <div class="span5">
        <h3 class="heading">Member by Location <small>this year</small></h3>
        <div id="fl_2" style="height:200px;width:80%;margin:50px auto 0"></div>
      </div>
      <div class="span7">
        <div class="heading clearfix">
          <h3 class="pull-left">Chart</h3>
          <span class="pull-right label label-info ttip_t" title="Here is a sample info tooltip">Info</span> </div>
        <div id="fl_1" style="height:270px;width:100%;margin:15px auto 0"></div>
      </div>
    </div>
    
  </div>
</div>
