ChartJS is not displayed properly - javascript

I have a problem when using ChartJS for displaying data. My data can displayed correctly but when using ChartJS it is not displayed properly.
I need help for this. and this is my code below.
screenshot page when use this code
?>
<div class="contentDesc">
<div class="container-fluid">
<div class="row">
<div class="col-lg-8 s-dashboard">
<div class="panel panel-info">
<div class="panel-heading">
<h2 class="panel-title"><?php echo __('Status Ketersediaan Ijazah') ?></h2>
</div>
<div class="panel-body">
<div class="s-chart">
<canvas id="line-chartjs" width="175" height="315"></canvas>
</div>
</div>
<div class="panel-footer">
<table class="table">
<tr>
<td class="text-left"><i class="fa fa-square" style="color:#99FF33;"></i> <?php echo __('Ijazah Ada') ?></td>
<td class="text-right"><?php echo $get_total_ijazahada?></td>
</tr>
<tr>
<td class="text-left"><i class="fa fa-square" style="color:#337AB7;"></i> <?php echo __('Ijazah Sudah Dikembalikan') ?></td>
<td class="text-right"><?php echo $get_total_ijazahkembali?></td>
</tr>
</table>
</div>
</div>
</div>
<div class="col-lg-4 s-dashboard">
<div class="panel panel-default s-dashboard">
<div class="panel-heading">
<h2 class="panel-title"><?php echo __('Status Karyawan') ?></h2>
</div>
<div class="panel-body">
<div class="s-chart">
<canvas id="radar-chartjs" width="175" height="175"></canvas>
</div>
</div>
<div class="panel-footer">
<table class="table">
<tr>
<td class="text-left"><i class="fa fa-square" style="color:#f2f2f2;"></i> <?php echo __('Total Data Ijazah') ?></td>
<td class="text-right"><?php echo $get_total_ijazah?></td>
</tr>
<tr>
<td class="text-left"><i class="fa fa-square" style="color:#99FF33;"></i> <?php echo __('Karyawan Aktif') ?></td>
<td class="text-right"><?php echo $get_total_aktif?></td>
</tr>
<tr>
<td class="text-left"><i class="fa fa-square" style="color:#337AB7;"></i> <?php echo __('Karyawan Kontrak') ?></td>
<td class="text-right"><?php echo $get_total_kontrak?></td>
</tr>
<tr>
<td class="text-left"><i class="fa fa-square" style="color:#FF9F40;"></i> <?php echo __('Karyawan Harian') ?></td>
<td class="text-right"><?php echo $get_total_harian?></td>
</tr>
<tr>
<td class="text-left"><i class="fa fa-square" style="color:#FF6384;"></i> <?php echo __('Karyawan Resign') ?></td>
<td class="text-right"><?php echo $get_total_resign?></td>
</tr>
<tr>
<td class="text-left"><i class="fa fa-square" style="color:#C9CBCF;"></i> <?php echo __('Pelamar Batal Join') ?></td>
<td class="text-right"><?php echo $get_total_bataljoin?></td>
</tr>
<tr>
<td class="text-left"><i class="fa fa-square" style="color:#D9534F;"></i> <?php echo __('Pelamar Tidak Ada Kabar') ?></td>
<td class="text-right"><?php echo $get_total_tidakada?></td>
</tr>
</table>
</div>
</div>
</div>
</div>
<div class="clearfix"></div>
</div>
</div>
<script src="<?php echo JWB?>chartjs/Chart.min.js"></script>
<script>
$(function(){
var lineChartData = {
labels : [<?php echo $get_date?>],
datasets :
[
{
fillColor : "#99FF33",
data : [<?php echo $get_total_ijazahada?>]
},
{
fillColor : "#5D45BD",
data : [<?php echo $get_total_ijazahkembali?>]
}
]
}
var c = $('#line-chartjs');
var container = $(c).parent();
var ct = c.get(0).getContext("2d");
$(window).resize( respondCanvas );
function respondCanvas(){
c.attr('width', $(container).width() ); //max width
c.attr('height', $(container).height() ); //max height
//Call a function to redraw other content (texts, images etc)
var myChart = new Chart(ct).Bar(lineChartData,{
barShowStroke: true,
barDatasetSpacing : 2,
animation: false
});
}
respondCanvas();
var data = [
{
value : <?php echo $get_total_aktif?>,
color : "#99FF33",
label : "<?php echo __('Aktif'); ?>"
},
{
value : <?php echo $get_total_kontrak?>,
color : "#337AB7",
label : "<?php echo __('Kontrak'); ?>"
},
{
value : <?php echo $get_total_harian?>,
color : "#FF9F40",
label : "<?php echo __('Harian'); ?>"
},
{
value : <?php echo $get_total_resign?>,
color : "#FF6384",
label : "<?php echo __('Resign'); ?>"
},
{
value : <?php echo $get_total_bataljoin?>,
color : "#C9CBCF",
label : "<?php echo __('Batal Join'); ?>"
},
{
value : <?php echo $get_total_tidakada?>,
color : "#D9534F",
label : "<?php echo __('Tidak Ada Kabar'); ?>"
}
];
var r = $('#radar-chartjs');
var container = $(r).parent();
var rt = r.get(0).getContext("2d");
$(window).resize( respondCanvas );
function respondCanvasRadar(){
r.attr('width', $(container).width()); //max width
r.attr('height', $(container).height()); //max height
//Call a function to redraw other content (texts, images etc)
var myChart = new Chart(rt).Doughnut(data,{
animation: false,
segmentStrokeWidth : 1
});
}
respondCanvasRadar();
});
</script>

Related

How to store the input value to php variable

<input type="text" id="transaction_id_input" name="transaction_name">
Above is the value that I want to store in PHP variables so I can compare it in the MySQL data to display specific data. I try storing the input value also to a javascript document.getElementByID("sampleID").value then store it in a variable but it didn't also work, hoping you will help me solve this problem.
<form method="GET" id="reg" name="valid" action="<?php echo htmlspecialchars(
$_SERVER["PHP_SELF"]
); ?>">
<input type="text" id="transaction_id_input" name="transaction_name">
<div class="wrapper" >
<div class="search-input">
<a href="" target="_blank" hidden></a>
<input type="text" id="searchmodal" placeholder="Type to search..">
<div class="icon"><i class="fas fa-search"></i></div>
</div>
</div>
<br><br>
<div class="card-header" id="cardheader2">
List of Medicine Transaction
</div><br><br>
<div class="enrollbutton2">
<a class="nav-link" id="transactioninfo_to_addtransan_class" data-toggle="modal" data-target="#myModal_transaction">Add Transaction
<span>
<lord-icon
src="https://cdn.lordicon.com/mecwbjnp.json"
trigger="loop"
colors="primary:#ffffff,secondary:#ffffff"
stroke="70"
style="width:30px;height:30px">
</lord-icon>
</span>
</a>
</div>
<div class="tableholdermodal" id="transactiontable">
<br><br><br><br>
<table>
<thead>
<tr>
<th scope="col">Transaction No.</th>
<th scope="col">Medicine Code</th>
<th scope="col">Supply</th>
<th scope="col">Lot No.</th>
<th scope="col">Expiration Date</th>
<th scope="col">Inputed Date</th>
</tr>
</thead>
<tbody id="myModalTable">
<?php
include "pdo_connection2.php";
$stm3 = $conn->query(
"SELECT * FROM tbl_transaction WHERE transaction_medicinecode = '' "
);
$rows = $stm3->fetchAll(PDO::FETCH_ASSOC);
if (count($rows) > 0) {
foreach ($rows as $row) { ?>
<tr>
<td data-label='Transaction ID' value="<?php echo $row[
"transaction_id"
]; ?>"><?php echo $row["transaction_id"]; ?></td>
<td data-label='Medicine Code' value="<?php echo $row[
"transaction_medicinecode"
]; ?>"><?php echo $row["transaction_medicinecode"]; ?></td>
<td data-label='Supply' value="<?php echo $row[
"transaction_supply"
]; ?>"><?php echo $row["transaction_supply"]; ?></td>
<td data-label='Lot No.' value="<?php echo $row[
"transaction_lotnum"
]; ?>"><?php echo $row["transaction_lotnum"]; ?></td>
<td data-label='Expiration Date' value="<?php echo $row[
"transaction_expdate"
]; ?>"><?php echo $row["transaction_expdate"]; ?></td>
<td data-label='Date Registered' value="<?php echo $row[
"transaction_date"
]; ?>"><?php echo $row["transaction_date"]; ?></td>
<td data-label='Action'>
<button type="button" class="transaction_update_class" name="transaction_update_name" data-toggle="modal" data-target="#myModalupdate_transactopn" value="<?php echo $row[
"transaction_id"
]; ?>">
<lord-icon
src="https://cdn.lordicon.com/wloilxuq.json"
trigger="loop"
colors="primary:#fb0054,secondary:#f55b2a "
stroke="70"
style="width:55px;height:55px">
</lord-icon>
</button>
<button type="button" class="transaction_delete_class" name="transaction_delete_name" data-toggle="modal" data-target="#myModaldelete_transaction" value="<?php echo $row[
"transaction_id"
]; ?>">
<lord-icon
src="https://cdn.lordicon.com/gsqxdxog.json"
trigger="loop"
colors="primary:#fb0054,secondary:#f55b2a "
stroke="70"
style="width:55px;height:55px">
</lord-icon>
</button>
</td>
</tr>
<?php }
} else {
?>
<tr><td><h4 id="h4nodatafound">------ NO DATA FOUND ------</h4></td></tr>
<?php
}
?>
</tbody>
</table>
</div>
</form>

highlight column differences

I need to Highlight columns that have different values.
If the value on $b['nama'] and $c['nama'] is not the same i need to highlight the <tr>. I wanted the system admin to easily see which of the field is having different values so the admin can decide to approve user edit request or to reject the request.
<?php
error_reporting(0);
$b = $data->row_array();
$c = $data2->row_array();
?>
<!-- Begin Page Content -->
<div class="container-fluid">
<!-- DataTales Example -->
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary">User requested changes</h6>
</div>
<div class="card-body">
<table id="tabel" class="table table-bordered table-striped" style="width: 75%">
<thead>
<tr>
<th>Variable</th>
<th>Current data</th>
<th>Requested changes</th>
</tr>
</thead>
<tbody>
<tr>
<td>Nama</td>
<td>
<?php echo $b['nama']; ?>
</td>
<td>
<?php echo $c['nama']; ?>
</td>
</tr>
<tr>
<td>NIP Baru</td>
<td>
<?php echo $b['nipBaru']; ?>
</td>
<td>
<?php echo $c['nipBaru']; ?>
</td>
</tr>
<tr>
<td>NIP lama</td>
<td>
<?php echo $b['nipLama']; ?>
</td>
<td>
<?php echo $c['nipLama']; ?>
</td>
</tr>
<tr>
<td>Gelar depan</td>
<td>
<?php echo $b['gelarDepan']; ?>
</td>
<td>
<?php echo $c['gelarDepan']; ?>
</td>
</tr>
<tr>
<td>Gelar belakang</td>
<td>
<?php echo $b['gelarBelakang']; ?>
</td>
<td>
<?php echo $c['gelarBelakang']; ?>
</td>
</tr>
<tr>
<td>Tempat lahir</td>
<td>
<?php echo $b['tempatLahir']; ?>
</td>
<td>
<?php echo $c['tempatLahir']; ?>
</td>
</tr>
</tbody>
</table>
<button type="submit" class="btn btn-primary btn-sm" style="width:10%"><span class="icon-cursor"></span> Approve</button>
<button type="submit" class="btn btn-primary btn-sm" style="width:10%"><span class="icon-cursor"></span> Reject</button>
</div>
</div>
</div>
Check if those two values are different and apply a class to the row
<tr<?php if ($b['nama'] != $c['nama']) { echo ' class="highlight"'; } ?>>
<td>Nama</td>
<td>
<?php echo $b['nama']; ?>
</td>
<td>
<?php echo $c['nama']; ?>
</td>
</tr>
then use CSS to highlight the cells
.highlight td {
background: yellowgreen;
}
try this code
you can change the bgcolor value or you can create css class and inside of if you echo the class='my_class'
<?php
error_reporting(0);
$b = $data->row_array();
$c = $data2->row_array();
?>
<!-- Begin Page Content -->
<div class="container-fluid">
<!-- DataTales Example -->
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary">User requested changes</h6>
</div>
<div class="card-body">
<table id="tabel" class="table table-bordered table-striped" style="width: 75%">
<thead>
<tr>
<th>Variable</th>
<th>Current data</th>
<th>Requested changes</th>
</tr>
</thead>
<tbody>
<tr <?php if ($b['nama'] != $c['nama']){echo "bgcolor='#FF0000'";} ?>>
<td>Nama</td>
<td>
<?php echo $b['nama']; ?>
</td>
<td>
<?php echo $c['nama']; ?>
</td>
</tr>
<tr <?php if ($b['nipBaru'] != $c['nipBaru']){echo "bgcolor='#FF0000'";} ?> >
<td>NIP Baru</td>
<td>
<?php echo $b['nipBaru']; ?>
</td>
<td>
<?php echo $c['nipBaru']; ?>
</td>
</tr>
<tr <?php if ($b['nipBaru'] != $c['nipBaru']){echo "bgcolor='#FF0000'";} ?> >
<td>NIP lama</td>
<td>
<?php echo $b['nipLama']; ?>
</td>
<td>
<?php echo $c['nipLama']; ?>
</td>
</tr>
<tr <?php if ($b['gelarDepan'] != $c['gelarDepan']){echo "bgcolor='#FF0000'";} ?> >
<td>Gelar depan</td>
<td>
<?php echo $b['gelarDepan']; ?>
</td>
<td>
<?php echo $c['gelarDepan']; ?>
</td>
</tr>
<tr <?php if ($b['gelarBelakang'] != $c['gelarBelakang']){echo "bgcolor='#FF0000'";} ?> >
<td>Gelar belakang</td>
<td>
<?php echo $b['gelarBelakang']; ?>
</td>
<td>
<?php echo $c['gelarBelakang']; ?>
</td>
</tr>
<tr <?php if ($b['tempatLahir'] != $c['tempatLahir']){echo "bgcolor='#FF0000'";} ?> >
<td>Tempat lahir</td>
<td>
<?php echo $b['tempatLahir']; ?>
</td>
<td>
<?php echo $c['tempatLahir']; ?>
</td>
</tr>
</tbody>
</table>
<button type="submit" class="btn btn-primary btn-sm" style="width:10%"><span class="icon-cursor"></span> Approve</button>
<button type="submit" class="btn btn-primary btn-sm" style="width:10%"><span class="icon-cursor"></span> Reject</button>
</div>
</div>
</div>
You can define a class named 'same' and 'different'. Then in php check if the values are same and echo the class property based on being same or different.
php
<tr>
<td>Nama</td>
<td class="<?php echo ($b['nama'] == $c['nama'])? 'same': 'different'; ">
<?php echo $b['nama']; ?>
</td>
<td class="<?php echo ($b['nama'] == $c['nama'])? 'same': 'different'; ">
<?php echo $c['nama']; ?>
</td>
</tr>
In Styles
.same{
color:green;
}
.different{
color:red;
}
We have used ternary operator to figure out if the variables are same or not.
https://www.abeautifulsite.net/how-to-use-the-php-ternary-operator
Since you seem to be using Bootstrap, you could just apply an already defined style to the cells to highlight the difference. For instance:
<tr>
<td>Nama</td>
<td class="<?php echo ($b['nama'] == $c['nama'])? 'bg-success': 'bg-danger'; ">
<?php echo $b['nama']; ?>
</td>
<td class="bg-<?php echo ($b['nama'] == $c['nama'])? 'bg-success': 'bg-danger'; ">
<?php echo $c['nama']; ?>
</td>
</tr>
By doing this, if $b['nama'] and $c['nama'] are different, the cells would have an near-red background and if they are equal, they'd have a near-green background. If you'd like to only highlight differences (in order to make the screen less overwhelming, just replace the 'bg-success' with '' so the equal cells don't get styled

How I will change my date and time to my country time in my PHP table query

I have table query from MY SQl database. My table look like this my table image I just want to change my table date and time to my country date and time. Here is my database image my database image. my table date and time pull out from "created" rows.in my database. Here is my table code.`
<div class="row">
<div id="middlecolumn" align="center">
<table class="table">
<thead>
<tr>
<th id="tabletext">
<?php echo $lang['send']; ?>
</th>
<th id="tabletext">
<?php echo $lang['receive']; ?>
</th>
<th id="tabletext">
<?php echo $lang['amount']; ?>
</th>
<th id="tabletext">
<?php echo $lang['exchange_id']; ?>
</th>
<th id="tabletext">
<?php echo $lang['status']; ?>
</th>
<th id="tabletext">
<?php echo $lang['date_time']; ?>
</th>
</tr>
</thead>
<tbody>
<?php
$query = $db->query("SELECT * FROM bit_exchanges ORDER BY id DESC LIMIT 5000");
if($query->num_rows>0) {
while($row = $query->fetch_assoc()) {
?>
<tr>
<td id="tabletext"><img src="<?php echo gatewayicon(gatewayinfo($row['gateway_send']," name ")); ?>" width="20px" height="20">
<?php echo gatewayinfo($row['gateway_send'],"name"); ?>
</td>
<td id="tabletext"><img src="<?php echo gatewayicon(gatewayinfo($row['gateway_receive']," name ")); ?>" width="20px" height="20">
<?php echo gatewayinfo($row['gateway_receive'],"name"); ?>
</td>
<td id="tabletext">
<?php echo $row['amount_send']; ?>
<?php echo gatewayinfo($row['gateway_send'],"currency"); ?>
</td>
<td id="tabletext">
<?php echo cropexchangeid($row['exchange_id'],8); ?>
</td>
<td id="tabletext">
<?php
if($row['status'] == "1") {
echo '<span class="label label-warning"><i class="fa fa-clock-o"></i> '.$lang[status_1].'</span>';
} elseif($row['status'] == "2") {
echo '<span class="label label-warning"><i class="fa fa-clock-o"></i> '.$lang[status_2].'</span>';
} elseif($row['status'] == "3") {
echo '<span class="label label-info"><i class="fa fa-clock-o"></i> '.$lang[status_3].'</span>';
} elseif($row['status'] == "4") {
echo '<span class="label label-success"><i class="fa fa-check"></i> '.$lang[status_4].'</span>';
} elseif($row['status'] == "5") {
echo '<span class="label label-danger"><i class="fa fa-times"></i> '.$lang[status_5].'</span>';
} elseif($row['status'] == "6") {
echo '<span class="label label-danger"><i class="fa fa-times"></i> '.$lang[status_6].'</span>';
} elseif($row['status'] == "7") {
echo '<span class="label label-danger"><i class="fa fa-times"></i> '.$lang[status_7].'</span>';
} else {
echo '<span class="label label-default">'.$lang[status_unknown].'</span>';
}
?>
</td>
<td id="tabletext">
<?php echo date("d/m/Y H:i:s",$row['created']) ?>
</td>
</tr>
<?php
}
} else {
echo '<tr><td colspan="5">'.$lang[still_no_exchanges].'</td></tr>';
}
?>
</tbody>
</table>
</div>

how to print data in php with css and js?

Above Image is image of invoice before print it look good with css and js.
and this is the image after i print it, it not look good as before printing so please help me to take print same as Image 1 ['Before Print'].
CSS
<link rel="stylesheet" type="text/css" href="css/custom_css/invoice.css">
CODE:
<aside class="right-side">
<!-- Content Header (Page header) -->
<section class="content-header">
<h1>Invoice</h1>
<ol class="breadcrumb">
<li>
<a href="index.html">
<i class="fa fa-fw fa-home"></i> Dashboard
</a>
</li>
<li> Pages</li>
<li class="active">
Invoice
</li>
</ol>
</section>
<!-- Main content -->
<section class="content p-l-r-15" id="invoice-stmt">
<div class="panel panel-primary">
<div class="panel-body">
<div class="row printableArea">
<h1 align="center">National Battery Centre</h1>
<h4 align="center" style="text-transform:uppercase;" > Tax Invoice </h4>
<div class="col-md-12">
<div class="col-md-6 col-sm-12 col-xs-12">
<h4><strong>Jameel Khan</strong></h4>
<address>
<br/> Shop No : 1, Patel Tower
<br/> Bardoli, Dist - Surat
<br/> +91 9426890590
</address>
</div>
<?php
$query = mysql_query("SELECT * FROM customer_mst WHERE CUSTOMER_ID = '".$_SESSION['cust']."'");
$row = mysql_fetch_array($query);
$query_cart = mysql_query("SELECT * FROM final_invoice_mst WHERE CUSTOMER_ID = '".$_SESSION['cust']."' AND DATE = '".$_SESSION['date']."' AND FLAG = '0'");
$row_cart = mysql_fetch_array($query_cart);
?>
<div class="col-md-6 col-sm-12 col-xs-6 text-right">
<div class="pull-right">
<h4><strong><?php echo $row['CUSTOMER_NAME']; ?></strong></h4>
<address>
<br/> <?php echo $row['CUSTOMER_ADDRESS']; ?>
<br/> <?php echo $row['CUSTOMER_CITY'] ?>
<br/> <?php echo $row['CUSTOMER_CONTACT'] ?>
<br/> <?php echo $row['VEHICLE_NO'] ?>
</address>
</div>
</div>
</div>
<div class="col-md-12">
<div class="pull-right">
<font color="#000000" size="4">Bill No : <?php echo $row_cart['BILL_NO'] ?></font>
</div>
<div class="pull-left">
<font color="#000000" size="4">Date : <?php echo $_SESSION['date'] ?></font>
</div>
</div>
<div class="col-md-12">
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr class="bg-primary">
<th width="10%"><strong>Sr No.</strong></th>
<th class="text-left"><strong>Item Name</strong></th>
<th class="text-left"><strong> Serial No </strong></th>
<th class="text-right"><strong> CGST </strong></th>
<th class="text-right"><strong> SGST </strong></th>
<th class="text-right"><strong> Net Amount </strong></th>
</tr>
</thead>
<tbody>
<?php
$query_cart1 = mysql_query("SELECT * FROM final_invoice_mst, item_details WHERE final_invoice_mst.CUSTOMER_ID = '".$_SESSION['cust']."' AND final_invoice_mst.FLAG = '0' AND final_invoice_mst.ITEM_NAME = item_details.ITEM_NAME");
$counter = 0;
while($row_cart1 = mysql_fetch_array($query_cart1))
{
?>
<tr>
<td ><?php echo ++$counter; ?></td>
<td class="text-left"><?php echo $row_cart1['ITEM_NAME']; ?></td>
<td class="text-left"><?php echo $row_cart1['SERIAL_NO'];?></td>
<td class="text-right"><?php echo $row_cart1['CGST'];?></td>
<td class="text-right"><?php echo $row_cart1['SGST'];?></td>
<td class="text-right"><?php echo $row_cart1['NAMT'];?></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
<div class="col-md-12">
<?php
//Battery Inverter Both
$sum_cgst = mysql_query("SELECT SUM(CGST) FROM final_invoice_mst, item_details WHERE final_invoice_mst.CUSTOMER_ID = '".$_SESSION['cust']."' AND final_invoice_mst.FLAG = '0' AND final_invoice_mst.ITEM_NAME = item_details.ITEM_NAME AND item_details.TYPE = 'BAT'");
$row_sum_cgst = mysql_fetch_array($sum_cgst);
$sum_sgst = mysql_query("SELECT SUM(SGST) FROM final_invoice_mst, item_details WHERE final_invoice_mst.CUSTOMER_ID = '".$_SESSION['cust']."' AND final_invoice_mst.FLAG = '0' AND final_invoice_mst.ITEM_NAME = item_details.ITEM_NAME AND item_details.TYPE = 'BAT'");
$row_sum_sgst = mysql_fetch_array($sum_sgst);
$sum_namt = mysql_query("SELECT SUM(NAMT) FROM final_invoice_mst, item_details WHERE final_invoice_mst.CUSTOMER_ID = '".$_SESSION['cust']."' AND final_invoice_mst.FLAG = '0' AND final_invoice_mst.ITEM_NAME = item_details.ITEM_NAME AND item_details.TYPE = 'BAT'");
$row_sum_namt = mysql_fetch_array($sum_namt);
//Inverter
$isum_cgst = mysql_query("SELECT SUM(CGST) FROM final_invoice_mst, item_details WHERE final_invoice_mst.CUSTOMER_ID = '".$_SESSION['cust']."' AND final_invoice_mst.FLAG = '0' AND final_invoice_mst.ITEM_NAME = item_details.ITEM_NAME AND item_details.TYPE = 'INV'");
$irow_sum_cgst = mysql_fetch_array($isum_cgst);
$isum_sgst = mysql_query("SELECT SUM(SGST) FROM final_invoice_mst, item_details WHERE final_invoice_mst.CUSTOMER_ID = '".$_SESSION['cust']."' AND final_invoice_mst.FLAG = '0' AND final_invoice_mst.ITEM_NAME = item_details.ITEM_NAME AND item_details.TYPE = 'INV'");
$irow_sum_sgst = mysql_fetch_array($isum_sgst);
$isum_namt = mysql_query("SELECT SUM(NAMT) FROM final_invoice_mst, item_details WHERE final_invoice_mst.CUSTOMER_ID = '".$_SESSION['cust']."' AND final_invoice_mst.FLAG = '0' AND final_invoice_mst.ITEM_NAME = item_details.ITEM_NAME AND item_details.TYPE = 'INV'");
$irow_sum_namt = mysql_fetch_array($isum_namt);
if($rque1['TYPE'] == 'BAT' && $rque2['TYPE'] != 'INV')
{
?>
<div class="col-lg-9">
</div>
<div class="col-lg-3">
<table class="table">
<thead>
<tbody>
<tr>
<td>Net Amount</td>
<td class="text-left"><?php $inamt = $row_sum_namt['SUM(NAMT)']; echo "$inamt"; ?></td>
</tr>
<tr>
<td>CGST 14%</td>
<td class="text-left"><?php $icgst = $row_sum_cgst['SUM(CGST)']; echo "$icgst"; ?></td>
</tr>
<tr>
<td>SGST 14%</td>
<td class="text-left"><?php $isgst = $row_sum_sgst['SUM(SGST)']; echo "$isgst"; ?></td>
</tr>
<tr>
<td>IGST 28%</td>
<td class="text-left"> </td>
</tr>
<tr>
<td>TOTAL</td>
<td class="text-left"><?php $total = $inamt + $icgst + $isgst; echo round($total); ?></td>
</tr>
</tbody>
</table>
</div>
<?php
}
if($rque2['TYPE'] == 'INV' && $rque1['TYPE'] != 'BAT')
{
?>
<div class="col-lg-9">
</div>
<div class="col-lg-3">
<table class="table">
<tbody>
<tr>
<td>Net Amount</td>
<td class="text-left"><?php $inamt = $irow_sum_namt['SUM(NAMT)']; echo "$inamt"; ?></td>
</tr>
<tr>
<td>CGST 9%</td>
<td class="text-left"><?php $icgst = $irow_sum_cgst['SUM(CGST)']; echo "$icgst"; ?></td>
</tr>
<tr>
<td>SGST 9%</td>
<td class="text-left"><?php $isgst = $irow_sum_sgst['SUM(SGST)']; echo "$isgst"; ?></td>
</tr>
<tr>
<td>IGST 18%</td>
<td class="text-left"> </td>
</tr>
<tr>
<td>TOTAL</td>
<td class="text-left"><?php $total = $inamt + $icgst + $isgst; echo round($total); ?></td>
</tr>
</tbody>
</table>
</div>
<?php
}
if($rque1['TYPE'] == 'BAT' && $rque2['TYPE'] == 'INV')
{
?>
<div class="col-lg-6">
</div>
<div class="col-lg-3">
<table class="table">
<thead>
<tbody>
<tr>
<td>Net Amount</td>
<td class="text-left"><?php $inamt = $row_sum_namt['SUM(NAMT)']; echo "$inamt"; ?></td>
</tr>
<tr>
<td>CGST 14%</td>
<td class="text-left"><?php $icgst = $row_sum_cgst['SUM(CGST)']; echo "$icgst"; ?></td>
</tr>
<tr>
<td>SGST 14%</td>
<td class="text-left"><?php $isgst = $row_sum_sgst['SUM(SGST)']; echo "$isgst"; ?></td>
</tr>
<tr>
<td>IGST 28%</td>
<td class="text-left"> </td>
</tr>
<tr>
<td>TOTAL</td>
<td class="text-left"><?php $total = $inamt + $icgst + $isgst; echo round($total); ?></td>
</tr>
</tbody>
</table>
</div>
<div class="col-lg-3">
<table class="table">
<tbody>
<tr>
<td>Net Amount</td>
<td class="text-left"><?php $inamt = $irow_sum_namt['SUM(NAMT)']; echo "$inamt"; ?></td>
</tr>
<tr>
<td>CGST 9%</td>
<td class="text-left"><?php $icgst = $irow_sum_cgst['SUM(CGST)']; echo "$icgst"; ?></td>
</tr>
<tr>
<td>SGST 9%</td>
<td class="text-left"><?php $isgst = $irow_sum_sgst['SUM(SGST)']; echo "$isgst"; ?></td>
</tr>
<tr>
<td>IGST 18%</td>
<td class="text-left"> </td>
</tr>
<tr>
<td>TOTAL</td>
<td class="text-left"><?php $total = $inamt + $icgst + $isgst; echo round($total); ?></td>
</tr>
</tbody>
</table>
</div>
<?php
}
?>
<h4><Strong>Terms and conditions:</Strong></h4>
<ul>
<li>An invoice must accompany products returned for warantty</li>
<li>Balance due within 10 days of invoice date,1.5% interest/month thereafter.</li>
<li>All goods returned for replacement/credit must be saleable condition with original
packaging.
</li>
</ul>
</div>
</div>
<div class="btn-section">
<div class="col-md-12 col-sm-12 col-xs-12">
<span class="pull-right">
<form id="form1">
<input type="button" value="Print" class="btn btn-danger" onclick='PrintDiv();' id="print" />
</form>
</span>
</div>
</div>
</div>
</div>
</section>
<!-- /.content -->
</aside>
<script src="js/jquery.PrintArea.js" type="text/JavaScript"></script>
<script>
$(document).ready(function() {
$("#print").click(function() {
var mode = 'iframe'; //popup
var close = mode == "popup";
var options = {
mode: mode,
popClose: close
};
$("div.printableArea").printArea(options);
});
});
</script>
You can specify a print style in a different file and import it with:
<link rel="stylesheet" type="text/css" href="print.css" media="print">
The default media is all which applies for all devices, printers included, and I guess is the one you are using now. If that doesn't work you need to create a new CSS file.
After i tried all, I find best solution is open printing page another tab via target="_blank" or window.open(url).
For Hiding the url on top of the page
<style type="text/css" media="print">
#page {
size: auto; /* auto is the initial value */
margin: 0; /* this affects the margin in the printer settings */
}
</style>
And javascript for immediate open the print dialogue and close after print done
<script>
window.onload= function () {
window.print();
setTimeout(function(){
window.close();
},500 )
}
</script>

CodeIgniter AJAX Pagination Delete issue

I have managed to implement ajax pagination and delete in my code. However, I can only delete one only.The first time succeeds. The next time however, gives me an error that says there is no such file or directory to unlink. I suspect it has something to do with how my ajax pagination works but I am unsure of how to fix it.
The way my code works is that when I click on a pagination link, ajax_pagination.php is loaded. The javascript is only contained in the index.php view. Adding the script to both pages won't work though unfortunately.
This is my controller
public function index()
{
$conditions = array();
$data = array();
$totalRec = count($this->DocumentModel->admin_get_and_search($conditions));
$config['target'] = '#list';
$config['base_url'] = site_url('/AdminDocuments/Search');
$config['total_rows'] = $totalRec;
$config['per_page'] = $this->get_per_page();
$this->ajax_pagination->initialize($config);
$data['links'] = $this->ajax_pagination->create_links();
$data['datatable'] = $this->DocumentModel->admin_get_and_search(array('limit'=>$this->get_per_page()));
$data['user'] = $this->AccountModel->get_person($this->get_person_id());
// print_r($totalRec);
// print_r($data['datatable']);
$this->input->is_ajax_request()?'':$this->load->view('layout/admins/common/header');
$this->input->is_ajax_request()?'':$this->load->view('layout/admins/common/navigation');
$this->input->is_ajax_request()?'':$this->load->view('layout/admins/common/title');
$this->input->is_ajax_request()?'':$this->load->view('layout/admins/common/errors');
$this->input->is_ajax_request()?'':$this->load->view('layout/admins/common/search');
$this->load->view('admins/documents/index',$data);
$this->input->is_ajax_request()?'':$this->load->view('layout/admins/common/footer');
}
public function search(){
$conditions = array();
$page = $this->input->post('page');
if(!$page){
$offset = 0;
}else{
$offset = $page;
}
$keywords = $this->input->post('keywords');
if(!empty($keywords)){
$conditions['search']['keywords'] = $keywords;
}
$totalRec = count($this->DocumentModel->admin_get_and_search($conditions));
$config['target'] = '#list';
$config['base_url'] = site_url('/AdminDocuments/Search');
$config['total_rows'] = $totalRec;
$config['per_page'] = $this->get_per_page();
$this->ajax_pagination->initialize($config);
$conditions['start'] = $offset;
$conditions['limit'] = $this->get_per_page();
$data['links'] = $this->ajax_pagination->create_links();
$data['datatable'] = $this->DocumentModel->admin_get_and_search($conditions);
$this->load->view('admins/documents/ajax_pagination', $data, false);
}
public function delete(){
$id = $this->input->post('id');
unlink($this->DocumentModel->admin_get($id)['file_location']);
$result = $this->DocumentModel->delete($id);
$activity = array(
'page'=>'Documents',
'action'=>'Deleted document',
'created_on'=>date('Y-m-d'),
'time_on'=>date('h:i:s')
);
$this->ActivitiesModel->admin_create($activity);
if($result===false){
echo "false";
}else{
echo "true";
}
}
My view
<script>
function searchFilter(page_num) {
page_num = page_num?page_num:0;
var keywords = $('#search').val();
$.ajax({
type: 'POST',
url: '<?php echo site_url('/AdminDocuments/Search/'); ?>'+page_num,
data:'page='+page_num+'&keywords='+keywords,
beforeSend: function () {
$('.loading').show();
},
success: function (html) {
$('#list').html(html);
$('.loading').fadeOut("slow");
}
});
}
function deleteDocument(input){
var id = input;
console.log("javascript id "+id);
$.ajax({
type:'POST',
url:'<?php echo site_url('/AdminDocuments/Delete/'); ?>',
data:'id='+id,
beforeSend: function () {
$('.loading').show();
},
success:function(result){
console.log(result);
// $('#list').html(result);
searchFilter();
$('.loading').fadeOut("slow");
}
});
}
</script>
<div id="maincontainer">
<div id="list" class="row">
<div class="col-sm-12 table-responsive">
<table class="table">
<thead>
<tr class="text-left">
<td>Period</td>
<td>Name</td>
<td>Policy Number</td>
<td>Agent ID</td>
<td>Client ID</td>
<td>Policy Type</td>
<td>Transaction ID</td>
<td>File Name</td>
<td></td>
<td></td>
</tr>
</thead>
<tbody>
<?php
if(!empty($datatable)){
foreach ($datatable as $data){
?>
<tr class="text-left">
<td><?php echo $data['month']."/"; ?><?php echo $data['year']; ?></td>
<td><?php echo $data['first_name']; ?> <?php echo $data['last_name']; ?></td>
<td><?php echo $data['policy_number']; ?></td>
<td><?php echo $data['agent_id']; ?> </td>
<td><?php echo $data['client_id']; ?> </td>
<td><?php echo $data['policy_type']; ?></td>
<td><?php echo $data['transaction_id']; ?></td>
<td><?php echo $data['file_name']; ?></td>
<td><i class="fa fa-file" aria-hidden="true"></i> View</td>
<!--<td><i class="fa fa-trash" aria-hidden="true"></i> Delete</td>-->
<td><i class="fa fa-trash" aria-hidden="true"></i> Delete</td>
</tr>
<?php
}
}else{
?>
<tr>
<td colspan="7">You do not have any items at the moment</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
<div class="pagination-links pull-right">
<?php echo $links; ?>
</div>
</div>
<div class="loading" style="display: none;">
<div class="content">
<img src="<?php echo base_url().'assets/images/loading/loading.gif'; ?>"/>
</div>
</div>
</div>
Ajax pagination page which is what loads when a pagination link is selected
<div id="list" class="row">
<div class="col-sm-12 table-responsive">
<table class="table">
<thead>
<tr class="text-left">
<td>Period</td>
<td>Name</td>
<td>Policy Number</td>
<td>Agent ID</td>
<td>Client ID</td>
<td>Policy Type</td>
<td>Transaction ID</td>
<td>File Name</td>
<td></td>
<td></td>
</tr>
</thead>
<tbody>
<?php
if(!empty($datatable)){
foreach ($datatable as $data){
?>
<tr class="text-left">
<td><?php echo $data['month']."/"; ?><?php echo $data['year']; ?></td>
<td><?php echo $data['first_name']; ?> <?php echo $data['last_name']; ?></td>
<td><?php echo $data['policy_number']; ?></td>
<td><?php echo $data['agent_id']; ?> </td>
<td><?php echo $data['client_id']; ?> </td>
<td><?php echo $data['policy_type']; ?></td>
<td><?php echo $data['transaction_id']; ?></td>
<td><?php echo $data['file_name']; ?></td>
<td><i class="fa fa-file" aria-hidden="true"></i> View</td>
<td><i class="fa fa-trash" aria-hidden="true"></i> Delete</td>
</tr>
<?php
}
}else{
?>
<tr>
<td colspan="7">You do not have any items at the moment</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
<div class="pagination-links pull-right">
<?php echo $links; ?>
</div>
</div>
Pagination javascript located in the library
<script>
function getData(page){
// console.log(page);
$.ajax({
method: "POST",
url: "<?php echo $this->base_url; ?>"+page,
data: { page: page },
beforeSend: function(){
$('<?php echo $this->loading; ?>').show();
},
success: function(data){
$('<?php echo $this->loading; ?>').hide();
$('<?php echo $this->target; ?>').html(data);
}
});
}
</script>
I am unsure of how I can get the page number from the page itself.
You have to pass page_num in your function :
Check comment on below code:
success:function(result){
console.log(result);
// $('#list').html(result);
searchFilter(); // look at here
$('.loading').fadeOut("slow");
}
function searchFilter(page_num) // look at here

Categories

Resources