public function executeGCessio(sfWebRequest $request) { $this->setLayout('gestio'); $this->IDS = $this->getUser()->getSessionPar('idS'); //Netegem cerca if ($request->getParameter('accio') == 'C') { $this->CERCA = $this->getUser()->setSessionPar('cerca', array('text' => '', 'select' => '')); $this->PAGINA = $this->getUser()->setSessionPar('pagina', 1); } $this->PAGINA = $this->getUser()->ParReqSesForm($request, 'PAGINA', 1); //Inicialitzem el formulari de cerca $this->CERCA = $this->getUser()->ParReqSesForm($request, 'cerca', array('text' => '', 'select' => '')); $this->FCerca = new CercaTextChoiceForm(); $this->FCerca->setChoice(array(1 => 'Cedit', 0 => 'Retornat')); $this->FCerca->bind($this->CERCA); $this->MODE = ""; $this->ERROR_OCUPAT = ""; $this->IDC = $request->getParameter('IDC', 0); if ($request->isMethod('POST') || $request->isMethod('GET')) { $accio = $request->getParameter('accio'); if ($request->hasParameter('BCERCA')) { $accio = ' '; } if ($request->hasParameter('BNOU_CESSIO')) { $accio = 'NC'; } if ($request->hasParameter('BESCULL_MATERIAL')) { $accio = 'EM'; } if ($request->hasParameter('B_SAVE_CESSIO')) { $accio = 'SC'; } if ($request->hasParameter('BDELETE_CESSIO')) { $accio = 'DC'; } if ($request->hasParameter('BSAVE_RETORN')) { $accio = 'SR'; } } switch ($accio) { case 'C': $this->getUser()->addLogAction('inside', 'gCessio'); $this->CERCA['select'] = 1; break; //Nova Cessió //Nova Cessió case 'NC': $this->FCessio = CessioPeer::inicialitza(0, $this->IDS); $this->MODE = 'NOU_CESSIO'; break; //Escull el material //Escull el material case 'EM': $RCESSIO = $request->getParameter('cessio'); $this->FCessio = CessioPeer::inicialitza($RCESSIO['cessio_id'], $this->IDS); $this->FCessio->bind($RCESSIO); if ($this->FCessio->isValid()) { $this->FCessio->save(); $this->LoadEscullMaterial($this->FCessio->getObject()); } else { $this->MODE = 'EDICIO_CESSIO'; $this->MISSATGE = array('Hi ha hagut algun error guardant la cessió'); } break; //Edita Cessio //Edita Cessio case 'EC': $this->FCessio = CessioPeer::inicialitza($this->IDC, $this->IDS); $this->MODE = 'EDICIO_CESSIO'; break; //Edita Retorn //Edita Retorn case 'ER': $this->FCessio = CessioPeer::inicialitza($this->IDC, $this->IDS, true); $OC = $this->FCessio->getObject(); if (!$OC->isNew()) { $OC->setRetornat(true); } $this->MODE = 'EDICIO_RETORN'; break; //Guarda cessió //Guarda cessió case 'SC': $RMATERIAL = $request->getParameter('material'); $RMATERIALNOINV = $request->getParameter('material_no_inventariat'); $this->FCessio = CessioPeer::inicialitza($this->IDC, $this->IDS); $ERROR = CessiomaterialPeer::update($RMATERIAL, $this->FCessio, $this->IDS); if (!empty($ERROR)) { $this->FCessio = CessioPeer::inicialitza($this->IDC, $this->IDS); $OCESSIO = $this->FCessio->getObject(); $this->LoadEscullMaterial($OCESSIO, $RMATERIAL, $RMATERIALNOINV, true); $this->MISSATGE = array(); foreach ($ERROR as $idM => $text) { $RET = MaterialPeer::OnOcupatMaterialHores($idM, $OCESSIO->getDatacessio(), $OCESSIO->getDataRetorn(), '00:00', '24:00', $this->IDS, null, null, null); foreach ($RET as $idM => $O) { if ($O instanceof Cessio) { $this->MISSATGE[] = 'El material ' . $text . ' està en ús a la cessió ' . $O->getNom(); } elseif ($O instanceof Horaris) { $this->MISSATGE[] = 'El material ' . $text . ' està en ús en activitats el dia ' . $O->getDia() . ' a les ' . $O->getHorainici(); } } } } else { if ($request->hasParameter('material_no_inventariat')) { $this->FCessio->getObject()->setMaterialNoInventariat($RMATERIALNOINV); $this->FCessio->getObject()->save(); } $this->getUser()->addLogAction($accio, 'gCessio', $this->FCessio->getObject()); myUser::addLogTimeline('alta', 'cessio', $this->getUser()->getSessionPar('idU'), $this->IDS, $this->FCessio->getObject()->getCessioId()); $this->MODE = 'FINALITZAT'; } break; //Esborra cessió //Esborra cessió case 'DC': $OC = CessioPeer::retrieveByPK($this->getUser()->getSessionPar('IDC')); $this->getUser()->addLogAction($accio, 'gCessio', $OC); myUser::addLogTimeline('baixa', 'cessio', $this->getUser()->getSessionPar('idU'), $this->IDS, $OC); $OC->setActiu(false)->save(); break; //Guarda retorn //Guarda retorn case 'SR': $RCESSIO = $request->getParameter('cessio'); $OCESSIO = CessioPeer::retrieveByPK($RCESSIO['cessio_id']); $this->FCessio = new CessiomaterialRetornForm($OCESSIO); $this->FCessio->bind($RCESSIO); if ($this->FCessio->isValid()) { $this->FCessio->save(); $this->getUser()->addLogAction($accio, 'gCessio', $this->FCessio->getObject()); myUser::addLogTimeline('retorn', 'cessio', $this->getUser()->getSessionPar('idU'), $this->IDS, $RCESSIO['cessio_id']); $this->redirect('gestio/gCessio?accio=C'); } $this->MODE = 'EDICIO_RETORN'; break; case 'PRINT': $OCESSIO = CessioPeer::retrieveByPK($request->getParameter('IDC')); $pdf = CessioPeer::printDocument($OCESSIO); $pdf->output(); return sfView::NONE; break; } $this->CESSIONS = CessioPeer::getCessions($this->PAGINA, $this->CERCA['select'], $this->CERCA['text'], $this->IDS); }