@@ -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']) ; |
@@ -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> |
@@ -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', |
@@ -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) ; | |||
}, |
@@ -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([ |
@@ -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>' ; | |||
} | |||
} |
@@ -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([ |
@@ -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([ |