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.

427 satır
16KB

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