github.com/decred/politeia@v1.4.0/politeiawww/cmd/cmswww/invoicepayouts.go (about)

     1  // Copyright (c) 2017-2019 The Decred developers
     2  // Use of this source code is governed by an ISC
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import (
     8  	"fmt"
     9  	"time"
    10  
    11  	v1 "github.com/decred/politeia/politeiawww/api/cms/v1"
    12  	"github.com/decred/politeia/politeiawww/cmd/shared"
    13  )
    14  
    15  // InvoicePayoutsCmd request the invoices that were paid out in the specified
    16  // month/year.
    17  type InvoicePayoutsCmd struct {
    18  	Args struct {
    19  		Month uint `positional-arg-name:"month"`
    20  		Year  uint `positional-arg-name:"year"`
    21  	} `positional-args:"true" required:"true"`
    22  }
    23  
    24  // Execute executes the invoice payouts command
    25  func (cmd *InvoicePayoutsCmd) Execute(args []string) error {
    26  	// Fetch CSRF tokens
    27  	_, err := client.Version()
    28  	if err != nil {
    29  		return fmt.Errorf("Version: %v", err)
    30  	}
    31  
    32  	if cmd.Args.Month == 0 || cmd.Args.Year == 0 {
    33  		return fmt.Errorf("month and year are both required to determine invoice date range")
    34  	}
    35  
    36  	startDate := time.Date(int(cmd.Args.Year), time.Month(int(cmd.Args.Month)),
    37  		0, 0, 0, 0, 0, time.UTC)
    38  	endDate := time.Date(int(cmd.Args.Year), time.Month(int(cmd.Args.Month+1)),
    39  		0, 0, 0, 0, 0, time.UTC)
    40  
    41  	lip := v1.InvoicePayouts{
    42  		StartTime: startDate.Unix(),
    43  		EndTime:   endDate.Unix(),
    44  	}
    45  	// Send request
    46  	lipr, err := client.InvoicePayouts(&lip)
    47  	if err != nil {
    48  		return fmt.Errorf("error InvoicePayouts: %v", err)
    49  	}
    50  
    51  	// Print response details
    52  	return shared.PrintJSON(lipr)
    53  }