namespace backend\controllers; | namespace backend\controllers; | ||||
use common\models\Product; | |||||
use common\models\User ; | use common\models\User ; | ||||
use common\models\Document ; | |||||
use common\helpers\GlobalParam ; | use common\helpers\GlobalParam ; | ||||
use common\models\Order ; | |||||
use yii\base\UserException; | |||||
class DocumentController extends BackendController | class DocumentController extends BackendController | ||||
{ | { | ||||
if ($model->load(Yii::$app->request->post())) { | if ($model->load(Yii::$app->request->post())) { | ||||
$model->id_producer = GlobalParam::getCurrentProducerId() ; | $model->id_producer = GlobalParam::getCurrentProducerId() ; | ||||
$model->reference = $model->generateReference() ; | |||||
if($model->save()) { | if($model->save()) { | ||||
Yii::$app->getSession()->setFlash('success', $this->getFlashMessage('create', $model)); | Yii::$app->getSession()->setFlash('success', $this->getFlashMessage('create', $model)); | ||||
return $this->redirect(['index']); | |||||
return $this->redirect(['/'.$model->getControllerUrlPath().'/update', 'id' => $model->id]); | |||||
} | } | ||||
else { | else { | ||||
Yii::$app->getSession()->setFlash('error', 'Un problème est survenu lors de la création du document.'); | Yii::$app->getSession()->setFlash('error', 'Un problème est survenu lors de la création du document.'); | ||||
'id' => $id | 'id' => $id | ||||
]) ; | ]) ; | ||||
if($model->isStatusValid()) { | |||||
throw new UserException('Vous ne pouvez pas modifier un document validé.'); | |||||
} | |||||
if ($model && $model->load(Yii::$app->request->post()) && $model->save()) { | if ($model && $model->load(Yii::$app->request->post()) && $model->save()) { | ||||
Yii::$app->getSession()->setFlash('success', $this->getFlashMessage('update', $model)); | Yii::$app->getSession()->setFlash('success', $this->getFlashMessage('update', $model)); | ||||
return ['return' => 'error'] ; | return ['return' => 'error'] ; | ||||
} | } | ||||
public function actionAjaxValidateDocument($idDocument, $classDocument) | |||||
{ | |||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | |||||
if($idDocument > 0 && Document::isValidClass($classDocument)) { | |||||
$document = $classDocument::searchOne([ | |||||
'id' => $idDocument | |||||
]) ; | |||||
if($document) { | |||||
$document->changeStatus(Document::STATUS_VALID) ; | |||||
$document->save() ; | |||||
return ['return' => 'success'] ; | |||||
} | |||||
} | |||||
return ['return' => 'error'] ; | |||||
} | |||||
public function actionAjaxInit($idDocument, $classDocument) | public function actionAjaxInit($idDocument, $classDocument) | ||||
{ | { | ||||
]) ; | ]) ; | ||||
if($document) { | if($document) { | ||||
$productsArray = Product::searchAll([], [ | |||||
'as_array' => true, | |||||
]) ; | |||||
$ordersArray = [] ; | |||||
foreach($document->orders as $order) { | |||||
$order->init() ; | |||||
$productsOrderArray = [] ; | |||||
foreach($order->productOrder as $productOrder) { | |||||
$productsOrderArray[$productOrder->id] = $productOrder->getAttributes() ; | |||||
} | |||||
$ordersArray[$order->id] = array_merge( | |||||
$order->getAttributes(), | |||||
[ | |||||
'productOrder' => $productsOrderArray, | |||||
] | |||||
); | |||||
} | |||||
return [ | return [ | ||||
'return' => 'success', | |||||
'address' => $document->address, | |||||
'idUser' => $document->user->id | |||||
'return' => 'success', | |||||
'document' => array_merge($document->getAttributes(), [ | |||||
'html_label' => $document->getHtmlLabel(), | |||||
'class' => $document->getClass() | |||||
]), | |||||
'idUser' => $document->user->id, | |||||
'products' => ArrayHelper::map($productsArray, 'id', function($product) { | |||||
$product['wording_unit'] = Product::strUnit($product['unit']) ; | |||||
return $product; | |||||
}), | |||||
'orders' => $ordersArray, | |||||
'total' => $document->getAmount(Order::AMOUNT_TOTAL) | |||||
] ; | ] ; | ||||
} | } | ||||
} | } | ||||
return ['return' => 'error'] ; | return ['return' => 'error'] ; | ||||
} | } | ||||
public function actionAjaxAddProduct($idDocument, $classDocument, $idProduct, $quantity, $price) | |||||
{ | |||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | |||||
if(Document::isValidClass($classDocument)) { | |||||
$document = $classDocument::searchOne([ | |||||
'id' => $idDocument | |||||
]) ; | |||||
$product = Product::searchOne([ | |||||
'id' => $idProduct | |||||
]) ; | |||||
if($document && $product) { | |||||
if(count($document->orders) == 0) { | |||||
$order = new Order ; | |||||
$order->id_user = $document->id_user ; | |||||
$order->id_point_sale = null ; | |||||
$order->id_distribution = null ; | |||||
$order->origin = Order::ORIGIN_ADMIN ; | |||||
$order->date = date('Y-m-d H:i:s'); | |||||
$fieldIdDocument = 'id_'.$classDocument::tableName() ; | |||||
$order->$fieldIdDocument = $document->id ; | |||||
$order->save() ; | |||||
} | |||||
else { | |||||
$order = $document->orders[0] ; | |||||
} | |||||
if($order) { | |||||
$productOrder = new ProductOrder ; | |||||
$productOrder->id_order = $order->id ; | |||||
$productOrder->id_product = $idProduct ; | |||||
$quantity = $quantity / Product::$unitsArray[$product->unit]['coefficient']; | |||||
$productOrder->quantity = $quantity ; | |||||
$productOrder->price = (float) $price ; | |||||
$productOrder->unit = $product->unit ; | |||||
$productOrder->step = $product->step ; | |||||
$productOrder->id_tax_rate = $productOrder->id_tax_rate ? | |||||
$product->taxRate->id : GlobalParam::getCurrentProducer()->taxRate->id ; | |||||
$productOrder->save() ; | |||||
return [ | |||||
'return' => 'success', | |||||
] ; | |||||
} | |||||
} | |||||
} | |||||
return [ | |||||
'return' => 'error' | |||||
] ; | |||||
} | |||||
public function actionAjaxDeleteProductOrder($idProductOrder) | |||||
{ | |||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | |||||
$productOrder = ProductOrder::searchOne([ | |||||
'id' => $idProductOrder | |||||
]) ; | |||||
if($productOrder) { | |||||
$productOrder->delete() ; | |||||
return [ | |||||
'return' => 'success' | |||||
] ; | |||||
} | |||||
return [ | |||||
'return' => 'error' | |||||
] ; | |||||
} | |||||
protected function getClass() | protected function getClass() | ||||
{ | { | ||||
$class = get_class($this); | $class = get_class($this); |
* pris connaissance de la licence CeCILL, et que vous en avez accepté les | * pris connaissance de la licence CeCILL, et que vous en avez accepté les | ||||
* termes. | * termes. | ||||
*/ | */ | ||||
use yii\helpers\Html; | use yii\helpers\Html; | ||||
use yii\widgets\ActiveForm; | use yii\widgets\ActiveForm; | ||||
use common\models\Product; | use common\models\Product; | ||||
?> | ?> | ||||
<div class="document-form" id="app-document-form" data-class-document="<?= $model->getClass() ?>" data-id-document="<?= ($model->id > 0) ? $model->id : $model->id ?>"> | |||||
<div class="document-form" id="app-document-form" data-class-document="<?= $model->getClass() ?>" | |||||
data-id-document="<?= ($model->id > 0) ? $model->id : $model->id ?>"> | |||||
<div class="<?php if($action == 'create') : ?>col-md-12<?php else : ?>col-md-4<?php endif; ?>"> | |||||
<div class="<?= ($action == 'update') ? 'col-md-6' : '' ?>"> | |||||
<div class="panel panel-default"> | <div class="panel panel-default"> | ||||
<div class="panel-heading"> | <div class="panel-heading"> | ||||
Informations | |||||
Général | |||||
</div> | </div> | ||||
<div class="panel-body"> | <div class="panel-body"> | ||||
<?php $form = ActiveForm::begin(); ?> | <?php $form = ActiveForm::begin(); ?> | ||||
<?= $form->field($model, 'name')->label('Nom du document') ?> | <?= $form->field($model, 'name')->label('Nom du document') ?> | ||||
<?php $usersArray = User::findBy()->all() ; ?> | |||||
<?= $form->field($model, 'id_user', [ | |||||
'template' => '{label} <a href="'.Yii::$app->urlManager->createUrl(['user/create']).'" class="btn btn-xs btn-default">Nouvel utilisateur <span class="glyphicon glyphicon-plus"></span></a><div>{input}</div>{hint}', | |||||
]) | |||||
<?php $usersArray = User::findBy()->all(); ?> | |||||
<?= $form->field($model, 'id_user', [ | |||||
'template' => '{label} <a href="' . Yii::$app->urlManager->createUrl(['user/create']) . '" class="btn btn-xs btn-default">Nouvel utilisateur <span class="glyphicon glyphicon-plus"></span></a><div>{input}</div>{hint}', | |||||
]) | |||||
->dropDownList( | ->dropDownList( | ||||
ArrayHelper::map($usersArray, 'user_id', function($model) { return $model['lastname'].' '.$model['name']; }), | |||||
ArrayHelper::map($usersArray, 'user_id', function ($model) { | |||||
return $model['lastname'] . ' ' . $model['name']; | |||||
}), | |||||
[ | [ | ||||
'@change' => 'changeUser', | |||||
'prompt' => '--', | |||||
'v-model' => 'idUser', | |||||
'@change' => 'changeUser', | |||||
'prompt' => '--', | |||||
'v-model' => 'idUser', | |||||
] | ] | ||||
); ?> | ); ?> | ||||
<?= $form->field($model, 'address')->textarea(['rows' => 3, 'v-model' => 'address']) ?> | |||||
<?= $form->field($model, 'address')->textarea(['rows' => 2, 'v-model' => 'document.address']) ?> | |||||
<?php if ($action == 'update'): ?> | |||||
<?= $form->field($model, 'comment')->textarea(['rows' => 2])->hint('Affiché en bas de la facture') ?> | |||||
<?php endif; ?> | |||||
<div class="form-group"> | <div class="form-group"> | ||||
<?= Html::submitButton($model->isNewRecord ? 'Ajouter' : 'Modifier', ['class' => 'btn btn-primary']) ?> | <?= Html::submitButton($model->isNewRecord ? 'Ajouter' : 'Modifier', ['class' => 'btn btn-primary']) ?> | ||||
</div> | </div> | ||||
</div> | </div> | ||||
</div> | </div> | ||||
</div> | </div> | ||||
<?php if($action == 'update'): ?> | |||||
<div class="col-md-8"> | |||||
<?php if ($action == 'update'): ?> | |||||
<div class="col-md-6"> | |||||
<div id="" class="info-box"> | |||||
<span class="info-box-icon bg-green"><i class="fa fa-sticky-note-o"></i></span> | |||||
<div class="info-box-content"> | |||||
<span class="info-box-text"><?= $typeDocument ?> <span v-html="document.html_label"></span></span> | |||||
<span class="info-box-number">{{ document.reference }}</span> | |||||
<span class="info-box-text">Date</span> | |||||
<span class="info-box-number">{{ document.date }}</span> | |||||
</div> | |||||
</div> | |||||
<div id="" class="info-box"> | |||||
<span class="info-box-icon bg-yellow"><i class="fa fa-euro"></i></span> | |||||
<div class="info-box-content"> | |||||
<span class="info-box-text">Total (TTC)</span> | |||||
<span class="info-box-number">{{ formatPrice(total) }}</span> | |||||
</div> | |||||
</div> | |||||
<div id="" class="info-box"> | |||||
<span class="info-box-icon bg-blue"><i class="fa fa-download"></i></span> | |||||
<div class="info-box-content"> | |||||
<a href="#" class="btn btn-default">Télécharger (PDF)</a> | |||||
</div> | |||||
</div> | |||||
<div id="" class="info-box"> | |||||
<span class="info-box-icon bg-red"><i class="fa fa-flash"></i></span> | |||||
<div class="info-box-content"> | |||||
<a v-if="document.status == 'draft' && document.class == 'Invoice'" class="btn btn-default" @click="validateDocument">Valider le document</a> | |||||
</div> | |||||
</div> | |||||
</div> | |||||
<div class="clr"></div> | |||||
<div class=""> | |||||
<div class="panel panel-default" id="block-add-product"> | |||||
<div class="panel-heading"> | |||||
Ajouter un produit | |||||
</div> | |||||
<div class="panel-body"> | |||||
<div class="col-md-5"> | |||||
<select class="form-control" v-model="productAddId" | |||||
@change="changeProductAdd"> | |||||
<option value="0" selected="selected">--</option> | |||||
<option v-for="product in productsArray" :value="product.id"> | |||||
{{ product.name }} | |||||
</option> | |||||
</select> | |||||
</div> | |||||
<template v-if="productAddId > 0"> | |||||
<div class="col-md-2"> | |||||
<div class="input-group"> | |||||
<input type="text" class="form-control input-price" | |||||
v-model="productAddPrice"/> | |||||
<span class="input-group-addon"><span | |||||
class="glyphicon glyphicon-euro"></span></span> | |||||
</div> | |||||
</div> | |||||
<div class="col-md-3"> | |||||
<div class="input-group input-group-quantity"> | |||||
<span class="input-group-btn"> | |||||
<button class="btn btn-default" type="button" | |||||
@click="changeQuantityProductAdd(-1)">-</button> | |||||
</span> | |||||
<input type="text" class="form-control input-quantity" | |||||
v-model="productAddQuantity"/> | |||||
<span class="input-group-addon">{{ productsArray[productAddId].wording_unit }}</span> | |||||
<span class="input-group-btn"> | |||||
<button class="btn btn-default" | |||||
type="button" | |||||
@click="changeQuantityProductAdd(1)">+</button> | |||||
</span> | |||||
</div> | |||||
</div> | |||||
<div class="col-md-2"> | |||||
<button class="btn btn-primary" value="Ajouter" | |||||
@click="submitProductAdd">Ajouter | |||||
</button> | |||||
</div> | |||||
</template> | |||||
<div class="clr"></div> | |||||
</div> | |||||
</div> | |||||
<div class="panel panel-default"> | <div class="panel panel-default"> | ||||
<div class="panel-heading"> | <div class="panel-heading"> | ||||
Produits | Produits | ||||
</div> | </div> | ||||
<div class="panel-body"> | <div class="panel-body"> | ||||
<div id="block-list-products"> | |||||
<table class="table table-bordered" v-if="total > 0"> | |||||
<thead> | |||||
<tr> | |||||
<td>Nom</td> | |||||
<td>Prix (unité)</td> | |||||
<td>Quantité</td> | |||||
<td>Total</td> | |||||
<td>Supprimer</td> | |||||
</tr> | |||||
</thead> | |||||
<tbody> | |||||
<template v-for="order in ordersArray"> | |||||
<tr v-for="productOrder in order.productOrder"> | |||||
<td>{{ | |||||
productsArray[productOrder.id_product].name | |||||
}} | |||||
</td> | |||||
<td>{{ formatPrice(productOrder.price) }}</td> | |||||
<td>{{ productOrder.quantity }}</td> | |||||
<td>{{ formatPrice(productOrder.quantity * | |||||
productOrder.price) }} | |||||
</td> | |||||
<td> | |||||
<a class="btn btn-default" @click="deleteProductOrder(productOrder.id)"> | |||||
<span class="glyphicon glyphicon-trash"></span> | |||||
</a> | |||||
</td> | |||||
</tr> | |||||
</template> | |||||
<tr> | |||||
<td colspan="3"><strong>Total</strong></td> | |||||
<td><strong>{{ formatPrice(total) }}</strong></td> | |||||
<td></td> | |||||
</tr> | |||||
</tbody> | |||||
</table> | |||||
<div v-else class="alert alert-info"> | |||||
Aucun produit. | |||||
</div> | |||||
</div> | |||||
</div> | </div> | ||||
</div> | </div> | ||||
</div> | </div> | ||||
<?php endif; ?> | <?php endif; ?> | ||||
</div> | </div> |
'filterModel' => $searchModel, | 'filterModel' => $searchModel, | ||||
'dataProvider' => $dataProvider, | 'dataProvider' => $dataProvider, | ||||
'columns' => [ | 'columns' => [ | ||||
'reference', | |||||
[ | |||||
'attribute' => 'status', | |||||
'header' => 'Statut', | |||||
'format' => 'raw', | |||||
'value' => function($model) { | |||||
return $model->getHtmlLabel() ; | |||||
} | |||||
], | |||||
[ | |||||
'attribute' => 'reference', | |||||
'value' => function($model) { | |||||
if(strlen($model->reference) > 0) { | |||||
return $model->reference ; | |||||
} | |||||
return '' ; | |||||
} | |||||
], | |||||
'name', | 'name', | ||||
[ | [ | ||||
'attribute' => 'id_user', | 'attribute' => 'id_user', | ||||
'contentOptions' => ['class' => 'column-actions'], | 'contentOptions' => ['class' => 'column-actions'], | ||||
'buttons' => [ | 'buttons' => [ | ||||
'update' => function ($url, $model) { | 'update' => function ($url, $model) { | ||||
return Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, [ | |||||
return ($model->isStatusDraft() ? Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, [ | |||||
'title' => Yii::t('app', 'Modifier'), 'class' => 'btn btn-default' | 'title' => Yii::t('app', 'Modifier'), 'class' => 'btn btn-default' | ||||
]); | |||||
]) : ''); | |||||
}, | }, | ||||
'delete' => function ($url, $model) { | 'delete' => function ($url, $model) { | ||||
return Html::a('<span class="glyphicon glyphicon-trash"></span>', $url, [ | |||||
return ($model->isStatusDraft() ? Html::a('<span class="glyphicon glyphicon-trash"></span>', $url, [ | |||||
'title' => Yii::t('app', 'Supprimer'), 'class' => 'btn btn-default' | 'title' => Yii::t('app', 'Supprimer'), 'class' => 'btn btn-default' | ||||
]); | |||||
]) : ''); | |||||
} | } | ||||
], | ], | ||||
], | ], |
.report-index #report .section .comma:last-child { | .report-index #report .section .comma:last-child { | ||||
display: none; | display: none; | ||||
} | } | ||||
/* line 4, ../sass/document/_form.scss */ | |||||
.document-form .info-box .info-box-text { | |||||
font-size: 13px; | |||||
} | |||||
/* line 7, ../sass/document/_form.scss */ | |||||
.document-form .info-box .info-box-number { | |||||
font-size: 15px; | |||||
} | |||||
/* line 12, ../sass/document/_form.scss */ | |||||
.document-form #block-add-product .input-price { | |||||
text-align: center; | |||||
} | |||||
/* line 16, ../sass/document/_form.scss */ | |||||
.document-form #block-add-product .input-group-quantity .input-quantity { | |||||
text-align: center; | |||||
} |
var app = new Vue({ | var app = new Vue({ | ||||
el: '#app-document-form', | el: '#app-document-form', | ||||
data: { | data: { | ||||
document: [], | |||||
idDocument: 0, | idDocument: 0, | ||||
typeDocument: '', | typeDocument: '', | ||||
idUser: '', | |||||
address : '' | |||||
idUser: '', | |||||
productsArray: [], | |||||
productAddId: 0, | |||||
productAddPrice: '', | |||||
productAddQuantity: 1, | |||||
ordersArray: [], | |||||
total: 0 | |||||
}, | }, | ||||
mounted: function() { | mounted: function() { | ||||
this.init() ; | this.init() ; | ||||
}, | }, | ||||
methods: { | methods: { | ||||
formatPrice: formatPrice, | |||||
init: function() { | init: function() { | ||||
var idDocument = $('#app-document-form').attr('data-id-document') ; | var idDocument = $('#app-document-form').attr('data-id-document') ; | ||||
this.idDocument = idDocument ; | |||||
var classDocument = $('#app-document-form').attr('data-class-document') ; | var classDocument = $('#app-document-form').attr('data-class-document') ; | ||||
this.classDocument = classDocument ; | |||||
if(idDocument) { | if(idDocument) { | ||||
var app = this ; | var app = this ; | ||||
}}) | }}) | ||||
.then(function(response) { | .then(function(response) { | ||||
if(response.data.return == 'success') { | if(response.data.return == 'success') { | ||||
app.address = response.data.address ; | |||||
app.document = response.data.document ; | |||||
app.idUser = response.data.idUser ; | app.idUser = response.data.idUser ; | ||||
app.productsArray = response.data.products ; | |||||
app.ordersArray = response.data.orders ; | |||||
app.total = response.data.total ; | |||||
} | } | ||||
}) ; | }) ; | ||||
} | } | ||||
}}) | }}) | ||||
.then(function(response) { | .then(function(response) { | ||||
if(response.data.return == 'success') { | if(response.data.return == 'success') { | ||||
app.address = response.data.address ; | |||||
Vue.set(app.document, 'address', response.data.address); | |||||
} | } | ||||
else { | else { | ||||
app.address = '' ; | |||||
app.document.address = '' ; | |||||
} | } | ||||
}) ; | }) ; | ||||
}, | |||||
formatPrice: formatPrice, | |||||
validateDocument: function() { | |||||
var app = this ; | |||||
axios.get(UrlManager.getBaseUrlAbsolute()+"document/ajax-validate-document",{params: { | |||||
idDocument: app.idDocument, | |||||
classDocument: app.classDocument, | |||||
}}) | |||||
.then(function(response) { | |||||
app.init() ; | |||||
}) ; | |||||
}, | |||||
getStepProductAdd: function() { | |||||
return parseInt(this.productsArray[this.productAddId].step) ; | |||||
}, | |||||
changeProductAdd: function(event) { | |||||
var idProduct = event.currentTarget.value ; | |||||
this.productAddId = idProduct ; | |||||
this.productAddPrice = parseFloat(this.productsArray[idProduct].price).toFixed(2) ; | |||||
this.productAddQuantity = this.getStepProductAdd() ; | |||||
}, | |||||
changeQuantityProductAdd: function(quantity) { | |||||
var step = this.getStepProductAdd() ; | |||||
quantity = quantity * step ; | |||||
this.productAddQuantity += quantity ; | |||||
if(this.productAddQuantity < 1) { | |||||
this.productAddQuantity = step ; | |||||
} | |||||
}, | |||||
submitProductAdd: function() { | |||||
var app = this ; | |||||
axios.get(UrlManager.getBaseUrlAbsolute()+"document/ajax-add-product",{params: { | |||||
idDocument: app.idDocument, | |||||
classDocument: app.classDocument, | |||||
idProduct: app.productAddId, | |||||
quantity: app.productAddQuantity, | |||||
price: app.productAddPrice, | |||||
}}) | |||||
.then(function(response) { | |||||
app.productAddId = 0 ; | |||||
app.init() ; | |||||
alert('Produit ajouté') ; | |||||
}) ; | |||||
}, | |||||
deleteProductOrder: function(idProductOrder) { | |||||
var app = this ; | |||||
axios.get(UrlManager.getBaseUrlAbsolute()+"document/ajax-delete-product-order",{params: { | |||||
idProductOrder: idProductOrder | |||||
}}) | |||||
.then(function(response) { | |||||
app.init() ; | |||||
}) ; | |||||
} | } | ||||
} | } | ||||
}); | }); |
.document-form { | |||||
.info-box { | |||||
.info-box-text { | |||||
font-size: 13px ; | |||||
} | |||||
.info-box-number { | |||||
font-size: 15px ; | |||||
} | |||||
} | |||||
#block-add-product { | |||||
.input-price { | |||||
text-align: center ; | |||||
} | |||||
.input-group-quantity { | |||||
.input-quantity { | |||||
text-align: center ; | |||||
} | |||||
} | |||||
} | |||||
} |
@import "user/_form.scss" ; | @import "user/_form.scss" ; | ||||
@import "producer/_update.scss" ; | @import "producer/_update.scss" ; | ||||
@import "point_sale/_index.scss" ; | @import "point_sale/_index.scss" ; | ||||
@import "report/_index.scss" ; | |||||
@import "report/_index.scss" ; | |||||
@import "document/_form.scss" ; |
->with($optionsSearch['with']) | ->with($optionsSearch['with']) | ||||
->joinWith($optionsSearch['join_with'], true) | ->joinWith($optionsSearch['join_with'], true) | ||||
->where(['delivery_note.id_producer' => GlobalParam::getCurrentProducerId()]) | ->where(['delivery_note.id_producer' => GlobalParam::getCurrentProducerId()]) | ||||
->orderBy('delivery_note.reference DESC') | |||||
->orderBy('delivery_note.status ASC, delivery_note.reference DESC') | |||||
; | ; | ||||
$dataProvider = new ActiveDataProvider([ | $dataProvider = new ActiveDataProvider([ |
class Document extends ActiveRecordCommon | class Document extends ActiveRecordCommon | ||||
{ | { | ||||
const STATUS_DRAFT = 'draft' ; | |||||
const STATUS_VALID = 'valid' ; | |||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
[['date'], 'safe'], | [['date'], 'safe'], | ||||
[['comment', 'address'], 'string'], | [['comment', 'address'], 'string'], | ||||
[['id_user','id_producer'], 'integer'], | [['id_user','id_producer'], 'integer'], | ||||
[['name', 'reference'], 'string', 'max' => 255], | |||||
[['name', 'reference', 'status'], 'string', 'max' => 255], | |||||
]; | ]; | ||||
} | } | ||||
'comment' => 'Commentaire', | 'comment' => 'Commentaire', | ||||
'id_user' => 'Utilisateur', | 'id_user' => 'Utilisateur', | ||||
'address' => 'Adresse', | 'address' => 'Adresse', | ||||
'id_producer' => 'Producteur' | |||||
'id_producer' => 'Producteur', | |||||
'status' => 'Statut', | |||||
]; | ]; | ||||
} | } | ||||
{ | { | ||||
return str_replace('common\models\\','',get_class($this)) ; | return str_replace('common\models\\','',get_class($this)) ; | ||||
} | } | ||||
public function getControllerUrlPath() | |||||
{ | |||||
$class = $this->getClass() ; | |||||
$path = strtolower($class) ; | |||||
if($path == 'deliverynote') { | |||||
$path = 'delivery_note' ; | |||||
} | |||||
return $path ; | |||||
} | |||||
public function isValidClass($typeDocument) | |||||
{ | |||||
return in_array($typeDocument, ['Invoice', 'DeliveryNote', 'Quotation']) ; | |||||
} | |||||
public function generateReference() | public function generateReference() | ||||
{ | { | ||||
} | } | ||||
} | } | ||||
} | } | ||||
public function isValidClass($typeDocument) | |||||
public function changeStatus($status) | |||||
{ | { | ||||
return in_array($typeDocument, ['Invoice', 'DeliveryNote', 'Quotation']) ; | |||||
if($status == Document::STATUS_VALID) { | |||||
$this->status = $status ; | |||||
$this->reference = $this->generateReference() ; | |||||
} | |||||
} | |||||
public function getStatusWording() | |||||
{ | |||||
return ($this->status == self::STATUS_DRAFT) ? 'Brouillon' : 'Validé' ; | |||||
} | |||||
public function getStatusCssClass() | |||||
{ | |||||
return ($this->status == self::STATUS_DRAFT) ? 'default' : 'success' ; | |||||
} | |||||
public function getHtmlLabel() | |||||
{ | |||||
$label = $this->getStatusWording(); | |||||
$classLabel = $this->getStatusCssClass() ; | |||||
return '<span class="label label-'.$classLabel.'">'.$label.'</span>' ; | |||||
} | |||||
public function isStatus($status) | |||||
{ | |||||
return $this->status == $status ; | |||||
} | |||||
public function isStatusDraft() | |||||
{ | |||||
return $this->isStatus(self::STATUS_DRAFT) ; | |||||
} | } | ||||
public function isStatusValid() | |||||
{ | |||||
return $this->isStatus(self::STATUS_VALID) ; | |||||
} | |||||
} | } |
->with($optionsSearch['with']) | ->with($optionsSearch['with']) | ||||
->joinWith($optionsSearch['join_with'], true) | ->joinWith($optionsSearch['join_with'], true) | ||||
->where(['invoice.id_producer' => GlobalParam::getCurrentProducerId()]) | ->where(['invoice.id_producer' => GlobalParam::getCurrentProducerId()]) | ||||
->orderBy('invoice.reference DESC') | |||||
->orderBy('invoice.status ASC, invoice.reference DESC') | |||||
; | ; | ||||
$dataProvider = new ActiveDataProvider([ | $dataProvider = new ActiveDataProvider([ |
*/ | */ | ||||
public function initAmount() | public function initAmount() | ||||
{ | { | ||||
$this->amount = 0 ; | |||||
$this->weight = 0 ; | |||||
if (isset($this->productOrder)) { | if (isset($this->productOrder)) { | ||||
foreach ($this->productOrder as $productOrder) { | foreach ($this->productOrder as $productOrder) { | ||||
$this->amount += $productOrder->price * $productOrder->quantity; | $this->amount += $productOrder->price * $productOrder->quantity; |
->with($optionsSearch['with']) | ->with($optionsSearch['with']) | ||||
->joinWith($optionsSearch['join_with'], true) | ->joinWith($optionsSearch['join_with'], true) | ||||
->where(['quotation.id_producer' => GlobalParam::getCurrentProducerId()]) | ->where(['quotation.id_producer' => GlobalParam::getCurrentProducerId()]) | ||||
->orderBy('quotation.reference DESC') | |||||
->orderBy('quotation.status ASC, quotation.reference DESC') | |||||
; | ; | ||||
$dataProvider = new ActiveDataProvider([ | $dataProvider = new ActiveDataProvider([ |
<?php | |||||
use yii\db\Migration; | |||||
use yii\db\Schema; | |||||
class m200109_070952_module_devis_bl_factures_champs_order_valeur_default extends Migration | |||||
{ | |||||
public function safeUp() | |||||
{ | |||||
$this->alterColumn('order', 'id_point_sale', Schema::TYPE_INTEGER.' DEFAULT NULL') ; | |||||
$this->alterColumn('order', 'id_distribution', Schema::TYPE_INTEGER.' DEFAULT NULL') ; | |||||
} | |||||
public function safeDown() | |||||
{ | |||||
$this->alterColumn('order', 'id_point_sale', Schema::TYPE_INTEGER) ; | |||||
$this->alterColumn('order', 'id_distribution', Schema::TYPE_INTEGER) ; | |||||
} | |||||
} |