Explorar el Código

Possibilité de générer les factures sur base des BL #178

dev
Guillaume Bourgeois hace 4 años
padre
commit
3829d8c60c
Se han modificado 8 ficheros con 129 adiciones y 22 borrados
  1. +4
    -1
      backend/controllers/DistributionController.php
  2. +53
    -4
      backend/controllers/DocumentController.php
  3. +31
    -0
      backend/views/document/_form.php
  4. +1
    -1
      backend/views/invoice/index.php
  5. +27
    -14
      backend/web/js/vuejs/document-form.js
  6. +2
    -1
      common/models/Document.php
  7. +2
    -0
      common/models/Invoice.php
  8. +9
    -1
      common/models/User.php

+ 4
- 1
backend/controllers/DistributionController.php Ver fichero

@@ -1022,7 +1022,10 @@ class DistributionController extends BackendController
if($deliveryNote && $deliveryNote->status == Document::STATUS_VALID) {
return [
'return' => 'error',
'alert' => 'Vous ne pouvez pas modifier un bon de livraison déjà validé.',
'alert' => [
'type' => 'danger',
'message' => 'Vous ne pouvez pas modifier un bon de livraison déjà validé.'
]
] ;
}


+ 53
- 4
backend/controllers/DocumentController.php Ver fichero

@@ -38,6 +38,7 @@

namespace backend\controllers;

use common\models\DeliveryNote;
use common\models\Product;
use common\models\User;
use common\models\Document;
@@ -81,6 +82,9 @@ class DocumentController extends BackendController
$model->id_producer = GlobalParam::getCurrentProducerId();

if ($model->save()) {

$this->processInvoiceViaDeliveryNotes($model) ;

Yii::$app->getSession()->setFlash('success', $this->getFlashMessage('create', $model));
return $this->redirect(['/' . $model->getControllerUrlPath() . '/update', 'id' => $model->id]);
} else {
@@ -95,6 +99,21 @@ class DocumentController extends BackendController
]);
}

public function processInvoiceViaDeliveryNotes($model)
{
if($model->getClass() == 'Invoice') {
if($model->deliveryNotes && is_array($model->deliveryNotes) && count($model->deliveryNotes)) {
foreach($model->deliveryNotes as $key => $idDeliveryNote) {
Order::updateAll([
'id_invoice' => $model->id
], [
'id_delivery_note' => $idDeliveryNote
]) ;
}
}
}
}

/**
* Modifie un modèle Produit existant.
* Si la modification réussit, le navigateur est redirigé vers la page 'index'.
@@ -120,7 +139,6 @@ class DocumentController extends BackendController
}

if ($model && $model->load(Yii::$app->request->post()) && $model->save()) {

Yii::$app->getSession()->setFlash('success', $this->getFlashMessage('update', $model));
}

@@ -148,7 +166,7 @@ class DocumentController extends BackendController
]);

Yii::$app->getSession()->setFlash('success', $this->getFlashMessage('delete', $model));
$this->redirect(['delivery-note/index']);
$this->redirect([$model->getControllerUrlPath().'/index']);
}

public function actionDownload($id)
@@ -194,7 +212,7 @@ class DocumentController extends BackendController
return $pdf->render();
}

public function actionAjaxAddressUser($idUser)
public function actionAjaxUserInfos($typeAction, $idUser, $classDocument, $idDocument = false)
{
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;

@@ -204,10 +222,41 @@ class DocumentController extends BackendController
]);

if ($user) {
return [
$json = [
'return' => 'success',
'address' => $user->getFullAddress()
];

if($classDocument == 'Invoice') {
if($typeAction == 'create') {
$deliveryNotesArray = DeliveryNote::searchAll([
'id_user' => $user->id,
'status' => Document::STATUS_VALID
]) ;
}
elseif($typeAction == 'update' && $idDocument > 0) {
$deliveryNotesArray = DeliveryNote::searchAll([
'id_user' => $user->id,
'status' => Document::STATUS_VALID,
'order.id_invoice' => $idDocument
]) ;
}

if(isset($deliveryNotesArray)) {
$json['delivery_notes'] = [] ;

foreach($deliveryNotesArray as $deliveryNote) {
$json['delivery_notes'][] = array_merge(
$deliveryNote->getAttributes(),
[
'total' => $deliveryNote->getAmountWithTax()
]
) ;
}
}
}

return $json ;
}
}


+ 31
- 0
backend/views/document/_form.php Ver fichero

@@ -57,6 +57,11 @@ use common\models\Producer;
</div>
<div class="panel-body">
<?php $form = ActiveForm::begin(); ?>
<?= Html::hiddenInput('classDocument',$model->getClass(), ['id' => 'class-document']) ?>
<?= Html::hiddenInput('typeAction',$action, ['id' => 'type-action']) ?>
<?php if ($action == 'update'): ?>
<?= Html::hiddenInput('idDocument',$model->id, ['id' => 'id-document']) ?>
<?php endif; ?>
<?= $form->field($model, 'name')->label('Nom du document') ?>
<?php $usersArray = User::findBy()->all(); ?>
<?= $form->field($model, 'id_user', [
@@ -81,6 +86,32 @@ use common\models\Producer;
<?php if ($action == 'update'): ?>
<?= $form->field($model, 'comment')->textarea(['rows' => 2])->hint('Affiché en bas de la facture') ?>
<?php endif; ?>

<?php if($model->getClass() == 'Invoice'): ?>
<template v-if="idUser > 0">
<strong>Bons de livraison</strong>
<table v-if="deliveryNotes && deliveryNotes.length > 0" class="table table-bordered">
<thead>
<tr>
<?php if($action == 'create'): ?><th></th><?php endif; ?>
<th>Libellé</th>
<th>Montant (TTC)</th>
</tr>
</thead>
<tbody>
<tr v-for="deliveryNote in deliveryNotes">
<?php if($action == 'create'): ?>
<td><input type="checkbox" name="Invoice[deliveryNotes][]" :value="deliveryNote.id" /></td>
<?php endif; ?>
<td>{{ deliveryNote.name }}</td>
<td>{{ formatPrice(deliveryNote.total) }}</td>
</tr>
</tbody>
</table>
<div v-else class="alert alert-warning">Aucun bon de livraison pour cet utilisateur.</div>
</template>
<?php endif; ?>

<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? 'Ajouter' : 'Modifier', ['class' => 'btn btn-primary']) ?>
</div>

+ 1
- 1
backend/views/invoice/index.php Ver fichero

@@ -80,7 +80,7 @@ $this->addButton(['label' => 'Nouvelle facture <span class="glyphicon glyphicon-
'attribute' => 'id_user',
'header' => 'Utilisateur',
'value' => function($model) {
return $model->user->lastname.' '.$model->user->name ;
return $model->user->getUsername() ;
}
],
[

+ 27
- 14
backend/web/js/vuejs/document-form.js Ver fichero

@@ -39,6 +39,7 @@ var app = new Vue({
el: '#app-document-form',
data: {
document: [],
deliveryNotes: [],
idDocument: 0,
typeDocument: '',
idUser: '',
@@ -56,16 +57,12 @@ var app = new Vue({
methods: {
formatPrice: formatPrice,
init: function() {
var idDocument = $('#app-document-form').attr('data-id-document') ;
this.idDocument = idDocument ;
var classDocument = $('#app-document-form').attr('data-class-document') ;
this.classDocument = classDocument ;
if(idDocument) {
if(this.getDocumentId()) {
var app = this ;
axios.get(UrlManager.getBaseUrlAbsolute()+"document/ajax-init",{params: {
idDocument: idDocument,
classDocument: classDocument
idDocument: this.getDocumentId(),
classDocument: this.getDocumentClass()
}})
.then(function(response) {
if(response.data.return == 'success') {
@@ -75,18 +72,34 @@ var app = new Vue({
app.ordersArray = response.data.orders ;
app.total = response.data.total ;
app.total_with_tax = response.data.total_with_tax ;

if(app.idUser > 0) {
app.changeUser() ;
}
}
}) ;
}
},
changeUser: function(event) {
getDocumentId: function() {
var documentId = $('#app-document-form').attr('data-id-document') ;
return documentId ;
},
getDocumentClass: function() {
var documentClass = $('#app-document-form').attr('data-class-document') ;
return documentClass ;
},
changeUser: function() {
var app = this ;
axios.get(UrlManager.getBaseUrlAbsolute()+"document/ajax-address-user",{params: {
idUser: app.idUser
axios.get(UrlManager.getBaseUrlAbsolute()+"document/ajax-user-infos",{params: {
idUser: app.idUser,
classDocument: app.getDocumentClass(),
idDocument: app.getDocumentId(),
typeAction: $('#type-action').val(),
}})
.then(function(response) {
if(response.data.return == 'success') {
Vue.set(app.document, 'address', response.data.address);
app.deliveryNotes = response.data.delivery_notes ;
}
else {
app.document.address = '' ;
@@ -97,8 +110,8 @@ var app = new Vue({
validateDocument: function() {
var app = this ;
axios.get(UrlManager.getBaseUrlAbsolute()+"document/ajax-validate-document",{params: {
idDocument: app.idDocument,
classDocument: app.classDocument,
idDocument: app.getDocumentId(),
classDocument: app.getDocumentClass(),
}})
.then(function(response) {
appAlerts.alertResponse(response) ;
@@ -125,8 +138,8 @@ var app = new Vue({
submitProductAdd: function() {
var app = this ;
axios.get(UrlManager.getBaseUrlAbsolute()+"document/ajax-add-product",{params: {
idDocument: app.idDocument,
classDocument: app.classDocument,
idDocument: this.getDocumentId(),
classDocument: this.getDocumentClass(),
idProduct: app.productAddId,
quantity: app.productAddQuantity,
price: app.productAddPrice,

+ 2
- 1
common/models/Document.php Ver fichero

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


+ 2
- 0
common/models/Invoice.php Ver fichero

@@ -57,6 +57,8 @@ use Yii;
class Invoice extends Document
{

public $deliveryNotes ;

/**
* @inheritdoc
*/

+ 9
- 1
common/models/User.php Ver fichero

@@ -689,7 +689,15 @@ class User extends ActiveRecordCommon implements IdentityInterface

public function getUsername()
{
return $this->lastname.' '.$this->name ;
$username = '' ;
if(isset($this->name_legal_person) && strlen($this->name_legal_person)) {
$username = $this->name_legal_person ;
}
else {
$username = $this->lastname.' '.$this->name ;
}

return $username ;
}

/**

Cargando…
Cancelar
Guardar