| 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/dialogo/application/plugins/module_pcp/models/ |
Upload File : |
<?php
/**
*
*/
class ProductionSteps extends Model
{
/**
* To override the default naming behaviour and directly specify a table name
*
* @var string
*/
public static $_table = 'module_pcp_production_steps';
/**
* Associate to Equipament.
*
*/
public function equipaments()
{
return $this->has_many('EquipamentsSteps','equipament_id','id');
}
public static function ProductHasStruct($product_id) {
return Model::factory('ProductionSteps')->where('product_id', $product_id)->find_many();
}
public function getCost()
{
$result = 0;
$equipaments = Model::factory('EquipamentsSteps')->where('id_production_steps', $this->id)->find_many();
foreach ($equipaments as $equipament) {
$model = Model::factory('Equipament')->find_one($equipament->id_equipament);
$result = $result + (float)$model->production_cost;
}
return $result * $this->duration_time;
}
public function saveOrUpdate($params = null)
{
try {
$ids_equipaments = isset($_POST['ids_equipaments']) ? $_POST['ids_equipaments'] : array();
$equipaments = Model::factory('EquipamentsSteps')->where('id_production_steps', $this->id)->find_many();
if($this->id) {
$this->name = $params['name'];
$this->product_id = $params['product_id'];
$this->duration_time = $params['duration_time'];
$this->description = $params['description'];
$this->save();
} else {
$this->create_at = ib_today();
$this->save();
}
if(count($equipaments)) {
$equipaments->delete();
}
$arr_equipaments = $params['arr_equipaments'];
foreach ($arr_equipaments as $id_equipament) {
$model = Model::factory('EquipamentsSteps')->create();
$model->id_equipament = $id_equipament['id_equipament'];
$model->time = $id_equipament['time'];
$model->obs = $id_equipament['obs'];
$model->id_production_steps = $this->id;
$model->save();
}
// foreach ($ids_equipaments as $id_equipament) {
// $model = Model::factory('EquipamentsSteps')->create();
// $model->id_equipament = $id_equipament;
// $model->id_production_steps = $this->id;
// $model->save();
// }
return true;
} catch (Exception $e) {
// Roll back a transaction
die($e->getMessage());
return false;
}
}
}