editSuccess.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <div class="content-add01">
  2. <div class="heading01"><h1><?php echo $katao_supplier_invoice->isNew()?'Ajout':'Modification' ?> d'une facture fournisseur</h1></div>
  3. </div>
  4. <?php echo form_tag('kataoSupplierInvoice/update?id=' . $katao_supplier_invoice->getId()) ?>
  5. <table>
  6. <tr valign="top">
  7. <th align="left"><?php echo label_for('period', 'Période') ?></th>
  8. <td><?php echo select_tag('period', options_for_select(KataoPeriodPeer::getAll(), $katao_supplier_invoice->getKataoPeriodId()?$katao_supplier_invoice->getKataoPeriodId():KataoPeriodPeer::getActivePeriod()->getId()), array('onchange' => 'updateOrdersList();')) ?></td>
  9. </tr>
  10. <tr valign="top">
  11. <th align="left"><?php echo label_for('supplier', 'Fournisseur') ?></th>
  12. <td><?php echo select_tag('supplier', options_for_select(KataoSupplierPeer::getAllSimple(), $katao_supplier_invoice->getKataoSupplierId(), array('include_custom' => '&mdash;&nbsp;choisir&nbsp;&mdash;')), array('onchange' => 'updateOrdersList();')) ?></td>
  13. </tr>
  14. <tr valign="top">
  15. <th align="left"><?php echo label_for('reference', 'Référence') ?></th>
  16. <td><?php echo input_tag('reference', $katao_supplier_invoice->getReference()) ?></td>
  17. </tr>
  18. <tr valign="top">
  19. <th align="left"><?php echo label_for('invoice_date', 'Date') ?></th>
  20. <td><?php echo input_date_tag('invoice_date', !$katao_supplier_invoice->isNew()?$katao_supplier_invoice->getInvoiceDate():time(), array('rich' => true, 'calendar_button_img' => '/sf/sf_admin/images/date.png', 'css' => 'skins/aqua/theme', 'format' => 'dd/MM/yyyy', 'culture' => 'fr', 'style' => 'width: 56px')) ?></td>
  21. </tr>
  22. <tr valign="top">
  23. <th align="left"><?php echo label_for('due_date', 'Echéance') ?></th>
  24. <td><?php echo input_date_tag('due_date', !$katao_supplier_invoice->isNew()?$katao_supplier_invoice->getDueDate():time(), array('rich' => true, 'calendar_button_img' => '/sf/sf_admin/images/date.png', 'css' => 'skins/aqua/theme', 'format' => 'dd/MM/yyyy', 'culture' => 'fr', 'style' => 'width: 56px')) ?></td>
  25. </tr>
  26. <tr valign="top">
  27. <th align="left"><label>Commande(s)</label></th>
  28. <td id="orders"><i>Merci de choisir une période et un fournisseur</i></td>
  29. </tr>
  30. <tr valign="top">
  31. <th align="left"><label>Observations</label></th>
  32. <td><?php echo textarea_tag('comment', $katao_supplier_invoice->getComment(), array('rows' => 4, 'cols' => 5, 'style' => 'width:525px;height:80px')) ?></td>
  33. </tr>
  34. </table>
  35. <div id="products"><br /><i>Merci de sélectionner des commandes</i></div>
  36. <br /><input type="submit" value="Sauver" onclick="return submitForm();" /> ou <a href="<?php echo url_for('kataoSupplierInvoice/index') ?>">annuler</a>
  37. </form>
  38. <script type="text/javascript" language="JavaScript">
  39. /* <![CDATA[ */
  40. function updateOrdersList(){
  41. if ($F('period') && $F('supplier')) {
  42. new Ajax.Request('<?php echo url_for('kataoSupplierInvoice/updateOrdersList') ?>', {
  43. method: 'get',
  44. parameters: {
  45. id: <?php echo (int)$katao_supplier_invoice->getId() ?>,
  46. period: $F('period'),
  47. supplier: $F('supplier')
  48. },
  49. onSuccess: updateOrdersListResponse
  50. });
  51. }
  52. }
  53. function updateOrdersListResponse(xhr){
  54. $('orders').innerHTML = xhr.responseText;
  55. updateProductsList();
  56. }
  57. function updateProductsList(){
  58. var orders = new Array();
  59. var supplier_invoice_orders = $$('.supplier-invoice-order');
  60. for(var i = 0; i < supplier_invoice_orders.length; i++){
  61. if (supplier_invoice_orders[i].checked) {
  62. orders.push(supplier_invoice_orders[i].value);
  63. }
  64. }
  65. new Ajax.Request('<?php echo url_for('kataoSupplierInvoice/updateProductsList') ?>', {
  66. method: 'get',
  67. parameters: {
  68. id: <?php echo (int)$katao_supplier_invoice->getId() ?>,
  69. orders: orders.join(',')
  70. },
  71. onSuccess: updateProductsListResponse
  72. });
  73. }
  74. function updateProductsListResponse(xhr){
  75. $('products').innerHTML = xhr.responseText;
  76. }
  77. function updateProductTotalPrice(id){
  78. $('product_price_total_'+id).value = round2decimals(parseFloat(parseInt($F('product_quantity_'+id)) * parseFloat($F('product_price_unit_'+id))));
  79. updateTotalPrices();
  80. }
  81. function updateTotalPricesHT(){
  82. <?php $tva_rates = array('0.2' => 1, '0.055' => 2, '0' => 0) ?>
  83. <?php $total_by_tva_rate = array('0.2' => 0, '0.055' => 0, '0' => 0) ?>
  84. <?php $discount_by_tva_rate = $total_by_tva_rate ?>
  85. <?php foreach ($total_by_tva_rate as $tva_rate => $tva_rate_total): ?>
  86. <?php $tva_rate_discount = $discount_by_tva_rate[$tva_rate] ?>
  87. $('without_taxes_by_tva_rate_<?php echo $tva_rates[(string)$tva_rate] ?>').value = 0;
  88. var total_price_by_tva_rate = $$('.product-price-total-<?php echo $tva_rates[(string)$tva_rate] ?>');
  89. for(var i = 0; i < total_price_by_tva_rate.length; i++){
  90. $('without_taxes_by_tva_rate_<?php echo $tva_rates[(string)$tva_rate] ?>').value = round2decimals(parseFloat($F('without_taxes_by_tva_rate_<?php echo $tva_rates[(string)$tva_rate] ?>')) + parseFloat(total_price_by_tva_rate[i].value));
  91. }
  92. <?php endforeach ?>
  93. updateTotalHT();
  94. }
  95. function updateTotalPricesTTC(){
  96. <?php $tva_rates = array('0.2' => 1, '0.055' => 2, '0' => 0) ?>
  97. <?php $total_by_tva_rate = array('0.2' => 0, '0.055' => 0, '0' => 0) ?>
  98. <?php $discount_by_tva_rate = $total_by_tva_rate ?>
  99. var without_taxes_total = 0;
  100. var tva_total = 0;
  101. <?php foreach ($total_by_tva_rate as $tva_rate => $tva_rate_total): ?>
  102. <?php $tva_rate_discount = $discount_by_tva_rate[$tva_rate] ?>
  103. $('total_by_tva_rate_<?php echo $tva_rates[(string)$tva_rate] ?>').value = round2decimals(parseFloat(<?php echo $tva_rate ?> * ($F('without_taxes_by_tva_rate_<?php echo $tva_rates[(string)$tva_rate] ?>') - $F('discount_by_tva_rate_<?php echo $tva_rates[(string)$tva_rate] ?>'))));
  104. without_taxes_total += parseFloat($F('without_taxes_by_tva_rate_<?php echo $tva_rates[(string)$tva_rate] ?>'));
  105. tva_total += parseFloat($F('total_by_tva_rate_<?php echo $tva_rates[(string)$tva_rate] ?>'));
  106. <?php endforeach ?>
  107. without_taxes_total = without_taxes_total + parseFloat($F('fees_shipping_ht')) + parseFloat($F('fees_billing_ht'));
  108. tva_total = tva_total + parseFloat($F('fees_shipping_tva')) + parseFloat($F('fees_billing_tva'));
  109. $('without_taxes_total').value = without_taxes_total;
  110. $('tva_total').value = tva_total;
  111. updateTotalTTC();
  112. }
  113. function updateFeesTVA(){
  114. $('fees_shipping_tva').value = round2decimals(parseFloat($F('fees_shipping_ht')) * parseFloat($F('fees_shipping_rate')));
  115. $('fees_billing_tva').value = round2decimals(parseFloat($F('fees_billing_ht')) * parseFloat($F('fees_billing_rate')));
  116. updateTotalHT();
  117. }
  118. function updateTotalHT(){
  119. <?php $tva_rates = array('0.2' => 1, '0.055' => 2, '0' => 0) ?>
  120. <?php $total_by_tva_rate = array('0.2' => 0, '0.055' => 0, '0' => 0) ?>
  121. <?php $discount_by_tva_rate = $total_by_tva_rate ?>
  122. var without_taxes_total = 0;
  123. <?php foreach ($total_by_tva_rate as $tva_rate => $tva_rate_total): ?>
  124. <?php $tva_rate_discount = $discount_by_tva_rate[$tva_rate] ?>
  125. without_taxes_total += parseFloat($F('without_taxes_by_tva_rate_<?php echo $tva_rates[(string)$tva_rate] ?>'));
  126. <?php endforeach ?>
  127. $('without_taxes_total').value = round2decimals(without_taxes_total + parseFloat($F('fees_shipping_ht')) + parseFloat($F('fees_billing_ht')));
  128. updateTotalTVA();
  129. }
  130. function updateTotalTVA(){
  131. <?php $tva_rates = array('0.2' => 1, '0.055' => 2, '0' => 0) ?>
  132. <?php $total_by_tva_rate = array('0.2' => 0, '0.055' => 0, '0' => 0) ?>
  133. <?php $discount_by_tva_rate = $total_by_tva_rate ?>
  134. var tva_total = 0;
  135. <?php foreach ($total_by_tva_rate as $tva_rate => $tva_rate_total): ?>
  136. <?php $tva_rate_discount = $discount_by_tva_rate[$tva_rate] ?>
  137. tva_total += parseFloat($F('total_by_tva_rate_<?php echo $tva_rates[(string)$tva_rate] ?>'));
  138. <?php endforeach ?>
  139. $('tva_total').value = round2decimals(tva_total + parseFloat($F('fees_shipping_tva')) + parseFloat($F('fees_billing_tva')));
  140. updateTotalTTC();
  141. }
  142. function updateTotalTTC(){
  143. $('ttc_total').innerHTML = round2decimals(parseFloat($F('without_taxes_total')) + parseFloat($F('tva_total')));
  144. }
  145. function updateTotalPrices(){
  146. updateTotalPricesHT();
  147. updateTotalPricesTTC();
  148. }
  149. function round2decimals(value){
  150. return Math.round(value*100)/100;
  151. }
  152. function submitForm(){
  153. if (!$F('supplier')) {
  154. alert('Merci de choisir un fournisseur')
  155. return false;
  156. }
  157. if ('' == $F('reference')) {
  158. alert('Merci de saisir la référence de la facture fournisseur')
  159. return false;
  160. }
  161. var supplier_invoice_orders_checked = 0;
  162. var supplier_invoice_orders = $$('.supplier-invoice-order');
  163. for(var i = 0; i < supplier_invoice_orders.length; i++){
  164. if (supplier_invoice_orders[i].checked) {
  165. supplier_invoice_orders_checked++;
  166. }
  167. }
  168. if (0 == supplier_invoice_orders_checked) {
  169. alert('Merci de sélectionner au moins une commande')
  170. return false;
  171. }
  172. return true;
  173. }
  174. updateOrdersList();
  175. /* ]]> */
  176. </script>