AnonSec Shell
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/imobles/application/plugins/module_fish/models/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     

Current File : /home/lrsys/www/lrsys_apps/imobles/application/plugins/module_fish/models/FoodProgramsModel.php
<?php

include_once __DIR__ . "/../../../autoload/My_Model.php";
include_once __DIR__ . "/../factories/FoodProgramsFactory.php";

class FoodProgramsModel extends My_Model {

    /**
     * @var string
     */
    public $table = 'module_fish_food_programs';

    /**
     * @param array $data
     * @return bool|ORM
     */
    public function createFoodPrograms($data) {
        $foodPrograms = self::create();
        FoodProgramsFactory::create($data, $foodPrograms, true);
        $foodPrograms->save();

        return $foodPrograms;
    }

    /**
     * @param array $data
     * @param ORM $foodPrograms
     * @return bool|ORM
     */
    public function updateFoodPrograms($data, $foodPrograms) {
        ORM::for_table($this->table)->create($foodPrograms);
        FoodProgramsFactory::create($data, $foodPrograms);
        $foodPrograms->save();

        return $foodPrograms;
    }

    public function insertPeriod($data, $food) {
        ORM::for_table('module_fish_food_program_periods')->where('module_fish_food_programs_id', $food->id)->delete_many();
        for ($i = 0; $i < count($data['sys_item_id']); $i++) {
            $d = ORM::for_table('module_fish_food_program_periods')->create();
            $d->module_fish_food_programs_id = $food->id;
            $d->period = intval($data['period'][$i]);
            $d->period_total = intval($data['period_total'][$i]);
            $d->sys_item_id = intval($data['sys_item_id'][$i]);
            $d->number_deals = intval($data['number_deals'][$i]);
            $d->weight_of = intval($data['weight_of'][$i]) / 1000; //para guardar em KG
            $d->weight_up = intval($data['weight_up'][$i]) / 1000; //para guardar em KG
            $d->mortality_rate = intval($data['mortality_rate'][$i]);
            $d->biomass = Finance::amount_fix($data['biomass'][$i]);
            $d->pv = Finance::amount_fix($data['pv'][$i]);
            $d->gpd = intval($data['gpd'][$i]) / 1000;
            $d->consumption_day = Finance::amount_fix($data['consumption_day'][$i]);
            $d->tca = Finance::amount_fix($data['tca'][$i]);
            $d->created_at = $food->created_at;
            $d->save();
        }
    }

    /**
     * @param ORM $foodPrograms
     * @return bool|ORM
     */
    public function deleteFoodPrograms($foodPrograms) {
        ORM::for_table($this->table)->create($foodPrograms);

        $now = new DateTime('now', new DateTimeZone('America/Sao_Paulo'));

        $foodPrograms->deleted_at = $now->format('Y-m-d H:i:s');
        $foodPrograms->save();

        return $foodPrograms;
    }

//função que verifica o peso atual para o peixe de acordo com a data de povoamento e programa
    function weigthEstimatedProgram($dateStetlement, $moduleFishProgramId, $date, $lote_id) {
        //verifica o peso medio atual de acordo com o programa para a data atual
        $data_inicio = new DateTime($dateStetlement);
        $data_fim = new DateTime($date);
        $dateInterval = $data_inicio->diff($data_fim);
         if (strtotime($dateStetlement) <= strtotime($date)) {
            $periodo = ORM::for_table('module_fish_food_program_periods')
                    ->table_alias('pp')
                    ->select('pp.*')
                    ->where("module_fish_food_programs_id", $moduleFishProgramId)
                    ->where_raw('pp.period_total>=' . $dateInterval->days)
                    ->limit(1)
                    ->order_by_expr('pp.period_total ASC')
                    ->find_many();
            //PEGA O ultimo período do programa
            if (count($periodo) == 0) {
                $periodo = ORM::for_table('module_fish_food_program_periods')
                        ->table_alias('pp')
                        ->select('pp.*')
                        ->where("module_fish_food_programs_id", $moduleFishProgramId)
                        ->where_raw('pp.period_total<=' . $dateInterval->days)
                        ->limit(1)
                        ->order_by_expr('pp.period_total DESC')
                        ->find_many();
            }
            if (count($periodo) > 0) {
//            if ($periodo[0]->period_total <= $dateInterval->days) {
//                $weightActual = $periodo[0]->weight_up;
//            } else {
                //pega a media de peso inicial
//                $biom = ORM::for_table('module_fish_lots_distribution_biometry')
//                        ->table_alias('pp')
//                        ->select('pp.*')
//                        ->where("module_fish_lots_distribution_id", $lote_id)
//                        ->order_by_expr('pp.id desc')
//                        ->find_many();
               
                $weightActual = ((($periodo[0]->weight_up - $periodo[0]->weight_of) / $periodo[0]->period) * ($dateInterval->days-($periodo[0]->period_total-$periodo[0]->period))) + $periodo[0]->weight_of;
//            }
            } else {
                $weightActual = 0;
            }
        } else {
            $weightActual = 0;
        }
        return $weightActual;
    }

//função que calcula o peso médio veirficando o programa e a ultima biometria realizada
    function weigthEstimatedProgramLastBiometry($lote,$date="") {
        //verifica se o peso da biometria 

        $biom = ORM::for_table('module_fish_lots_distribution_biometry')
                ->table_alias('pp')
                ->select('pp.*')
                ->limit(1)
                ->where("pp.module_fish_lots_distribution_id", $lote->lote_id)
                ->where_raw(empty($date)?" 1=1":"pp.date<'".$date. "'")
                ->order_by_expr('pp.date desc')
                ->find_many();

        $diferecaBiometriaProgramDays = 0;
        //verifica se teve somente a primeira biometria, usa com base a estimativa do 
//        if (count($biom) == 1) {//somente a biometria inicial, pega somente o valor do programa hoje  
//            $weight_actual = $this->weigthEstimatedProgram($lote->date_settlement, $lote->module_fish_program_id, date('Y-m-d'), $lote->lote_id);
//        } else {

        $diferecaBiometriaProgramDays = $this->positionLoteProgram($lote->module_fish_program_id, $lote->date_settlement, $biom[0]->average_weight, $biom[0]->date);

        $weight_actual = $this->weigthEstimatedProgram($lote->date_settlement, $lote->module_fish_program_id, date('Y-m-d', strtotime($diferecaBiometriaProgramDays . ' days', strtotime(date('Y-m-d')))), $lote->lote_id);
//        }
        return array("weight_actual" => $weight_actual, 'diferecaBiometriaProgramDays' => $diferecaBiometriaProgramDays);
    }

    //função que calcula o peso médio veirficando o programa e a ultima biometria realizada
    function weigthEstimatedProgramFirstBiometry($lote, $date = "") {
        //verifica se o peso da biometria 

        $biom = ORM::for_table('module_fish_lots_distribution_biometry')
                ->table_alias('pp')
                ->select('pp.*')
                ->limit(1)
                ->where("pp.module_fish_lots_distribution_id", $lote->lote_id)
                ->order_by_expr('pp.date asc')
                ->find_many();

        $diferecaBiometriaProgramDays = 0;
        //verifica se teve somente a primeira biometria, usa com base a estimativa do 
//        if (count($biom) == 1) {//somente a biometria inicial, pega somente o valor do programa hoje  
//            $weight_actual = $this->weigthEstimatedProgram($lote->date_settlement, $lote->module_fish_program_id, date('Y-m-d'), $lote->lote_id);
//        } else {

        $diferecaBiometriaProgramDays = $this->positionLoteProgram($lote->module_fish_program_id, $lote->date_settlement, $biom[0]->average_weight, $biom[0]->date);
        if (empty($date)) {
            $date = date('Y-m-d');
        }
        $weight_actual = $this->weigthEstimatedProgram($lote->date_settlement, $lote->module_fish_program_id, date('Y-m-d', strtotime($diferecaBiometriaProgramDays . ' days', strtotime($date))), $lote->lote_id);
//        }
        return array("weight_actual" => $weight_actual, 'diferecaBiometriaProgramDays' => $diferecaBiometriaProgramDays);
    }

    function positionLoteProgram($module_fish_program_id, $date_settlement, $average_weight, $date_average_weight) {
        //se tem mais biometrias uso elas para gerar o novo valor

        $periodo = ORM::for_table('module_fish_food_program_periods')
                ->table_alias('pp')
                ->select('pp.*')
                ->where("pp.module_fish_food_programs_id", $module_fish_program_id)
                ->where_raw("(pp.weight_of<=" . $average_weight . " and pp.weight_up>=" . $average_weight . ")")
                ->order_by_expr('pp.period_total ASC')
                ->find_many();
        if (count($periodo) == 0) {
            //se nao encontrou pega o ultimo
            $periodo = ORM::for_table('module_fish_food_program_periods')
                    ->table_alias('pp')
                    ->select('pp.*')
                    ->where("pp.module_fish_food_programs_id", $module_fish_program_id)
                    ->limit(1)
                    ->order_by_expr('pp.period_total DESC') //pega o ultimo periodo cadastrado para o programa
                    ->find_many();
        }

        //pega o peso da primeira biometria
        //  $weight_inicial=$biom[count($biom)-1]->average_weight;


        $mediaDay = (($periodo[0]->weight_up - $periodo[0]->weight_of) / $periodo[0]->period);

        if ($mediaDay > 0) {
            //verifica desse periodo do programa, a media de peso por dia
            $numDayBiometry = ($periodo[0]->period_total - $periodo[0]->period + 1) + intval(($average_weight - $periodo[0]->weight_of) / $mediaDay);
        } else {
            $numDayBiometry = 0;
        }

        //descobre qual dia corresponde  o peso medio da biometria
        $data_inicio = new DateTime($date_settlement);
        $data_fim = new DateTime($date_average_weight);
        $dateInterval = $data_inicio->diff($data_fim);
        //aqui verifica qual seria o numero de dias, para a data da biometria
        return $numDayBiometry - $dateInterval->days;
    }

}

Anon7 - 2022
AnonSec Team