Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def get_duplicated_epin() do
- Temp.track!()
- {:ok, _pd, file} = Temp.open(%{prefix: "Getrecharge_duplicate_stock", suffix: "sales.csv"})
- key = ["buying_price", "csv_id", "inserted_at", "order_id","pin", "product_name","provider", "provider_order_id","sale_type", "serial_number", "sold_date"]
- query = from(
- s in Sales,
- where: s.salestype == "epin" and s.status == "success",
- select: s.epinstock_id
- )
- list =
- Repo.all(query)
- |> Enum.group_by(&(&1))
- |> Enum.filter(fn {_, [_,_|_]} -> true; _ -> false end)
- |> Enum.map(fn {x, _} -> x end)
- |> Enum.map(fn x ->
- query = from(
- s in Sales,
- where: s.salestype == "epin" and s.status == "success" and s.epinstock_id == ^x,
- join: e in Epinstocks,
- where: s.epinstock_id == e.id,
- join: p in Products,
- where: s.product_id == p.id,
- select: %{
- :buying_price => s.buying_price,
- :csv_id => e.csvfile,
- :inserted_at => s.inserted_at,
- :order_id => s.merchant_order_id,
- :pin => e.pin,
- :product_name => p.name,
- :provider => s.provider,
- :provider_order_id => e.batch,
- :sale_type => s.salestype,
- :serial_number => s.epin_serial,
- :sold_date => s.updated_at,
- }
- )
- Repo.all(query)
- end )
- list
- |> List.flatten()
- |> Enum.map(fn x -> Map.values(QueryHelpers.get_purchase_date(x)) end)
- |> List.insert_at(0, key)
- |> CSV.encode()
- |> Enum.each(&File.write(file, &1, [:append]))
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement