No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

808 líneas
30KB

  1. /**
  2. Copyright La boîte à pain (2018)
  3. contact@laboiteapain.net
  4. Ce logiciel est un programme informatique servant à aider les producteurs
  5. à distribuer leur production en circuits courts.
  6. Ce logiciel est régi par la licence CeCILL soumise au droit français et
  7. respectant les principes de diffusion des logiciels libres. Vous pouvez
  8. utiliser, modifier et/ou redistribuer ce programme sous les conditions
  9. de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA
  10. sur le site "http://www.cecill.info".
  11. En contrepartie de l'accessibilité au code source et des droits de copie,
  12. de modification et de redistribution accordés par cette licence, il n'est
  13. offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons,
  14. seule une responsabilité restreinte pèse sur l'auteur du programme, le
  15. titulaire des droits patrimoniaux et les concédants successifs.
  16. A cet égard l'attention de l'utilisateur est attirée sur les risques
  17. associés au chargement, à l'utilisation, à la modification et/ou au
  18. développement et à la reproduction du logiciel par l'utilisateur étant
  19. donné sa spécificité de logiciel libre, qui peut le rendre complexe à
  20. manipuler et qui le réserve donc à des développeurs et des professionnels
  21. avertis possédant des connaissances informatiques approfondies. Les
  22. utilisateurs sont donc invités à charger et tester l'adéquation du
  23. logiciel à leurs besoins dans des conditions permettant d'assurer la
  24. sécurité de leurs systèmes et ou de leurs données et, plus généralement,
  25. à l'utiliser et l'exploiter dans les mêmes conditions de sécurité.
  26. Le fait que vous puissiez accéder à cet en-tête signifie que vous avez
  27. pris connaissance de la licence CeCILL, et que vous en avez accepté les
  28. termes.
  29. */
  30. $(document).ready(function() {
  31. chat_calendar() ;
  32. chat_datepicker() ;
  33. chat_vrac() ;
  34. chat_email_masse() ;
  35. $('button[data-toggle=popover]').popover() ;
  36. chat_ordre_produits() ;
  37. chat_index_commandes_liste_produits() ;
  38. chat_index_commandes_points_vente() ;
  39. chat_index_commandes_points_vente_livraison() ;
  40. chat_btn_plus_moins() ;
  41. chat_commandeauto() ;
  42. chat_points_vente_acces() ;
  43. chat_tooltip() ;
  44. chat_points_vente_jours_livraison() ;
  45. chat_index_commandes_maj_points_vente() ;
  46. // admin
  47. chat_select_etablissement() ;
  48. }) ;
  49. var UrlManager = {
  50. getBaseUrl: function() {
  51. return $('meta[name=baseurl]').attr('content')+'/' ;
  52. },
  53. getBaseUrlAbsolute: function() {
  54. return $('meta[name=baseurl-absolute]').attr('content')+'/' ;
  55. }
  56. };
  57. function chat_tooltip() {
  58. $('[data-toggle="tooltip"]').tooltip({container:'body'});
  59. }
  60. function chat_nl2br(str, is_xhtml) {
  61. var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '<br />' : '<br>';
  62. return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1'+ breakTag +'$2');
  63. }
  64. function chat_index_commandes_points_vente_livraison() {
  65. $('#productionpointvente-productions_point_vente input[type=checkbox]').change(function() {
  66. var nb = $('#productionpointvente-productions_point_vente input[type=checkbox]:checked').size() ;
  67. if(nb == 0) {
  68. $(this).prop('checked',true) ;
  69. chat_alert('danger','Vous devez avoir au moins un point de vente activé') ;
  70. }
  71. else {
  72. var val = $(this).val() ;
  73. var arr_val = val.split('-') ;
  74. var livraison = 0 ;
  75. if($(this).prop('checked'))
  76. livraison = 1 ;
  77. $.get(UrlManager.getBaseUrl()+'commande/ajax-point-vente-livraison',{
  78. id_production: arr_val[0],
  79. id_point_vente: arr_val[1],
  80. bool_livraison: livraison
  81. }, function(data) {
  82. chat_alert('success','Point de vente modifié') ;
  83. }) ;
  84. chat_index_commandes_maj_points_vente() ;
  85. }
  86. }) ;
  87. }
  88. function chat_index_commandes_maj_points_vente() {
  89. if($('#productions-point-vente').size()) {
  90. var nb = $('#productionpointvente-productions_point_vente input[type=checkbox]:checked').size() ;
  91. if(nb == 0)
  92. {
  93. $('#panel-commandes #tabs-points-vente, #panel-commandes #commandes-points-vente').hide() ;
  94. $('#panel-commandes .alert-danger').show();
  95. }
  96. else {
  97. $('#panel-commandes #tabs-points-vente, #panel-commandes #commandes-points-vente').show() ;
  98. $('#panel-commandes .alert-danger').hide();
  99. }
  100. }
  101. var id_production = $('#id-production').val() ;
  102. if(id_production) {
  103. $('#tabs-points-vente li').each(function() {
  104. var id_point_vente = $(this).find('a').attr('id').replace('btn-point-vente-','') ;
  105. var nb_commandes = parseInt($(this).find('.badge-success').html()) ;
  106. var checked = $('#productionpointvente-productions_point_vente input[value='+id_production+'-'+id_point_vente+']').prop('checked') ;
  107. if(checked || nb_commandes > 0)
  108. {
  109. $(this).show() ;
  110. }
  111. else {
  112. $(this).hide() ;
  113. }
  114. }) ;
  115. $('#tabs-points-vente li:visible:first a').click() ;
  116. }
  117. }
  118. function chat_points_vente_jours_livraison() {
  119. $('#pointvente-point_fabrication').change(function() {
  120. chat_points_vente_jours_livraison_event() ;
  121. }) ;
  122. chat_points_vente_jours_livraison_event();
  123. }
  124. function chat_points_vente_jours_livraison_event() {
  125. if($('#pointvente-point_fabrication').prop('checked')) {
  126. $('#jours-livraison').hide() ;
  127. }
  128. else {
  129. $('#jours-livraison').fadeIn() ;
  130. }
  131. }
  132. function chat_points_vente_acces() {
  133. // affichage du bloc acces restreint
  134. $('#pointvente-acces_restreint').change(function() {
  135. chat_points_vente_acces_event() ;
  136. }) ;
  137. chat_points_vente_acces_event() ;
  138. // affichage du champs commentaire
  139. $('#pointvente-users input[type=checkbox]').change(function() {
  140. chat_points_vente_commentaire_event() ;
  141. }) ;
  142. chat_points_vente_commentaire_event() ;
  143. }
  144. function chat_points_vente_commentaire_event() {
  145. $('#pointvente-users input[type=checkbox]').each(function() {
  146. if($(this).prop('checked')) {
  147. $(this).parent().find('.commentaire').fadeIn() ;
  148. }
  149. else {
  150. $(this).parent().find('.commentaire').hide() ;
  151. }
  152. }) ;
  153. }
  154. function chat_points_vente_acces_event() {
  155. if($('#pointvente-acces_restreint').prop('checked')) {
  156. $('#pointvente-users').fadeIn() ;
  157. }
  158. else {
  159. $('#pointvente-users').hide() ;
  160. }
  161. }
  162. function chat_select_etablissement() {
  163. $('select[name="select_etablissement"]').change(function() {
  164. window.location.href = UrlManager.getBaseUrlAbsolute()+'/site/change-etablissement?id='+$(this).val() ;
  165. }) ;
  166. }
  167. function chat_commandeauto() {
  168. // dates
  169. $('#commandeautoform-date_debut, #commandeautoform-date_fin').datepicker() ;
  170. }
  171. function chat_index_commandes_points_vente() {
  172. $('#commandes-points-vente .liste-commandes a').unbind('click').click(function() {
  173. var id_pv = $(this).data('pv-id') ;
  174. // affiche la commande
  175. var id_commande = $(this).data('id-commande') ;
  176. chat_index_commandes_affiche_commande(id_pv, id_commande) ;
  177. }) ;
  178. $('#commandes-points-vente .bloc-point-vente').each(function() {
  179. var id_pv = $(this).data('id-pv') ;
  180. // edit
  181. $('#point-vente-'+id_pv+' .btn-edit').unbind('click').click(function() {
  182. // boutons
  183. $('#point-vente-'+id_pv+' .buttons-edit-remove').hide() ;
  184. $('#point-vente-'+id_pv+' .buttons-save-cancel').show() ;
  185. $('#point-vente-'+id_pv+' .tr-total').hide() ;
  186. // inputs
  187. chat_index_commandes_inputs_commande(id_pv, true) ;
  188. }) ;
  189. // remove
  190. $('#point-vente-'+id_pv+' .btn-remove').unbind('click').click(function() {
  191. var id_commande = $(this).data('id-commande') ;
  192. $(this).attr('disabled', 'disabled') ;
  193. $.get(UrlManager.getBaseUrl()+'commande/ajax-delete',{
  194. date: $('#date-production').val(),
  195. id_commande: id_commande
  196. }, function(data) {
  197. $('#point-vente-'+id_pv+' .btn-remove').removeAttr('disabled') ;
  198. if($('#point-vente-'+id_pv+' .liste-commandes li').size()) {
  199. if($('#point-vente-'+id_pv+' .liste-commandes li:last-child a').is('.active')) {
  200. var commande_next = $('#point-vente-'+id_pv+' .liste-commandes a.active').parent().prev().find('a') ;
  201. }
  202. else {
  203. var commande_next = $('#point-vente-'+id_pv+' .liste-commandes a.active').parent().next().find('a') ;
  204. }
  205. $('#point-vente-'+id_pv+' .liste-commandes a.active').parent().remove() ;
  206. if($('#point-vente-'+id_pv+' .liste-commandes li').size()) {
  207. chat_index_commandes_affiche_commande(id_pv, commande_next.data('id-commande')) ;
  208. }
  209. else {
  210. $('#point-vente-'+id_pv+' .liste-commandes').hide() ;
  211. $('#point-vente-'+id_pv+' .creer-commande').trigger('click') ;
  212. }
  213. }
  214. chat_index_commandes_maj_recap_pv(id_pv, data.total_pv) ;
  215. chat_index_commandes_maj_total_commandes() ;
  216. chat_alert('success','Commande supprimée') ;
  217. }, 'json') ;
  218. });
  219. // cancel
  220. $('#point-vente-'+id_pv+' .btn-cancel').unbind('click').click(function() {
  221. $('#point-vente-'+id_pv+' .buttons-edit-remove').show() ;
  222. $('#point-vente-'+id_pv+' .buttons-save-cancel').hide() ;
  223. $('#point-vente-'+id_pv+' .btn-save').removeClass('is-create') ;
  224. chat_index_commandes_affiche_commande(id_pv, $(this).data('id-commande')) ;
  225. }) ;
  226. // save
  227. $('#point-vente-'+id_pv+' .btn-save').unbind('click').click(function() {
  228. var tab_produits = {} ;
  229. var cpt_produits = 0 ;
  230. $('#point-vente-'+id_pv+' .table-produits tr').each(function() {
  231. tab_produits[$(this).data('id-produit')] = $(this).find('.quantite').val() ;
  232. if($(this).find('.quantite').val())
  233. cpt_produits ++ ;
  234. }) ;
  235. if(cpt_produits) {
  236. // création
  237. if($(this).hasClass('is-create')) {
  238. if($('#point-vente-'+id_pv+' .user-id').val() || $('#point-vente-'+id_pv+' .username').val().length) {
  239. $(this).attr('disabled', 'disabled') ;
  240. $.get(UrlManager.getBaseUrl()+'commande/ajax-create',{
  241. date: $('#date-production').val(),
  242. id_pv: id_pv,
  243. id_user: $('#point-vente-'+id_pv+' .user-id').val(),
  244. username: $('#point-vente-'+id_pv+' .username').val(),
  245. produits: JSON.stringify(tab_produits),
  246. commentaire: $('#point-vente-'+id_pv+' .textarea-commentaire').val()
  247. }, function(data) {
  248. $('#point-vente-'+id_pv+' .btn-save').removeAttr('disabled') ;
  249. $('#point-vente-'+id_pv+' .btn-save').removeClass('is-create') ;
  250. $('#point-vente-'+id_pv+' .liste-commandes').append(data.commande) ;
  251. chat_index_commandes_points_vente() ;
  252. chat_index_commandes_maj_recap_pv(id_pv, data.total_pv) ;
  253. $('#point-vente-'+id_pv+' .buttons-edit-remove').show() ;
  254. $('#point-vente-'+id_pv+' .buttons-save-cancel').hide() ;
  255. $('#point-vente-'+id_pv+' .btn-create').removeClass('is-create') ;
  256. $('#point-vente-'+id_pv+' .user-id').val(0) ;
  257. $('#point-vente-'+id_pv+' .user-id').val('') ;
  258. chat_index_commandes_affiche_commande(id_pv, data.id_commande) ;
  259. chat_alert('success', 'Commande créée') ;
  260. }, 'json') ;
  261. }
  262. else {
  263. chat_alert('danger', 'Veuillez choisir ou saisir un nom d\'utilisateur') ;
  264. }
  265. }
  266. // modification
  267. else {
  268. var id_commande = $(this).data('id-commande') ;
  269. $(this).attr('disabled', 'disabled') ;
  270. $.get(UrlManager.getBaseUrl()+'commande/ajax-update',{
  271. id_commande: id_commande,
  272. produits: JSON.stringify(tab_produits),
  273. date: $('#date-production').val(),
  274. commentaire: $('#point-vente-'+id_pv+' .textarea-commentaire').val()
  275. }, function(data) {
  276. $('#point-vente-'+id_pv+' .btn-save').removeAttr('disabled') ;
  277. $('#point-vente-'+id_pv+' a[data-id-commande='+id_commande+']').attr('data-commande',data.json_commande);
  278. $('#point-vente-'+id_pv+' a[data-id-commande='+id_commande+'] .montant').html(data.json_commande.str_montant) ;
  279. chat_index_commandes_affiche_commande(id_pv, id_commande) ;
  280. chat_index_commandes_maj_recap_pv(id_pv, data.total_pv) ;
  281. $('#point-vente-'+id_pv+' .buttons-edit-remove').show() ;
  282. $('#point-vente-'+id_pv+' .buttons-save-cancel').hide() ;
  283. chat_alert('success','Commande modifiée') ;
  284. }, 'json') ;
  285. }
  286. }
  287. else {
  288. chat_alert('danger', 'Veuillez saisir au moins un produit') ;
  289. }
  290. chat_index_commandes_maj_total_commandes() ;
  291. }) ;
  292. // create
  293. $('.creer-commande').unbind('click').click(function() {
  294. var id_pv = $(this).data('pv-id') ;
  295. $('#point-vente-'+id_pv+' .bloc-commande').fadeIn() ;
  296. $('#point-vente-'+id_pv+' .liste-commandes a.active').removeClass('active') ;
  297. $('#point-vente-'+id_pv+' .tr-total').hide() ;
  298. $('#point-vente-'+id_pv+' .buttons-edit-remove').hide() ;
  299. $('#point-vente-'+id_pv+' .the-title').hide() ;
  300. $('#point-vente-'+id_pv+' .buttons-save-cancel').show() ;
  301. $('#point-vente-'+id_pv+' .choix-user').show() ;
  302. $('#point-vente-'+id_pv+' .choix-user .user-id').val(0) ;
  303. $('#point-vente-'+id_pv+' .choix-user .username').val('') ;
  304. $('#point-vente-'+id_pv+' .commentaire').hide() ;
  305. $('#point-vente-'+id_pv+' .btn-save').addClass('is-create');
  306. /*if(!$('#point-vente-'+id_pv+' .btn-cancel').data('id-commande') &&
  307. $('#point-vente-'+id_pv+' .liste-commandes li').size()) {
  308. $('#point-vente-'+id_pv+' .btn-cancel').data('id-commande',$('#point-vente-'+id_pv+' .liste-commandes li:first a').data('id-commande')) ;
  309. }*/
  310. $('#point-vente-'+id_pv+' .btn-save').data('id-commande',0) ;
  311. chat_index_commandes_inputs_commande(id_pv, false) ;
  312. $('#point-vente-'+id_pv+' .title-user').show() ;
  313. }) ;
  314. }) ;
  315. $('#commandes-points-vente .liste-commandes').each(function() {
  316. //$(this).find('a:first').trigger('click') ;
  317. }) ;
  318. }
  319. function chat_index_commandes_maj_total_commandes() {
  320. $.get(UrlManager.getBaseUrl()+'commande/ajax-total-commandes',{
  321. date: $('#date-production').val()
  322. }, function(data) {
  323. $('#bloc-totaux').html(data.html_totaux) ;
  324. }, 'json') ;
  325. }
  326. function chat_index_commandes_maj_recap_pv(id_pv, total) {
  327. $('#point-vente-'+id_pv+' .recap-pv .recettes').html(total) ;
  328. var nb_commandes = $('#point-vente-'+id_pv+' .liste-commandes li').size() ;
  329. if(nb_commandes == 0) {
  330. $('#point-vente-'+id_pv+' .recap-pv .commandes').html('Aucune commande') ;
  331. $('#point-vente-'+id_pv+' .recap-pv .recettes').hide() ;
  332. $('#point-vente-'+id_pv+' .liste-commandes').addClass('no-commande') ;
  333. }
  334. else if(nb_commandes == 1) {
  335. $('#point-vente-'+id_pv+' .recap-pv .commandes').html('1 commande') ;
  336. $('#point-vente-'+id_pv+' .recap-pv .recettes').show() ;
  337. $('#point-vente-'+id_pv+' .liste-commandes').removeClass('no-commande') ;
  338. }
  339. else {
  340. $('#point-vente-'+id_pv+' .recap-pv .commandes').html(nb_commandes+' commandes') ;
  341. $('#point-vente-'+id_pv+' .recap-pv .recettes').show() ;
  342. $('#point-vente-'+id_pv+' .liste-commandes').removeClass('no-commande') ;
  343. }
  344. $('#btn-point-vente-'+id_pv+' .badge').html(nb_commandes) ;
  345. }
  346. function chat_index_commandes_inputs_commande(id_pv, use_quantite) {
  347. // commentaire
  348. $('#point-vente-'+id_pv+' .commentaire').hide() ;
  349. $('#point-vente-'+id_pv+' .textarea-commentaire').show() ;
  350. var id_commande = $('#point-vente-'+id_pv+' .btn-save').data('id-commande') ;
  351. if(id_commande) {
  352. var link = $('a[data-id-commande='+id_commande+']') ;
  353. if(!$.isPlainObject(link.attr('data-commande'))) {
  354. var commande = JSON.parse(link.attr('data-commande')) ;
  355. if(commande.commentaire && commande.commentaire.length)
  356. $('#point-vente-'+id_pv+' .textarea-commentaire').val(commande.commentaire) ;
  357. }
  358. }
  359. else {
  360. $('#point-vente-'+id_pv+' .textarea-commentaire').val('') ;
  361. }
  362. // produits
  363. $('#point-vente-'+id_pv+' .table-produits tr').each(function() {
  364. var quantite = '' ;
  365. if(use_quantite)
  366. quantite = $(this).find('.td-commande').html() ;
  367. var id_produit = $(this).data('id-produit') ;
  368. $(this).find('.td-commande').html('<div class="input-group">'+
  369. '<span class="input-group-btn">'+
  370. '<button class="btn btn-default btn-moins" type="button"><span class="glyphicon glyphicon-minus"></span></button>'+
  371. '</span>'+
  372. '<input type="text" class="form-control quantite" value="'+quantite+'" name="produit_'+id_produit+'">'+
  373. '<span class="input-group-btn">'+
  374. '<button class="btn btn-default btn-plus" type="button"><span class="glyphicon glyphicon-plus"></span></button>'+
  375. '</span>'+
  376. '</div>') ;
  377. }) ;
  378. // plus / moins
  379. chat_btn_plus_moins() ;
  380. }
  381. function chat_btn_plus_moins() {
  382. $('.btn-plus').each(function() {
  383. $(this).click(function() {
  384. var input = $(this).parent().parent().find('input') ;
  385. var value = input.val() ;
  386. if(value)
  387. value ++ ;
  388. else
  389. value = 1 ;
  390. input.val(value) ;
  391. }) ;
  392. }) ;
  393. $('.btn-moins').each(function() {
  394. $(this).click(function() {
  395. var input = $(this).parent().parent().find('input') ;
  396. var value = input.val() ;
  397. if(value && value > 1)
  398. value -- ;
  399. else
  400. value = '' ;
  401. input.val(value) ;
  402. }) ;
  403. }) ;
  404. }
  405. function chat_index_commandes_affiche_commande(id_pv, id_commande) {
  406. var link = $("a[data-id-commande="+id_commande+"]") ;
  407. if(id_commande) {
  408. $('#point-vente-'+id_pv+' .bloc-commande').hide() ;
  409. $('#point-vente-'+id_pv+' .liste-commandes a').removeClass('active') ;
  410. link.addClass('active') ;
  411. var commande = link.attr('data-commande') ;
  412. if(!$.isPlainObject(link.attr('data-commande'))) {
  413. commande = JSON.parse(link.attr('data-commande')) ;
  414. }
  415. // maj ligne commande
  416. $('#point-vente-'+id_pv+' a[data-id-commande='+id_commande+'] .montant').removeClass('paye') ;
  417. $('#point-vente-'+id_pv+' a[data-id-commande='+id_commande+'] .montant .glyphicon').remove() ;
  418. $('#point-vente-'+id_pv+' a[data-id-commande='+id_commande+'] .montant').html() ;
  419. $('#point-vente-'+id_pv+' a[data-id-commande='+id_commande+'] .montant').html(commande.str_montant) ;
  420. if(commande.montant_paye >= commande.montant) {
  421. $('#point-vente-'+id_pv+' a[data-id-commande='+id_commande+'] .montant').addClass('paye') ;
  422. if(commande.montant_paye > commande.montant) {
  423. $('#point-vente-'+id_pv+' a[data-id-commande='+id_commande+'] .montant').append(' <span class="glyphicon glyphicon-warning-sign"></span>') ;
  424. }
  425. }
  426. // commentaire
  427. if(commande.commentaire && commande.commentaire.length) {
  428. if(!$('#point-vente-'+id_pv+' a[data-id-commande='+id_commande+'] .glyphicon-comment').size()) {
  429. $('#point-vente-'+id_pv+' a[data-id-commande='+id_commande+']').append(' <span class="glyphicon glyphicon-comment"></span>') ;
  430. }
  431. console.log(id_pv+' '+commande.commentaire) ;
  432. $('#point-vente-'+id_pv+' .commentaire').html(chat_nl2br(commande.commentaire)).show() ;
  433. }
  434. else {
  435. $('#point-vente-'+id_pv+' a[data-id-commande='+id_commande+'] .glyphicon-comment').remove() ;
  436. $('#point-vente-'+id_pv+' .commentaire').hide() ;
  437. }
  438. // set id_commande
  439. $('#point-vente-'+id_pv+' .btn-cancel').data('id-commande',id_commande) ;
  440. $('#point-vente-'+id_pv+' .btn-save').data('id-commande',id_commande) ;
  441. $('#point-vente-'+id_pv+' .btn-remove').data('id-commande',id_commande) ;
  442. $('#point-vente-'+id_pv+' .btn-create').removeClass('is-create') ;
  443. $('#point-vente-'+id_pv+' .buttons-edit-remove').show() ;
  444. $('#point-vente-'+id_pv+' .buttons-save-cancel').hide() ;
  445. $('#point-vente-'+id_pv+' .choix-user').hide() ;
  446. $('#point-vente-'+id_pv+' .the-title').show() ;
  447. $('#point-vente-'+id_pv+' .textarea-commentaire').hide() ;
  448. $('#point-vente-'+id_pv+' .td-commande').html('') ;
  449. $('#point-vente-'+id_pv+' .td-total').html('') ;
  450. $('#point-vente-'+id_pv+' tr').removeClass('active') ;
  451. $.each(commande.produits, function(i, item) {
  452. $('#point-vente-'+id_pv+' .produit-'+i+' .td-commande').html(item) ;
  453. $('#point-vente-'+id_pv+' .produit-'+i).addClass('active') ;
  454. }) ;
  455. $('#point-vente-'+id_pv+' .td-total').html('<span>'+commande.str_montant+'</span>') ;
  456. $('#point-vente-'+id_pv+' .tr-total').show() ;
  457. /*var commentaire = link.data('commentaire') ;
  458. if(commentaire) {
  459. $('#point-vente-'+id_pv+' .commentaire').html(commentaire).show() ;
  460. }
  461. else {
  462. $('#point-vente-'+id_pv+' .commentaire').hide() ;
  463. }*/
  464. $('#point-vente-'+id_pv+' .title-user span.the-title').html(link.find('.user').html()+" <small>"+link.data('date')+"</small>") ;
  465. $('#point-vente-'+id_pv+' .bloc-commande').fadeIn() ;
  466. $('#point-vente-'+id_pv+' .title-user').show() ;
  467. $('#point-vente-'+id_pv+' .tr-total').show() ;
  468. // paiement
  469. $.get(UrlManager.getBaseUrl()+'commande/statut-paiement',{
  470. id_commande: id_commande
  471. }, function(data) {
  472. $('#point-vente-'+id_pv+' .bloc-commande .td-paiement').html(data.html_statut_paiement) ;
  473. $('#point-vente-'+id_pv+' a[data-id-commande='+id_commande+']').attr('data-commande',data.json_commande) ;
  474. chat_index_commandes_boutons_paiement(id_pv, id_commande) ;
  475. },'json') ;
  476. }
  477. else {
  478. $('#point-vente-'+id_pv+' .bloc-commande').hide() ;
  479. }
  480. }
  481. function chat_index_commandes_boutons_paiement(id_pv, id_commande) {
  482. // boutons paiement/remboursement
  483. $('#point-vente-'+id_pv+' .payer, #point-vente-'+id_pv+' .rembourser').click(function() {
  484. $.get(UrlManager.getBaseUrl()+'commande/paiement',{
  485. id_commande: id_commande,
  486. type: $(this).data('type'),
  487. montant: $(this).data('montant')
  488. }, function(data) {
  489. $('#point-vente-'+id_pv+' .bloc-commande .td-paiement').html(data.html_statut_paiement) ;
  490. $('#point-vente-'+id_pv+' a[data-id-commande='+id_commande+']').attr('data-commande',data.json_commande) ;
  491. chat_index_commandes_affiche_commande(id_pv, id_commande) ;
  492. chat_index_commandes_boutons_paiement(id_pv, id_commande) ;
  493. }, 'json') ;
  494. }) ;
  495. }
  496. function chat_index_commandes_liste_produits() {
  497. $('#produits-production .td-max input').click(function() {
  498. $(this).select() ;
  499. }) ;
  500. $('#produits-production .td-actif input').change(function() {
  501. if($(this).prop('checked')) {
  502. $(this).parent().parent().addClass('active') ;
  503. }
  504. else {
  505. $(this).parent().parent().removeClass('active') ;
  506. }
  507. }) ;
  508. }
  509. function chat_alert(type, message) {
  510. var id = 'alert-'+$('#alerts-fixed .alert').size() + 1 ;
  511. $('#alerts-fixed').append('<div id="'+id+'" class="alert alert-'+type+'">'+message+'</div>') ;
  512. setTimeout('$("#'+id+'").fadeOut();',3000) ;
  513. }
  514. function chat_ordre_produits() {
  515. var fixHelper = function(e, ui) {
  516. ui.children().each(function() {
  517. $(this).width($(this).width());
  518. });
  519. return ui;
  520. };
  521. $(".produit-index table tbody").sortable({
  522. items: "> tr",
  523. appendTo: "parent",
  524. cursor: "move",
  525. placeholder: "ui-state-highlight",
  526. handle: '.btn-order',
  527. //helper: "clone"
  528. helper: fixHelper,
  529. stop: function(event, ui) {
  530. var tab_ordre = {} ;
  531. var ordre = 1 ;
  532. $(".produit-index table tbody tr").each(function() {
  533. tab_ordre[$(this).attr('data-key')] = ordre ;
  534. ordre++ ;
  535. }) ;
  536. console.log(tab_ordre) ;
  537. $.get(UrlManager.getBaseUrl()+'produit/ordre',{
  538. tab: JSON.stringify(tab_ordre)
  539. }) ;
  540. }
  541. }).disableSelection();
  542. }
  543. function chat_email_masse() {
  544. $('#ids-users .label').click(function() {
  545. if($(this).hasClass('label-default')) {
  546. $(this).removeClass('label\-default') ;
  547. $(this).addClass('label-danger') ;
  548. }
  549. else if($(this).hasClass('label-danger'))
  550. $(this).removeClass('label-danger').addClass('label-default') ;
  551. }) ;
  552. $('#email-masse-form button[type=submit]').click(function() {
  553. $(this).attr('disabled','disabled').html('Envoyer ...') ;
  554. chat_email_masse_send() ;
  555. return false ;
  556. }) ;
  557. }
  558. function chat_email_masse_send() {
  559. var user = $('#ids-users .label-default:first') ;
  560. if(user.size()) {
  561. $('input[name=id_user]').val(user.data('id')) ;
  562. $.post(UrlManager.getBaseUrl()+'user/mail',$('#email-masse-form').serialize(), function(retour) {
  563. user.removeClass('label-default').addClass('label-success') ;
  564. setTimeout("chat_email_masse_send()",30000) ;
  565. }) ;
  566. }
  567. else {
  568. alert('Fini !') ;
  569. }
  570. }
  571. function chat_vrac() {
  572. $('.edit-vrac').click(function() {
  573. if($('.vrac').css('display') == 'none')
  574. $('.vrac').show() ;
  575. else
  576. $('.vrac').hide() ;
  577. }) ;
  578. }
  579. function chat_datepicker() {
  580. $('.datepicker').datepicker({dateFormat:'dd/mm/yy'}) ;
  581. }
  582. function chat_calendar() {
  583. if($('#page-commande').size()) {
  584. var events = new Array ;
  585. $('ul#jours-production li').each(function() {
  586. var date = $(this).html() ;
  587. events.push({
  588. title: 'Production',
  589. start: date,
  590. allDay: true
  591. }) ;
  592. }) ;
  593. jQuery('#calendar').fullCalendar({
  594. header: {
  595. left:"prev,next",
  596. center: "title",
  597. //right:"month,agendaWeek,agendaDay"
  598. right:""
  599. },
  600. lang:"fr-fr",
  601. loading:function loading(bool) {
  602. if (bool) $('#loading').show();
  603. else $('#loading').hide();
  604. },
  605. dayClick: function(date, jsEvent, view) {
  606. var url = $(location).attr('href') ;
  607. var tab_url = url.split('?') ;
  608. $(location).attr('href',tab_url[0]+'?r=commande/index&date='+date.format());
  609. },
  610. eventRender: function (event, element) {
  611. var dataToFind = moment(event.start).format('YYYY-MM-DD');
  612. $("td[data-date='"+dataToFind+"']").addClass('dayWithEvent');
  613. },
  614. //eventBackgroundColor: '#000000',
  615. events: events,
  616. id:"calendar"
  617. });
  618. if($('#current-date').val())
  619. $('td[data-date='+$('#current-date').val()+']').addClass('current-date') ;
  620. }
  621. }
  622. /* French initialisation for the jQuery UI date picker plugin. */
  623. /* Written by Keith Wood (kbwood{at}iinet.com.au),
  624. Stéphane Nahmani (sholby@sholby.net),
  625. Stéphane Raimbault <stephane.raimbault@gmail.com> */
  626. (function( factory ) {
  627. if ( typeof define === "function" && define.amd ) {
  628. // AMD. Register as an anonymous module.
  629. define([ "../jquery.ui.datepicker" ], factory );
  630. } else {
  631. // Browser globals
  632. factory( jQuery.datepicker );
  633. }
  634. }(function( datepicker ) {
  635. datepicker.regional['fr'] = {
  636. closeText: 'Fermer',
  637. prevText: 'Précédent',
  638. nextText: 'Suivant',
  639. currentText: 'Aujourd\'hui',
  640. monthNames: ['janvier', 'février', 'mars', 'avril', 'mai', 'juin',
  641. 'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre'],
  642. monthNamesShort: ['janv.', 'févr.', 'mars', 'avril', 'mai', 'juin',
  643. 'juil.', 'août', 'sept.', 'oct.', 'nov.', 'déc.'],
  644. dayNames: ['dimanche', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi'],
  645. dayNamesShort: ['dim.', 'lun.', 'mar.', 'mer.', 'jeu.', 'ven.', 'sam.'],
  646. dayNamesMin: ['D','L','M','M','J','V','S'],
  647. weekHeader: 'Sem.',
  648. dateFormat: 'dd/mm/yy',
  649. firstDay: 1,
  650. isRTL: false,
  651. showMonthAfterYear: false,
  652. yearSuffix: ''};
  653. datepicker.setDefaults(datepicker.regional['fr']);
  654. return datepicker.regional['fr'];
  655. }));