Postingan lainnya
Kelas Premium!
Belajar bikin website dari nol sekarang
Gunakan kupon "lebihcepat" untuk diskon 25%!
Bagaimana caranya mencetak data, berdasarkan range filter tanggal menggunakan codeigniter 4?
Controllers:
<?php
namespace App\Controllers;
use App\Controllers\BaseController;
use App\Models\M_Transaction;
class Transaction extends BaseController
{
public function __construct()
{
$this->M_Transaction = new M_Transaction();
helper('form');
}
public function index()
{
$data = [
'title' => 'Goods Transaction',
'message' => 'Goods Transaction Page ',
'choose_date' => $this->M_Transaction->choose_date(),
];
return view('content/transaction/v_transaction', $data);
}
public function print_report()
{
$data = [
'title' => 'Print Goods Report',
'message' => 'Goods Report Page ',
'choose_date' => $this->M_Transaction->choose_date(),
];
return view('content/transaction/v_goods_report', $data);
}
}
Models:
<?php
namespace App\Models;
use CodeIgniter\Model;
class M_Transaction extends Model
{
public function choose_date()
{
$this->db = db_connect();
$from = @$_POST['mulai_tanggal'];
$to = @$_POST['sampai_tanggal'];
return $this->db->table('tbl_barang')
->join('tbl_kategori', 'tbl_kategori.id_kategori=tbl_barang.id_kategori')
->join('tbl_satuan', 'tbl_satuan.id_satuan=tbl_barang.id_satuan')
->where("tgl_barang BETWEEN '{$from}' AND '{$to}'")
->orderBy('id_barang', 'ASC')
->get()
->getResultArray();
}
}
Views (v_transaction):
<?= $this->extend('template/v_backend') ?>
<?= $this->section('content') ?>
<div class="col-sm-12">
<section class="content">
<div class="card">
<div class="card-header">
<h3 class="card-title">Goods Transaction List</h3>
<div class="card-tools">
<button type="button" class="btn btn-tool" data-card-widget="collapse" title="Collapse">
<i class="fas fa-minus"></i>
</button>
<button type="button" class="btn btn-tool" data-card-widget="remove" title="Remove">
<i class="fas fa-times"></i>
</button>
</div>
</div>
<div class="card-body">
<?php echo form_open('Transaction') ?>
<?= csrf_field(); ?>
<div class="container align-items-center">
<div class="row">
<div class="col-6">
<div class="form-group">
<label for="inputMulaiTanggal" class="font-weight-bold">Mulai Tanggal :</label>
<input type="date" id="inputMulaiTanggal" name="mulai_tanggal" class="form-control" name="mulai_tanggal" required>
</div>
</div>
<div class="col-6">
<div class="form-group">
<label for="inputSampaiTanggal" class="font-weight-bold">Sampai Tanggal :</label>
<input type="date" id="inputSampaiTanggal" name="sampai_tanggal" class="form-control" name="sampai_tanggal" required>
</div>
</div>
<div class="container text-center">
<button type="submit" class="btn btn-success"><i class="fas fa-search"></i> Find</button>
<a href="<?= base_url('Transaction/print_report'); ?>" target="_blank" class="btn btn-primary"><i class="fas fa-print"></i> Print</a>
</div>
</div>
</div>
<?php echo form_close() ?>
<br>
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th class="text-center" width="20px">No</th>
<th class="text-center">Items Code</th>
<th class="text-center">Date Goods</th>
<th class="text-center">Category</th>
<th class="text-center">Item Unit</th>
<th class="text-center">Items Name</th>
<th class="text-center">Brand</th>
<th class="text-center">Goods Stock</th>
</tr>
</thead>
<tbody>
<?php $no = 1 ?>
<?php foreach ($choose_date as $key => $value) { ?>
<tr>
<td class="text-center"><?= $no++; ?></td>
<td class="text-center"><?= $value['kode_barang']; ?></td>
<td class="text-center"><?php if (!empty($value["tgl_barang"])) { ?><?= date('d/m/Y', strtotime($value["tgl_barang"])); ?><?php }; ?></td>
<td class="text-center"><?= $value['nama_kategori']; ?></td>
<td class="text-center"><?= $value['nama_satuan']; ?></td>
<td class="text-center"><?= $value['nama_barang']; ?></td>
<td class="text-center"><?= $value['merk_barang']; ?></td>
<td class="text-center"><?= $value['stok_barang']; ?></td>
</tr>
<?php }; ?>
</tbody>
</table>
</div>
</div>
</section>
</div>
<?= $this->endSection() ?>
Filter tanggal.jpg
Bagaimana mencetak data yg sudah di filter tanggal oleh user agar tercetak ke sini (v_goods_report)?
Views (v_goods_report):
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Goods Reports</title>
</head>
<body>
<div class="wrapper">
<section class="invoice">
<div class="row">
<div class="col sm-1">
Logo
</div>
<div class="col-11">
<h3 class="page-header">
Herlan
<small class="float-right">Di Cetak Tanggal: <?= date('d-m-Y'); ?></small>
</h3>
<h5>Alamat</h5>
</div>
</div>
<br>
<div class="row">
<div class="col sm-12">
<div class="text-center">
<h3><b>Goods Reports</b></h3>
</div>
</div>
<div class="col-12 table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th class="text-center" width="20px">No</th>
<th class="text-center">Items Code</th>
<th class="text-center">Date Goods</th>
<th class="text-center">Category</th>
<th class="text-center">Item Unit</th>
<th class="text-center">Items Name</th>
<th class="text-center">Brand</th>
<th class="text-center">Goods Stock</th>
</tr>
</thead>
<tbody>
<?php $no = 1 ?>
<?php foreach ($choose_date as $key => $value) { ?>
<tr>
<td class="text-center"><?= $no++; ?></td>
<td class="text-center"><?= $value['kode_barang']; ?></td>
<td class="text-center"><?php if (!empty($value["tgl_barang"])) { ?><?= date('d/m/Y', strtotime($value["tgl_barang"])); ?><?php }; ?></td>
<td class="text-center"><?= $value['nama_kategori']; ?></td>
<td class="text-center"><?= $value['nama_satuan']; ?></td>
<td class="text-center"><?= $value['nama_barang']; ?></td>
<td class="text-center"><?= $value['merk_barang']; ?></td>
<td class="text-center"><?= $value['stok_barang']; ?></td>
</tr>
<?php }; ?>
</tbody>
</table>
</div>
</div>
</section>
</div>
<script>
window.addEventListener("load", window.print());
</script>
</body>
</html>
0
Belum ada Jawaban. Jadi yang pertama Jawaban
Login untuk ikut Jawaban