Vuex Tutorial

By ukmodak | May 18th 2022 09:26:00 AM | viewed 21 times

Run the following command:

restaurentPos>npm install vuex@next --save

create a folder store in the location resources\js\

create index.js in the location resources\js\store\ and add the following code


import Vue from "vue";
import Vuex from "vuex";


import admin from "./modules/admin";
import admin from "./modules/setup";
import notificationMessage from "./modules/notificationMessage";

Vue.use(Vuex);

export default new Vuex.Store({
       modules:{
           admin,
		   setup,
           notificationMessage
       } 
});

create a file configManual.js in the location ../../components/config/ and add the following code

const siteBasePath = document.querySelector("meta[name='path']").getAttribute('data-path');
export default{
        sitePath:siteBasePath,
        basePath:'/posmaster/'
        //basePath:'/'
                
}

create a a file admin.js in the location resources\js\store\modules\ and add the following code

import axios from "axios";
import configManual from "../../components/config/configManual"


const getters = {
   allPosCompany:state=>state.posCompany,
   editPosCompanyList:state=>state.editPosCompanyList,
   
  
   
   allPosRole:state=>state.posRole,
   editPosRoleList:state=>state.editPosRoleList,
   
    allPosUser:state=>state.posUser,
    editPosUserList:state=>state.editPosUserList,
    
    
   allPosMenu:state=>state.posMenu,
   editPosMenuList:state=>state.editPosMenuList,
   
   allPosRoleMenu:state =>state.posRoleMenu,
   
   authLoginUser:state =>state.authLoginUserInfo,

  
};

const state = {
    
     posCompany:[],
     editPosCompanyList:[],
    
    
     
     posRole:[],
     editPosRoleList:[],
     
     posUser:[],
     editPosUserList:[],
      
     posMenu:[],
     editPosMenuList:[],
     
      posRoleMenu:[],
      
      authLoginUserInfo:[],
     
     
};


const mutations = {
    
      /* company info */
     addComMutation:(state,data)=>(state.posCompany.unshift(data.response)),
     getPosCompanyMutation:(state,data)=>(state.posCompany = data),
     editPosCompanyMutation:(state,data)=>(state.editPosCompanyList = data),
     updateCompanyMutation:(state,data)=>(state.editPosCompanyList = data),
     removeCompany:(state,data)=>(state.posCompany.filter(fil => fil.id != data.data.id)),
      /* end company info */
      
     
        
         /* role info */
     addRoleMutation:(state,data)=>(state.posRole.unshift(data.response)),
     getPosRoleMutation:(state,data)=>(state.posRole = data),
     editPosRoleMutation:(state,data)=>(state.editPosRoleList = data),
     updateRoleMutation:(state,data)=>(state.editPosRoleList = data),
     removeRole:(state,data)=>(state.posRole.filter(fil => fil.id != data.data.id)),
        /* end role info */
        
     
        
        /* user info */
     addUserMutation:(state,data)=>(state.posUser.unshift(data)),
     getPosUserMutation:(state,data)=>(state.posUser = data),
     editPosUserMutation:(state,data)=>(state.editPosUserList = data),
     updateUserMutation:(state,data)=>(state.editPosUserList = data),
     removeUser:(state,data)=>(state.posUser.filter(fil => fil.id != data.id)),
        /* end user info */
        
        
         /* menu info */
     addMenuMutation:(state,data)=>(state.posMenu.unshift(data.response)),
     getPosMenuMutation:(state,data)=>(state.posMenu = data),
     editPosMenuMutation:(state,data)=>(state.editPosMenuList = data),
     updateMenuMutation:(state,data)=>(state.editPosMenuList = data),
     removeMenu:(state,data)=>(state.posMenu.filter(fil => fil.id != data.data.id)),
     instantMenuMutation:(state,data)=>(state.editPosMenuList = data),
        /* end menu info */
        
        
         /* role menu  permission */
    
     getPosRoleMenuMutation:(state,data)=>(state.posRoleMenu = data),
     
    
        /* end role menu permission */
        
        
         /* userLogin */
    
     loginMutation:(state,data)=>{
           state.authLoginUserInfo = data
           //localStorage.setItem('userData', JSON.stringify(data))
     },
     
    
        /* end userLogin */
    
    

};


const actions = {
    
    /* company api */
   async addCompany({commit,dispatch},conpanyData){
        const response = await axios.post(configManual.sitePath+"/api/company_insert",conpanyData);
                 
                let group ='message1';
                let type ='';
                let message ='';
		if(response.data.status=='no_unique'){
                    type ='error';
                    message ='Data not unique';	
		}else if(response.data.status=='fail'){
                     type ='error';
                    message ='Data insert fail'; 
                }else if(response.data.status=='success'){
                      type ='success';
                    message ='Data insert successful'; 
                }
                const messageData = {
                    group:group,
                    type:type,
                    message:message
                };

               dispatch('addNotification',messageData,{root:true});
               commit("addComMutation",{response:response.data});

       
    },
     async getPosCompanyFilterList({commit},filterData){
        const response = await axios.post(configManual.sitePath+"/api/company_filter",filterData);
        commit("getPosCompanyMutation",response.data);
    },
     async editPosCompany({commit,dispatch},data){
        console.log("checl edit "+data.id);
        const response = await axios.get(configManual.sitePath+"/api/company_edit/"+data.id+"");
                let group ='message1';
                let type ='';
                let message ='';
		if(response.data.status =='fail'){
                    type ='error';
                    message ='Data edit fail';	
                     dispatch('addNotification',{ 
                          group:group,
                           type:type,
                           message:message
                       });
		}
             
                
           commit("editPosCompanyMutation",response.data);
        
    },
    async updateCompany({commit,dispatch},conpanyData){
        const response = await axios.post(configManual.sitePath+"/api/company_update",conpanyData);
                 
                let group ='message1';
                let type ='';
                let message ='';
		if(response.data.status=='no_unique'){
                    type ='error';
                    message ='Data not unique';	
		}else if(response.data.status=='fail'){
                     type ='error';
                    message ='Data insert fail'; 
                }else if(response.data.status=='success'){
                      type ='success';
                    message ='Data update successful'; 
                }
                const messageData = {
                    group:group,
                    type:type,
                    message:message
                };

               dispatch('addNotification',messageData,{root:true});
               commit("updateCompanyMutation",{response:response.data});

       
    },
    async deleteCom({commit},data){
       const response = await axios.post(configManual.sitePath+"/api/company_del",data);
       commit("removeCompany",{data:data,response:response.data}); 
       
    },
       /* end company api */
       

        /* role api */
   async addRole({commit,dispatch},data){
        const response = await axios.post(configManual.sitePath+"/api/role_insert",data);
                 
                let group ='message1';
                let type ='';
                let message ='';
		if(response.data.status=='no_unique'){
                    type ='error';
                    message ='Data not unique';	
		}else if(response.data.status=='fail'){
                     type ='error';
                    message ='Data insert fail'; 
                }else if(response.data.status=='success'){
                      type ='success';
                    message ='Data insert successful'; 
                }
               
               if(type !=''){
                  dispatch('addNotification',
                  {
                    group:group,
                    type:type,
                    message:message
                  },
                  {root:true}
                  );  
               }
              
               commit("addRoleMutation",{response:response.data});

       
    },
     async getPosRoleFilterList({commit},filterData){
        const response = await axios.post(configManual.sitePath+"/api/role_filter",filterData);
        commit("getPosRoleMutation",response.data);
    },
     async editPosRole({commit,dispatch},data){
        const response = await axios.get(configManual.sitePath+"/api/role_edit/"+data.id+"");
                let group ='message1';
                let type ='';
                let message ='';
		if(response.data.status =='fail'){
                    type ='error';
                    message ='Data edit fail';	
		} 
             if(type !=''){
                  dispatch('addNotification',
                    {
                    group:group,
                    type:type,
                    message:message
                   },
                   {root:true}
                   ); 
             }
          
           commit("editPosRoleMutation",response.data);
        
    },
     async updateRole({commit,dispatch},data){
        const response = await axios.post(configManual.sitePath+"/api/role_update",data);
                 
                let group ='message1';
                let type ='';
                let message ='';
		if(response.data.status=='no_unique'){
                    type ='error';
                    message ='Data not unique';	
		}else if(response.data.status=='fail'){
                     type ='error';
                    message ='Data insert fail'; 
                }else if(response.data.status=='success'){
                      type ='success';
                    message ='Data update successful'; 
                }
                const messageData = {
                    group:group,
                    type:type,
                    message:message
                };

               dispatch('addNotification',messageData,{root:true});
               commit("updateRoleMutation",{response:response.data});

       
    },
    async deleteRole({commit,dispatch},data){
       const response = await axios.post(configManual.sitePath+"/api/role_del",data);
       
                let group ='message1';
                let type ='';
                let message ='';
		if(response.data.status =='no_record_found'){
                    type ='error';
                    message ='No record found';	
		}else if(response.data.status =='success'){
                    type ='success';
                    message ='deletion successful';	 
                } 
                
             if(type){
                  dispatch('addNotification',
                    {
                    group:group,
                    type:type,
                    message:message
                     },
                    {root:true}
                  ); 
             }
           commit("removeRole",{data:data,response:response.data}); 
       
    },
       /* end role api */
       
       
       /* user api */
   async addUser({commit,dispatch},data){
      
       const config = {
                    headers: {
                        'content-type': 'multipart/form-data',
                        'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').content
                      }
                    };
        const response = await axios.post(configManual.sitePath+"/api/user_insert",data,config);
                
                let group ='message1';
                let type ='';
                let message ='';
		if(response.data.status=='no_unique'){
                    type ='error';
                    message ='Data not unique';	
		}else if(response.data.status=='fail'){
                     type ='error';
                    message ='Data insert fail'; 
                }else if(response.data.status=='success'){
                      type ='success';
                    message ='Data insert successful'; 
                }
               
               if(type){
                  dispatch('addNotification',
                  {
                    group:group,
                    type:type,
                    message:message
                  },
                  {root:true}
                  );  
               }
              
               commit("addItemMutation",response.data);

       
    },
     async getPosUserFilterList({commit},filterData){
        const response = await axios.post(configManual.sitePath+"/api/user_filter",filterData);
        commit("getPosUserMutation",response.data);
    },
     async editPosUser({commit,dispatch},data){
        const response = await axios.get(configManual.sitePath+"/api/user_edit/"+data.id+"");
                let group ='message1';
                let type ='';
                let message ='';
		if(response.data.status =='fail'){
                    type ='error';
                    message ='Data edit fail';	
		} 
             if(type !=''){
                  dispatch('addNotification',
                    {
                    group:group,
                    type:type,
                    message:message
                   },
                   {root:true}
                   ); 
             }
          
           commit("editPosUserMutation",response.data);
        
    },
     async updateUser({commit,dispatch},data){
         
          const config = {
                    headers: {
                        'content-type': 'multipart/form-data',
                        'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').content
                      }
                    };
        const response = await axios.post(configManual.sitePath+"/api/user_update",data,config);
                 
                let group ='message1';
                let type ='';
                let message ='';
		if(response.data.status=='no_unique'){
                    type ='error';
                    message ='Data not unique';	
		}else if(response.data.status=='fail'){
                     type ='error';
                    message ='Data insert fail'; 
                }else if(response.data.status=='success'){
                      type ='success';
                    message ='Data update successful'; 
                }
                const messageData = {
                    group:group,
                    type:type,
                    message:message
                };

               dispatch('addNotification',messageData,{root:true});
               commit("updateItemMutation",response.data);

       
    },
    async deleteUser({commit,dispatch},data){
       const response = await axios.post(configManual.sitePath+"/api/user_del",data);
       
                let group ='message1';
                let type ='';
                let message ='';
		if(response.data.status =='no_record_found'){
                    type ='error';
                    message ='No record found';	
		}else if(response.data.status =='success'){
                    type ='success';
                    message ='Deletion successful';	 
                } 
                
             if(type){
                  dispatch('addNotification',
                    {
                    group:group,
                    type:type,
                    message:message
                     },
                    {root:true}
                  ); 
             }
           commit("removeUser",data); 
       
    },

    /* end user api */
    
    
    
     /* menu api */
   async addMenu({commit,dispatch},data){
        const response = await axios.post(configManual.sitePath+"/api/menu_insert",data);
                 
                let group ='message1';
                let type ='';
                let message ='';
		if(response.data.status=='no_unique'){
                    type ='error';
                    message ='Data not unique';	
		}else if(response.data.status=='fail'){
                     type ='error';
                    message ='Data insert fail'; 
                }else if(response.data.status=='success'){
                      type ='success';
                    message ='Data insert successful'; 
                }
               
               if(type !=''){
                  dispatch('addNotification',
                  {
                    group:group,
                    type:type,
                    message:message
                  },
                  {root:true}
                  );  
               }
              
               commit("addMenuMutation",{response:response.data});

       
    },
     async getPosMenuFilterList({commit},filterData){
        const response = await axios.post(configManual.sitePath+"/api/menu_filter",filterData);
        commit("getPosMenuMutation",response.data);
    },
     async editPosMenu({commit,dispatch},data){
        const response = await axios.get(configManual.sitePath+"/api/menu_edit/"+data.id+"");
                let group ='message1';
                let type ='';
                let message ='';
		if(response.data.status =='fail'){
                    type ='error';
                    message ='Data edit fail';	
		} 
             if(type !=''){
                  dispatch('addNotification',
                    {
                    group:group,
                    type:type,
                    message:message
                   },
                   {root:true}
                   ); 
             }
          
           commit("editPosMenuMutation",response.data);
        
    },
     async updateMenu({commit,dispatch},data){
        const response = await axios.post(configManual.sitePath+"/api/menu_update",data);
                 
                let group ='message1';
                let type ='';
                let message ='';
		if(response.data.status=='no_unique'){
                    type ='error';
                    message ='Data not unique';	
		}else if(response.data.status=='fail'){
                     type ='error';
                    message ='Data insert fail'; 
                }else if(response.data.status=='success'){
                      type ='success';
                    message ='Data update successful'; 
                }
                const messageData = {
                    group:group,
                    type:type,
                    message:message
                };

               dispatch('addNotification',messageData,{root:true});
               commit("updateMenuMutation",{response:response.data});

       
    },
    async deleteMenu({commit,dispatch},data){
       const response = await axios.post(configManual.sitePath+"/api/menu_del",data);
       
                let group ='message1';
                let type ='';
                let message ='';
		if(response.data.status =='no_record_found'){
                    type ='error';
                    message ='No record found';	
		}else if(response.data.status =='success'){
                    type ='success';
                    message ='deletion successful';	 
                } 
                
             if(type){
                  dispatch('addNotification',
                    {
                    group:group,
                    type:type,
                    message:message
                     },
                    {root:true}
                  ); 
             }
           commit("removeMenu",{data:data,response:response.data}); 
       
    },
    
    async instantMenu({commit,dispatch},data){
        const response = await axios.post(configManual.sitePath+"/api/menu_instant",data);
             //alert(response.data.menu_name);
        commit("instantMenuMutation",response.data);

       
    },
       /* end menu api */
       
       
   /* role menu permission */
   
    async getPosRoleMenuFilterList({commit},filterData){
        const response = await axios.post(configManual.sitePath+"/api/role_menu_filter",filterData);
        commit("getPosRoleMenuMutation",response.data);
    },
    
    async updateRoleMenu({commit,dispatch},data){
        const response = await axios.post(configManual.sitePath+"/api/role_menu_update",data);
                 
                let group ='message1';
                let type ='';
                let message ='';
		if(response.data.status=='fail'){
                     type ='error';
                    message ='Data insert fail'; 
                }else if(response.data.status=='success'){
                      type ='success';
                    message ='Data update successful'; 
                }
                const messageData = {
                    group:group,
                    type:type,
                    message:message
                };

               dispatch('addNotification',messageData,{root:true});

    },
   
   /* role menu permission */
   
    /* login user */
    
     async userLoginCheck({commit,dispatch},data){
        const response = await axios.post(configManual.sitePath+"/api/logincheck",data);
                 
                let group ='message1';
                let type ='';
                let message ='';
		if(response.data.status=='fail'){
                     type ='error';
                    message ='Data insert fail'; 
                }else{
                      type ='success';
                      message ='Loin successful'; 
                      //alert(response.data.id);
                      //localStorage.setItem('userData',response.data); 
                      
                      
                      
                }
                const messageData = {
                    group:group,
                    type:type,
                    message:message
                };

               dispatch('addNotification',messageData,{root:true});
               
               commit("loginMutation",response.data);
               
             

    },
    
    /* end login user */
    

};

export default {
    state,
    getters,
    mutations,
    actions
}

create a file setup.js in the location resources\js\store\modules\ and add the following code


import axios from "axios";
import configManual from "../../components/config/configManual"


const getters = {
   allPosCompany:state=>state.posCompany,
   editPosCompanyList:state=>state.editPosCompanyList,
   
   allPosCategory:state=>state.posCategory,
   editPosCategoryList:state=>state.editPosCategoryList,
   
   allPosUnit:state=>state.posUnit,
   editPosUnitList:state=>state.editPosUnitList,
   
   allPosRole:state=>state.posRole,
   editPosRoleList:state=>state.editPosRoleList,
   
    allPosUser:state=>state.posUser,
    editPosUserList:state=>state.editPosUserList,
    
    
   allPosMenu:state=>state.posMenu,
   editPosMenuList:state=>state.editPosMenuList,
   
   allPosRoleMenu:state =>state.posRoleMenu,

  
};

const state = {
    
     posCompany:[],
     editPosCompanyList:[],
    
     posCategory:[],
     editPosCategoryList:[],
     
     posUnit:[],
     editPosUnitList:[],
     
     posRole:[],
     editPosRoleList:[],
     
     posUser:[],
     editPosUserList:[],
      
     posMenu:[],
     editPosMenuList:[],
     
      posRoleMenu:[],
     
     
};


const mutations = {
    
      /* company info */
     addComMutation:(state,data)=>(state.posCompany.unshift(data.response)),
     getPosCompanyMutation:(state,data)=>(state.posCompany = data),
     editPosCompanyMutation:(state,data)=>(state.editPosCompanyList = data),
     updateCompanyMutation:(state,data)=>(state.editPosCompanyList = data),
     removeCompany:(state,data)=>(state.posCompany.filter(fil => fil.id != data.data.id)),
      /* end company info */
      
      /* category info */
     addCategoryMutation:(state,data)=>(state.posCategory.unshift(data.response)),
     getPosCategoryMutation:(state,data)=>(state.posCategory = data),
     editPosCategoryMutation:(state,data)=>(state.editPosCategoryList = data),
     updateCategoryMutation:(state,data)=>(state.editPosCategoryList = data),
     removeCategory:(state,data)=>(state.posCategory.filter(fil => fil.id != data.data.id)),
      /* end category info */
      
      
        /* unit info */
     addUnitMutation:(state,data)=>(state.posUnit.unshift(data.response)),
     getPosUnitMutation:(state,data)=>(state.posUnit = data),
     editPosUnitMutation:(state,data)=>(state.editPosUnitList = data),
     updateUnitMutation:(state,data)=>(state.editPosUnitList = data),
     removeUnit:(state,data)=>(state.posUnit.filter(fil => fil.id != data.data.id)),
        /* end unit info */
        
        
         /* role info */
     addRoleMutation:(state,data)=>(state.posRole.unshift(data.response)),
     getPosRoleMutation:(state,data)=>(state.posRole = data),
     editPosRoleMutation:(state,data)=>(state.editPosRoleList = data),
     updateRoleMutation:(state,data)=>(state.editPosRoleList = data),
     removeRole:(state,data)=>(state.posRole.filter(fil => fil.id != data.data.id)),
        /* end role info */
        
     
        
        /* user info */
     addUserMutation:(state,data)=>(state.posUser.unshift(data)),
     getPosUserMutation:(state,data)=>(state.posUser = data),
     editPosUserMutation:(state,data)=>(state.editPosUserList = data),
     updateUserMutation:(state,data)=>(state.editPosUserList = data),
     removeUser:(state,data)=>(state.posUser.filter(fil => fil.id != data.id)),
        /* end user info */
        
        
         /* menu info */
     addMenuMutation:(state,data)=>(state.posMenu.unshift(data.response)),
     getPosMenuMutation:(state,data)=>(state.posMenu = data),
     editPosMenuMutation:(state,data)=>(state.editPosMenuList = data),
     updateMenuMutation:(state,data)=>(state.editPosMenuList = data),
     removeMenu:(state,data)=>(state.posMenu.filter(fil => fil.id != data.data.id)),
     instantMenuMutation:(state,data)=>(state.editPosMenuList = data),
        /* end menu info */
        
        
         /* role menu  permission */
    
     getPosRoleMenuMutation:(state,data)=>(state.posRoleMenu = data),
     
    
        /* end role menu permission */
    
    

};


const actions = {
    
    /* company api */
   async addCompany({commit,dispatch},conpanyData){
        const response = await axios.post(configManual.sitePath+"/api/company_insert",conpanyData);
                 
                let group ='message1';
                let type ='';
                let message ='';
		if(response.data.status=='no_unique'){
                    type ='error';
                    message ='Data not unique';	
		}else if(response.data.status=='fail'){
                     type ='error';
                    message ='Data insert fail'; 
                }else if(response.data.status=='success'){
                      type ='success';
                    message ='Data insert successful'; 
                }
                const messageData = {
                    group:group,
                    type:type,
                    message:message
                };

               dispatch('addNotification',messageData,{root:true});
               commit("addComMutation",{response:response.data});

       
    },
     async getPosCompanyFilterList({commit},filterData){
        const response = await axios.post(configManual.sitePath+"/api/company_filter",filterData);
        commit("getPosCompanyMutation",response.data);
    },
     async editPosCompany({commit,dispatch},data){
        console.log("checl edit "+data.id);
        const response = await axios.get(configManual.sitePath+"/api/company_edit/"+data.id+"");
                let group ='message1';
                let type ='';
                let message ='';
		if(response.data.status =='fail'){
                    type ='error';
                    message ='Data edit fail';	
                     dispatch('addNotification',{ 
                          group:group,
                           type:type,
                           message:message
                       });
		}
             
                
           commit("editPosCompanyMutation",response.data);
        
    },
    async updateCompany({commit,dispatch},conpanyData){
        const response = await axios.post(configManual.sitePath+"/api/company_update",conpanyData);
                 
                let group ='message1';
                let type ='';
                let message ='';
		if(response.data.status=='no_unique'){
                    type ='error';
                    message ='Data not unique';	
		}else if(response.data.status=='fail'){
                     type ='error';
                    message ='Data insert fail'; 
                }else if(response.data.status=='success'){
                      type ='success';
                    message ='Data update successful'; 
                }
                const messageData = {
                    group:group,
                    type:type,
                    message:message
                };

               dispatch('addNotification',messageData,{root:true});
               commit("updateCompanyMutation",{response:response.data});

       
    },
    async deleteCom({commit},data){
       const response = await axios.post(configManual.sitePath+"/api/company_del",data);
       commit("removeCompany",{data:data,response:response.data}); 
       
    },
       /* end company api */
       
       
       
        /* category api */
   async addCategory({commit,dispatch},conpanyData){
        const response = await axios.post(configManual.sitePath+"/api/category_insert",conpanyData);
                 
                let group ='message1';
                let type ='';
                let message ='';
		if(response.data.status=='no_unique'){
                    type ='error';
                    message ='Data not unique';	
		}else if(response.data.status=='fail'){
                     type ='error';
                    message ='Data insert fail'; 
                }else if(response.data.status=='success'){
                      type ='success';
                    message ='Data update successful'; 
                }
               
               if(type !=''){
                  dispatch('addNotification',
                  {
                    group:group,
                    type:type,
                    message:message
                  },
                  {root:true}
                  );  
               }
              
               commit("addCategoryMutation",{response:response.data});

       
    },
     async getPosCategoryFilterList({commit},filterData){
        const response = await axios.post(configManual.sitePath+"/api/category_filter",filterData);
        commit("getPosCategoryMutation",response.data);
    },
     async editPosCategory({commit,dispatch},data){
        const response = await axios.get(configManual.sitePath+"/api/category_edit/"+data.id+"");
                let group ='message1';
                let type ='';
                let message ='';
		if(response.data.status =='fail'){
                    type ='error';
                    message ='Data edit fail';	
		} 
             if(type !=''){
                  dispatch('addNotification',
                    {
                    group:group,
                    type:type,
                    message:message
                   },
                   {root:true}
                   ); 
             }
          
           commit("editPosCategoryMutation",response.data);
        
    },
     async updateCategory({commit,dispatch},conpanyData){
        const response = await axios.post(configManual.sitePath+"/api/category_update",conpanyData);
                 
                let group ='message1';
                let type ='';
                let message ='';
		if(response.data.status=='no_unique'){
                    type ='error';
                    message ='Data not unique';	
		}else if(response.data.status=='fail'){
                     type ='error';
                    message ='Data insert fail'; 
                }else if(response.data.status=='success'){
                      type ='success';
                    message ='Data update successful'; 
                }
                const messageData = {
                    group:group,
                    type:type,
                    message:message
                };

               dispatch('addNotification',messageData,{root:true});
               commit("updateCategoryMutation",{response:response.data});

       
    },
    async deleteCategory({commit,dispatch},data){
       const response = await axios.post(configManual.sitePath+"/api/category_del",data);
       
                let group ='message1';
                let type ='';
                let message ='';
		if(response.data.status =='no_record_found'){
                    type ='error';
                    message ='No record found';	
		}else if(response.data.status =='success'){
                    type ='success';
                    message ='deletion successful';	 
                } 
                
             if(type !=''){
                  dispatch('addNotification',
                    {
                    group:group,
                    type:type,
                    message:message
                     },
                    {root:true}
                  ); 
             }
           commit("removeCategory",{data:data,response:response.data}); 
       
    },
       /* end category api */
       
       
        /* unit api */
   async addUnit({commit,dispatch},conpanyData){
        const response = await axios.post(configManual.sitePath+"/api/unit_insert",conpanyData);
                 
                let group ='message1';
                let type ='';
                let message ='';
		if(response.data.status=='no_unique'){
                    type ='error';
                    message ='Data not unique';	
		}else if(response.data.status=='fail'){
                     type ='error';
                    message ='Data insert fail'; 
                }else if(response.data.status=='success'){
                      type ='success';
                    message ='Data insert successful'; 
                }
               
               if(type !=''){
                  dispatch('addNotification',
                  {
                    group:group,
                    type:type,
                    message:message
                  },
                  {root:true}
                  );  
               }
              
               commit("addUnitMutation",{response:response.data});

       
    },
     async getPosUnitFilterList({commit},filterData){
        const response = await axios.post(configManual.sitePath+"/api/unit_filter",filterData);
        commit("getPosUnitMutation",response.data);
    },
     async editPosUnit({commit,dispatch},data){
        const response = await axios.get(configManual.sitePath+"/api/unit_edit/"+data.id+"");
                let group ='message1';
                let type ='';
                let message ='';
		if(response.data.status =='fail'){
                    type ='error';
                    message ='Data edit fail';	
		} 
             if(type !=''){
                  dispatch('addNotification',
                    {
                    group:group,
                    type:type,
                    message:message
                   },
                   {root:true}
                   ); 
             }
          
           commit("editPosUnitMutation",response.data);
        
    },
     async updateUnit({commit,dispatch},conpanyData){
        const response = await axios.post(configManual.sitePath+"/api/unit_update",conpanyData);
                 
                let group ='message1';
                let type ='';
                let message ='';
		if(response.data.status=='no_unique'){
                    type ='error';
                    message ='Data not unique';	
		}else if(response.data.status=='fail'){
                     type ='error';
                    message ='Data insert fail'; 
                }else if(response.data.status=='success'){
                      type ='success';
                    message ='Data update successful'; 
                }
                const messageData = {
                    group:group,
                    type:type,
                    message:message
                };

               dispatch('addNotification',messageData,{root:true});
               commit("updateUnitMutation",{response:response.data});

       
    },
    async deleteUnit({commit,dispatch},data){
       const response = await axios.post(configManual.sitePath+"/api/unit_del",data);
       
                let group ='message1';
                let type ='';
                let message ='';
		if(response.data.status =='no_record_found'){
                    type ='error';
                    message ='No record found';	
		}else if(response.data.status =='success'){
                    type ='success';
                    message ='deletion successful';	 
                } 
                
             if(type){
                  dispatch('addNotification',
                    {
                    group:group,
                    type:type,
                    message:message
                     },
                    {root:true}
                  ); 
             }
           commit("removeUnit",{data:data,response:response.data}); 
       
    },
       /* end unit api */
       
       
       
        /* role api */
   async addRole({commit,dispatch},data){
        const response = await axios.post(configManual.sitePath+"/api/role_insert",data);
                 
                let group ='message1';
                let type ='';
                let message ='';
		if(response.data.status=='no_unique'){
                    type ='error';
                    message ='Data not unique';	
		}else if(response.data.status=='fail'){
                     type ='error';
                    message ='Data insert fail'; 
                }else if(response.data.status=='success'){
                      type ='success';
                    message ='Data insert successful'; 
                }
               
               if(type !=''){
                  dispatch('addNotification',
                  {
                    group:group,
                    type:type,
                    message:message
                  },
                  {root:true}
                  );  
               }
              
               commit("addRoleMutation",{response:response.data});

       
    },
     async getPosRoleFilterList({commit},filterData){
        const response = await axios.post(configManual.sitePath+"/api/role_filter",filterData);
        commit("getPosRoleMutation",response.data);
    },
     async editPosRole({commit,dispatch},data){
        const response = await axios.get(configManual.sitePath+"/api/role_edit/"+data.id+"");
                let group ='message1';
                let type ='';
                let message ='';
		if(response.data.status =='fail'){
                    type ='error';
                    message ='Data edit fail';	
		} 
             if(type !=''){
                  dispatch('addNotification',
                    {
                    group:group,
                    type:type,
                    message:message
                   },
                   {root:true}
                   ); 
             }
          
           commit("editPosRoleMutation",response.data);
        
    },
     async updateRole({commit,dispatch},data){
        const response = await axios.post(configManual.sitePath+"/api/role_update",data);
                 
                let group ='message1';
                let type ='';
                let message ='';
		if(response.data.status=='no_unique'){
                    type ='error';
                    message ='Data not unique';	
		}else if(response.data.status=='fail'){
                     type ='error';
                    message ='Data insert fail'; 
                }else if(response.data.status=='success'){
                      type ='success';
                    message ='Data update successful'; 
                }
                const messageData = {
                    group:group,
                    type:type,
                    message:message
                };

               dispatch('addNotification',messageData,{root:true});
               commit("updateRoleMutation",{response:response.data});

       
    },
    async deleteRole({commit,dispatch},data){
       const response = await axios.post(configManual.sitePath+"/api/role_del",data);
       
                let group ='message1';
                let type ='';
                let message ='';
		if(response.data.status =='no_record_found'){
                    type ='error';
                    message ='No record found';	
		}else if(response.data.status =='success'){
                    type ='success';
                    message ='deletion successful';	 
                } 
                
             if(type){
                  dispatch('addNotification',
                    {
                    group:group,
                    type:type,
                    message:message
                     },
                    {root:true}
                  ); 
             }
           commit("removeRole",{data:data,response:response.data}); 
       
    },
       /* end role api */
       
       
       /* user api */
   async addUser({commit,dispatch},data){
      
       const config = {
                    headers: {
                        'content-type': 'multipart/form-data',
                        'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').content
                      }
                    };
        const response = await axios.post(configManual.sitePath+"/api/user_insert",data,config);
                
                let group ='message1';
                let type ='';
                let message ='';
		if(response.data.status=='no_unique'){
                    type ='error';
                    message ='Data not unique';	
		}else if(response.data.status=='fail'){
                     type ='error';
                    message ='Data insert fail'; 
                }else if(response.data.status=='success'){
                      type ='success';
                    message ='Data insert successful'; 
                }
               
               if(type){
                  dispatch('addNotification',
                  {
                    group:group,
                    type:type,
                    message:message
                  },
                  {root:true}
                  );  
               }
              
               commit("addItemMutation",response.data);

       
    },
     async getPosUserFilterList({commit},filterData){
        const response = await axios.post(configManual.sitePath+"/api/user_filter",filterData);
        commit("getPosUserMutation",response.data);
    },
     async editPosUser({commit,dispatch},data){
        const response = await axios.get(configManual.sitePath+"/api/user_edit/"+data.id+"");
                let group ='message1';
                let type ='';
                let message ='';
		if(response.data.status =='fail'){
                    type ='error';
                    message ='Data edit fail';	
		} 
             if(type !=''){
                  dispatch('addNotification',
                    {
                    group:group,
                    type:type,
                    message:message
                   },
                   {root:true}
                   ); 
             }
          
           commit("editPosUserMutation",response.data);
        
    },
     async updateUser({commit,dispatch},data){
         
          const config = {
                    headers: {
                        'content-type': 'multipart/form-data',
                        'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').content
                      }
                    };
        const response = await axios.post(configManual.sitePath+"/api/user_update",data,config);
                 
                let group ='message1';
                let type ='';
                let message ='';
		if(response.data.status=='no_unique'){
                    type ='error';
                    message ='Data not unique';	
		}else if(response.data.status=='fail'){
                     type ='error';
                    message ='Data insert fail'; 
                }else if(response.data.status=='success'){
                      type ='success';
                    message ='Data update successful'; 
                }
                const messageData = {
                    group:group,
                    type:type,
                    message:message
                };

               dispatch('addNotification',messageData,{root:true});
               commit("updateItemMutation",response.data);

       
    },
    async deleteUser({commit,dispatch},data){
       const response = await axios.post(configManual.sitePath+"/api/user_del",data);
       
                let group ='message1';
                let type ='';
                let message ='';
		if(response.data.status =='no_record_found'){
                    type ='error';
                    message ='No record found';	
		}else if(response.data.status =='success'){
                    type ='success';
                    message ='Deletion successful';	 
                } 
                
             if(type){
                  dispatch('addNotification',
                    {
                    group:group,
                    type:type,
                    message:message
                     },
                    {root:true}
                  ); 
             }
           commit("removeUser",data); 
       
    },

    /* end user api */
    
    
    
     /* menu api */
   async addMenu({commit,dispatch},data){
        const response = await axios.post(configManual.sitePath+"/api/menu_insert",data);
                 
                let group ='message1';
                let type ='';
                let message ='';
		if(response.data.status=='no_unique'){
                    type ='error';
                    message ='Data not unique';	
		}else if(response.data.status=='fail'){
                     type ='error';
                    message ='Data insert fail'; 
                }else if(response.data.status=='success'){
                      type ='success';
                    message ='Data insert successful'; 
                }
               
               if(type !=''){
                  dispatch('addNotification',
                  {
                    group:group,
                    type:type,
                    message:message
                  },
                  {root:true}
                  );  
               }
              
               commit("addMenuMutation",{response:response.data});

       
    },
     async getPosMenuFilterList({commit},filterData){
        const response = await axios.post(configManual.sitePath+"/api/menu_filter",filterData);
        commit("getPosMenuMutation",response.data);
    },
     async editPosMenu({commit,dispatch},data){
        const response = await axios.get(configManual.sitePath+"/api/menu_edit/"+data.id+"");
                let group ='message1';
                let type ='';
                let message ='';
		if(response.data.status =='fail'){
                    type ='error';
                    message ='Data edit fail';	
		} 
             if(type !=''){
                  dispatch('addNotification',
                    {
                    group:group,
                    type:type,
                    message:message
                   },
                   {root:true}
                   ); 
             }
          
           commit("editPosMenuMutation",response.data);
        
    },
     async updateMenu({commit,dispatch},data){
        const response = await axios.post(configManual.sitePath+"/api/menu_update",data);
                 
                let group ='message1';
                let type ='';
                let message ='';
		if(response.data.status=='no_unique'){
                    type ='error';
                    message ='Data not unique';	
		}else if(response.data.status=='fail'){
                     type ='error';
                    message ='Data insert fail'; 
                }else if(response.data.status=='success'){
                      type ='success';
                    message ='Data update successful'; 
                }
                const messageData = {
                    group:group,
                    type:type,
                    message:message
                };

               dispatch('addNotification',messageData,{root:true});
               commit("updateMenuMutation",{response:response.data});

       
    },
    async deleteMenu({commit,dispatch},data){
       const response = await axios.post(configManual.sitePath+"/api/menu_del",data);
       
                let group ='message1';
                let type ='';
                let message ='';
		if(response.data.status =='no_record_found'){
                    type ='error';
                    message ='No record found';	
		}else if(response.data.status =='success'){
                    type ='success';
                    message ='deletion successful';	 
                } 
                
             if(type){
                  dispatch('addNotification',
                    {
                    group:group,
                    type:type,
                    message:message
                     },
                    {root:true}
                  ); 
             }
           commit("removeMenu",{data:data,response:response.data}); 
       
    },
    
    async instantMenu({commit,dispatch},data){
        const response = await axios.post(configManual.sitePath+"/api/menu_instant",data);
             //alert(response.data.menu_name);
        commit("instantMenuMutation",response.data);

       
    },
       /* end menu api */
       
       
   /* role menu permission */
   
    async getPosRoleMenuFilterList({commit},filterData){
        const response = await axios.post(configManual.sitePath+"/api/role_menu_filter",filterData);
        commit("getPosRoleMenuMutation",response.data);
    },
    
    async updateRoleMenu({commit,dispatch},data){
        const response = await axios.post(configManual.sitePath+"/api/role_menu_update",data);
                 
                let group ='message1';
                let type ='';
                let message ='';
		if(response.data.status=='fail'){
                     type ='error';
                    message ='Data insert fail'; 
                }else if(response.data.status=='success'){
                      type ='success';
                    message ='Data update successful'; 
                }
                const messageData = {
                    group:group,
                    type:type,
                    message:message
                };

               dispatch('addNotification',messageData,{root:true});

    },
   
   /* role menu permission */
       
   
   
};

export default {
    state,
    getters,
    mutations,
    actions
}

create a file notificationMessage.js in the location resources\js\store\modules\ and add the following code


import axios from "axios";

const getters = {
   getNotifications:state =>state.notifications
  
};

const state = {
     notifications:null,
};

const mutations = {
     push_notification:(state,messageData)=>(state.notifications = messageData),
     remove_notification:(state)=>(state.notifications = null),
};


const actions = {
    async addNotification({commit},message){
       commit("push_notification",message); 
    }
};

export default {
    state,
    getters,
    mutations,
    actions
}

Import index.js in the location resources\js\app.js

import store from "../js/store/index";

add the following code in the laravel project location:posmaster\routes\api.php



use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use App\Auth\Role;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::middleware('auth:api')->get('/user', function (Request $request) {
    return $request->user();
});


// api
Route::get('getuser','Json\ApiController@getUser'); 
//Route::post('vlogin','Json\ApiController@loginUser'); 
Route::post('logincheck','Json\ApiController@loginUser'); 

/* company api */
Route::post('company_insert','Json\ApiController@company_insert');
Route::post('company_filter','Json\ApiController@company_filter');
Route::get('company_edit/{id}','Json\ApiController@company_edit'); 
Route::post('company_update','Json\ApiController@company_update'); 
Route::post('company_del','Json\ApiController@company_del');
Route::get('company_list','Json\ApiController@company_list');
/* company api */

/* category api */
Route::post('category_insert','Json\ApiController@category_insert'); 
Route::post('category_filter','Json\ApiController@category_filter');
Route::get('category_edit/{id}','Json\ApiController@category_edit'); 
Route::post('category_update','Json\ApiController@category_update'); 
Route::post('category_del','Json\ApiController@category_del');
/* category api */


/* unit api */
Route::post('unit_insert','Json\ApiController@unit_insert'); 
Route::post('unit_filter','Json\ApiController@unit_filter');
Route::get('unit_edit/{id}','Json\ApiController@unit_edit'); 
Route::post('unit_update','Json\ApiController@unit_update'); 
Route::post('unit_del','Json\ApiController@unit_del');
/* unit api */


/* item api */

Route::post('item_insert','Json\ApiController@item_insert'); 
Route::post('item_filter','Json\ApiController@item_filter');
Route::get('item_edit/{id}','Json\ApiController@item_edit'); 
Route::post('item_update','Json\ApiController@item_update'); 
Route::post('item_del','Json\ApiController@item_del');
Route::get('item_last_code','Json\ApiController@item_last_code');
Route::post('productUpload','Json\ApiController@productUpload');

/* unit api */



/* role api */
Route::post('role_insert','Json\ApiController@role_insert'); 
Route::post('role_filter','Json\ApiController@role_filter');
Route::get('role_edit/{id}','Json\ApiController@role_edit'); 
Route::post('role_update','Json\ApiController@role_update'); 
Route::post('role_del','Json\ApiController@role_del');
/* role api */


/* user api */

Route::post('user_insert','Json\ApiController@user_insert'); 
Route::post('user_filter','Json\ApiController@user_filter');
Route::get('user_edit/{id}','Json\ApiController@user_edit'); 
Route::post('user_update','Json\ApiController@user_update'); 
Route::post('user_del','Json\ApiController@user_del');

/* user api */


/* menu api */
Route::post('menu_insert','Json\ApiController@menu_insert'); 
Route::post('menu_filter','Json\ApiController@menu_filter');
Route::get('menu_edit/{id}','Json\ApiController@menu_edit'); 
Route::post('menu_update','Json\ApiController@menu_update'); 
Route::post('menu_del','Json\ApiController@menu_del');
Route::post('menu_instant','Json\ApiController@menu_instant');
/* menu api */


/* role menu api */

Route::post('role_menu_filter','Json\ApiController@role_menu_filter');
Route::post('role_menu_update','Json\ApiController@role_menu_update');

/* role menu api */

/* user menu api */
  Route::post('user_menu','Json\ApiController@getUserMenu');
/* end user menu api */
  
  
/* inv customer api */
Route::post('customer_insert','Json\ApiController@customer_insert'); 
Route::post('customer_filter','Json\ApiController@customer_filter');
Route::get('customer_edit/{id}','Json\ApiController@customer_edit'); 
Route::post('customer_update','Json\ApiController@customer_update'); 
Route::post('customer_del','Json\ApiController@customer_del');
/* inv customer api */


/* inv supplier api */
Route::post('supplier_insert','Json\ApiController@supplier_insert'); 
Route::post('supplier_filter','Json\ApiController@supplier_filter');
Route::get('supplier_edit/{id}','Json\ApiController@supplier_edit'); 
Route::post('supplier_update','Json\ApiController@supplier_update'); 
Route::post('supplier_del','Json\ApiController@supplier_del');
/* inv supplier api */

Route::get('testapi','Json\ApiController@testapi');



add the following code in the laravel project location:posmaster\app\Http\Controllers\Json\ApiController.php

<?php namespace App\Http\Controllers\Json;

use App\Http\Requests;
use App\Http\Controllers\Controller;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;

use Carbon\Carbon;
use Session;
use DB;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Input;
use App\Models\Auth\Role;

use App\Services\Web\WebServices;
use Illuminate\Support\Facades\File;

use App\User;
use App\Models\Admin\AdminCompany;
use App\Models\Admin\AdminMenu;
use App\Models\Admin\AdminRoleMenuPermission;
use App\Models\Admin\AdminRole;

use App\Models\Inventory\InvCategory;
use App\Models\Inventory\InvUnit;
use App\Models\Inventory\InvItem;
use App\Models\Inventory\InvCustomer;
use App\Models\Inventory\InvSupplier;







class ApiController extends Controller {
    
    public static $BAG_ITEMS="";
    

     public function __construct()
     {
           
     }
    
    
    public function getUser(Request $request){
         
         //$userId = $request->user_id;
          $userId =35;
         
         $userRoleData = array();
         
         $userIns = User::orderBy('admin_user.id','desc')
                   ->where('admin_user.id',$userId)
                   ->first()->toArray();
         
         if($userIns){
              $role = Role::orderBy('roles.role_name','asc')
                      ->select('roles.*')
                      ->join('user_roles','user_roles.role_id','=','roles.id')
                      ->where('user_roles.user_id',$userId)
                      ->get()->toArray();
              
         $userRoleData = array_merge($userIns,['roles'=>$role]);
         }
         
         if($userIns){
            return response()->json($userRoleData);    
         }else{
             return response()->json([]);  
         }
   
    }
    
   

    
     public function loginUser(Request $request){
         
         $userRoleData = array();
         $userInstance = null;
         $credentials = null;
         
         
         if($request->input('email') !=''){
               $userInstance = User::where('email',trim($request->input('email')))->first(); 
               if($userInstance){
                     
                    $credentials = $request->only('email', 'password'); 
                 }
         }else if($request->input('mobile') !=''){
                $userInstance = User::where('mobile',trim($request->input('mobile')))->first(); 
                
                if($userInstance){
                     
                    $credentials = $request->only('mobile', 'password'); 
                 }
         }
   

        
         if($userInstance ){
                    if($userInstance && Auth::attempt($credentials)){

                          $rolemenuPermission = AdminRoleMenuPermission::orderBy('admin_role_menu_permission.id','asc')
                                  ->select(
                                           'admin_menu.id as menu_id',
                                           'admin_role_menu_permission.id as role_menu_permission_id',
                                           'admin_menu.menu_name',
                                           'admin_menu.route_path',
                                           'admin_menu.route_name',
                                           'admin_role_menu_permission.is_insert',
                                           'admin_role_menu_permission.is_edit',
                                           'admin_role_menu_permission.is_view',
                                           'admin_role_menu_permission.is_delete'
                                          )
                                  ->join('admin_menu','admin_menu.id','=','admin_role_menu_permission.menu_id')
                                  ->where('admin_role_menu_permission.role_id',@$userInstance->role_id)
                                  ->get()->toArray();


                              foreach($rolemenuPermission as $rolemenuPermi){
                                  $menuPermissionData[$rolemenuPermi['route_name']] = $rolemenuPermi;
                              }

                              $userRoleMenuData = array_merge($userInstance->toArray(),['access_by_company_id'=>$userInstance->company_id],['menu'=>$menuPermissionData]);

                              return response()->json($userRoleMenuData);  
               }else{
                   return response()->json(['status'=>'fail']);  
               }  
         
        }else{
           return response()->json(['status'=>'mismatch']);  
        }

    }
    
    /*  company api */
    public function company_insert(Request $request){
        
       
        $insert = null;
        
         $checkUnique = null;
           
         $checkUnique = AdminCompany::where('name',$request->input('name'))->orWhere('short_name',$request->input('short_name'))->first();
         
          if($request->input('name') && $request->input('short_name')){
              
                if(! @$checkUnique->id){
                    
                              $companyIns = new AdminCompany();
                              $companyIns->name = $request->input('name');
                              $companyIns->short_name = $request->input('short_name');
                              $companyIns->is_active = $request->input('is_active');
                              $companyIns->create_date = Carbon::now();
                              $companyIns->create_by = $request->input('create_by'); 

                              $insert = $companyIns->save();
                              
                                if($insert){
                                    return response()->json(['status'=>'success']);   
                                }else{
                                    return response()->json(['status'=>'fail']);  
                                }


                }else{
                   return response()->json(['status'=>'no_unique']);  
                }
        
          } 
          
         
        
        
    }
    
     public function company_edit(Request $request){
        
        $update = null;
        $id = @$request->route()->parameter('id');
        if($id){
            
              $companyIns = AdminCompany::orderBy('admin_company_info.create_date','desc')
                               ->select('admin_company_info.*','admin_user.full_name as create_by_name')
                               ->leftJoin('admin_user','admin_user.id','=','admin_company_info.create_by')
                               ->where('admin_company_info.id',$id)
                               ->first();
              
               if($companyIns){
                    return response()->json($companyIns);   
                }else{
                     return response()->json(['status'=>'fail']);  
                }

        }
   
    }
    
    public function company_update(Request $request){
        
        $update = null;
        if($request->input('id')){
            
            $checkUnique = null;
            $checkUnique = AdminCompany::where('name',$request->input('name'))->where('short_name',$request->input('short_name'))->where('id','!=',$request->input('id'))->first();
             
            if(! @$checkUnique->id){
                
                  $companyIns = AdminCompany::where('id',$request->input('id'))->first(); 
            
                    if($companyIns){

                          $companyIns->name = $request->input('name');
                          $companyIns->short_name = $request->input('short_name');
                          $companyIns->is_active = $request->input('is_active');
                          $companyIns->update_date = Carbon::now();
                          $companyIns->update_by = $request->input('update_by'); 

                          $update = $companyIns->save();

                          if($update){
                              return response()->json(['status'=>'success']);   
                           }else{
                               return response()->json(['status'=>'fail']);  
                           }

                    }else{
                        return response()->json(['status'=>'no_data']);  
                    }
                
            }else{
                return response()->json(['status'=>'no_unique']); 
            }
           
          
           
        }
   
    }
    
     public function company_list(Request $request){
         
          $companyList = AdminCompany::orderBy('create_date','desc')->where('is_active',1)->limit(500)->get(); 
          
          if($companyList){
               return response()->json($companyList);   
          }else{
              return response()->json(['status'=>'no table record found']);   
          }
     }
     
     public function company_filter(Request $request){
          
           $name = ($request->input('name'))? trim($request->input('name')):null;
           $short_name = ($request->input('short_name'))? trim($request->input('short_name')):null;
           $is_active = ($request->input('is_active'))? $request->input('is_active'):null;

          if($name || $short_name || $is_active){
               
                    $companyList = AdminCompany::orderBy('admin_company_info.create_date','desc')
                                               ->select('admin_company_info.*','admin_user.full_name as create_by_name')
                                               ->leftJoin('admin_user','admin_user.id','=','admin_company_info.create_by')
                                               ->where(function($search) use($name,$short_name,$is_active){
                                                   if($name){
                                                      $search->where('admin_company_info.name','like', $name.'%');
                                                      //$search->where('name','=',$name);
                                                   }
                                                   if($short_name){
                                                      $search->where('admin_company_info.short_name','like', $short_name.'%');
                                                   }
                                                   if($is_active=='yes'){
                                                      $search->where('admin_company_info.is_active','=', 1);
                                                   }else if($is_active=='no'){
                                                        $search->where('admin_company_info.is_active','=', 0);
                                                   }else{
                                                       $search->where('admin_company_info.is_active','=', 1); 
                                                   }
                                               })
                                               ->limit(500)
                                               ->get(); 
           }else{
               $companyList = AdminCompany::orderBy('admin_company_info.create_date','desc')
                               ->select('admin_company_info.*','admin_user.full_name as create_by_name')
                               ->leftJoin('admin_user','admin_user.id','=','admin_company_info.create_by')
                               ->where('admin_company_info.is_active',1)
                               ->limit(500)
                              ->get();  
           }
 
          if($companyList){
               return response()->json($companyList);   
          }else{
              return response()->json(['status'=>'no_data']);   
          }
     }

      public function company_del(Request $request){
          
          if($request->input('id')){
                  $companyList = AdminCompany::where("id",$request->input('id'))->first(); 
                    if($companyList){
                        $companyList->is_active = 0;
                        $companyList->save();
                        return response()->json(['status'=>'success']);

                    }else{
                        return response()->json(['status'=>'no_record_found']);  
                    }
              
          }  
      }
      
       /*  end company api */
      
      
      /* category api */
       
    public function category_insert(Request $request){
        
       
        $insert = null;
        
         $checkUnique = null;
           
         $checkUnique = InvCategory::where('category_name',$request->input('category_name'))->where('short_name',$request->input('short_name'))->where('company_id',$request->input('company_id'))->first();
         
          if($request->input('category_name') && $request->input('short_name')){
              
                if(! @$checkUnique->id){
                    
                              $categoryIns = new InvCategory();
                              $categoryIns->category_name = $request->input('category_name');
                              $categoryIns->short_name = $request->input('short_name');
                              $categoryIns->is_active = $request->input('is_active');
                              $categoryIns->create_date = Carbon::now();
                              $categoryIns->create_by = $request->input('create_by'); 
                              $categoryIns->company_id = $request->input('company_id'); 
                              $categoryIns->vat_percent =  ($request->input('vat_percent'))? $request->input('vat_percent'):0; 
                              $categoryIns->scharge_percent= ($request->input('scharge_percent'))? $request->input('scharge_percent'):0; 
                              $categoryIns->code_ref = $request->input('code_ref'); 

                              $insert = $categoryIns->save();
                              
                                if($insert){
                                    return response()->json(['status'=>'success']);   
                                }else{
                                    return response()->json(['status'=>'fail']);  
                                }


                }else{
                   return response()->json(['status'=>'no_unique']);  
                }
        
          } 
          
         
        
        
    }
    
     public function category_edit(Request $request){
        
        $update = null;
        $id = @$request->route()->parameter('id');
        if($id){
              $categoryIns = InvCategory::orderBy('inv_item_category.create_date','desc')
                               ->select('inv_item_category.*','admin_user.full_name as create_by_name','admin_company_info.name as company_name','admin_company_info.short_name as company_short_name')
                               ->leftJoin('admin_user','admin_user.id','=','inv_item_category.create_by')
                                ->join('admin_company_info','admin_company_info.id','=','inv_item_category.company_id')
                                ->where('inv_item_category.id',$id)
                                ->first();
              
               if($categoryIns){
                    return response()->json($categoryIns);   
                }else{
                     return response()->json(['status'=>'fail']);  
                }

        }
   
    }
    
    public function category_update(Request $request){
        
        $update = null;
        if($request->input('id')){
            
            $checkUnique = null;
            $checkUnique = InvCategory::where('category_name',$request->input('category_name'))->where('short_name',$request->input('short_name'))->where('company_id',$request->input('company_id'))->where('id','!=',$request->input('id'))->first();
             
            if(! @$checkUnique->id){
                
                  $categoryIns = InvCategory::where('id',$request->input('id'))->first(); 
            
                    if($categoryIns){

                          $categoryIns->category_name = $request->input('category_name');
                          $categoryIns->short_name = $request->input('short_name');
                          $categoryIns->is_active = $request->input('is_active');
                          $categoryIns->update_date = Carbon::now();
                          $categoryIns->update_by = $request->input('update_by'); 
                          $categoryIns->company_id = $request->input('company_id');
                          $categoryIns->vat_percent =  ($request->input('vat_percent'))? $request->input('vat_percent'):0; 
                          $categoryIns->scharge_percent= ($request->input('scharge_percent'))? $request->input('scharge_percent'):0; 
                          $categoryIns->code_ref = $request->input('code_ref'); 

                          $update = $categoryIns->save();

                          if($update){
                              return response()->json(['status'=>'success']);   
                           }else{
                               return response()->json(['status'=>'fail']);  
                           }

                    }else{
                        return response()->json(['status'=>'no_data']);  
                    }
                
            }else{
                return response()->json(['status'=>'no_unique']); 
            }
           
          
           
        }
   
    }
    
     public function category_list(Request $request){
         
          $categoryList = InvCategory::orderBy('create_date','desc')->where('is_active',1)->limit(500)->get(); 
          
          if($categoryList){
               return response()->json($categoryList);   
          }else{
              return response()->json(['status'=>'no table record found']);   
          }
     }
     
     public function category_filter(Request $request){
          
           $category_name = ($request->input('category_name'))? trim($request->input('category_name')):null;
           $short_name = ($request->input('short_name'))? trim($request->input('short_name')):null;
           $is_active = ($request->input('is_active'))? $request->input('is_active'):null;
           $company_id = ($request->input('company_id'))? $request->input('company_id'):null;

          if($category_name || $short_name || $is_active || $company_id){
               
                    $categoryList = InvCategory::orderBy('inv_item_category.create_date','desc')
                                               ->select('inv_item_category.*','admin_user.full_name as create_by_name','admin_company_info.name as company_name','admin_company_info.short_name as company_short_name')
                                               ->leftJoin('admin_user','admin_user.id','=','inv_item_category.create_by')
                                               ->join('admin_company_info','admin_company_info.id','=','inv_item_category.company_id')
                                               ->where(function($search) use($category_name,$short_name,$is_active,$company_id){
                                                   if($category_name){
                                                      $search->where('inv_item_category.category_name','like', $category_name.'%');
                                                   }
                                                   if($short_name){
                                                      $search->where('inv_item_category.short_name','like', $short_name.'%');
                                                   }
                                                   if($is_active=='yes'){
                                                      $search->where('inv_item_category.is_active','=', 1);
                                                   }else if($is_active=='no'){
                                                       $search->where('inv_item_category.is_active','=', 0); 
                                                   }else{
                                                       $search->where('inv_item_category.is_active','=', 1);  
                                                   }
                                                    if($company_id){
                                                      $search->where('inv_item_category.company_id','=', $company_id);
                                                   }
                                               })
                                               ->limit(500)
                                               ->get(); 
           }else{
               $categoryList = InvCategory::orderBy('inv_item_category.create_date','desc')
                               ->select('inv_item_category.*','admin_user.full_name as create_by_name','admin_company_info.name as company_name','admin_company_info.short_name as company_short_name')
                               ->leftJoin('admin_user','admin_user.id','=','inv_item_category.create_by')
                                ->join('admin_company_info','admin_company_info.id','=','inv_item_category.company_id')
                               ->where('inv_item_category.is_active',1)
                               ->limit(500)
                              ->get();  
           }
 
          if($categoryList){
               return response()->json($categoryList);   
          }else{
              return response()->json(['status'=>'no_data']);   
          }
     }

      public function category_del(Request $request){
          
          if($request->input('id')){
                  $categoryList = InvCategory::where("id",$request->input('id'))->first(); 
                    if($categoryList){
                        $categoryList->is_active = 0;
                        $categoryList->save();
                        return response()->json(['status'=>'success']);

                    }else{
                        return response()->json(['status'=>'no_record_found']);  
                    }
              
          }  
      }

       /* end category api */
      
      
      
      /* unit api */
      
         public function unit_insert(Request $request){
        
       
         $insert = null;
        
         $checkUnique = null;
           
         $checkUnique = InvUnit::where('unit_name',$request->input('unit_name'))->where('short_name',$request->input('short_name'))->where('company_id',$request->input('company_id'))->first();
         
         if($request->input('unit_name') && $request->input('short_name')){
              
                if(! @$checkUnique->id){
                    
                              $unitIns = new InvUnit();
                              $unitIns->unit_name = $request->input('unit_name');
                              $unitIns->short_name = $request->input('short_name');
                              $unitIns->is_active = $request->input('is_active');
                              $unitIns->create_date = Carbon::now();
                              $unitIns->create_by = $request->input('create_by'); 
                              $unitIns->company_id = $request->input('company_id');

                              $insert = $unitIns->save();
                              
                                if($insert){
                                    return response()->json(['status'=>'success']);   
                                }else{
                                    return response()->json(['status'=>'fail']);  
                                }


                }else{
                   return response()->json(['status'=>'no_unique']);  
                }
        
          } 
          
         
        
        
    }
    
     public function unit_edit(Request $request){
        
        $update = null;
        $id = @$request->route()->parameter('id');
        if($id){
            
              $unitIns = InvUnit::orderBy('inv_item_unit.create_date','desc')
                               ->select('inv_item_unit.*','admin_user.full_name as create_by_name')
                               ->leftJoin('admin_user','admin_user.id','=','inv_item_unit.create_by')
                               ->where('inv_item_unit.id',$id)
                               ->first();
              
               if($unitIns){
                    return response()->json($unitIns);   
                }else{
                     return response()->json(['status'=>'fail']);  
                }

        }
   
    }
    
    public function unit_update(Request $request){
        
        $update = null;
        if($request->input('id')){
            
            $checkUnique = null;
            $checkUnique = InvUnit::where('unit_name',$request->input('unit_name'))->where('short_name',$request->input('short_name'))->where('company_id',$request->input('company_id'))->where('id','!=',$request->input('id'))->first();
             
            if(! @$checkUnique->id){
                
                  $unitIns = InvUnit::where('id',$request->input('id'))->where('company_id',$request->input('company_id'))->first(); 
            
                    if($unitIns){
                          $unitIns->unit_name = $request->input('unit_name');
                          $unitIns->short_name = $request->input('short_name');
                          $unitIns->is_active = $request->input('is_active');
                          $unitIns->update_date = Carbon::now();
                          $unitIns->update_by = $request->input('update_by'); 
                          $unitIns->company_id = $request->input('company_id'); 

                          $update = $unitIns->save();

                          if($update){
                              return response()->json(['status'=>'success']);   
                           }else{
                               return response()->json(['status'=>'fail']);  
                           }

                    }else{
                        return response()->json(['status'=>'no_data']);  
                    }
                
            }else{
                return response()->json(['status'=>'no_unique']); 
            }
           
          
           
        }
   
    }
    
     public function unit_list(Request $request){
         
          $unitList = InvUnit::orderBy('create_date','desc')->where('is_active',1)->limit(500)->get(); 
          
          if($unitList){
               return response()->json($unitList);   
          }else{
              return response()->json(['status'=>'no table record found']);   
          }
     }
     
     public function unit_filter(Request $request){
          
           $company_id = ($request->input('company_id'))? $request->input('company_id'):'';
           $unit_name = ($request->input('unit_name'))? $request->input('unit_name'):'';
           $short_name = ($request->input('short_name'))? $request->input('short_name'):'';
           $is_active = ($request->input('is_active'))? $request->input('is_active'):'';

          if($unit_name || $short_name || $is_active || $company_id){
               
                    $unitList = InvUnit::orderBy('inv_item_unit.create_date','desc')
                                               ->select('inv_item_unit.*','admin_user.full_name as create_by_name')
                                               ->leftJoin('admin_user','admin_user.id','=','inv_item_unit.create_by')
                                               ->where(function($search) use($unit_name,$short_name,$is_active,$company_id){
                                                   if($unit_name){
                                                      $search->where('inv_item_unit.unit_name','like', $unit_name.'%');
                                                   }
                                                   if($short_name){
                                                      $search->where('inv_item_unit.short_name','like', $short_name.'%');
                                                   }
                                                   if($is_active=='yes'){
                                                      $search->where('inv_item_unit.is_active','=', 1);
                                                   }if($is_active=='no'){
                                                      $search->where('inv_item_unit.is_active','=', 0);
                                                   }else{
                                                       $search->where('inv_item_unit.is_active','=', 1); 
                                                   }
                                                    if($company_id){
                                                      $search->where('inv_item_unit.company_id','=', $company_id);
                                                   }
                                               })
                                               ->limit(500)
                                               ->get(); 
           }else{
               $unitList = InvUnit::orderBy('inv_item_unit.create_date','desc')
                               ->select('inv_item_unit.*','admin_user.full_name as create_by_name')
                               ->leftJoin('admin_user','admin_user.id','=','inv_item_unit.create_by')
                               ->where('inv_item_unit.is_active',1)
                               ->limit(500)
                              ->get();  
           }
 
          if($unitList){
               return response()->json($unitList);   
          }else{
              return response()->json(['status'=>'no_data']);   
          }
     }

      public function unit_del(Request $request){
          
          if($request->input('id')){
                  $unitList = InvUnit::where("id",$request->input('id'))->first(); 
                    if($unitList){
                        $unitList->is_active = 0;
                        $unitList->save();
                        return response()->json(['status'=>'success']);

                    }else{
                        return response()->json(['status'=>'no_record_found']);  
                    }
              
          }  
      }
      
     /* end unit api */
      
      
      
      /* item */
      
      public function item_insert(Request $request){
    
         
        
         $insert = null;
         $checkUnique = null;
         $location = base_path()."/public/images/upload/inv/";
         
         if(!File::exists($location)) {
             File::makeDirectory($location, 0775, true);
         }
         
   
         $checkUnique = InvItem::where('item_code',$request->input('item_code'))->first();
         
         if($request->input('item_code') && $request->input('item_name') && $request->input('category_id') && $request->input('unit_id') && $request->input('company_id')){
              
                if(! @$checkUnique->id){
                    
                              $unitIns = new InvItem();
                              
                              $unitIns->item_code = $request->input('item_code');
                              $unitIns->item_name = $request->input('item_name');
                              $unitIns->short_name = $request->input('short_name');
                              
                              $unitIns->category_id = $request->input('category_id');
                              $unitIns->company_id = $request->input('company_id');
                              $unitIns->unit_id = $request->input('unit_id');
                              
                              $unitIns->rate = ($request->input('rate'))? $request->input('rate'):0;
                              $unitIns->offer_rate =( $request->input('offer_rate'))?  $request->input('offer_rate'):0;
                              $unitIns->offer_rate_from = ($request->input('offer_rate_from'))? $request->input('offer_rate_from'):0;
                              $unitIns->offer_rate_to = ($request->input('offer_rate_to'))? $request->input('offer_rate_to'):0;
                              $unitIns->is_trade_offer = ($request->input('is_trade_offer'))? $request->input('is_trade_offer'):0;
                              $unitIns->trade_offer_from = ($request->input('trade_offer_from'))? $request->input('trade_offer_from'):0;
                              $unitIns->trade_offer_to = ($request->input('trade_offer_to'))? $request->input('trade_offer_to'):0;
                             
                              
                              $unitIns->is_active = $request->input('is_active');
                              $unitIns->create_date = Carbon::now();
                              $unitIns->create_by = $request->input('create_by'); 
                              $unitIns->company_id = $request->input('company_id');
                              
                              
                               $file_name = $request->file->getClientOriginalName();
                               $item_image = md5($file_name. microtime()).'.'.$request->file->getClientOriginalExtension();
                               $upFile = $request->file('file')->move($location ,$item_image);
                               
                               
                               $unitIns->item_image_path = $item_image;

                               $insert = $unitIns->save();
                              
                                if($insert){
                                    return response()->json(['status'=>'success']);   
                                }else{
                                    return response()->json(['status'=>'fail']);  
                                }


                }else{
                   return response()->json(['status'=>'no_unique']);  
                }
        
          } 
          
         
        
        
    }
    
     public function item_edit(Request $request){
        
        $update = null;
        $id = @$request->route()->parameter('id');
        if($id){
            
              $unitIns = InvItem::orderBy('inv_item.create_date','desc')
                               ->select(
                                       'inv_item.*',
                                       'admin_user.full_name as create_by_name',
                                       'inv_item_unit.unit_name',
                                       'inv_item_unit.short_name as unit_short_name',
                                       'admin_company_info.name as company_name',
                                       'admin_company_info.short_name as company_short_name',
                                       'inv_item_category.category_name',
                                       'inv_item_category.short_name as category_short_name',
                                       'inv_item_category.vat_percent',
                                       'inv_item_category.scharge_percent'
                                       )
                                ->join('inv_item_unit','inv_item_unit.id','=','inv_item.unit_id')
                                ->join('admin_company_info','admin_company_info.id','=','inv_item.company_id')
                                ->join('inv_item_category','inv_item_category.id','=','inv_item.category_id')
                               ->leftJoin('admin_user','admin_user.id','=','inv_item.create_by')
                               ->where('inv_item.id',$id)
                               ->first();
              
               if($unitIns){
                    return response()->json($unitIns);   
                }else{
                     return response()->json(['status'=>'fail']);  
                }

        }
   
    }
    
    public function item_update(Request $request){
        
        $update = null;
        $location = base_path()."/public/images/upload/inv/";
        if($request->input('id')){
            
            $checkUnique = null;
            $checkUnique = InvItem::where('item_code',$request->input('item_code'))->where('id','!=',$request->input('id'))->first();
             
            if(! @$checkUnique->id){
                
                  $unitIns = InvItem::where('id',$request->input('id'))->where('item_code',$request->input('item_code'))->first(); 
            
                    if($unitIns){
                        
                          $unitIns->item_name = $request->input('item_name');
                          $unitIns->short_name = $request->input('short_name');

                          $unitIns->category_id = $request->input('category_id');
                          $unitIns->company_id = $request->input('company_id');
                          $unitIns->unit_id = $request->input('unit_id');

                        $unitIns->rate = ($request->input('rate'))? $request->input('rate'):0;
                        $unitIns->offer_rate =( $request->input('offer_rate'))?  $request->input('offer_rate'):0;
                        $unitIns->offer_rate_from = ($request->input('offer_rate_from'))? $request->input('offer_rate_from'):0;
                        $unitIns->offer_rate_to = ($request->input('offer_rate_to'))? $request->input('offer_rate_to'):0;
                        $unitIns->is_trade_offer = ($request->input('is_trade_offer'))? $request->input('is_trade_offer'):0;
                        $unitIns->trade_offer_from = ($request->input('trade_offer_from'))? $request->input('trade_offer_from'):0;
                        $unitIns->trade_offer_to = ($request->input('trade_offer_to'))? $request->input('trade_offer_to'):0;
                        
     
                          
                          $unitIns->is_active = $request->input('is_active');
                          $unitIns->update_date = Carbon::now();
                          $unitIns->update_by = $request->input('update_by'); 
                          $unitIns->company_id = $request->input('company_id'); 
                          
                          
                          
                           if(@$request->file->getClientOriginalName() && @$unitIns->item_image_path){
                             $exist_item_image_path = $location.@$unitIns->item_image_path;  
                                    if(File::exists($exist_item_image_path)){
                                         File::delete($exist_item_image_path);
                                    }
                           }
                           
                          
                           $file_name = $request->file->getClientOriginalName();
                           $item_image = md5($file_name. microtime()).'.'.$request->file->getClientOriginalExtension();
                           $upFile = $request->file('file')->move($location ,$item_image);
   
                           $unitIns->item_image_path = $item_image;
                           
                          

                          $update = $unitIns->save();

                          if($update){
                              return response()->json(['status'=>'success']);   
                           }else{
                               return response()->json(['status'=>'fail']);  
                           }

                    }else{
                        return response()->json(['status'=>'no_data']);  
                    }
                
            }else{
                return response()->json(['status'=>'no_unique']); 
            }
           
          
           
        }
   
    }
    

     public function item_filter(Request $request){
          
           $company_id = ($request->input('company_id'))? $request->input('company_id'):'';
           $category_id = ($request->input('category_id'))? $request->input('category_id'):'';
           $unit_id = ($request->input('unit_id'))? $request->input('unit_id'):'';
           $item_name = ($request->input('item_name'))? trim($request->input('item_name')):'';
           $item_code = ($request->input('item_code'))? trim($request->input('item_code')):'';
           $is_active = ($request->input('is_active'))? $request->input('is_active'):'';

          if($item_name || $item_code || $is_active || $company_id || $category_id || $unit_id){
               
                    $unitList = InvItem::orderBy('inv_item.create_date','desc')
                                               ->select(
                                                        'inv_item.*',
                                                        'admin_user.full_name as create_by_name',
                                                        'inv_item_unit.unit_name',
                                                        'inv_item_unit.short_name as unit_short_name',
                                                        'admin_company_info.name as company_name',
                                                        'admin_company_info.short_name as company_short_name',
                                                        'inv_item_category.category_name',
                                                        'inv_item_category.short_name as category_short_name',
                                                        'inv_item_category.vat_percent',
                                                        'inv_item_category.scharge_percent'
                                                        )
                                                ->join('inv_item_unit','inv_item_unit.id','=','inv_item.unit_id')
                                                ->join('admin_company_info','admin_company_info.id','=','inv_item.company_id')
                                                ->join('inv_item_category','inv_item_category.id','=','inv_item.category_id')
                                               ->leftJoin('admin_user','admin_user.id','=','inv_item.create_by')
                                               ->where(function($search) use($item_name,$item_code,$is_active,$company_id,$category_id,$unit_id){
                                                   if($item_name){
                                                      $search->where('inv_item.item_name','like', $item_name.'%');
                                                   }
                                                   if($item_code){
                                                      $search->where('inv_item.item_code','=', $item_code);
                                                   }
                                                   if($is_active=='yes'){
                                                      $search->where('inv_item.is_active','=', 1);
                                                   }if($is_active=='no'){
                                                      $search->where('inv_item.is_active','=', 0);
                                                   }else{
                                                       $search->where('inv_item.is_active','=', 1); 
                                                   }
                                                    if($company_id){
                                                      $search->where('inv_item.company_id','=', $company_id);
                                                   }
                                                   
                                                   if($category_id){
                                                      $search->where('inv_item.category_id','=', $category_id);
                                                   }
                                                   
                                                    if($unit_id){
                                                      $search->where('inv_item.unit_id','=', $unit_id);
                                                   }
                                               })
                                               ->limit(500)
                                               ->get(); 
           }else{
               $unitList = InvItem::orderBy('inv_item.create_date','desc')
                               ->select(
                                        'inv_item.*',
                                        'admin_user.full_name as create_by_name',
                                        'inv_item_unit.unit_name',
                                        'inv_item_unit.short_name as unit_short_name',
                                        'admin_company_info.name as company_name',
                                        'admin_company_info.short_name as company_short_name',
                                        'inv_item_category.category_name',
                                        'inv_item_category.short_name as category_short_name',
                                        'inv_item_category.vat_percent',
                                        'inv_item_category.scharge_percent'
                                        )
                                ->join('inv_item_unit','inv_item_unit.id','=','inv_item.unit_id')
                                ->join('admin_company_info','admin_company_info.id','=','inv_item.company_id')
                                ->join('inv_item_category','inv_item_category.id','=','inv_item.category_id')
                               ->leftJoin('admin_user','admin_user.id','=','inv_item.create_by')
                               ->where('inv_item.is_active',1)
                               ->limit(500)
                              ->get();  
           }
 
          if($unitList){
               return response()->json($unitList);   
          }else{
              return response()->json(['status'=>'no_data']);   
          }
     }

      public function item_del(Request $request){
          
          if($request->input('id')){
                  $unitList = InvItem::where("id",$request->input('id'))->first(); 
                    if($unitList){
                        $unitList->is_active = 0;
                        $unitList->save();
                        return response()->json(['status'=>'success']);

                    }else{
                        return response()->json(['status'=>'no_record_found']);  
                    }
              
          }  
      }
       public function item_last_code(Request $request){
          
             $last_item_code = null;
                  $unitList = InvItem::orderBy('id','desc')->limit(1)->first(); 
                  
                    if(@$unitList->item_code){
                        
                        $increment = (int)explode("-",@$unitList->item_code)[1];
                        
                        $last_item_code ="item-".($increment+1);
                        
                        return response()->json(['code'=>$last_item_code]);

                    }else{
                        $last_item_code ="item-1";
                        return response()->json(['code'=>$last_item_code]);  
                    }

      }
      
      public function productUpload(Request $request){
          
         
          
           $all = $request->all();

           $file_name = $request->file->getClientOriginalName();
           $original= 'test'.$request->file->getClientOriginalExtension();

           $location = base_path()."/public/images/upload/inv/";
           
           //$upFile = WebServices::apiFileUpload($request,true,$location);
             $upFile = $request->file('file')->move($location ,$file_name);
           
           $okk = $upFile;
         
      }
      
      /* end item */
      
      
      
    /* role api */
      
         public function role_insert(Request $request){
        
       
         $insert = null;
        
         $checkUnique = null;
           
         $checkUnique = AdminRole::where('role_name',$request->input('role_name'))->first();
         
         if($request->input('role_name')){
              
                if(! @$checkUnique->id){
                    
                              $unitIns = new AdminRole();
                              $unitIns->role_name = $request->input('role_name');
                              $unitIns->is_active = $request->input('is_active');
                              $unitIns->create_date = Carbon::now();
                              $unitIns->create_by = $request->input('create_by'); 

                              $insert = $unitIns->save();
                              
                                if($insert){
                                    return response()->json(['status'=>'success']);   
                                }else{
                                    return response()->json(['status'=>'fail']);  
                                }


                }else{
                   return response()->json(['status'=>'no_unique']);  
                }
        
          } 
          
         
        
        
    }
    
     public function role_edit(Request $request){
        
        $update = null;
        $id = @$request->route()->parameter('id');
        if($id){
            
              $unitIns = AdminRole::orderBy('admin_role.create_date','desc')
                               ->select('admin_role.*','admin_user.full_name as create_by_name')
                               ->leftJoin('admin_user','admin_user.id','=','admin_role.create_by')
                               ->where('admin_role.id',$id)
                               ->first();
              
               if($unitIns){
                    return response()->json($unitIns);   
                }else{
                     return response()->json(['status'=>'fail']);  
                }

        }
   
    }
    
    public function role_update(Request $request){
        
        $update = null;
        if($request->input('id')){
            
            $checkUnique = null;
            $checkUnique = AdminRole::where('role_name',$request->input('role_name'))->where('id','!=',$request->input('id'))->first();
             
            if(! @$checkUnique->id){
                
                  $unitIns = AdminRole::where('id',$request->input('id'))->first(); 
            
                    if($unitIns){
                          $unitIns->role_name = $request->input('role_name');
                          $unitIns->is_active = $request->input('is_active');
                          $unitIns->update_date = Carbon::now();
                          $unitIns->update_by = $request->input('update_by'); 

                          $update = $unitIns->save();

                          if($update){
                              return response()->json(['status'=>'success']);   
                           }else{
                               return response()->json(['status'=>'fail']);  
                           }

                    }else{
                        return response()->json(['status'=>'no_data']);  
                    }
                
            }else{
                return response()->json(['status'=>'no_unique']); 
            }
           
          
           
        }
   
    }
    
     public function role_list(Request $request){
         
          $unitList = AdminRole::orderBy('create_date','desc')->where('is_active',1)->limit(500)->get(); 
          
          if($unitList){
               return response()->json($unitList);   
          }else{
              return response()->json(['status'=>'no table record found']);   
          }
     }
     
     public function role_filter(Request $request){
          

           $role_name = ($request->input('role_name'))? $request->input('role_name'):'';
           $is_active = ($request->input('is_active'))? $request->input('is_active'):'';

          if($role_name || $is_active ){
               
                    $unitList = AdminRole::orderBy('admin_role.create_date','desc')
                                               ->select('admin_role.*','admin_user.full_name as create_by_name')
                                               ->leftJoin('admin_user','admin_user.id','=','admin_role.create_by')
                                               ->where(function($search) use($role_name,$is_active){
                                                   if($role_name){
                                                      $search->where('admin_role.role_name','like', $role_name.'%');
                                                   }
                                                  
                                                   if($is_active=='yes'){
                                                      $search->where('admin_role.is_active','=', 1);
                                                   }if($is_active=='no'){
                                                      $search->where('admin_role.is_active','=', 0);
                                                   }else{
                                                       $search->where('admin_role.is_active','=', 1); 
                                                   }
                                                   
                                               })
                                               ->limit(500)
                                               ->get(); 
           }else{
               $unitList = AdminRole::orderBy('admin_role.create_date','desc')
                              ->select('admin_role.*','admin_user.full_name as create_by_name')
                              ->leftJoin('admin_user','admin_user.id','=','admin_role.create_by')
                               ->where('admin_role.is_active',1)
                               ->limit(500)
                               ->get();  
           }
 
          if($unitList){
               return response()->json($unitList);   
          }else{
              return response()->json(['status'=>'no_data']);   
          }
     }

      public function role_del(Request $request){
          
          if($request->input('id')){
                  $unitList = AdminRole::where("id",$request->input('id'))->first(); 
                    if($unitList){
                        $unitList->is_active = 0;
                        $unitList->save();
                        return response()->json(['status'=>'success']);

                    }else{
                        return response()->json(['status'=>'no_record_found']);  
                    }
              
          }  
      }
      
     /* end role api */
      
      
      
            
      /* user */
      
      public function user_insert(Request $request){
    
         
        
         $insert = null;
         $checkUnique = null;
         $location = base_path()."/public/images/upload/photo/";
         
         if(!File::exists($location)) {
             File::makeDirectory($location, 0775, true);
         }
         
        
   
         $checkUnique = User::where('email',$request->input('email'))->first();
         
         $pass = $request->input('pass');
         $bcryptPass = bcrypt($pass);
         
         if($request->input('email') && $request->input('full_name')){
              
                if(! @$checkUnique->id){
                    
                              $unitIns = new User();
                              
                              $unitIns->full_name = $request->input('full_name');
                              $unitIns->email = $request->input('email');
                              $unitIns->mobile = $request->input('mobile');
                              $unitIns->password = $bcryptPass;
                              //$userIns->password = bcrypt($request->input('pass'));
                              
                              $unitIns->company_id = $request->input('company_id');
                              $unitIns->role_id = $request->input('role_id');
                              
                              $unitIns->date_of_birth = (Carbon::createFromFormat('d-m-Y',$request->input('date_of_birth'))? Carbon::createFromFormat('d-m-Y',$request->input('date_of_birth')):null);
                              $unitIns->gender = $request->input('gender');
                              $unitIns->user_type = $request->input('user_type');
                              $unitIns->address = $request->input('address');

                              $unitIns->is_active = $request->input('is_active');
                              $unitIns->create_date = Carbon::now();
                              $unitIns->create_by = $request->input('create_by'); 
                              
                              
                              if(@$request->file !='null'){
                                  
                                  $file_name = $request->file->getClientOriginalName();
                                  $item_image = md5($file_name. microtime()).'.'.$request->file->getClientOriginalExtension();
                                  $upFile = $request->file('file')->move($location ,$item_image);
                               
                               
                                   $unitIns->photo_path = $item_image;
                                  
                              }
                               

                               $insert = $unitIns->save();
                              
                                if($insert){
                                    return response()->json(['status'=>'success']);   
                                }else{
                                    return response()->json(['status'=>'fail']);  
                                }


                }else{
                   return response()->json(['status'=>'no_unique']);  
                }
        
          } 
          
         
        
        
    }
    
     public function user_edit(Request $request){
        
        $update = null;
        $id = @$request->route()->parameter('id');
        if($id){
            
              $unitIns = User::orderBy('admin_user.create_date','desc')
                               ->select(
                                       'admin_user.*',
                                       'user2.full_name as create_by_name',
                                       'admin_company_info.name as company_name',
                                       'admin_company_info.short_name as company_short_name',
                                       'admin_role.role_name'
                                       )
                                ->join('admin_company_info','admin_company_info.id','=','admin_user.company_id')
                                ->join('admin_role','admin_role.id','=','admin_user.role_id')
                              ->leftJoin('admin_user as user2','user2.id','=','admin_user.create_by')
                               ->where('admin_user.id',$id)
                               ->first();
              
               if($unitIns){
                    return response()->json($unitIns);   
                }else{
                     return response()->json(['status'=>'fail']);  
                }

        }
   
    }
    
    public function user_update(Request $request){
        
        $update = null;
        $location = base_path()."/public/images/upload/photo/";
         //$ss = $request->all();
         $pass = $request->input('pass');
         $bcryptPass = bcrypt($pass);
        if($request->input('id')){
            
            $checkUnique = null;
            $checkUnique = User::where('email',$request->input('email'))->where('id','!=',$request->input('id'))->first();
             
            if(! @$checkUnique->id){
                
                  $unitIns = User::where('id',$request->input('id'))->first(); 
            
                    if($unitIns){
                        
                        $unitIns->full_name = $request->input('full_name');
                        $unitIns->email = $request->input('email');
                        $unitIns->mobile = $request->input('mobile');
                        $unitIns->password = $bcryptPass;
                        //$userIns->password = bcrypt($request->input('pass'));
                        //if(Hash::check($pass, Hash::make($pass))){
                          //$userIns->password = Hash::make($pass); 
                        //}
                        
                        

                        $unitIns->company_id = $request->input('company_id');
                        $unitIns->role_id = $request->input('role_id');

                        $unitIns->date_of_birth = (Carbon::createFromFormat('d-m-Y',$request->input('date_of_birth'))? Carbon::createFromFormat('d-m-Y',$request->input('date_of_birth')):null);
                        $unitIns->gender = $request->input('gender');
                        $unitIns->user_type = $request->input('user_type');
                        $unitIns->address = $request->input('address');


                        $unitIns->is_active = $request->input('is_active');
                        $unitIns->update_date = Carbon::now();
                        $unitIns->update_by = $request->input('update_by'); 

                          
                          
                          
                           if(@$request->file !='null'){
                               
                                if(@$unitIns->photo_path){

                                    $exist_item_image_path = $location.@$unitIns->photo_path;  
                                     if(File::exists($exist_item_image_path)){
                                          File::delete($exist_item_image_path);
                                     }

                                }
                                  
                                    
                                    $file_name = $request->file->getClientOriginalName();
                                    $item_image = md5($file_name. microtime()).'.'.$request->file->getClientOriginalExtension();
                                    $upFile = $request->file('file')->move($location ,$item_image);

                                    $unitIns->photo_path = $item_image;
                           }
                           
                          
                          
                           
                          

                          $update = $unitIns->save();

                          if($update){
                              return response()->json(['status'=>'success']);   
                           }else{
                               return response()->json(['status'=>'fail']);  
                           }

                    }else{
                        return response()->json(['status'=>'no_data']);  
                    }
                
            }else{
                return response()->json(['status'=>'no_unique']); 
            }
           
          
           
        }
   
    }
    

     public function user_filter(Request $request){
          
           $company_id = ($request->input('company_id'))? $request->input('company_id'):'';
           $role_id = ($request->input('role_id'))? $request->input('role_id'):'';
           $full_name = ($request->input('full_name'))? trim($request->input('full_name')):'';
           $email = ($request->input('email'))? trim($request->input('email')):'';
           $mobile = ($request->input('mobile'))? trim($request->input('mobile')):'';
           $is_active = ($request->input('is_active'))? $request->input('is_active'):'';

          if($email || $mobile || $is_active || $company_id || $role_id || $full_name){
               
                    $unitList = User::orderBy('admin_user.create_date','desc')
                               ->select(
                                       'admin_user.*',
                                       'user2.full_name as create_by_name',
                                       'admin_company_info.name as company_name',
                                       'admin_company_info.short_name as company_short_name',
                                       'admin_role.role_name'
                                       )
                                ->join('admin_company_info','admin_company_info.id','=','admin_user.company_id')
                                ->join('admin_role','admin_role.id','=','admin_user.role_id')
                                ->leftJoin('admin_user as user2','user2.id','=','admin_user.create_by')
                                               ->where(function($search) use($email,$mobile,$is_active,$company_id,$role_id,$full_name){
                                                   if($full_name){
                                                      $search->where('admin_user.full_name','like', $full_name.'%');
                                                   }
                                                   if($email){
                                                      $search->where('admin_user.email','=', $email);
                                                   }
                                                   if($mobile){
                                                      $search->where('admin_user.mobile','=', $mobile);
                                                   }
                                                   if($is_active=='yes'){
                                                      $search->where('admin_user.is_active','=', 1);
                                                      $search->where('admin_user.is_delete','=', 0);
                                                   }if($is_active=='no'){
                                                      $search->where('admin_user.is_active','=', 0);
                                                       $search->where('admin_user.is_delete','=', 0);
                                                   }else{
                                                       $search->where('admin_user.is_active','=', 1); 
                                                       $search->where('admin_user.is_delete','=', 0);
                                                   }
                                                    if($company_id){
                                                      $search->where('admin_user.company_id','=', $company_id);
                                                   }
                                                   
                                                   if($role_id){
                                                      $search->where('admin_user.role_id','=', $role_id);
                                                   }
 
                                               })
                                               ->limit(500)
                                               ->get(); 
           }else{
               $unitList = User::orderBy('admin_user.create_date','desc')
                               ->select(
                                       'admin_user.*',
                                       'user2.full_name as create_by_name',
                                       'admin_company_info.name as company_name',
                                       'admin_company_info.short_name as company_short_name',
                                       'admin_role.role_name'
                                       )
                                ->join('admin_company_info','admin_company_info.id','=','admin_user.company_id')
                                ->join('admin_role','admin_role.id','=','admin_user.role_id')
                               ->leftJoin('admin_user as user2','user2.id','=','admin_user.create_by')
                               ->where('admin_user.is_active',1)
                               ->where('admin_user.is_delete',0)
                               ->limit(500)
                               ->get();  
           }
 
          if($unitList){
               return response()->json($unitList);   
          }else{
              return response()->json(['status'=>'no_data']);   
          }
     }

      public function user_del(Request $request){
          
          if($request->input('id')){
                  $unitList = User::where("id",$request->input('id'))->first(); 
                    if($unitList){
                        $unitList->is_delete = 1;
                        $unitList->save();
                        return response()->json(['status'=>'success']);

                    }else{
                        return response()->json(['status'=>'no_record_found']);  
                    }
              
          }  
      }
      
      /* end user */
      
      
      
         /* menu api */
      
         public function menu_insert(Request $request){
        
       
         $insert = null;
        
         $checkUnique = null;
           
         $checkUnique = AdminMenu::where('menu_name',$request->input('menu_name'))->first();
         
         if($request->input('menu_name')){
              
                if(! @$checkUnique->id){
                    
                              $unitIns = new AdminMenu();
                              $unitIns->menu_name = $request->input('menu_name');
                              $unitIns->type = $request->input('type');
                              //$unitIns->parent_type = $request->input('parent_type');
                              $unitIns->parent_id = $request->input('parent_id');
                              $unitIns->sl_no = $request->input('sl_no');
                              $unitIns->route_path = $request->input('route_path');
                              $unitIns->route_name = $request->input('route_name');
                              $unitIns->is_active = $request->input('is_active');
                              $unitIns->create_date = Carbon::now();
                              $unitIns->create_by = $request->input('create_by'); 

                              $insert = $unitIns->save();
                              
                                if($insert){
                                    return response()->json(['status'=>'success']);   
                                }else{
                                    return response()->json(['status'=>'fail']);  
                                }


                }else{
                   return response()->json(['status'=>'no_unique']);  
                }
        
          } 
          
         
        
        
    }
    
     public function menu_edit(Request $request){
        
        $update = null;
        $id = @$request->route()->parameter('id');
        if($id){
            
              $unitIns = AdminMenu::orderBy('admin_menu.create_date','desc')
                               ->select('admin_menu.*','admin_user.full_name as create_by_name')
                               ->leftJoin('admin_user','admin_user.id','=','admin_menu.create_by')
                               ->where('admin_menu.id',$id)
                               ->first();
              
               if($unitIns){
                    return response()->json($unitIns);   
                }else{
                     return response()->json(['status'=>'fail']);  
                }

        }
   
    }
    
    public function menu_update(Request $request){
        
        $update = null;
        if($request->input('id')){
            
            $checkUnique = null;
            $checkUnique = AdminMenu::where('menu_name',$request->input('menu_name'))->where('id','!=',$request->input('id'))->first();
             
            if(! @$checkUnique->id){
                
                  $unitIns = AdminMenu::where('id',$request->input('id'))->first(); 
            
                    if($unitIns){
                          $unitIns->menu_name = $request->input('menu_name');
                          $unitIns->type = $request->input('type');
                          //$unitIns->parent_type = $request->input('parent_type');
                          $unitIns->parent_id = ($request->input('parent_id'))? $request->input('parent_id'):null;
                          $unitIns->sl_no = $request->input('sl_no');
                          $unitIns->route_path = $request->input('route_path');
                          $unitIns->route_name = $request->input('route_name');
                          $unitIns->is_active = $request->input('is_active');
                          $unitIns->update_date = Carbon::now();
                          $unitIns->update_by = $request->input('update_by'); 

                          $update = $unitIns->save();

                          if($update){
                              return response()->json(['status'=>'success']);   
                           }else{
                               return response()->json(['status'=>'fail']);  
                           }

                    }else{
                        return response()->json(['status'=>'no_data']);  
                    }
                
            }else{
                return response()->json(['status'=>'no_unique']); 
            }
           
          
           
        }
   
    }

     
    public function menu_filter(Request $request){
          

           $menu_name = ($request->input('menu_name'))? $request->input('menu_name'):'';
           $type = ($request->input('type'))? $request->input('type'):'';
           $is_active = ($request->input('is_active'))? $request->input('is_active'):'';

          if($menu_name || $is_active || $type ){
               
                    $unitList = AdminMenu::orderBy('admin_menu.sl_no','asc')
                                               ->select(
                                                       'admin_menu.*',
                                                       'admin_user.full_name as create_by_name',
                                                        DB::raw("(SELECT menu_name FROM admin_menu p WHERE p.id = admin_menu.parent_id) as parent_menu_name")
                                                       )
                                               ->leftJoin('admin_user','admin_user.id','=','admin_menu.create_by')
                                               ->where(function($search) use($menu_name,$is_active,$type){
                                                   if($menu_name){
                                                      $search->where('admin_menu.menu_name','like', $menu_name.'%');
                                                   }
                                                   
                                                   if($type){
                                                      $search->where('admin_menu.type','=', $type);
                                                   }
                                                  
                                                   if($is_active=='yes'){
                                                      $search->where('admin_menu.is_active','=', 1);
                                                   }if($is_active=='no'){
                                                      $search->where('admin_menu.is_active','=', 0);
                                                   }else{
                                                       $search->where('admin_menu.is_active','=', 1); 
                                                   }
                                                   
                                               })
                                               ->limit(500)
                                               ->get(); 
           }else{
               $unitList = AdminMenu::orderBy('admin_menu.sl_no','asc')
                              ->select(
                                    'admin_menu.*',
                                    'admin_user.full_name as create_by_name',
                                     DB::raw("(SELECT menu_name FROM admin_menu p WHERE p.id = admin_menu.parent_id) as parent_menu_name")
                                    )
                             ->leftJoin('admin_user','admin_user.id','=','admin_menu.create_by')
                              ->where('admin_menu.is_active',1)
                              ->limit(500)
                              ->get(); 
           }
 
          if($unitList){
               return response()->json($unitList);   
          }else{
              return response()->json(['status'=>'no_data']);   
          }
     }

      public function menu_del(Request $request){
          
          if($request->input('id')){
                  $unitList = AdminMenu::where("id",$request->input('id'))->first(); 
                    if($unitList){
                        $unitList->is_active = 0;
                        $unitList->save();
                        return response()->json(['status'=>'success']);

                    }else{
                        return response()->json(['status'=>'no_record_found']);  
                    }
              
          }  
      }
      
       public function menu_instant(Request $request){
         
          if($request->input('id')){
                  $unitIns = AdminMenu::orderBy('admin_menu.create_date','desc')
                               ->select('admin_menu.*','admin_user.full_name as create_by_name')
                               ->leftJoin('admin_user','admin_user.id','=','admin_menu.create_by')
                               ->where('admin_menu.id',$request->input('id'))
                               ->first();
              
               if($unitIns){
                    return response()->json($unitIns);   
                }else{
                     return response()->json();  
                }
              
          }  
      }
      
     /* end menu api */
      
      
      
      /* role menu permission */
      
      
       public function role_menu_update(Request $request){
        
        $update = null;
        
        $roleId =$request->input('role_id');
        $deleteObject = $request->input('deleteObject');
        $editObject = $request->input('editObject');
        $insertObject = $request->input('insertObject');
        $viewObject = $request->input('viewObject');
        $create_by = $request->input('create_by');
        
        if($roleId){
            
            for($i = 0; $i< count((array)$insertObject); $i++){
                
               
                
                $checkUniquePosRoleMenuIns = AdminRoleMenuPermission::
                                               where('role_id','=',$roleId)
                                               ->where('menu_id','=',$insertObject[$i]['id'])
                                               ->first();

                if(@$checkUniquePosRoleMenuIns->id){
                    
                     if($viewObject[$i]['val'] == "view" || $insertObject[$i]['val'] == "insert" || $editObject[$i]['val'] == "edit" || $deleteObject[$i]['val']=="delete"){
                         
                         if($viewObject[$i]['val'] == "view"){
                         @$checkUniquePosRoleMenuIns->is_view="yes";
                        }else{
                          @$checkUniquePosRoleMenuIns->is_view="no";  
                        }

                        if($insertObject[$i]['val'] == "insert"){
                            @$checkUniquePosRoleMenuIns->is_insert ="yes";
                        }else{
                          @$checkUniquePosRoleMenuIns->is_insert ="no";  
                        }

                        if($editObject[$i]['val'] == "edit"){
                            @$checkUniquePosRoleMenuIns->is_edit ="yes";
                        }else{
                          @$checkUniquePosRoleMenuIns->is_edit ="no";  
                        }

                        if($deleteObject[$i]['val']=="delete"){
                            @$checkUniquePosRoleMenuIns->is_delete ="yes";
                        }else{
                          @$checkUniquePosRoleMenuIns->is_delete ="no";  
                        }

                        @$checkUniquePosRoleMenuIns->update_date = Carbon::now();
                        @$checkUniquePosRoleMenuIns->update_by = $create_by; 


                       $update = $checkUniquePosRoleMenuIns->save();
                         
                     }else{
                         @$checkUniquePosRoleMenuIns->delete();
                     }
                   
                    
   
                }elseif($viewObject[$i]['val'] == "view" || $insertObject[$i]['val'] == "insert" || $editObject[$i]['val'] == "edit" || $deleteObject[$i]['val']=="delete"){
                    
                  $newPosRoleMenuIns = new AdminRoleMenuPermission();
                  
                     $newPosRoleMenuIns->role_id = $roleId;
                     $newPosRoleMenuIns->menu_id = $viewObject[$i]['id'];
                     
                     
                     if($viewObject[$i]['val'] == "view"){
                         $newPosRoleMenuIns->is_view="yes";
                     }else{
                       $newPosRoleMenuIns->is_view="no";  
                     }
                     
                     if($insertObject[$i]['val'] == "insert"){
                         $newPosRoleMenuIns->is_insert ="yes";
                     }else{
                       $newPosRoleMenuIns->is_insert ="no";  
                     }
                  
                     if($editObject[$i]['val'] == "edit"){
                         $newPosRoleMenuIns->is_edit ="yes";
                     }else{
                       $newPosRoleMenuIns->is_edit ="no";  
                     }
                     
                     if($deleteObject[$i]['val']=="delete"){
                         $newPosRoleMenuIns->is_delete ="yes";
                     }else{
                       $newPosRoleMenuIns->is_delete ="no";  
                     }
                     
                      $newPosRoleMenuIns->create_date = Carbon::now();
                      $newPosRoleMenuIns->create_by = $create_by; 
                     
                     
                      $update = $newPosRoleMenuIns->save();
                     
                  
                }
                
                
                
              
                
            }// end foreach
            
            
            if($update){
                return response()->json(['status'=>'success']);   
            }else{
                return response()->json(['status'=>'fail']);  
            }
  
        }
   
    }

      
       public function role_menu_filter(Request $request){
          

           $role_id = ($request->input('role_id'))? $request->input('role_id'):'';
           $status = ($request->input('status'))? $request->input('status'):'';
           
           $isRole = null;
           
           $unitList = null;
           
          

          if($role_id){
              
                if($status=='permited'){
                    
                     $unitList = AdminMenu::orderBy('admin_menu.sl_no','asc')
                                               ->select(
                                                       'admin_menu.id as pos_menu_id',
                                                       'admin_menu.menu_name as pos_menu_name',
                                                       'admin_menu.type',
                                                       'admin_menu.parent_type',
                                                       'admin_menu.parent_id',
                                                       'admin_role_menu_permission.*',
                                                       'admin_user.full_name as create_by_name',
                                                       'user2.full_name as update_by_name',
                                                       DB::raw("(SELECT menu_name FROM admin_menu p WHERE p.id = admin_menu.parent_id) as parent_menu_name")
                                                       )
                                               ->join('admin_role_menu_permission','admin_role_menu_permission.menu_id','=','admin_menu.id')
                                               ->leftJoin('admin_user','admin_user.id','=','admin_role_menu_permission.create_by')
                                               ->leftJoin('admin_user as user2','user2.id','=','admin_role_menu_permission.update_by')
                                               ->where('admin_role_menu_permission.role_id','=',$role_id)
                                               ->where('admin_menu.is_active','=',1)
                                               ->where('admin_menu.type','=','MENU')
                                               ->limit(500)
                                               ->get();
                    
                }else{
                    
                    
                    $permissionlist = @AdminRoleMenuPermission::select('menu_id')->where('role_id',$role_id)->get()->toArray();
                    $unitList = AdminMenu::orderBy('admin_menu.sl_no','asc')
                                               ->select(
                                                       'admin_menu.id as pos_menu_id',
                                                       'admin_menu.menu_name as pos_menu_name',
                                                       'admin_menu.type',
                                                       'admin_menu.parent_type',
                                                       'admin_menu.parent_id',
                                                       DB::raw("(SELECT menu_name FROM admin_menu p WHERE p.id = admin_menu.parent_id) as parent_menu_name")
                                                       )
                                               ->where('admin_menu.is_active','=',1)
                                               ->where('admin_menu.type','=','MENU')
                                               ->whereNotIn('admin_menu.id',@$permissionlist)
                                               ->limit(500)
                                               ->get();
                    
                    
                    
                }
             
               
                    
           }
 
          if($unitList){
               return response()->json($unitList);   
          }else{
              return response()->json([]);   
          }
     }
      
      /* end role menu permission */
     
     
     /*  user menu */
       public function getUserMenu(Request $request){
           
       $roleId = $request->role_id;
       
       $rootMenuArray = array();
       $treeMenuArray = array();
       $menuArray = array();
       
              if($roleId){
           
      
       
                    $adminMenuList = AdminRoleMenuPermission::orderBy('admin_menu.sl_no','asc')
                                      ->select(
                                              'admin_menu.id',
                                              'admin_menu.parent_id',
                                              'admin_menu.menu_name',
                                              'admin_menu.type',
                                              'admin_menu.sl_no',
                                              'admin_menu.route_path',
                                              'admin_menu.route_name'
                                              )
                                        ->join('admin_menu','admin_menu.id','=','admin_role_menu_permission.menu_id')
                                        ->where('admin_role_menu_permission.role_id','=',$roleId)
                                        ->get();
                    
                    
                   


                foreach($adminMenuList as $adminMenuL){

                            if($adminMenuL->type=='MENU'){

                                $innerOneMenuIns = AdminMenu::where('id',$adminMenuL->parent_id)->first();

                                if(@$innerOneMenuIns->type=='TREE'){

                                       $innerTwoMenuIns = @AdminMenu::where('id',$innerOneMenuIns->parent_id)->first(); 

                                         if(@$innerTwoMenuIns->type="ROOT"){
                                             
                                            /*if(array_search(@$innerTwoMenuIns->menu_name, array_column($rootMenuArray, 'root')) == false) {
                                               $rootMenuArray[] = array('root'=>@$innerTwoMenuIns->menu_name,'has_tree'=>'yes');
                                            }*/
                                            
                                             /*if(! array_column($rootMenuArray, 'root')) {
                                               $rootMenuArray[] = array('root'=>@$innerTwoMenuIns->menu_name,'has_tree'=>'yes');
                                            }*/
                                            
                                            if(! in_array(@$innerTwoMenuIns->menu_name, array_column($rootMenuArray,'root'))){
                                                  $rootMenuArray[@$innerTwoMenuIns->sl_no] = array('root'=>@$innerTwoMenuIns->menu_name,'has_tree'=>'yes');
                                             }
                                            
                                           
                                            if(! array_column($treeMenuArray,@$innerTwoMenuIns->menu_name)){
                                               
                                                $treeMenuArray []= array(@$innerTwoMenuIns->menu_name=>@$innerOneMenuIns->menu_name);
                                            }
                                           
                                            $menuArray[] = array(@$innerOneMenuIns->menu_name => $adminMenuL->menu_name,'sl'=>$adminMenuL->sl_no,'route_path'=>$adminMenuL->route_path,'route_name'=>$adminMenuL->route_name);
                                         }


                                }else if(@$innerOneMenuIns->type=='ROOT'){
                                    
                                      
                                    /*if(array_search(@$innerOneMenuIns->menu_name, array_column($rootMenuArray, 'root')) == false) {
                                               $rootMenuArray[] = array('root'=>@$innerOneMenuIns->menu_name,'has_tree'=>'no');
                                    }*/
                                    
                                     /*if(! array_column($rootMenuArray,'root')){
                                        $rootMenuArray[] = array('root'=>@$innerOneMenuIns->menu_name,'has_tree'=>'no');  
                                     }*/
                                    

                                     if(! in_array(@$innerOneMenuIns->menu_name, array_column($rootMenuArray,'root'))){
                                        $rootMenuArray[@$innerOneMenuIns->sl_no] = array('root'=>@$innerOneMenuIns->menu_name,'has_tree'=>'no'); 
                                     }
                                   

                                    $menuArray[] = array(@$innerOneMenuIns->menu_name => $adminMenuL->menu_name,'sl'=>$adminMenuL->sl_no,'route_path'=>$adminMenuL->route_path,'route_name'=>$adminMenuL->route_name);
                                }


                            }

                     }
                     
                    

                    //$rootMenuArray = array_unique(array_column($rootMenuArray, 'root'));  // multidimentional filtering
                          //$rootMenuArray = array_unique($rootMenuArray);
                    $rootMenuArray = array_filter($rootMenuArray);
                    ksort($rootMenuArray);
                    
                

                        //$treeMenuArray = array_unique($treeMenuArray);
                    $treeMenuArray = array_filter($treeMenuArray);

                        //$menuArray = array_unique($menuArray);
                    $menuArray = array_filter($menuArray);

                    $menu = array_merge(['root'=>$rootMenuArray],['tree'=>$treeMenuArray],['menu'=>$menuArray]);
                    
                   
              
                    return response()->json($menu);
            }
       }
       
     /* end user menu */
       
       
       
         /* unit inv customer */
      
         public function customer_insert(Request $request){
        
       
         $insert = null;
         
         //$ss = $request->all();
        
         $checkUnique = null;
           
         $checkUnique = InvCustomer::where('email',$request->input('email'))->where('company_id',$request->input('company_id'))->first();
         
         if($request->input('customer_name') && $request->input('email')){
              
                if(! @$checkUnique->id){
                    
                              $unitIns = new InvCustomer();
                              $unitIns->company_id = $request->input('company_id');
                              $unitIns->customer_name = $request->input('customer_name');
                              $unitIns->address = $request->input('address');
                              $unitIns->contact_person = $request->input('contact_person');
                              $unitIns->email = $request->input('email');
                              $unitIns->mobile = $request->input('mobile');
                              $unitIns->website = $request->input('website');
                              $unitIns->opening_date = (Carbon::createFromFormat('d-m-Y',$request->input('opening_date'))? Carbon::createFromFormat('d-m-Y',$request->input('opening_date')):null);
                              $unitIns->opening_balance = $request->input('opening_balance');
                              $unitIns->is_active = $request->input('is_active');
                              $unitIns->create_date = Carbon::now();
                              $unitIns->create_by = $request->input('create_by'); 


                              $insert = $unitIns->save();
                              
                                if($insert){
                                    return response()->json(['status'=>'success']);   
                                }else{
                                    return response()->json(['status'=>'fail']);  
                                }


                }else{
                   return response()->json(['status'=>'no_unique']);  
                }
        
          } 
          
         
        
        
    }
    
     public function customer_edit(Request $request){
        
        $update = null;
        $id = @$request->route()->parameter('id');
        if($id){
            
              $unitIns = InvCustomer::orderBy('inv_customer.create_date','desc')
                               ->select('inv_customer.*','admin_user.full_name as create_by_name','admin_company_info.short_name as company_name')
                               ->join('admin_company_info','admin_company_info.id','=','inv_customer.company_id')
                               ->leftJoin('admin_user','admin_user.id','=','inv_customer.create_by')
                               ->where('inv_customer.id',$id)
                               ->first();
              
               if($unitIns){
                    return response()->json($unitIns);   
                }else{
                     return response()->json(['status'=>'fail']);  
                }

        }
   
    }
    
    public function customer_update(Request $request){
        
        $update = null;
        if($request->input('id')){
            
            $checkUnique = null;
            $checkUnique = InvCustomer::where('email',$request->input('email'))->where('company_id',$request->input('company_id'))->where('id','!=',$request->input('id'))->first();
             
            if(! @$checkUnique->id){
                
                  $unitIns = InvCustomer::where('id',$request->input('id'))->where('company_id',$request->input('company_id'))->first(); 
            
                    if($unitIns){
                         $unitIns->company_id = $request->input('company_id');
                        $unitIns->customer_name = $request->input('customer_name');
                        $unitIns->address = $request->input('address');
                        $unitIns->contact_person = $request->input('contact_person');
                        $unitIns->email = $request->input('email');
                        $unitIns->mobile = $request->input('mobile');
                        $unitIns->website = $request->input('website');
                        $unitIns->opening_date = (Carbon::createFromFormat('d-m-Y',$request->input('opening_date'))? Carbon::createFromFormat('d-m-Y',$request->input('opening_date')):null);
                        $unitIns->opening_balance = $request->input('opening_balance');
                        $unitIns->is_active = $request->input('is_active');
                          $unitIns->update_date = Carbon::now();
                          $unitIns->update_by = $request->input('update_by'); 

                          $update = $unitIns->save();

                          if($update){
                              return response()->json(['status'=>'success']);   
                           }else{
                               return response()->json(['status'=>'fail']);  
                           }

                    }else{
                        return response()->json(['status'=>'no_data']);  
                    }
                
            }else{
                return response()->json(['status'=>'no_unique']); 
            }
           
          
           
        }
   
    }
    

     public function customer_filter(Request $request){
          
           $company_id = ($request->input('company_id'))? $request->input('company_id'):'';
           $customer_name = ($request->input('customer_name'))? $request->input('customer_name'):'';
           $email = ($request->input('email'))? $request->input('email'):'';
           $mobile = ($request->input('mobile'))? $request->input('mobile'):'';
           $is_active = ($request->input('is_active'))? $request->input('is_active'):'';

          if($customer_name || $email || $mobile || $is_active || $company_id){
               
                    $unitList = InvCustomer::orderBy('inv_customer.create_date','desc')
                                               ->select('inv_customer.*','admin_user.full_name as create_by_name','admin_company_info.short_name as company_name','admin_company_info.id as company_id')
                                               ->join('admin_company_info','admin_company_info.id','=','inv_customer.company_id')
                                               ->leftJoin('admin_user','admin_user.id','=','inv_customer.create_by')
                                               ->where(function($search) use($customer_name,$email,$mobile,$is_active,$company_id){
                                                   if($customer_name){
                                                      $search->where('inv_customer.customer_name','like', $customer_name.'%');
                                                   }
                                                   if($mobile){
                                                      $search->where('inv_customer.mobile','=', $mobile);
                                                   }
                                                   if($email){
                                                      $search->where('inv_customer.email','=', $email);
                                                   }
                                                   if($is_active=='yes'){
                                                      $search->where('inv_customer.is_active','=', 1);
                                                   }if($is_active=='no'){
                                                      $search->where('inv_customer.is_active','=', 0);
                                                   }else{
                                                       $search->where('inv_customer.is_active','=', 1); 
                                                   }
                                                    if($company_id){
                                                      $search->where('inv_customer.company_id','=', $company_id);
                                                   }
                                               })
                                               ->limit(500)
                                               ->get(); 
           }else{
               $unitList = InvCustomer::orderBy('inv_customer.create_date','desc')
                               ->select('inv_customer.*','admin_user.full_name as create_by_name','admin_company_info.short_name as company_name','admin_company_info.id as company_id')
                               ->join('admin_company_info','admin_company_info.id','=','inv_customer.company_id')
                               ->leftJoin('admin_user','admin_user.id','=','inv_customer.create_by')
                               ->where('inv_customer.is_active',1)
                               ->limit(500)
                              ->get();  
           }
 
          if($unitList){
               return response()->json($unitList);   
          }else{
              return response()->json(['status'=>'no_data']);   
          }
     }

      public function customer_del(Request $request){
          
          if($request->input('id')){
                  $unitList = InvCustomer::where("id",$request->input('id'))->first(); 
                    if($unitList){
                        $unitList->is_active = 0;
                        $unitList->save();
                        return response()->json(['status'=>'success']);

                    }else{
                        return response()->json(['status'=>'no_record_found']);  
                    }
              
          }  
      }
      
     /* end inv customer api */
      
      
      
   /* unit inv supplier */
      
         public function supplier_insert(Request $request){
        
       
         $insert = null;
         
         //$ss = $request->all();
        
         $checkUnique = null;
           
         $checkUnique = InvSupplier::where('email',$request->input('email'))->where('company_id',$request->input('company_id'))->first();
         
         if($request->input('supplier_name') && $request->input('email')){
              
                if(! @$checkUnique->id){
                    
                              $unitIns = new InvSupplier();
                              $unitIns->company_id = $request->input('company_id');
                              $unitIns->supplier_name = $request->input('supplier_name');
                              $unitIns->address = $request->input('address');
                              $unitIns->contact_person = $request->input('contact_person');
                              $unitIns->email = $request->input('email');
                              $unitIns->mobile = $request->input('mobile');
                              $unitIns->website = $request->input('website');
                              $unitIns->opening_date = (Carbon::createFromFormat('d-m-Y',$request->input('opening_date'))? Carbon::createFromFormat('d-m-Y',$request->input('opening_date')):null);
                              $unitIns->opening_balance = $request->input('opening_balance');
                              $unitIns->is_active = $request->input('is_active');
                              $unitIns->create_date = Carbon::now();
                              $unitIns->create_by = $request->input('create_by'); 


                              $insert = $unitIns->save();
                              
                                if($insert){
                                    return response()->json(['status'=>'success']);   
                                }else{
                                    return response()->json(['status'=>'fail']);  
                                }


                }else{
                   return response()->json(['status'=>'no_unique']);  
                }
        
          } 
          
         
        
        
    }
    
     public function supplier_edit(Request $request){
        
        $update = null;
        $id = @$request->route()->parameter('id');
        if($id){
            
              $unitIns = InvSupplier::orderBy('inv_supplier.create_date','desc')
                               ->select('inv_supplier.*','admin_user.full_name as create_by_name','admin_company_info.short_name as company_name')
                               ->join('admin_company_info','admin_company_info.id','=','inv_supplier.company_id')
                               ->leftJoin('admin_user','admin_user.id','=','inv_supplier.create_by')
                               ->where('inv_supplier.id',$id)
                               ->first();
              
               if($unitIns){
                    return response()->json($unitIns);   
                }else{
                     return response()->json(['status'=>'fail']);  
                }

        }
   
    }
    
    public function supplier_update(Request $request){
        
        $update = null;
        if($request->input('id')){
            
            $checkUnique = null;
            $checkUnique = InvSupplier::where('email',$request->input('email'))->where('company_id',$request->input('company_id'))->where('id','!=',$request->input('id'))->first();
             
            if(! @$checkUnique->id){
                
                  $unitIns = InvSupplier::where('id',$request->input('id'))->where('company_id',$request->input('company_id'))->first(); 
            
                    if($unitIns){
                         $unitIns->company_id = $request->input('company_id');
                        $unitIns->supplier_name = $request->input('supplier_name');
                        $unitIns->address = $request->input('address');
                        $unitIns->contact_person = $request->input('contact_person');
                        $unitIns->email = $request->input('email');
                        $unitIns->mobile = $request->input('mobile');
                        $unitIns->website = $request->input('website');
                        $unitIns->opening_date = (Carbon::createFromFormat('d-m-Y',$request->input('opening_date'))? Carbon::createFromFormat('d-m-Y',$request->input('opening_date')):null);
                        $unitIns->opening_balance = $request->input('opening_balance');
                        $unitIns->is_active = $request->input('is_active');
                          $unitIns->update_date = Carbon::now();
                          $unitIns->update_by = $request->input('update_by'); 

                          $update = $unitIns->save();

                          if($update){
                              return response()->json(['status'=>'success']);   
                           }else{
                               return response()->json(['status'=>'fail']);  
                           }

                    }else{
                        return response()->json(['status'=>'no_data']);  
                    }
                
            }else{
                return response()->json(['status'=>'no_unique']); 
            }
           
          
           
        }
   
    }
    

     public function supplier_filter(Request $request){
          
           $company_id = ($request->input('company_id'))? $request->input('company_id'):'';
           $supplier_name = ($request->input('supplier_name'))? $request->input('supplier_name'):'';
           $email = ($request->input('email'))? $request->input('email'):'';
           $mobile = ($request->input('mobile'))? $request->input('mobile'):'';
           $is_active = ($request->input('is_active'))? $request->input('is_active'):'';

          if($supplier_name || $email || $mobile || $is_active || $company_id){
               
                    $unitList = InvSupplier::orderBy('inv_supplier.create_date','desc')
                                               ->select('inv_supplier.*','admin_user.full_name as create_by_name','admin_company_info.short_name as company_name','admin_company_info.id as company_id')
                                               ->join('admin_company_info','admin_company_info.id','=','inv_supplier.company_id')
                                               ->leftJoin('admin_user','admin_user.id','=','inv_supplier.create_by')
                                               ->where(function($search) use($supplier_name,$email,$mobile,$is_active,$company_id){
                                                   if($supplier_name){
                                                      $search->where('inv_supplier.supplier_name','like', $supplier_name.'%');
                                                   }
                                                   if($mobile){
                                                      $search->where('inv_supplier.mobile','=', $mobile);
                                                   }
                                                   if($email){
                                                      $search->where('inv_supplier.email','=', $email);
                                                   }
                                                   if($is_active=='yes'){
                                                      $search->where('inv_supplier.is_active','=', 1);
                                                   }if($is_active=='no'){
                                                      $search->where('inv_supplier.is_active','=', 0);
                                                   }else{
                                                       $search->where('inv_supplier.is_active','=', 1); 
                                                   }
                                                    if($company_id){
                                                      $search->where('inv_supplier.company_id','=', $company_id);
                                                   }
                                               })
                                               ->limit(500)
                                               ->get(); 
           }else{
               $unitList = InvSupplier::orderBy('inv_supplier.create_date','desc')
                               ->select('inv_supplier.*','admin_user.full_name as create_by_name','admin_company_info.short_name as company_name','admin_company_info.id as company_id')
                               ->join('admin_company_info','admin_company_info.id','=','inv_supplier.company_id')
                               ->leftJoin('admin_user','admin_user.id','=','inv_supplier.create_by')
                               ->where('inv_supplier.is_active',1)
                               ->limit(500)
                              ->get();  
           }
 
          if($unitList){
               return response()->json($unitList);   
          }else{
              return response()->json(['status'=>'no_data']);   
          }
     }

      public function supplier_del(Request $request){
          
          if($request->input('id')){
                  $unitList = InvSupplier::where("id",$request->input('id'))->first(); 
                    if($unitList){
                        $unitList->is_active = 0;
                        $unitList->save();
                        return response()->json(['status'=>'success']);

                    }else{
                        return response()->json(['status'=>'no_record_found']);  
                    }
              
          }  
      }
      
     /* end inv supplier api */
      
      
      
      
   public function testapi(Request $request){
       
      
       $userId =1;
       $roleId =1;
       
       $rootMenuArray = array();
       $treeMenuArray = array();
       $menuArray = array();
       
        if($roleId){
           
                    $adminMenuList = AdminRoleMenuPermission::orderBy('admin_menu.sl_no','asc')
                                      ->select(
                                              'admin_menu.id',
                                              'admin_menu.parent_id',
                                              'admin_menu.menu_name',
                                              'admin_menu.type',
                                              'admin_menu.sl_no',
                                              'admin_menu.route_path',
                                              'admin_menu.route_name'
                                              )
                                        ->join('admin_menu','admin_menu.id','=','admin_role_menu_permission.menu_id')
                                        ->where('admin_role_menu_permission.role_id','=',$roleId)
                                        ->get();
                    
                    
                   


                foreach($adminMenuList as $adminMenuL){

                            if($adminMenuL->type=='MENU'){

                                $innerOneMenuIns = AdminMenu::where('id',$adminMenuL->parent_id)->first();

                                if(@$innerOneMenuIns->type=='TREE'){

                                       $innerTwoMenuIns = @AdminMenu::where('id',$innerOneMenuIns->parent_id)->first(); 

                                         if(@$innerTwoMenuIns->type="ROOT"){
                                             
                                            /*if(array_search(@$innerTwoMenuIns->menu_name, array_column($rootMenuArray, 'root')) == false) {
                                               $rootMenuArray[] = array('root'=>@$innerTwoMenuIns->menu_name,'has_tree'=>'yes');
                                            }*/
                                            
                                             /*if(! array_column($rootMenuArray, 'root')) {
                                               $rootMenuArray[] = array('root'=>@$innerTwoMenuIns->menu_name,'has_tree'=>'yes');
                                            }*/
                                            
                                            if(! in_array(@$innerTwoMenuIns->menu_name, array_column($rootMenuArray,'root'))){
                                                  $rootMenuArray[@$innerTwoMenuIns->sl_no] = array('root'=>@$innerTwoMenuIns->menu_name,'has_tree'=>'yes');
                                             }
                                            
                                           
                                            if(! array_column($treeMenuArray,@$innerTwoMenuIns->menu_name)){
                                               
                                                $treeMenuArray []= array(@$innerTwoMenuIns->menu_name=>@$innerOneMenuIns->menu_name);
                                            }
                                           
                                            $menuArray[] = array(@$innerOneMenuIns->menu_name => $adminMenuL->menu_name,'sl'=>$adminMenuL->sl_no,'route_path'=>$adminMenuL->route_path,'route_name'=>$adminMenuL->route_name);
                                         }


                                }else if(@$innerOneMenuIns->type=='ROOT'){
                                    
                                      
                                    /*if(array_search(@$innerOneMenuIns->menu_name, array_column($rootMenuArray, 'root')) == false) {
                                               $rootMenuArray[] = array('root'=>@$innerOneMenuIns->menu_name,'has_tree'=>'no');
                                    }*/
                                    
                                     /*if(! array_column($rootMenuArray,'root')){
                                        $rootMenuArray[] = array('root'=>@$innerOneMenuIns->menu_name,'has_tree'=>'no');  
                                     }*/
                                    

                                     if(! in_array(@$innerOneMenuIns->menu_name, array_column($rootMenuArray,'root'))){
                                        $rootMenuArray[@$innerOneMenuIns->sl_no] = array('root'=>@$innerOneMenuIns->menu_name,'has_tree'=>'no'); 
                                     }
                                   

                                    $menuArray[] = array(@$innerOneMenuIns->menu_name => $adminMenuL->menu_name,'sl'=>$adminMenuL->sl_no,'route_path'=>$adminMenuL->route_path,'route_name'=>$adminMenuL->route_name);
                                }


                            }

                     }
                     
                    

                    //$rootMenuArray = array_unique(array_column($rootMenuArray, 'root'));  // multidimentional filtering
                          //$rootMenuArray = array_unique($rootMenuArray);
                    $rootMenuArray = array_filter($rootMenuArray);
                    ksort($rootMenuArray);
                    
                  

                        //$treeMenuArray = array_unique($treeMenuArray);
                    $treeMenuArray = array_filter($treeMenuArray);

                        //$menuArray = array_unique($menuArray);
                    $menuArray = array_filter($menuArray);

                    $menu = array_merge(['root'=>$rootMenuArray],['tree'=>$treeMenuArray],['menu'=>$menuArray]);
                    
                    print_r($menu);die;
              
                    return response()->json($menu);
            }
    
       
   }   
    


}
?>


bONEandALL
Visitor

Total : 4241

Today :37

Today Visit Country :

  • United States