Advertisement
Guest User

Untitled

a guest
Jan 16th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. public function savePriceAction($id, $type)
  2. {
  3. $items = $this->getRequest()->get('item-selection-container');
  4. $costingTitleId = $this->getRequest()->get('costing-type');
  5. $newCostingTitle = $this->getRequest()->get('new-costing-type');
  6.  
  7. $job = $this->getDoctrine()->getRepository('UniversalJobBundle:Job')->find($id);
  8.  
  9. if (is_null($job)) {
  10. throw $this->createNotFoundException('Job not found');
  11. }
  12.  
  13. if(!is_null($newCostingTitle) && !$this->get('security.authorization_checker')->isGranted('ROLE_TYPE_EMPLOYEE') && !$this->get('security.authorization_checker')->isGranted('ROLE_TYPE_ADMIN')) {
  14. throw new AccessDeniedHttpException();
  15. }
  16.  
  17. if ((is_null($newCostingTitle) && $costingTitleId == 0) || (!is_null($newCostingTitle) && $newCostingTitle == '') ) {
  18. $this->get('session')->getFlashBag()->set('error', 'Costing Title required.');
  19.  
  20. return $this->redirect($this->generateUrl('UniversalJobBundle_add_price', array('id' => $job->getId(), 'type' => $type)));
  21. } else
  22. /** If correct matrix */
  23. if ( ($rowCount = count($items)) && ($columnCount = count($items[1])) ) {
  24.  
  25. $em = $this->getDoctrine()->getManager();
  26.  
  27. if (!is_null($newCostingTitle)) {
  28. $costingTitle = $this->getDoctrine()->getRepository('UniversalJobBundle:CostingTitle')->findOneBy(array('title' => $newCostingTitle));
  29.  
  30. if (is_null($costingTitle)) {
  31. $costingTitle = new CostingTitle();
  32. $costingTitle->setTitle($newCostingTitle);
  33.  
  34. $em->persist($costingTitle);
  35. $em->flush();
  36. }
  37. } else {
  38. $costingTitle = $this->getDoctrine()->getRepository('UniversalJobBundle:CostingTitle')->find($costingTitleId);
  39. }
  40.  
  41. $priceType = ($type==='dubroom')?JobPrice::TYPE_DUBROOM:JobPrice::TYPE_STOCK;
  42.  
  43. $data = $this->getDoctrine()->getRepository('UniversalJobBundle:RateCard')->find($priceType)->getMatrix();
  44. $user = $this->getUser();
  45. $percent = $this->getDoctrine()->getRepository('UniversalJobBundle:DubRoom')->getCurrentPercent();
  46.  
  47. /** Fill job prices */
  48. for ($r = 1; $r < $rowCount; $r++) {
  49. for ($c = 1; $c < $columnCount; $c++) {
  50. if ($items[$r][$c] !== '') {
  51. if ($data[0][$c] === $items[0][$c] && $data[$r][0] === $items[$r][0]) {
  52. $jobPrice = new JobPrice($percent);
  53. $jobPrice->setType($priceType);
  54. $jobPrice->setDescription($items[$r][0] . '/' . $items[0][$c]);
  55. $jobPrice->setQuantity($items[$r][$c]);
  56. $jobPrice->setPrice($data[$r][$c]);
  57. $jobPrice->setJob($job);
  58. $jobPrice->setCostingTitle($costingTitle);
  59. $jobPrice->setSubmitter($user);
  60.  
  61. $em->persist($jobPrice);
  62. } else {
  63. throw new \Exception('Wrong grid data');
  64. }
  65. }
  66. }
  67. }
  68.  
  69. $em->flush();
  70. }
  71.  
  72. return $this->redirect($this->generateUrl('UniversalJobBundle_job_view_price', array('id' => $job->getId())));
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement