예제 #1
0
 protected function traceEntity(Sale $cloneSale, Sale $sale)
 {
     $curUser = $this->getSecurityTokenStorage()->getToken()->getUser();
     $trace = new Trace();
     $trace->setActionId($sale->getId());
     $trace->setActionType(Trace::AT_UPDATE);
     $trace->setUserId($curUser->getId());
     $trace->setCompanyId($sale->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_SALE);
     $trace->setActionId2($sale->getMonthlyBalance()->getCompany()->getId());
     $trace->setActionEntity2(Trace::AE_COMPANY);
     $trace->setActionId3($sale->getMonthlyBalance()->getId());
     $trace->setActionEntity2(Trace::AE_MBSALE);
     $msg = '';
     if ($cloneSale->getNumber() != $sale->getNumber()) {
         $msg .= '<tr><td>' . $this->translate('Sale.number.label') . '</td><td>';
         if ($cloneSale->getNumber() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneSale->getNumberFormated();
         }
         $msg .= '</td><td>';
         if ($sale->getNumber() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $sale->getNumberFormated();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneSale->getDtActivation() != $sale->getDtActivation()) {
         $msg .= '<tr><td>' . $this->translate('Sale.dtActivation.label') . '</td><td>';
         if ($cloneSale->getDtActivation() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneSale->getDtActivation()->format('Y-m-d');
         }
         $msg .= '</td><td>';
         if ($sale->getDtActivation() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $sale->getDtActivation()->format('Y-m-d');
         }
         $msg .= '</td></tr>';
     }
     if ($cloneSale->getBill() != $sale->getBill()) {
         $msg .= '<tr><td>' . $this->translate('Sale.bill.label') . '</td><td>';
         if ($cloneSale->getBill() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneSale->getBill();
         }
         $msg .= '</td><td>';
         if ($sale->getBill() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $sale->getBill();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneSale->getRelation() != $sale->getRelation()) {
         $msg .= '<tr><td>' . $this->translate('Sale.relation.label') . '</td><td>';
         if ($cloneSale->getRelation() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneSale->getRelation()->getLabel();
         }
         $msg .= '</td><td>';
         if ($sale->getRelation() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $sale->getRelation()->getLabel();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneSale->getLabel() != $sale->getLabel()) {
         $msg .= '<tr><td>' . $this->translate('Sale.label.label') . '</td><td>';
         if ($cloneSale->getLabel() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneSale->getLabel();
         }
         $msg .= '</td><td>';
         if ($sale->getLabel() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $sale->getLabel();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneSale->getDevise() != $sale->getDevise()) {
         $msg .= '<tr><td>' . $this->translate('Sale.devise.label') . '</td><td>';
         if ($cloneSale->getDevise() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneSale->getDevise();
         }
         $msg .= '</td><td>';
         if ($sale->getDevise() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $sale->getDevise();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneSale->getConversionRate() != $sale->getConversionRate()) {
         $msg .= '<tr><td>' . $this->translate('Sale.conversionRate.label') . '</td><td>';
         if ($cloneSale->getConversionRate() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneSale->getConversionRate();
         }
         $msg .= '</td><td>';
         if ($sale->getConversionRate() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $sale->getConversionRate();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneSale->getVat() != $sale->getVat()) {
         $msg .= '<tr><td>' . $this->translate('Sale.vat.label') . '</td><td>';
         if ($cloneSale->getVat() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneSale->getVat();
         }
         $msg .= '</td><td>';
         if ($sale->getVat() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $sale->getVat();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneSale->getStamp() != $sale->getStamp()) {
         $msg .= '<tr><td>' . $this->translate('Sale.stamp.label') . '</td><td>';
         if ($cloneSale->getStamp() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneSale->getStamp();
         }
         $msg .= '</td><td>';
         if ($sale->getStamp() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $sale->getStamp();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneSale->getBalanceTtc() != $sale->getBalanceTtc()) {
         $msg .= '<tr><td>' . $this->translate('Sale.balanceTtc.label') . '</td><td>';
         if ($cloneSale->getBalanceTtc() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneSale->getBalanceTtc();
         }
         $msg .= '</td><td>';
         if ($sale->getBalanceTtc() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $sale->getBalanceTtc();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneSale->getBalanceNet() != $sale->getBalanceNet()) {
         $msg .= '<tr><td>' . $this->translate('Sale.balanceNet.label') . '</td><td>';
         if ($cloneSale->getBalanceNet() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneSale->getBalanceNet();
         }
         $msg .= '</td><td>';
         if ($sale->getBalanceNet() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $sale->getBalanceNet();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneSale->getVatDevise() != $sale->getVatDevise()) {
         $msg .= '<tr><td>' . $this->translate('Sale.vatDevise.label') . '</td><td>';
         if ($cloneSale->getVatDevise() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneSale->getVatDevise();
         }
         $msg .= '</td><td>';
         if ($sale->getVatDevise() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $sale->getVatDevise();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneSale->getStampDevise() != $sale->getStampDevise()) {
         $msg .= '<tr><td>' . $this->translate('Sale.stampDevise.label') . '</td><td>';
         if ($cloneSale->getStampDevise() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneSale->getStampDevise();
         }
         $msg .= '</td><td>';
         if ($sale->getStampDevise() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $sale->getStampDevise();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneSale->getBalanceTtcDevise() != $sale->getBalanceTtcDevise()) {
         $msg .= '<tr><td>' . $this->translate('Sale.balanceTtcDevise.label') . '</td><td>';
         if ($cloneSale->getBalanceTtcDevise() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneSale->getBalanceTtcDevise();
         }
         $msg .= '</td><td>';
         if ($sale->getBalanceTtcDevise() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $sale->getBalanceTtcDevise();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneSale->getBalanceNetDevise() != $sale->getBalanceNetDevise()) {
         $msg .= '<tr><td>' . $this->translate('Sale.balanceNetDevise.label') . '</td><td>';
         if ($cloneSale->getBalanceNetDevise() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneSale->getBalanceNetDevise();
         }
         $msg .= '</td><td>';
         if ($sale->getBalanceNetDevise() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $sale->getBalanceNetDevise();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneSale->getVatInfo() != $sale->getVatInfo()) {
         $msg .= '<tr><td>' . $this->translate('Sale.vatInfo.label') . '</td><td>';
         if ($cloneSale->getVatInfo() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $this->translate('Sale.vatInfo.' . $cloneSale->getVatInfo());
         }
         $msg .= '</td><td>';
         if ($sale->getVatInfo() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $this->translate('Sale.vatInfo.' . $sale->getVatInfo());
         }
         $msg .= '</td></tr>';
     }
     if ($cloneSale->getRegime() != $sale->getRegime()) {
         $msg .= '<tr><td>' . $this->translate('Sale.regime.label') . '</td><td>';
         if ($cloneSale->getRegime() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $this->translate('Sale.regime.' . $cloneSale->getRegime());
         }
         $msg .= '</td><td>';
         if ($sale->getRegime() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $this->translate('Sale.regime.' . $sale->getRegime());
         }
         $msg .= '</td></tr>';
     }
     if ($cloneSale->getWithholding() != $sale->getWithholding()) {
         $msg .= '<tr><td>' . $this->translate('Sale.withholding.label') . '</td><td>';
         if ($cloneSale->getWithholding() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneSale->getWithholding()->getLabel();
         }
         $msg .= '</td><td>';
         if ($sale->getWithholding() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $sale->getWithholding()->getLabel();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneSale->getPaymentType() != $sale->getPaymentType()) {
         $msg .= '<tr><td>' . $this->translate('Sale.paymentType.label') . '</td><td>';
         if ($cloneSale->getPaymentType() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $this->translate('Transaction.paymentType.' . $cloneSale->getPaymentType());
         }
         $msg .= '</td><td>';
         if ($sale->getPaymentType() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $this->translate('Transaction.paymentType.' . $sale->getPaymentType());
         }
         $msg .= '</td></tr>';
     }
     if ($cloneSale->getDtPayment() != $sale->getDtPayment()) {
         $msg .= '<tr><td>' . $this->translate('Sale.dtPayment.label') . '</td><td>';
         if ($cloneSale->getDtPayment() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneSale->getDtPayment()->format('Y-m-d');
         }
         $msg .= '</td><td>';
         if ($sale->getDtPayment() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $sale->getDtActivation()->format('Y-m-d');
         }
         $msg .= '</td></tr>';
     }
     if ($cloneSale->getAccount() != $sale->getAccount()) {
         $msg .= '<tr><td>' . $this->translate('Sale.account.label') . '</td><td>';
         if ($cloneSale->getAccount() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneSale->getAccount()->getLabel();
         }
         $msg .= '</td><td>';
         if ($sale->getAccount() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $sale->getAccount()->getLabel();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneSale->getNature() != $sale->getNature()) {
         $msg .= '<tr><td>' . $this->translate('Sale.nature.label') . '</td><td>';
         if ($cloneSale->getNature() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneSale->getNature()->getLabel();
         }
         $msg .= '</td><td>';
         if ($sale->getNature() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $sale->getNature()->getLabel();
         }
         $msg .= '</td></tr>';
     }
     if ($cloneSale->getTransactionStatus() != $sale->getTransactionStatus()) {
         $msg .= '<tr><td>' . $this->translate('Sale.transactionStatus.label') . '</td><td>';
         if ($cloneSale->getTransactionStatus() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $this->translate('Transaction.transactionStatus.' . $cloneSale->getTransactionStatus());
         }
         $msg .= '</td><td>';
         if ($sale->getTransactionStatus() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $this->translate('Transaction.transactionStatus.' . $sale->getTransactionStatus());
         }
         $msg .= '</td></tr>';
     }
     if ($cloneSale->getValidated() != $sale->getValidated()) {
         $msg .= '<tr><td>' . $this->translate('Sale.validated.label') . '</td><td>';
         if ($cloneSale->getValidated() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $this->translate('Transaction.validated.' . $cloneSale->getValidated());
         }
         $msg .= '</td><td>';
         if ($sale->getValidated() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $this->translate('Transaction.validated.' . $sale->getValidated());
         }
         $msg .= '</td></tr>';
     }
     if ($cloneSale->getOtherInfos() != $sale->getOtherInfos()) {
         $msg .= '<tr><td>' . $this->translate('Sale.otherInfos.label') . '</td><td>';
         if ($cloneSale->getOtherInfos() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $cloneSale->getOtherInfos();
         }
         $msg .= '</td><td>';
         if ($sale->getOtherInfos() == null) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= $sale->getOtherInfos();
         }
         $msg .= '</td></tr>';
     }
     if (\count(\array_diff($sale->getDocs()->toArray(), $cloneSale->getDocs()->toArray())) != 0 || \count(\array_diff($cloneSale->getDocs()->toArray(), $sale->getDocs()->toArray())) != 0) {
         $msg .= '<tr><td>' . $this->translate('Sale.docs.label') . '</td><td>';
         if (\count($cloneSale->getDocs()) == 0) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= '<ul>';
             foreach ($cloneSale->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($sale->getDocs()) == 0) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= '<ul>';
             foreach ($sale->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 (\count(\array_diff($sale->getSecondaryVats()->toArray(), $cloneSale->getSecondaryVats()->toArray())) != 0 || \count(\array_diff($cloneSale->getSecondaryVats()->toArray(), $sale->getSecondaryVats()->toArray())) != 0) {
         $msg .= '<tr><td>' . $this->translate('Sale.secondaryVats.label') . '</td><td>';
         if (\count($cloneSale->getSecondaryVats()) == 0) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= '<ul>';
             foreach ($cloneSale->getSecondaryVats() as $secondaryVat) {
                 $msg .= '<li><a href="' . $this->generateUrl('_admin_secondaryVat_editGet', array('uid' => $secondaryVat->getId())) . '">' . $secondaryVat->getVat() . '</a></li>';
             }
             $msg .= '<ul>';
         }
         $msg .= '</td><td>';
         if (\count($sale->getSecondaryVats()) == 0) {
             $msg .= '<span class="label label-warning">' . $this->translate('_NA') . '</span>';
         } else {
             $msg .= '<ul>';
             foreach ($sale->getSecondaryVats() as $secondaryVat) {
                 $msg .= '<li><a href="' . $this->generateUrl('_admin_secondaryVat_editGet', array('uid' => $secondaryVat->getId())) . '">' . $secondaryVat->getVat() . '</a></li>';
             }
             $msg .= '<ul>';
         }
         $msg .= '</td></tr>';
     }
     if ($msg != '') {
         $msg = $tableBegin . $msg . $tableEnd;
         $trace->setMsg($this->translate('Sale.traceEdit', array('%sale%' => $sale->getLabel(), '%mbsale%' => $sale->getMonthlyBalance()->getRef(), '%company%' => $sale->getCompany()->getCorporateName())) . $msg);
         $trace->setDtCrea(new \DateTime('now'));
         $em = $this->getEntityManager();
         $em->persist($trace);
         $em->flush();
     }
 }