<?php 
$menudisp = "dashboard";

include "includes/header.php"; 

$rslt_supplier = $db->get_a_line("select count(*) as disp_cnt from m_supplier where 1=1 and IsActive=1 ");
$rslt_customer = $db->get_a_line("select count(*) as disp_cnt from m_customer where 1=1 and IsActive=1 ");
$rslt_purchase = $db->get_a_line("select count(*) as disp_cnt from t_purchase_entry_main where 1=1 and IsActive=1 ");
$rslt_sales = $db->get_a_line("select count(*) as disp_cnt from t_sales_entry_main where 1=1 and IsActive=1 ");

?> 
 <div class="wrapper">
            <div class="container">

                <!-- Page-Title - START -->
                <div class="row">
                    <div class="col-sm-12">                        
                        <h4 class="page-title">Dashboard</h4>
                    </div>
                </div>				
				<!-- Page-Title - END -->


                <div class="row">
                    <div class="col-xs-12 col-md-6 col-lg-6 col-xl-3">
                        <div class="card-box tilebox-one">
                            <i class="icon-layers pull-xs-right text-muted"></i>
                            <h6 class="text-muted text-uppercase m-b-20">Suppliers</h6>
                            <h2 class="m-b-20" data-plugin="counterup"><?php echo $rslt_supplier['disp_cnt']; ?></h2>                            
                        </div>
                    </div>

                    <div class="col-xs-12 col-md-6 col-lg-6 col-xl-3">
                        <div class="card-box tilebox-one">
                            <i class="icon-paypal pull-xs-right text-muted"></i>
                            <h6 class="text-muted text-uppercase m-b-20">Customers</h6>
                            <h2 class="m-b-20"><span data-plugin="counterup"><?php echo $rslt_customer['disp_cnt']; ?></span></h2>                           
                        </div>
                    </div>

                    <div class="col-xs-12 col-md-6 col-lg-6 col-xl-3">
                        <div class="card-box tilebox-one">
                            <i class="icon-chart pull-xs-right text-muted"></i>
                            <h6 class="text-muted text-uppercase m-b-20">Purchase Invoices</h6>
                            <h2 class="m-b-20"><span data-plugin="counterup"><?php echo $rslt_purchase['disp_cnt']; ?></span></h2>                           
                        </div>
                    </div>

                    <div class="col-xs-12 col-md-6 col-lg-6 col-xl-3">
                        <div class="card-box tilebox-one">
                            <i class="icon-rocket pull-xs-right text-muted"></i>
                            <h6 class="text-muted text-uppercase m-b-20">Sales Invoices</h6>
                            <h2 class="m-b-20" data-plugin="counterup"><?php echo $rslt_sales['disp_cnt']; ?></h2>                            
                        </div>
                    </div>
                </div>
                <!-- end row -->
				
				<div class="row">					
					<div class="col-sm-6">
						<div class="card-box">                         
							<div class="row">
								<h3 class="panel-title">Supplier Payment</h3>
								
							</div>
							<br/>
							<div class="row">								
								<div class="col-md-6">
									<select name="srch_sup_company" id="srch_sup_company" class="form-control select2 jsrequired">
										<option value="">Select Company</option>
										<?php 
										$rslt_list = $db->get_rsltset("select company_id AS Id,company_name AS Name from m_company where IsActive = '1' order by company_name asc");
										foreach($rslt_list as $r){											
										?>
										<option value="<?php echo $r['Id']; ?>"><?php echo $r['Name']; ?></option>
										<?php	
										}
										?>
									</select>
								</div>
								<div class="col-md-6">
									<select name="srch_sup_supplier" id="srch_sup_supplier" class="form-control select2 jsrequired">
										<option value="">Select Supplier</option>
										<?php 
										$rslt_list = $db->get_rsltset("select sup_id AS Id,sup_name AS Name from m_supplier where IsActive = '1' order by sup_name asc");
										foreach($rslt_list as $r){											
										?>
										<option value="<?php echo $r['Id']; ?>" ><?php echo $r['Name']; ?></option>
										<?php	
										}
										?>
									</select>
								</div>								
							</div>
							<br/>
							<div class="row">
								<div class="col-md-8">
									&nbsp;
								</div>
								<div class="col-md-4">
									<button onclick="supplier_payment();" type="button" class="btn btn-warning pull-right">Add Payment</button>
								</div>
							</div>
							
						</div>
					</div>
					
					
					<div class="col-sm-6">
						<div class="card-box">                         
							<div class="row">
								<h3 class="panel-title">Customer Payment</h3>								
							</div>
							
							<br/>
							<div class="row">								
								<div class="col-md-6">
									<select name="srch_cus_company" id="srch_cus_company" class="form-control select2 jsrequired">
										<option value="">Select Company</option>
										<?php 
										$rslt_list = $db->get_rsltset("select company_id AS Id,company_name AS Name from m_company where IsActive = '1' order by company_name asc");
										foreach($rslt_list as $r){											
										?>
										<option value="<?php echo $r['Id']; ?>" ><?php echo $r['Name']; ?></option>
										<?php	
										}
										?>
									</select>
								</div>
								<div class="col-md-6">
									<select name="srch_cus_customer" id="srch_cus_customer" class="form-control select2 jsrequired">
										<option value="">Select Customer</option>
										<?php 
										$rslt_list = $db->get_rsltset("select cus_id AS Id,cus_name AS Name from m_customer where IsActive = '1' order by cus_name asc");
										foreach($rslt_list as $r){											
										?>
										<option value="<?php echo $r['Id']; ?>"><?php echo $r['Name']; ?></option>
										<?php	
										}
										?>
									</select>
								</div>								
							</div>
							<br/>
							<div class="row">
								<div class="col-md-8">
									&nbsp;
								</div>
								<div class="col-md-4">
									<button onclick="customer_payment();" type="button" class="btn btn-warning pull-right">Add Payment</button>
								</div>
							</div>
							
						</div>
					</div>
					
				</div> 
				

<?php include "includes/footer.php";  ?>             


 </div> <!-- container -->

</div> <!-- End wrapper -->

<?php include "includes/footer_script.php";  ?> 

<!-- Counter Up  -->
<!--<script src="assets/plugins/waypoints/lib/jquery.waypoints.js"></script>
<script src="assets/plugins/counterup/jquery.counterup.min.js"></script>-->


<!-- Page specific js -->
<!--<script src="assets/pages/jquery.dashboard.js"></script> -->

<script type="text/javascript">

function supplier_payment(){
	if ($("#srch_sup_company").val() !='' && $("#srch_sup_supplier").val() !='') {	
		$.ajax({		
			url        : 'dashboard_actions.php',
			method     : 'POST',
			dataType   : 'json',
			data       : 'action=supplier_payment_add&srch_company='+$("#srch_sup_company").val()+'&srch_supplier='+$("#srch_sup_supplier").val(),
			beforeSend: function() { loading(); },
			success: function(response){				
				if(response.rslt == '1'){					
					$(location).attr('href', response.redirect_url);
				}
				else if(response.rslt == '-1'){					
					swal("Failure!", "Search data not getting, Please try again once", "warning");
				}
				else if(response.rslt == '-2'){					
					swal("Failure!", "No data mapping this keyword", "warning");
				}
				else{
					swal("Failure!", "Some session data are missing please login once after that try this operation", "warning");
				}
				unloading();
			}		
		});	
	}else{
		swal("Failure!", "Please select company and supplier to add a payment", "warning");
	}
}


function customer_payment(){
	if ($("#srch_cus_company").val() !='' && $("#srch_cus_customer").val() !='') {	
		$.ajax({		
			url        : 'dashboard_actions.php',
			method     : 'POST',
			dataType   : 'json',
			data       : 'action=customer_payment_add&srch_company='+$("#srch_cus_company").val()+'&srch_customer='+$("#srch_cus_customer").val(),
			beforeSend: function() { loading(); },
			success: function(response){				
				if(response.rslt == '1'){					
					$(location).attr('href', response.redirect_url);
				}
				else if(response.rslt == '-1'){					
					swal("Failure!", "Search data not getting, Please try again once", "warning");
				}
				else if(response.rslt == '-2'){					
					swal("Failure!", "No data mapping this keyword", "warning");
				}
				else{
					swal("Failure!", "Some session data are missing please login once after that try this operation", "warning");
				}
				unloading();
			}		
		});	
	}else{
		swal("Failure!", "Please select company and supplier to add a payment", "warning");
	}
}

</script>

  </body>
</html>

