@@ -4,10 +4,6 @@ namespace common\logic\Config\TaxRate; | |||
use common\components\ActiveRecordCommon; | |||
/** | |||
* This is the model class for table "tax_rate". | |||
* | |||
*/ | |||
class TaxRate extends ActiveRecordCommon | |||
{ | |||
/** |
@@ -8,10 +8,6 @@ use common\logic\RepositoryInterface; | |||
class TaxRateRepository extends BaseService implements RepositoryInterface | |||
{ | |||
/** | |||
* Retourne les options de base nécessaires à la fonction de recherche. | |||
* | |||
*/ | |||
public function defaultOptionsSearch(): array | |||
{ | |||
return [ |
@@ -42,14 +42,8 @@ use common\logic\Distribution\PointSaleDistribution\PointSaleDistribution; | |||
use common\logic\Distribution\ProductDistribution\ProductDistribution; | |||
use common\logic\Order\Order\Order; | |||
use common\logic\Producer\Producer\Producer; | |||
use common\helpers\GlobalParam; | |||
use common\components\ActiveRecordCommon; | |||
use common\logic\Product\Product\Product; | |||
/** | |||
* This is the model class for table "distribution". | |||
* | |||
*/ | |||
class Distribution extends ActiveRecordCommon | |||
{ | |||
/** | |||
@@ -107,98 +101,4 @@ class Distribution extends ActiveRecordCommon | |||
{ | |||
return $this->hasMany(PointSaleDistribution::class, ['id_distribution' => 'id']); | |||
} | |||
/** | |||
* Lie un produit aux jours de distribution futurs. | |||
* | |||
* @param Product $product | |||
*/ | |||
public static function linkProductIncomingDistributions($product) | |||
{ | |||
$distributionsArray = self::getIncoming(); | |||
foreach ($distributionsArray as $distribution) { | |||
$distribution->linkProduct($product); | |||
} | |||
} | |||
/** | |||
* Lie un point de vente aux jours de distribution futurs. | |||
* | |||
* @param PointSale $pointSale | |||
*/ | |||
public static function linkPointSaleIncomingDistributions($pointSale) | |||
{ | |||
$distributionsArray = self::getIncoming(); | |||
foreach ($distributionsArray as $distribution) { | |||
$distribution->linkPointSale($pointSale); | |||
} | |||
} | |||
/** | |||
* | |||
* @param type $pointSale | |||
*/ | |||
public function linkPointSale($pointSale) | |||
{ | |||
$pointSaleDistribution = PointSaleDistribution::searchOne([ | |||
'id_distribution' => $this->id, | |||
'id_point_sale' => $pointSale->id | |||
]); | |||
if (!$pointSaleDistribution) { | |||
$pointSaleDistribution = new PointSaleDistribution(); | |||
$pointSaleDistribution->id_distribution = $this->id; | |||
$pointSaleDistribution->id_point_sale = $pointSale->id; | |||
} | |||
$dayDistribution = date('N', strtotime($this->date)); | |||
$daysArray = [ | |||
1 => 'monday', | |||
2 => 'tuesday', | |||
3 => 'wednesday', | |||
4 => 'thursday', | |||
5 => 'friday', | |||
6 => 'saturday', | |||
7 => 'sunday', | |||
]; | |||
$pointSaleDistribution->delivery = 0; | |||
$deliveryDay = 'delivery_' . $daysArray[$dayDistribution]; | |||
if ($pointSale->$deliveryDay) { | |||
$pointSaleDistribution->delivery = 1; | |||
} | |||
$pointSaleDistribution->save(); | |||
} | |||
public function isPointSaleActive($distribution, $pointSaleId) | |||
{ | |||
$pointSaleActive = false; | |||
if ($distribution->pointSaleDistribution) { | |||
foreach ($distribution->pointSaleDistribution as $pointSaleDistribution) { | |||
if ($pointSaleDistribution->id_point_sale == $pointSaleId && $pointSaleDistribution->delivery) { | |||
$pointSaleActive = true; | |||
} | |||
} | |||
} | |||
return $pointSaleActive; | |||
} | |||
/** | |||
* Active ou désactive la distribution. | |||
*/ | |||
public function active($active = true) | |||
{ | |||
PointSaleDistribution::setAll($this->id, true); | |||
$this->active = (int)$active; | |||
$this->save(); | |||
if ($active) { | |||
// ajout des abonnements | |||
Subscription::addAll($this->date); | |||
} | |||
} | |||
} |
@@ -4,6 +4,7 @@ namespace common\logic\Distribution\Distribution; | |||
use common\logic\BaseService; | |||
use common\logic\BuilderInterface; | |||
use common\logic\Distribution\PointSaleDistribution\PointSaleDistribution; | |||
use common\logic\Distribution\PointSaleDistribution\PointSaleDistributionBuilder; | |||
use common\logic\Distribution\PointSaleDistribution\PointSaleDistributionRepository; | |||
use common\logic\Distribution\ProductDistribution\ProductDistribution; | |||
@@ -11,14 +12,17 @@ use common\logic\Distribution\ProductDistribution\ProductDistributionBuilder; | |||
use common\logic\Distribution\ProductDistribution\ProductDistributionRepository; | |||
use common\logic\Order\Order\Order; | |||
use common\logic\Order\Order\OrderRepository; | |||
use common\logic\PointSale\PointSale\PointSale; | |||
use common\logic\Producer\Producer\Producer; | |||
use common\logic\Product\Product\Product; | |||
use common\logic\Product\Product\ProductRepository; | |||
use common\logic\Subscription\Subscription\Subscription; | |||
use common\logic\User\UserProducer\UserProducer; | |||
class DistributionBuilder extends BaseService implements BuilderInterface | |||
{ | |||
protected DistributionRepository $distributionRepository; | |||
protected DistributionSolver $distributionSolver; | |||
protected PointSaleDistributionRepository $pointSaleDistributionRepository; | |||
protected PointSaleDistributionBuilder $pointSaleDistributionBuilder; | |||
protected ProductRepository $productRepository; | |||
@@ -29,6 +33,7 @@ class DistributionBuilder extends BaseService implements BuilderInterface | |||
public function __construct() | |||
{ | |||
$this->distributionRepository = $this->loadService(DistributionRepository::class); | |||
$this->distributionSolver = $this->loadService(DistributionSolver::class); | |||
$this->pointSaleDistributionRepository = $this->loadService(PointSaleDistributionRepository::class); | |||
$this->pointSaleDistributionBuilder = $this->loadService(PointSaleDistributionBuilder::class); | |||
$this->productRepository = $this->loadService(ProductRepository::class); | |||
@@ -91,7 +96,7 @@ class DistributionBuilder extends BaseService implements BuilderInterface | |||
} | |||
/** | |||
* Lie un produit à la distribution. | |||
* Lie un produit à une distribution. | |||
*/ | |||
public function linkProduct(Distribution $distribution, Product $product): ProductDistribution | |||
{ | |||
@@ -101,6 +106,49 @@ class DistributionBuilder extends BaseService implements BuilderInterface | |||
return $productDistribution; | |||
} | |||
/** | |||
* Lie un produit aux distributions futures. | |||
*/ | |||
public function linkProductIncomingDistributions(Product $product): void | |||
{ | |||
$distributionArray = $this->distributionRepository->getIncoming(); | |||
foreach ($distributionArray as $distribution) { | |||
$this->linkProduct($distribution, $product); | |||
} | |||
} | |||
/** | |||
* Lie un point de vente à une distribution | |||
*/ | |||
public function linkPointSale(Distribution $distribution, PointSale $pointSale): PointSaleDistribution | |||
{ | |||
$pointSaleDistribution = $this->pointSaleDistributionBuilder->createIfNotExist($distribution, $pointSale); | |||
$dayString = $this->distributionSolver->getDayAsString($distribution); | |||
$pointSaleDistribution->delivery = 0; | |||
$deliveryDay = 'delivery_' . $dayString; | |||
if ($pointSale->$deliveryDay) { | |||
$pointSaleDistribution->delivery = 1; | |||
} | |||
$pointSaleDistribution->save(); | |||
return $pointSaleDistribution; | |||
} | |||
/** | |||
* Lie un point de vente aux distributions futures. | |||
*/ | |||
public function linkPointSaleIncomingDistributions(PointSale $pointSale): void | |||
{ | |||
$distributionArray = $this->distributionRepository->getIncoming(); | |||
foreach ($distributionArray as $distribution) { | |||
$this->linkPointSale($distribution, $pointSale); | |||
} | |||
} | |||
public function updateOrderProductPrices(Distribution $distribution, Product $product): void | |||
{ | |||
$ordersArray = $this->orderRepository->getByDistribution($distribution, 'AND origin != "user"'); | |||
@@ -134,4 +182,19 @@ class DistributionBuilder extends BaseService implements BuilderInterface | |||
} | |||
} | |||
} | |||
/** | |||
* Active ou désactive la distribution. | |||
*/ | |||
public function active(Distribution $distribution, bool $active = true): void | |||
{ | |||
$this->pointSaleDistributionBuilder->createAll($distribution, true); | |||
$distribution->active = (int) $active; | |||
$distribution->save(); | |||
if ($active) { | |||
Subscription::addAll($distribution->date); | |||
} | |||
} | |||
} |
@@ -9,9 +9,6 @@ use common\logic\RepositoryInterface; | |||
class DistributionRepository extends BaseService implements RepositoryInterface | |||
{ | |||
/** | |||
* Retourne les options de base nécessaires à la fonction de recherche. | |||
*/ | |||
public function defaultOptionsSearch(): array | |||
{ | |||
return [ |
@@ -4,6 +4,7 @@ namespace common\logic\Distribution\Distribution; | |||
use common\helpers\GlobalParam; | |||
use common\logic\BaseService; | |||
use common\logic\PointSale\PointSale\PointSale; | |||
use common\logic\Product\Product\Product; | |||
use common\logic\SolverInterface; | |||
@@ -46,7 +47,7 @@ class DistributionSolver extends BaseService implements SolverInterface | |||
return false; | |||
} | |||
/* | |||
/** | |||
* Filtre les distributions par délai de commande. | |||
*/ | |||
public function filterDistributionsByDateDelay(array $distributionsArray): array | |||
@@ -90,4 +91,20 @@ class DistributionSolver extends BaseService implements SolverInterface | |||
return $newDistributionsArray; | |||
} | |||
public function isPointSaleActive(Distribution $distribution, PointSale $pointSale): bool | |||
{ | |||
$pointSaleActive = false; | |||
if ($distribution->pointSaleDistribution) { | |||
foreach ($distribution->pointSaleDistribution as $pointSaleDistribution) { | |||
if ($pointSaleDistribution->id_point_sale == $pointSale->id && $pointSaleDistribution->delivery) { | |||
$pointSaleActive = true; | |||
} | |||
} | |||
} | |||
return $pointSaleActive; | |||
} | |||
} |
@@ -38,14 +38,10 @@ termes. | |||
namespace common\logic\Distribution\PointSaleDistribution; | |||
use common\helpers\GlobalParam; | |||
use Yii; | |||
use common\components\ActiveRecordCommon ; | |||
use common\logic\Distribution\Distribution\Distribution; | |||
use common\logic\PointSale\PointSale\PointSale; | |||
/** | |||
* This is the model class for table "point_sale_distribution". | |||
* | |||
*/ | |||
class PointSaleDistribution extends ActiveRecordCommon | |||
{ | |||
var $points_sale_distribution; | |||
@@ -87,26 +83,11 @@ class PointSaleDistribution extends ActiveRecordCommon | |||
public function getDistribution() | |||
{ | |||
return $this->hasOne(Distribution::className(), ['id' => 'id_distribution']); | |||
return $this->hasOne(Distribution::class, ['id' => 'id_distribution']); | |||
} | |||
public function getPointSale() | |||
{ | |||
return $this->hasOne(PointSale::className(), ['id' => 'id_point_sale']); | |||
return $this->hasOne(PointSale::class, ['id' => 'id_point_sale']); | |||
} | |||
/** | |||
* Retourne les options de base nécessaires à la fonction de recherche. | |||
* | |||
* @return array | |||
*/ | |||
public static function defaultOptionsSearch() { | |||
return [ | |||
'with' => ['distribution', 'pointSale'], | |||
'join_with' => [], | |||
'orderby' => '', | |||
'attribute_id_producer' => '' | |||
] ; | |||
} | |||
} |
@@ -10,7 +10,14 @@ use common\logic\PointSale\PointSale\PointSale; | |||
class PointSaleDistributionBuilder extends BaseService implements BuilderInterface | |||
{ | |||
/* | |||
protected PointSaleDistributionRepository $pointSaleDistributionRepository; | |||
public function __construct() | |||
{ | |||
$this->pointSaleDistributionRepository = $this->loadService(PointSaleDistributionRepository::class); | |||
} | |||
/** | |||
* Instancie un PointSaleDistribution. | |||
*/ | |||
public function instanciate(Distribution $distribution, PointSale $pointSale): PointSaleDistribution | |||
@@ -23,7 +30,7 @@ class PointSaleDistributionBuilder extends BaseService implements BuilderInterfa | |||
return $pointSaleDistribution; | |||
} | |||
/* | |||
/** | |||
* Crée un PointSaleDistribution. | |||
*/ | |||
public function create(Distribution $distribution, PointSale $pointSale): PointSaleDistribution | |||
@@ -34,8 +41,19 @@ class PointSaleDistributionBuilder extends BaseService implements BuilderInterfa | |||
return $pointSaleDistribution; | |||
} | |||
public function createIfNotExist(Distribution $distribution, PointSale $pointSale): PointSaleDistribution | |||
{ | |||
$pointSaleDistribution = $this->pointSaleDistributionRepository->getOne($distribution, $pointSale); | |||
if(!$pointSaleDistribution) { | |||
$pointSaleDistribution = $this->create($distribution, $pointSale); | |||
} | |||
return $pointSaleDistribution; | |||
} | |||
/** | |||
* Initialise les PointSaleDistribution pour une distribution donnée. | |||
* Crée les PointSaleDistribution pour une distribution donnée. | |||
*/ | |||
// setAll | |||
public function createAll(Distribution $distribution, bool $delivery): void | |||
@@ -70,15 +88,16 @@ class PointSaleDistributionBuilder extends BaseService implements BuilderInterfa | |||
public function initDelivery(PointSaleDistribution $pointSaleDistribution, bool $delivery) | |||
{ | |||
$day = date('N', strtotime($pointSaleDistribution->distribution->date)); | |||
$pointSale = $pointSaleDistribution->pointSale; | |||
if ($delivery && | |||
(($day == 1 && $pointSaleDistribution->pointSale->delivery_monday) || | |||
($day == 2 && $pointSaleDistribution->pointSale->delivery_tuesday) || | |||
($day == 3 && $pointSaleDistribution->pointSale->delivery_wednesday) || | |||
($day == 4 && $pointSaleDistribution->pointSale->delivery_thursday) || | |||
($day == 5 && $pointSaleDistribution->pointSale->delivery_friday) || | |||
($day == 6 && $pointSaleDistribution->pointSale->delivery_saturday) || | |||
($day == 7 && $pointSaleDistribution->pointSale->delivery_sunday) | |||
(($day == 1 && $pointSale->delivery_monday) || | |||
($day == 2 && $pointSale->delivery_tuesday) || | |||
($day == 3 && $pointSale->delivery_wednesday) || | |||
($day == 4 && $pointSale->delivery_thursday) || | |||
($day == 5 && $pointSale->delivery_friday) || | |||
($day == 6 && $pointSale->delivery_saturday) || | |||
($day == 7 && $pointSale->delivery_sunday) | |||
)) { | |||
$pointSaleDistribution->delivery = 1; | |||
} else { |
@@ -4,15 +4,32 @@ namespace common\logic\Distribution\PointSaleDistribution; | |||
use common\logic\BaseService; | |||
use common\logic\Distribution\Distribution\Distribution; | |||
use common\logic\PointSale\PointSale\PointSale; | |||
use common\logic\RepositoryInterface; | |||
class PointSaleDistributionRepository extends BaseService implements RepositoryInterface | |||
{ | |||
public function defaultOptionsSearch() { | |||
return [ | |||
'with' => ['distribution', 'pointSale'], | |||
'join_with' => [], | |||
'orderby' => '', | |||
'attribute_id_producer' => '' | |||
] ; | |||
} | |||
public function getOne(Distribution $distribution, PointSale $pointSale): ?PointSaleDistribution | |||
{ | |||
return PointSaleDistribution::searchOne([ | |||
'id_distribution' => $distribution->id, | |||
'id_point_sale' => $pointSale->id | |||
]); | |||
} | |||
public function countByDistribution(Distribution $distribution): int | |||
{ | |||
return PointSaleDistribution::searchCount([ | |||
'id_distribution' => $distribution->id | |||
]); | |||
} | |||
} |
@@ -39,18 +39,11 @@ termes. | |||
namespace common\logic\Distribution\ProductDistribution; | |||
use common\components\ActiveRecordCommon ; | |||
use common\logic\Distribution\Distribution\Distribution; | |||
use common\logic\Product\Product\Product; | |||
/** | |||
* This is the model class for table "production_produit". | |||
* | |||
* @property integer $id | |||
* @property integer $id_distribution | |||
* @property integer $id_product | |||
* @property integer $active | |||
*/ | |||
class ProductDistribution extends ActiveRecordCommon | |||
{ | |||
/** | |||
* @inheritdoc | |||
*/ | |||
@@ -70,24 +63,10 @@ class ProductDistribution extends ActiveRecordCommon | |||
]; | |||
} | |||
/* | |||
* Relations | |||
*/ | |||
public function getProduct() | |||
{ | |||
return $this->hasOne( Product::className(), ['id' => 'id_product']); | |||
} | |||
public function getDistribution() | |||
{ | |||
return $this->hasOne(Distribution::className(), ['id' => 'id_distribution']); | |||
} | |||
/** | |||
* @inheritdoc | |||
*/ | |||
public function attributeLabels() | |||
public function attributeLabels() | |||
{ | |||
return [ | |||
'id' => 'ID', | |||
@@ -97,50 +76,18 @@ class ProductDistribution extends ActiveRecordCommon | |||
'quantity_max' => 'Quantité max', | |||
]; | |||
} | |||
/** | |||
* Retourne les options de base nécessaires à la fonction de recherche. | |||
* | |||
* @return array | |||
*/ | |||
public static function defaultOptionsSearch() { | |||
return [ | |||
'with' => ['product','distribution'], | |||
'join_with' => [], | |||
'orderby' => '', | |||
'attribute_id_producer' => '' | |||
] ; | |||
} | |||
/** | |||
* Recherche les enregistrement ProductionProduit liés à une production. | |||
* | |||
* @param integer $idDistribution | |||
* @return array | |||
/* | |||
* Relations | |||
*/ | |||
public static function searchByDistribution($idDistribution) | |||
public function getProduct() | |||
{ | |||
$arrayProductsDistribution = ProductDistribution::searchAll([ | |||
'id_distribution' => $idDistribution | |||
]) ; | |||
$orders = Order::searchAll([ | |||
'distribution.id' => $idDistribution | |||
]) ; | |||
foreach ($arrayProductsDistribution as $productDistribution) { | |||
if (isset($productDistribution->product)) { | |||
$arrayProductsDistribution[$productDistribution->id_product] = [ | |||
'active' => (int) $productDistribution->active, | |||
'unavailable' => (int) $productDistribution->product->unavailable, | |||
'quantity_max' => $productDistribution->quantity_max, | |||
'quantity_order' => Order::getProductQuantity($productDistribution->id_product, $orders), | |||
'quantity_remaining' => $productDistribution->quantity_max - Order::getProductQuantity($productDistribution->id_product, $orders) | |||
]; | |||
} | |||
} | |||
return $arrayProductsDistribution; | |||
return $this->hasOne(Product::class, ['id' => 'id_product']); | |||
} | |||
public function getDistribution() | |||
{ | |||
return $this->hasOne(Distribution::class, ['id' => 'id_distribution']); | |||
} | |||
} |
@@ -41,11 +41,14 @@ class ProductDistributionBuilder extends BaseService implements BuilderInterface | |||
->initQuantityMax($productDistribution); | |||
$productDistribution->save(); | |||
return $productDistribution; | |||
} | |||
public function createIfNotExist(Distribution $distribution, Product $product): ProductDistribution | |||
{ | |||
$productDistribution = $this->productDistributionRepository->getOne($distribution, $product); | |||
if(!$productDistribution) { | |||
$productDistribution = $this->create($distribution, $product); | |||
} |
@@ -4,11 +4,21 @@ namespace common\logic\Distribution\ProductDistribution; | |||
use common\logic\BaseService; | |||
use common\logic\Distribution\Distribution\Distribution; | |||
use common\logic\Order\Order\Order; | |||
use common\logic\Product\Product\Product; | |||
use common\logic\RepositoryInterface; | |||
class ProductDistributionRepository extends BaseService implements RepositoryInterface | |||
{ | |||
public function defaultOptionsSearch() { | |||
return [ | |||
'with' => ['product','distribution'], | |||
'join_with' => [], | |||
'orderby' => '', | |||
'attribute_id_producer' => '' | |||
] ; | |||
} | |||
public function countByDistribution(Distribution $distribution): int | |||
{ | |||
return ProductDistribution::searchCount([ | |||
@@ -23,4 +33,31 @@ class ProductDistributionRepository extends BaseService implements RepositoryInt | |||
'id_product' => $product->id | |||
]); | |||
} | |||
// @TODO : à déplacer dans OrderRepository | |||
// searchByDistribution | |||
public static function getByDistribution(Distribution $distribution): array | |||
{ | |||
$productDistributionArray = ProductDistribution::searchAll([ | |||
'id_distribution' => $distribution->id | |||
]) ; | |||
$orderArray = Order::searchAll([ | |||
'distribution.id' => $distribution->id | |||
]) ; | |||
foreach ($productDistributionArray as $productDistribution) { | |||
if (isset($productDistribution->product)) { | |||
$arrayProductsDistribution[$productDistribution->id_product] = [ | |||
'active' => (int) $productDistribution->active, | |||
'unavailable' => (int) $productDistribution->product->unavailable, | |||
'quantity_max' => $productDistribution->quantity_max, | |||
'quantity_order' => Order::getProductQuantity($productDistribution->id_product, $orderArray), | |||
'quantity_remaining' => $productDistribution->quantity_max - Order::getProductQuantity($productDistribution->id_product, $orders) | |||
]; | |||
} | |||
} | |||
return $productDistributionArray; | |||
} | |||
} |
@@ -38,26 +38,10 @@ termes. | |||
namespace common\logic\Document\DeliveryNote; | |||
use common\components\ActiveRecordCommon; | |||
use Yii; | |||
/** | |||
* This is the model class for table "delivery_note". | |||
* | |||
* @property integer $id | |||
* @property string $name | |||
* @property string $reference | |||
* @property string $date | |||
* @property string $comment | |||
* @property integer $id_point_sale_distribution | |||
* @property integer $id_user | |||
* @property string $address | |||
* @property string $city | |||
* @property string $postcode | |||
*/ | |||
use common\logic\Document\Document\Document; | |||
class DeliveryNote extends Document | |||
{ | |||
/** | |||
* @inheritdoc | |||
*/ | |||
@@ -75,21 +59,6 @@ class DeliveryNote extends Document | |||
return $this->relationOrders('id_delivery_note') ; | |||
} | |||
/** | |||
* Retourne les options de base nécessaires à la fonction de recherche. | |||
* | |||
* @return array | |||
*/ | |||
public static function defaultOptionsSearch() | |||
{ | |||
return [ | |||
'with' => [], | |||
'join_with' => ['user AS user_delivery_note', 'producer'], | |||
'orderby' => 'date ASC', | |||
'attribute_id_producer' => 'delivery_note.id_producer' | |||
]; | |||
} | |||
public function getInvoiceId() | |||
{ | |||
if($this->orders && count($this->orders) > 0) { |
@@ -7,5 +7,13 @@ use common\logic\RepositoryInterface; | |||
class DeliveryNoteRepository extends BaseService implements RepositoryInterface | |||
{ | |||
public function defaultOptionsSearch(): array | |||
{ | |||
return [ | |||
'with' => [], | |||
'join_with' => ['user AS user_delivery_note', 'producer'], | |||
'orderby' => 'date ASC', | |||
'attribute_id_producer' => 'delivery_note.id_producer' | |||
]; | |||
} | |||
} |