Retrieve all products prices with multiple currency options - node.js

I have two products A and B with two prices each (1 monthly and 3 months cycle).
Every price has two currency options (USD and EUR).
I'm able to list all the prices using :
const prices = await stripe.prices.list({});
But it doesn't return the currency options for each product prices. I only get the price in the default currency (USD).
How can retrieve prices with all the currencies ?
I tried this :
const businessOwnerProduct = await stripe.prices.retrieve(
'price_xxxxxxxxxxxxxx',
{expand: ['currency_options']}
);
But it returns the price per product. Thus i need multiple requests (4).
Is there a way to retrieve a list of products + prices (in multiple currencies) ?

The currency_options property is not returned by default. This is what Stripe calls an "includable" property. The idea is that it's costly to render as you could have many currencies and so you have to explicitly ask for it when you retrieve it using their Expand feature.
This is what your second example does where you expand it when calling the Retrieve Price API.
The Expand feature also works during a list call as documented here. So your code should look like this:
const prices = await stripe.prices.list({
expand: ['data.currency_options'],
});
Note the data. prefix as the API return a List which has the data array with 10 Prices by default

Related

Stripe modelling prices that are a % of revenue of customer

I have a case where customers that use the product generate revenue with it and a small percentage should be paid to my company in return.
I wonder how to model that in stripe. If all customers would make their revenue in the same currency I could setup a usage based price in EUR that reflects the percentage and for each customer generated revenue could create a UsageRecord with an amount that represents the revenue e.g. EUR-Cent like with below code.
However I have customers with multiple currencies and thus their revenue comes in multiple currencies too. And then I cannot use the approach as the UsageRecord just states an amount but not currency. And the amount*pricePerAmount in Currency is specified in the UsagePrice. Thus I would report amounts in a different currency which with this approach would be considered to be in EUR - i.e. that wouldn't work.
const record: Stripe.UsageRecord = await this.stripe.subscriptionItems.createUsageRecord(subscription.stripeUsageSubscriptionItem,
{
quantity: order.customerPrice * 100,
timestamp: Math.trunc(order.createdDate.getTime() / 1000),
action: 'increment',
},
{
idempotencyKey: idempotencyKey
}
);
Also I dont want to create a price item for each currency and apply the UsageRecord to that price since I would need to create lots of such prices(one per currency).
Or should I jsut for each customer order create a paymentintent with the right amount sort of manually?
Weird thing to me is that Stripe itself charges the same way i.e. percent of revenue we make over it - so they somehow can do it right?
Thanks
Tom

UOM and UOM ratio incorrect on Pick Ticket

We use UOM conversions at this client. We stock in Eaches and sell in Cases. The problem we are having with the Pick ticket is that both the quantity to be picked and the UOM being picked are the stocking unit and not the selling unit.
e.g. The customer orders 73 cases (12 ea per case). The pick ticket prints 876 each. This requires the warehouse person to look up each item determine if there is a Selling UOM and ratio and to then manually convert 876 eaches to 73 cases.
Obviously, the pick ticket should print 73 cases. But I cannot find a way to do this. The items are lotted and an order of 73 case might have 50 cases of Lot A and 23 cases of Lot B. This is represented in the SOShipLineSplit table. The quantities and UOM in this table are based on Stocking units.
Ideally, I could join the INUnits table to both the SOSHipLine and SOShipLineSPlit table. See Below.
Select case when isnull(U.UnitRate,0) = 0 then S.Qty else S.Qty/U.Unitrate end as ShipQty
,case when isnull(U.UnitRate,0) = 0 then s.uom else U.FromUnit end as UOM
from SOShipLineSplit S
inner join SOShipLine SL
ON S.CompanyID = SL.CompanyID and s.ShipmentNbr = SL.ShipmentNbr and S.LineNbr = SL.LineNbr and S.InventoryID = SL.InventoryID
Left Outer Join INUnit U
On S.CompanyID = U.CompanyID and S.InventoryID = U.InventoryID and s.UOm = U.ToUnit and SL.UOM = U.FromUnit
where S.ShipmentNbr = '000161' and S.CompanyId = 4
The problem is the Acumatica Report writer does not support a join with multiple tables.
Left Outer Join INUnit U
On S.CompanyID = U.CompanyID and S.InventoryID = U.InventoryID and s.UOm = U.ToUnit and SL.UOM = U.FromUnit
I believe I must be missing something. This cannot be the only client using Acumatica who utilizes Selling Units of Measure. Is there another table I could use that would contain the quantities and UOM already converted for this order to Selling Units?
Or another solution?
Thanks in advance.
pat
EDIT:
If the goal is to display accurate quantities before/after conversion then INUnit DAC can't be used. It doesn't store historical data, you can change INUnit values after an order has been finalized so re-using it to compute quantities will not yield accurate results.
For that scenario you would need to use the historical data fields with Base prefixes like ShippedQuantity/BaseShippedQuantity. If you require to store more historical data you need to add a custom field to hold these values and update them when shipment is created/modified.
The main issue appears to be a logical error in the requirement:
The problem is that the INUnit table has to be joined to BOTH the
SOShipLine and the SOShipLineSplit tables.
INUnit DAC has a single parent, not 2 so you need to change your requirement to reflect that constraint.
If SOShipLine and SOShipLineSplit values differ then you'll never get any record.
If they are identical then there's no need to join on both since they have the same value.
I suggest to add 2 joins, one for SOShipLine and another for SOShipLineSplit. In the report you can choose which one to display (1st, 2nd or both).
You can also add visibility conditions or IIF formula condition in the report if you want to handle null values error check for display purpose.
Use the Child Alias property in schema builder to join the same table 2 times without name conflicts. In the report formulas (to display field or in formula conditions) use the Child Alias table name too.
Example:

NetSuite get transactions that do not contain items with specified attributes

I am attempting to create a list of open pending approval sales orders that do not contain items with specific values defined in a custom field. I am able to do this when the sales order contains only items that meet this criteria. However, when their are two items and one meets while the other does not my search is no longer valid.
I have two sales orders. Sales order 123 has a shipping method of Ground, while Sales order 321 has an item with Shipping method of Ground and shipping method of Freight. I expect to get only Sales order 123 returned.
I made this formula in criteria section:
CASE WHEN {item.custitem_shippingmethod} = 'Freight' Or {item.custitem_shippingmethod} = 'Free Freight' THEN 1 ELSE 0 END
but got both orders returned. I tried using the same formula in the summary criteria but that also did not work. Any suggestions?
Picture of Criteria in NetSuite
Thank you!
You could potentially use summary criteria. It's practical but it's not the cleanest looking search. You need to have a corresponding formula column in your results for it to work:
Group by Document Number.
Create a formula (Numeric) result column with summary type of Sum using your above formula.
Create a summary criteria of type formula (Numeric) with summary of type Sum
and use the same formula and set the value to be less than 0.
This will return only records that do not include those shipping
methods.
Alternatively, have you considered running the logic (workflow/suitescript) when the record is saved and storing a checkbox value such as "Does not include freight"? It would make searches based on that criteria easier.
For example if you store the ship method on the line, something like:
// Set your freight method indexes
var freightMethods = ['1','2']
var itemLinesCount = nlapiGetLineItemCount('item');
// If a line is found with one of the freight methods you're looking for then mark the record.
for(var i = 1; i < itemLinesCount; i++)
{
var shipMethod = nlapiGetLineItemValue('item', 'custcol_shipmethod', i);
if(freightMethods.indexOf(shipMethod) !== -1)
{
nlapiSetFieldValue('custbody_includes_freight', 'T');
break;
}
}
If you store the ship method only on the item record it can be a bit trickier to manipulate (due to the way Netsuite handles item record types).
Does the line being returned have a freight value or are you getting another line from the same order?

How to query a view in cloudant using startkey and endkey where key has two elements in it?

I have a requirement to filter some records on the basis of period for example get me all products count between 201704 and 201705.
So my emit is something like:
emit([doc.productId, doc.period],1)
and reduce used is _count. But when i am trying to filter on startkey and endkey it gives me all records. I am trying something like:
startkey=["201604"]&endkey=[{},"201605"]
where my key structure is something like key:
[
"aws-60826348802",
201703
]
I dont want to reverse the order of elements in key as i want a count on ids by defining the group_level=1. Could anyone help me out. I did not get any solution yet.
In order to be able to select (with startkey/endkey), your index needs to be in in that order. Let's say your docs look like this:
{
"_id": "someid",
"product": "aws-60826348802",
"date": "201604",
"price": 42.42
}
You could create a map function to index the documents in date order like so:
function(doc) {
emit([doc.date, doc.product], doc.price);
}
You now have a two-dimensional key (on date & product code) and the value is emitted is the price.
This allows you to select items by date:
?startkey=["201604"] // find items where the date is >= 201604
?startkey=["201604"]&endkey=["201605"] // find items in April 2016
if you choose a reducer (_count, _sum, or _stats) you can also perform aggregation:
?startkey=["201601"]&endkey=["201701"]&group_level=1 // find items in 2016, group by month
?startkey=["201601"]&endkey=["201701"]&group_level=2 // find items in 2016, grouped by month and product code
This could get you monthly totals of product sales, for example.

Count Index based on Multiple Conditions - Excel

I have a table with order records for each Product Type. The columns contain information like Order Number, Customer Name, Product Category, Product, and Order Receipt Date.
My goal is to find the quantity of orders that fall into the below conditions:
New Customers Ordering any Product Category for the First Time
Existing Customers Ordering from any Product Category for the First Time
Reorders from any Product Category
What would be the best way to go about this?
Think I figured it out:
I created two columns for records: "First Product Type Order?" and "First Order?"
"First_Product_Type_Order": IF(AND(Order2=Order1,Product_Type2=Product_Type1),First_Product_Type_Order1,IF(SUMPRODUCT(($Customer$2:$Customer2=D2)*($Product_Type$2:$Product_Type2=Product_Type2))>1,"Reorder","First Time Order"))
"First_Order":
IF(Order2=Order1,First_Order1,IF(SUMPRODUCT(($Customer$2:$Customer2=Customer2)*1)>1,"Existing Customer","New Customer"))

Resources