<?php

//$forumla_lines = array(new pm_formula_line());
$forumla_ingredients = array(new pm_formula_ingredient());
$pm_formula_lines = array(new pm_formula_line());
$pm_formula_byproducts = array(new pm_formula_byproduct());
$pm_process_routing_lines = array(new pm_process_routing_line);
if (empty($$class->pm_recipe_material_header_id) && !empty($_GET['pm_recipe_header_id'])) {
 $$class->pm_recipe_header_id = $_GET['pm_recipe_header_id'];
 $pm_recipe_material_header_obj_x = pm_recipe_material_header::find_by_fieldVal(['pm_recipe_header_id' => $$class->pm_recipe_header_id ]);

 if ($pm_recipe_material_header_obj_x) {
  foreach ($$class->field_a as $f_k => $f_v) {
   if (property_exists($pm_recipe_material_header_obj_x[0], $f_v)) {
    $$class->$f_v = $pm_recipe_material_header_obj_x[0]->$f_v;
   }
  }
 }
 
}

if (!empty($$class->pm_recipe_header_id)) {
 $pm_recipe_all_obj_arr = pm_recipe_all_v::find_by_fieldVal(['pm_recipe_header_id' => $$class->pm_recipe_header_id]);
 if ($pm_recipe_all_obj_arr) {
  $pm_recipe_all_obj = $pm_recipe_all_obj_arr[0];
  $$class->recipe_name = $pm_recipe_all_obj->recipe_name;
  $$class->routing_name = $pm_recipe_all_obj->routing_name;
  $$class->formula_name = $pm_recipe_all_obj->formula_name;
  $$class->routing_description = $pm_recipe_all_obj->routing_description;
  $$class->formula_description = $pm_recipe_all_obj->formula_description;
  
  $forumla_ingredients = pm_formula_ingredient::find_all_by_formulaHeaderId($pm_recipe_all_obj->pm_formula_header_id);
  $pm_formula_lines = pm_formula_line::find_all_by_formulaHeaderId($pm_recipe_all_obj->pm_formula_header_id);
  $pm_formula_byproducts = pm_formula_byproduct::find_all_by_formulaHeaderId($pm_recipe_all_obj->pm_formula_header_id);
 }
 
 
 
}

if (!empty($$class->pm_recipe_header_id)) {
 $pm_process_routing_lines = pm_process_routing_line::find_allLine_byRecipeHeaderId($$class->pm_recipe_header_id);
}

if ($pm_recipe_material_line_object) {
 if(!empty($$class->pm_recipe_material_header_id)){
  $pm_recipe_material_line_object = pm_recipe_material_line::find_by_parent_id($$class->pm_recipe_material_header_id);
 }else{
  $pm_recipe_material_line_object = [new pm_recipe_material_line()];
 }
 
}



//pa($forumla_ingredients);

//$all_operation_objs = !empty($$class->org_id) ? pm_process_operation_header::find_by_fieldVal(['org_id' => $$class->org_id]) : pm_process_operation_header::find_all();

if (empty($$class->status)) {
 $$class->status = 'APPROVED';
}
?>

