HEX
Server: LiteSpeed
System: Linux mail.aatilis.ir 6.8.0-100-generic #100-Ubuntu SMP PREEMPT_DYNAMIC Tue Jan 13 16:40:06 UTC 2026 x86_64
User: www (1000)
PHP: 8.3.30
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: /www/wwwroot/soqatland.com/wp-content/plugins/persian-woocommerce/assets/js/pages/stock.js
//Alpine
document.addEventListener('alpine:init', () => {

    Alpine.data("stock", ()=>({

        stock: {
            loading: false,
            data: null
        },

        statuses: [],

        table: {
            data: [],
            loading: false,
            filters: {
                page: 1,
                per_page: 25,
                from_date: null,
                to_date: null,
                status: null
            },
            pagination: {
                items: [],
                currentPage: 1,
                totalPage: 0,
            }
        },

        async init(){
            await this.getPageData();

            pwLoadTippyInPage();
        },

        //request functions
        async getPageData(){
            await Promise.all([
                this.getSummary(),
                this.getProducts()
            ]);
        },

        async getSummary(){
            this.stock.loading = true;

            try{
                const result = await pwApiRequest('persian-woocommerce/reports/stock/summary', {
                    method: 'GET'
                })

                if(result.success){
                    const data = result.data;

                    this.stock.data = data;

                    this.statuses = [
                        {
                            value: 'همه',
                            key: null,
                            count: data.outofstock_count + data.outofstock_count +  data.lowstock_count + data.onbackorder_count
                        },
                        {
                            value: 'ناموجود',
                            key: 'outofstock',
                            count: data.outofstock_count
                        },
                        {
                            value: 'کمبود موجودی',
                            key: 'lowstock',
                            count: data.lowstock_count
                        },
                        {
                            value: 'موجود',
                            key: 'instock',
                            count: data.instock_count
                        },
                        {
                            value: 'در پیش خرید',
                            key: 'onbackorder',
                            count: data.onbackorder_count
                        }
                    ]

                }else{
                    pwNotyf.error(result.message ? result.message : 'حطایی رخ داده است!');
                }

                this.stock.loading = false;

            }catch (error){
                console.error('Error fetching posts:', error);
                this.stock.loading = false;
            }
        },

        async getProducts(){
            this.table.loading = true;

            try{
                const result = await pwApiRequest('persian-woocommerce/reports/stock/products', {
                    method: 'GET',
                    data: pwGenerateFiltersObject(this.table.filters)
                })

                if(result.success){
                    const data = result.data;

                    this.table.data =  data.products;
                    this.table.pagination = {
                        currentPage: data.pagination.current_page,
                        totalPage: parseInt((data.pagination.total_items / this. table.filters.per_page)) + 1,
                        items: pwGetVisiblePages({
                            currentPage: data.pagination.current_page,
                            totalPage: parseInt((data.pagination.total_items / this. table.filters.per_page)) + 1
                        })
                    }

                }else{
                    pwNotyf.error(result.message ? result.message : 'حطایی رخ داده است!');
                }

                this.table.loading = false;

            }catch (error){
                console.error('Error fetching posts:', error);
                this.table.loading = false;
            }
        },

        //other function
        changePage(newPage){
            this.table.pagination.currentPage = newPage;
            this.table.filters.page = newPage;
            this.getProducts();
        },

    }))

})