use common\components\ActiveRecordCommon; | use common\components\ActiveRecordCommon; | ||||
/** | |||||
* This is the model class for table "tax_rate". | |||||
* | |||||
*/ | |||||
class TaxRate extends ActiveRecordCommon | class TaxRate extends ActiveRecordCommon | ||||
{ | { | ||||
/** | /** |
class TaxRateRepository extends BaseService implements RepositoryInterface | class TaxRateRepository extends BaseService implements RepositoryInterface | ||||
{ | { | ||||
/** | |||||
* Retourne les options de base nécessaires à la fonction de recherche. | |||||
* | |||||
*/ | |||||
public function defaultOptionsSearch(): array | public function defaultOptionsSearch(): array | ||||
{ | { | ||||
return [ | return [ |
use common\logic\Distribution\ProductDistribution\ProductDistribution; | use common\logic\Distribution\ProductDistribution\ProductDistribution; | ||||
use common\logic\Order\Order\Order; | use common\logic\Order\Order\Order; | ||||
use common\logic\Producer\Producer\Producer; | use common\logic\Producer\Producer\Producer; | ||||
use common\helpers\GlobalParam; | |||||
use common\components\ActiveRecordCommon; | use common\components\ActiveRecordCommon; | ||||
use common\logic\Product\Product\Product; | |||||
/** | |||||
* This is the model class for table "distribution". | |||||
* | |||||
*/ | |||||
class Distribution extends ActiveRecordCommon | class Distribution extends ActiveRecordCommon | ||||
{ | { | ||||
/** | /** | ||||
{ | { | ||||
return $this->hasMany(PointSaleDistribution::class, ['id_distribution' => 'id']); | 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); | |||||
} | |||||
} | |||||
} | } |
use common\logic\BaseService; | use common\logic\BaseService; | ||||
use common\logic\BuilderInterface; | use common\logic\BuilderInterface; | ||||
use common\logic\Distribution\PointSaleDistribution\PointSaleDistribution; | |||||
use common\logic\Distribution\PointSaleDistribution\PointSaleDistributionBuilder; | use common\logic\Distribution\PointSaleDistribution\PointSaleDistributionBuilder; | ||||
use common\logic\Distribution\PointSaleDistribution\PointSaleDistributionRepository; | use common\logic\Distribution\PointSaleDistribution\PointSaleDistributionRepository; | ||||
use common\logic\Distribution\ProductDistribution\ProductDistribution; | use common\logic\Distribution\ProductDistribution\ProductDistribution; | ||||
use common\logic\Distribution\ProductDistribution\ProductDistributionRepository; | use common\logic\Distribution\ProductDistribution\ProductDistributionRepository; | ||||
use common\logic\Order\Order\Order; | use common\logic\Order\Order\Order; | ||||
use common\logic\Order\Order\OrderRepository; | use common\logic\Order\Order\OrderRepository; | ||||
use common\logic\PointSale\PointSale\PointSale; | |||||
use common\logic\Producer\Producer\Producer; | use common\logic\Producer\Producer\Producer; | ||||
use common\logic\Product\Product\Product; | use common\logic\Product\Product\Product; | ||||
use common\logic\Product\Product\ProductRepository; | use common\logic\Product\Product\ProductRepository; | ||||
use common\logic\Subscription\Subscription\Subscription; | |||||
use common\logic\User\UserProducer\UserProducer; | use common\logic\User\UserProducer\UserProducer; | ||||
class DistributionBuilder extends BaseService implements BuilderInterface | class DistributionBuilder extends BaseService implements BuilderInterface | ||||
{ | { | ||||
protected DistributionRepository $distributionRepository; | protected DistributionRepository $distributionRepository; | ||||
protected DistributionSolver $distributionSolver; | |||||
protected PointSaleDistributionRepository $pointSaleDistributionRepository; | protected PointSaleDistributionRepository $pointSaleDistributionRepository; | ||||
protected PointSaleDistributionBuilder $pointSaleDistributionBuilder; | protected PointSaleDistributionBuilder $pointSaleDistributionBuilder; | ||||
protected ProductRepository $productRepository; | protected ProductRepository $productRepository; | ||||
public function __construct() | public function __construct() | ||||
{ | { | ||||
$this->distributionRepository = $this->loadService(DistributionRepository::class); | $this->distributionRepository = $this->loadService(DistributionRepository::class); | ||||
$this->distributionSolver = $this->loadService(DistributionSolver::class); | |||||
$this->pointSaleDistributionRepository = $this->loadService(PointSaleDistributionRepository::class); | $this->pointSaleDistributionRepository = $this->loadService(PointSaleDistributionRepository::class); | ||||
$this->pointSaleDistributionBuilder = $this->loadService(PointSaleDistributionBuilder::class); | $this->pointSaleDistributionBuilder = $this->loadService(PointSaleDistributionBuilder::class); | ||||
$this->productRepository = $this->loadService(ProductRepository::class); | $this->productRepository = $this->loadService(ProductRepository::class); | ||||
} | } | ||||
/** | /** | ||||
* Lie un produit à la distribution. | |||||
* Lie un produit à une distribution. | |||||
*/ | */ | ||||
public function linkProduct(Distribution $distribution, Product $product): ProductDistribution | public function linkProduct(Distribution $distribution, Product $product): ProductDistribution | ||||
{ | { | ||||
return $productDistribution; | 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 | public function updateOrderProductPrices(Distribution $distribution, Product $product): void | ||||
{ | { | ||||
$ordersArray = $this->orderRepository->getByDistribution($distribution, 'AND origin != "user"'); | $ordersArray = $this->orderRepository->getByDistribution($distribution, 'AND origin != "user"'); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
/** | |||||
* 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); | |||||
} | |||||
} | |||||
} | } |
class DistributionRepository extends BaseService implements RepositoryInterface | class DistributionRepository extends BaseService implements RepositoryInterface | ||||
{ | { | ||||
/** | |||||
* Retourne les options de base nécessaires à la fonction de recherche. | |||||
*/ | |||||
public function defaultOptionsSearch(): array | public function defaultOptionsSearch(): array | ||||
{ | { | ||||
return [ | return [ |
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use common\logic\BaseService; | use common\logic\BaseService; | ||||
use common\logic\PointSale\PointSale\PointSale; | |||||
use common\logic\Product\Product\Product; | use common\logic\Product\Product\Product; | ||||
use common\logic\SolverInterface; | use common\logic\SolverInterface; | ||||
return false; | return false; | ||||
} | } | ||||
/* | |||||
/** | |||||
* Filtre les distributions par délai de commande. | * Filtre les distributions par délai de commande. | ||||
*/ | */ | ||||
public function filterDistributionsByDateDelay(array $distributionsArray): array | public function filterDistributionsByDateDelay(array $distributionsArray): array | ||||
return $newDistributionsArray; | 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; | |||||
} | |||||
} | } |
namespace common\logic\Distribution\PointSaleDistribution; | namespace common\logic\Distribution\PointSaleDistribution; | ||||
use common\helpers\GlobalParam; | |||||
use Yii; | |||||
use common\components\ActiveRecordCommon ; | 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 | class PointSaleDistribution extends ActiveRecordCommon | ||||
{ | { | ||||
var $points_sale_distribution; | var $points_sale_distribution; | ||||
public function getDistribution() | public function getDistribution() | ||||
{ | { | ||||
return $this->hasOne(Distribution::className(), ['id' => 'id_distribution']); | |||||
return $this->hasOne(Distribution::class, ['id' => 'id_distribution']); | |||||
} | } | ||||
public function getPointSale() | 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' => '' | |||||
] ; | |||||
} | |||||
} | } |
class PointSaleDistributionBuilder extends BaseService implements BuilderInterface | class PointSaleDistributionBuilder extends BaseService implements BuilderInterface | ||||
{ | { | ||||
/* | |||||
protected PointSaleDistributionRepository $pointSaleDistributionRepository; | |||||
public function __construct() | |||||
{ | |||||
$this->pointSaleDistributionRepository = $this->loadService(PointSaleDistributionRepository::class); | |||||
} | |||||
/** | |||||
* Instancie un PointSaleDistribution. | * Instancie un PointSaleDistribution. | ||||
*/ | */ | ||||
public function instanciate(Distribution $distribution, PointSale $pointSale): PointSaleDistribution | public function instanciate(Distribution $distribution, PointSale $pointSale): PointSaleDistribution | ||||
return $pointSaleDistribution; | return $pointSaleDistribution; | ||||
} | } | ||||
/* | |||||
/** | |||||
* Crée un PointSaleDistribution. | * Crée un PointSaleDistribution. | ||||
*/ | */ | ||||
public function create(Distribution $distribution, PointSale $pointSale): PointSaleDistribution | public function create(Distribution $distribution, PointSale $pointSale): PointSaleDistribution | ||||
return $pointSaleDistribution; | 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 | // setAll | ||||
public function createAll(Distribution $distribution, bool $delivery): void | public function createAll(Distribution $distribution, bool $delivery): void | ||||
public function initDelivery(PointSaleDistribution $pointSaleDistribution, bool $delivery) | public function initDelivery(PointSaleDistribution $pointSaleDistribution, bool $delivery) | ||||
{ | { | ||||
$day = date('N', strtotime($pointSaleDistribution->distribution->date)); | $day = date('N', strtotime($pointSaleDistribution->distribution->date)); | ||||
$pointSale = $pointSaleDistribution->pointSale; | |||||
if ($delivery && | 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; | $pointSaleDistribution->delivery = 1; | ||||
} else { | } else { |
use common\logic\BaseService; | use common\logic\BaseService; | ||||
use common\logic\Distribution\Distribution\Distribution; | use common\logic\Distribution\Distribution\Distribution; | ||||
use common\logic\PointSale\PointSale\PointSale; | |||||
use common\logic\RepositoryInterface; | use common\logic\RepositoryInterface; | ||||
class PointSaleDistributionRepository extends BaseService implements 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 | public function countByDistribution(Distribution $distribution): int | ||||
{ | { | ||||
return PointSaleDistribution::searchCount([ | return PointSaleDistribution::searchCount([ | ||||
'id_distribution' => $distribution->id | 'id_distribution' => $distribution->id | ||||
]); | ]); | ||||
} | } | ||||
} | } |
namespace common\logic\Distribution\ProductDistribution; | namespace common\logic\Distribution\ProductDistribution; | ||||
use common\components\ActiveRecordCommon ; | 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 | class ProductDistribution extends ActiveRecordCommon | ||||
{ | { | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
]; | ]; | ||||
} | } | ||||
/* | |||||
* Relations | |||||
*/ | |||||
public function getProduct() | |||||
{ | |||||
return $this->hasOne( Product::className(), ['id' => 'id_product']); | |||||
} | |||||
public function getDistribution() | |||||
{ | |||||
return $this->hasOne(Distribution::className(), ['id' => 'id_distribution']); | |||||
} | |||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
public function attributeLabels() | |||||
public function attributeLabels() | |||||
{ | { | ||||
return [ | return [ | ||||
'id' => 'ID', | 'id' => 'ID', | ||||
'quantity_max' => 'Quantité max', | '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']); | |||||
} | |||||
} | } |
->initQuantityMax($productDistribution); | ->initQuantityMax($productDistribution); | ||||
$productDistribution->save(); | $productDistribution->save(); | ||||
return $productDistribution; | |||||
} | } | ||||
public function createIfNotExist(Distribution $distribution, Product $product): ProductDistribution | public function createIfNotExist(Distribution $distribution, Product $product): ProductDistribution | ||||
{ | { | ||||
$productDistribution = $this->productDistributionRepository->getOne($distribution, $product); | $productDistribution = $this->productDistributionRepository->getOne($distribution, $product); | ||||
if(!$productDistribution) { | if(!$productDistribution) { | ||||
$productDistribution = $this->create($distribution, $product); | $productDistribution = $this->create($distribution, $product); | ||||
} | } |
use common\logic\BaseService; | use common\logic\BaseService; | ||||
use common\logic\Distribution\Distribution\Distribution; | use common\logic\Distribution\Distribution\Distribution; | ||||
use common\logic\Order\Order\Order; | |||||
use common\logic\Product\Product\Product; | use common\logic\Product\Product\Product; | ||||
use common\logic\RepositoryInterface; | use common\logic\RepositoryInterface; | ||||
class ProductDistributionRepository extends BaseService implements 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 | public function countByDistribution(Distribution $distribution): int | ||||
{ | { | ||||
return ProductDistribution::searchCount([ | return ProductDistribution::searchCount([ | ||||
'id_product' => $product->id | '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; | |||||
} | |||||
} | } |
namespace common\logic\Document\DeliveryNote; | 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 | class DeliveryNote extends Document | ||||
{ | { | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
return $this->relationOrders('id_delivery_note') ; | 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() | public function getInvoiceId() | ||||
{ | { | ||||
if($this->orders && count($this->orders) > 0) { | if($this->orders && count($this->orders) > 0) { |
class DeliveryNoteRepository extends BaseService implements 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' | |||||
]; | |||||
} | |||||
} | } |