$pointSale = $this->findModel($id) ; | $pointSale = $this->findModel($id) ; | ||||
if($confirm) { | if($confirm) { | ||||
$pointSale->delete(); | |||||
$pointSale->status = -1; | |||||
$pointSale->save(); | |||||
// Suppression du lien entre les utilisateurs et le point de vente | |||||
UserPointSale::deleteAll(['id_point_sale' => $id]); | UserPointSale::deleteAll(['id_point_sale' => $id]); | ||||
PointSaleDistribution::deleteAll(['id_point_sale' => $id]) ; | |||||
Order::updateAll(['id_point_sale' => 0], 'id_point_sale = :id_point_sale', [':id_point_sale' => $id]) ; | |||||
// Suppression du lien PointSaleDistribution pour toutes les distributions à venir | |||||
$incomingDistributions = Distribution::getIncomingDistributions(); | |||||
foreach ($incomingDistributions as $distribution) { | |||||
PointSaleDistribution::deleteAll(['id_point_sale' => $id, 'id_distribution' => $distribution->id]); | |||||
} | |||||
// Suppression de toutes les commandes à venir de ce point de vente | |||||
$ordersArray = Order::searchAll( | |||||
[ | |||||
'id_point_sale' => $id, | |||||
], | |||||
[ | |||||
'conditions' => 'date_delete IS NULL AND distribution.date > :today', | |||||
'params' => [':today' => date('Y-m-d')] | |||||
] | |||||
); | |||||
if($ordersArray) { | |||||
foreach($ordersArray as $order) { | |||||
$order->delete(true); | |||||
} | |||||
} | |||||
Yii::$app->getSession()->setFlash('success', 'Point de vente <strong>'.Html::encode($pointSale->name).'</strong> supprimé.'); | Yii::$app->getSession()->setFlash('success', 'Point de vente <strong>'.Html::encode($pointSale->name).'</strong> supprimé.'); | ||||
} | |||||
} | |||||
else { | else { | ||||
Yii::$app->getSession()->setFlash('info', 'Souhaitez-vous vraiment supprimer le point de vente <strong>'.Html::encode($pointSale->name).'</strong> ? ' | Yii::$app->getSession()->setFlash('info', 'Souhaitez-vous vraiment supprimer le point de vente <strong>'.Html::encode($pointSale->name).'</strong> ? ' | ||||
. Html::a('Oui',['point-sale/delete','id' => $id, 'confirm' => 1], ['class' => 'btn btn-default']).' '.Html::a('Non', ['point-sale/index'], ['class' => 'btn btn-default'])); | . Html::a('Oui',['point-sale/delete','id' => $id, 'confirm' => 1], ['class' => 'btn btn-default']).' '.Html::a('Non', ['point-sale/index'], ['class' => 'btn btn-default'])); |
$pointsSaleArray = PointSale::find() | $pointsSaleArray = PointSale::find() | ||||
->where([ | ->where([ | ||||
'id_producer' => GlobalParam::getCurrentProducerId(), | 'id_producer' => GlobalParam::getCurrentProducerId(), | ||||
'status' => 1 | |||||
]) | ]) | ||||
->joinWith(['userPointSale' => function ($query) use ($model) { | ->joinWith(['userPointSale' => function ($query) use ($model) { | ||||
if ($model->id) { | if ($model->id) { |
</tr> | </tr> | ||||
</thead> | </thead> | ||||
<tbody> | <tbody> | ||||
<tr v-for="pointSale in pointsSale"> | |||||
<tr v-for="pointSale in pointsSale" v-if="pointSale.status == 1"> | |||||
<td> | <td> | ||||
<button class="btn btn-success" v-if="pointSale.pointSaleDistribution[0].delivery == 1"><span class="glyphicon glyphicon-ok"></span></button> | <button class="btn btn-success" v-if="pointSale.pointSaleDistribution[0].delivery == 1"><span class="glyphicon glyphicon-ok"></span></button> | ||||
<button class="btn btn-default" v-else data-delivery-point-sale="1" :data-id-point-sale="pointSale.id" @click="pointSaleActiveClick"><span class="glyphicon glyphicon-ok"></span></button> | <button class="btn btn-default" v-else data-delivery-point-sale="1" :data-id-point-sale="pointSale.id" @click="pointSaleActiveClick"><span class="glyphicon glyphicon-ok"></span></button> |
<div class="clr"></div> | <div class="clr"></div> | ||||
<?= $form->field($model, 'id_producer')->hiddenInput() ?> | <?= $form->field($model, 'id_producer')->hiddenInput() ?> | ||||
<?= $form->field($model, 'id_point_sale')->dropDownList(ArrayHelper::map(PointSale::find()->where('id_producer = '.GlobalParam::getCurrentProducerId())->all(), 'id', function($model, $defaultValue) { | |||||
<?= $form->field($model, 'id_point_sale')->dropDownList(ArrayHelper::map(PointSale::searchAll(), 'id', function($model, $defaultValue) { | |||||
return $model['name']; | return $model['name']; | ||||
}), ['prompt' => '--','class' => 'form-control user-id']) ?> | }), ['prompt' => '--','class' => 'form-control user-id']) ?> | ||||
<?= $form->field($model, 'date_begin') ?> | <?= $form->field($model, 'date_begin') ?> |
$options['type_search'] = self::SEARCH_ALL; | $options['type_search'] = self::SEARCH_ALL; | ||||
} | } | ||||
if($class == 'common\models\PointSale' && !isset($options['status'])) { | |||||
$params['status'] = 1; | |||||
} | |||||
$records = $class::find(); | $records = $class::find(); | ||||
// With | // With |
'delivery_wednesday', 'delivery_thursday', 'delivery_friday', | 'delivery_wednesday', 'delivery_thursday', 'delivery_friday', | ||||
'delivery_saturday', 'delivery_sunday', 'default', 'is_bread_box'], 'boolean'], | 'delivery_saturday', 'delivery_sunday', 'default', 'is_bread_box'], 'boolean'], | ||||
['point_production', 'default', 'value' => 0], | ['point_production', 'default', 'value' => 0], | ||||
[['id_producer', 'id_user', 'maximum_number_orders'], 'integer'], | |||||
[['id_producer', 'id_user', 'maximum_number_orders', 'status'], 'integer'], | |||||
['id_producer', 'required'], | ['id_producer', 'required'], | ||||
[['users', 'users_comment', 'code'], 'safe'], | [['users', 'users_comment', 'code'], 'safe'], | ||||
[['product_price_percent'], 'double'], | [['product_price_percent'], 'double'], | ||||
'maximum_number_orders' => 'Nombre maximum de commandes', | 'maximum_number_orders' => 'Nombre maximum de commandes', | ||||
'is_bread_box' => 'Boîte à pain', | 'is_bread_box' => 'Boîte à pain', | ||||
'bread_box_code' => 'Code boîte à pain', | 'bread_box_code' => 'Code boîte à pain', | ||||
'status' => 'Statut' | |||||
]; | ]; | ||||
} | } | ||||
$query = PointSale::find() | $query = PointSale::find() | ||||
->with($optionsSearch['with']) | ->with($optionsSearch['with']) | ||||
->innerJoinWith($optionsSearch['join_with'], true) | ->innerJoinWith($optionsSearch['join_with'], true) | ||||
->where(['point_sale.id_producer' => GlobalParam::getCurrentProducerId()]) | |||||
->orderBy('is_bread_box ASC, name ASC') | |||||
; | |||||
->where([ | |||||
'status' => 1, | |||||
'point_sale.id_producer' => GlobalParam::getCurrentProducerId() | |||||
]) | |||||
->orderBy('is_bread_box ASC, name ASC'); | |||||
$dataProvider = new ActiveDataProvider([ | $dataProvider = new ActiveDataProvider([ | ||||
'query' => $query, | 'query' => $query, |
<?php | |||||
use yii\db\Migration; | |||||
use yii\db\Schema; | |||||
/** | |||||
* Class m230119_083942_point_sale_add_status | |||||
*/ | |||||
class m230119_083942_point_sale_add_status extends Migration | |||||
{ | |||||
/** | |||||
* {@inheritdoc} | |||||
*/ | |||||
public function safeUp() | |||||
{ | |||||
$this->addColumn('point_sale', 'status', Schema::TYPE_SMALLINT . ' NOT NULL DEFAULT 1'); | |||||
} | |||||
/** | |||||
* {@inheritdoc} | |||||
*/ | |||||
public function safeDown() | |||||
{ | |||||
$this->dropColumn('point_sale', 'status'); | |||||
} | |||||
} |
$pointsSaleArray = $pointsSaleArray->where(['id_producer' => $idProducer]) | $pointsSaleArray = $pointsSaleArray->where(['id_producer' => $idProducer]) | ||||
->andWhere( | ->andWhere( | ||||
'restricted_access = 0 OR (restricted_access = 1 AND (SELECT COUNT(*) FROM user_point_sale WHERE point_sale.id = user_point_sale.id_point_sale AND user_point_sale.id_user = :id_user) > 0)' | |||||
'status = 1 AND (restricted_access = 0 OR (restricted_access = 1 AND (SELECT COUNT(*) FROM user_point_sale WHERE point_sale.id = user_point_sale.id_point_sale AND user_point_sale.id_user = :id_user) > 0))' | |||||
) | ) | ||||
->params([':id_user' => User::getCurrentId()]) | ->params([':id_user' => User::getCurrentId()]) | ||||
->orderBy('code ASC, restricted_access ASC, is_bread_box ASC, `default` DESC, name ASC') | ->orderBy('code ASC, restricted_access ASC, is_bread_box ASC, `default` DESC, name ASC') |
->where([ | ->where([ | ||||
'id_producer' => $this->getProducer( | 'id_producer' => $this->getProducer( | ||||
)->id, | )->id, | ||||
'restricted_access' => 0 | |||||
'restricted_access' => 0, | |||||
'status' => 1 | |||||
])->orderBy( | ])->orderBy( | ||||
'default DESC, is_bread_box ASC, name ASC' | 'default DESC, is_bread_box ASC, name ASC' | ||||
), | ), |