Im currently doing the generate report from fetched data. I got 2 type
of search filter , search by date and search using customername (select
dropdown list). The one using the date search is worked but when i try
using the drop down list to fetch the data, it does’nt appear.
<?php
include '../include/navbar.php';
$post_at = "";
$post_at_to_date = "";
$count = 1000;
$queryCondition = "";
if(!empty($_POST["search"]["DOCDATE"])) {
$post_at = $_POST["search"]["DOCDATE"];
list($fid,$fim,$fiy) = explode("-",$post_at);
$post_at_todate = date('Y-m-d');
if(!empty($_POST["search"]["post_at_to_date"])) {
$post_at_to_date = $_POST["search"]["post_at_to_date"];
list($tid,$tim,$tiy) = explode("-",$_POST["search"]["post_at_to_date"]);
$post_at_todate = "$tiy-$tim-$tid";
}
$queryCondition .= "WHERE sl_iv.DOCDATE BETWEEN '$fiy-$fim-$fid' AND '" . $post_at_todate . "'";
}
$sql = "SELECT * From `sl_iv` Inner Join `ar_iv` On ar_iv.DOCNO = sl_iv.DOCNO Inner Join `payment_terms` On ar_iv.TERMS = payment_terms.id " . $queryCondition . " ORDER BY sl_iv.DOCNO Asc";
$result = mysqli_query($conn_connection,$sql);
$item_q = "SELECT * FROM `sl_iv`";
$item = mysqli_query($conn_connection, $item_q);
$curdate = "SELECT DATEDIFF(CURDATE(), `DOCDATE`) AS DAYS FROM ar_iv";
$resultdate = mysqli_query($conn_connection, $curdate);
$query = "SELECT * FROM sl_iv GROUP by COMPANYNAME";
$result1 = mysqli_query($conn_connection, $query);
?>
<link rel='stylesheet' type='text/css' href='css/style.css' />
<link rel='stylesheet' type='text/css' href='css/print.css' media="print" />
<script type='text/javascript' src='js/jquery-1.3.2.min.js'></script>
<script type='text/javascript' src='js/example.js'></script>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
</head>
<body class="invoice" onLoad="calculateSum()">
<div class="modal-body">
<div id="page-wrap">
<textarea id="header">Report</textarea>
<div id="cust">
<textarea id="cust-title"></textarea>
<table id="meta">
<tr>
<td class="meta-head">Report No.</td>
<td name="reportno" class="input-control" /><?php echo $count; ?></td>
</tr>
<tr>
<td class="meta-head">Date</td>
<td placeholder="Today Date" name="todaydate" class="input-control" /><?php echo date('Y-m-d'); ?></td>
</tr>
</table>
</div>
<br></br>
<form name="frmSearch" method="post" action="">
<p class="search_input" id="hiderow">
<input type="text" placeholder="From Date" id="post_at" name="search[DOCDATE]" value="<?php echo $post_at; ?>" class="input-control" />
<input type="text" placeholder="To Date" id="post_at_to_date" name="search[post_at_to_date]" style="margin-left:10px" value="<?php echo $post_at_to_date; ?>" class="input-control" />
<input type="submit" name="go" value="Search">
</p>
<br></br>
<p id="hiderow">
<select name= "COMPANYNAME">
<option value="">ALL</option>
<?php while ($row = mysqli_fetch_array($result1)):;?>
<option value="<?php echo ($row['COMPANYNAME']); ?>"><?php echo ($row['COMPANYNAME']); ?></option>
<?php
endwhile;
?>
</select>
<input type="submit" name="submit" value="Submit"/>
</p>
<br /><hr />
<?php if(!empty($result)) { ?>
<table id="items">
<center>
<thead>
<tr>
<th width="15%" style="text-align:center"><span>Doc No.</span></th>
<th width="10%" style="text-align:center"><span>Date</span></th>
<th width="10%" style="text-align:center"><span>Terms</span></th>
<th width="10%" style="text-align:center"><span>Due</span></th>
<th width="5%" style="text-align:center"><span>Age</span></th>
<th width="20%" style="text-align:center"><span>Customer Name</span></th>
<th width="10%" style="text-align:center"><span>Ammount</span></th>
<th width="10%" style="text-align:center"><span>Payment</span></th>
<th width="10%" style="text-align:center"><span>OutStanding</span></th>
</tr>
</thead>
</center>
<tbody>
<?php
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
$docamt = $row['DOCAMT'];
$paymentamt = $row['PAYMENTAMT'];
$outstanding = $docamt - $paymentamt;
$then = $row['DOCDATE'];
$then = strtotime($then);
$now = time();
$difference = $now - $then;
$dateage = floor($difference / (60*60*24));
?>
<tr class="item-row">
<td style="text-align:left; font-size:15px" readonly><?php echo ($row['DOCNO']);?></td>
<td style="text-align:center; font-size:15px"><?php echo ($row['DOCDATE']);?></td>
<td style="text-align:center; font-size:15px"><?php echo ($row['terms']);?></td>
<td style="text-align:center; font-size:15px"><?php echo ($row['DUEDATE']);?></td>
<td style="text-align:center; font-size:15px"><?php echo $dateage;?></td>
<td style="text-align:left; font-size:15px" readonly><?php echo ($row['COMPANYNAME']);?></td>
<td><input type="text" style="text-align:right; font-size:15px" class="form-control input-sm TotalAmt" id="TotalAmt0" name="TotalAmt[]" value="<?php echo htmlspecialchars($row['DOCAMT']);?>" readonly></td>
<td><input type="text" style="text-align:right; font-size:15px" class="form-control input-sm payment" id="payment0" name="payment[]" value="<?php echo htmlspecialchars($row['PAYMENTAMT']);?>" readonly></td>
<td><input type="text" style="text-align:right; font-size:15px" class="form-control input-sm Total_Outstanding" id="Total_Outstanding0" name="Total_Outstanding[]" value="<?php echo number_format((float)$outstanding, 2, '.', '');?>" readonly></td>
</tr>
<?php
}
} else {
echo "0 results";
}
?>
</tbody>
</table>
<?php } ?>
</form>
<br>
<div class="row">
<div class="col-md-3 pull-right">
<table class="table table-condensed table-bordered table-striped table-custom-font" border="0">
<tr>
<td><b>Total Amount (RM)</b></td>
<td><input type="text" style="text-align:right; font-size:15px" class="form-control input-sm total_amount" id="total_amount" name="total_amount" value="0.00" readonly></td>
</tr>
</table>
<table class="table table-condensed table-bordered table-striped table-custom-font" border="0">
<tr>
<td><b>Total Outstanding (RM)</b></td>
<td><input type="text" style="text-align:right; font-size:15px" class="form-control input-sm Net_Total" id="net_total" name="net_total" value="0.00" readonly></td>
</tr>
</table>
</div>
</div>
<div class="pull-right">
<a href="print_tax.php" target="_blank">
<button type="button" class="btn btn-default btn-sm">
<span class="glyphicon glyphicon-print"></span> PRINT
</button>
</a>
</div>
</div>
</div>
<script>
<!--unitcost, taxes, qty, discount, price-->
function calculate(qty,rt,up,subttl,taxr,taxa,total,disc,totaltax){
var quantity = $('#'+qty).val();
var rate = $('#'+rt).val();
var unit_price = $('#'+up).val();
var subtotal = quantity * rate * unit_price; // count subtotal
$('#'+subttl).val(subtotal.toFixed(2));
var t_disc = $('#'+disc).val();
// check something if that something exists. what something? find that something. no spoon feeding.
if (/\%/g.test(t_disc)) {
var count_disc = t_disc.match(/\%/g).length;
} else {
var count_disc = 0;
}
// replace something2 hahahahahaha. go and learn. again, no spoon feeding.
var discount = t_disc.replace(/^[ ]+|[ ]+$/g,'');
// not full checking, but you get the idea.
if ((/\s/g.test(discount)) || (/[a-zA-Z]/g.test(discount)) || (/[^0-9.?%]/g.test(discount))) {
alert("Please Re-Enter Your Discount");
} else {
if((count_disc == 1) && (discount[discount.length - 1] === '%')) {
// if found something at the end of something, something will happen.
var s_disc = discount;
str_disc = s_disc.slice(0, -1);
var disc_amt = subtotal * str_disc / 100;
var ttl = subtotal - disc_amt;
$('#'+total).val(ttl.toFixed(2));
} else if (count_disc == 0) {
var str_disc = discount;
var ttl = subtotal - str_disc;
if (isNaN(ttl) == 0 ){
$('#'+total).val(ttl.toFixed(2));
} else {
alert("Please Re-Enter Your Discount");
}
} else {
alert("Please Re-Enter Your Discount");
}
}
var t_rate = $('#'+taxr).val();
var temp1 = ttl * t_rate / 100;
var tax_amount = Math.round(temp1 * 100) / 100;
$('#'+taxa).val(tax_amount.toFixed(2));
var total = ttl + tax_amount;
$('#'+totaltax).val(total.toFixed(2));
calculateSum();
}
function calculateSum() {
var total = 0;
$(".Total_Outstanding").each(function() {
//add only if the value is number
if(!isNaN(this.value) && this.value.length!=0) {
total += parseFloat(this.value);
}
});
$("#net_total").val(total.toFixed(2));
var sum_gst = 0;
$(".TotalAmt").each(function() {
//add only if the value is number
if(!isNaN(this.value) && this.value.length!=0) {
sum_gst += parseFloat(this.value);
}
});
$("#total_amount").val(sum_gst.toFixed(2));
var totaltax = 0;
$(".TotalTax").each(function() {
//add only if the value is number
if(!isNaN(this.value) && this.value.length!=0) {
totaltax += parseFloat(this.value);
}
});
$("#total_including_gst").val(totaltax.toFixed(2));
//var aftr_rndg = rndfunc(sum_final*2, 1)/2;
//var rndg_adj = aftr_rndg - sum_final;
//$("#rounding_adjustment").val(rndg_adj.toFixed(2));
//var pewpewpew = sum_final + rndg_adj;
//$("#final_total").val(pewpewpew.toFixed(2));
//$("#bal_payable").val(pewpewpew.toFixed(2));
}
function rndfunc(number, p)
{
//return Math.round((number*2))/2;
return +(Math.round(number + "e+"+p) + "e-"+p);
}
function RoundNum(num, length) {
var number = Math.round(num * Math.pow(10, length)) / Math.pow(10, length);
return number;
}
</script>
<script>
function myFunction() {
window.print();
}
</script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script>
$.datepicker.setDefaults({
showOn: "button",
buttonImage: "datepicker.png",
buttonText: "Date Picker",
buttonImageOnly: true,
dateFormat: 'dd-mm-yy'
});
$(function() {
$("#post_at").datepicker();
$("#post_at_to_date").datepicker();
});
</script>