Ejemplo n.º 1
0
 /**
  * Add doc
  *
  * @param Doc $doc
  *
  * @return Docgroupfiscal
  */
 public function addDoc(Doc $doc)
 {
     $this->docs[] = $doc;
     $doc->addGroupfiscal($this);
     return $this;
 }
Ejemplo n.º 2
0
 /**
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
  */
 public function addPostAction()
 {
     if (!$this->hasRole('ROLE_SUPERADMIN')) {
         return $this->redirect($this->generateUrl('_admin_homepage'));
     }
     $urlFrom = $this->getReferer();
     if (null == $urlFrom || trim($urlFrom) == '') {
         return $this->redirect($this->generateUrl('_admin_company_addGet'));
     }
     $company = new Company();
     $companyNewForm = $this->createForm(CompanyNewTForm::class, $company);
     $request = $this->getRequest();
     $reqData = $request->request->all();
     if (isset($reqData['CompanyNewForm'])) {
         $companyNewForm->handleRequest($request);
         if ($companyNewForm->isValid()) {
             $em = $this->getEntityManager();
             $em->persist($company);
             $em->flush();
             if (null != $companyNewForm['clone']->getData()) {
                 $companyClone = $companyNewForm['clone']->getData();
                 $oldDocgroupaudits = $em->getRepository('AcfDataBundle:Docgroupaudit')->getAll($companyClone);
                 $docgroupauditsCloneArray = array();
                 foreach ($oldDocgroupaudits as $oldDocgroupaudit) {
                     $docgroupaudit = new Docgroupaudit();
                     $docgroupaudit->setCompany($company);
                     $docgroupaudit->setLabel($oldDocgroupaudit->getLabel());
                     $docgroupaudit->setOtherInfos($oldDocgroupaudit->getOtherInfos());
                     if (null != $oldDocgroupaudit->getParent()) {
                         $parentId = $oldDocgroupaudit->getParent()->getId();
                         $docgroupaudit->setParent($docgroupauditsCloneArray[$parentId]);
                     }
                     $docgroupauditsCloneArray[$oldDocgroupaudit->getId()] = $docgroupaudit;
                     $em->persist($docgroupaudit);
                 }
                 $oldDocgroupbanks = $em->getRepository('AcfDataBundle:Docgroupbank')->getAll($companyClone);
                 $docgroupbanksCloneArray = array();
                 foreach ($oldDocgroupbanks as $oldDocgroupbank) {
                     $docgroupbank = new Docgroupbank();
                     $docgroupbank->setCompany($company);
                     $docgroupbank->setLabel($oldDocgroupbank->getLabel());
                     $docgroupbank->setOtherInfos($oldDocgroupbank->getOtherInfos());
                     if (null != $oldDocgroupbank->getParent()) {
                         $parentId = $oldDocgroupbank->getParent()->getId();
                         $docgroupbank->setParent($docgroupbanksCloneArray[$parentId]);
                     }
                     $docgroupbanksCloneArray[$oldDocgroupbank->getId()] = $docgroupbank;
                     $em->persist($docgroupbank);
                 }
                 $oldDocgroupcomptables = $em->getRepository('AcfDataBundle:Docgroupcomptable')->getAll($companyClone);
                 $docgroupcomptablesCloneArray = array();
                 foreach ($oldDocgroupcomptables as $oldDocgroupcomptable) {
                     $docgroupcomptable = new Docgroupcomptable();
                     $docgroupcomptable->setCompany($company);
                     $docgroupcomptable->setLabel($oldDocgroupcomptable->getLabel());
                     $docgroupcomptable->setOtherInfos($oldDocgroupcomptable->getOtherInfos());
                     if (null != $oldDocgroupcomptable->getParent()) {
                         $parentId = $oldDocgroupcomptable->getParent()->getId();
                         $docgroupcomptable->setParent($docgroupcomptablesCloneArray[$parentId]);
                     }
                     $docgroupcomptablesCloneArray[$oldDocgroupcomptable->getId()] = $docgroupcomptable;
                     $em->persist($docgroupcomptable);
                 }
                 $oldDocgroupfiscals = $em->getRepository('AcfDataBundle:Docgroupfiscal')->getAll($companyClone);
                 $docgroupfiscalsCloneArray = array();
                 foreach ($oldDocgroupfiscals as $oldDocgroupfiscal) {
                     $docgroupfiscal = new Docgroupfiscal();
                     $docgroupfiscal->setCompany($company);
                     $docgroupfiscal->setLabel($oldDocgroupfiscal->getLabel());
                     $docgroupfiscal->setOtherInfos($oldDocgroupfiscal->getOtherInfos());
                     if (null != $oldDocgroupfiscal->getParent()) {
                         $parentId = $oldDocgroupfiscal->getParent()->getId();
                         $docgroupfiscal->setParent($docgroupfiscalsCloneArray[$parentId]);
                     }
                     $docgroupfiscalsCloneArray[$oldDocgroupfiscal->getId()] = $docgroupfiscal;
                     $em->persist($docgroupfiscal);
                 }
                 $oldDocgrouppersos = $em->getRepository('AcfDataBundle:Docgroupperso')->getAll($companyClone);
                 $docgrouppersosCloneArray = array();
                 foreach ($oldDocgrouppersos as $oldDocgroupperso) {
                     $docgroupperso = new Docgroupperso();
                     $docgroupperso->setCompany($company);
                     $docgroupperso->setLabel($oldDocgroupperso->getLabel());
                     $docgroupperso->setOtherInfos($oldDocgroupperso->getOtherInfos());
                     if (null != $oldDocgroupperso->getParent()) {
                         $parentId = $oldDocgroupperso->getParent()->getId();
                         $docgroupperso->setParent($docgrouppersosCloneArray[$parentId]);
                     }
                     $docgrouppersosCloneArray[$oldDocgroupperso->getId()] = $docgroupperso;
                     $em->persist($docgroupperso);
                 }
                 $oldDocgroups = $em->getRepository('AcfDataBundle:Docgroup')->getAll($companyClone);
                 $docgroupsCloneArray = array();
                 foreach ($oldDocgroups as $oldDocgroup) {
                     $docgroup = new Docgroup();
                     $docgroup->setCompany($company);
                     $docgroup->setLabel($oldDocgroup->getLabel());
                     $docgroup->setOtherInfos($oldDocgroup->getOtherInfos());
                     if (null != $oldDocgroup->getParent()) {
                         $parentId = $oldDocgroup->getParent()->getId();
                         $docgroup->setParent($docgroupsCloneArray[$parentId]);
                     }
                     $docgroupsCloneArray[$oldDocgroup->getId()] = $docgroup;
                     $em->persist($docgroup);
                 }
                 $oldDocgroupsysts = $em->getRepository('AcfDataBundle:Docgroupsyst')->getAll($companyClone);
                 $docgroupsystsCloneArray = array();
                 foreach ($oldDocgroupsysts as $oldDocgroupsyst) {
                     $docgroupsyst = new Docgroupsyst();
                     $docgroupsyst->setCompany($company);
                     $docgroupsyst->setLabel($oldDocgroupsyst->getLabel());
                     $docgroupsyst->setOtherInfos($oldDocgroupsyst->getOtherInfos());
                     if (null != $oldDocgroupsyst->getParent()) {
                         $parentId = $oldDocgroupsyst->getParent()->getId();
                         $docgroupsyst->setParent($docgroupsystsCloneArray[$parentId]);
                     }
                     $docgroupsystsCloneArray[$oldDocgroupsyst->getId()] = $docgroupsyst;
                     $em->persist($docgroupsyst);
                 }
                 $em->flush();
                 $docDir = $this->getParameter('kernel.root_dir') . '/../web/res/docs';
                 $oldDocs = $em->getRepository('AcfDataBundle:Doc')->getAllByCompany($companyClone);
                 foreach ($oldDocs as $oldDoc) {
                     $oldFileName = $oldDoc->getFileName();
                     $fileName = sha1(uniqid(mt_rand(), true)) . '.' . $oldFileName;
                     $doc = new Doc();
                     $doc->setCompany($company);
                     $doc->setDescription($oldDoc->getDescription());
                     $doc->setNbrDownloads(0);
                     $doc->setSize($oldDoc->getSize());
                     $doc->setFileName($fileName);
                     $doc->setMimeType($oldDoc->getMimeType());
                     $doc->setMd5($oldDoc->getMd5());
                     $doc->setOriginalName($oldDoc->getOriginalName());
                     $doc->setFileName($fileName);
                     copy($docDir . '/' . $oldFileName, $docDir . '/' . $fileName);
                     foreach ($oldDoc->getGroupaudits() as $oldDocgroupaudit) {
                         $doc->addGroupaudit($docgroupauditsCloneArray[$oldDocgroupaudit->getId()]);
                     }
                     foreach ($oldDoc->getGroupbanks() as $oldDocgroupbank) {
                         $doc->addGroupbank($docgroupbanksCloneArray[$oldDocgroupbank->getId()]);
                     }
                     foreach ($oldDoc->getGroupcomptables() as $oldDocgroupcomptable) {
                         $doc->addGroupcomptable($docgroupcomptablesCloneArray[$oldDocgroupcomptable->getId()]);
                     }
                     foreach ($oldDoc->getGroupfiscals() as $oldDocgroupfiscal) {
                         $doc->addGroupfiscal($docgroupfiscalsCloneArray[$oldDocgroupfiscal->getId()]);
                     }
                     foreach ($oldDoc->getGrouppersos() as $oldDocgroupperso) {
                         $doc->addGroupperso($docgrouppersosCloneArray[$oldDocgroupperso->getId()]);
                     }
                     foreach ($oldDoc->getGroups() as $oldDocgroup) {
                         $doc->addGroup($docgroupsCloneArray[$oldDocgroup->getId()]);
                     }
                     foreach ($oldDoc->getGroupsysts() as $oldDocgroupsyst) {
                         $doc->addGroupsyst($docgroupsystsCloneArray[$oldDocgroupsyst->getId()]);
                     }
                     $em->persist($doc);
                 }
                 $em->flush();
             }
             $this->flashMsgSession('success', $this->translate('Company.add.success', array('%company%' => $company->getCorporateName())));
             return $this->redirect($this->generateUrl('_admin_company_editGet', array('uid' => $company->getId())));
         } else {
             $this->flashMsgSession('error', $this->translate('Company.add.failure'));
         }
     }
     $this->gvars['company'] = $company;
     $this->gvars['CompanyNewForm'] = $companyNewForm->createView();
     $sector = new Sector();
     $sectorNewForm = $this->createForm(SectorNewTForm::class, $sector);
     $this->gvars['sector'] = $sector;
     $this->gvars['SectorNewForm'] = $sectorNewForm->createView();
     $this->gvars['pagetitle'] = $this->translate('pagetitle.company.add');
     $this->gvars['pagetitle_txt'] = $this->translate('pagetitle.company.add.txt');
     $this->gvars['smenu_active'] = 'add';
     return $this->renderResponse('AcfAdminBundle:Company:add.html.twig', $this->gvars);
 }