Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function savePriceAction($id, $type)
- {
- $items = $this->getRequest()->get('item-selection-container');
- $costingTitleId = $this->getRequest()->get('costing-type');
- $newCostingTitle = $this->getRequest()->get('new-costing-type');
- $job = $this->getDoctrine()->getRepository('UniversalJobBundle:Job')->find($id);
- if (is_null($job)) {
- throw $this->createNotFoundException('Job not found');
- }
- if(!is_null($newCostingTitle) && !$this->get('security.authorization_checker')->isGranted('ROLE_TYPE_EMPLOYEE') && !$this->get('security.authorization_checker')->isGranted('ROLE_TYPE_ADMIN')) {
- throw new AccessDeniedHttpException();
- }
- if ((is_null($newCostingTitle) && $costingTitleId == 0) || (!is_null($newCostingTitle) && $newCostingTitle == '') ) {
- $this->get('session')->getFlashBag()->set('error', 'Costing Title required.');
- return $this->redirect($this->generateUrl('UniversalJobBundle_add_price', array('id' => $job->getId(), 'type' => $type)));
- } else
- /** If correct matrix */
- if ( ($rowCount = count($items)) && ($columnCount = count($items[1])) ) {
- $em = $this->getDoctrine()->getManager();
- if (!is_null($newCostingTitle)) {
- $costingTitle = $this->getDoctrine()->getRepository('UniversalJobBundle:CostingTitle')->findOneBy(array('title' => $newCostingTitle));
- if (is_null($costingTitle)) {
- $costingTitle = new CostingTitle();
- $costingTitle->setTitle($newCostingTitle);
- $em->persist($costingTitle);
- $em->flush();
- }
- } else {
- $costingTitle = $this->getDoctrine()->getRepository('UniversalJobBundle:CostingTitle')->find($costingTitleId);
- }
- $priceType = ($type==='dubroom')?JobPrice::TYPE_DUBROOM:JobPrice::TYPE_STOCK;
- $data = $this->getDoctrine()->getRepository('UniversalJobBundle:RateCard')->find($priceType)->getMatrix();
- $user = $this->getUser();
- $percent = $this->getDoctrine()->getRepository('UniversalJobBundle:DubRoom')->getCurrentPercent();
- /** Fill job prices */
- for ($r = 1; $r < $rowCount; $r++) {
- for ($c = 1; $c < $columnCount; $c++) {
- if ($items[$r][$c] !== '') {
- if ($data[0][$c] === $items[0][$c] && $data[$r][0] === $items[$r][0]) {
- $jobPrice = new JobPrice($percent);
- $jobPrice->setType($priceType);
- $jobPrice->setDescription($items[$r][0] . '/' . $items[0][$c]);
- $jobPrice->setQuantity($items[$r][$c]);
- $jobPrice->setPrice($data[$r][$c]);
- $jobPrice->setJob($job);
- $jobPrice->setCostingTitle($costingTitle);
- $jobPrice->setSubmitter($user);
- $em->persist($jobPrice);
- } else {
- throw new \Exception('Wrong grid data');
- }
- }
- }
- }
- $em->flush();
- }
- return $this->redirect($this->generateUrl('UniversalJobBundle_job_view_price', array('id' => $job->getId())));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement