浏览代码

Import des données prestashop

feature/export_comptable
Fab 4 年前
父节点
当前提交
693d3fdc81
共有 22 个文件被更改,包括 619 次插入352 次删除
  1. +0
    -8
      ShopBundle/Context/DocumentDeliveryNoteInterface.php
  2. +1
    -1
      ShopBundle/Context/DocumentInterface.php
  3. +0
    -8
      ShopBundle/Context/DocumentQuotationInterface.php
  4. +23
    -0
      ShopBundle/Controller/Frontend/CartController.php
  5. +12
    -14
      ShopBundle/Form/Backend/Common/AddressType.php
  6. +26
    -0
      ShopBundle/Form/Frontend/ReductionCartType.php
  7. +1
    -0
      ShopBundle/Model/Address.php
  8. +246
    -0
      ShopBundle/Model/Document.php
  9. +0
    -55
      ShopBundle/Model/DocumentDeliveryNote.php
  10. +0
    -56
      ShopBundle/Model/DocumentInvoice.php
  11. +0
    -73
      ShopBundle/Model/DocumentQuotation.php
  12. +33
    -53
      ShopBundle/Model/OrderShop.php
  13. +20
    -0
      ShopBundle/Model/Product.php
  14. +0
    -21
      ShopBundle/Repository/DocumentDeliveryNoteRepository.php
  15. +0
    -23
      ShopBundle/Repository/DocumentInvoiceRepository.php
  16. +0
    -23
      ShopBundle/Repository/DocumentQuotationRepository.php
  17. +23
    -0
      ShopBundle/Repository/DocumentRepository.php
  18. +19
    -6
      ShopBundle/Repository/OrderShopRepository.php
  19. +7
    -0
      ShopBundle/Repository/ReductionCartRepository.php
  20. +94
    -0
      ShopBundle/Services/DocumentUtils.php
  21. +50
    -9
      ShopBundle/Services/OrderUtils.php
  22. +64
    -2
      ShopBundle/Services/PriceUtils.php

+ 0
- 8
ShopBundle/Context/DocumentDeliveryNoteInterface.php 查看文件

@@ -1,8 +0,0 @@
<?php

namespace Lc\ShopBundle\Context;

interface DocumentDeliveryNoteInterface
{

}

ShopBundle/Context/DocumentInvoiceInterface.php → ShopBundle/Context/DocumentInterface.php 查看文件

@@ -2,7 +2,7 @@

namespace Lc\ShopBundle\Context;

interface DocumentInvoiceInterface
interface DocumentInterface
{

}

+ 0
- 8
ShopBundle/Context/DocumentQuotationInterface.php 查看文件

@@ -1,8 +0,0 @@
<?php

namespace Lc\ShopBundle\Context;

interface DocumentQuotationInterface
{

}

+ 23
- 0
ShopBundle/Controller/Frontend/CartController.php 查看文件

@@ -6,8 +6,11 @@ use App\Form\Frontend\OrderProductsType;
use Doctrine\ORM\EntityManagerInterface;
use Lc\ShopBundle\Context\MerchantUtilsInterface;
use Lc\ShopBundle\Context\OrderProductInterface;
use Lc\ShopBundle\Context\OrderReductionCartInterface;
use Lc\ShopBundle\Context\OrderUtilsInterface;
use Lc\ShopBundle\Context\ProductFamilyInterface;
use Lc\ShopBundle\Context\ReductionCartInterface;
use Lc\ShopBundle\Model\OrderReductionCart;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Security;
@@ -59,4 +62,24 @@ class CartController extends BaseController
return new JsonResponse($return) ;
}

public function deleteReductionCart($id)
{
$orderReductionCartRepository = $this->em->getRepository($this->em->getClassMetadata(OrderReductionCartInterface::class)->getName()) ;
$orderReductionCart = $orderReductionCartRepository->findOneById((int) $id) ;

$orderShop = $this->orderUtils->getCartCurrent() ;

if($orderReductionCart && $orderShop->getOrderReductionCarts() && $orderShop->getOrderReductionCarts()->contains($orderReductionCart)) {
$this->em->remove($orderReductionCart) ;
$this->em->flush() ;

$this->addFlash('success', 'La réduction a bien été supprimée de votre panier.') ;
}
else {
$this->addFlash('error', 'Une erreur est survenue lors de la suppression de la réduction. ') ;
}

return $this->redirectToRoute('frontend_order_cart') ;
}

}

+ 12
- 14
ShopBundle/Form/Backend/Common/AddressType.php 查看文件

@@ -44,20 +44,18 @@ class AddressType extends AbstractType
'Homme' => 0,
],
])
->add('lastname', TextType::class, ['label' => 'Nom', 'required' => false])
->add('firstname', TextType::class, ['label' => 'Prénom', 'required' => false])
->add('address', TextareaType::class, ['label' => 'Adresse'])
->add('zip', TextType::class, ['label' => 'Code postale'])
->add('city', TextType::class, ['label' => 'Ville'])
->add('country', TextType::class, ['label' => 'Pays'])
->add('phone', CollectionType::class, [
'entry_type'=>TextType::class,
'label' => 'Téléphone',
'required' => false
])
->add('company', TextType::class, ['label' => 'Entreprise', 'required' => false])
->add('siret', TextType::class, ['label' => 'SIRET', 'required' => false])
->add('tva', TextType::class, ['label' => 'Numéro TVA', 'required' => false]);

->add('lastname', TextType::class, ['required' => false])
->add('firstname', TextType::class, ['required' => false])
->add('address', TextareaType::class)
->add('zip', TextType::class)
->add('city', TextType::class)
->add('country', TextType::class)
->add('phone', TextType::class, ['required' => false])
->add('company', TextType::class, ['required' => false])
->add('siret', TextType::class, ['required' => false])
->add('tva', TextType::class, ['required' => false]);

}

public function configureOptions(OptionsResolver $resolver)

+ 26
- 0
ShopBundle/Form/Frontend/ReductionCartType.php 查看文件

@@ -0,0 +1,26 @@
<?php

namespace Lc\ShopBundle\Form\Frontend;

use Lc\ShopBundle\Validator\Constraints\UniqueEmailValidator;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class ReductionCartType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('code', TextType::class, [
'label' => 'Bon de réduction :'
]);
}

public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([

]);
}
}

+ 1
- 0
ShopBundle/Model/Address.php 查看文件

@@ -100,6 +100,7 @@ abstract class Address extends AbstractEntity
*/
protected $deliveryInfos;


public function __toString()
{
return $this->getTitle() . ' - ' . $this->getZip() . ' ' . $this->getCity();

+ 246
- 0
ShopBundle/Model/Document.php 查看文件

@@ -0,0 +1,246 @@
<?php

namespace Lc\ShopBundle\Model;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Lc\ShopBundle\Context\FilterMerchantInterface;

/**
* @ORM\MappedSuperclass()
*/
abstract class Document extends AbstractDocumentEntity implements FilterMerchantInterface
{
const TYPE_INVOICE = 'invoice' ;
const TYPE_QUOTATION = 'quotation' ;
const TYPE_PURCHASE_ORDER = 'purchase-order' ;
const TYPE_DELIVERY_NOTE = 'delivery-note' ;

/**
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\MerchantInterface")
* @ORM\JoinColumn(nullable=false)
*/
protected $merchant;

/**
* @ORM\Column(type="string", length=64)
*/
protected $type;

/**
* @ORM\Column(type="string", length=128, nullable=true)
*/
protected $reference;

/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
protected $logo;

/**
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\AddressInterface")
* @ORM\JoinColumn(nullable=false)
*/
protected $merchantAddress;

/**
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\AddressInterface")
* @ORM\JoinColumn(nullable=false)
*/
protected $buyerAddress;

/**
* @ORM\Column(type="text")
*/
protected $merchantAddressText;

/**
* @ORM\Column(type="text")
*/
protected $buyerAddressText;

/**
* @ORM\Column(type="text", nullable=true)
*/
protected $deliveryAddressText;

/**
* @ORM\Column(type="boolean", nullable=true)
*/
protected $isSent;

/**
* @ORM\ManyToMany(targetEntity="Lc\ShopBundle\Context\OrderShopInterface", mappedBy="documents")
*/
protected $orderShops;

public function __construct()
{
$this->orderShops = new ArrayCollection();
}

public function getMerchant(): ?Merchant
{
return $this->merchant;
}

public function setMerchant(?Merchant $merchant): self
{
$this->merchant = $merchant;

return $this;
}

public function getLabel()
{
if($this->getType() == self::TYPE_INVOICE) {
return 'Facture' ;
}
elseif($this->getType() == self::TYPE_QUOTATION) {
return 'Devis' ;
}
elseif($this->getType() == self::TYPE_PURCHASE_ORDER) {
return 'Bon de commande' ;
}
elseif($this->getType() == self::TYPE_DELIVERY_NOTE) {
return 'Bon de livraison' ;
}
}

public function getType(): ?string
{
return $this->type;
}

public function setType(string $type): self
{
$this->type = $type;

return $this;
}

public function getReference(): ?string
{
return $this->reference;
}

public function setReference(?string $reference): self
{
$this->reference = $reference;

return $this;
}

public function getLogo(): ?string
{
return $this->logo;
}

public function setLogo(string $logo): self
{
$this->logo = $logo;

return $this;
}

public function getMerchantAddress(): ?Address
{
return $this->merchantAddress;
}

public function setMerchantAddress(?Address $merchantAddress): self
{
$this->merchantAddress = $merchantAddress;

return $this;
}

public function getBuyerAddress(): ?Address
{
return $this->buyerAddress;
}

public function setBuyerAddress(?Address $buyerAddress): self
{
$this->buyerAddress = $buyerAddress;

return $this;
}

public function getMerchantAddressText(): ?string
{
return $this->merchantAddressText;
}

public function setMerchantAddressText(string $merchantAddressText): self
{
$this->merchantAddressText = $merchantAddressText;

return $this;
}

public function getBuyerAddressText(): ?string
{
return $this->buyerAddressText;
}

public function setBuyerAddressText(string $buyerAddressText): self
{
$this->buyerAddressText = $buyerAddressText;

return $this;
}

public function getDeliveryAddressText(): ?string
{
return $this->deliveryAddressText;
}

public function setDeliveryAddressText(?string $deliveryAddressText): self
{
$this->deliveryAddressText = $deliveryAddressText;

return $this;
}

public function getIsSent(): ?bool
{
return $this->isSent;
}

public function setIsSent(?bool $isSent): self
{
$this->isSent = $isSent;

return $this;
}

/**
* @return Collection|OrderShop[]
*/
public function getOrderShops(): Collection
{
return $this->orderShops;
}

public function addOrderShop(OrderShop $orderShop): self
{
if (!$this->orderShops->contains($orderShop)) {
$this->orderShops[] = $orderShop;
$orderShop->addDocument($this);
}

return $this;
}

public function removeOrderShop(OrderShop $orderShop): self
{
if ($this->orderShops->contains($orderShop)) {
$this->orderShops->removeElement($orderShop);
$orderShop->removeDocument($this);
}

return $this;
}
}

+ 0
- 55
ShopBundle/Model/DocumentDeliveryNote.php 查看文件

@@ -1,55 +0,0 @@
<?php

namespace Lc\ShopBundle\Model;

use Lc\ShopBundle\Model\OrderShop;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\MappedSuperclass()
*/
abstract class DocumentDeliveryNote extends AbstractDocumentOrder
{
/**
* @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\OrderShopInterface", mappedBy="documentDeliveryNote")
*/
protected $orderShops;

public function __construct()
{
$this->orderShops = new ArrayCollection();
}

/**
* @return Collection|OrderShop[]
*/
public function getOrderShops(): Collection
{
return $this->orderShops;
}

public function addOrderShop(OrderShop $orderShop): self
{
if (!$this->orderShops->contains($orderShop)) {
$this->orderShops[] = $orderShop;
$orderShop->setDocumentDeliveryNote($this);
}

return $this;
}

public function removeOrderShop(OrderShop $orderShop): self
{
if ($this->orderShops->contains($orderShop)) {
$this->orderShops->removeElement($orderShop);
// set the owning side to null (unless already changed)
if ($orderShop->getDocumentDeliveryNote() === $this) {
$orderShop->setDocumentDeliveryNote(null);
}
}

return $this;
}
}

+ 0
- 56
ShopBundle/Model/DocumentInvoice.php 查看文件

@@ -1,56 +0,0 @@
<?php

namespace Lc\ShopBundle\Model;

use Lc\ShopBundle\Model\OrderShop;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\MappedSuperclass()
*/
abstract class DocumentInvoice extends AbstractDocumentOrder
{
/**
* @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\OrderShopInterface", mappedBy="documentInvoice")
*/
protected $orderShops;

public function __construct()
{
$this->orderShops = new ArrayCollection();
}

/**
* @return Collection|OrderShop[]
*/
public function getOrderShops(): Collection
{
return $this->orderShops;
}

public function addOrderShop(OrderShop $orderShop): self
{
if (!$this->orderShops->contains($orderShop)) {
$this->orderShops[] = $orderShop;
$orderShop->setDocumentInvoice($this);
}

return $this;
}

public function removeOrderShop(OrderShop $orderShop): self
{
if ($this->orderShops->contains($orderShop)) {
$this->orderShops->removeElement($orderShop);
// set the owning side to null (unless already changed)
if ($orderShop->getDocumentInvoice() === $this) {
$orderShop->setDocumentInvoice(null);
}
}

return $this;
}

}

+ 0
- 73
ShopBundle/Model/DocumentQuotation.php 查看文件

@@ -1,73 +0,0 @@
<?php

namespace Lc\ShopBundle\Model;

use App\Entity\OrderShop;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\MappedSuperclass()
*/
abstract class DocumentQuotation extends AbstractDocumentOrder
{

/**
* @ORM\Column(type="integer", nullable=true)
*/
protected $duration;

/**
* @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\OrderShopInterface", mappedBy="documentQuotation")
*/
protected $orderShops;

public function __construct()
{
$this->orderShops = new ArrayCollection();
}

public function getDuration(): ?int
{
return $this->duration;
}

public function setDuration(?int $duration): self
{
$this->duration = $duration;

return $this;
}

/**
* @return Collection|OrderShop[]
*/
public function getOrderShops(): Collection
{
return $this->orderShops;
}

public function addOrderShop(OrderShop $orderShop): self
{
if (!$this->orderShops->contains($orderShop)) {
$this->orderShops[] = $orderShop;
$orderShop->setDocumentQuotation($this);
}

return $this;
}

public function removeOrderShop(OrderShop $orderShop): self
{
if ($this->orderShops->contains($orderShop)) {
$this->orderShops->removeElement($orderShop);
// set the owning side to null (unless already changed)
if ($orderShop->getDocumentQuotation() === $this) {
$orderShop->setDocumentQuotation(null);
}
}

return $this;
}
}

+ 33
- 53
ShopBundle/Model/OrderShop.php 查看文件

@@ -2,10 +2,10 @@

namespace Lc\ShopBundle\Model;

use App\Entity\Visitor;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Lc\ShopBundle\Context\DocumentInterface;
use Lc\ShopBundle\Context\FilterMerchantInterface;

/**
@@ -13,7 +13,6 @@ use Lc\ShopBundle\Context\FilterMerchantInterface;
*/
abstract class OrderShop extends AbstractEntity implements FilterMerchantInterface
{

/**
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\MerchantInterface", inversedBy="productFamilies")
* @ORM\JoinColumn(nullable=false)
@@ -65,21 +64,6 @@ abstract class OrderShop extends AbstractEntity implements FilterMerchantInterfa
*/
protected $creditHistories;

/**
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\DocumentInvoiceInterface", inversedBy="orderShops")
*/
protected $documentInvoice;

/**
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\DocumentQuotationInterface", inversedBy="orderShops")
*/
protected $documentQuotation;

/**
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\DocumentDeliveryNoteInterface", inversedBy="orderShops")
*/
protected $documentDeliveryNote;

/**
* @ORM\Column(type="text", nullable=true)
*/
@@ -101,6 +85,11 @@ abstract class OrderShop extends AbstractEntity implements FilterMerchantInterfa
*/
protected $orderReductionCredits;

/**
* @ORM\ManyToMany(targetEntity="Lc\ShopBundle\Context\DocumentInterface", inversedBy="orderShops")
*/
protected $documents;

public function __construct()
{
$this->orderStatusHistories = new ArrayCollection();
@@ -108,6 +97,7 @@ abstract class OrderShop extends AbstractEntity implements FilterMerchantInterfa
$this->creditHistories = new ArrayCollection();
$this->orderReductionCarts = new ArrayCollection();
$this->orderReductionCredits = new ArrayCollection();
$this->documents = new ArrayCollection();
}

public function getDateCreated()
@@ -299,42 +289,6 @@ abstract class OrderShop extends AbstractEntity implements FilterMerchantInterfa
return $this;
}

public function getDocumentInvoice(): ?DocumentInvoice
{
return $this->documentInvoice;
}

public function setDocumentInvoice(?DocumentInvoice $documentInvoice): self
{
$this->documentInvoice = $documentInvoice;

return $this;
}

public function getDocumentQuotation(): ?DocumentQuotation
{
return $this->documentQuotation;
}

public function setDocumentQuotation(?DocumentQuotation $documentQuotation): self
{
$this->documentQuotation = $documentQuotation;

return $this;
}

public function getDocumentDeliveryNote(): ?DocumentDeliveryNote
{
return $this->documentDeliveryNote;
}

public function setDocumentDeliveryNote(?DocumentDeliveryNote $documentDeliveryNote): self
{
$this->documentDeliveryNote = $documentDeliveryNote;

return $this;
}

public function getVisitor(): ?Visitor
{
return $this->visitor;
@@ -435,4 +389,30 @@ abstract class OrderShop extends AbstractEntity implements FilterMerchantInterfa
return $this;
}

/**
* @return Collection|Document[]
*/
public function getDocuments(): Collection
{
return $this->documents;
}

public function addDocument(Document $document): self
{
if (!$this->documents->contains($document)) {
$this->documents[] = $document;
}

return $this;
}

public function removeDocument(Document $document): self
{
if ($this->documents->contains($document)) {
$this->documents->removeElement($document);
}

return $this;
}

}

+ 20
- 0
ShopBundle/Model/Product.php 查看文件

@@ -37,6 +37,26 @@ abstract class Product extends AbstractEntity implements SortableInterface, Prod
$this->orderProducts = new ArrayCollection() ;
}

public function getBuyingPriceInherited()
{
if($this->getBuyingPrice()) {
return $this->getBuyingPrice();
}
else {
return $this->getProductFamily()->getBuyingPrice();
}
}

public function getBuyingPriceByRefUnitInherited()
{
if($this->getBuyingPriceByRefUnit()) {
return $this->getBuyingPriceByRefUnit();
}
else {
return $this->getProductFamily()->getBuyingPriceByRefUnit();
}
}

public function getPriceInherited()
{
if($this->getPrice()) {

+ 0
- 21
ShopBundle/Repository/DocumentDeliveryNoteRepository.php 查看文件

@@ -1,21 +0,0 @@
<?php

namespace Lc\ShopBundle\Repository;

use Lc\ShopBundle\Context\DefaultRepositoryInterface;
use Lc\ShopBundle\Context\DocumentDeliveryNoteInterface;

/**
* @method DocumentDeliveryNoteInterface|null find($id, $lockMode = null, $lockVersion = null)
* @method DocumentDeliveryNoteInterface|null findOneBy(array $criteria, array $orderBy = null)
* @method DocumentDeliveryNoteInterface[] findAll()
* @method DocumentDeliveryNoteInterface[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class DocumentDeliveryNoteRepository extends BaseRepository implements DefaultRepositoryInterface
{
public function getInterfaceClass()
{
return DocumentDeliveryNoteInterface::class;
}

}

+ 0
- 23
ShopBundle/Repository/DocumentInvoiceRepository.php 查看文件

@@ -1,23 +0,0 @@
<?php

namespace Lc\ShopBundle\Repository;

use App\Entity\DocumentInvoice;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Common\Persistence\ManagerRegistry;
use Lc\ShopBundle\Context\DefaultRepositoryInterface;
use Lc\ShopBundle\Context\DocumentInvoiceInterface;

/**
* @method DocumentInvoice|null find($id, $lockMode = null, $lockVersion = null)
* @method DocumentInvoice|null findOneBy(array $criteria, array $orderBy = null)
* @method DocumentInvoice[] findAll()
* @method DocumentInvoice[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class DocumentInvoiceRepository extends BaseRepository implements DefaultRepositoryInterface
{
public function getInterfaceClass()
{
return DocumentInvoiceInterface::class;
}
}

+ 0
- 23
ShopBundle/Repository/DocumentQuotationRepository.php 查看文件

@@ -1,23 +0,0 @@
<?php

namespace Lc\ShopBundle\Repository;

use App\Entity\DocumentQuotation;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Common\Persistence\ManagerRegistry;
use Lc\ShopBundle\Context\DefaultRepositoryInterface;
use Lc\ShopBundle\Context\DocumentQuotationInterface;

/**
* @method DocumentQuotation|null find($id, $lockMode = null, $lockVersion = null)
* @method DocumentQuotation|null findOneBy(array $criteria, array $orderBy = null)
* @method DocumentQuotation[] findAll()
* @method DocumentQuotation[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class DocumentQuotationRepository extends BaseRepository implements DefaultRepositoryInterface
{
public function getInterfaceClass()
{
return DocumentQuotationInterface::class;
}
}

+ 23
- 0
ShopBundle/Repository/DocumentRepository.php 查看文件

@@ -0,0 +1,23 @@
<?php

namespace Lc\ShopBundle\Repository;

use App\Entity\DocumentQuotation;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Common\Persistence\ManagerRegistry;
use Lc\ShopBundle\Context\DefaultRepositoryInterface;
use Lc\ShopBundle\Context\DocumentInterface;

/**
* @method Document|null find($id, $lockMode = null, $lockVersion = null)
* @method Document|null findOneBy(array $criteria, array $orderBy = null)
* @method Document[] findAll()
* @method Document[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class DocumentRepository extends BaseRepository implements DefaultRepositoryInterface
{
public function getInterfaceClass()
{
return DocumentInterface::class;
}
}

+ 19
- 6
ShopBundle/Repository/OrderShopRepository.php 查看文件

@@ -56,8 +56,10 @@ class OrderShopRepository extends BaseRepository implements DefaultRepositoryInt
$query->andWhere('e.visitor = :visitor')->setParameter('visitor', $params['visitor']) ;
}

$query->leftJoin('e.orderStatusHistories', 'orderStatusHistories')
->andWhere('SIZE(e.orderStatusHistories) = 0') ;
$this->filterOrderCart($query, true) ;

$query->leftJoin('e.orderReductionCarts', 'orderReductionCarts')
->addSelect('orderReductionCarts');

$results = $query->getQuery()->getResult() ;

@@ -81,7 +83,7 @@ class OrderShopRepository extends BaseRepository implements DefaultRepositoryInt
}

if(!isset($params['isCart'])) {
$query = $this->filterOrderCart($query) ;
$this->filterOrderCart($query) ;
}

if(isset($params['user'])) {
@@ -103,14 +105,25 @@ class OrderShopRepository extends BaseRepository implements DefaultRepositoryInt

$this->filterOrderCart($query) ;

$query->leftJoin('e.deliveryAvailabilityZone', 'deliveryAvailabilityZone') ;
$query->leftJoin('deliveryAvailabilityZone.deliverySlot', 'deliverySlotZone') ;
$query->addOrderBy('deliverySlotZone.day', 'ASC') ;
$query->addOrderBy('deliverySlotZone.timeStart', 'ASC') ;

$query->leftJoin('e.deliveryAvailabilityPointSale', 'deliveryAvailabilityPointSale') ;
$query->leftJoin('deliveryAvailabilityPointSale.deliverySlot', 'deliverySlotPointSale') ;
$query->addOrderBy('deliverySlotPointSale.day', 'ASC') ;
$query->addOrderBy('deliverySlotPointSale.timeStart', 'ASC') ;

return $query->getQuery()->getResult() ;
}

public function filterOrderCart($query, $isCart = false)
{
$operator = $isCart ? '=' : '>' ;
return $query->leftJoin('e.orderStatusHistories', 'orderStatusHistories')
->andWhere('SIZE(e.orderStatusHistories) '.$operator.' 0') ;
$operator = $isCart ? '=' : '!=' ;
return $query->leftJoin('e.orderStatus', 'orderStatus')
->andWhere('orderStatus.alias '.$operator.' :orderStatus')
->setParameter('orderStatus', 'cart');
}

//getValidOrders()

+ 7
- 0
ShopBundle/Repository/ReductionCartRepository.php 查看文件

@@ -18,6 +18,13 @@ class ReductionCartRepository extends BaseRepository implements DefaultRepositor
return ReductionCartInterface::class;
}

public function findOneByCode($code)
{
$query = $this->findByMerchantQuery() ;
$query->andWhere('e.codes LIKE :code')->setParameter('code', '%'.$code.'%') ;
return $query->getQuery()->getOneOrNullResult() ;
}

public function getValuesOfFieldType(){
$query = $this->findByMerchantQuery() ;
$query->select('DISTINCT e.type');

+ 94
- 0
ShopBundle/Services/DocumentUtils.php 查看文件

@@ -0,0 +1,94 @@
<?php

namespace Lc\ShopBundle\Services ;

use Doctrine\ORM\EntityManagerInterface;
use Lc\ShopBundle\Context\DocumentInterface;
use Lc\ShopBundle\Context\MerchantUtilsInterface;
use Lc\ShopBundle\Model\Document ;

class DocumentUtils
{
protected $em ;
protected $merchantUtils ;
protected $documentRepository ;

public function __construct(EntityManagerInterface $em, MerchantUtilsInterface $merchantUtils)
{
$this->em = $em ;
$this->documentRepository = $this->em->getRepository($this->em->getClassMetadata(DocumentInterface::class)->getName()) ;
$this->merchantUtils = $merchantUtils ;
}

public function generateReference($documentType)
{
$prefix = '';
if($documentType == Document::TYPE_DELIVERY_NOTE) {
$prefix = 'BL';
}
elseif($documentType == Document::TYPE_PURCHASE_ORDER) {
$prefix = 'BC';
}
elseif($documentType == Document::TYPE_INVOICE) {
$prefix = 'FA';
}
elseif($documentType == Document::TYPE_QUOTATION) {
$prefix = 'DE';
}

$oneDocumentExist = $this->documentRepository->findOneBy([
'status' => 1,
'type' => $documentType,
'merchant' => $this->merchantUtils->getMerchantCurrent()
], [
'reference' => 'DESC'
]);

if ($oneDocumentExist) {
$reference = $oneDocumentExist->getReference();
$pattern = '#([A-Z]+)?([0-9]+)#';
preg_match($pattern, $reference, $matches, PREG_OFFSET_CAPTURE);
$sizeNumReference = strlen($matches[2][0]);
$numReference = ((int)$matches[2][0]) + 1;
$numReference = str_pad($numReference, $sizeNumReference, '0', STR_PAD_LEFT);

return $prefix . $numReference;
}
else {
return $prefix . '00001';
}
}

public function createDocument($params = [])
{
$documentClass = $this->em->getClassMetadata(DocumentInterface::class)->getName();
$document = new $documentClass ;

if(isset($params['merchant'])) {
$document->setMerchant($params['merchant']) ;
}
else {
$document->setMerchant($params['order_shops'][0]->getMerchant()) ;
}

foreach($params['order_shops'] as $orderShop) {
$document->addOrderShop($orderShop) ;
}

$document->setType($params['type']) ;
$document->setTitle($params['title']) ;
$document->setStatus((isset($params['status'])) ? $params['status'] : 1) ;
$document->setReference($this->generateReference($params['type'])) ;
$document->setMerchantAddress($params['merchant_address']) ;
$document->setBuyerAddress($params['buyer_address']) ;
$document->setMerchantAddressText($params['merchant_address']->getSummary()) ;
$document->setBuyerAddressText($params['buyer_address']->getSummary()) ;
$document->setCreatedBy($params['created_by']) ;
$document->setUpdatedBy($params['created_by']) ;

$this->em->persist($document);
$this->em->flush() ;

return $document ;
}
}

+ 50
- 9
ShopBundle/Services/OrderUtils.php 查看文件

@@ -5,6 +5,7 @@ namespace Lc\ShopBundle\Services;
use App\Entity\OrderProductReductionCatalog;
use App\Entity\OrderShop;
use Doctrine\ORM\EntityManagerInterface;
use Lc\ShopBundle\Context\DocumentInterface;
use Lc\ShopBundle\Context\MerchantUtilsInterface;
use Lc\ShopBundle\Context\OrderReductionCartInterface;
use Lc\ShopBundle\Context\OrderProductInterface;
@@ -16,6 +17,7 @@ use Lc\ShopBundle\Context\ProductFamilyUtilsInterface;
use Lc\ShopBundle\Context\ReductionCartInterface;
use Lc\ShopBundle\Context\ReductionCreditInterface;
use Lc\ShopBundle\Context\UserInterface;
use Lc\ShopBundle\Model\Document;
use Lc\ShopBundle\Form\Backend\Order\OrderReductionCreditType;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Security\Core\Security;
@@ -29,9 +31,11 @@ class OrderUtils
protected $orderShopRepo;
protected $priceUtils;
protected $productFamilyUtils;
protected $documentUtils ;

public function __construct(EntityManagerInterface $em, Security $security, UserUtils $userUtils,
MerchantUtilsInterface $merchantUtils, PriceUtils $priceUtils, ProductFamilyUtilsInterface $productFamilyUtils)
MerchantUtilsInterface $merchantUtils, PriceUtils $priceUtils, ProductFamilyUtilsInterface $productFamilyUtils,
DocumentUtils $documentUtils)
{
$this->em = $em;
$this->security = $security;
@@ -40,6 +44,7 @@ class OrderUtils
$this->orderShopRepo = $this->em->getRepository($this->em->getClassMetadata(OrderShopInterface::class)->getName());
$this->priceUtils = $priceUtils;
$this->productFamilyUtils = $productFamilyUtils;
$this->documentUtils = $documentUtils ;
}


@@ -199,18 +204,12 @@ class OrderUtils

public function compareOrderProductReductionCatalog($orderProductReductionCatalog1, $orderProductReductionCatalog2)
{

return $orderProductReductionCatalog1 && $orderProductReductionCatalog2
&& $orderProductReductionCatalog1->getUnit() == $orderProductReductionCatalog2->getUnit()
&& $orderProductReductionCatalog1->getValue() == $orderProductReductionCatalog2->getValue()
&& $orderProductReductionCatalog1->getBehaviorTaxRate() == $orderProductReductionCatalog2->getBehaviorTaxRate();

/*return (!$orderProductReductionCatalog1 && !$orderProductReductionCatalog2)
return (!$orderProductReductionCatalog1 && !$orderProductReductionCatalog2)
|| ($orderProductReductionCatalog1
&& $orderProductReductionCatalog2
&& $orderProductReductionCatalog1->getUnit() == $orderProductReductionCatalog2->getUnit()
&& (string) $orderProductReductionCatalog1->getValue() == (string) $orderProductReductionCatalog2->getValue()
&& $orderProductReductionCatalog1->getBehaviorTaxRate() == $orderProductReductionCatalog2->getBehaviorTaxRate()) ;*/
&& $orderProductReductionCatalog1->getBehaviorTaxRate() == $orderProductReductionCatalog2->getBehaviorTaxRate()) ;
}

public function countQuantities($orderShop)
@@ -337,6 +336,8 @@ class OrderUtils
$orderReductionCart->setAppliedTo($reductionCart->getAppliedTo());
$orderReductionCart->setType($reductionCart->getType());

$this->em->persist($orderReductionCart) ;
$this->em->flush() ;

return $orderReductionCart;
}
@@ -375,6 +376,7 @@ class OrderUtils

}
}*/

public function mergeOrderShops($orderShop1, $orderShop2)
{
if ($orderShop1 && $orderShop2) {
@@ -391,4 +393,43 @@ class OrderUtils
return $orderShop1;
}
}

public function createDocumentInvoice(OrderShopInterface $orderShop)
{
$merchantAddress = $orderShop->getMerchant()->getAddress() ;
$buyerAddress = $orderShop->getBillingAddress() ;

$document = $this->documentUtils->createDocument([
'type' => Document::TYPE_INVOICE,
'title' => '',
'status' => 1,
'order_shops' => [$orderShop],
'merchant_address' => $merchantAddress,
'buyer_address' => $buyerAddress,
'created_by' => $orderShop->getUser()
]) ;

return $document ;
}

public function groupOrderProductsByProductFamily($orderProducts)
{
$orderProductsByProductFamily = [] ;
foreach($orderProducts as $orderProduct) {
if($orderProduct->getProduct() && $orderProduct->getProduct()->getProductFamily()) {
$productFamily = $orderProduct->getProduct()->getProductFamily() ;
if(!isset($orderProductsByProductFamily[$productFamily->getId()])) {
$orderProductsByProductFamily[$productFamily->getId()] = [
'order_products' => [],
'total_quantity_weight' => 0,
] ;
}
$orderProductsByProductFamily[$productFamily->getId()]['order_products'][] = $orderProduct ;
$orderProductsByProductFamily[$productFamily->getId()]['total_quantity_weight'] += ($orderProduct->getQuantityProduct() / $orderProduct->getUnit()->getCoefficient()) * $orderProduct->getQuantityOrder() ;
}
}

return $orderProductsByProductFamily ;
}

}

+ 64
- 2
ShopBundle/Services/PriceUtils.php 查看文件

@@ -138,6 +138,21 @@ class PriceUtils
}
}

public function getTotalWithReduction($entity)
{
if($entity instanceof OrderProductInterface) {
return $this->getPriceWithReductionCatalog(
$entity,
$this->getTotal($entity),
$this->getTotalWithTax($entity)
) ;
}

if($entity instanceof OrderShopInterface) {
return $this->getTotalOrderProductsWithReduction($entity->getOrderProducts(), true, true) ;
}
}

public function getTotalOrderProducts($entity)
{
return $this->getSumOrderProductsDispatch($entity) ;
@@ -148,6 +163,11 @@ class PriceUtils
return $this->getSumOrderProductsDispatch($entity, true) ;
}

public function getTotalOrderProductsWithReduction($entity)
{
return $this->getSumOrderProductsDispatch($entity, false, true) ;
}

public function getTotalOrderProductsWithTaxAndReduction($entity)
{
return $this->getSumOrderProductsDispatch($entity, true, true) ;
@@ -173,6 +193,9 @@ class PriceUtils
elseif($withTax) {
$total += $this->getTotalWithTax($orderProduct) ;
}
elseif($withReduction) {
$total += $this->getTotalWithReduction($orderProduct) ;
}
else {
$total += $this->getTotal($orderProduct) ;
}
@@ -180,7 +203,17 @@ class PriceUtils
return $total ;
}

public function getPriceWithTaxAndReductionCatalog($entity, $price, $priceWithTax, $reductionCatalog = null): ?float
public function getPriceWithTaxAndReductionCatalog($entity, $price, $priceWithTax, $reductionCatalog = null)
{
return $this->getPriceWithReductionCatalogGeneric($entity, $price, $priceWithTax, $reductionCatalog, true) ;
}

public function getPriceWithReductionCatalog($entity, $price, $priceWithTax, $reductionCatalog = null)
{
return $this->getPriceWithReductionCatalogGeneric($entity, $price, $priceWithTax, $reductionCatalog, false) ;
}

public function getPriceWithReductionCatalogGeneric($entity, $price, $priceWithTax, $reductionCatalog = null, $withTax = true): ?float
{
if($reductionCatalog) {
$reductionCatalogValue = $reductionCatalog->getValue() ;
@@ -234,7 +267,31 @@ class PriceUtils
}
}

return $this->round($priceWithTax) ;
if($withTax) {
$priceReturn = $priceWithTax ;
}
else {
$priceReturn = $this->applyPercentNegative($priceWithTax, $entity->getTaxRateInherited()->getValue()) ;
}

return $this->round($priceReturn) ;
}

public function getTotalTaxes($entity)
{
if($entity instanceof OrderProductInterface) {
return $this->getTotalWithReduction($entity) * ($entity->getTaxRateInherited()->getValue() / 100) ;
}

if($entity instanceof OrderShopInterface) {
$totalTaxes = 0 ;
foreach($entity->getOrderProducts() as $orderProduct) {
$totalTaxes += $this->getTotalTaxes($orderProduct) ;
}
return $totalTaxes ;
}

return 0 ;
}

public function applyTax($price, $taxRateValue)
@@ -257,6 +314,11 @@ class PriceUtils
return $price * ($percentage / 100 + 1) ;
}

public function applyPercentNegative($price, $percentage)
{
return $price / ($percentage / 100 + 1) ;
}

public function round($price)
{
return round((($price * 100)) / 100, 2);

正在加载...
取消
保存