editSuccess.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <?php $katao_product = $form->getObject() ?>
  2. <div class="content-add01">
  3. <div class="heading01"><h1><?php echo $katao_product->isNew() ? 'Ajout' : 'Modification' ?> d'un produit</h1></div>
  4. </div>
  5. <form action="<?php echo url_for('kataoProduct/update' . (!$katao_product->isNew() ? '?id=' . $katao_product->getId() : '')) ?>" method="post" <?php $form->isMultipart() and print 'enctype="multipart/form-data" ' ?>>
  6. <table>
  7. <tfoot>
  8. <tr>
  9. <td colspan="2">
  10. <br /><input type="submit" value="Sauver" onclick="if(checkPrices()){computeMaxSolAmount();return true;}else{return false;}" /> ou <a href="<?php echo url_for('kataoProduct/index') ?>">annuler</a><?php if (!$katao_product->isNew()): ?> ou <a href="<?php echo url_for('@katao_product_edit_presentation?id=' . $katao_product->getId()) ?>">modifier sa présentation</a><?php endif ?>
  11. </td>
  12. </tr>
  13. </tfoot>
  14. <tbody>
  15. <?php echo $form->renderGlobalErrors() ?>
  16. <tr valign="top">
  17. <td colspan="2" align="left"><u>Produit</u></td>
  18. </tr>
  19. <tr valign="top">
  20. <th align="left"><?php echo $form['name']->renderLabel() ?></th>
  21. <td>
  22. <?php echo $form['name'] ?>
  23. <?php echo $form['name']->renderError() ?>
  24. </td>
  25. </tr>
  26. <tr valign="top">
  27. <th align="left"><?php echo $form['reference']->renderLabel() ?></th>
  28. <td>
  29. <?php echo $form['reference'] ?>
  30. <?php echo $form['reference']->renderError() ?>
  31. </td>
  32. </tr>
  33. <tr valign="top">
  34. <th align="left"><?php echo $form['katao_product_family_id']->renderLabel() ?></th>
  35. <td>
  36. <?php echo $form['katao_product_family_id'] ?>
  37. <?php echo $form['katao_product_family_id']->renderError() ?>
  38. </td>
  39. </tr>
  40. <tr valign="top">
  41. <th align="left"><?php echo $form['picture']->renderLabel() ?></th>
  42. <td>
  43. <?php echo $form['picture'] ?>
  44. <?php echo $form['picture']->renderError() ?>
  45. </td>
  46. </tr>
  47. <tr valign="top">
  48. <td colspan="2" align="left"><br /><u>Fournisseur</u></td>
  49. </tr>
  50. <?php if (!$sf_user->isJustSupplier()): ?>
  51. <tr valign="top">
  52. <th align="left"><?php echo $form['katao_supplier_id']->renderLabel() ?></th>
  53. <td>
  54. <?php echo $form['katao_supplier_id'] ?>
  55. <?php echo $form['katao_supplier_id']->renderError() ?>
  56. </td>
  57. </tr>
  58. <?php endif ?>
  59. <tr valign="top">
  60. <th align="left"><?php echo $form['min_order_number']->renderLabel() ?></th>
  61. <td>
  62. <?php echo $form['min_order_number'] ?>
  63. <?php echo $form['min_order_number']->renderError() ?>
  64. </td>
  65. </tr>
  66. <tr valign="top">
  67. <th align="left"><?php echo $form['delivery_delay']->renderLabel() ?></th>
  68. <td>
  69. <?php echo $form['delivery_delay'] ?> jours
  70. <?php echo $form['delivery_delay']->renderError() ?>
  71. </td>
  72. </tr>
  73. <tr valign="top">
  74. <th align="left"><?php echo $form['is_archived']->renderLabel() ?></th>
  75. <td>
  76. <?php echo $form['is_archived'] ?>
  77. <?php echo $form['is_archived']->renderError() ?>
  78. <?php echo $form['id'] ?>
  79. <?php if ($sf_user->isJustSupplier()): ?>
  80. <?php echo input_hidden_tag('katao_product[katao_supplier_id]', $sf_user->getInstance()->getKataoSupplierId()) ?>
  81. <?php echo input_hidden_tag('katao_product[margin]', $form['margin']->getValue()) ?>
  82. <?php echo input_hidden_tag('katao_product[tva_rate]', $form['tva_rate']->getValue()) ?>
  83. <?php endif ?>
  84. </td>
  85. </tr>
  86. <tr valign="top">
  87. <td colspan="2" align="left"><br /><u>Tarification</u></td>
  88. </tr>
  89. <tr valign="top">
  90. <th align="left"><?php echo $form['unit_price_euro']->renderLabel() ?></th>
  91. <td>
  92. <?php echo $form['unit_price_euro'] ?> €
  93. <?php if (!$sf_user->isJustSupplier()): ?>
  94. &nbsp;<a href="javascript://" onclick="computeUnitPriceWithTaxes();" title="Calculer le prix de vente TTC"><?php echo image_tag('actions/calculator.png', array('alt' => 'Calculer le prix de vente TTC', 'align' => 'top')) ?></a>
  95. <?php endif ?>
  96. <?php echo $form['unit_price_euro']->renderError() ?>
  97. </td>
  98. </tr>
  99. <?php if (!$sf_user->isJustSupplier()): ?>
  100. <tr valign="top">
  101. <th align="left"><?php echo $form['margin']->renderLabel() ?></th>
  102. <td>
  103. <?php echo $form['margin'] ?> %
  104. <?php if (!$sf_user->isJustSupplier()): ?>
  105. &nbsp;<a href="javascript://" onclick="computeMargin();" title="Calculer la marge"><?php echo image_tag('actions/calculator.png', array('alt' => 'Calculer la marge', 'align' => 'top')) ?></a>
  106. <?php endif ?>
  107. <?php echo $form['margin']->renderError() ?>
  108. </td>
  109. </tr>
  110. <?php endif ?>
  111. <tr valign="top">
  112. <th align="left"><?php echo $form['tva_rate']->renderLabel() ?></th>
  113. <td>
  114. <?php echo $form['tva_rate'] ?>
  115. <?php echo $form['tva_rate']->renderError() ?>
  116. </td>
  117. </tr>
  118. <?php if (!$sf_user->isJustSupplier()): ?>
  119. <tr valign="top">
  120. <th align="left"><label>Prix de vente TTC</label></th>
  121. <td>
  122. <?php echo input_tag('sell_price', '', array('style' => 'width: 54px')) ?> €
  123. &nbsp;<a href="javascript://" onclick="computeUnitPriceWithoutTaxes();" title="Calculer le prix d'achat HT"><?php echo image_tag('actions/calculator.png', array('alt' => 'Calculer le prix d\'achat HT', 'align' => 'top')) ?></a>
  124. </td>
  125. </tr>
  126. <?php endif ?>
  127. <tr valign="top">
  128. <td colspan="2" align="left"><br /><u>Monnaie complémentaire</u></td>
  129. </tr>
  130. <?php if (!$sf_user->isJustSupplier()): ?>
  131. <tr valign="top">
  132. <th align="left"><label>Pourcentage</label></th>
  133. <td>
  134. <?php echo input_tag('sol_percent', '', array('style' => 'width: 54px')) ?> %
  135. </td>
  136. </tr>
  137. <?php endif ?>
  138. <tr valign="top">
  139. <th align="left"><?php echo $form['max_sol_amount']->renderLabel() ?></th>
  140. <td>
  141. <?php echo $form['max_sol_amount'] ?> <?php echo wpConfig::getAdditionalCurrencyName() ?>
  142. <?php if (!$sf_user->isJustSupplier()): ?>
  143. &nbsp;<a href="javascript://" onclick="computeMaxSolAmount();" title="Calculer le montant maxi de la monnaie complémentaire"><?php echo image_tag('actions/calculator.png', array('alt' => 'Calculer le montant maxi de la monnaie complémentaire', 'align' => 'top')) ?></a>
  144. <?php endif ?>
  145. <?php echo $form['max_sol_amount']->renderError() ?>
  146. </td>
  147. </tr>
  148. <?php if (!$sf_user->isJustSupplier()): ?>
  149. <tr valign="top">
  150. <td colspan="2" align="left"><br /><u>Codes comptables</u></td>
  151. </tr>
  152. <tr valign="top">
  153. <th align="left"><?php echo $form['accounting_code_purchase']->renderLabel() ?></th>
  154. <td>
  155. <?php echo $form['accounting_code_purchase'] ?>
  156. <?php echo $form['accounting_code_purchase']->renderError() ?>
  157. </td>
  158. </tr>
  159. <tr valign="top">
  160. <th align="left"><?php echo $form['accounting_code_sell']->renderLabel() ?></th>
  161. <td>
  162. <?php echo $form['accounting_code_sell'] ?>
  163. <?php echo $form['accounting_code_sell']->renderError() ?>
  164. </td>
  165. </tr>
  166. <tr><td colspan="2"><i>Laisser vide pour utiliser celui du rayon</i></td></tr>
  167. <?php endif ?>
  168. </tbody>
  169. </table>
  170. </form>
  171. <script type="text/javascript" language="JavaScript">
  172. /* <![CDATA[ */
  173. function checkPrices(){
  174. var price_ht_displayed = parseFloat($F('katao_product_unit_price_euro'));
  175. var price_ht_calculated = round3decimals(parseFloat($F('sell_price')) / (1+parseFloat($F('katao_product_margin'))/100) / (1+parseFloat($F('katao_product_tva_rate'))));
  176. if (price_ht_displayed != price_ht_calculated) {
  177. alert('ATTENTION : Le prix d\'achat HT ('+price_ht_displayed+' €) ne correspond pas à celui calculé ('+price_ht_calculated+' €).\n\nMerci de bien vouloir le modifier ou le calculer en cliquant sur la calculette\nà côté du champ "Prix de vente TTC".\n');
  178. return false;
  179. }
  180. return true;
  181. }
  182. function computeUnitPriceWithTaxes(){
  183. $('sell_price').value = round2decimals(parseFloat($F('katao_product_unit_price_euro')) * (1+parseFloat($F('katao_product_margin'))/100) * (1+parseFloat($F('katao_product_tva_rate'))));
  184. }
  185. function computeUnitPriceWithoutTaxes(){
  186. $('katao_product_unit_price_euro').value = round3decimals(parseFloat($F('sell_price')) / (1+parseFloat($F('katao_product_margin'))/100) / (1+parseFloat($F('katao_product_tva_rate'))));
  187. }
  188. function computeMaxSolAmount(){
  189. if (!$F('sol_percent')) {
  190. $('sol_percent').value = 0;
  191. }
  192. if (!$F('sell_price')) {
  193. computeUnitPriceWithTaxes();
  194. }
  195. $('katao_product_max_sol_amount').value = Math.floor(10 * parseFloat($F('sell_price')) * parseFloat($F('sol_percent')) / 100);
  196. }
  197. function computeSolPercent(){
  198. $('sol_percent').value = Math.round(100 * parseFloat($F('katao_product_max_sol_amount')) / parseFloat($F('sell_price')) / 10);
  199. }
  200. function computeMargin(){
  201. $('katao_product_margin').value = Math.round(100 * parseFloat($F('sell_price')) / (parseFloat($F('katao_product_unit_price_euro')) * (parseFloat($F('katao_product_tva_rate')) + 1)) - 100);
  202. }
  203. function round2decimals(value){
  204. return Math.round(value*100)/100;
  205. }
  206. function round3decimals(value){
  207. return Math.round(value*1000)/1000;
  208. }
  209. var margin = parseFloat($F('katao_product_margin'));
  210. if (1 >= margin) {
  211. margin = 100 * margin;
  212. }
  213. $('katao_product_margin').value = margin;
  214. <?php if (!$sf_user->isJustSupplier()): ?>
  215. <?php if ($katao_product->isNew() && !$sf_request->isMethod('post')): ?>
  216. $('sell_price').value = '';
  217. $('sol_percent').value = <?php echo wpConfig::getDefaultProductSolPercent() ?>
  218. <?php else: ?>
  219. computeUnitPriceWithTaxes();
  220. computeSolPercent();
  221. <?php endif ?>
  222. <?php endif ?>
  223. /* ]]> */
  224. </script>