all subscriptions
This commit is contained in:
		
							
								
								
									
										54
									
								
								static/js/all-subscriptions.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								static/js/all-subscriptions.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,54 @@
 | 
			
		||||
export function showTable(api) {
 | 
			
		||||
    let token = localStorage.getItem("token");
 | 
			
		||||
    let tbody = document.getElementById("subscriptions-table").getElementsByTagName("tbody")[0];
 | 
			
		||||
 | 
			
		||||
    const requestOptions = {
 | 
			
		||||
        method: 'post',
 | 
			
		||||
        headers: {
 | 
			
		||||
            'Accept': `application/json`,
 | 
			
		||||
            'Content-Type': 'application/json',
 | 
			
		||||
            'Authorization': 'Bearer ' + token,
 | 
			
		||||
        },
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    fetch(api + "/api/admin/all-subscriptions", requestOptions)
 | 
			
		||||
        .then(response => response.json())
 | 
			
		||||
        .then(function (data) {
 | 
			
		||||
            if (data) {
 | 
			
		||||
            data.forEach(function (i) {
 | 
			
		||||
                let newRow = tbody.insertRow();
 | 
			
		||||
                let newCell = newRow.insertCell();
 | 
			
		||||
 | 
			
		||||
                newCell.innerHTML = `<a href="/admin/subscriptions/${i.id}">Order ${i.id}</a>`;
 | 
			
		||||
 | 
			
		||||
                newCell = newRow.insertCell();
 | 
			
		||||
                let item = document.createTextNode(i.customer.last_name + ", " + i.customer.first_name);
 | 
			
		||||
                newCell.appendChild(item)
 | 
			
		||||
 | 
			
		||||
                newCell = newRow.insertCell();
 | 
			
		||||
                item = document.createTextNode(i.widget.name);
 | 
			
		||||
                newCell.appendChild(item)
 | 
			
		||||
 | 
			
		||||
                let cur = formatCurrency(i.transaction.amount)
 | 
			
		||||
                newCell = newRow.insertCell();
 | 
			
		||||
                item = document.createTextNode(cur + "/month");
 | 
			
		||||
                newCell.appendChild(item)
 | 
			
		||||
 | 
			
		||||
            });
 | 
			
		||||
            } else {
 | 
			
		||||
                let newRow = tbody.insertRow();
 | 
			
		||||
                let newCell = newRow.insertCell();
 | 
			
		||||
                newCell.setAttribute("colspan", "4");
 | 
			
		||||
                newCell.innerHTML = "No data available";
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function formatCurrency(amount) {
 | 
			
		||||
    let c = parseFloat(amount/100);
 | 
			
		||||
    return c.toLocaleString("fr-FR", {
 | 
			
		||||
        style:"currency",
 | 
			
		||||
        currency: "EUR",
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user