You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

760 line
30KB

  1. /**
  2. Copyright distrib (2018)
  3. contact@opendistrib.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. var app = new Vue({
  31. el: '#app-distribution-index',
  32. data: {
  33. UrlManager: UrlManager,
  34. baseUrl: $('meta[name=baseurl]').attr('content'),
  35. date: null,
  36. dateFormat: null,
  37. loading: true,
  38. distribution: {
  39. active: false,
  40. },
  41. producer: null,
  42. oneDistributionWeekActive: false,
  43. products: [],
  44. countActiveProducts: 0,
  45. pointsSale: [],
  46. meansPayment: [],
  47. idActivePointSale: 0,
  48. idDefaultPointSale: 0,
  49. countActivePointsSale: 0,
  50. countOrdersByPointSale: [],
  51. orders: [],
  52. ordersUpdate: [],
  53. countOrders: 0,
  54. users: [],
  55. deliveryNotes: [],
  56. showModalProducts: false,
  57. showModalPointsSale: false,
  58. showModalFormOrderCreate: false,
  59. orderCreate: null,
  60. showModalFormOrderUpdate: false,
  61. idOrderUpdate: 0,
  62. showViewProduct: false,
  63. idOrderView: 0,
  64. showModalPayment: false,
  65. idOrderPayment: 0,
  66. showLoading: false,
  67. tillerIsSynchro: false,
  68. checkboxSelectAllOrders: false,
  69. messageGenerateDeliveryNoteDisplayed: false,
  70. missingSubscriptions: false,
  71. calendar: {
  72. mode: 'single',
  73. attrs: [],
  74. themeStyles: {
  75. wrapper: {
  76. background: '#F7F7F7',
  77. color: '#333',
  78. border: 'solid 1px #e0e0e0'
  79. },
  80. header: {
  81. padding: '10px 10px',
  82. },
  83. headerHorizontalDivider: {
  84. borderTop: 'solid rgba(255, 255, 255, 0.2) 1px',
  85. width: '80%',
  86. },
  87. weekdays: {
  88. color: '#e0e0e0',
  89. fontWeight: '600',
  90. padding: '10px 10px',
  91. fontSize: '2rem'
  92. },
  93. weeks: {
  94. padding: '0 15px 15px 15px',
  95. },
  96. dayContent: function(object) {
  97. var style = {
  98. fontSize: '2rem',
  99. padding: '16px',
  100. };
  101. if(object.isHovered || object.isFocus) {
  102. style.backgroundColor = '#F39C12' ;
  103. }
  104. return style ;
  105. },
  106. },
  107. formats: {
  108. dayPopover: 'DD/MM/YYYY'
  109. }
  110. },
  111. },
  112. mounted: function() {
  113. if($('#distribution-date').size()) {
  114. this.date = new Date($('#distribution-date').html()) ;
  115. this.dateFormat = ('0' + this.date.getDate()).slice(-2)+ '/'
  116. + ('0' + (this.date.getMonth() +1)).slice(-2) + '/'
  117. + this.date.getFullYear() ;
  118. }
  119. this.init() ;
  120. this.loading = false ;
  121. },
  122. methods: {
  123. getDate: function() {
  124. return this.formatDate(this.date) ;
  125. },
  126. formatDate: function(date) {
  127. if(date) {
  128. return date.getFullYear() + '-'
  129. + ('0' + (date.getMonth() +1)).slice(-2) + '-'
  130. + ('0' + date.getDate()).slice(-2) ;
  131. }
  132. return false ;
  133. },
  134. init: function(idActivePointSale) {
  135. var app = this ;
  136. this.showLoading = true ;
  137. axios.get("ajax-infos",{params: {date : this.getDate()}})
  138. .then(function(response) {
  139. app.distribution = response.data.distribution ;
  140. app.producer = response.data.producer ;
  141. app.products = response.data.products ;
  142. app.initCountActiveProducts() ;
  143. app.meansPayment = response.data.means_payment ;
  144. app.oneDistributionWeekActive = response.data.one_distribution_week_active ;
  145. app.missingSubscriptions = response.data.missing_subscriptions ;
  146. app.countOrders = 0 ;
  147. if(response.data.orders) {
  148. app.orders = JSON.parse(JSON.stringify(response.data.orders)) ;
  149. app.ordersUpdate = JSON.parse(JSON.stringify(response.data.orders)) ;
  150. for(i=0 ; i < app.orders.length ; i++) {
  151. if(!app.orders[i].date_delete) {
  152. app.countOrders ++ ;
  153. }
  154. }
  155. }
  156. else {
  157. app.orders = [] ;
  158. }
  159. if(response.data.order_create) {
  160. app.orderCreate = response.data.order_create ;
  161. app.idDefaultPointSale = app.orderCreate.id_point_sale ;
  162. }
  163. if(response.data.points_sale) {
  164. app.pointsSale = response.data.points_sale ;
  165. app.initPointsSale(idActivePointSale) ;
  166. }
  167. else {
  168. app.pointsSale = [] ;
  169. }
  170. if(response.data.users) {
  171. app.users = response.data.users ;
  172. }
  173. if(response.data.delivery_notes) {
  174. app.deliveryNotes = response.data.delivery_notes ;
  175. }
  176. app.tillerIsSynchro = response.data.tiller_is_synchro ;
  177. app.calendar.attrs = [] ;
  178. var distributions = response.data.distributions ;
  179. if(distributions.length) {
  180. for(var i= 0; i < distributions.length; i++) {
  181. app.calendar.attrs.push({
  182. highlight: {
  183. backgroundColor: '#5cb85c',
  184. },
  185. contentStyle: {
  186. color: 'white',
  187. },
  188. dates: distributions[i].date,
  189. }) ;
  190. }
  191. }
  192. app.showLoading = false ;
  193. app.checkboxSelectAllOrders = false ;
  194. let searchParams = new URLSearchParams(window.location.search) ;
  195. if(searchParams.has('message_generate_bl') && !app.messageGenerateDeliveryNoteDisplayed) {
  196. appAlerts.alert('info','Pour générer un bon de livraison, sélectionnez tout d\'abord un jour et un lieu de distribution.', 6000) ;
  197. app.messageGenerateDeliveryNoteDisplayed = true ;
  198. }
  199. }) ;
  200. },
  201. initCountActiveProducts: function() {
  202. this.countActiveProducts = 0 ;
  203. for(var i= 0; i < this.products.length; i++) {
  204. if(this.products[i].productDistribution[0].active == 1) {
  205. this.countActiveProducts ++ ;
  206. }
  207. }
  208. },
  209. initPointsSale: function(idActivePointSale) {
  210. this.countActivePointsSale = 0 ;
  211. this.setIdActivePointSale(0) ;
  212. for(var i= 0; i < this.pointsSale.length; i++) {
  213. if(this.pointsSale[i].pointSaleDistribution[0].delivery == 1) {
  214. this.countActivePointsSale ++ ;
  215. this.setIdActivePointSale(this.pointsSale[i].id) ;
  216. }
  217. }
  218. if(this.countActivePointsSale > 1) {
  219. this.setIdActivePointSale(0) ;
  220. }
  221. if(idActivePointSale) {
  222. this.setIdActivePointSale(idActivePointSale) ;
  223. }
  224. this.countOrdersByPointSale = [] ;
  225. for(var i = 0; i < this.pointsSale.length ; i++) {
  226. this.countOrdersByPointSale[this.pointsSale[i].id] = 0 ;
  227. }
  228. for(var i = 0; i < this.orders.length ; i++) {
  229. this.countOrdersByPointSale[this.orders[i].id_point_sale] ++ ;
  230. }
  231. },
  232. dayClicked: function(day) {
  233. this.date = day.date ;
  234. this.dateFormat = ('0' + this.date.getDate()).slice(-2)+ '/'
  235. + ('0' + (this.date.getMonth() +1)).slice(-2) + '/'
  236. + this.date.getFullYear() ;
  237. this.init() ;
  238. },
  239. productQuantityMaxChange: function(event) {
  240. axios.get("ajax-process-product-quantity-max",{params: {
  241. idDistribution: this.distribution.id,
  242. idProduct: event.currentTarget.getAttribute('data-id-product'),
  243. quantityMax: event.currentTarget.value
  244. }})
  245. .then(function(response) {
  246. }) ;
  247. },
  248. productActiveClick: function(event) {
  249. var idProduct = event.currentTarget.getAttribute('data-id-product') ;
  250. var activeProduct = event.currentTarget.getAttribute('data-active-product') ;
  251. axios.get("ajax-process-active-product",{params: {
  252. idDistribution: this.distribution.id,
  253. idProduct: idProduct,
  254. active: activeProduct
  255. }})
  256. .then(function(response) {
  257. }) ;
  258. for(i = 0 ; i < this.products.length ; i++) {
  259. if(this.products[i].id == idProduct) {
  260. this.products[i].productDistribution[0].active = activeProduct ;
  261. }
  262. }
  263. this.initCountActiveProducts() ;
  264. },
  265. pointSaleActiveClick: function(event) {
  266. var idPointSale = event.currentTarget.getAttribute('data-id-point-sale') ;
  267. var deliveryPointSale = event.currentTarget.getAttribute('data-delivery-point-sale') ;
  268. axios.get("ajax-process-active-point-sale",{params: {
  269. idDistribution: this.distribution.id,
  270. idPointSale: idPointSale,
  271. delivery: deliveryPointSale
  272. }})
  273. .then(function(response) {
  274. }) ;
  275. for(i = 0 ; i < this.pointsSale.length ; i++) {
  276. if(this.pointsSale[i].id == idPointSale) {
  277. this.pointsSale[i].pointSaleDistribution[0].delivery = deliveryPointSale ;
  278. }
  279. }
  280. this.initPointsSale() ;
  281. },
  282. activeDistribution: function(event) {
  283. var app = this ;
  284. axios.get("ajax-process-active-distribution",{params: {
  285. idDistribution: this.distribution.id,
  286. active: event.currentTarget.getAttribute('data-active')
  287. }})
  288. .then(function(response) {
  289. app.init() ;
  290. }) ;
  291. },
  292. activeWeekDistribution: function(event) {
  293. var app = this ;
  294. axios.get("ajax-process-active-week-distribution",{params: {
  295. date: this.date.getFullYear() + '-'
  296. + ('0' + (this.date.getMonth() +1)).slice(-2) + '-'
  297. + ('0' + this.date.getDate()).slice(-2),
  298. active: event.currentTarget.getAttribute('data-active')
  299. }})
  300. .then(function(response) {
  301. app.init() ;
  302. }) ;
  303. },
  304. pointSaleClick: function(event) {
  305. this.setIdActivePointSale(event.currentTarget.getAttribute('data-id-point-sale')) ;
  306. },
  307. setIdActivePointSale: function(id) {
  308. this.idActivePointSale = id ;
  309. if(!id) {
  310. this.orderCreate.id_point_sale = this.idDefaultPointSale ;
  311. }
  312. else {
  313. this.orderCreate.id_point_sale = id ;
  314. }
  315. },
  316. orderCreatedUpdated: function() {
  317. this.showModalFormOrderCreate = false ;
  318. this.showModalFormOrderUpdate = false ;
  319. this.init(this.idActivePointSale) ;
  320. },
  321. deleteOrderClick: function(event) {
  322. var app = this ;
  323. var idOrder = event.currentTarget.getAttribute('data-id-order') ;
  324. axios.get(UrlManager.getBaseUrlAbsolute()+"order/ajax-delete",{params: {
  325. idOrder: idOrder
  326. }})
  327. .then(function(response) {
  328. app.init(app.idActivePointSale) ;
  329. }) ;
  330. },
  331. updateOrderClick: function(event) {
  332. var idOrder = event.currentTarget.getAttribute('data-id-order') ;
  333. this.idOrderUpdate = idOrder ;
  334. this.showModalFormOrderUpdate = true ;
  335. this.initModalFormOrder() ;
  336. },
  337. openModalFormOrderCreate: function() {
  338. this.showModalFormOrderCreate = true ;
  339. this.initModalFormOrder() ;
  340. this.updateProductOrderPrices() ;
  341. },
  342. initModalFormOrder: function() {
  343. setTimeout(function() {
  344. $('.modal-body').css('height',$(window).height()) ;
  345. $('.modal-body').css('maxHeight','unset') ;
  346. },500);
  347. },
  348. orderPaymentModalClick: function(event) {
  349. var idOrder = event.currentTarget.getAttribute('data-id-order') ;
  350. this.idOrderPayment = idOrder ;
  351. this.showModalPayment = true ;
  352. },
  353. orderPaymentClick: function(event) {
  354. var app = this ;
  355. var idOrder = event.currentTarget.getAttribute('data-id-order') ;
  356. if(!idOrder) {
  357. idOrder = this.idOrderPayment ;
  358. }
  359. axios.get(UrlManager.getBaseUrlAbsolute()+"order/ajax-payment",{params: {
  360. idOrder: idOrder,
  361. type: event.currentTarget.getAttribute('data-type'),
  362. amount: event.currentTarget.getAttribute('data-amount')
  363. }})
  364. .then(function(response) {
  365. app.init(app.idActivePointSale) ;
  366. }) ;
  367. },
  368. orderViewClick: function(event) {
  369. var currentIdOrderView = event.currentTarget.getAttribute('data-id-order') ;
  370. if(this.idOrderView == currentIdOrderView) {
  371. this.showViewProduct = !this.showViewProduct ;
  372. }
  373. else {
  374. this.showViewProduct = true ;
  375. this.idOrderView = currentIdOrderView ;
  376. }
  377. },
  378. closeModalProducts: function() {
  379. this.showModalProducts = false ;
  380. this.init(this.idActivePointSale) ;
  381. },
  382. cloneOrder: function(order) {
  383. var clone = Object.assign({}, order) ;
  384. clone.productOrder = {} ;
  385. for(var key in order.productOrder) {
  386. clone.productOrder[key] = order.productOrder[key] ;
  387. }
  388. return clone ;
  389. },
  390. addSubscriptions: function() {
  391. var app = this ;
  392. axios.get(UrlManager.getBaseUrlAbsolute()+"distribution/ajax-process-add-subscriptions",{params: {
  393. date: this.getDate()
  394. }})
  395. .then(function(response) {
  396. app.init(app.idActivePointSale) ;
  397. }) ;
  398. },
  399. synchroTiller: function() {
  400. var app = this ;
  401. this.showLoading = true ;
  402. axios.get(UrlManager.getBaseUrlAbsolute()+"distribution/ajax-process-synchro-tiller",{params: {
  403. date: this.getDate()
  404. }})
  405. .then(function(response) {
  406. app.init(app.idActivePointSale) ;
  407. }) ;
  408. },
  409. totalActivePointSale: function() {
  410. var total = 0 ;
  411. for(var i = 0; i < this.orders.length ; i++) {
  412. if(this.orders[i].id_point_sale == this.idActivePointSale) {
  413. total += this.orders[i].amount ;
  414. }
  415. }
  416. return formatPrice(total) ;
  417. },
  418. changeSynchroTiller: function(event) {
  419. var app = this ;
  420. var idOrder = event.currentTarget.getAttribute('data-id-order') ;
  421. axios.get(UrlManager.getBaseUrlAbsolute()+"order/ajax-change-synchro-tiller",{params: {
  422. idOrder: idOrder,
  423. boolSynchroTiller: event.currentTarget.checked ? 1 : 0
  424. }})
  425. .then(function(response) {
  426. app.init() ;
  427. }) ;
  428. },
  429. selectAllOrdersEvent: function(event) {
  430. var bool = event.currentTarget.checked ;
  431. this.selectAllOrders(bool) ;
  432. },
  433. selectAllOrders: function(bool) {
  434. for(var key in this.orders) {
  435. if(this.orders[key].id_point_sale == this.idActivePointSale) {
  436. this.orders[key].selected = bool ;
  437. }
  438. }
  439. },
  440. oneOrderSelected: function() {
  441. for(var key in this.orders) {
  442. if(this.orders[key].selected == true) {
  443. return true ;
  444. }
  445. }
  446. return false ;
  447. },
  448. generateDeliveryNote: function() {
  449. if(!this.oneOrderSelected()) {
  450. this.selectAllOrders(true) ;
  451. }
  452. if(this.oneOrderSelected()) {
  453. var app = this ;
  454. var idOrders = {} ;
  455. for(var key in this.orders) {
  456. if(this.orders[key].selected == true) {
  457. idOrders[key] = this.orders[key].id ;
  458. }
  459. }
  460. axios.get(UrlManager.getBaseUrlAbsolute()+"distribution/ajax-generate-delivery-note",{params: {
  461. idOrders: JSON.stringify(idOrders)
  462. }})
  463. .then(function(response) {
  464. appAlerts.alertResponse(response) ;
  465. app.init(app.idActivePointSale) ;
  466. }) ;
  467. }
  468. else {
  469. appAlerts.alert('danger','Veuillez sélectionner au moins une commande pour générer un bon de livraison') ;
  470. }
  471. },
  472. generateDeliveryNoteEachUser: function() {
  473. if(!this.oneOrderSelected()) {
  474. this.selectAllOrders(true) ;
  475. }
  476. if(this.oneOrderSelected()) {
  477. var app = this ;
  478. var idOrders = {} ;
  479. for(var key in this.orders) {
  480. if(this.orders[key].selected == true) {
  481. idOrders[key] = this.orders[key].id ;
  482. }
  483. }
  484. axios.get(UrlManager.getBaseUrlAbsolute()+"distribution/ajax-generate-delivery-note-each-user",{params: {
  485. idOrders: JSON.stringify(idOrders)
  486. }})
  487. .then(function(response) {
  488. appAlerts.alertResponse(response) ;
  489. app.init(app.idActivePointSale) ;
  490. }) ;
  491. }
  492. else {
  493. appAlerts.alert('danger','Veuillez sélectionner au moins une commande pour générer un bon de livraison') ;
  494. }
  495. },
  496. validateDeliveryNotes: function() {
  497. if(!this.oneOrderSelected()) {
  498. this.selectAllOrders(true) ;
  499. }
  500. if(this.oneOrderSelected()) {
  501. var app = this ;
  502. var idOrders = {} ;
  503. for(var key in this.orders) {
  504. if(this.orders[key].selected == true) {
  505. idOrders[key] = this.orders[key].id ;
  506. }
  507. }
  508. axios.get(UrlManager.getBaseUrlAbsolute()+"distribution/ajax-validate-delivery-notes",{params: {
  509. idOrders: JSON.stringify(idOrders)
  510. }})
  511. .then(function(response) {
  512. appAlerts.alertResponse(response) ;
  513. app.init(app.idActivePointSale) ;
  514. }) ;
  515. }
  516. else {
  517. appAlerts.alert('danger','Veuillez sélectionner au moins une commande pour valider un bon de livraison') ;
  518. }
  519. },
  520. deliveryNoteExist: function(idPointSale) {
  521. return typeof this.deliveryNotes[this.idActivePointSale] != 'undefined' ;
  522. },
  523. payOrders: function() {
  524. var app = this ;
  525. axios.get(UrlManager.getBaseUrlAbsolute()+"cron/pay-orders",{params: {
  526. date: app.getDate()
  527. }})
  528. .then(function(response) {
  529. appAlerts.alertResponse(response) ;
  530. app.init(app.idActivePointSale) ;
  531. }) ;
  532. },
  533. updateProductOrderPrices: function() {
  534. var app = this ;
  535. var order = null ;
  536. if(app.showModalFormOrderCreate) {
  537. order = app.orderCreate ;
  538. }
  539. if(app.showModalFormOrderUpdate && app.idOrderUpdate) {
  540. for (keyOrderUpdate in app.ordersUpdate) {
  541. if (app.ordersUpdate[keyOrderUpdate].id == app.idOrderUpdate) {
  542. order = app.ordersUpdate[keyOrderUpdate] ;
  543. }
  544. }
  545. }
  546. if(order) {
  547. axios.get(UrlManager.getBaseUrlAbsolute() + "distribution/ajax-update-product-order", {
  548. params: {
  549. idUser: order.id_user,
  550. idPointSale: order.id_point_sale
  551. }
  552. })
  553. .then(function (response) {
  554. if (response.data) {
  555. for (idProduct in response.data) {
  556. if (app.showModalFormOrderCreate) {
  557. Vue.set(app.orderCreate.productOrder[idProduct], 'price', response.data[idProduct].price);
  558. }
  559. if (app.showModalFormOrderUpdate && app.idOrderUpdate) {
  560. for (keyOrderUpdate in app.ordersUpdate) {
  561. if (order.id == app.idOrderUpdate) {
  562. Vue.set(app.ordersUpdate[keyOrderUpdate].productOrder[idProduct], 'price', response.data[idProduct].price);
  563. }
  564. }
  565. }
  566. }
  567. }
  568. });
  569. }
  570. }
  571. },
  572. });
  573. Vue.component('modal', {
  574. template: '#modal-template'
  575. })
  576. Vue.component('order-form',{
  577. props: ['date', 'pointsSale','meansPayment', 'users', 'products', 'order', 'producer'],
  578. data: function() {
  579. return {
  580. errors: [],
  581. idPointSale: 0,
  582. idUser: 0,
  583. username : '',
  584. comment: '',
  585. baseUrl: $('meta[name=baseurl]').attr('content'),
  586. } ;
  587. },
  588. template: '#order-form-template',
  589. methods: {
  590. checkForm: function() {
  591. this.errors = [] ;
  592. var countProducts = 0 ;
  593. for(var key in this.order.productOrder) {
  594. if(this.order.productOrder[key].quantity > 0) {
  595. countProducts ++ ;
  596. }
  597. }
  598. if(this.order.id_point_sale
  599. && (this.order.id_user > 0 || (this.order.username && this.order.username.length))
  600. && countProducts > 0) {
  601. return true ;
  602. }
  603. if(!this.order.id_point_sale) {
  604. this.errors.push('Veuillez sélectionner un point de vente') ;
  605. }
  606. if((!this.order.id_user || this.order.id_user == 0) && !this.order.username.length) {
  607. this.errors.push('Veuillez sélectionner ou saisir un utilisateur') ;
  608. }
  609. if(!countProducts) {
  610. this.errors.push('Veuillez sélectionner au moins un produit') ;
  611. }
  612. },
  613. submitFormCreate: function(event) {
  614. var app = this ;
  615. if(this.checkForm()) {
  616. var processCredit = event.currentTarget.getAttribute('data-process-credit') ;
  617. axios.get(UrlManager.getBaseUrlAbsolute()+"order/ajax-create",{params: {
  618. date: this.date.getFullYear() + '-'
  619. + ('0' + (this.date.getMonth() +1)).slice(-2) + '-'
  620. + ('0' + this.date.getDate()).slice(-2),
  621. idPointSale: this.order.id_point_sale,
  622. idUser: this.order.id_user,
  623. username: this.order.username,
  624. meanPayment: this.order.mean_payment,
  625. products: JSON.stringify(this.order.productOrder),
  626. comment: this.order.comment,
  627. processCredit: processCredit
  628. }})
  629. .then(function(response) {
  630. app.order.id_point_sale = 0 ;
  631. app.order.id_user = 0 ;
  632. app.order.username = '' ;
  633. app.order.comment = '' ;
  634. for(i=0 ; i<app.order.productOrder.length ; i++) {
  635. app.order.productOrder[i] = 0 ;
  636. }
  637. app.$emit('ordercreatedupdated') ;
  638. }) ;
  639. }
  640. },
  641. submitFormUpdate: function(event) {
  642. var app = this ;
  643. if(this.checkForm()) {
  644. var processCredit = event.currentTarget.getAttribute('data-process-credit') ;
  645. if(processCredit == null) {
  646. processCredit = 0 ;
  647. }
  648. var data = new FormData();
  649. data.append('date', this.date.getFullYear() + '-'
  650. + ('0' + (this.date.getMonth() +1)).slice(-2) + '-'
  651. + ('0' + this.date.getDate()).slice(-2));
  652. data.append('idOrder', this.order.id) ;
  653. data.append('idPointSale', this.order.id_point_sale) ;
  654. data.append('meanPayment', this.order.mean_payment) ;
  655. data.append('idUser', this.order.id_user) ;
  656. data.append('username', ''+this.order.username) ;
  657. data.append('products', JSON.stringify(this.order.productOrder)) ;
  658. data.append('comment', this.order.comment) ;
  659. data.append('processCredit', processCredit) ;
  660. axios.post(UrlManager.getBaseUrlAbsolute()+"order/ajax-update",data)
  661. .then(function(response) {
  662. app.$emit('ordercreatedupdated') ;
  663. }) ;
  664. }
  665. },
  666. productQuantityClick: function(id_product, quantity) {
  667. if(!this.order.productOrder[id_product].quantity) {
  668. this.order.productOrder[id_product].quantity = 0 ;
  669. }
  670. if(parseFloat(this.order.productOrder[id_product].quantity) + quantity >= 0) {
  671. var theQuantity = parseFloat(this.order.productOrder[id_product].quantity) + parseFloat(quantity) ;
  672. Vue.set(this.order.productOrder, id_product, {
  673. quantity: theQuantity,
  674. unit: this.order.productOrder[id_product].unit,
  675. price: this.order.productOrder[id_product].price
  676. });
  677. }
  678. },
  679. productPriceChange: function(event) {
  680. var idProduct = event.currentTarget.getAttribute('data-id-product') ;
  681. var price = parseFloat(event.currentTarget.value) ;
  682. if(isNaN(price)) {
  683. price = 0 ;
  684. }
  685. Vue.set(this.order.productOrder, idProduct, {
  686. quantity: this.order.productOrder[idProduct].quantity,
  687. unit: this.order.productOrder[idProduct].unit,
  688. price: price
  689. });
  690. },
  691. userChange: function(event) {
  692. var app = this ;
  693. axios.get(UrlManager.getBaseUrlAbsolute()+"distribution/ajax-point-sale-favorite",{params: {
  694. idUser: app.order.id_user,
  695. }})
  696. .then(function(response) {
  697. app.order.id_point_sale = response.data.id_favorite_point_sale ;
  698. app.updateProductOrderPrices() ;
  699. }) ;
  700. },
  701. pointSaleChange: function(event) {
  702. this.updateProductOrderPrices() ;
  703. },
  704. updateProductOrderPrices: function() {
  705. this.$emit('updateproductorderprices') ;
  706. }
  707. }
  708. }) ;