Browse Source

Modifier un document : amélioration formulaire ajout de produits (affichage total, mise en page, format inputs) #166

dev
Guillaume Bourgeois 4 years ago
parent
commit
56399dbe36
6 changed files with 72 additions and 24 deletions
  1. +5
    -5
      backend/controllers/DocumentController.php
  2. +27
    -16
      backend/views/document/_form.php
  3. +8
    -0
      backend/web/css/screen.css
  4. +13
    -1
      backend/web/js/vuejs/document-form.js
  5. +9
    -0
      backend/web/sass/document/_form.scss
  6. +10
    -2
      common/models/Product.php

+ 5
- 5
backend/controllers/DocumentController.php View File

if($document) { if($document) {
$productsArray = Product::searchAll([], [
'as_array' => true,
]) ;
$productsArray = Product::searchAll() ;
$ordersArray = [] ; $ordersArray = [] ;
foreach($document->orders as $order) { foreach($document->orders as $order) {
]), ]),
'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']) ;
return $product;
return array_merge($product->getAttributes(),[
'price_with_tax' => $product->price_with_tax,
'wording_unit' => $product->wording_unit,
]) ;
}), }),
'orders' => $ordersArray, 'orders' => $ordersArray,
'total' => $document->getAmount(Order::AMOUNT_TOTAL) 'total' => $document->getAmount(Order::AMOUNT_TOTAL)

+ 27
- 16
backend/views/document/_form.php View File

Ajouter un produit Ajouter un produit
</div> </div>
<div class="panel-body"> <div class="panel-body">
<div class="col-md-5">
<div class="col-md-3">
<strong>Produit</strong>
<select class="form-control" v-model="productAddId" <select class="form-control" v-model="productAddId"
@change="changeProductAdd"> @change="changeProductAdd">
<option value="0" selected="selected">--</option> <option value="0" selected="selected">--</option>
</select> </select>
</div> </div>
<template v-if="productAddId > 0"> <template v-if="productAddId > 0">
<div class="col-md-2">
<div class="col-md-3">
<strong>Prix unitaire</strong>
<div class="input-group"> <div class="input-group">
<input type="text" class="form-control input-price" <input type="text" class="form-control input-price"
v-model="productAddPrice"/>
v-model="productAddPrice" @change="formatProductAddPrice"/>
<span class="input-group-addon"><span <span class="input-group-addon"><span
class="glyphicon glyphicon-euro"></span></span>
class="glyphicon glyphicon-euro"></span> TTC</span>
</div> </div>
</div> </div>
<div class="col-md-3"> <div class="col-md-3">
<strong>Quantité</strong>
<div class="input-group input-group-quantity"> <div class="input-group input-group-quantity">
<span class="input-group-btn"> <span class="input-group-btn">
<button class="btn btn-default" type="button" <button class="btn btn-default" type="button"
@click="changeQuantityProductAdd(-1)">-</button> @click="changeQuantityProductAdd(-1)">-</button>
</span> </span>
<input type="text" class="form-control input-quantity" <input type="text" class="form-control input-quantity"
v-model="productAddQuantity"/>
v-model="productAddQuantity" @change="formatProductAddQuantity"/>
<span class="input-group-addon">{{ productsArray[productAddId].wording_unit }}</span> <span class="input-group-addon">{{ productsArray[productAddId].wording_unit }}</span>
<span class="input-group-btn"> <span class="input-group-btn">
<button class="btn btn-default" <button class="btn btn-default"
</span> </span>
</div> </div>
</div> </div>
<div class="col-md-2">
<div class="col-md-3 total">
<strong>Total</strong>
<div class="input-group">
<input type="text" class="form-control input-price" readonly
:value="formatPrice(productAddPrice * productAddQuantity)"/>
<span class="input-group-addon"><span
class="glyphicon glyphicon-euro"></span> TTC</span>
</div>
<button class="btn btn-primary" value="Ajouter" <button class="btn btn-primary" value="Ajouter"
@click="submitProductAdd">Ajouter @click="submitProductAdd">Ajouter
</button> </button>
<div class="clr"></div>
</div> </div>
</template> </template>
<div class="clr"></div> <div class="clr"></div>
<table class="table table-bordered" v-if="total > 0"> <table class="table table-bordered" v-if="total > 0">
<thead> <thead>
<tr> <tr>
<td>Nom</td>
<td>Prix (unité)</td>
<td>Quantité</td>
<td>Total</td>
<td>Supprimer</td>
<th>Nom</th>
<th>Prix (unité)</th>
<th>Quantité</th>
<th>Total</th>
<th>Supprimer</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<template v-for="order in ordersArray"> <template v-for="order in ordersArray">
<tr v-for="productOrder in order.productOrder"> <tr v-for="productOrder in order.productOrder">
<td>{{
<td class="col-md-4">{{
productsArray[productOrder.id_product].name productsArray[productOrder.id_product].name
}} }}
</td> </td>
<td>{{ formatPrice(productOrder.price) }}</td>
<td>{{ productOrder.quantity }}</td>
<td>{{ formatPrice(productOrder.quantity *
<td class="col-md-2">{{ formatPrice(productOrder.price) }}</td>
<td class="col-md-2">{{ productOrder.quantity }}</td>
<td class="col-md-2">{{ formatPrice(productOrder.quantity *
productOrder.price) }} productOrder.price) }}
</td> </td>
<td>
<td class="col-md-2">
<a class="btn btn-default" @click="deleteProductOrder(productOrder.id)"> <a class="btn btn-default" @click="deleteProductOrder(productOrder.id)">
<span class="glyphicon glyphicon-trash"></span> <span class="glyphicon glyphicon-trash"></span>
</a> </a>

+ 8
- 0
backend/web/css/screen.css View File

.document-form #block-add-product .input-group-quantity .input-quantity { .document-form #block-add-product .input-group-quantity .input-quantity {
text-align: center; text-align: center;
} }
/* line 22, ../sass/document/_form.scss */
.document-form #block-add-product .total .input-group {
margin-bottom: 10px;
}
/* line 25, ../sass/document/_form.scss */
.document-form #block-add-product .total .btn {
float: right;
}

+ 13
- 1
backend/web/js/vuejs/document-form.js View File

changeProductAdd: function(event) { changeProductAdd: function(event) {
var idProduct = event.currentTarget.value ; var idProduct = event.currentTarget.value ;
this.productAddId = idProduct ; this.productAddId = idProduct ;
this.productAddPrice = parseFloat(this.productsArray[idProduct].price).toFixed(2) ;
this.productAddPrice = parseFloat(this.productsArray[idProduct].price_with_tax).toFixed(2) ;
this.productAddQuantity = this.getStepProductAdd() ; this.productAddQuantity = this.getStepProductAdd() ;
}, },
changeQuantityProductAdd: function(quantity) { changeQuantityProductAdd: function(quantity) {
app.init() ; app.init() ;
appAlerts.alert('danger','Produit supprimé') ; appAlerts.alert('danger','Produit supprimé') ;
}) ; }) ;
},
formatProductAddPrice: function() {
this.productAddPrice = Number(this.productAddPrice).toFixed(2).replace(',', '.');
if(isNaN(this.productAddPrice)) {
this.productAddPrice = 0 ;
}
},
formatProductAddQuantity: function() {
this.productAddQuantity = parseInt(this.productAddQuantity) ;
if(isNaN(this.productAddQuantity)) {
this.productAddQuantity = 1 ;
}
} }
} }
}); });

+ 9
- 0
backend/web/sass/document/_form.scss View File

text-align: center ; text-align: center ;
} }
} }

.total {
.input-group {
margin-bottom: 10px ;
}
.btn {
float: right ;
}
}
} }
} }

+ 10
- 2
common/models/Product.php View File

*/ */
class Product extends ActiveRecordCommon class Product extends ActiveRecordCommon
{ {
var $total = 0;
var $apply_distributions = true;
public $total = 0;
public $apply_distributions = true;

public $price_with_tax = 0 ;
public $wording_unit = '' ;


public static $unitsArray = [ public static $unitsArray = [
'piece' => [ 'piece' => [
} }
return false; return false;
}], }],
[['price_with_tax', 'wording_unit'], 'safe']
]; ];
} }


if ($this->taxRate == null) { if ($this->taxRate == null) {
$this->populateRelation('taxRate', GlobalParam::getCurrentProducer()->taxRate); $this->populateRelation('taxRate', GlobalParam::getCurrentProducer()->taxRate);
} }

$this->wording_unit = Product::strUnit($this->unit) ;
$this->price_with_tax = $this->getpriceWithTax() ;

parent::afterFind(); parent::afterFind();
} }



Loading…
Cancel
Save