Skip to content

Instantly share code, notes, and snippets.

@TechnotronicOz
Created March 23, 2015 22:48
Show Gist options
  • Select an option

  • Save TechnotronicOz/047c1cd073274d5dd72b to your computer and use it in GitHub Desktop.

Select an option

Save TechnotronicOz/047c1cd073274d5dd72b to your computer and use it in GitHub Desktop.
func (me *AdjustmentState) AddUnmatchedAdjustmentsDetails(unmatchedAdjustments []Adjustment) error {
/*unmatchedCount := int64(len(unmatchedAdjustments))
unmatchedSum := float64(0.0)
for _, adjustment := range unmatchedAdjustments {
unmatchedSum -= math.Abs(adjustment.Amount)
}
me.audit.unmatchedAdjustmentInvoiceAmount = number.RoundCurrency(unmatchedSum)
me.audit.unmatchedAdjustmentInvoiceCount = unmatchedCount
return nil*/
unmatchedCount, unmatchedSum := countAndSumAdustments(unmatchedAdjustments)
me.audit.unmatchedAdjustmentInvoiceAmount = unmatchedSum
me.audit.unmatchedAdjustmentInvoiceCount = unmatchedCount
return nil
}
func (me *AdjustmentState) AddMatchedAdjustmentDetails(matchedAdjustments []AdjustmentInvoice) error {
matchedCount := int64(len(matchedAdjustments))
matchedSum := float64(0.0)
for _, adjustment := range matchedAdjustments {
matchedSum -= math.Abs(adjustment.Amount)
}
me.audit.matchedAdjustmentInvoiceAmount = number.RoundCurrency(matchedSum)
me.audit.matchedAdjustmentInvoiceCount = matchedCount
return nil
}
func countAndSumAdustments(adjustments []Adjustment) (adjustmentCount int64, adjustmentAmount float64) {
count := int64(len(adjustments))
sum := float64(0.0)
for _, adjustment := range adjustments {
sum -= math.Abs(adjustment.Amount)
}
sum = number.RoundCurrency(sum)
return count, sum
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment