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.

410 line
15KB

  1. var app = new Vue({
  2. el: '#app-distribution-index',
  3. data: {
  4. date: null,
  5. dateFormat: null,
  6. loading: true,
  7. distribution: {
  8. active: false,
  9. },
  10. products: [],
  11. countActiveProducts: 0,
  12. pointsSale: [],
  13. idActivePointSale: 0,
  14. countActivePointsSale: 0,
  15. countOrdersByPointSale: [],
  16. orders: [],
  17. countOrders: 0,
  18. users: [],
  19. showModalProducts: false,
  20. showModalPointsSale: false,
  21. showModalFormOrderCreate: false,
  22. orderCreate: null,
  23. showModalFormOrderUpdate: false,
  24. idOrderUpdate: 0,
  25. showViewProduct: false,
  26. idOrderView: 0,
  27. showModalPayment: false,
  28. idOrderPayment: 0,
  29. showLoading: false,
  30. calendar: {
  31. mode: 'single',
  32. attrs: [],
  33. themeStyles: {
  34. wrapper: {
  35. background: '#BB8757',
  36. color: '#fafafa',
  37. },
  38. header: {
  39. padding: '10px 10px',
  40. },
  41. headerHorizontalDivider: {
  42. borderTop: 'solid rgba(255, 255, 255, 0.2) 1px',
  43. width: '80%',
  44. },
  45. weekdays: {
  46. color: 'white',
  47. fontWeight: '600',
  48. padding: '10px 10px',
  49. fontSize: '2rem'
  50. },
  51. weeks: {
  52. padding: '0 15px 15px 15px',
  53. },
  54. dayContent: function(object) {
  55. var style = {
  56. fontSize: '2rem',
  57. padding: '16px',
  58. };
  59. if(object.isHovered || object.isFocus) {
  60. style.backgroundColor = '#F39C12' ;
  61. }
  62. return style ;
  63. },
  64. },
  65. formats: {
  66. dayPopover: 'DD/MM/YYYY'
  67. }
  68. },
  69. },
  70. mounted: function() {
  71. if($('#distribution-date').size()) {
  72. this.date = new Date($('#distribution-date').html()) ;
  73. this.dateFormat = ('0' + this.date.getDate()).slice(-2)+ '/'
  74. + ('0' + (this.date.getMonth() +1)).slice(-2) + '/'
  75. + this.date.getFullYear() ;
  76. }
  77. this.init() ;
  78. this.loading = false ;
  79. },
  80. methods: {
  81. getDate: function() {
  82. return this.formatDate(this.date) ;
  83. },
  84. formatDate: function(date) {
  85. if(date) {
  86. return date.getFullYear() + '-'
  87. + ('0' + (date.getMonth() +1)).slice(-2) + '-'
  88. + ('0' + date.getDate()).slice(-2) ;
  89. }
  90. return false ;
  91. },
  92. init: function(idActivePointSale) {
  93. this.showLoading = true ;
  94. axios.get("ajax-infos",{params: {date : this.getDate()}})
  95. .then(response => {
  96. this.distribution = response.data.distribution ;
  97. this.products = response.data.products ;
  98. this.initCountActiveProducts() ;
  99. if(response.data.orders) {
  100. this.orders = response.data.orders ;
  101. this.countOrders = 0 ;
  102. for(i=0 ; i < this.orders.length ; i++) {
  103. if(!this.orders[i].date_delete) {
  104. this.countOrders ++ ;
  105. }
  106. }
  107. }
  108. else {
  109. this.orders = [] ;
  110. }
  111. if(response.data.order_create) {
  112. this.orderCreate = response.data.order_create ;
  113. }
  114. if(response.data.points_sale) {
  115. this.pointsSale = response.data.points_sale ;
  116. this.initPointsSale(idActivePointSale) ;
  117. }
  118. else {
  119. this.pointsSale = [] ;
  120. }
  121. if(response.data.users) {
  122. this.users = response.data.users ;
  123. }
  124. this.calendar.attrs = [] ;
  125. var distributions = response.data.distributions ;
  126. if(distributions.length) {
  127. for(var i= 0; i < distributions.length; i++) {
  128. this.calendar.attrs.push({
  129. highlight: {
  130. backgroundColor: '#00A65A',
  131. },
  132. dates: distributions[i].date,
  133. }) ;
  134. }
  135. }
  136. this.showLoading = false ;
  137. }) ;
  138. },
  139. initCountActiveProducts: function() {
  140. this.countActiveProducts = 0 ;
  141. for(var i= 0; i < this.products.length; i++) {
  142. if(this.products[i].productDistribution[0].active == 1) {
  143. this.countActiveProducts ++ ;
  144. }
  145. }
  146. },
  147. initPointsSale: function(idActivePointSale) {
  148. this.countActivePointsSale = 0 ;
  149. this.setIdActivePointSale(0) ;
  150. for(var i= 0; i < this.pointsSale.length; i++) {
  151. if(this.pointsSale[i].pointSaleDistribution[0].delivery == 1) {
  152. this.countActivePointsSale ++ ;
  153. this.setIdActivePointSale(this.pointsSale[i].id) ;
  154. }
  155. }
  156. if(this.countActivePointsSale > 1) {
  157. this.setIdActivePointSale(0) ;
  158. }
  159. if(idActivePointSale) {
  160. this.setIdActivePointSale(idActivePointSale) ;
  161. }
  162. this.countOrdersByPointSale = [] ;
  163. for(var i = 0; i < this.pointsSale.length ; i++) {
  164. this.countOrdersByPointSale[this.pointsSale[i].id] = 0 ;
  165. }
  166. for(var i = 0; i < this.orders.length ; i++) {
  167. this.countOrdersByPointSale[this.orders[i].id_point_sale] ++ ;
  168. }
  169. },
  170. dayClicked: function(day) {
  171. this.date = day.date ;
  172. this.dateFormat = ('0' + this.date.getDate()).slice(-2)+ '/'
  173. + ('0' + (this.date.getMonth() +1)).slice(-2) + '/'
  174. + this.date.getFullYear() ;
  175. this.init() ;
  176. },
  177. productQuantityMaxChange: function(event) {
  178. axios.get("ajax-process-product-quantity-max",{params: {
  179. idDistribution: this.distribution.id,
  180. idProduct: event.currentTarget.getAttribute('data-id-product'),
  181. quantityMax: event.currentTarget.value
  182. }})
  183. .then(response => {
  184. }) ;
  185. },
  186. productActiveClick: function(event) {
  187. var idProduct = event.currentTarget.getAttribute('data-id-product') ;
  188. var activeProduct = event.currentTarget.getAttribute('data-active-product') ;
  189. axios.get("ajax-process-active-product",{params: {
  190. idDistribution: this.distribution.id,
  191. idProduct: idProduct,
  192. active: activeProduct
  193. }})
  194. .then(response => {
  195. }) ;
  196. for(i = 0 ; i < this.products.length ; i++) {
  197. if(this.products[i].id == idProduct) {
  198. this.products[i].productDistribution[0].active = activeProduct ;
  199. }
  200. }
  201. this.initCountActiveProducts() ;
  202. },
  203. pointSaleActiveClick: function(event) {
  204. var idPointSale = event.currentTarget.getAttribute('data-id-point-sale') ;
  205. var deliveryPointSale = event.currentTarget.getAttribute('data-delivery-point-sale') ;
  206. axios.get("ajax-process-active-point-sale",{params: {
  207. idDistribution: this.distribution.id,
  208. idPointSale: idPointSale,
  209. delivery: deliveryPointSale
  210. }})
  211. .then(response => {
  212. }) ;
  213. for(i = 0 ; i < this.pointsSale.length ; i++) {
  214. if(this.pointsSale[i].id == idPointSale) {
  215. this.pointsSale[i].pointSaleDistribution[0].delivery = deliveryPointSale ;
  216. }
  217. }
  218. this.initPointsSale() ;
  219. },
  220. activeDistribution: function(event) {
  221. axios.get("ajax-process-active-distribution",{params: {
  222. idDistribution: this.distribution.id,
  223. active: event.currentTarget.getAttribute('data-active')
  224. }})
  225. .then(response => {
  226. this.init() ;
  227. }) ;
  228. },
  229. pointSaleClick: function(event) {
  230. this.setIdActivePointSale(event.currentTarget.getAttribute('data-id-point-sale')) ;
  231. },
  232. setIdActivePointSale: function(id) {
  233. this.idActivePointSale = id ;
  234. this.orderCreate.id_point_sale = id ;
  235. },
  236. orderCreatedUpdated: function() {
  237. this.showModalFormOrderCreate = false ;
  238. this.showModalFormOrderUpdate = false ;
  239. this.init(this.idActivePointSale) ;
  240. },
  241. deleteOrderClick: function(event) {
  242. var idOrder = event.currentTarget.getAttribute('data-id-order') ;
  243. axios.get(UrlManager.getBaseUrlAbsolute()+"order/ajax-delete",{params: {
  244. idOrder: idOrder
  245. }})
  246. .then(response => {
  247. this.init(this.idActivePointSale) ;
  248. }) ;
  249. },
  250. updateOrderClick: function(event) {
  251. var idOrder = event.currentTarget.getAttribute('data-id-order') ;
  252. this.idOrderUpdate = idOrder ;
  253. this.showModalFormOrderUpdate = true ;
  254. },
  255. orderPaymentModalClick: function(event) {
  256. var idOrder = event.currentTarget.getAttribute('data-id-order') ;
  257. this.idOrderPayment = idOrder ;
  258. this.showModalPayment = true ;
  259. },
  260. orderPaymentClick: function(event) {
  261. var idOrder = event.currentTarget.getAttribute('data-id-order') ;
  262. axios.get(UrlManager.getBaseUrlAbsolute()+"order/ajax-payment",{params: {
  263. idOrder: this.idOrderPayment,
  264. type: event.currentTarget.getAttribute('data-type'),
  265. amount: event.currentTarget.getAttribute('data-amount')
  266. }})
  267. .then(response => {
  268. this.init(this.idActivePointSale) ;
  269. }) ;
  270. },
  271. orderViewClick: function(event) {
  272. var currentIdOrderView = event.currentTarget.getAttribute('data-id-order') ;
  273. if(this.idOrderView == currentIdOrderView) {
  274. this.showViewProduct = !this.showViewProduct ;
  275. }
  276. else {
  277. this.showViewProduct = true ;
  278. this.idOrderView = currentIdOrderView ;
  279. }
  280. }
  281. },
  282. });
  283. Vue.component('modal', {
  284. template: '#modal-template'
  285. })
  286. Vue.component('order-form',{
  287. props: ['date', 'pointsSale', 'users', 'products', 'order'],
  288. data: function() {
  289. return {
  290. errors: [],
  291. idPointSale: 0,
  292. idUser: 0,
  293. username : '',
  294. comment: '',
  295. } ;
  296. },
  297. template: '#order-form-template',
  298. methods: {
  299. checkForm: function() {
  300. this.errors = [] ;
  301. var countProducts = 0 ;
  302. for(var key in this.order.productOrder) {
  303. if(this.order.productOrder[key] > 0) {
  304. countProducts ++ ;
  305. }
  306. }
  307. if(this.order.id_point_sale
  308. && (this.order.id_user || (this.order.username && this.order.username.length))
  309. && countProducts > 0) {
  310. return true ;
  311. }
  312. if(!this.order.id_point_sale) {
  313. this.errors.push('Veuillez sélectionner un point de vente') ;
  314. }
  315. if(!this.order.id_user && !this.order.username) {
  316. this.errors.push('Veuillez sélectionner ou saisir un utilisateur') ;
  317. }
  318. if(!countProducts) {
  319. this.errors.push('Veuillez sélectionner au moins un produit') ;
  320. }
  321. },
  322. submitFormCreate: function() {
  323. if(this.checkForm()) {
  324. axios.get(UrlManager.getBaseUrlAbsolute()+"order/ajax-create",{params: {
  325. date: this.date.getFullYear() + '-'
  326. + ('0' + (this.date.getMonth() +1)).slice(-2) + '-'
  327. + ('0' + this.date.getDate()).slice(-2),
  328. idPointSale: this.order.id_point_sale,
  329. idUser: this.order.id_user,
  330. username: this.order.username,
  331. products: JSON.stringify(this.order.productOrder),
  332. comment: this.order.comment
  333. }})
  334. .then(response => {
  335. this.order.id_point_sale = 0 ;
  336. this.order.id_user = 0 ;
  337. this.order.username = '' ;
  338. this.order.comment = '' ;
  339. for(i=0 ; i<this.order.productOrder.length ; i++) {
  340. this.order.productOrder[i] = 0 ;
  341. }
  342. this.$emit('ordercreatedupdated') ;
  343. }) ;
  344. }
  345. },
  346. submitFormUpdate: function() {
  347. if(this.checkForm()) {
  348. axios.get(UrlManager.getBaseUrlAbsolute()+"order/ajax-update",{params: {
  349. date: this.date.getFullYear() + '-'
  350. + ('0' + (this.date.getMonth() +1)).slice(-2) + '-'
  351. + ('0' + this.date.getDate()).slice(-2),
  352. idOrder: this.order.id,
  353. idPointSale: this.order.id_point_sale,
  354. idUser: this.order.id_user,
  355. username: ''+this.order.username,
  356. products: JSON.stringify(this.order.productOrder),
  357. comment: this.comment
  358. }})
  359. .then(response => {
  360. this.$emit('ordercreatedupdated') ;
  361. }) ;
  362. }
  363. },
  364. productQuantityClick: function(id_product, quantity) {
  365. if(this.order.productOrder[id_product] + quantity >= 0) {
  366. this.order.productOrder[id_product] += quantity ;
  367. }
  368. }
  369. }
  370. }) ;