public $css = []; | public $css = []; | ||||
public $js = []; | public $js = []; | ||||
public $depends = [ | public $depends = [ | ||||
'common\assets\CommonAsset' | |||||
'common\assets\CommonAsset', | |||||
'backend\assets\AppAsset', | |||||
]; | ]; | ||||
public function __construct() | public function __construct() |
return $this->render('/document/create', [ | return $this->render('/document/create', [ | ||||
'title' => $this->getTitle('Ajouter'), | 'title' => $this->getTitle('Ajouter'), | ||||
'documentType' => $this->getDocumentType(), | |||||
'typeDocument' => $this->getDocumentType(), | |||||
'model' => $model, | 'model' => $model, | ||||
]); | ]); | ||||
} | } | ||||
*/ | */ | ||||
public function actionUpdate($id) | public function actionUpdate($id) | ||||
{ | { | ||||
$request = Yii::$app->request; | |||||
$model = $this->findModel($id) ; | $model = $this->findModel($id) ; | ||||
$class = $this->getClass(); | |||||
$model = $class::searchOne([ | |||||
'id' => $id | |||||
]) ; | |||||
if ($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 $this->redirect(['index']); | |||||
} else { | |||||
return $this->render('update', [ | |||||
'title' => $this->getTitle('Modifier'), | |||||
'documentType' => $this->getDocumentType(), | |||||
'model' => $model, | |||||
]); | |||||
} | } | ||||
return $this->render('/document/update', [ | |||||
'title' => $this->getTitle('Modifier'), | |||||
'typeDocument' => $this->getDocumentType(), | |||||
'model' => $model, | |||||
]); | |||||
} | } | ||||
public function actionAddressUser($idUser) | |||||
public function actionAjaxAddressUser($idUser) | |||||
{ | { | ||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | ||||
return ['return' => 'error'] ; | return ['return' => 'error'] ; | ||||
} | } | ||||
public function actionAjaxInit($idDocument, $classDocument) | |||||
{ | |||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | |||||
if($idDocument > 0 && Document::isValidClass($classDocument)) { | |||||
$document = $classDocument::searchOne([ | |||||
'id' => $idDocument | |||||
]) ; | |||||
if($document) { | |||||
return [ | |||||
'return' => 'success', | |||||
'address' => $document->address, | |||||
'idUser' => $document->user->id | |||||
] ; | |||||
} | |||||
} | |||||
return ['return' => 'error'] ; | |||||
} | |||||
protected function getClass() | protected function getClass() | ||||
{ | { | ||||
$class = get_class($this); | $class = get_class($this); |
?> | ?> | ||||
<div class="document-form" id="app-document-form"> | |||||
<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="col-md-12"> | |||||
<div class="<?php if($action == 'create') : ?>col-md-12<?php else : ?>col-md-4<?php endif; ?>"> | |||||
<div class="panel panel-default"> | <div class="panel panel-default"> | ||||
<div class="panel-heading"> | <div class="panel-heading"> | ||||
Informations | Informations | ||||
</div> | </div> | ||||
</div> | </div> | ||||
</div> | </div> | ||||
<?php if($action == 'update'): ?> | |||||
<div class="col-md-8"> | |||||
<div class="panel panel-default"> | |||||
<div class="panel-heading"> | |||||
Produits | |||||
</div> | |||||
<div class="panel-body"> | |||||
</div> | |||||
</div> | |||||
</div> | |||||
<?php endif; ?> | |||||
</div> | </div> |
use yii\helpers\Html; | use yii\helpers\Html; | ||||
$this->setTitle($title) ; | $this->setTitle($title) ; | ||||
$this->addBreadcrumb(['label' => $documentType.'s', 'url' => ['index']]) ; | |||||
$this->addBreadcrumb(['label' => $typeDocument.'s', 'url' => ['index']]) ; | |||||
$this->addBreadcrumb('Ajouter') ; | $this->addBreadcrumb('Ajouter') ; | ||||
?> | ?> | ||||
<div class="document-create"> | <div class="document-create"> | ||||
<?= $this->render('_form', [ | <?= $this->render('_form', [ | ||||
'action' => 'create', | |||||
'model' => $model, | 'model' => $model, | ||||
'documentType' => $documentType | |||||
'typeDocument' => $typeDocument, | |||||
]) ?> | ]) ?> | ||||
</div> | </div> |
$this->setTitle($title) ; | $this->setTitle($title) ; | ||||
$this->addBreadcrumb(['label' => $documentType.'s', 'url' => ['index']]) ; | |||||
$this->addBreadcrumb(['label' => $typeDocument.'s', 'url' => ['index']]) ; | |||||
$this->addBreadcrumb(['label' => $model->name, 'url' => ['update', 'id' => $model->id]]) ; | $this->addBreadcrumb(['label' => $model->name, 'url' => ['update', 'id' => $model->id]]) ; | ||||
$this->addBreadcrumb('Modifier') ; | $this->addBreadcrumb('Modifier') ; | ||||
<div class="product-update"> | <div class="product-update"> | ||||
<?= $this->render('_form', [ | <?= $this->render('_form', [ | ||||
'action' => 'update', | |||||
'model' => $model, | 'model' => $model, | ||||
'documentType' => $documentType | |||||
'typeDocument' => $typeDocument, | |||||
]) ?> | ]) ?> | ||||
</div> | </div> |
'value' => function($invoice) { | 'value' => function($invoice) { | ||||
return $invoice->getAmount(Order::AMOUNT_TOTAL, true) ; | return $invoice->getAmount(Order::AMOUNT_TOTAL, true) ; | ||||
} | } | ||||
] | |||||
/*[ | |||||
], | |||||
[ | |||||
'class' => 'yii\grid\ActionColumn', | 'class' => 'yii\grid\ActionColumn', | ||||
'template' => '{update} {delete}', | 'template' => '{update} {delete}', | ||||
'headerOptions' => ['class' => 'column-actions'], | 'headerOptions' => ['class' => 'column-actions'], | ||||
]); | ]); | ||||
} | } | ||||
], | ], | ||||
],*/ | |||||
], | |||||
], | ], | ||||
]); ?> | ]); ?> | ||||
</div> | </div> |
var app = new Vue({ | var app = new Vue({ | ||||
el: '#app-document-form', | el: '#app-document-form', | ||||
data: { | data: { | ||||
idDocument: 0, | |||||
typeDocument: '', | |||||
idUser: '', | idUser: '', | ||||
address : '' | address : '' | ||||
}, | }, | ||||
mounted: function() { | |||||
this.init() ; | |||||
}, | |||||
methods: { | methods: { | ||||
init: function() { | |||||
var idDocument = $('#app-document-form').attr('data-id-document') ; | |||||
var classDocument = $('#app-document-form').attr('data-class-document') ; | |||||
if(idDocument) { | |||||
var app = this ; | |||||
axios.get(UrlManager.getBaseUrlAbsolute()+"document/ajax-init",{params: { | |||||
idDocument: idDocument, | |||||
classDocument: classDocument | |||||
}}) | |||||
.then(function(response) { | |||||
if(response.data.return == 'success') { | |||||
app.address = response.data.address ; | |||||
app.idUser = response.data.idUser ; | |||||
} | |||||
}) ; | |||||
} | |||||
}, | |||||
changeUser: function(event) { | changeUser: function(event) { | ||||
var app = this ; | var app = this ; | ||||
axios.get(UrlManager.getBaseUrlAbsolute()+"document/address-user",{params: { | |||||
axios.get(UrlManager.getBaseUrlAbsolute()+"document/ajax-address-user",{params: { | |||||
idUser: app.idUser | idUser: app.idUser | ||||
}}) | }}) | ||||
.then(function(response) { | .then(function(response) { | ||||
console.log(response.data) ; | |||||
if(response.data.return == 'success') { | if(response.data.return == 'success') { | ||||
app.address = response.data.address ; | app.address = response.data.address ; | ||||
} | } |
} | } | ||||
} | } | ||||
} | } | ||||
public function isValidClass($typeDocument) | |||||
{ | |||||
return in_array($typeDocument, ['Invoice', 'DeliveryNote', 'Quotation']) ; | |||||
} | |||||
} | } |