PageRenderTime 102ms CodeModel.GetById 18ms RepoModel.GetById 6ms app.codeStats 0ms

/htdocs/core/tpl/objectline_edit.tpl.php

https://bitbucket.org/speedealing/speedealing
PHP | 376 lines | 309 code | 35 blank | 32 comment | 120 complexity | f51c2bb9646cf2fa60941f4327a76a52 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@capnetworks.com>
  3. * Copyright (C) 2010-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. *
  20. * Need to have following variables defined:
  21. * $conf
  22. * $langs
  23. * $dateSelector
  24. * $this (invoice, order, ...)
  25. * $line defined
  26. */
  27. ?>
  28. <!-- BEGIN PHP TEMPLATE objectline_edit.tpl.php -->
  29. <form action="<?php echo $_SERVER["PHP_SELF"].'?id='.$this->id.'#'.$line->id; ?>" method="POST">
  30. <input type="hidden" name="token" value="<?php echo $_SESSION['newtoken']; ?>">
  31. <input type="hidden" name="action" value="updateligne">
  32. <input type="hidden" name="usenewupdatelineform" value="1" />
  33. <input type="hidden" name="id" value="<?php echo $this->id; ?>">
  34. <input type="hidden" name="lineid" value="<?php echo $line->id; ?>">
  35. <input type="hidden" id="product_type" name="type" value="<?php echo $line->product_type; ?>">
  36. <input type="hidden" id="product_id" name="productid" value="<?php echo (! empty($line->fk_product)?$line->fk_product:0); ?>" />
  37. <tr <?php echo $bc[$var]; ?>>
  38. <td<?php echo (! empty($conf->global->MAIN_VIEW_LINE_NUMBER) ? ' colspan="2"' : ''); ?>>
  39. <div id="<?php echo $line->id; ?>"></div>
  40. <?php
  41. if ($conf->global->MAIN_FEATURES_LEVEL > 1)
  42. {
  43. if ($line->fk_product > 0)
  44. {
  45. echo $text . ' - ';
  46. }
  47. else
  48. {
  49. echo $form->select_type_of_lines($line->product_type, 'type', 1, 1);
  50. }
  51. ?>
  52. <input id="product_label" name="product_label" size="40" value="<?php echo $label; ?>"<?php echo $placeholder . ((! empty($line->fk_product) && empty($line->label)) ? ' disabled="disabled"' : ''); ?>>
  53. <input type="hidden" id="origin_label_cache" name="origin_label_cache" value="<?php echo $line->product_label; ?>" />
  54. <span id="update_label_area" class="hideobject"><input type="checkbox" id="update_label_checkbox" name="update_label" value="1" />
  55. <?php echo $form->textwithtooltip($langs->trans('UpdateOriginalProductLabel'), $langs->trans('HelpUpdateOriginalProductLabel'),1,0,'','',3); ?>
  56. </span>
  57. <span id="price_base_type" class="hideobject"></span>
  58. <br>
  59. <?php } else if ($line->fk_product > 0) { ?>
  60. <a href="<?php echo DOL_URL_ROOT.'/product/fiche.php?id='.$line->fk_product; ?>">
  61. <?php
  62. if ($line->product_type==1) echo img_object($langs->trans('ShowService'),'service');
  63. else print img_object($langs->trans('ShowProduct'),'product');
  64. echo ' '.$line->ref;
  65. ?>
  66. </a>
  67. <?php
  68. echo ' - '.nl2br($line->product_label);
  69. ?>
  70. <br>
  71. <?php } ?>
  72. <?php
  73. if (is_object($hookmanager))
  74. {
  75. $fk_parent_line = (GETPOST('fk_parent_line') ? GETPOST('fk_parent_line') : $line->fk_parent_line);
  76. $parameters=array('line'=>$line,'fk_parent_line'=>$fk_parent_line,'var'=>$var,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer);
  77. $reshook=$hookmanager->executeHooks('formEditProductOptions',$parameters,$this,$action);
  78. }
  79. // editeur wysiwyg
  80. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  81. $nbrows=ROWS_2;
  82. if (! empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) $nbrows=$conf->global->MAIN_INPUT_DESC_HEIGHT;
  83. $enable=(isset($conf->global->FCKEDITOR_ENABLE_DETAILS)?$conf->global->FCKEDITOR_ENABLE_DETAILS:0);
  84. $doleditor=new DolEditor('product_desc',$line->description,'',164,'dolibarr_details','',false,true,$enable,$nbrows,70);
  85. $doleditor->Create();
  86. ?>
  87. </td>
  88. <td align="right"><?php echo $form->load_tva('tva_tx',$line->tva_tx,$seller,$buyer,0,$line->info_bits,$line->product_type); ?></td>
  89. <td align="right"><input type="text" class="flat" size="8" id="price_ht" name="price_ht" value="<?php echo price($line->subprice,0,'',0); ?>"></td>
  90. <?php if ($conf->global->MAIN_FEATURES_LEVEL > 1) { ?>
  91. <td align="right"><input type="text" class="flat" size="8" id="price_ttc" name="price_ttc" value="<?php echo price($pu_ttc,0,'',0); ?>"></td>
  92. <?php } ?>
  93. <td align="right">
  94. <?php if (($line->info_bits & 2) != 2) {
  95. // I comment this because it shows info even when not required
  96. // for example always visible on invoice but must be visible only if stock module on and stock decrease option is on invoice validation and status is not validated
  97. // must also not be output for most entities (proposal, intervention, ...)
  98. //if($line->qty > $line->stock) print img_picto($langs->trans("StockTooLow"),"warning", 'style="vertical-align: bottom;"')." ";
  99. ?>
  100. <input size="3" type="text" class="flat" name="qty" value="<?php echo $line->qty; ?>">
  101. <?php } else { ?>
  102. &nbsp;
  103. <?php } ?>
  104. </td>
  105. <td align="right" nowrap>
  106. <?php if (($line->info_bits & 2) != 2) { ?>
  107. <input size="1" type="text" class="flat" name="remise_percent" value="<?php echo $line->remise_percent; ?>">%
  108. <?php } else { ?>
  109. &nbsp;
  110. <?php } ?>
  111. </td>
  112. <?php if (! empty($conf->margin->enabled)) { ?>
  113. <td align="right">
  114. <select id="fournprice" name="fournprice" class="hideobject"></select>
  115. <input type="text" size="5" id="buying_price" name="buying_price" class="hideobject" value="<?php echo price($line->pa_ht,0,'',0); ?>">
  116. </td>
  117. <?php } ?>
  118. <td align="center" colspan="5" valign="middle">
  119. <input type="submit" class="button" id="savelinebutton" name="save" value="<?php echo $langs->trans("Save"); ?>"><br>
  120. <input type="submit" class="button" id="cancellinebutton" name="cancel" value="<?php echo $langs->trans("Cancel"); ?>">
  121. </td>
  122. </tr>
  123. <?php if (! empty($conf->service->enabled) && $line->product_type == 1 && $dateSelector) { ?>
  124. <tr id="service_duration_area" <?php echo $bc[$var]; ?>>
  125. <td colspan="11"><?php echo $langs->trans('ServiceLimitedDuration').' '.$langs->trans('From').' '; ?>
  126. <?php
  127. $hourmin=(isset($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE)?$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE:'');
  128. echo $form->select_date($line->date_start,'date_start',$hourmin,$hourmin,$line->date_start?0:1,"updateligne");
  129. echo ' '.$langs->trans('to').' ';
  130. echo $form->select_date($line->date_end,'date_end',$hourmin,$hourmin,$line->date_end?0:1,"updateligne");
  131. ?>
  132. </td>
  133. </tr>
  134. <?php } ?>
  135. </form>
  136. <script type="text/javascript">
  137. $(document).ready(function() {
  138. <?php if ($conf->global->MAIN_FEATURES_LEVEL > 1) { ?>
  139. if ($('#product_type').val() == 0) {
  140. $('#service_duration_area').hide();
  141. } else if ($('#product_type').val() == 1) {
  142. $('#service_duration_area').show();
  143. }
  144. if ($('#product_label').attr('disabled')) {
  145. $('#update_label_area').show();
  146. }
  147. $('#update_label_checkbox').change(function() {
  148. if ($(this).attr('checked')) {
  149. $('#product_label').removeAttr('disabled').focus();
  150. } else {
  151. $('#product_label')
  152. .attr('disabled','disabled')
  153. .val($('#origin_label_cache').val());
  154. }
  155. });
  156. $('#select_type').change(function() {
  157. var type = $(this).val();
  158. if (type >= 0) {
  159. if (type == 0) {
  160. $('#service_duration_area').hide();
  161. $('#date_start').val('').trigger('change');
  162. $('#date_end').val('').trigger('change');
  163. } else if (type == 1) {
  164. $('#service_duration_area').show();
  165. }
  166. var addline=false;
  167. if ($('#price_ht').val().length > 0) {
  168. if ($('#product_id').val() == 0) {
  169. if (typeof CKEDITOR == 'object' && typeof CKEDITOR.instances != 'undefined' && CKEDITOR.instances['product_desc'] != 'undefined') {
  170. var content = CKEDITOR.instances['product_desc'].getData();
  171. } else {
  172. var content = $('#product_desc').val();
  173. }
  174. if (content.length > 0) {
  175. addline=true;
  176. }
  177. } else {
  178. addline=true;
  179. }
  180. }
  181. if (addline) {
  182. $('#savelinebutton').removeAttr('disabled');
  183. } else {
  184. $('#savelinebutton').attr('disabled','disabled');
  185. }
  186. } else {
  187. $('#savelinebutton').attr('disabled','disabled');
  188. $('#service_duration_area').hide();
  189. $('#date_start').val('').trigger('change');
  190. $('#date_end').val('').trigger('change');
  191. }
  192. });
  193. $('#price_ht').focusin(function() {
  194. $('#price_base_type').val('HT');
  195. });
  196. $('#price_ht').bind('change keyup input', function() {
  197. if ($('#price_base_type').val() == 'HT') {
  198. update_price('price_ht', 'price_ttc');
  199. }
  200. });
  201. $('#price_ttc').focusin(function() {
  202. $('#price_base_type').val('TTC');
  203. });
  204. $('#price_ttc').bind('change keyup input', function() {
  205. if ($('#price_base_type').val() == 'TTC') {
  206. update_price('price_ttc', 'price_ht');
  207. }
  208. });
  209. if ($('#tva_tx').val() == 0) {
  210. $('#price_ttc').attr('disabled','disabled');
  211. }
  212. $('#tva_tx').change(function() {
  213. if ($(this).val() == 0) {
  214. $('#price_ttc').attr('disabled','disabled');
  215. $('#price_ttc').val('');
  216. } else {
  217. $('#price_ttc').removeAttr('disabled');
  218. if ($('#price_base_type').val() == 'HT') {
  219. update_price('price_ht', 'price_ttc');
  220. } else if ($('#price_base_type').val() == 'TTC') {
  221. update_price('price_ttc', 'price_ht');
  222. }
  223. }
  224. });
  225. function update_price(input, output) {
  226. $.post('<?php echo DOL_URL_ROOT; ?>/core/ajax/price.php', {
  227. 'amount': $('#' + input).val(),
  228. 'output': output,
  229. 'tva_tx': $('#tva_tx').val()
  230. },
  231. function(data) {
  232. var addline=false;
  233. if (typeof data[output] != 'undefined') {
  234. // Hide price_ttc if no vat
  235. if ($('#tva_tx').val() > 0 || ($('#tva_tx').val() == 0 && output == 'price_ht')) {
  236. $('#' + output).val(data[output]);
  237. }
  238. if ($('#product_id').val() == 0 && $('#select_type').val() >= 0) {
  239. if (typeof CKEDITOR == 'object' && typeof CKEDITOR.instances != 'undefined' && CKEDITOR.instances['product_desc'] != 'undefined') {
  240. var content = CKEDITOR.instances['product_desc'].getData();
  241. } else {
  242. var content = $('#product_desc').val();
  243. }
  244. if (content.length > 0) {
  245. addline=true;
  246. }
  247. } else {
  248. addline=true;
  249. }
  250. } else {
  251. $('#' + input).val('');
  252. $('#' + output).val('');
  253. }
  254. if (addline) {
  255. $('#savelinebutton').removeAttr('disabled');
  256. } else {
  257. $('#savelinebutton').attr('disabled','disabled');
  258. }
  259. }, 'json');
  260. }
  261. // Check if decription is not empty for free line
  262. <?php if (! empty($conf->fckeditor->enabled) && ! empty($conf->global->FCKEDITOR_ENABLE_DETAILS)) { ?>
  263. CKEDITOR.on('instanceReady', function() {
  264. CKEDITOR.instances['product_desc'].on('key', function() {
  265. var addline=false;
  266. if ($('#product_id').val() == 0 && $('#select_type').val() >= 0 && $('#price_ht').val().length > 0) {
  267. var content = CKEDITOR.instances['product_desc'].getData();
  268. if (content.length > 0) {
  269. addline=true;
  270. }
  271. } else if ($('#product_id').val() > 0 && $('#price_ht').val().length > 0) {
  272. addline=true;
  273. }
  274. if (addline) {
  275. $('#savelinebutton').removeAttr('disabled');
  276. } else {
  277. $('#savelinebutton').attr('disabled','disabled');
  278. }
  279. });
  280. });
  281. <?php } else { ?>
  282. $('#product_desc').onDelayedKeyup({
  283. 'handler': function() {
  284. var addline=false;
  285. if ($('#product_id').val() == 0 && $('#select_type').val() >= 0 && $('#price_ht').val().length > 0) {
  286. var content = $('#product_desc').val();
  287. if (content.length > 0) {
  288. addline=true;
  289. }
  290. } else if ($('#product_id').val() > 0 && $('#price_ht').val().length > 0) {
  291. addline=true;
  292. }
  293. if (addline) {
  294. $('#savelinebutton').removeAttr('disabled');
  295. } else {
  296. $('#savelinebutton').attr('disabled','disabled');
  297. }
  298. }
  299. });
  300. <?php } ?>
  301. <?php } ?>
  302. <?php if (! empty($conf->margin->enabled)) { ?>
  303. $.post('<?php echo DOL_URL_ROOT; ?>/fourn/ajax/getSupplierPrices.php', {'idprod': <?php echo $line->fk_product?$line->fk_product:0; ?>}, function(data) {
  304. if (data && data.length > 0) {
  305. var options = '';
  306. var trouve=false;
  307. $(data).each(function() {
  308. options += '<option value="'+this.id+'" price="'+this.price+'"';
  309. <?php if ($line->fk_fournprice > 0) { ?>
  310. if (this.id == <?php echo $line->fk_fournprice; ?>) {
  311. options += ' selected';
  312. $("#buying_price").val(this.price);
  313. trouve = true;
  314. }
  315. <?php } ?>
  316. options += '>'+this.label+'</option>';
  317. });
  318. options += '<option value=null'+(trouve?'':' selected')+'><?php echo $langs->trans("InputPrice"); ?></option>';
  319. $("#fournprice").html(options);
  320. if (trouve) {
  321. $("#buying_price").hide();
  322. $("#fournprice").show();
  323. } else {
  324. $("#buying_price").show();
  325. }
  326. $("#fournprice").change(function() {
  327. var selval = $(this).find('option:selected').attr("price");
  328. if (selval)
  329. $("#buying_price").val(selval).hide();
  330. else
  331. $('#buying_price').show();
  332. });
  333. } else {
  334. $("#fournprice").hide();
  335. $('#buying_price').show();
  336. }
  337. }, 'json');
  338. <?php } ?>
  339. });
  340. </script>
  341. <!-- END PHP TEMPLATE objectline_edit.tpl.php -->