Sfoglia il codice sorgente

Modifier un document : informations générales #166

dev
parent
commit
2d8d2e9ade
9 ha cambiato i file con 91 aggiunte e 24 eliminazioni
  1. +2
    -1
      backend/assets/VuejsDocumentFormAsset.php
  2. +36
    -12
      backend/controllers/DocumentController.php
  3. +15
    -2
      backend/views/document/_form.php
  4. +3
    -2
      backend/views/document/create.php
  5. +3
    -2
      backend/views/document/update.php
  6. +3
    -3
      backend/views/invoice/index.php
  7. +24
    -2
      backend/web/js/vuejs/document-form.js
  8. +5
    -0
      common/models/Document.php
  9. +0
    -0
      producer/web/assets/.gitignore

+ 2
- 1
backend/assets/VuejsDocumentFormAsset.php Vedi File

@@ -51,7 +51,8 @@ class VuejsDocumentFormAsset extends \common\components\MyAssetBundle
public $css = [];
public $js = [];
public $depends = [
'common\assets\CommonAsset'
'common\assets\CommonAsset',
'backend\assets\AppAsset',
];
public function __construct()

+ 36
- 12
backend/controllers/DocumentController.php Vedi File

@@ -87,7 +87,7 @@ class DocumentController extends BackendController
return $this->render('/document/create', [
'title' => $this->getTitle('Ajouter'),
'documentType' => $this->getDocumentType(),
'typeDocument' => $this->getDocumentType(),
'model' => $model,
]);
}
@@ -101,24 +101,26 @@ class DocumentController extends BackendController
*/
public function actionUpdate($id)
{
$request = Yii::$app->request;

$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));
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;
@@ -139,6 +141,28 @@ class DocumentController extends BackendController
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()
{
$class = get_class($this);

+ 15
- 2
backend/views/document/_form.php Vedi File

@@ -46,9 +46,9 @@ use common\models\Producer;

?>

<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-heading">
Informations
@@ -76,5 +76,18 @@ use common\models\Producer;
</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>

+ 3
- 2
backend/views/document/create.php Vedi File

@@ -39,14 +39,15 @@ termes.
use yii\helpers\Html;

$this->setTitle($title) ;
$this->addBreadcrumb(['label' => $documentType.'s', 'url' => ['index']]) ;
$this->addBreadcrumb(['label' => $typeDocument.'s', 'url' => ['index']]) ;
$this->addBreadcrumb('Ajouter') ;

?>

<div class="document-create">
<?= $this->render('_form', [
'action' => 'create',
'model' => $model,
'documentType' => $documentType
'typeDocument' => $typeDocument,
]) ?>
</div>

+ 3
- 2
backend/views/document/update.php Vedi File

@@ -40,7 +40,7 @@ use yii\helpers\Html;


$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('Modifier') ;

@@ -48,7 +48,8 @@ $this->addBreadcrumb('Modifier') ;

<div class="product-update">
<?= $this->render('_form', [
'action' => 'update',
'model' => $model,
'documentType' => $documentType
'typeDocument' => $typeDocument,
]) ?>
</div>

+ 3
- 3
backend/views/invoice/index.php Vedi File

@@ -76,8 +76,8 @@ $this->addButton(['label' => 'Nouvelle facture <span class="glyphicon glyphicon-
'value' => function($invoice) {
return $invoice->getAmount(Order::AMOUNT_TOTAL, true) ;
}
]
/*[
],
[
'class' => 'yii\grid\ActionColumn',
'template' => '{update} {delete}',
'headerOptions' => ['class' => 'column-actions'],
@@ -94,7 +94,7 @@ $this->addButton(['label' => 'Nouvelle facture <span class="glyphicon glyphicon-
]);
}
],
],*/
],
],
]); ?>
</div>

+ 24
- 2
backend/web/js/vuejs/document-form.js Vedi File

@@ -38,17 +38,39 @@ termes.
var app = new Vue({
el: '#app-document-form',
data: {
idDocument: 0,
typeDocument: '',
idUser: '',
address : ''
},
mounted: function() {
this.init() ;
},
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) {
var app = this ;
axios.get(UrlManager.getBaseUrlAbsolute()+"document/address-user",{params: {
axios.get(UrlManager.getBaseUrlAbsolute()+"document/ajax-address-user",{params: {
idUser: app.idUser
}})
.then(function(response) {
console.log(response.data) ;
if(response.data.return == 'success') {
app.address = response.data.address ;
}

+ 5
- 0
common/models/Document.php Vedi File

@@ -174,4 +174,9 @@ class Document extends ActiveRecordCommon
}
}
}
public function isValidClass($typeDocument)
{
return in_array($typeDocument, ['Invoice', 'DeliveryNote', 'Quotation']) ;
}
}

+ 0
- 0
producer/web/assets/.gitignore Vedi File


Loading…
Annulla
Salva