| 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/MovementModel.php";
include_once __DIR__ . "/../models/FoodProgramsModel.php";
class MovementController extends Controller {
/**
* @var ID
*/
protected $id;
/**
* @var MovementModel
*/
protected $model;
/**
* @var Client ID
*/
protected $client_id;
/**
* @var SimplifiedProgramModel
*/
protected $modelProgram;
/**
* @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->model = new MovementModel();
$this->modelProgram = new FoodProgramsModel();
$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/movement-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 Select tank origin\'] = \'' . $this->_L['Module_Fish Select tank origin'] . '\';
_L[\'Module_Fish Program\'] = \'' . $this->_L['Module_Fish Program'] . '\';
_L[\'All movement destiny will be removed, it will be necessary to re-register them. You Want do Continue?\'] = \'' . $this->_L['All movement destiny will be removed, it will be necessary to re-register them. You Want do Continue?'] . '\';
_L[\'Module_Fish Is necessarie clear qtd restant tank\'] = \'' . $this->_L['Module_Fish Is necessarie clear qtd restant tank'] . '\';
');
$this->ui->assign('_st', $this->_L['Fish Description module']);
$this->ui->assign('_include', 'movement/add');
$this->ui->display('wrapper.tpl');
}
public function data_lote() {
if (!empty(_post('module_fish_lots_distribuition_id'))) {
$d = ORM::for_table('module_fish_lots')
->table_alias('l')
->select('l.*')
->select_expr('t.title_tank,t.id as id_tank,ld.qty')
->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');
$d->where('ld.id', intval(_post('module_fish_lots_distribuition_id')));
if($this->client_id > 0)
{
$d->where('l.crm_accounts_id', $this->client_id );
}
$records = $d->find_many();
if (count($records) > 0) {
$records[0]['weight_actual'] = $this->modelProgram->weigthEstimatedProgram($records[0]->date_settlement, $records[0]->module_fish_program_id, _postDate('date'),$records[0]->lote_id);
}
$totalMovimented = $this->model->getTotalMovimentTankLote($records[0]->lote_id, $records[0]->id_tank, date('Y-m-d H:i:s'));
$records[0]->qty = $records[0]->qty + $totalMovimented;
$this->ui->assign('lote', $records[0]);
$this->ui->assign('date', _postDate('date'));
$this->ui->display($this->_pd . '/views/movement/data-lote.tpl');
} else {
$this->ui->assign('lote', array());
$this->ui->display($this->_pd . '/views/movement/data-lote.tpl');
}
}
//echo 0 se nao eccontrar o lote com o tank, e maior que 0 se encontrar
public function verifyTankLote() {
echo $this->model->verifyTankLote(_post('module_fish_lots_distribuition_id'), _post("module_fish_tank_id"));
}
public function post() {
$msg = '';
if (empty(_postDate('date'))) {
$msg .= $this->_L['Date'] . $this->_L['is required'];
}
if (empty(_postDate('hour'))) {
$msg .= $this->_L['Hour'] . $this->_L['is required'];
}
if (empty(_post('module_fish_lots_distribuition_id'))) {
$msg .= $this->_L['Origin'] . " - " . $this->_L['Module_Fish Lote'] . " - " . $this->$this->_L['Module_Fish Tank'] . $this->_L['is required'];
}
if (empty(_post('close')) && Finance::amount_fix(_post("weight_restant") == 0)) {
$msg .= $this->_L['Module_Fish average weight'] . " " . $this->_L['Origin'] . $this->_L['is required'];
}
$row = $_POST['row'];
for ($i = 0; $i < count($row); $i++) {
if (_post("type") == 'transfer') {
if (empty(_post('tank_' . $row[$i]))) {
$msg.=($i + 1) . "° " . $this->_L['Module_Fish Tank'] . $this->_L['is required'];
}
if (empty(_post('qty_' . $row[$i]))) {
$msg.=($i + 1) . "° " . $this->_L['Quantity'] . $this->_L['is required'];
}
if (empty(_post('weight_' . $row[$i]))) {
$msg.=($i + 1) . "° " . $this->_L['Module_Fish average weight'] . $this->_L['is required'];
}
if (_post('program_required_' . $row[$i]) == 1 && empty(_post('program_' . $row[$i]))) {
$msg.=($i + 1) . "° " . $this->_L['Module_Fish Program'] . $this->_L['is required'];
}
}else {
if (empty(_post('qty_' . $row[$i]))) {
$msg.= $this->_L['Quantity'] . $this->_L['is required'];
}
if (empty(_post('weight_' . $row[$i]))) {
$msg.= $this->_L['Module_Fish average weight'] . $this->_L['is required'];
}
if (_post("type") == 'sale') {
if (empty(_post('client_id'))) {
$msg.= $this->_L['Customer'] . $this->_L['is required'];
}
if (empty(_post('sales_price'))) {
$msg.= $this->_L['Value'] . $this->_L['is required'];
}
}
}
}
if ($msg == '') {
//busca o lote de origem
$module_fish_lots_distribution = ORM::for_table('module_fish_lots_distribution')->find_one(_post('module_fish_lots_distribuition_id'));
$module_fish_movement = ORM::for_table('module_fish_movement')->create();
//para transfer tem dois tipos possíveis tratados abaixo
if($this->client_id ==null){
$user = User::_info();
$module_fish_movement->user_id = $user->id;
}
$module_fish_movement->module_fish_lots_distribution_id = $module_fish_lots_distribution->id;
$module_fish_movement->date = _postDate("date") . " " . _post("hour");
$module_fish_movement->created_at = date("Y-m-d H:i:s");
if (_post("type") == 'sale') {
$module_fish_movement->client_id=_post('client_id');
$module_fish_movement->sales_price=Finance::amount_fix(_post('sales_price'));
}
$module_fish_movement->save();
if (!empty(_post('close')) && _post("close") == 1) {
$module_fish_lots_distribution->closed = 1;
$module_fish_lots_distribution->save();
} else {
//se nao for para fechar insere uma biometria para o tanque de origem
$b = ORM::for_table('module_fish_lots_distribution_biometry')->create();
$b->module_fish_lots_distribution_id = $module_fish_lots_distribution->id;
$b->date = _postDate("date");
$b->average_weight = (Finance::amount_fix(_post("weight_restant")) / 1000);
$b->created_at = $module_fish_movement->created_at;
$b->module_fish_movement_id = $module_fish_movement->id;
if($this->client_id ==null){
$b->user_id = $user->id;
}
$b->save();
}
for ($i = 0; $i < count($row); $i++) {
$module_fish_movementItem = ORM::for_table('module_fish_movement_itens')->create();
// $module_fish_movementItem->module_fish_tank_id_origin = $module_fish_lots_distribution->module_fish_tank_id;
if (_post("type") == 'transfer') {
$module_fish_movementItem->module_fish_tank_id_destiny = _post("tank_" . $row[$i]);
} else {
$module_fish_movementItem->type = _post("type");
}
$module_fish_movementItem->average_weight =(Finance::amount_fix(_post("weight_" . $row[$i])) / 1000);
$module_fish_movementItem->qty = _post("qty_" . $row[$i]);
$module_fish_movementItem->created_at = date("Y-m-d H:i:s");
$module_fish_movementItem->module_fish_movement_id = $module_fish_movement->id;
$module_fish_movementItem->save();
if (_post("type") == 'transfer') {
$dT = ORM::for_table('module_fish_lots')
->table_alias('l')
->select('l.*')
->select_expr('t.title_tank,t.id as id_tank,ld.qty')
->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');
$dT->where('l.id', $module_fish_lots_distribution->module_fish_lots_id);
$dT->where('ld.module_fish_tank_id', _post("tank_" . $row[$i]));
$dT->where('ld.closed', 0);
$module_fish_lots_distributionTank = $dT->find_many();
//VERIFICA SE TEM O LOTE cOM O TANK DA MOVIMENTAÇÃO
if (count($module_fish_lots_distributionTank) > 0) {
$estimated = $this->modelProgram->weigthEstimatedProgram($module_fish_lots_distributionTank[0]->date_settlement, $module_fish_lots_distributionTank[0]->module_fish_program_id, _postDate('date'),$module_fish_lots_distributionTank[0]->lote_id);
$b = ORM::for_table('module_fish_lots_distribution_biometry')->create();
$b->module_fish_lots_distribution_id = $module_fish_lots_distributionTank[0]->lote_id;
$b->date = _postDate("date");
$b->average_weight = ((Finance::amount_fix(_post("weight_" + $row[$i])) / 1000) + $estimated) / 2;
$b->created_at = date("Y-m-d H:i:s");
$b->module_fish_movement_id = $module_fish_movement->id;
$b->user_id = $user->id;
$b->save();
//nesse caso uma fusao, insere somente a biometria e o registro de movimentação
$module_fish_movementItem->type = "fusion";
$module_fish_movementItem->save();
} else {
//insere o TANQUE
$module_fish_lots_distributionTank = ORM::for_table('module_fish_lots_distribution')->create();
$module_fish_lots_distributionTank->module_fish_lots_id = $module_fish_lots_distribution->module_fish_lots_id;
$module_fish_lots_distributionTank->module_fish_tank_id = _post("tank_" . $row[$i]);
$module_fish_lots_distributionTank->qty = _post("qty_" . $row[$i]);
$module_fish_lots_distributionTank->created_at = date("Y-m-d H:i:s");
$module_fish_lots_distributionTank->module_fish_movement_id = $module_fish_movement->id;
$module_fish_lots_distributionTank->save();
$b = ORM::for_table('module_fish_lots_distribution_biometry')->create();
$b->module_fish_lots_distribution_id = $module_fish_lots_distributionTank->id;
$b->date = _postDate("date");
$b->average_weight = (Finance::amount_fix(_post("weight_" . $row[$i])) / 1000);
$b->created_at = $module_fish_lots_distributionTank->created_at;
$b->module_fish_movement_id = $module_fish_movement->id;
$b->user_id = $user->id;
$b->save();
$p = ORM::for_table('module_fish_lots_distribution_program')->create();
$p->module_fish_lots_distribution_id = $module_fish_lots_distributionTank->id;
$p->date = _postDate("date");
$p->module_fish_program_id = _post("program_" . $row[$i]);
$p->created_at = $module_fish_lots_distributionTank->created_at;
$p->save();
//nesse caso, cria todo o povoamento com os dados da movimentação
$module_fish_movementItem->type = "division";
$module_fish_movementItem->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 listMovement() {
$filter = array();
$filter['items_per_page'] = 10;
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$filter['crm_accounts_id'] = filter_var(_post('crm_accounts_id'), FILTER_SANITIZE_STRING);
$filter['module_fish_lots_id'] = filter_var(_post('module_fish_lots_id'), FILTER_SANITIZE_STRING);
$filter['period_ini'] = filter_var(_post('period_ini'), FILTER_SANITIZE_STRING);
$filter['period_end'] = filter_var(_post('period_end'), FILTER_SANITIZE_STRING);
$filter['period_create_ini'] = filter_var(_post('period_create_ini'), FILTER_SANITIZE_STRING);
$filter['period_create_end'] = filter_var(_post('period_create_end'), FILTER_SANITIZE_STRING);
$filter['items_per_page'] = filter_var(_post('items_per_page'), FILTER_SANITIZE_STRING);
} else {
if ($i = array_search('crm_accounts_id', $this->routes))
$filter['crm_accounts_id'] = filter_var($this->routes[$i + 1], FILTER_SANITIZE_NUMBER_INT);
if ($i = array_search('module_fish_lots_id', $this->routes))
$filter['module_fish_lots_id'] = filter_var($this->routes[$i + 1], FILTER_SANITIZE_STRING);
if ($i = array_search('period_create_ini', $this->routes))
$filter['period_create_ini'] = filter_var($this->routes[$i + 1], FILTER_SANITIZE_STRING);
if ($i = array_search('period_create_end', $this->routes))
$filter['period_create_end'] = filter_var($this->routes[$i + 1], FILTER_SANITIZE_STRING);
if ($i = array_search('period_ini', $this->routes))
$filter['period_ini'] = filter_var($this->routes[$i + 1], FILTER_SANITIZE_STRING);
if ($i = array_search('period_end', $this->routes))
$filter['period_end'] = filter_var($this->routes[$i + 1], FILTER_SANITIZE_STRING);
if ($i = array_search('items_per_page', $this->routes))
$filter['items_per_page'] = filter_var($this->routes[$i + 1], FILTER_SANITIZE_STRING);
}
$sql = 'Select l.title_lote,m.*,t.title_tank,'
. ' (select sub_i.type from module_fish_movement_itens sub_i where sub_i.module_fish_movement_id=m.id limit 1) as type';
$from = ' from module_fish_movement m '
. ' LEFT JOIN module_fish_lots_distribution ld ON(ld.id=m.module_fish_lots_distribution_id)'
. ' LEFT JOIN module_fish_lots l ON(ld.module_fish_lots_id=l.id)'
. ' LEFT JOIN module_fish_tank t ON(ld.module_fish_tank_id=t.id)'
. " WHERE m.deleted_at IS NULL ";
$where = "";
// Filtro por períodos
if (isset($filter['period_ini']) && $filter['period_ini'] != '')
$where .= " AND m.date>= '" . implode('-', array_reverse(explode('/', $filter['period_ini']))) .
"'";
if (isset($filter['period_end']) && $filter['period_end'] != '')
$where .= " AND m.date<= '" . implode('-', array_reverse(explode('/', $filter['period_end']))) . " 23:59:59" .
"'";
if (isset($filter['period_create_ini']) && $filter['period_create_ini'] != '')
$where .= " AND m.created_at>= '" . implode('-', array_reverse(explode('/', $filter['period_create_ini']))) .
"'";
if (isset($filter['period_create_end']) && $filter['period_create_end'] != '')
$where .= " AND m.created_at<= '" . implode('-', array_reverse(explode('/', $filter['period_create_end']))) . " 23:59:59" .
"'";
if (isset($filter['module_fish_lots_id']) && $filter['module_fish_lots_id'] != '') {
$where .= " AND l.id=" . intval($filter['module_fish_lots_id']);
$this->ui->assign('lote', ORM::for_table('module_fish_lots')->find_one(intval($filter['module_fish_lots_id'])));
} else {
$this->ui->assign('lote', false);
}
if (isset($filter['crm_accounts_id']) && $filter['crm_accounts_id'] != '') {
$where .= " AND l.crm_accounts_id=".intval($filter['crm_accounts_id']);
$this->ui->assign('account',ORM::for_table('crm_accounts')->find_one(intval($filter['crm_accounts_id'])));
}else{
$this->ui->assign('account',false);
}
// verifido se é um cliente que está acessando
if($this->client_id > 0)
{
$where.=" AND l.crm_accounts_id ='" . $this->client_id . "'";
}
if ($filter['items_per_page'] != 'all')
$filter['items_per_page'] = ($filter['items_per_page'] > 0) ? $filter['items_per_page'] : 10;
$sql.=$from . $where . ' order by m.created_at desc';
$page = isset($this->routes['3']) ? $this->routes['3'] : 1;
$paginator = new ModulePaginator('module_fish_movement', $sql, $filter);
$records = $paginator->setItemsPerPage($filter['items_per_page'])
->setCurrentPageNumber($page)
->run();
$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',
'/../../../application/plugins/module_fish/assets/js/movement-list'
);
$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('formatDateHour', $this->config['df'] . " H:i:s");
$this->ui->assign('filter', $filter);
$this->ui->assign('movement', $records);
$this->ui->assign('paginator', $paginator);
$this->ui->assign('_st', $this->_L['Fish Description module']);
$this->ui->assign('_include', 'movement/list');
$this->ui->display('wrapper.tpl');
}
public function movementDetail() {
$this->id = $this->routes[3];
if (empty($this->routes[3]) || !is_numeric($this->routes[3])) {
die($this->_L['Id_Required']);
}
$dT = ORM::for_table('module_fish_movement')
->table_alias('m')
->select('m.*')
->select_expr('u.fullname as user_name')
->select_expr('t.title_tank,t.id as id_tank,ld.qty')
->select_expr('ld.id as lote_id,l.date_settlement,l.title_lote,ld.module_fish_lots_id')
->select('lp.module_fish_program_id')
->left_outer_join('sys_users', array('u.id', '=', 'm.user_id'), 'u')
->join('module_fish_lots_distribution', array('ld.id', '=', 'm.module_fish_lots_distribution_id'), 'ld')
->join('module_fish_lots', array('l.id', '=', 'ld.module_fish_lots_id'), 'l')
->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')
;
$dT->where('m.id', $this->id);
// verifido se é um cliente que está acessando
if($this->client_id > 0)
{
$dT->where('l.crm_accounts_id',$this->client_id );
}
$movement = $dT->find_many();
if (count($movement)==0) {
r2(U.($this->client_id>0?'client/':'') . 'module_fish/movement/listMovement/', 'e', $this->_L['Not_Found']);
}
$movement[0]->weight_actual = $this->modelProgram->weigthEstimatedProgram($movement[0]->date_settlement, $movement[0]->module_fish_program_id, $movement[0]->date,$movement[0]->lote_id);
$totalMovimented = $this->model->getTotalMovimentTankLote($movement[0]->lote_id, $movement[0]->id_tank, $movement[0]->created_at,$movement[0]->id); //verific todas as movimentações registradas anteriores a esse registro
//que foi o que havia registrado no sistema e mostrou de informaçaõ ao usuário
$movement[0]->qty = $movement[0]->qty + $totalMovimented;
$movement[0]->qty_out = 0;
$bio = ORM::for_table('module_fish_lots_distribution_biometry')
->where('module_fish_lots_distribution_id', $movement[0]->lote_id)
->where('module_fish_movement_id', $movement[0]->id)->find_one();
$movement[0]->biometry = count($bio) > 0 ? $bio->average_weight : 0;
$itens = ORM::for_table('module_fish_movement_itens')->where('module_fish_movement_id',$movement[0]->id)->find_many();
if (!$itens) {
r2(U.($this->client_id>0?'client/':'') . 'module_fish/movement/listMovement/', 'e', $this->_L['Not_Found']);
}
$movement[0]->average_weight_out = 0;
$movement[0]->total_average_weight = 0;
$movement[0]->total = 0;
$movement[0]->total_weight_movement=0;
for ($i = 0; $i < count($itens); $i++) {
$movement[0]->qty_out+=$itens[$i]->qty; //soma os totas de saida
$movement[0]->average_weight_out+=$itens[$i]->average_weight;
if ($itens[$i]->type == 'fusion' || $itens[$i]->type == 'division') {
$loteTank = ORM::for_table('module_fish_lots')
->table_alias('l')
->select('l.*')
->select_expr('t.title_tank,t.id as id_tank,ld.qty')
->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')
;
$loteTank->where('l.id', $movement[0]->module_fish_lots_id);
$loteTank->where('ld.module_fish_tank_id', $itens[$i]->module_fish_tank_id_destiny);
$itens[$i]->dataLote = $loteTank->find_many();
if (count($itens[$i]->dataLote) > 0) {
$itens[$i]->dataLote[0]->weight_actual = $this->modelProgram->weigthEstimatedProgram($itens[0]->dataLote[0]->date_settlement, $itens[0]->dataLote[0]->module_fish_program_id, $movement[0]->date,$itens[0]->dataLote[0]->lote_id);
$totalMovimented = $this->model->getTotalMovimentTankLote($itens[$i]->dataLote[0]->lote_id, $itens[0]->dataLote[0]->id_tank, $movement[0]->created_at, $movement[0]->id); //verific todas as movimentações registradas anteriores a esse registro
//que foi o que havia registrado no sistema e mostrou de informaçaõ ao usuário
$itens[$i]->dataLote[0]->qty = $itens[0]->dataLote[0]->qty + $totalMovimented;
$bio = ORM::for_table('module_fish_lots_distribution_biometry')
->where('module_fish_lots_distribution_id', $itens[0]->dataLote[0]->lote_id)
->where('module_fish_movement_id', $movement[0]->id)->find_one();
$itens[$i]->biometry = count($bio) > 0 ? $bio->average_weight : 0;
$movement[0]->total_weight_movement+=($itens[$i]->average_weight*$itens[$i]->qty);
}
}
if ($itens[$i]->type == 'fusion') {
$movement[0]->total_average_weight+=$itens[$i]->biometry;
$movement[0]->total+= $itens[$i]->dataLote[0]->qty;
$movement[0]->total_biomass+=$itens[$i]->biometry*($itens[$i]->qty+$itens[$i]->dataLote[0]->qty);
} else {
$movement[0]->total_average_weight+=$itens[$i]->average_weight;
$movement[0]->total_biomass+=$itens[$i]->average_weight*$itens[$i]->qty;
}
}
if (count($itens) > 0) {
$movement[0]->average_weight_out = $movement[0]->average_weight_out / count($itens);
$movement[0]->total_average_weight = ($movement[0]->total_average_weight + $movement[0]->biometry) / count($itens);
} else {
$movement[0]->average_weight_out = 0;
$movement[0]->total_average_weight = $movement[0]->biometry;
}
$movement[0]->total+= $movement[0]->qty;
$movement[0]->total_biomass+=$movement[0]['biometry']*($movement[0]['qty']-$movement[0]['qty_out']);
$css_arr = array(
'/../../../application/plugins/module_fish/assets/css/default');
$assets_css = Asset::css($css_arr);
$this->ui->assign('xheader', $assets_css);
$this->ui->assign('itens', $itens);
$this->ui->assign('movement', $movement[0]);
$this->ui->assign('_st', $this->_L['Fish Description module']);
$this->ui->assign('_include', 'movement/detail');
$this->ui->assign('formatDateHour', $this->config['df'] . " H:i:s");
$this->ui->display('wrapper.tpl');
}
public function delete(){
$this->data = $_POST;
if (empty($this->data['id']) || !is_numeric($this->data['id'])) {
r2(U.($this->client_id>0?'client/':'') . 'module_fish/movement/listMovement', 's', $this->_L['Not Found']);
}
$movement = $this->model->getOne($this->data['id']);
if (!$movement) {
r2(U.($this->client_id>0?'client/':'') . 'module_fish/movement/listMovement', 's', $this->_L['Not Found']);
}
$ld = ORM::for_table('module_fish_lots_distribution')->where('module_fish_movement_id',$movement->id)->find_many();
if(count($ld)>0){
for($i=0;$i<count($ld);$i++){
ORM::for_table('module_fish_lots_distribution_program')->where('module_fish_lots_distribution_id', $ld[$i]->id)->delete_many();
ORM::for_table('module_fish_lots_distribution')->where('id', $ld[$i]->id)->delete_many();
}
}
ORM::for_table('module_fish_lots_distribution_biometry')->where('module_fish_movement_id', $movement->id)->delete_many();
ORM::for_table('module_fish_lots_distribution')->where('module_fish_movement_id',$movement->id)->delete_many();
ORM::for_table('module_fish_movement_itens')->where('module_fish_movement_id',$movement->id)->delete_many();
$movement->delete();
r2(U.($this->client_id>0?'client/':'') . 'module_fish/movement/listMovement', 's', $this->_L['Module_Fish Moviementation Successfully Undone']);
}
public function listSales() {
// LISTAR SALES, Movement
$filter = array();
$filter['items_per_page'] = 10;
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_search'] = _post('search');
$_SESSION['filter_fish_period'] = _post('period');
if ($_SESSION['filter_fish_period'] == 'interval') {
$_SESSION['filter_fish_period_ini'] = _postDate('period_ini');
$_SESSION['filter_fish_period_end'] = _postDate('period_end');
} else {
$_SESSION['filter_fish_period_ini'] = '';
$_SESSION['filter_fish_period_end'] = '';
}
$filter['items_per_page'] = filter_var(_post('items_per_page'), FILTER_SANITIZE_STRING);
} else {
if ($i = array_search('items_per_page', $this->routes))
$filter['items_per_page'] = filter_var($this->routes[$i + 1], FILTER_SANITIZE_STRING);
}
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_period'])) {
$filter['period'] = $_SESSION['filter_fish_period'];
} else {
$filter['period'] = '';
}
if (isset($_SESSION['filter_fish_period_ini'])) {
$filter['period_ini'] = $_SESSION['filter_fish_period_ini'];
} else {
$filter['period_ini'] = '';
}
if (isset($_SESSION['filter_fish_period_end'])) {
$filter['period_end'] = $_SESSION['filter_fish_period_end'];
} else {
$filter['period_end'] = '';
}
$sql = 'Select distinct(m.id), m.* ,ca.account,s.popular_name, s.scientific_name'
. ',(select sum(qty) from module_fish_movement_itens sub_mi where sub_mi.module_fish_movement_id=m.id and sub_mi.type="sale") as qty '
. ',(select sum(average_weight) from module_fish_movement_itens sub_mi where sub_mi.module_fish_movement_id=m.id and sub_mi.type="sale") as average_weight '
. ',(select count(sub_mi.id) from module_fish_movement_itens sub_mi where sub_mi.module_fish_movement_id=m.id and sub_mi.type="sale") as total_itens ';
$from= ' from module_fish_movement m '
. ' LEFT JOIN module_fish_movement_itens mi ON(mi.module_fish_movement_id=m.id and mi.type="sale")'
. ' LEFT JOIN module_fish_lots_distribution ld ON(ld.id=m.module_fish_lots_distribution_id)'
. ' LEFT JOIN module_fish_lots l ON(ld.module_fish_lots_id=l.id)'
. ' LEFT JOIN crm_accounts ca ON(l.crm_accounts_id=ca.id)'
. ' LEFT JOIN module_fish_species s ON(l.module_fish_species_id=s.id)'
. " WHERE m.deleted_at IS NULL AND m.id IN (select sub_mi2.module_fish_movement_id from module_fish_movement_itens sub_mi2 where sub_mi2.type='sale') ";
$where = "";
// Filtro por períodos
if (isset($filter['period']) && $filter['period'] != '') {
if ($filter['period'] == 'all')
$where .= " AND m.date IS NOT NULL";
if ($filter['period'] == 'day')
$where .= " AND m.date = '" . date('Y-m-d') . "'";
if ($filter['period'] == 'week')
$where .= " AND WEEK( m.date) = WEEK('" . date('Y-m-d') . "')";
if ($filter['period'] == 'month')
$where .= " AND MONTH( m.date) = MONTH('" . date('Y-m-d') . "')";
if ($filter['period'] == 'interval'){
if ($filter['period_ini'] != ''){
$where .= " AND DATE(m.date) >= '" .$filter['period_ini']."'";
}
if ($filter['period_end'] != ''){
$where .= " AND DATE(m.date) <= '" .$filter['period_end']."'";
}
}
}
if (isset($filter['crm_accounts_id']) && $filter['crm_accounts_id'] != '') {
$where .= " AND l.crm_accounts_id IN (" . implode(',', $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);
}
// verifido se é um cliente que está acessando
if($this->client_id > 0)
{
$where.=" AND l.crm_accounts_id ='" . $this->client_id . "'";
}
if (isset($filter['module_fish_species_id']) && $filter['module_fish_species_id'] != '') {
$where .= " AND l.module_fish_species_id=".intval($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 ($filter['items_per_page'] != 'all')
$filter['items_per_page'] = ($filter['items_per_page'] > 0) ? $filter['items_per_page'] : 10;
$sql.=$from.$where.' order by ca.account asc, m.date DESC ';
$page = isset($this->routes['3']) ? $this->routes['3'] : 1;
$paginator = new ModulePaginator('module_fish_movement', $sql, $filter);
$records = $paginator->setItemsPerPage($filter['items_per_page'])
->setCurrentPageNumber($page)
->run();
$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/movement-sale-list'
);
$assets_css = Asset::css($css_arr);
$assets_js = Asset::js($js_arr);
$this->ui->assign('xheader', $assets_css);
$this->ui->assign('xfooter', $assets_js);
$graph['date']=array();
$graph['qty']=array();
$graph['biomass']=array();
$graph['sales_price']=array();
$total['qty']=0;
$total['biomass']=0;
$total['sales_price']=0;
$allRecords= ORM::for_table('module_fish_movement_itens')->raw_query($sql)->find_many();
foreach ($allRecords as $a){
$total['qty']+=$a->qty;
$total['biomass']+=$a->qty*($a->average_weight/$a->total_itens);
$total['sales_price']+=$a->sales_price;
if(isset($graph['qty'][date('Y-m-d',strtotime($a->date))])){
$graph['qty'][date('Y-m-d',strtotime($a->date))]+=$a->qty;
$graph['biomass'][date('Y-m-d',strtotime($a->date))]+=number_format(($a->qty*($a->average_weight/$a->total_itens)),3);
$graph['sales_price'][date('Y-m-d',strtotime($a->date))]+=number_format(($a->sales_price),2);
}else{
$graph['date'][date('Y-m-d',strtotime($a->date))]="'".date($this->config['df'],strtotime($a->date))."'";
$graph['qty'][date('Y-m-d',strtotime($a->date))]=$a->qty;
$graph['biomass'][date('Y-m-d',strtotime($a->date))]=number_format(($a->qty*($a->average_weight/$a->total_itens)),3);
$graph['sales_price'][date('Y-m-d',strtotime($a->date))]=number_format(($a->sales_price),2);
}
}
$bottomBar = array(
array('type' => 'float3', 'info' =>$this->_L['Module_Fish Biomass Total'] ." kg", 'value' => $total['biomass']),
array('type' => 'int', 'info' =>$this->_L['Module_Fish Total fish'] , 'value' =>$total['qty']),
array('type' => 'float', 'info' => $this->_L['Value']." ".$this->_L['Total'], 'value' => $total['sales_price'])
);
$this->ui->assign('bottomBar', $bottomBar);
$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'] . '\';
';
$this->ui->assign('jsvar', $jsvar
.showGraph($this->_L['Module_Fish Nº of fish sold'],$this->_L['Module_Fish Nº of fish sold'].$this->_L['Module_Fish / Day'], "graph_qty",$graph['qty'],$graph['date'])
.showGraph($this->_L['Module_Fish Biomass Sold'],$this->_L['Module_Fish Biomass Sold'].$this->_L['Module_Fish / Day'], "graph_biomass",$graph['biomass'],$graph['date'])
.showGraph($this->_L['Module_Fish Sales Value']." ".$this->config['currency_code'],$this->_L['Module_Fish Sales Value']." ".$this->config['currency_code']." ".$this->_L['Module_Fish / Day'], "graph_sales",$graph['sales_price'],$graph['date']));
$this->ui->assign('filter', $filter);
$this->ui->assign('sales', $records);
$this->ui->assign('paginator', $paginator);
$this->ui->assign('_st', $this->_L['Fish Description module']);
$this->ui->assign('_include', 'movement/sale');
$this->ui->display('wrapper.tpl');
}
}
function showGraph($title,$description, $identificador,$valueSeries,$listDay,$showBackground=false,$color="#2196f3"){
global $_L;
$series="{
name:'".$title."',
type:'line',
smooth:true,
color: [
'".$color."'
],".
($showBackground? "itemStyle: {normal: {areaStyle: {type: 'default'}}}," :"")
." data:[". implode(",", $valueSeries)."]
}";
return " $(function() { var ".$identificador."_opt = {
title : {
text:'".$description."',
subtext: ''
},
tooltip : {
trigger: 'axis'
},
legend: {
data:['".$title."']
},
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);
});";
}