/** * @Route("/newPCBA", name="newPCBAjax") * @Template() */ public function newPCBAjaxAction() { $post = $this->get('request')->request; $id = $post->get('id'); $wire = $post->get('wire'); $smt = $post->get('smt'); $formData = $post->get('formData'); $objF = json_decode($formData); $obj = $objF->form; if ($id == -1) { $id = intval($obj->system); } $em = $this->getDoctrine()->getManager(); $serviceSystem = $this->get('ikaros_systemService'); $servicePCB = $this->get('ikaros_pcbService'); $system = $serviceSystem->getItem($id); $sEnv = $system->getEnvironment(); $env = $servicePCB->getEnvironmentPcb(); $piE = $env[0][$sEnv]; $dt = $env[1][$sEnv]; $pcb = new PCB(); $pcb->setLabel($obj->Label); $pcb->setLifetime(intval($obj->Lifetime)); //$equipID = intval($obj->EquipType); //$eq = $servicePCB->getEquipmentTypeByID($equipID); $pcb->setEquipType($obj->EquipType); //$pcb->setEquipType($eq[0]['Description']); $matID = intval($obj->SubstrateMaterial); $m = $servicePCB->getMaterialByID($matID); $pcb->setSubstrateMaterial($m[0]['Description']); $CR = $servicePCB->getEquipmentTypeByDesc($pcb->getEquipType())['Value']; $alfaS = $m[0]['Value']; $lambda = 0; $LamSMT = 0; if ($wire == "true") { $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); $pcb->setLam($lambda); } if ($smt == "true") { $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); $zivot = $pcb->getLifetime(); $LamSMT = $servicePCB->lamPCBsmt($smtP, $CR, $alfaS, $zivot, $dt); $smtP->setLam($LamSMT); //$pcb->setSumLam($LamSMT); } $sumLam = $lambda + $LamSMT; if ($sumLam > 0) { $pcb->setSumLam($sumLam); $system->setLam($system->getLam() + $sumLam); } $pcb->setSystemID($system); try { $em->persist($pcb); if ($smt == "true") { $em->persist($smtP); } if ($sumLam > 0) { $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(); $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')); }