hr dan payroll
This commit is contained in:
@@ -15,10 +15,17 @@ class Generatebuku extends MY_Controller
|
||||
|
||||
public function generatepdf($account_id, $start, $end)
|
||||
{
|
||||
if ($this->session->userdata('role') != 'Admin') {
|
||||
if (!is_master_admin_user() && $this->session->userdata('role') != 'Admin') {
|
||||
show_error('Akses ditolak', 403);
|
||||
}
|
||||
|
||||
$startDate = DateTime::createFromFormat('Y-m-d', (string) $start);
|
||||
$endDate = DateTime::createFromFormat('Y-m-d', (string) $end);
|
||||
if (!$startDate || $startDate->format('Y-m-d') !== $start
|
||||
|| !$endDate || $endDate->format('Y-m-d') !== $end || $end < $start) {
|
||||
show_error('Periode Buku Besar tidak valid.', 422);
|
||||
}
|
||||
|
||||
if (ob_get_length()) {
|
||||
ob_end_clean();
|
||||
}
|
||||
@@ -28,8 +35,12 @@ class Generatebuku extends MY_Controller
|
||||
// =============================================================
|
||||
$akun = null;
|
||||
if (!empty($account_id)) {
|
||||
$akun = $this->db->get_where('accounts', ['id' => (int) $account_id])->row();
|
||||
$akun = $this->db->get_where('accounts', ['id' => (int) $account_id, 'company_id'=>(int)$this->companycontext->id()])->row();
|
||||
}
|
||||
if (!$akun) show_error('Akun Buku Besar tidak ditemukan pada perusahaan aktif.', 404);
|
||||
|
||||
$openingRow=$this->db->select('COALESCE(SUM(d.debit),0) debit,COALESCE(SUM(d.kredit),0) kredit',false)->from('journal_details d')->join('journals j','j.id=d.journal_id')->where(array('j.company_id'=>(int)$this->companycontext->id(),'d.account_id'=>(int)$account_id))->where_in('j.status',array('posted','reversed'))->where('j.tanggal <',$start)->get()->row();
|
||||
$saldoAwal=in_array($akun->tipe,array('asset','expense'),true)?(float)$openingRow->debit-(float)$openingRow->kredit:(float)$openingRow->kredit-(float)$openingRow->debit;
|
||||
|
||||
// =============================================================
|
||||
// QUERY DATA
|
||||
@@ -46,6 +57,7 @@ class Generatebuku extends MY_Controller
|
||||
$this->db->join('journals', 'journals.id = journal_details.journal_id');
|
||||
$this->db->join('accounts', 'accounts.id = journal_details.account_id');
|
||||
$this->db->where_in('journals.status', array('posted', 'reversed'));
|
||||
$this->db->where('journals.company_id', (int)$this->companycontext->id());
|
||||
|
||||
if (!empty($account_id)) {
|
||||
$this->db->where('journal_details.account_id', (int) $account_id);
|
||||
@@ -61,14 +73,14 @@ class Generatebuku extends MY_Controller
|
||||
$this->db->or_where('journal_details.kredit >', 0);
|
||||
$this->db->group_end();
|
||||
|
||||
$this->db->order_by('journals.tanggal', 'ASC');
|
||||
$this->db->order_by('journals.tanggal', 'ASC')->order_by('journals.id','ASC')->order_by('journal_details.id','ASC');
|
||||
|
||||
$rows = $this->db->get()->result();
|
||||
|
||||
// =============================================================
|
||||
// HITUNG SALDO BERJALAN
|
||||
// =============================================================
|
||||
$saldo = 0;
|
||||
$saldo = $saldoAwal;
|
||||
$result = [];
|
||||
|
||||
foreach ($rows as $r) {
|
||||
@@ -94,7 +106,7 @@ class Generatebuku extends MY_Controller
|
||||
// =============================================================
|
||||
// DATA PERUSAHAAN
|
||||
// =============================================================
|
||||
$company = $this->db->get('pengaturan')->row();
|
||||
$company = $this->db->get_where('companies',array('id'=>(int)$this->companycontext->id()))->row();
|
||||
|
||||
// =============================================================
|
||||
// BUILD STRING INFO LAPORAN
|
||||
@@ -117,16 +129,16 @@ class Generatebuku extends MY_Controller
|
||||
$pdf->SetMargins(10, 10, 10);
|
||||
|
||||
$pdf->setHeaderData(
|
||||
$company->nama_perusahaan,
|
||||
$company->alamat_perusahaan,
|
||||
FCPATH . 'uploads/img/logo-ljn.png'
|
||||
$company->name,
|
||||
$company->address,
|
||||
!empty($company->logo_path) ? FCPATH.$company->logo_path : ''
|
||||
);
|
||||
|
||||
$pdf->setInfoLaporan($namaAkun, $periodeStr);
|
||||
|
||||
$pdf->AddPage('P', 'A4');
|
||||
$pdf->BukuBesarTable($result);
|
||||
$pdf->BukuBesarTotal($total_debit, $total_kredit, $saldo);
|
||||
$pdf->BukuBesarTotal($saldoAwal, $total_debit, $total_kredit, $saldo);
|
||||
$pdf->Pembuat('Tito Ngudiana', 'Finance Department');
|
||||
|
||||
// =============================================================
|
||||
|
||||
Reference in New Issue
Block a user