浏览代码

Modification d'un document : gestion des status (brouillon, validé) #166

refactoring
父节点
当前提交
a35dcb850e
共有 8 个文件被更改,包括 87 次插入11 次删除
  1. +23
    -2
      backend/controllers/DocumentController.php
  2. +2
    -3
      backend/views/document/_form.php
  3. +17
    -1
      backend/views/invoice/index.php
  4. +10
    -0
      backend/web/js/vuejs/document-form.js
  5. +1
    -1
      common/models/DeliveryNoteSearch.php
  6. +32
    -2
      common/models/Document.php
  7. +1
    -1
      common/models/InvoiceSearch.php
  8. +1
    -1
      common/models/QuotationSearch.php

+ 23
- 2
backend/controllers/DocumentController.php 查看文件

@@ -77,7 +77,6 @@ class DocumentController extends BackendController
if ($model->load(Yii::$app->request->post())) {
$model->id_producer = GlobalParam::getCurrentProducerId() ;
$model->reference = $model->generateReference() ;
if($model->save()) {
Yii::$app->getSession()->setFlash('success', $this->getFlashMessage('create', $model));
@@ -143,6 +142,25 @@ class DocumentController extends BackendController
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)
{
@@ -177,7 +195,10 @@ class DocumentController extends BackendController
return [
'return' => 'success',
'document' => $document->getAttributes(),
'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']) ;

+ 2
- 3
backend/views/document/_form.php 查看文件

@@ -90,7 +90,7 @@ use common\models\Producer;
<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">Référence</span>
<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>
@@ -112,8 +112,7 @@ use common\models\Producer;
<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 href="#" class="btn btn-default">Action 1</a>
<a href="#" class="btn btn-default">Action 2</a>
<a v-if="document.status == 'draft' && document.class == 'Invoice'" class="btn btn-default" @click="validateDocument">Valider le document</a>
</div>
</div>
</div>

+ 17
- 1
backend/views/invoice/index.php 查看文件

@@ -54,7 +54,23 @@ $this->addButton(['label' => 'Nouvelle facture <span class="glyphicon glyphicon-
'filterModel' => $searchModel,
'dataProvider' => $dataProvider,
'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',
[
'attribute' => 'id_user',

+ 10
- 0
backend/web/js/vuejs/document-form.js 查看文件

@@ -92,6 +92,16 @@ var app = new Vue({
}) ;
},
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) ;
},

+ 1
- 1
common/models/DeliveryNoteSearch.php 查看文件

@@ -62,7 +62,7 @@ class DeliveryNoteSearch extends DeliveryNote
->with($optionsSearch['with'])
->joinWith($optionsSearch['join_with'], true)
->where(['delivery_note.id_producer' => GlobalParam::getCurrentProducerId()])
->orderBy('delivery_note.reference DESC')
->orderBy('delivery_note.status ASC, delivery_note.reference DESC')
;
$dataProvider = new ActiveDataProvider([

+ 32
- 2
common/models/Document.php 查看文件

@@ -40,6 +40,8 @@ namespace common\models;

class Document extends ActiveRecordCommon
{
const STATUS_DRAFT = 'draft' ;
const STATUS_VALID = 'valid' ;
/**
* @inheritdoc
@@ -51,7 +53,7 @@ class Document extends ActiveRecordCommon
[['date'], 'safe'],
[['comment', 'address'], 'string'],
[['id_user','id_producer'], 'integer'],
[['name', 'reference'], 'string', 'max' => 255],
[['name', 'reference', 'status'], 'string', 'max' => 255],
];
}

@@ -68,7 +70,8 @@ class Document extends ActiveRecordCommon
'comment' => 'Commentaire',
'id_user' => 'Utilisateur',
'address' => 'Adresse',
'id_producer' => 'Producteur'
'id_producer' => 'Producteur',
'status' => 'Statut',
];
}
@@ -191,4 +194,31 @@ class Document extends ActiveRecordCommon
}
}
}

public function changeStatus($status)
{
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>' ;
}


}

+ 1
- 1
common/models/InvoiceSearch.php 查看文件

@@ -62,7 +62,7 @@ class InvoiceSearch extends Invoice
->with($optionsSearch['with'])
->joinWith($optionsSearch['join_with'], true)
->where(['invoice.id_producer' => GlobalParam::getCurrentProducerId()])
->orderBy('invoice.reference DESC')
->orderBy('invoice.status ASC, invoice.reference DESC')
;
$dataProvider = new ActiveDataProvider([

+ 1
- 1
common/models/QuotationSearch.php 查看文件

@@ -62,7 +62,7 @@ class QuotationSearch extends Quotation
->with($optionsSearch['with'])
->joinWith($optionsSearch['join_with'], true)
->where(['quotation.id_producer' => GlobalParam::getCurrentProducerId()])
->orderBy('quotation.reference DESC')
->orderBy('quotation.status ASC, quotation.reference DESC')
;
$dataProvider = new ActiveDataProvider([

正在加载...
取消
保存