Exemple #1
0
 /**
  * achat ht de l'année en cours par nature d'achat
  *
  * @param CompanyNature $cn
  * @param integer $year
  *
  * @return Ambigous <\Doctrine\ORM\mixed, mixed, multitype:,
  *         \Doctrine\DBAL\Driver\Statement, \Doctrine\Common\Cache\mixed>
  */
 public function achatHtByCompanyNatureInYear(CompanyNature $cn, $year)
 {
     $qb = $this->createQueryBuilder('b')->select('sum(b.balanceTtc - b.vat - b.stamp)')->join('b.nature', 'n')->join('b.monthlyBalance', 'm')->join('m.company', 'c')->where('n.id = :id')->andWhere('m.year = :year')->andWhere('(b.transactionStatus = :status1 OR b.transactionStatus = :status2)')->andWhere('c.id = :cid')->setParameter('id', $cn->getId())->setParameter('year', \intval($year))->setParameter('status1', Transaction::STATUS_DONE)->setParameter('status2', Transaction::STATUS_PENDING)->setParameter('cid', $cn->getCompany()->getId());
     $query = $qb->getQuery();
     $res = $query->getSingleScalarResult();
     if (null == $res) {
         $res = 0;
     }
     return $res;
 }
 protected function traceEntity(CompanyNature $cloneCompanyNature, CompanyNature $companyNature)
 {
     $curUser = $this->getSecurityTokenStorage()->getToken()->getUser();
     $trace = new Trace();
     $trace->setActionId($companyNature->getId());
     $trace->setActionType(Trace::AT_UPDATE);
     $trace->setUserId($curUser->getId());
     $trace->setCompanyId($companyNature->getCompany()->getId());
     $trace->setUserFullname($curUser->getFullName());
     if (!$this->hasRole('ROLE_SUPERADMIN')) {
         if (!$this->hasRole('ROLE_ADMIN')) {
             $trace->setUserType(Trace::UT_CLIENT);
         } else {
             $trace->setUserType(Trace::UT_ADMIN);
         }
     } else {
         $trace->setUserType(Trace::UT_SUPERADMIN);
     }
     $tableBegin = ': <br><table class="table table-bordered table-condensed table-hover table-striped">';
     $tableBegin .= '<thead><tr><th class="text-left">' . $this->translate('Entity.field') . '</th>';
     $tableBegin .= '<th class="text-left">' . $this->translate('Entity.oldVal') . '</th>';
     $tableBegin .= '<th class="text-left">' . $this->translate('Entity.newVal') . '</th></tr></thead><tbody>';
     $tableEnd = '</tbody></table>';
     $trace->setActionEntity(Trace::AE_NATURE);
     $trace->setActionId2($companyNature->getCompany()->getId());
     $trace->setActionEntity2(Trace::AE_COMPANY);
     $msg = '';
     if ($cloneCompanyNature->getLabel() != $companyNature->getLabel()) {
         $msg .= '<tr><td>' . $this->translate('CompanyNature.label.label') . '</td><td>';
         if ($cloneCompanyNature->getLabel() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneCompanyNature->getLabel();
         }
         $msg .= '</td><td>';
         if ($companyNature->getLabel() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $companyNature->getLabel();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneCompanyNature->getColor() != $companyNature->getColor()) {
         $msg .= '<tr><td>' . $this->translate('CompanyNature.color.label') . '</td><td>';
         if ($cloneCompanyNature->getColor() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneCompanyNature->getColor() . ' &nbsp; <span style="display:inline-block; background-color: ' . $cloneCompanyNature->getColor() . ';  border: 1px solid ' . $cloneCompanyNature->getColor() . '; width: 60px; height: 20px;"></span>&nbsp;';
         }
         $msg .= '</td><td>';
         if ($companyNature->getColor() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $companyNature->getColor() . ' &nbsp; <span style="display:inline-block; background-color: ' . $companyNature->getColor() . ';  border: 1px solid ' . $companyNature->getColor() . '; width: 60px; height: 20px;"></span>&nbsp;';
         }
         $msg .= '</td></tr>';
     }
     if ($msg != '') {
         $msg = $tableBegin . $msg . $tableEnd;
         $trace->setMsg($this->translate('CompanyNature.traceEdit', array('%companyNature%' => $companyNature->getLabel(), '%company%' => $companyNature->getCompany()->getCorporateName())) . $msg);
         $trace->setDtCrea(new \DateTime('now'));
         $em = $this->getEntityManager();
         $em->persist($trace);
         $em->flush();
     }
 }