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.

429 lines
16KB

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