| Server IP : 162.214.74.102 / Your IP : 216.73.216.59 Web Server : Apache System : Linux dedi-4363141.lrsys.com.br 3.10.0-1160.119.1.el7.tuxcare.els25.x86_64 #1 SMP Wed Oct 1 17:37:27 UTC 2025 x86_64 User : lrsys ( 1015) PHP Version : 5.6.40 Disable Function : exec,passthru,shell_exec,system MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/lrsys/www/lrsys_apps/leve/application/plugins/module_fish/controllers/ |
Upload File : |
<?php
include_once "Controller.php";
include_once __DIR__ . "/../models/FeedingModel.php";
include_once __DIR__ . "/../models/FoodProgramsModel.php";
include_once __DIR__ . "/../models/MovementModel.php";
class FeedingController extends Controller {
/**
* @var ID
*/
protected $id;
/**
* @var FeedingModel
*/
protected $model;
/**
* @var Client ID
*/
protected $client_id;
/**
* @var SimplifiedProgramModel
*/
protected $model_simplified;
protected $modelProgram;
protected $modelMovement;
/**
* @param $ui
* @param array $_L
* @param array $config
* @param $_pd
*/
public function __construct($ui, $_L, $config, $_pd, $client_id = null) {
parent::__construct($ui, $_L, $config, $_pd);
$this->ui->assign('_title', $this->_L['Fish Description module'] . ' - ' . $this->config['CompanyName']);
$this->modelProgram = new FoodProgramsModel();
$this->model = new FeedingModel();
$this->modelMovement = new MovementModel();
$this->id = $this->routes[3];
$this->client_id = $client_id;
}
/**
* Show list to Feeding
*/
public function add() {
// LISTAR dearraçoamento
$css_arr = array('s2/css/select2.min', 'dp/dist/datepicker.min');
$js_arr = array(
's2/js/select2.min',
'dataTables/jquery.dataTables',
'/../../../application/plugins/module_fish/assets/js/feeding-add',
'dp/dist/datepicker.min',
// 'redactor/fontcolor',
'numeric'
);
$assets_css = Asset::css($css_arr);
$assets_js = Asset::js($js_arr);
$this->ui->assign('xheader', $assets_css);
$this->ui->assign('xfooter', $assets_js);
$this->ui->assign('jsvar', '
_L[\'are_you_sure\'] = \'' . $this->_L['are_you_sure'] . '\';
_L[\'Module_Fish Feeding are_you_sure\'] = \'' . $this->_L['Module_Fish Feeding are_you_sure'] . '\';
');
$this->ui->assign('_st', $this->_L['Fish Description module']);
$this->ui->assign('_include', 'feeding/add');
$this->ui->display('wrapper.tpl');
}
public function table() {
if (!empty(_post('sys_item_id'))) {
$d = ORM::for_table('sys_items')->find_one(_post('sys_item_id'));
$this->ui->assign('descritionProduct', "(" . $d->id . ") " . $d->description);
} else {
$this->ui->assign('descritionProduct', "");
}
$date_start = _postDate('date');
$date_end = _postDate('date_end');
if (empty($date_end)) {
$date_end = $date_start;
}
$di = new DateTime($date_start);
$interval = $di->diff(new DateTime($date_end));
if (strtotime(_postDate('date')) <= strtotime(_postDate('date_end'))) {
$totalDias = $interval->days;
} else {
$totalDias = 0;
}
$result = array();
for ($j = 0; $j <= $totalDias; $j++) {
$d = ORM::for_table('module_fish_lots')
->table_alias('l')
->select('l.*')
->select('t.title_tank')
->select('lp.module_fish_program_id')
->select_expr('ld.id as lote_id')
->join('module_fish_lots_distribution', array('ld.module_fish_lots_id', '=', 'l.id'), 'ld')
->join('module_fish_tank', array('t.id', '=', 'ld.module_fish_tank_id'), 't')
->join('module_fish_lots_distribution_program', array('lp.module_fish_lots_distribution_id', '=', 'ld.id'), 'lp')
->order_by_expr('concat(l.title_lote,t.title_tank) ASC');
if (!empty(_post('module_fish_lots_id'))) {
$d->where('l.id', _post('module_fish_lots_id'));
}
if (!empty(_post('crm_accounts_id'))) {
$d->where('l.crm_accounts_id', _post('crm_accounts_id'));
}
if ($this->client_id > 0) {
$d->where('l.crm_accounts_id', $this->client_id);
}
$d->where_raw(" ld.deleted_at IS NULL AND l.deleted_at IS NULL and ld.closed=0");
$lotes = $d->find_array();
$ex = count($lotes);
for ($i = 0; $i < $ex; $i++) {
if (strtotime($lotes[$i]['date_settlement']) <= strtotime("+ " . $j . " days", strtotime($date_start))) {
$data_inicio = new DateTime($lotes[$i]['date_settlement']);
$data_fim = new DateTime(date('Y-m-d', strtotime("+ " . $j . " days", strtotime($date_start))));
// Resgata diferença entre as datas
$dateInterval = $data_inicio->diff($data_fim);
//echo $l->date_settlement." - ".$dateInterval->days."<br/>";
//calcula, com base no peso incial, qual é a posição da ração
//pega a ultima biometria
$biom = ORM::for_table('module_fish_lots_distribution_biometry')
->table_alias('pp')
->select('pp.*')
->where("module_fish_lots_distribution_id", $lotes[$i]['lote_id'])
->where_raw("pp.date<='" . date('Y-m-d', strtotime("+ " . $j . " days", strtotime($date_start))) . "'")
->order_by_expr('pp.date desc')
->limit(1)
->find_many();
$diferecaBiometriaProgramDays = $this->modelProgram->positionLoteProgram($lotes[$i]['module_fish_program_id'], $lotes[$i]['date_settlement'], $biom[0]->average_weight, $biom[0]->date);
$periodo = ORM::for_table('module_fish_food_program_periods')
->table_alias('pp')
->select('pp.*')
->where("pp.module_fish_food_programs_id", $lotes[$i]['module_fish_program_id'])
->where_raw('pp.period_total >=' . ($dateInterval->days + $diferecaBiometriaProgramDays))
->limit(1)
->order_by_expr('pp.period_total ASC')
->find_many();
if (count($periodo) == 0 && (($dateInterval->days + $diferecaBiometriaProgramDays) > 0)) {
//se nao achou umperíodo pega como base o último período
$periodo = ORM::for_table('module_fish_food_program_periods')
->table_alias('pp')
->select('pp.*')
->where("module_fish_food_programs_id", $lotes[$i]['module_fish_program_id'])
->limit(1)
->order_by_expr('pp.period_total DESC')
->find_many();
}
$lotes[$i]['period'] = $periodo;
$sum = ORM::for_table('module_fish_feeding')
->select_expr('sum(qty) as total_feed')
->where('module_fish_lots_distribution_id', $lotes[$i]['lote_id'])
->where('date', date('Y-m-d', strtotime("+ " . $j . " days", strtotime($date_start))))->find_many();
if (!empty(_post('without_execution')) && $sum[0]->total_feed > 0) {
unset($lotes[$i]);
} else {
$lotes[$i]['be_performand'] = ($lotes[$i]['period'][0]->consumption_day - $sum[0]->total_feed) > 0 ? $lotes[$i]['period'][0]->consumption_day - $sum[0]->total_feed : 0;
$lotes[$i]['total_feed'] = $sum[0]->total_feed == null ? 0 : $sum[0]->total_feed;
$lotes[$i]['date'] = date($this->config['df'], strtotime("+ " . $j . " days", strtotime($date_start)));
$lotes[$i]['date_order'] = date("Y-m-d", strtotime("+ " . $j . " days", strtotime($date_start)));
}
} else {
unset($lotes[$i]); //data de povoamento menor que a data de arraçoamento
}
}
if (!empty($lotes)) {
$result = array_merge($result, $lotes);
}
}
$this->ui->assign('row', 0);
$this->ui->assign('lotes', $result);
$this->ui->display($this->_pd . '/views/feeding/table.tpl');
}
public function post() {
$msg = '';
if (empty(_post('sys_item_id'))) {
$msg .= $this->_L['Module_Fish Ration'] . $this->_L['is required'];
}
if (empty(_postDate('date'))) {
$msg .= $this->_L['Date'] . $this->_L['is required'];
}
if (!isset($_POST['row'])) {
$msg .= $this->_L['Module_Fish Select one tank execution'];
}
if ($msg == '') {
$row = $_POST['row'];
$costPrice = ORM::for_table('sys_items_costs')
->where('sys_items_id', _post('sys_item_id'))
->where_raw("cost_date<='" . date('Y-m-d') . "'")
->order_by_expr('cost_date desc')->limit(1)->find_many();
if (count($costPrice) > 0) {
$costPrice = $costPrice[0]->cost_price;
} else {
$costPrice = 0;
}
for ($i = 0; $i < count($row); $i++) {
$d = ORM::for_table('module_fish_feeding')->create();
$d->module_fish_lots_distribution_id = _post('id_' . $row[$i]);
$d->date = _postDate('date_feed_' . $row[$i]);
$d->sys_item_id = _post('sys_item_id');
if ($this->client_id == null) {
$user = User::_info();
$d->user_id = $user->id;
}
$d->qty = Finance::amount_fix(_post('feed_qty_' . $row[$i]));
if (_post('unity') == 1) {
$d->qty = $d->qty / 1000;
}
$now = new DateTime('now', new DateTimeZone('America/Sao_Paulo'));
$d->created_at = $now->format('Y-m-d H:i:s');
$d->save();
//carrrega os dados referente ao lote_distribuition tratado
$dataLote = ORM::for_table('module_fish_lots')
->table_alias('l')
->select('l.*')
->select('t.title_tank')
->join('module_fish_lots_distribution', array('ld.module_fish_lots_id', '=', 'l.id'), 'ld')
->join('module_fish_tank', array('t.id', '=', 'ld.module_fish_tank_id'), 't')
->join('module_fish_lots_distribution_program', array('lp.module_fish_lots_distribution_id', '=', 'ld.id'), 'lp')
->where('ld.id', $d->module_fish_lots_distribution_id)->find_many();
// sensibilizo o estoque
$stock = ORM::for_table('sys_stock')
->create();
$stock->sys_items_id = $d->sys_item_id;
$stock->type = 'out';
$stock->date = $d->date;
$stock->time = date("H:i:s");
$stock->quantity = $d->qty;
$stock->unit_price = $costPrice;
$stock->observation = "Arraçoamento realizado dia " . date($this->config['df'], strtotime($stock->date)) . " " . $dataLote[0]->title_lote . "/" . $dataLote[0]->title_lote;
$stock->dt_cadastro = date("Y-m-d H:i:s");
$stock->crm_accounts_id = $dataLote[0]->crm_accounts_id;
$stock->save();
//
//
// atualizo o saldo de produtos
$current_stocks = ORM::for_table('sys_items_stock')
->select('current_stock')
->where('sys_items_id', $d->sys_item_id)
->find_many();
$current_stock = ORM::for_table('sys_items_stock')->find_one($current_stocks[0]->id);
$current_stock->current_stock = $current_stock->current_stock - $d->qty;
$current_stock->save();
}
_notify($this->_L['Add Successfull'], 's');
echo json_encode(array('status' => 'OK', 'msg' => ''));
} else {
echo json_encode(array('status' => 'ERROR', 'msg' => $msg));
}
}
public function remove() {
$x = ORM::for_table('module_fish_feeding')->where('module_fish_lots_distribution_id', _post('lote_id'))->where('date', _postDate('date'))->delete_many();
echo 'OK';
}
public function view_feeding() {
$filter = array();
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$_SESSION['filter_fish_module_fish_species_id'] = _post('module_fish_species_id');
$_SESSION['filter_fish_crm_accounts_id'] = isset($_POST['crm_accounts_id']) ? $_POST['crm_accounts_id'] : '';
$_SESSION['filter_fish_period'] = _post('period');
$_SESSION['filter_fish_module_fish_lots_id'] = _post('module_fish_lots_id');
if ($_SESSION['filter_fish_period'] == 'interval') {
$_SESSION['filter_fish_period_ini'] = _postDate('period_ini');
$_SESSION['filter_fish_period_end'] = _postDate('period_end');
}
}
if (isset($_SESSION['filter_fish_module_fish_species_id'])) {
$filter['module_fish_species_id'] = $_SESSION['filter_fish_module_fish_species_id'];
} else {
$filter['module_fish_species_id'] = '';
}
if (isset($_SESSION['filter_fish_crm_accounts_id'])) {
$filter['crm_accounts_id'] = $_SESSION['filter_fish_crm_accounts_id'];
} else {
$filter['crm_accounts_id'] = '';
}
if (isset($_SESSION['filter_fish_module_fish_lots_id'])) {
$filter['module_fish_lots_id'] = $_SESSION['filter_fish_module_fish_lots_id'];
} else {
$filter['module_fish_lots_id'] = '';
}
if (isset($_SESSION['filter_fish_period'])) {
$filter['period'] = $_SESSION['filter_fish_period'];
} else {
$filter['period'] = 'day';
}
//regra para inciar listando sempre do mês Atual
if (empty($filter['period'])) {
$filter['period'] = 'day';
}
if (isset($_SESSION['filter_fish_period_ini'])) {
$filter['period_ini'] = $_SESSION['filter_fish_period_ini'];
$date_start = $filter['period_ini'];
} else {
$filter['period_ini'] = '';
}
if (isset($_SESSION['filter_fish_period_end'])) {
$filter['period_end'] = $_SESSION['filter_fish_period_end'];
$date_end = $filter['period_end'];
} else {
$filter['period_end'] = '';
}
if (isset($filter['period']) && $filter['period'] != '') {
if ($filter['period'] == 'day') {
$date_start = date('Y-m-d');
$date_end = date('Y-m-d');
}
if ($filter['period'] == 'week') {
$date_start = date("Y-m-d", strtotime("last sunday"));
$date_end = date("Y-m-d", strtotime("next saturday"));
}
if ($filter['period'] == 'month') {
$date_start = date("Y-m-1");
$date_end = date("Y-m-t");
}
if ($filter['period'] == 'all') {
$dataFirstSettlement = ORM::for_table('module_fish_lots')->order_by_expr(' date_settlement ASC')->limit(1)->find_many();
if (count($dataFirstSettlement) == 1) {
$date_start = $dataFirstSettlement[0]->date_settlement;
} else {
$date_start = date('Y-m-d');
}
$date_end = date('Y-m-d');
}
}
$graph['date'] = array();
$graph['total_feed'] = array();
$graph['total_feed_prev'] = array();
$graph['total_biomass_prev'] = array();
$graph['total_biomass_real'] = array();
$total['total_feed'] = 0;
$total['total_feed_prev'] = 0;
$totalBiomassPrev = array();
$totalBiomassReal = array();
$totalBiomassInicial = array();
$di = new DateTime($date_start);
$interval = $di->diff(new DateTime($date_end));
$totalDias = $interval->days;
$result = array();
for ($j = 0; $j <= $totalDias; $j++) {
$d = ORM::for_table('module_fish_lots')
->table_alias('l')
->select('l.*')
->select_expr('t.title_tank,t.id as id_tank')
->select('lp.module_fish_program_id')
->select_expr('ld.id as lote_id')
->select_expr('ld.qty as initial_qty')
->join('module_fish_lots_distribution', array('ld.module_fish_lots_id', '=', 'l.id'), 'ld')
->join('module_fish_tank', array('t.id', '=', 'ld.module_fish_tank_id'), 't')
->join('module_fish_lots_distribution_program', array('lp.module_fish_lots_distribution_id', '=', 'ld.id'), 'lp')
->order_by_expr('concat(l.title_lote,t.title_tank) ASC');
if (isset($filter['module_fish_species_id']) && $filter['module_fish_species_id'] != '') {
$d->where('l.module_fish_species_id', $filter['module_fish_species_id']);
}
if (isset($filter['module_fish_lots_id']) && $filter['module_fish_lots_id'] != '') {
$d->where('l.id',$filter['module_fish_lots_id']);
}
if (isset($filter['crm_accounts_id']) && $filter['crm_accounts_id'] != '') {
$d->where_in('l.crm_accounts_id', $filter['crm_accounts_id']);
}
if ($this->client_id > 0) {
$d->where('l.crm_accounts_id', $this->client_id);
}
$d->where_raw(" ld.deleted_at IS NULL AND l.deleted_at IS NULL and l.date_settlement<='" . date("Y-m-d", strtotime("+ " . $j . " days", strtotime($date_start))) . "'");
$lotes = $d->find_array();
$ex = count($lotes);
for ($i = 0; $i < $ex; $i++) {
$data_inicio = new DateTime($lotes[$i]['date_settlement']);
$data_fim = new DateTime(date('Y-m-d', strtotime("+ " . $j . " days", strtotime($date_start))));
$lotes[$i]['date_feed'] = date('Y-m-d', strtotime("+ " . $j . " days", strtotime($date_start)));
// Resgata diferença entre as datas
$dateInterval = $data_inicio->diff($data_fim);
//echo $l->date_settlement." - ".$dateInterval->days."<br/>";
//calcula, com base no peso incial, qual é a posição da ração
//pega a ultima biometria
$biom = ORM::for_table('module_fish_lots_distribution_biometry')
->table_alias('pp')
->select('pp.*')
->where("pp.module_fish_lots_distribution_id", $lotes[$i]['lote_id'])
->where_raw("pp.date<='" . date('Y-m-d', strtotime("+ " . $j . " days", strtotime($date_start))) . "'")
->order_by_expr('pp.date desc')
->limit(1)
->find_many();
$diferecaBiometriaProgramDays = $this->modelProgram->positionLoteProgram($lotes[$i]['module_fish_program_id'], $lotes[$i]['date_settlement'], $biom[0]->average_weight, $biom[0]->date);
$weightReal = $this->modelProgram->weigthEstimatedProgram($lotes[$i]['date_settlement'], $lotes[$i]['module_fish_program_id'], date('Y-m-d', strtotime($diferecaBiometriaProgramDays . ' days', strtotime("+ " . $j . " days", strtotime($date_start)))), $lotes[$i]['lote_id']);
$periodoReal = ORM::for_table('module_fish_food_program_periods')
->table_alias('pp')
->select('pp.*')
->where("pp.module_fish_food_programs_id", $lotes[$i]['module_fish_program_id'])
->where_raw('pp.period_total >=' . ($dateInterval->days + $diferecaBiometriaProgramDays))
->limit(1)
->order_by_expr('pp.period_total ASC')
->find_many();
if (count($periodoReal) == 0 && (($dateInterval->days + $diferecaBiometriaProgramDays) > 0)) {
//se nao achou umperíodo pega como base o último período
$periodoReal = ORM::for_table('module_fish_food_program_periods')
->table_alias('pp')
->select('pp.*')
->where("module_fish_food_programs_id", $lotes[$i]['module_fish_program_id'])
->limit(1)
->order_by_expr('pp.period_total DESC')
->find_many();
}
$biomPrev = ORM::for_table('module_fish_lots_distribution_biometry')
->table_alias('pp')
->select('pp.*')
->where("module_fish_lots_distribution_id", $lotes[$i]['lote_id'])
->where_raw("pp.date<='" . date('Y-m-d', strtotime("+ " . $j . " days", strtotime($date_start))) . "'")
->order_by_expr('pp.date asc')
->limit(1)
->find_many();
$diferecaBiometriaProgramDaysPrev = $this->modelProgram->positionLoteProgram($lotes[$i]['module_fish_program_id'], $lotes[$i]['date_settlement'], $biomPrev[0]->average_weight, $biomPrev[0]->date);
$weightPrev = $this->modelProgram->weigthEstimatedProgram($lotes[$i]['date_settlement'], $lotes[$i]['module_fish_program_id'], date('Y-m-d', strtotime($diferecaBiometriaProgramDaysPrev . ' days', strtotime("+ " . $j . " days", strtotime($date_start)))), $lotes[$i]['lote_id']);
$periodoPrev = ORM::for_table('module_fish_food_program_periods')
->table_alias('pp')
->select('pp.*')
->where("pp.module_fish_food_programs_id", $lotes[$i]['module_fish_program_id'])
->where_raw('pp.period_total >=' . ($dateInterval->days + $diferecaBiometriaProgramDaysPrev))
->limit(1)
->order_by_expr('pp.period_total ASC')
->find_many();
if (count($diferecaBiometriaProgramDaysPrev) == 0 && (($dateInterval->days + $diferecaBiometriaProgramDays) > 0)) {
//se nao achou umperíodo pega como base o último período
$periodoPrev = ORM::for_table('module_fish_food_program_periods')
->table_alias('pp')
->select('pp.*')
->where("module_fish_food_programs_id", $lotes[$i]['module_fish_program_id'])
->limit(1)
->order_by_expr('pp.period_total DESC')
->find_many();
}
//armazena a biomassa inicial de cada lote
$totalBiomassInicial[$lotes[$i]['lote_id']] = (($biomPrev[0]->average_weight * $lotes[$i]['initial_qty']));
//calcula a quantidade existente no tanque no momento dessa amostragem
$totalMovimented = $this->modelMovement->getTotalMovimentTankLote($lotes[$i]['lote_id'], $lotes[$i]['id_tank'], date('Y-m-d H:i:s', strtotime("+ " . $j . " days", strtotime($date_start))));
$lotes[$i]['initial_qty']+=$totalMovimented;
$sum = ORM::for_table('module_fish_feeding')
->select_expr('sum(qty) as total_feed')
->where('module_fish_lots_distribution_id', $lotes[$i]['lote_id'])
->where('date', date('Y-m-d', strtotime("+ " . $j . " days", strtotime($date_start))))->find_many();
$lotes[$i]['total_feed'] = (($sum[0]->total_feed));
$lotes[$i]['total_feed_prev'] = (($periodoReal[0]->consumption_day));
$lotes[$i]['total_biomass_prev'] = (($weightPrev * $lotes[$i]['initial_qty']));
$lotes[$i]['total_biomass_real'] = (($weightReal * $lotes[$i]['initial_qty']));
$total['total_feed']+=(($sum[0]->total_feed));
$total['total_feed_prev']+=(($periodoReal[0]->consumption_day));
//armazena, as ultimas biomassas de cada lote_tanque,
//assim mantem de qualquer lote, a ultima vez que passou aqui
//é o que deve ser usado na biomassa
$totalBiomassPrev[$lotes[$i]['lote_id']] = (($weightPrev * $lotes[$i]['initial_qty']));
$totalBiomassReal[$lotes[$i]['lote_id']] = (($weightReal * $lotes[$i]['initial_qty']));
if (isset($graph['total_feed'][date('Y-m-d', strtotime("+ " . $j . " days", strtotime($date_start)))])) {
$graph['total_feed'][date('Y-m-d', strtotime("+ " . $j . " days", strtotime($date_start)))]+=($sum[0]->total_feed);
$graph['total_feed_prev'][date('Y-m-d', strtotime("+ " . $j . " days", strtotime($date_start)))]+=(($periodoReal[0]->consumption_day));
$graph['total_biomass_prev'][date('Y-m-d', strtotime("+ " . $j . " days", strtotime($date_start)))]+=(($weightPrev * $lotes[$i]['initial_qty']));
$graph['total_biomass_real'][date('Y-m-d', strtotime("+ " . $j . " days", strtotime($date_start)))]+=(($weightReal * $lotes[$i]['initial_qty']));
} else {
$graph['date'][date('Y-m-d', strtotime("+ " . $j . " days", strtotime($date_start)))] = "'" . date($this->config['df'], strtotime(date('Y-m-d', strtotime("+ " . $j . " days", strtotime($date_start))))) . "'";
$graph['total_feed'][date('Y-m-d', strtotime("+ " . $j . " days", strtotime($date_start)))] = ($sum[0]->total_feed);
$graph['total_feed_prev'][date('Y-m-d', strtotime("+ " . $j . " days", strtotime($date_start)))] = (($periodoReal[0]->consumption_day));
$graph['total_biomass_prev'][date('Y-m-d', strtotime("+ " . $j . " days", strtotime($date_start)))] = (($weightPrev * $lotes[$i]['initial_qty']));
$graph['total_biomass_real'][date('Y-m-d', strtotime("+ " . $j . " days", strtotime($date_start)))] = (($weightReal * $lotes[$i]['initial_qty']));
}
}
if (!empty($lotes)) {
$result = array_merge($result, $lotes);
}
}
$css_arr = array(
's2/css/select2.min',
'dp/dist/datepicker.min',
'/../../../application/plugins/module_fish/assets/css/default');
$js_arr = array(
's2/js/select2.min',
'dp/dist/datepicker.min',
'dashboard/graph', 'chart/echarts.min',
'/../../../application/plugins/module_fish/assets/js/feeding_view'
);
$assets_css = Asset::css($css_arr);
$assets_js = Asset::js($js_arr);
$this->ui->assign('xheader', $assets_css);
$this->ui->assign('xfooter', $assets_js);
if (count($graph['total_feed']) > 0) {
//Formata 3 casas decimais
foreach ($graph['total_feed'] as $key => $value) {
$graph['total_feed'][$key] = number_format($value, 3, ".", "");
}
foreach ($graph['total_feed_prev'] as $key => $value) {
$graph['total_feed_prev'][$key] = number_format($value, 3, ".", "");
}
foreach ($graph['total_biomass_prev'] as $key => $value) {
$graph['total_biomass_prev'][$key] = number_format($value, 3, ".", "");
}
foreach ($graph['total_biomass_real'] as $key => $value) {
$graph['total_biomass_real'][$key] = number_format($value, 3, ".", "");
}
}
//faz o somatorio, das ultimas biomassas de cada lote tanque
$bottomBiomassTotal = 0;
$bottomBiomassTotalReal = 0;
$gpReal = 0;
$gpEstimado = 0;
if (count($totalBiomassPrev) > 0) {
foreach ($totalBiomassPrev as $key => $value) {
$bottomBiomassTotal+=$totalBiomassPrev[$key];
$bottomBiomassTotalReal+=$totalBiomassReal[$key];
$gpReal+=$totalBiomassReal[$key] - $totalBiomassInicial[$key];
$gpEstimado+=$totalBiomassPrev[$key] - $totalBiomassInicial[$key];
}
}
$jsvar = '
_L[\'Data View\'] = \'' . $this->_L['Data View'] . '\';
_L[\'Refresh\'] = \'' . $this->_L['Refresh'] . '\';
_L[\'Reset\'] = \'' . $this->_L['Reset'] . '\';
_L[\'Cancel\'] = \'' . $this->_L['Cancel'] . '\';
_L[\'Save as Image\'] = \'' . $this->_L['Save as Image'] . '\';
_L[\'Click to Save\'] = \'' . $this->_L['Click to Save'] . '\';
_L[\'Average\'] = \'' . $this->_L['Average'] . '\';
_L[\'Line\'] = \'' . $this->_L['Line'] . '\';
_L[\'Bar\'] = \'' . $this->_L['Bar'] . '\';
_L[\'Module_Fish Select Associated\'] = \'' . $this->_L['Module_Fish Select Associated'] . '\';
_L[\'Module_Fish Select Specie\'] = \'' . $this->_L['Module_Fish Select Specie'] . '\';
_L[\'Module_Fish Select Lote\'] = \'' . $this->_L['Module_Fish Select Lote'] . '\';
';
if (isset($filter['module_fish_species_id']) && $filter['module_fish_species_id'] != '') {
$this->ui->assign('species', ORM::for_table('module_fish_species')->find_one(intval($filter['module_fish_species_id'])));
} else {
$this->ui->assign('species', false);
}
if (isset($filter['module_fish_lots_id']) && $filter['module_fish_lots_id'] != '') {
$this->ui->assign('lots_filter', ORM::for_table('module_fish_lots')->find_one(intval($filter['module_fish_lots_id'])));
} else {
$this->ui->assign('lots_filter', false);
}
if (isset($filter['crm_accounts_id']) && $filter['crm_accounts_id'] != '') {
$options = "";
foreach ($filter['crm_accounts_id'] as $c) {
$c = ORM::for_table('crm_accounts')->find_one($c);
if (count($c) > 0) {
$options .= '<option value="' . $c->id . '" selected >' . $c->account . '</option>';
}
}
$this->ui->assign('account', $options);
} else {
$this->ui->assign('account', false);
}
$this->ui->assign('jsvar', $jsvar
. showGraph(array('Realizado', 'Previsto'), $this->_L['Module_Fish Feeding'] . $this->_L['Module_Fish / Day'], "graph_feed", array($graph['total_feed'], $graph['total_feed_prev']), $graph['date'], false, array("#ff0000", "#0000FF"))
. showGraph(array('Real', 'Previsto'), $this->_L['Module_Fish Biomass'] . $this->_L['Module_Fish / Day'], "graph_biomass", array($graph['total_biomass_real'], $graph['total_biomass_prev']), $graph['date'], false, array("#ff0000", "#0000FF"))
);
$bottomBar = array(
array('type' => 'float3', 'info' => $this->_L['Total'] . " " . $this->_L['Module_Fish Feed'] . " kg", 'value' => $total['total_feed']),
array('type' => 'float3', 'info' => $this->_L['Total'] . " " . $this->_L['Module_Fish Expected'] . " kg", 'value' => $total['total_feed_prev']),
array('type' => 'float3', 'info' => $this->_L['Module_Fish Biomass Total'] . " Real kg", 'value' => $bottomBiomassTotalReal),
array('type' => 'float3', 'info' => $this->_L['Module_Fish Biomass Total'] . " Prevista kg", 'value' => $bottomBiomassTotal),
array('type' => 'float', 'info' => $this->_L['Module_Fish Food conversion'] . " Real", 'value' => ($gpReal > 0 ? ($total['total_feed'] / $gpReal) : "0")),
array('type' => 'float', 'info' => $this->_L['Module_Fish Food conversion'] . " Previsto", 'value' => ($gpEstimado > 0 ? ($total['total_feed_prev'] / $gpEstimado) : "0")),
);
if ($filter['period'] == 'all') {
$filter['period_ini'] = "";
$filter['period_end'] = "";
}
$this->ui->assign('bottomBar', $bottomBar);
$this->ui->assign('filter', $filter);
$this->ui->assign('lotes', $result);
$this->ui->assign('_st', $this->_L['Fish Description module']);
$this->ui->assign('_include', 'feeding/view_feeding');
$this->ui->display('wrapper.tpl');
}
}
function showGraph($title, $description, $identificador, $valueSeries, $listDay, $showBackground = false, $color = "#2196f3") {
global $_L;
$series = "{
name:'" . $title[0] . "',
type:'line',
smooth:true,
color: [
'" . $color[0] . "'
]," .
($showBackground ? "itemStyle: {normal: {areaStyle: {type: 'default'}}}," : "")
. " data:[" . "'" . (count($valueSeries[0]) == 0 ? '' : implode("','", $valueSeries[0])) . "']
}"
.
",{
name:'" . $title[1] . "',
type:'line',
smooth:true,
color: [
'" . $color[1] . "'
]," .
($showBackground ? "itemStyle: {normal: {areaStyle: {type: 'default'}}}," : "")
. " data:[" . "'" . (count($valueSeries[1]) == 0 ? '' : implode("','", $valueSeries[1])) . "']
}"
;
return " $(function() { var " . $identificador . "_opt = {
title : {
text:'" . $description . "',
subtext: ''
},
tooltip : {
trigger: 'axis'
},
legend: {
data:['" . $title[0] . "','" . $title[1] . "']
},
toolbox: {
show : true,
feature : {
mark : {show: true},
dataView : {show: true, readOnly: false, title : _L['Data View'],
lang: [_L['Data View'], _L['Cancel'], _L['Reset']] },
magicType : {show: true, title : {
line : 'Line',
bar : 'Bar',
stack : 'Stack',
tiled : 'Tiled',
force: 'Force',
chord: 'Chord',
pie: 'Pie',
funnel: 'Funnel'
}, type: ['line', 'bar', 'stack', 'tiled']},
restore : {show: true, title : 'Reset'},
saveAsImage : {show: true, title : _L['Save as Image'],
type : 'png',
lang : [_L['Click to Save']]}
}
},
calculable : true,
xAxis : [
{
type : 'category',
boundaryGap : false,
data :[" . implode(",", $listDay) . "]
}
],
yAxis : [
{
type : 'value'
}
],
series :
[
" . $series . "
]
};
var " . $identificador . " = echarts.init(document.getElementById('" . $identificador . "'));
" . $identificador . ".setOption(" . $identificador . "_opt);
});";
}