選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

454 行
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. if(!app.orders[i].date_delete) {
  110. app.countOrders ++ ;
  111. }
  112. }
  113. }
  114. else {
  115. app.orders = [] ;
  116. }
  117. if(response.data.order_create) {
  118. app.orderCreate = response.data.order_create ;
  119. app.idDefaultPointSale = app.orderCreate.id_point_sale ;
  120. }
  121. if(response.data.points_sale) {
  122. app.pointsSale = response.data.points_sale ;
  123. app.initPointsSale(idActivePointSale) ;
  124. }
  125. else {
  126. app.pointsSale = [] ;
  127. }
  128. if(response.data.users) {
  129. app.users = response.data.users ;
  130. }
  131. app.calendar.attrs = [] ;
  132. var distributions = response.data.distributions ;
  133. if(distributions.length) {
  134. for(var i= 0; i < distributions.length; i++) {
  135. app.calendar.attrs.push({
  136. highlight: {
  137. backgroundColor: '#5cb85c',
  138. },
  139. contentStyle: {
  140. color: 'white',
  141. },
  142. dates: distributions[i].date,
  143. }) ;
  144. }
  145. }
  146. app.showLoading = false ;
  147. }) ;
  148. },
  149. initCountActiveProducts: function() {
  150. this.countActiveProducts = 0 ;
  151. for(var i= 0; i < this.products.length; i++) {
  152. if(this.products[i].productDistribution[0].active == 1) {
  153. this.countActiveProducts ++ ;
  154. }
  155. }
  156. },
  157. initPointsSale: function(idActivePointSale) {
  158. this.countActivePointsSale = 0 ;
  159. this.setIdActivePointSale(0) ;
  160. for(var i= 0; i < this.pointsSale.length; i++) {
  161. if(this.pointsSale[i].pointSaleDistribution[0].delivery == 1) {
  162. this.countActivePointsSale ++ ;
  163. this.setIdActivePointSale(this.pointsSale[i].id) ;
  164. }
  165. }
  166. if(this.countActivePointsSale > 1) {
  167. this.setIdActivePointSale(0) ;
  168. }
  169. if(idActivePointSale) {
  170. this.setIdActivePointSale(idActivePointSale) ;
  171. }
  172. this.countOrdersByPointSale = [] ;
  173. for(var i = 0; i < this.pointsSale.length ; i++) {
  174. this.countOrdersByPointSale[this.pointsSale[i].id] = 0 ;
  175. }
  176. for(var i = 0; i < this.orders.length ; i++) {
  177. this.countOrdersByPointSale[this.orders[i].id_point_sale] ++ ;
  178. }
  179. },
  180. dayClicked: function(day) {
  181. this.date = day.date ;
  182. this.dateFormat = ('0' + this.date.getDate()).slice(-2)+ '/'
  183. + ('0' + (this.date.getMonth() +1)).slice(-2) + '/'
  184. + this.date.getFullYear() ;
  185. this.init() ;
  186. },
  187. productQuantityMaxChange: function(event) {
  188. axios.get("ajax-process-product-quantity-max",{params: {
  189. idDistribution: this.distribution.id,
  190. idProduct: event.currentTarget.getAttribute('data-id-product'),
  191. quantityMax: event.currentTarget.value
  192. }})
  193. .then(function(response) {
  194. }) ;
  195. },
  196. productActiveClick: function(event) {
  197. var idProduct = event.currentTarget.getAttribute('data-id-product') ;
  198. var activeProduct = event.currentTarget.getAttribute('data-active-product') ;
  199. axios.get("ajax-process-active-product",{params: {
  200. idDistribution: this.distribution.id,
  201. idProduct: idProduct,
  202. active: activeProduct
  203. }})
  204. .then(function(response) {
  205. }) ;
  206. for(i = 0 ; i < this.products.length ; i++) {
  207. if(this.products[i].id == idProduct) {
  208. this.products[i].productDistribution[0].active = activeProduct ;
  209. }
  210. }
  211. this.initCountActiveProducts() ;
  212. },
  213. pointSaleActiveClick: function(event) {
  214. var idPointSale = event.currentTarget.getAttribute('data-id-point-sale') ;
  215. var deliveryPointSale = event.currentTarget.getAttribute('data-delivery-point-sale') ;
  216. axios.get("ajax-process-active-point-sale",{params: {
  217. idDistribution: this.distribution.id,
  218. idPointSale: idPointSale,
  219. delivery: deliveryPointSale
  220. }})
  221. .then(function(response) {
  222. }) ;
  223. for(i = 0 ; i < this.pointsSale.length ; i++) {
  224. if(this.pointsSale[i].id == idPointSale) {
  225. this.pointsSale[i].pointSaleDistribution[0].delivery = deliveryPointSale ;
  226. }
  227. }
  228. this.initPointsSale() ;
  229. },
  230. activeDistribution: function(event) {
  231. var app = this ;
  232. axios.get("ajax-process-active-distribution",{params: {
  233. idDistribution: this.distribution.id,
  234. active: event.currentTarget.getAttribute('data-active')
  235. }})
  236. .then(function(response) {
  237. app.init() ;
  238. }) ;
  239. },
  240. activeWeekDistribution: function(event) {
  241. var app = this ;
  242. axios.get("ajax-process-active-week-distribution",{params: {
  243. date: this.date.getFullYear() + '-'
  244. + ('0' + (this.date.getMonth() +1)).slice(-2) + '-'
  245. + ('0' + this.date.getDate()).slice(-2),
  246. active: event.currentTarget.getAttribute('data-active')
  247. }})
  248. .then(function(response) {
  249. app.init() ;
  250. }) ;
  251. },
  252. pointSaleClick: function(event) {
  253. this.setIdActivePointSale(event.currentTarget.getAttribute('data-id-point-sale')) ;
  254. },
  255. setIdActivePointSale: function(id) {
  256. this.idActivePointSale = id ;
  257. if(!id) {
  258. this.orderCreate.id_point_sale = this.idDefaultPointSale ;
  259. }
  260. else {
  261. this.orderCreate.id_point_sale = id ;
  262. }
  263. },
  264. orderCreatedUpdated: function() {
  265. this.showModalFormOrderCreate = false ;
  266. this.showModalFormOrderUpdate = false ;
  267. this.init(this.idActivePointSale) ;
  268. },
  269. deleteOrderClick: function(event) {
  270. var app = this ;
  271. var idOrder = event.currentTarget.getAttribute('data-id-order') ;
  272. axios.get(UrlManager.getBaseUrlAbsolute()+"order/ajax-delete",{params: {
  273. idOrder: idOrder
  274. }})
  275. .then(function(response) {
  276. app.init(app.idActivePointSale) ;
  277. }) ;
  278. },
  279. updateOrderClick: function(event) {
  280. var idOrder = event.currentTarget.getAttribute('data-id-order') ;
  281. this.idOrderUpdate = idOrder ;
  282. this.showModalFormOrderUpdate = true ;
  283. },
  284. orderPaymentModalClick: function(event) {
  285. var idOrder = event.currentTarget.getAttribute('data-id-order') ;
  286. this.idOrderPayment = idOrder ;
  287. this.showModalPayment = true ;
  288. },
  289. orderPaymentClick: function(event) {
  290. var app = this ;
  291. var idOrder = event.currentTarget.getAttribute('data-id-order') ;
  292. if(!idOrder) {
  293. idOrder = this.idOrderPayment ;
  294. }
  295. axios.get(UrlManager.getBaseUrlAbsolute()+"order/ajax-payment",{params: {
  296. idOrder: idOrder,
  297. type: event.currentTarget.getAttribute('data-type'),
  298. amount: event.currentTarget.getAttribute('data-amount')
  299. }})
  300. .then(function(response) {
  301. app.init(app.idActivePointSale) ;
  302. }) ;
  303. },
  304. orderViewClick: function(event) {
  305. var currentIdOrderView = event.currentTarget.getAttribute('data-id-order') ;
  306. if(this.idOrderView == currentIdOrderView) {
  307. this.showViewProduct = !this.showViewProduct ;
  308. }
  309. else {
  310. this.showViewProduct = true ;
  311. this.idOrderView = currentIdOrderView ;
  312. }
  313. },
  314. closeModalProducts: function() {
  315. this.showModalProducts = false ;
  316. this.init(this.idActivePointSale) ;
  317. }
  318. },
  319. });
  320. Vue.component('modal', {
  321. template: '#modal-template'
  322. })
  323. Vue.component('order-form',{
  324. props: ['date', 'pointsSale', 'users', 'products', 'order'],
  325. data: function() {
  326. return {
  327. errors: [],
  328. idPointSale: 0,
  329. idUser: 0,
  330. username : '',
  331. comment: '',
  332. } ;
  333. },
  334. template: '#order-form-template',
  335. methods: {
  336. checkForm: function() {
  337. this.errors = [] ;
  338. var countProducts = 0 ;
  339. for(var key in this.order.productOrder) {
  340. if(this.order.productOrder[key] > 0) {
  341. countProducts ++ ;
  342. }
  343. }
  344. if(this.order.id_point_sale
  345. && (this.order.id_user || (this.order.username && this.order.username.length))
  346. && countProducts > 0) {
  347. return true ;
  348. }
  349. if(!this.order.id_point_sale) {
  350. this.errors.push('Veuillez sélectionner un point de vente') ;
  351. }
  352. if(!this.order.id_user && !this.order.username) {
  353. this.errors.push('Veuillez sélectionner ou saisir un utilisateur') ;
  354. }
  355. if(!countProducts) {
  356. this.errors.push('Veuillez sélectionner au moins un produit') ;
  357. }
  358. },
  359. submitFormCreate: function(event) {
  360. var app = this ;
  361. if(this.checkForm()) {
  362. var processCredit = event.currentTarget.getAttribute('data-process-credit') ;
  363. axios.get(UrlManager.getBaseUrlAbsolute()+"order/ajax-create",{params: {
  364. date: this.date.getFullYear() + '-'
  365. + ('0' + (this.date.getMonth() +1)).slice(-2) + '-'
  366. + ('0' + this.date.getDate()).slice(-2),
  367. idPointSale: this.order.id_point_sale,
  368. idUser: this.order.id_user,
  369. username: this.order.username,
  370. products: JSON.stringify(this.order.productOrder),
  371. comment: this.order.comment,
  372. processCredit: processCredit
  373. }})
  374. .then(function(response) {
  375. app.order.id_point_sale = 0 ;
  376. app.order.id_user = 0 ;
  377. app.order.username = '' ;
  378. app.order.comment = '' ;
  379. for(i=0 ; i<app.order.productOrder.length ; i++) {
  380. app.order.productOrder[i] = 0 ;
  381. }
  382. app.$emit('ordercreatedupdated') ;
  383. }) ;
  384. }
  385. },
  386. submitFormUpdate: function(event) {
  387. var app = this ;
  388. if(this.checkForm()) {
  389. var processCredit = event.currentTarget.getAttribute('data-process-credit') ;
  390. axios.get(UrlManager.getBaseUrlAbsolute()+"order/ajax-update",{params: {
  391. date: this.date.getFullYear() + '-'
  392. + ('0' + (this.date.getMonth() +1)).slice(-2) + '-'
  393. + ('0' + this.date.getDate()).slice(-2),
  394. idOrder: this.order.id,
  395. idPointSale: this.order.id_point_sale,
  396. idUser: this.order.id_user,
  397. username: ''+this.order.username,
  398. products: JSON.stringify(this.order.productOrder),
  399. comment: this.comment,
  400. processCredit: processCredit
  401. }})
  402. .then(function(response) {
  403. app.$emit('ordercreatedupdated') ;
  404. }) ;
  405. }
  406. },
  407. productQuantityClick: function(id_product, quantity) {
  408. if(this.order.productOrder[id_product] + quantity >= 0) {
  409. this.order.productOrder[id_product] += quantity ;
  410. }
  411. }
  412. }
  413. }) ;