Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

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