Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

467 rindas
17KB

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