$.ajax({
type: "GET",
dataType: "JSON",
url: 'https://famagas-api.herokuapp.com/api/itapeCompanyNews',
success: function(allResponseThree) {
// Native Array
var receivedDataThree = [];
// Group Received JSON By Total Of Purchased
for (var i = 0; i < allResponseThree.length; i++) {
// Group Received JSON By Total Of Purchased
var totalOfPurchased = allResponseThree[i].purchase_history;
for (var x = 0; x < totalOfPurchased.length; x++) {
// Declare Variables Containing Extend Details
var purchasedProductNested = totalOfPurchased[x].purchasedProduct;
var dateOfPurchased = totalOfPurchased[x].dateOfPurchased;
var quantityOfPurchasedNested = totalOfPurchased[x].quantityPurchased;
var totalOfPurchasedNested = totalOfPurchased[x].totalOfPurchased;
var totalOfDiscountsPurchasedNested = totalOfPurchased[x].discountsToConsider;
// Format The Money So That It Is Possible To Count
totalOfPurchasedNested = totalOfPurchasedNested.replace(/\./g, "").replace(",", ".");
totalOfDiscountsPurchasedNested = totalOfDiscountsPurchasedNested.replace(/\./g, "").replace(",", ".");
// Final JSON Array Containing Extend Details
var allResponseThreeWithExtendDetails = {
product: purchasedProductNested,
dateOfPurchased: dateOfPurchased,
quantity: JSON.parse(quantityOfPurchasedNested),
totalPurchased: JSON.parse(totalOfPurchasedNested),
totalDiscounts: JSON.parse(totalOfDiscountsPurchasedNested)
};
// Push Group With Received JSON In Native Array
receivedDataThree.push(allResponseThreeWithExtendDetails);
}
}
// Set Locale For Moment JS
moment.locale("pt-BR");
var todayDate = moment();
var sortDate = _.filter(receivedDataThree, function(desc) {
return moment(desc.dateOfPurchased, "DD/MM/YYYY").isAfter(todayDate.subtract(30, 'days'))
});
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.