|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427 |
-
-
- var app = new Vue({
- el: '#app-distribution-index',
- data: {
- date: null,
- dateFormat: null,
- loading: true,
- distribution: {
- active: false,
- },
- oneDistributionWeekActive: false,
- products: [],
- countActiveProducts: 0,
- pointsSale: [],
- idActivePointSale: 0,
- countActivePointsSale: 0,
- countOrdersByPointSale: [],
- orders: [],
- countOrders: 0,
- users: [],
- showModalProducts: false,
- showModalPointsSale: false,
-
- showModalFormOrderCreate: false,
- orderCreate: null,
-
- showModalFormOrderUpdate: false,
- idOrderUpdate: 0,
-
- showViewProduct: false,
- idOrderView: 0,
-
- showModalPayment: false,
- idOrderPayment: 0,
-
- showLoading: false,
- calendar: {
- mode: 'single',
- attrs: [],
- themeStyles: {
- wrapper: {
- background: '#F7F7F7',
- color: '#333',
- border: 'solid 1px #e0e0e0'
- },
- header: {
- padding: '10px 10px',
- },
- headerHorizontalDivider: {
- borderTop: 'solid rgba(255, 255, 255, 0.2) 1px',
- width: '80%',
- },
- weekdays: {
- color: '#e0e0e0',
- fontWeight: '600',
- padding: '10px 10px',
- fontSize: '2rem'
- },
- weeks: {
- padding: '0 15px 15px 15px',
- },
- dayContent: function(object) {
- var style = {
- fontSize: '2rem',
- padding: '16px',
- };
-
- if(object.isHovered || object.isFocus) {
- style.backgroundColor = '#F39C12' ;
- }
-
- return style ;
- },
- },
- formats: {
- dayPopover: 'DD/MM/YYYY'
- }
- },
- },
-
- mounted: function() {
- if($('#distribution-date').size()) {
- this.date = new Date($('#distribution-date').html()) ;
- this.dateFormat = ('0' + this.date.getDate()).slice(-2)+ '/'
- + ('0' + (this.date.getMonth() +1)).slice(-2) + '/'
- + this.date.getFullYear() ;
- }
-
- this.init() ;
- this.loading = false ;
- },
-
- methods: {
- getDate: function() {
- return this.formatDate(this.date) ;
- },
- formatDate: function(date) {
- if(date) {
- return date.getFullYear() + '-'
- + ('0' + (date.getMonth() +1)).slice(-2) + '-'
- + ('0' + date.getDate()).slice(-2) ;
- }
- return false ;
- },
- init: function(idActivePointSale) {
- this.showLoading = true ;
-
- axios.get("ajax-infos",{params: {date : this.getDate()}})
- .then(response => {
- this.distribution = response.data.distribution ;
-
- this.products = response.data.products ;
- this.initCountActiveProducts() ;
-
- this.oneDistributionWeekActive = response.data.one_distribution_week_active ;
-
- if(response.data.orders) {
- this.orders = response.data.orders ;
-
- this.countOrders = 0 ;
- for(i=0 ; i < this.orders.length ; i++) {
- if(!this.orders[i].date_delete) {
- this.countOrders ++ ;
- }
- }
- }
- else {
- this.orders = [] ;
- }
-
- if(response.data.order_create) {
- this.orderCreate = response.data.order_create ;
- }
-
- if(response.data.points_sale) {
- this.pointsSale = response.data.points_sale ;
- this.initPointsSale(idActivePointSale) ;
- }
- else {
- this.pointsSale = [] ;
- }
-
- if(response.data.users) {
- this.users = response.data.users ;
- }
-
- this.calendar.attrs = [] ;
- var distributions = response.data.distributions ;
- if(distributions.length) {
- for(var i= 0; i < distributions.length; i++) {
- this.calendar.attrs.push({
- highlight: {
- backgroundColor: '#5cb85c',
- },
- contentStyle: {
- color: 'white',
- },
- dates: distributions[i].date,
- }) ;
- }
- }
-
- this.showLoading = false ;
- }) ;
- },
- initCountActiveProducts: function() {
- this.countActiveProducts = 0 ;
- for(var i= 0; i < this.products.length; i++) {
- if(this.products[i].productDistribution[0].active == 1) {
- this.countActiveProducts ++ ;
- }
- }
- },
- initPointsSale: function(idActivePointSale) {
- this.countActivePointsSale = 0 ;
- this.setIdActivePointSale(0) ;
- for(var i= 0; i < this.pointsSale.length; i++) {
- if(this.pointsSale[i].pointSaleDistribution[0].delivery == 1) {
- this.countActivePointsSale ++ ;
- this.setIdActivePointSale(this.pointsSale[i].id) ;
- }
- }
- if(this.countActivePointsSale > 1) {
- this.setIdActivePointSale(0) ;
- }
- if(idActivePointSale) {
- this.setIdActivePointSale(idActivePointSale) ;
- }
-
- this.countOrdersByPointSale = [] ;
- for(var i = 0; i < this.pointsSale.length ; i++) {
- this.countOrdersByPointSale[this.pointsSale[i].id] = 0 ;
- }
- for(var i = 0; i < this.orders.length ; i++) {
- this.countOrdersByPointSale[this.orders[i].id_point_sale] ++ ;
- }
- },
- dayClicked: function(day) {
- this.date = day.date ;
- this.dateFormat = ('0' + this.date.getDate()).slice(-2)+ '/'
- + ('0' + (this.date.getMonth() +1)).slice(-2) + '/'
- + this.date.getFullYear() ;
- this.init() ;
- },
- productQuantityMaxChange: function(event) {
- axios.get("ajax-process-product-quantity-max",{params: {
- idDistribution: this.distribution.id,
- idProduct: event.currentTarget.getAttribute('data-id-product'),
- quantityMax: event.currentTarget.value
- }})
- .then(response => {
-
- }) ;
- },
- productActiveClick: function(event) {
- var idProduct = event.currentTarget.getAttribute('data-id-product') ;
- var activeProduct = event.currentTarget.getAttribute('data-active-product') ;
- axios.get("ajax-process-active-product",{params: {
- idDistribution: this.distribution.id,
- idProduct: idProduct,
- active: activeProduct
- }})
- .then(response => {
-
- }) ;
-
- for(i = 0 ; i < this.products.length ; i++) {
- if(this.products[i].id == idProduct) {
- this.products[i].productDistribution[0].active = activeProduct ;
- }
- }
- this.initCountActiveProducts() ;
-
- },
- pointSaleActiveClick: function(event) {
- var idPointSale = event.currentTarget.getAttribute('data-id-point-sale') ;
- var deliveryPointSale = event.currentTarget.getAttribute('data-delivery-point-sale') ;
- axios.get("ajax-process-active-point-sale",{params: {
- idDistribution: this.distribution.id,
- idPointSale: idPointSale,
- delivery: deliveryPointSale
- }})
- .then(response => {
-
- }) ;
-
- for(i = 0 ; i < this.pointsSale.length ; i++) {
- if(this.pointsSale[i].id == idPointSale) {
- this.pointsSale[i].pointSaleDistribution[0].delivery = deliveryPointSale ;
- }
- }
-
- this.initPointsSale() ;
- },
- activeDistribution: function(event) {
- axios.get("ajax-process-active-distribution",{params: {
- idDistribution: this.distribution.id,
- active: event.currentTarget.getAttribute('data-active')
- }})
- .then(response => {
- this.init() ;
- }) ;
- },
- activeWeekDistribution: function(event) {
- axios.get("ajax-process-active-week-distribution",{params: {
- date: this.date.getFullYear() + '-'
- + ('0' + (this.date.getMonth() +1)).slice(-2) + '-'
- + ('0' + this.date.getDate()).slice(-2),
- active: event.currentTarget.getAttribute('data-active')
- }})
- .then(response => {
- this.init() ;
- }) ;
- },
- pointSaleClick: function(event) {
- this.setIdActivePointSale(event.currentTarget.getAttribute('data-id-point-sale')) ;
- },
- setIdActivePointSale: function(id) {
- this.idActivePointSale = id ;
- this.orderCreate.id_point_sale = id ;
- },
- orderCreatedUpdated: function() {
- this.showModalFormOrderCreate = false ;
- this.showModalFormOrderUpdate = false ;
- this.init(this.idActivePointSale) ;
- },
- deleteOrderClick: function(event) {
- var idOrder = event.currentTarget.getAttribute('data-id-order') ;
- axios.get(UrlManager.getBaseUrlAbsolute()+"order/ajax-delete",{params: {
- idOrder: idOrder
- }})
- .then(response => {
- this.init(this.idActivePointSale) ;
- }) ;
- },
- updateOrderClick: function(event) {
- var idOrder = event.currentTarget.getAttribute('data-id-order') ;
- this.idOrderUpdate = idOrder ;
- this.showModalFormOrderUpdate = true ;
- },
- orderPaymentModalClick: function(event) {
- var idOrder = event.currentTarget.getAttribute('data-id-order') ;
- this.idOrderPayment = idOrder ;
- this.showModalPayment = true ;
- },
- orderPaymentClick: function(event) {
- var idOrder = event.currentTarget.getAttribute('data-id-order') ;
- axios.get(UrlManager.getBaseUrlAbsolute()+"order/ajax-payment",{params: {
- idOrder: this.idOrderPayment,
- type: event.currentTarget.getAttribute('data-type'),
- amount: event.currentTarget.getAttribute('data-amount')
- }})
- .then(response => {
- this.init(this.idActivePointSale) ;
- }) ;
- },
- orderViewClick: function(event) {
- var currentIdOrderView = event.currentTarget.getAttribute('data-id-order') ;
- if(this.idOrderView == currentIdOrderView) {
- this.showViewProduct = !this.showViewProduct ;
- }
- else {
- this.showViewProduct = true ;
- this.idOrderView = currentIdOrderView ;
- }
-
- }
- },
- });
-
- Vue.component('modal', {
- template: '#modal-template'
- })
-
- Vue.component('order-form',{
- props: ['date', 'pointsSale', 'users', 'products', 'order'],
- data: function() {
- return {
- errors: [],
- idPointSale: 0,
- idUser: 0,
- username : '',
- comment: '',
- } ;
- },
- template: '#order-form-template',
- methods: {
- checkForm: function() {
- this.errors = [] ;
-
- var countProducts = 0 ;
- for(var key in this.order.productOrder) {
- if(this.order.productOrder[key] > 0) {
- countProducts ++ ;
- }
- }
-
- if(this.order.id_point_sale
- && (this.order.id_user || (this.order.username && this.order.username.length))
- && countProducts > 0) {
- return true ;
- }
-
- if(!this.order.id_point_sale) {
- this.errors.push('Veuillez sélectionner un point de vente') ;
- }
-
- if(!this.order.id_user && !this.order.username) {
- this.errors.push('Veuillez sélectionner ou saisir un utilisateur') ;
- }
-
- if(!countProducts) {
- this.errors.push('Veuillez sélectionner au moins un produit') ;
- }
-
- },
- submitFormCreate: function() {
- if(this.checkForm()) {
- axios.get(UrlManager.getBaseUrlAbsolute()+"order/ajax-create",{params: {
- date: this.date.getFullYear() + '-'
- + ('0' + (this.date.getMonth() +1)).slice(-2) + '-'
- + ('0' + this.date.getDate()).slice(-2),
- idPointSale: this.order.id_point_sale,
- idUser: this.order.id_user,
- username: this.order.username,
- products: JSON.stringify(this.order.productOrder),
- comment: this.order.comment
- }})
- .then(response => {
- this.order.id_point_sale = 0 ;
- this.order.id_user = 0 ;
- this.order.username = '' ;
- this.order.comment = '' ;
- for(i=0 ; i<this.order.productOrder.length ; i++) {
- this.order.productOrder[i] = 0 ;
- }
-
- this.$emit('ordercreatedupdated') ;
- }) ;
- }
- },
- submitFormUpdate: function() {
- if(this.checkForm()) {
- axios.get(UrlManager.getBaseUrlAbsolute()+"order/ajax-update",{params: {
- date: this.date.getFullYear() + '-'
- + ('0' + (this.date.getMonth() +1)).slice(-2) + '-'
- + ('0' + this.date.getDate()).slice(-2),
- idOrder: this.order.id,
- idPointSale: this.order.id_point_sale,
- idUser: this.order.id_user,
- username: ''+this.order.username,
- products: JSON.stringify(this.order.productOrder),
- comment: this.comment
- }})
- .then(response => {
- this.$emit('ordercreatedupdated') ;
- }) ;
- }
- },
- productQuantityClick: function(id_product, quantity) {
- if(this.order.productOrder[id_product] + quantity >= 0) {
- this.order.productOrder[id_product] += quantity ;
- }
- }
- }
- }) ;
|