public void MigrateDependenciesTo(Payout migrationTarget) { if (Identity > 0 && migrationTarget.Identity > 0) { // Persisted payout migration SwarmDb.GetDatabaseForWriting().MovePayoutDependencies(Identity, migrationTarget.Identity); } else { // In-memory migration: this payout isn't in database yet this.DependentCashAdvancesPayback.ForEach(item => migrationTarget.DependentCashAdvancesPayback.Add(item)); this.DependentCashAdvancesPayout.ForEach(item => migrationTarget.DependentCashAdvancesPayout.Add(item)); this.DependentExpenseClaims.ForEach(item => migrationTarget.DependentExpenseClaims.Add(item)); this.DependentInvoices.ForEach(item => migrationTarget.DependentInvoices.Add(item)); this.DependentSalariesNet.ForEach(item => migrationTarget.DependentSalariesNet.Add(item)); this.DependentSalariesTax.ForEach(item => migrationTarget.DependentSalariesTax.Add(item)); this.DependentCashAdvancesPayback = new CashAdvances(); this.DependentCashAdvancesPayout = new CashAdvances(); this.DependentExpenseClaims = new ExpenseClaims(); this.DependentInvoices = new InboundInvoices(); this.DependentSalariesNet = new Salaries(); this.DependentSalariesTax = new Salaries(); } migrationTarget.RecalculateAmount(); RecalculateAmount(); }
private void LoadDependencies() { DependentExpenseClaims = new ExpenseClaims(); DependentInvoices = new InboundInvoices(); DependentSalariesNet = new Salaries(); DependentSalariesTax = new Salaries(); DependentCashAdvancesPayout = new CashAdvances(); DependentCashAdvancesPayback = new CashAdvances(); BasicFinancialDependency[] dependencies = SwarmDb.GetDatabaseForReading().GetPayoutDependencies(this.Identity); foreach (BasicFinancialDependency dependency in dependencies) { switch (dependency.DependencyType) { case FinancialDependencyType.ExpenseClaim: DependentExpenseClaims.Add(ExpenseClaim.FromIdentity(dependency.ForeignId)); break; case FinancialDependencyType.InboundInvoice: DependentInvoices.Add(InboundInvoice.FromIdentity(dependency.ForeignId)); break; case FinancialDependencyType.Salary: Salary salary = Salary.FromIdentity(dependency.ForeignId); if (salary.NetSalaryCents == this.AmountCents) // HACK: Assumes that tax total is not identical { DependentSalariesNet.Add(salary); } else { DependentSalariesTax.Add(salary); } break; case FinancialDependencyType.CashAdvance: DependentCashAdvancesPayout.Add(CashAdvance.FromIdentity(dependency.ForeignId)); break; case FinancialDependencyType.CashAdvancePayback: DependentCashAdvancesPayback.Add(CashAdvance.FromIdentity(dependency.ForeignId)); break; default: throw new NotImplementedException("Unknown financial dependency type in Payout.LoadDependencies(): " + dependency.ToString()); } } }
private static void AddUnpaidInboundInvoices(Payouts payoutList, int organizationId) { InboundInvoices invoices = InboundInvoices.ForOrganization(Organization.PPSE); foreach (InboundInvoice invoice in invoices) { if (invoice.Attested) { BasicPayout basicPayout = new BasicPayout(0, organizationId, string.Empty, invoice.PayToAccount, invoice.Ocr.Length > 0? "OCR " + invoice.Ocr : "Ref# " + invoice.InvoiceReference, (Int64)(invoice.Amount * 100), invoice.DueDate, false, DateTime.Now, 0); Payout payout = Payout.FromBasic(basicPayout); payout.DependentInvoices.Add(invoice); payoutList.Add(payout); } } }
private static void AddUnpaidInboundInvoices(Payouts payoutList, Organization organization) { InboundInvoices invoices = InboundInvoices.ForOrganization(organization); foreach (InboundInvoice invoice in invoices) { if (invoice.Attested) { BasicPayout basicPayout = new BasicPayout(0, organization.Identity, string.Empty, invoice.PayToAccount, invoice.Ocr.Length > 0 ? invoice.Ocr : invoice.InvoiceReference, // prefer OCR (automatic) over Reference (manual) (Int64)(invoice.Amount * 100), invoice.DueDate, false, DateTime.Now, 0); Payout payout = Payout.FromBasic(basicPayout); payout.DependentInvoices.Add(invoice); payoutList.Add(payout); } } }
public static Dictionary <int, Int64> GetBudgetAttestationSpaceAdjustments(Organization organization) { // This function returns a dictionary for the cents that are either accounted for but not attested, // or attested but accounted for, to be used to understand how much is really left in budget // Positive adjustment means more [cost] budget available, negative less [cost] budget available if (_organizationBudgetAttestationSpaceLookup.ContainsKey(organization.Identity)) { return(_organizationBudgetAttestationSpaceLookup [organization.Identity]); } // TODO: This is expensive research, we should cache this result and clear cache on any attestation or create op Dictionary <int, Int64> result = new Dictionary <int, long>(); // Cash advances are accounted for when paid out. Make sure they count toward the budget when attested. CashAdvances advances = CashAdvances.ForOrganization(organization); foreach (CashAdvance advance in advances) { if (!result.ContainsKey(advance.BudgetId)) { result[advance.BudgetId] = 0; } if (advance.Attested) { result[advance.BudgetId] -= advance.AmountCents; } } // Expense claims, Inbound invoices, and Salaries are accounted for when filed. Make sure they DON'T // count toward the budget while they are NOT attested. ExpenseClaims claims = ExpenseClaims.ForOrganization(organization); // gets all open claims foreach (ExpenseClaim claim in claims) { if (!result.ContainsKey(claim.BudgetId)) { result[claim.BudgetId] = 0; } if (!claim.Attested) { result[claim.BudgetId] += claim.AmountCents; } } InboundInvoices invoices = InboundInvoices.ForOrganization(organization); foreach (InboundInvoice invoice in invoices) { if (!result.ContainsKey(invoice.BudgetId)) { result[invoice.BudgetId] = 0; } if (!invoice.Attested) { result[invoice.BudgetId] += invoice.AmountCents; } } Salaries salaries = Salaries.ForOrganization(organization); foreach (Salary salary in salaries) { if (!result.ContainsKey(salary.PayrollItem.BudgetId)) { result[salary.PayrollItem.BudgetId] = 0; } if (!salary.Attested) { result[salary.PayrollItem.BudgetId] += (salary.GrossSalaryCents + salary.AdditiveTaxCents); } } _organizationBudgetAttestationSpaceLookup[organization.Identity] = result; return(result); }