augustin-wien / augustina-backend

An open-source web shop designed for selling magazines on the street.
GNU Affero General Public License v3.0
4 stars 0 forks source link

Payout tracking logic #104

Closed jofmi closed 11 months ago

jofmi commented 11 months ago

Type of change

Description

Checklist:

jofmi commented 11 months ago

I am not sure what this linter error means. Any ideas?

Running golangci-lint ...
  /home/runner/work/_temp/reviewdog-P3LjpF/golangci-lint-1.55.0-linux-amd64/golangci-lint run --out-format line-number --tests=false
  level=error msg="Running error: context loading failed: failed to load packages: timed out to load packages: context deadline exceeded"
  level=error msg="Timeout exceeded: try increasing it by passing --timeout option"
Error: Error: golangci-lint exited with status code: 4
nanu-c commented 11 months ago

The api/payments/?from=2023-10-22T22:00:00.000Z&to=2023-10-25T22:00:00.000Z&payouts=true should return something like

[
   {
      "ID":6,
      "Timestamp":"2023-10-25T09:38:53.061924Z",
      "Sender":6,
      "Receiver":1,
      "SenderName":"fl-123",
      "ReceiverName":"Cash",
      "Amount":1300,
      "AuthorizedBy":"test_superuser",
      "Order":null,
      "OrderEntry":null,
      "IsSale":false,
      "Payout":null
      "PayoutPayments":[
         //the payments included in the payout
       ]
   }
]
jofmi commented 11 months ago

The api/payments/?from=2023-10-22T22:00:00.000Z&to=2023-10-25T22:00:00.000Z&payouts=true should return something like

[
   {
      "ID":6,
      "Timestamp":"2023-10-25T09:38:53.061924Z",
      "Sender":6,
      "Receiver":1,
      "SenderName":"fl-123",
      "ReceiverName":"Cash",
      "Amount":1300,
      "AuthorizedBy":"test_superuser",
      "Order":null,
      "OrderEntry":null,
      "IsSale":false,
      "Payout":null
      "PayoutPayments":[
         //the payments included in the payout
       ]
   }
]

done! I have called it "IsPayoutFor", which i found a bit more intuitive. is that ok?

nanu-c commented 11 months ago

I would say, the payout site looks like this: image

and then we redirect to the page where all payouts are displayed, which is not happening at the moment.

image

So we don't need a explicit response to the post call.

We can think about to join the item types with their amount and quantity into the payment, but then we need to redefine the type in the frontend for each new item. Currently the the frontend logic is to iterated over all item types and calculate the sum like this:

const sumItemsForOrder = (payment: any, itemID: number) => {
  let sum = 0
  payment.IsPayoutFor.forEach((payout: Payment) => {
    if (payout.Item === itemID) {
      if (payout.Receiver === payment.Sender) {
        sum += payout.Amount
      } else {
        sum -= payout.Amount
      }
    }
  })
  return `${formatAmount(sum)} €`
}