コード例 #1
0
ファイル: BuyController.php プロジェクト: sasedev/acf-expert
 protected function traceEntity(Buy $cloneBuy, Buy $buy)
 {
     $curUser = $this->getSecurityTokenStorage()->getToken()->getUser();
     $trace = new Trace();
     $trace->setActionId($buy->getId());
     $trace->setActionType(Trace::AT_UPDATE);
     $trace->setUserId($curUser->getId());
     $trace->setCompanyId($buy->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_BUY);
     $trace->setActionId2($buy->getMonthlyBalance()->getCompany()->getId());
     $trace->setActionEntity2(Trace::AE_COMPANY);
     $trace->setActionId3($buy->getMonthlyBalance()->getId());
     $trace->setActionEntity2(Trace::AE_MBPURCHASE);
     $msg = '';
     if ($cloneBuy->getNumber() != $buy->getNumber()) {
         $msg .= '<tr><td>' . $this->translate('Buy.number.label') . '</td><td>';
         if ($cloneBuy->getNumber() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneBuy->getNumberFormated();
         }
         $msg .= '</td><td>';
         if ($buy->getNumber() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $buy->getNumberFormated();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneBuy->getDtActivation() != $buy->getDtActivation()) {
         $msg .= '<tr><td>' . $this->translate('Buy.dtActivation.label') . '</td><td>';
         if ($cloneBuy->getDtActivation() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneBuy->getDtActivation()->format('Y-m-d');
         }
         $msg .= '</td><td>';
         if ($buy->getDtActivation() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $buy->getDtActivation()->format('Y-m-d');
         }
         $msg .= '</td></tr>';
     }
     if ($cloneBuy->getBill() != $buy->getBill()) {
         $msg .= '<tr><td>' . $this->translate('Buy.bill.label') . '</td><td>';
         if ($cloneBuy->getBill() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneBuy->getBill();
         }
         $msg .= '</td><td>';
         if ($buy->getBill() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $buy->getBill();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneBuy->getRelation() != $buy->getRelation()) {
         $msg .= '<tr><td>' . $this->translate('Buy.relation.label') . '</td><td>';
         if ($cloneBuy->getRelation() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneBuy->getRelation()->getLabel();
         }
         $msg .= '</td><td>';
         if ($buy->getRelation() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $buy->getRelation()->getLabel();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneBuy->getLabel() != $buy->getLabel()) {
         $msg .= '<tr><td>' . $this->translate('Buy.label.label') . '</td><td>';
         if ($cloneBuy->getLabel() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneBuy->getLabel();
         }
         $msg .= '</td><td>';
         if ($buy->getLabel() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $buy->getLabel();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneBuy->getDevise() != $buy->getDevise()) {
         $msg .= '<tr><td>' . $this->translate('Buy.devise.label') . '</td><td>';
         if ($cloneBuy->getDevise() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneBuy->getDevise();
         }
         $msg .= '</td><td>';
         if ($buy->getDevise() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $buy->getDevise();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneBuy->getConversionRate() != $buy->getConversionRate()) {
         $msg .= '<tr><td>' . $this->translate('Buy.conversionRate.label') . '</td><td>';
         if ($cloneBuy->getConversionRate() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneBuy->getConversionRate();
         }
         $msg .= '</td><td>';
         if ($buy->getConversionRate() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $buy->getConversionRate();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneBuy->getVat() != $buy->getVat()) {
         $msg .= '<tr><td>' . $this->translate('Buy.vat.label') . '</td><td>';
         if ($cloneBuy->getVat() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneBuy->getVat();
         }
         $msg .= '</td><td>';
         if ($buy->getVat() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $buy->getVat();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneBuy->getStamp() != $buy->getStamp()) {
         $msg .= '<tr><td>' . $this->translate('Buy.stamp.label') . '</td><td>';
         if ($cloneBuy->getStamp() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneBuy->getStamp();
         }
         $msg .= '</td><td>';
         if ($buy->getStamp() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $buy->getStamp();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneBuy->getBalanceTtc() != $buy->getBalanceTtc()) {
         $msg .= '<tr><td>' . $this->translate('Buy.balanceTtc.label') . '</td><td>';
         if ($cloneBuy->getBalanceTtc() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneBuy->getBalanceTtc();
         }
         $msg .= '</td><td>';
         if ($buy->getBalanceTtc() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $buy->getBalanceTtc();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneBuy->getBalanceNet() != $buy->getBalanceNet()) {
         $msg .= '<tr><td>' . $this->translate('Buy.balanceNet.label') . '</td><td>';
         if ($cloneBuy->getBalanceNet() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneBuy->getBalanceNet();
         }
         $msg .= '</td><td>';
         if ($buy->getBalanceNet() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $buy->getBalanceNet();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneBuy->getVatDevise() != $buy->getVatDevise()) {
         $msg .= '<tr><td>' . $this->translate('Buy.vatDevise.label') . '</td><td>';
         if ($cloneBuy->getVatDevise() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneBuy->getVatDevise();
         }
         $msg .= '</td><td>';
         if ($buy->getVatDevise() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $buy->getVatDevise();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneBuy->getStampDevise() != $buy->getStampDevise()) {
         $msg .= '<tr><td>' . $this->translate('Buy.stampDevise.label') . '</td><td>';
         if ($cloneBuy->getStampDevise() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneBuy->getStampDevise();
         }
         $msg .= '</td><td>';
         if ($buy->getStampDevise() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $buy->getStampDevise();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneBuy->getBalanceTtcDevise() != $buy->getBalanceTtcDevise()) {
         $msg .= '<tr><td>' . $this->translate('Buy.balanceTtcDevise.label') . '</td><td>';
         if ($cloneBuy->getBalanceTtcDevise() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneBuy->getBalanceTtcDevise();
         }
         $msg .= '</td><td>';
         if ($buy->getBalanceTtcDevise() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $buy->getBalanceTtcDevise();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneBuy->getBalanceNetDevise() != $buy->getBalanceNetDevise()) {
         $msg .= '<tr><td>' . $this->translate('Buy.balanceNetDevise.label') . '</td><td>';
         if ($cloneBuy->getBalanceNetDevise() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneBuy->getBalanceNetDevise();
         }
         $msg .= '</td><td>';
         if ($buy->getBalanceNetDevise() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $buy->getBalanceNetDevise();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneBuy->getVatInfo() != $buy->getVatInfo()) {
         $msg .= '<tr><td>' . $this->translate('Buy.vatInfo.label') . '</td><td>';
         if ($cloneBuy->getVatInfo() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $this->translate('Buy.vatInfo.' . $cloneBuy->getVatInfo());
         }
         $msg .= '</td><td>';
         if ($buy->getVatInfo() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $this->translate('Buy.vatInfo.' . $buy->getVatInfo());
         }
         $msg .= '</td></tr>';
     }
     if ($cloneBuy->getRegime() != $buy->getRegime()) {
         $msg .= '<tr><td>' . $this->translate('Buy.regime.label') . '</td><td>';
         if ($cloneBuy->getRegime() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $this->translate('Buy.regime.' . $cloneBuy->getRegime());
         }
         $msg .= '</td><td>';
         if ($buy->getRegime() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $this->translate('Buy.regime.' . $buy->getRegime());
         }
         $msg .= '</td></tr>';
     }
     if ($cloneBuy->getWithholding() != $buy->getWithholding()) {
         $msg .= '<tr><td>' . $this->translate('Buy.withholding.label') . '</td><td>';
         if ($cloneBuy->getWithholding() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneBuy->getWithholding()->getLabel();
         }
         $msg .= '</td><td>';
         if ($buy->getWithholding() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $buy->getWithholding()->getLabel();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneBuy->getPaymentType() != $buy->getPaymentType()) {
         $msg .= '<tr><td>' . $this->translate('Buy.paymentType.label') . '</td><td>';
         if ($cloneBuy->getPaymentType() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $this->translate('Transaction.paymentType.' . $cloneBuy->getPaymentType());
         }
         $msg .= '</td><td>';
         if ($buy->getPaymentType() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $this->translate('Transaction.paymentType.' . $buy->getPaymentType());
         }
         $msg .= '</td></tr>';
     }
     if ($cloneBuy->getDtPayment() != $buy->getDtPayment()) {
         $msg .= '<tr><td>' . $this->translate('Buy.dtPayment.label') . '</td><td>';
         if ($cloneBuy->getDtPayment() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneBuy->getDtPayment()->format('Y-m-d');
         }
         $msg .= '</td><td>';
         if ($buy->getDtPayment() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $buy->getDtActivation()->format('Y-m-d');
         }
         $msg .= '</td></tr>';
     }
     if ($cloneBuy->getAccount() != $buy->getAccount()) {
         $msg .= '<tr><td>' . $this->translate('Buy.account.label') . '</td><td>';
         if ($cloneBuy->getAccount() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneBuy->getAccount()->getLabel();
         }
         $msg .= '</td><td>';
         if ($buy->getAccount() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $buy->getAccount()->getLabel();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneBuy->getNature() != $buy->getNature()) {
         $msg .= '<tr><td>' . $this->translate('Buy.nature.label') . '</td><td>';
         if ($cloneBuy->getNature() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneBuy->getNature()->getLabel();
         }
         $msg .= '</td><td>';
         if ($buy->getNature() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $buy->getNature()->getLabel();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneBuy->getTransactionStatus() != $buy->getTransactionStatus()) {
         $msg .= '<tr><td>' . $this->translate('Buy.transactionStatus.label') . '</td><td>';
         if ($cloneBuy->getTransactionStatus() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $this->translate('Transaction.transactionStatus.' . $cloneBuy->getTransactionStatus());
         }
         $msg .= '</td><td>';
         if ($buy->getTransactionStatus() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $this->translate('Transaction.transactionStatus.' . $buy->getTransactionStatus());
         }
         $msg .= '</td></tr>';
     }
     if ($cloneBuy->getValidated() != $buy->getValidated()) {
         $msg .= '<tr><td>' . $this->translate('Buy.validated.label') . '</td><td>';
         if ($cloneBuy->getValidated() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $this->translate('Transaction.validated.' . $cloneBuy->getValidated());
         }
         $msg .= '</td><td>';
         if ($buy->getValidated() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $this->translate('Transaction.validated.' . $buy->getValidated());
         }
         $msg .= '</td></tr>';
     }
     if ($cloneBuy->getOtherInfos() != $buy->getOtherInfos()) {
         $msg .= '<tr><td>' . $this->translate('Buy.otherInfos.label') . '</td><td>';
         if ($cloneBuy->getOtherInfos() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneBuy->getOtherInfos();
         }
         $msg .= '</td><td>';
         if ($buy->getOtherInfos() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $buy->getOtherInfos();
         }
         $msg .= '</td></tr>';
     }
     if (\count(\array_diff($buy->getDocs()->toArray(), $cloneBuy->getDocs()->toArray())) != 0 || \count(\array_diff($cloneBuy->getDocs()->toArray(), $buy->getDocs()->toArray())) != 0) {
         $msg .= '<tr><td>' . $this->translate('Buy.docs.label') . '</td><td>';
         if (\count($cloneBuy->getDocs()) == 0) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= '<ul>';
             foreach ($cloneBuy->getDocs() as $doc) {
                 $msg .= '<li><a href="' . $this->generateUrl('_admin_doc_editGet', array('uid' => $doc->getId())) . '">' . $doc->getOriginalName() . '</a></li>';
             }
             $msg .= '<ul>';
         }
         $msg .= '</td><td>';
         if (\count($buy->getDocs()) == 0) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= '<ul>';
             foreach ($buy->getDocs() as $doc) {
                 $msg .= '<li><a href="' . $this->generateUrl('_admin_doc_editGet', array('uid' => $doc->getId())) . '">' . $doc->getOriginalName() . '</a></li>';
             }
             $msg .= '<ul>';
         }
         $msg .= '</td></tr>';
     }
     if ($msg != '') {
         $msg = $tableBegin . $msg . $tableEnd;
         $trace->setMsg($this->translate('Buy.traceEdit', array('%buy%' => $buy->getLabel(), '%mbpurchase%' => $buy->getMonthlyBalance()->getRef(), '%company%' => $buy->getCompany()->getCorporateName())) . $msg);
         $trace->setDtCrea(new \DateTime('now'));
         $em = $this->getEntityManager();
         $em->persist($trace);
         $em->flush();
     }
 }