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 ['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) | ||||
{ | { | ||||
return [ | return [ | ||||
'return' => 'success', | 'return' => 'success', | ||||
'document' => $document->getAttributes(), | |||||
'document' => array_merge($document->getAttributes(), [ | |||||
'html_label' => $document->getHtmlLabel(), | |||||
'class' => $document->getClass() | |||||
]), | |||||
'idUser' => $document->user->id, | 'idUser' => $document->user->id, | ||||
'products' => ArrayHelper::map($productsArray, 'id', function($product) { | 'products' => ArrayHelper::map($productsArray, 'id', function($product) { | ||||
$product['wording_unit'] = Product::strUnit($product['unit']) ; | $product['wording_unit'] = Product::strUnit($product['unit']) ; |
<div id="" class="info-box"> | <div id="" class="info-box"> | ||||
<span class="info-box-icon bg-green"><i class="fa fa-sticky-note-o"></i></span> | <span class="info-box-icon bg-green"><i class="fa fa-sticky-note-o"></i></span> | ||||
<div class="info-box-content"> | <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-number">{{ document.reference }}</span> | ||||
<span class="info-box-text">Date</span> | <span class="info-box-text">Date</span> | ||||
<span class="info-box-number">{{ document.date }}</span> | <span class="info-box-number">{{ document.date }}</span> | ||||
<div id="" class="info-box"> | <div id="" class="info-box"> | ||||
<span class="info-box-icon bg-red"><i class="fa fa-flash"></i></span> | <span class="info-box-icon bg-red"><i class="fa fa-flash"></i></span> | ||||
<div class="info-box-content"> | <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> | </div> | ||||
</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', |
}) ; | }) ; | ||||
}, | }, | ||||
formatPrice: formatPrice, | 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() { | getStepProductAdd: function() { | ||||
return parseInt(this.productsArray[this.productAddId].step) ; | return parseInt(this.productsArray[this.productAddId].step) ; | ||||
}, | }, |
->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', | |||||
]; | ]; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
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>' ; | |||||
} | |||||
} | } |
->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([ |
->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([ |