select('id')->select('name_plan')->find_many(); $plans = array(); $stocks = array("used" => 0, "unused" => 0); $n = 0; foreach ($tmp as $plan) { $unused = ORM::for_table('tbl_voucher') ->where('id_plan', $plan['id']) ->where('status', 0)->count(); $used = ORM::for_table('tbl_voucher') ->where('id_plan', $plan['id']) ->where('status', 1)->count(); if ($unused > 0 || $used > 0) { $plans[$n]['name_plan'] = $plan['name_plan']; $plans[$n]['unused'] = $unused; $plans[$n]['used'] = $used; $stocks["unused"] += $unused; $stocks["used"] += $used; $n++; } } file_put_contents($cacheStocksfile, json_encode($stocks)); file_put_contents($cachePlanfile, json_encode($plans)); } $ui->assign('stocks', $stocks); $ui->assign('plans', $plans); return $ui->fetch('widget/voucher_stocks.tpl'); } }