public static function addEstimationCost($em, $parameters) { $estimation = $em->getRepository("RenovateMainBundle:Estimation")->find($parameters->estimationid); $cost = $em->getRepository("RenovateMainBundle:Cost")->find($parameters->costid); $estimationCost = new EstimationCost(); $estimationCost->setEstimationid($estimation->getId()); $estimationCost->setEstimation($estimation); $estimationCost->setCategoryType($cost->getCategory()->getType()); $estimationCost->setName($cost->getName()); $estimationCost->setUnits($cost->getUnits()); $estimationCost->setPrice($cost->getPrice()); $estimationCost->setCount(1); $estimationCost->setTotal($cost->getPrice()); $em->persist($estimationCost); $em->flush(); $estimationCost->getEstimation()->calculateAmount(); $em->persist($estimationCost->getEstimation()); $em->flush(); return $estimationCost; }
public static function copyEstimationById($em, $id) { $estimation = $em->getRepository("RenovateMainBundle:Estimation")->find($id); $estimationCopy = new Estimation(); $estimationCopy->setEstimationNumber($estimation->getEstimationNumber()); $estimationCopy->setContractNumber($estimation->getContractNumber()); $estimationCopy->setCustomer($estimation->getCustomer()); $estimationCopy->setPerformer($estimation->getPerformer()); $estimationCopy->setMaterialsAmount($estimation->getMaterialsAmount()); $estimationCopy->setWorksAmount($estimation->getWorksAmount()); $estimationCopy->setDiscount($estimation->getDiscount()); $estimationCopy->setTotalAmount($estimation->getTotalAmount()); $estimationCopy->setCreated(new \DateTime()); $estimationCopy->setUpdated(new \DateTime()); $em->persist($estimationCopy); $em->flush(); foreach ($estimation->getEstimationCosts() as $estimationCost) { $estimationCostCopy = new EstimationCost(); $estimationCostCopy->setEstimationid($estimationCopy->getId()); $estimationCostCopy->setEstimation($estimationCopy); $estimationCostCopy->setCategoryType($estimationCost->getCategoryType()); $estimationCostCopy->setName($estimationCost->getName()); $estimationCostCopy->setUnits($estimationCost->getUnits()); $estimationCostCopy->setPrice($estimationCost->getPrice()); $estimationCostCopy->setCount($estimationCost->getCount()); $estimationCostCopy->setTotal($estimationCost->getTotal()); $em->persist($estimationCostCopy); $em->flush(); } return $estimationCopy->getId(); }