public function lamPCBsmt(PartSMT $smtP, $CR, $alfaS, $zivot, $dt)
 {
     $piLC = $this->getLeadConfigValue($smtP->getLeadConfig());
     $h = 5;
     $delka = $smtP->getHeight();
     $sirka = $smtP->getWidth();
     $d = sqrt(pow($delka, 2) + pow($sirka, 2)) / 2;
     $alfaCC = $this->getPackageValue($smtP->getTCEPackage());
     $otepleni = $smtP->getTempDissipation();
     $y = Abs($alfaS * $dt - $alfaCC * ($dt + $otepleni)) * pow(10, -6);
     $nf = $piLC * 3.5 * pow($d / (0.65 * $h) * $y, -2.26);
     $asmt = $nf / $CR;
     $x = $zivot * 8760 / $asmt;
     if ($x <= 0.1) {
         $ecf = 0.13;
     } else {
         if ($x > 0.1 && $x <= 0.2) {
             $ecf = 0.15;
         } else {
             if ($x > 0.2 && $x <= 0.3) {
                 $ecf = 0.23;
             } else {
                 if ($x > 0.3 && $x <= 0.4) {
                     $ecf = 0.31;
                 } else {
                     if ($x > 0.4 && $x <= 0.5) {
                         $ecf = 0.41;
                     } else {
                         if ($x > 0.5 && $x <= 0.6) {
                             $ecf = 0.51;
                         } else {
                             if ($x > 0.6 && $x <= 0.7) {
                                 $ecf = 0.61;
                             } else {
                                 if ($x > 0.7 && $x <= 0.8) {
                                     $ecf = 0.68;
                                 } else {
                                     if ($x > 0.8 && $x <= 0.9) {
                                         $ecf = 0.76;
                                     } else {
                                         $ecf = 1;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $LamSMT = $ecf / $asmt;
     $LamSMT *= $smtP->getCnt();
     return $LamSMT;
 }
 /**
  * @Route("/editPCB/{id}", name="editPCB")
  * @Template()
  */
 public function editPCBAction($id)
 {
     $post = $this->get('request')->request;
     $mode = $post->get('mode');
     $formData = $post->get('formData');
     $objF = json_decode($formData);
     $obj = $objF->form;
     $em = $this->getDoctrine()->getManager();
     $servicePCB = $this->get('ikaros_pcbService');
     $serviceSystem = $this->get('ikaros_systemService');
     $pcb = $servicePCB->getItem($id);
     $system = $serviceSystem->getItem($pcb->getSystemID());
     $sEnv = $system->getEnvironment();
     $env = $servicePCB->getEnvironmentPcb();
     $piE = $env[0][$sEnv];
     $dt = $env[1][$sEnv];
     $servicePCB = $this->get('ikaros_pcbService');
     switch ($mode) {
         case 1:
             $pcb->setLabel($obj->Label);
             $pcb->setLifetime(intval($obj->Lifetime));
             //$eq = $servicePCB->getEquipmentTypeByID(intval($obj->EquipType));
             $m = $servicePCB->getMaterialByID(intval($obj->SubstrateMaterial));
             $pcb->setEquipType($obj->EquipType);
             $pcb->setSubstrateMaterial($m[0]['Description']);
             //prepocet STM
             $partsSmtToChange = $servicePCB->getActivePartsSmtByPcbID($id);
             $CR = $servicePCB->getEquipmentTypeByDesc($pcb->getEquipType())['Value'];
             $alfaS = $m[0]['Value'];
             $zivot = $pcb->getLifetime();
             $oldSumLams = 0;
             $newSumLams = 0;
             foreach ($partsSmtToChange as $part) {
                 $newLam = $servicePCB->lamPCBsmt($part, $CR, $alfaS, $zivot, $dt);
                 $oldSumLams += $part->getLam();
                 $newSumLams += $newLam;
                 $part->setLam($newLam);
             }
             $pcb->setSumLam($pcb->getSumLam() - $oldSumLams + $newSumLams);
             $system->setLam($system->getLam() - $oldSumLams + $newSumLams);
             break;
         case 2:
             $pcb->setQuality(intval($obj->Quality));
             $pcb->setLayers(intval($obj->Layers));
             $pcb->setSolderingPointAuto(intval($obj->SolderingPointAuto));
             $pcb->setSolderingPointHand(intval($obj->SolderingPointHand));
             $lambda = $servicePCB->lamPCBwire($pcb, $piE);
             $oldLam = $pcb->getLam();
             $system->setLam($system->getLam() - $oldLam + $lambda);
             $pcb->setSumLam($pcb->getSumLam() - $oldLam + $lambda);
             $pcb->setLam($lambda);
             break;
         case 3:
             $smtP = new PartSMT();
             $smtP->setLeadConfig($obj->LeadConfig);
             $smtP->setTCEPackage($obj->TCEPackage);
             $smtP->setCnt(intval($obj->Cnt));
             $smtP->setHeight(intval($obj->Height));
             $smtP->setWidth(intval($obj->Width));
             $smtP->setTempDissipation(intval($obj->TempDissipation));
             $smtP->setPCBID($pcb);
             $eq = $servicePCB->getEquipmentTypeByDesc($pcb->getEquipType());
             $m = $servicePCB->getMaterialByDesc($pcb->getSubstrateMaterial());
             $CR = $eq[0]['Value'];
             $alfaS = $m[0]['Value'];
             $zivot = $pcb->getLifetime();
             $LamSMT = $servicePCB->lamPCBsmt($smtP, $CR, $alfaS, $zivot, $dt);
             $smtP->setLam($LamSMT);
             $pcb->setSumLam($pcb->getSumLam() + $LamSMT);
             $system->setLam($system->getLam() + $LamSMT);
             break;
     }
     try {
         $em->persist($pcb);
         if ($mode == 1) {
             foreach ($partsSmtToChange as $part) {
                 $em->persist($part);
             }
         } else {
             if ($mode == 3) {
                 $em->persist($smtP);
             }
         }
         $em->persist($system);
     } catch (\Exception $e) {
         return new Response(json_encode(array('e' => $e)), 400, array('Content-Type' => 'application/json; charset=utf-8'));
     }
     $em->flush();
     if ($mode == 1) {
         $url = $this->generateUrl('detailPCB', array('id' => $pcb->getIDPCB()));
         return new Response(json_encode(array('url' => $url)), 200, array('Content-Type' => 'application/json; charset=utf-8'));
     } else {
         if ($mode == 3) {
             return new Response(json_encode(array('LeadConfig' => $smtP->getLeadConfig(), 'TCEPackage' => $smtP->getTCEPackage(), 'Cnt' => $smtP->getCnt(intval($obj->Cnt)), 'Height' => $smtP->getHeight(intval($obj->Height)), 'Width' => $smtP->getWidth(intval($obj->Width)), 'TempDissipation' => $smtP->getTempDissipation(intval($obj->TempDissipation)), 'Lam' => $LamSMT, 'idSmt' => $smtP->getIDPartSMT())), 200, array('Content-Type' => 'application/json; charset=utf-8'));
         }
     }
     return new Response(json_encode(array('Lam' => $pcb->getLam(), 'SumLam' => $pcb->getSumLam())), 200, array('Content-Type' => 'application/json; charset=utf-8'));
 }