<?php
function generate_invoice_no($tipe = 'INV') {
    $db = \Config\Database::connect();
    $last = $db->table('orders')->orderBy('id_order', 'DESC')->limit(1)->get()->getRow();
    $no = $last ? (int)substr($last->no_invoice, -3) + 1 : 1;
    return $tipe . '/' . date('Y/m/') . str_pad($no, 3, '0', STR_PAD_LEFT);
}