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

distribution-index.js 16KB

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