1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808
| {% extends 'SonataAdminBundle:CRUD:edit.html.twig' %}
{% block form %}
{% if action == 'create' %}
{% set url = path('admin_billing_order_create') %}
{% else %}
{% set url = path('admin_billing_order_edit', { 'id': object.id }) %}
{% endif %}
<form class="order-form" action="{{ url }}" method="post">
{{ form_widget(form._token) }}
<fieldset>
<legend>Affectation {{ form_errors(form) }}</legend>
<div class="row-fluid" style="padding-top: 10px">
<div class="span3">
<div class="control-group">
<label class="control-label">Stock</label>
<div class="controls">
{{ form_widget(form.stock) }}
</div>
</div>
</div>
<div class="span1">
<span style="font-size: 30px; display: block; padding-top: 20px; text-align: center;">Ou</span>
</div>
<div class="span3">
<div class="control-group">
<label class="control-label">Intervention</label>
<div class="controls">
{{ form_widget(form.interventionSearch) }}
</div>
</div>
</div>
</fieldset>
<div class="row-fluid">
<div class="span4">
<fieldset>
<legend>General</legend>
<div class="control-group">
<label class="control-label">Ref devis fournisseur</label>
<div class="controls">
{{ form_widget(form.supplierRef) }}
</div>
</div>
<div class="control-group">
<label class="control-label">Nature *</label>
<div class="controls">
{{ form_widget(form.nature) }}
<div class="errors">
{{ form_errors(form.nature) }}
</div>
</div>
</div>
<div class="control-group">
<label class="control-label">Corps d'état *</label>
<div class="controls">
{{ form_widget(form.job) }}
<div class="errors">
{{ form_errors(form.job) }}
</div>
</div>
</div>
</fieldset>
</div>
<div class="span4">
<fieldset>
<legend>Fournisseur</legend>
<div class="control-group">
<label class="control-label">Fournisseur *</label>
<div class="controls">
{{ form_widget(form.companySearch) }}
</div>
</div>
<div class="control-group">
<label class="control-label">Magasin *</label>
<div class="controls">
{{ form_widget(form.supplierSearch) }}
<a href="#modal" role="button" class="btn addSupplier" data-toggle="modal" style="{{ (object.supplier is empty) ? "display: none;" }}"><i class="icon-plus-sign"></i></a>
</div>
</div>
</fieldset>
</div>
<div class="span4">
<fieldset>
<legend>Livraison</legend>
<div class="control-group delivery-container">
<label class="control-label">Livraison *</label>
<div class="controls">
{{ form_errors(form.deliveryType) }}
{{ form_widget(form.deliveryType) }}
</div>
</div>
<div class="control-group retreivedBy" {% if object.retrievedBy is empty %}style="display:none;"{% endif %}>
<label class="control-label">Enlevé par *</label>
<div class="controls">
{{ form_widget(form.userSearch) }}
</div>
</div>
<div class="control-group">
<label class="control-label">Souhaitée le *</label>
<div class="controls">
{{ form_widget(form.deliveryDesiredDate) }}
<div class="errors">
{{ form_errors(form.deliveryDesiredDate) }}
</div>
</div>
</div>
<div class="control-group">
<label class="control-label">Adresse *</label>
<div class="controls">
{{ form_widget(form.address) }}
</div>
</div>
<div class="control-group">
<label class="control-label">Code postal *</label>
<div class="controls">
{{ form_widget(form.postcode) }}
</div>
</div>
<div class="control-group">
<label class="control-label">Ville *</label>
<div class="controls">
{{ form_widget(form.city) }}
</div>
</div>
</fieldset>
</div>
</div>
{% if action == 'edit' %}
<fieldset>
<legend>Commentaire</legend>
<div class="control-group">
<div class="controls">
{{ form_widget(form.comment) }}
</div>
</div>
</fieldset>
<fieldset style="margin: 30px 0">
<table class="lines table table-striped">
<thead>
<tr>
<th>Article</th>
<th>Unité</th>
<th>Prix Unitaire</th>
<th>Eco-contrib.</th>
<th>Quantité</th>
<th>Réduction</th>
<th>Montant</th>
<th> </th>
<th>Commentaire</th>
<th> </th>
</tr>
</thead>
<tbody>
{% for key,line in object.lines %}
<tr>
<td>
<input type="hidden" name="id" value="{{ line.id }}" class="line-id" />
{% if line.article is not empty %}
<input id="article{{key}}" type="hidden" name="article_id" class="articleSearch" value="{{ line.article.label }}">
{% endif %}
</td>
<td><input type="text" name="unit" class="unit required callSave" value="{{ line.unit }}" placeholder="U"></td>
<td>
<div class="input-prepend">
<span class="add-on">€</span>
<input type="text" name="price" class="price required callSave tt number" value="{{ line.price }}"
{% if line.article is not empty %}
title="Prix commandé<br>moyen {{line.article.price }} €<br>min {{ line.article.priceMin }} €<br>max {{ line.article.priceMax }} €
{% endif %}
">
</div>
</td>
<td>
<div class="input-prepend">
<span class="add-on">€</span>
<input type="text" name="eco" class="eco required callSave tt number" value="{{ line.eco }}">
</div>
</td>
<td><input type="text" name="quantity" class="quantity required callSave number" value="{{ line.quantity }}"></td>
<td>
<div class="input-append">
<input type="text" name="discount" class="discount callSave number" value="{{ line.discount }}">
<span class="add-on">%</span>
</div>
</td>
<td class="total"></td>
<td>
<select name="vat" class="callSave" style="width: 65px">
{% for vat in vats %}
<option value="{{ vat.id }}" {% if line.vat is not empty and line.vat.id == vat.id %}selected="selected"{% endif %}>{{ vat }}</option>
{% endfor %}
</select>
</td>
<td>
<input type="text" name="comment" class="comment callSave" value="{{ line.comment }}">
</td>
<td><a href="#" class="btn btn-danger remove"><i class="icon-remove"></i></a></td>
</tr>
{% endfor %}
<tr>
<td>
<input type="hidden" name="id" value="" class="line-id" />
<input type="hidden" name="article_id" class="articleSearch">
<a href="#" class="btn btn-danger out" title="Hors base article"><i class="icon-signout"></i></a>
<a href="javascript:alert('1');void(0);alert('2');" class="po-invoice" data-original-title="Facture" data-content='
<iframe src="{{ path('admin_stock_article_list') }}" width="700" height="500"></iframe>
'><i class="icon-search"></i></a>
</td>
<td><input type="text" name="unit" class="unit required callSave" placeholder="U"></td>
<td>
<div class="input-prepend">
<span class="add-on">€</span>
<input type="text" name="price" class="price required callSave tt number">
</div>
</td>
<td>
<div class="input-prepend">
<span class="add-on">€</span>
<input type="text" name="eco" class="eco required callSave tt number" value="0">
</div>
</td>
<td><input type="text" name="quantity" class="quantity required callSave number" value="1"></td>
<td>
<div class="input-append">
<input type="text" name="discount" class="discount callSave number" value="0">
<span class="add-on">%</span>
</div>
</td>
<td class="total"></td>
<td>
<select name="vat" class="callSave" style="width: 65px">
{% for vat in vats %}
<option value="{{ vat.id }}">{{ vat }}</option>
{% endfor %}
</select>
</td>
<td>
<input type="text" name="comment" class="comment callSave" value="">
</td>
<td><a href="#" class="btn btn-danger remove"><i class="icon-remove"></i></a></td>
</tr>
</tbody>
<tfoot>
<tr>
<td>Nombre d'article : <span class="counter">XXX</span></td>
<td colspan="6" style="text-align: right">Total : <span class="total">XXX</span></td>
<td colspan="2"></td>
</tr>
</tfoot>
</table>
</fieldset>
{% endif %}
<div class="well form-actions">
<a href="{{ path('admin_billing_order_list') }}" class="btn">Annuler</a>
<input type="submit" class="btn btn-primary save" name="btn_update_and_edit" value="Enregistrer">
</div>
</form>
<table style="display: none;">
<tr class="clone">
<td>
<input type="hidden" name="id" value="" class="line-id" />
<input type="hidden" name="article_id" class="articleSearchTemp">
<a href="#" class="btn btn-danger out" title="Hors base article"><i class="icon-signout"></i></a>
</td>
<td><input type="text" name="unit" class="unit required callSave" placeholder="U"></td>
<td>
<div class="input-prepend">
<span class="add-on">€</span>
<input type="text" name="price" class="price required callSave tt number">
</div>
</td>
<td>
<div class="input-prepend">
<span class="add-on">€</span>
<input type="text" name="eco" class="eco required callSave tt number" value="0">
</div>
</td>
<td><input type="text" name="quantity" class="quantity required callSave number" value="1"></td>
<td>
<div class="input-append">
<input type="text" name="discount" class="discount callSave number" value="0">
<span class="add-on">%</span>
</div>
</td>
<td class="total"></td>
<td>
<select name="vat" class="callSave" style="width: 65px">
{% for vat in vats %}
<option value="{{ vat.id }}"@>{{ vat }}</option>
{% endfor %}
</select>
</td>
<td><a href="#" class="btn btn-danger remove"><i class="icon-remove"></i></a></td>
</tr>
</table>
<div id="modal" class="modal hide fade">
<div class="modal-header">
<button type="button" class="close" data-dismiss="#modal" aria-hidden="true">×</button>
<h3>Ajouter un magasin</h3>
</div>
<div class="modal-body">
<form class="supplierForm" method="post" action="{{ path('supplier_create') }}">
<input type="hidden" name="company" value="{{ (object.supplier is not empty) ? object.supplier.company.id }}"/>
{{ form_widget(form_supplier) }}
</form>
</div>
<div class="modal-footer">
<a href="#" class="btn closeModal">Annuler</a>
<a href="#" class="btn btn-primary modalSave">Enregistrer</a>
</div>
</div>
<script>
$(function(){
$('.tt').tooltip({'html': true});
// Prevent saving form on enter key
$('.order-form').bind("keypress", function(e) {
if (e.keyCode == 13) {
e.preventDefault();
return false;
}
});
$('.number').keypress(function(event) {
if ((event.which != 46 || $(this).val().indexOf('.') != -1) && (event.which < 48 || event.which > 57)) {
event.preventDefault();
}
});
$( ".save" ).click(function(e) {
e.preventDefault();
if ($('.interventionSearch').select2("val") != '') {
if ($('.deliveryType').val() == 1) {
if ($('.userSearch').select2("val") != '') {
$( ".order-form" ).submit();
} else {
alert('Pour un enlèvement comptoire vous devez choisir un technicien');
}
} else {
$( ".order-form" ).submit();
}
} else {
if ($('.stock').val() != '') {
$( ".order-form" ).submit();
} else {
alert('Veuillez choisir un stock ou une intervention');
}
}
});
var opts0 =
{
placeholder: "Choisir un fournisseur",
minimumInputLength: 0,
allowClear: true,
ajax: {
url: "{{path('billing_company_search')}}",
dataType: 'json',
data: function (term, page) {
return {
q: term,
page_limit: 10
};
},
results: function (data, page) {
return {results: data.results};
}
},
formatResult: companyFormatResult,
formatSelection: companyFormatSelection,
dropdownCssClass: "bigdrop",
escapeMarkup: function (m) { return m; }
};
$(".companySearch").select2( opts0 );
{% if object.supplier is not empty %}
$(".companySearch").select2("data", {id: {{ object.supplier.company.id }}, name: '{{ object.supplier.company.name }}'});
{% endif %}
$('.companySearch').on("change", function(e) {
$(".supplierSearch").select2('data', null);
$('.supplierForm input[name=company]').val($(".companySearch").select2("val"));
$('.addSupplier').show();
});
// Configure intervention select2
var opts3 =
{
placeholder: "Choisir un magasin",
minimumInputLength: 0,
allowClear: true,
ajax: {
url: "{{path('billing_supplier_search')}}",
dataType: 'json',
data: function (term, page) {
return {
q: term,
page_limit: 10,
company: $(".companySearch").select2("val")
};
},
results: function (data, page) {
return {results: data.results};
}
},
formatResult: supplierFormatResult,
formatSelection: supplierFormatSelection,
dropdownCssClass: "bigdrop",
escapeMarkup: function (m) { return m; }
};
$(".supplierSearch").select2( opts3 );
{% if object.supplier is not empty %}
$(".supplierSearch").select2("data", {id: {{ object.supplier.id }}, name: '{{ object.supplier.name }}'});
{% endif %}
$('.supplierSearch').on("change", function(e) {
var data = $(".supplierSearch").select2("data");
$(".companySearch").select2("data", {id: data.company_id, name: data.company_name});
});
// Configure intervention select2
var opts1 =
{
placeholder: "Choisir une intervention",
minimumInputLength: 2,
allowClear: true,
ajax: {
url: "{{path('billing_intervention_search')}}",
dataType: 'json',
data: function (term, page) {
return {
q: term,
page_limit: 10
};
},
results: function (data, page) {
return {results: data.results};
}
},
formatResult: interventionFormatResult,
formatSelection: interventionFormatSelection,
dropdownCssClass: "bigdrop",
escapeMarkup: function (m) { return m; }
};
$(".interventionSearch").select2( opts1 );
{% if object.intervention is not empty %}
$(".interventionSearch").select2("data", {id: {{ object.intervention.id }}, ref: '{{ object.intervention.ref }}'});
{% endif %}
$('.interventionSearch').on("change", function(e) {
$('.stock').val('');
$('.deliveryType').val('');
$('.deliveryType').addClass('error');
$('.delivery-container').show();
});
$('.stock').on("click", function(e) {
$('.interventionSearch').select2("data", null);
});
$('.stock').on("change", function(e) {
$('.deliveryType').val('3');
$('.deliveryType').change();
$('.delivery-container').hide();
});
// Configure article select2
var opts2 =
{
placeholder: "Ajouter un article",
minimumInputLength: 0,
ajax: {
url: "{{path('billing_article_search')}}",
dataType: 'json',
data: function (term, page) {
return {
q: term,
page_limit: 10,
company: $(".companySearch").select2("val")
};
},
results: function (data, page) {
return {results: data.results};
}
},
formatResult: articleFormatResult,
formatSelection: articleFormatSelection,
dropdownCssClass: "bigdrop",
escapeMarkup: function (m) { return m; }
};
$(".articleSearch").select2( opts2 );
{% for key,line in object.lines if line.article is not empty %}
$("#article{{key}}").select2("data", {id: {{ line.article.id }}, ref: '{{ line.article }}'});
{% endfor %}
var opts4 =
{
placeholder: "Choisir un technicien",
minimumInputLength: 0,
allowClear: true,
ajax: {
url: "{{path('billing_user_search')}}",
dataType: 'json',
data: function (term, page) {
return {
q: term,
page_limit: 10
};
},
results: function (data, page) {
return {results: data.results};
}
},
formatResult: userFormatResult,
formatSelection: userFormatSelection,
dropdownCssClass: "bigdrop",
escapeMarkup: function (m) { return m; }
};
$(".userSearch").select2( opts4 );
{% if object.retrievedBy is not empty %}
$(".userSearch").select2("data", {id: {{ object.retrievedBy.id }}, ref: '{{ object.retrievedBy.fullname }}'});
{% endif %}
$('.deliveryType').on("change", function(e) {
$(this).removeClass('error');
var type = $(this).val();
var supplier = $(".supplierSearch").select2("val");
var intervention = $(".interventionSearch").select2("val");
var stock = $(".stock").val();
if (type==1) {
$('.retreivedBy').show();
} else {
$('.retreivedBy').hide();
}
$.post("{{ path('billing_address_search') }}", {
'type': type,
'supplier': supplier,
'intervention': intervention,
'stock': stock
}, function(data) {
if (data.error) {
$('.deliveryType').val('');
$('.address').val('');
$('.city').val('');
$('.postcode').val('');
alert("Un problème est survenu\nVous devez\n- saisir un magasin pour un enlèvement comptoir\n- saisir un intervention pour une livraison chantier");
} else {
$('.address').val(data.address);
$('.city').val(data.city);
$('.postcode').val(data.postcode);
}
}, 'json');
}).change();
// On article select2 change : save line and create a new one if necessary
$(document).on("change", '.articleSearch', function(e) {
articleChange($(this));
});
function articleChange(elt) {
var line = elt.parent().parent();
var id = line.find('.line-id');
var price = line.find('.price');
var unit = line.find('.unit');
var eco = line.find('.eco');
//console.log('allo');
//console.log($(this).select2('data'));
var data = elt.select2('data');
price.val(data.price);
price.attr('title', 'Prix commandé<br>moyen '+ data.price +'€<br>min '+ data.priceMin +' €<br>max '+ data.priceMax +' €');
price.tooltip({'html': true});
unit.val(data.unit);
eco.val(data.eco);
$.post("{{ path('orderline_save', { order: object.id }) }}", line.find(':input').serialize(), function(data) {
if (id.val() == '') {
// Set price
//price.val(data.price);
//price.attr('title', 'Prix commandé<br>moyen '+ data.price +'€<br>min '+ data.priceMin +' €<br>max '+ data.priceMax +' €');
//price.tooltip({'html': true});
//unit.val(data.unit);
//eco.val(data.eco);
// Keep line select2 data and destroy it
//var sdata = line.find('.articleSearch').select2("data")
//line.find('.articleSearch').select2("destroy");
// Add new line
var newline = $('.clone').clone(true);
newline.removeClass('clone');
newline.appendTo($('.lines'));
// Reinit its inputs
newline.find('.ref').val('');
newline.find('.llabel').val('');
newline.find('.unit').val('');
newline.find('.price').val('0');
newline.find('.quantity').val('1');
newline.find('.discount').val('0');
newline.find('.articleSearchTemp').removeClass('articleSearchTemp').addClass('articleSearch');
newline.find('.articleSearch').select2(opts2);
//newline.find('.articleSearch').select2("data", {id: '', ref: 'Ajouter un article'});
// Recreate line select2
//line.find('.articleSearch').select2(opts2);
//line.find('.articleSearch').select2("data", sdata);
//Set the previous line id
id.val(data.id);
}
}, 'json');
}
$(document).on("click", '.order-form .out', function(e) {
e.preventDefault();
$(this).prev().remove();
$(this).prev().remove();
$(this).parent().append('<input type="hidden" name="article_id"><input type="text" name="ref" class="ref callSave" placeholder="Référence" /><input type="text" name="label" class="llabel callSave" placeholder="Libéllé" /><a href="#" class="btn btn-info in" title="Dans base article"><i class="icon-signin"></i></a>');
$(this).remove();
});
$(document).on("click", '.order-form .in', function(e) {
e.preventDefault();
$(this).prev().remove();
$(this).prev().remove();
$(this).parent().append('<input type="hidden" name="article_id" class="articleSearch"><a href="#" class="btn btn-danger out" title="Hors base article"><i class="icon-signout"></i></a>');
$(this).parent().find('.articleSearch').select2(opts2);
$(this).parent().find('.articleSearch').select2("data", {id: '', ref: 'Ajouter un article'});
$(this).remove();
});
$(document).on("change", '.callSave', function(event){
var elt = $(this);
var line = elt.closest('tr');
var id = line.find('.line-id');
var article = line.find("input[name='article_id']");
//alert(id);
if (elt.hasClass('ref')) {
//console.log('change1 '+elt);
{% if object.supplier is not empty %}
$.post("{{ path('orderline_checkArticle', {'company': object.supplier.company.id }) }}", line.find(':input').serialize(), function(data) {
if (data.id > 0) {
article.val(data.id);
line.find('.in').click();
//console.log('1 '+data.id);
//console.log(data.ref);
line.find('.articleSearch').select2(opts2);
line.find(".articleSearch").select2("data", data);
articleChange(line.find(".articleSearch"));
//line.find(".articleSearch").change();
}
});
{% endif %}
} else {
//console.log('change2 '+elt);
$.post("{{ path('orderline_save', { order: object.id }) }}", line.find(':input').serialize(), function(data) {
//console.log('2 '+data.id);
if (data.id != undefined && data.id > 0 && id.val() != data.id && !data.chapter) {
line.find('.articleSearch').select2("destroy");
// Add new line
var newline = line.clone(true);
newline.appendTo($('.lines'));
// Reinit its inputs
newline.find('.ref').val('');
newline.find('.llabel').val('');
newline.find('.price').val('0');
newline.find('.quantity').val('1');
newline.find('.discount').val('0');
newline.find('.articleSearch').select2(opts2);
newline.find('.articleSearch').select2("data", {id: '', ref: 'Ajouter un article'});
// Recreate line select2
line.find('.articleSearch').select2(opts2);
}
id.val(data.id);
article.val(data.article_id);
$('.callSave').prop('readonly', false);
});
}
updateTotals();
});
$(document).on("click", '.remove', function(event){
event.preventDefault();
var line = $(this).parent().parent();
var id = line.find('.line-id');
$.post("{{ path('orderline_delete') }}", {id: id.val()}, function(data) {
line.remove();
});
});
$(document).on("click", '.addSupplier', function(event){
$('#modal input[type=text]').val('');
});
$(document).on("click", '.modalSave', function(event){
event.preventDefault();
$.post("{{ path('supplier_create') }}", $('.supplierForm').serialize(), function(data) {
if (data != null) {
$(".supplierSearch").select2("data", {id: data.id, name: data.name});
$('#modal').modal('hide');
}
}, 'json');
});
$(document).on("click", '.closeModal', function(event){
event.preventDefault();
$('#modal').modal('hide');
});
updateTotals();
});
function updateTotals() {
var total = 0;
var counter = 0;
var totalspan = $('span.total');
var counterspan = $('span.counter');
$('.lines tbody tr').each(function( index ) {
var price = parseFloat($(this).find('.price').val());
var quantity = parseFloat($(this).find('.quantity').val());
var eco = parseFloat($(this).find('.eco').val());
var discount = parseFloat($(this).find('.discount').val());
var line_total = $(this).find('.total');
tot = (price + eco) * quantity;
if (discount > 0) {
tot = tot * (1 - (discount/100));
}
if (!isNaN(tot)) {
line_total.html(tot.toFixed(2));
total = total + tot;
counter++;
}
});
totalspan.html(total.toFixed(2));
counterspan.html(counter);
}
</script>
{% endblock %}
Comment faire? |
Partager