| Server IP : 162.214.74.102 / Your IP : 216.73.217.80 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/public_html/lrsys_apps/leo/application/plugins/module_fish/models/ |
Upload File : |
<?php
include_once __DIR__ . "/../../../autoload/My_Model.php";
include_once __DIR__ . "/../factories/SettlementFactory.php";
class SettlementModel extends My_Model
{
/**
* @var string
*/
public $table = 'module_fish_lots';
/**
* @param array $data
* @return bool|ORM
*/
public function createSettlement($data)
{
$settlement = self::create();
SettlementFactory::create($data, $settlement, true);
$settlement->save();
return $settlement;
}
public function updateSettlement($data, $settlement)
{
ORM::for_table($this->table)->create($settlement);
SettlementFactory::create($data, $settlement);
$settlement->save();
return $settlement;
}
public function insertLot($data,$settlement){
for ($i=0; $i<count($data['qty']);$i++){
if (empty($data['lote_id'][$i])) {
$d = ORM::for_table('module_fish_lots_distribution')->create();
$d->created_at = $settlement->created_at;
$b = ORM::for_table('module_fish_lots_distribution_biometry')->create();
$b->created_at = $d->created_at;
$p = ORM::for_table('module_fish_lots_distribution_program')->create();
$p->created_at = $d->created_at;
} else {
$d = ORM::for_table('module_fish_lots_distribution')->find_one($data['lote_id'][$i]);
$d->updated_at = $settlement->updated_at;
$p = ORM::for_table('module_fish_lots_distribution_program')->find_one($data['module_fish_lots_distribution_program_id'][$i]);
$p->updated_at = $settlement->updated_at;
$biometry = ORM::for_table('module_fish_lots_distribution_biometry')->where("module_fish_lots_distribution_id", $data['lote_id'][$i])
->order_by_expr('id asc')->limit(1)->find_many();
$b = $biometry[0];
$b->updated_at = $settlement->updated_at;
}
//LOTS_DISTRIBUITION
$d->module_fish_lots_id = $settlement->id;
$d->module_fish_tank_id = $data['tank'][$i];
$d->qty = $data['qty'][$i];
$d->save();
//BIOMETRIA
$b->module_fish_lots_distribution_id = $d->id;
$b->date = $settlement->date_settlement;
$b->average_weight = (Finance::amount_fix($data['average_weight']) / 1000);
$b->save();
//PROGRAM
$p->module_fish_lots_distribution_id = $d->id;
$p->date = $settlement->date_settlement;
$p->module_fish_program_id = $data['program'][$i];
$p->save();
if(!empty($data['loteIdDeleted'])){
$delet= explode(',', $data['loteIdDeleted']);
foreach ($delet as $del){
if(!empty($del)){
$r = ORM::for_table('module_fish_lots_distribution')->find_one($del);
$movements = ORM::for_table('module_fish_movement')->where('module_fish_lots_distribution_id',$r->id)->find_many();
if(count($movements)==0){
$x = ORM::for_table('module_fish_lots_distribution_biometry')->where('module_fish_lots_distribution_id', $r->id)->delete_many();
$x = ORM::for_table('module_fish_lots_distribution_program')->where('module_fish_lots_distribution_id', $r->id)->delete_many();
$r->delete();
}
}
}
}
}
}
public function getAll($order = 'id', $byDeletedNull = false) {
$orm = ORM::for_table($this->table)
->table_alias('l')
->select('l.*')
->select('c.account')
->select('s.popular_name')
->select('s.scientific_name')
->join('crm_accounts', array('c.id', '=', 'l.crm_accounts_id'), 'c')
->join('module_fish_species', array('s.id', '=', 'l.module_fish_species_id'), 's')
->order_by_asc($order);
if ($byDeletedNull) {
$orm->where_null('l.deleted_at');
}
return $orm->find_many();
}
// /**
// * @param array $data
// * @param ORM $settlement
// * @return bool|ORM
// */
// public function updateSettlement($data, $settlement)
// {
// ORM::for_table($this->table)->create($settlement);
// SettlementFactory::create($data, $settlement);
// $settlement->save();
//
// return $settlement;
// }
// /**
// * @param ORM $tank
// * @return bool|ORM
// */
public function deleteTank($tank)
{
ORM::for_table($this->table)->create($tank);
$now = new DateTime('now', new DateTimeZone('America/Sao_Paulo'));
$tank->deleted_at = $now->format('Y-m-d H:i:s');
$tank->save();
return $tank;
}
}