public string Calc1(PayCalcRow sr, PayCalcRow paid, decimal pay, out PayCalcRow rpay) { rpay = new PayCalcRow(); rpay.SetFrom(sr); rpay.SubtractThat(paid); rpay.CASH_REQ = pay; if (rpay.CASH == 0.0M) { return("OK"); } if (rpay.PAY_TAXED == 0.0M && rpay.PAY_NOSAI == 0.0M && rpay.PAY_NOTTAXED == 0.0M) { return("OK"); } var pfx = new PayFx(); var pfx2 = new PayFx(); var pfx3 = new PayFx(); paid.SetTo(pfx, sr); pfx2.SetFrom(pfx); pfx.IncPayByIncCash(pay, rpay.PAY_TAXED, rpay.PAY_NOSAI, rpay.PAY_NOTTAXED); pfx3.SetFrom(pfx); pfx.CalcAll(); pfx.Subtract(pfx2); rpay.SetFrom(pfx); pfx3.Pay = Math.Min(pfx3.Pay, sr.NOTPAID_TAXED); pfx3.PayNs = Math.Min(pfx3.PayNs, sr.NOTPAID_NOSAI); pfx3.PayNt = Math.Min(pfx3.PayNt, sr.NOTPAID_NOTTAXED); pfx3.CalcAll(); rpay.CASH_NOTPAID = pfx3.Cash - paid.CASH_NOTPAID; return("OK"); }
public string Calc2(PayCalcRow sr, PayCalcRow paid, decimal pay, out PayCalcRow rpay) { sr.CASH_NOTPAID = sr.RecalcCashNotPaid(); paid.CASH_NOTPAID = paid.RecalcCashNotPaid(); rpay = new PayCalcRow(); rpay.SetFrom(sr); rpay.SubtractThat(paid); rpay.CASH_REQ = pay; decimal paya = paid.CASH + pay; var paid2 = new PayCalcRow(); paid2.SetFrom(paid); decimal payleft = paya - paid2.CASH; if (PreparingReport) { RepRows.Add(sr.AsCopy("No algas apr.")); RepRows.Add(paid.AsCopy("Jau izmaksāts")); RepRows.Add(rpay.AsCopy("Atlicis")); } int ct1 = 0; if (PreparingReport) { ct1 = RepRows.Count; } if (rpay.CASH <= payleft) { var rpay0 = new PayCalcRow(); rpay0.SetFrom(rpay); paid2.AddThat(rpay0); rpay.SetFrom(rpay0); if (PreparingReport) { RepRows.Add(rpay0.AsCopy("Aprēķins")); RepRows.Add(paid2.AsCopy("Pēc aprēķina")); } return("OK"); } if (rpay.PAY_TAXED == 0.0M && rpay.PAY_NOSAI == 0.0M && rpay.PAY_NOTTAXED == 0.0M) { rpay = new PayCalcRow(); return("OK"); } //not-paid-not-taxed-PF-LI-HI var rpayNPNT = new PayCalcRow(); decimal npnt = rpay.PFNT + rpay.LINT + rpay.HINT; decimal npnt2 = Math.Min(npnt, pay); if (npnt2 > 0.0M) { rpayNPNT.PAY_NOTTAXED = npnt2; rpayNPNT.NOTPAID_NOTTAXED = npnt2; rpayNPNT.PFNT = rpay.PFNT; rpayNPNT.LINT = rpay.LINT; rpayNPNT.HINT = rpay.HINT; if (npnt2 < npnt) { decimal x = npnt2 / npnt; rpayNPNT.PFNT *= x; rpayNPNT.LINT *= x; rpayNPNT.HINT *= x; } rpayNPNT.CASH = npnt2; rpayNPNT.CASH_NOTPAID = npnt2; paid2.AddThat(rpayNPNT); rpay.SetFrom(sr); rpay.SubtractThat(paid2); payleft = paya - paid2.CASH; if (PreparingReport) { RepRows.Add(rpayNPNT.AsCopy("Neapl.iemaks.PF")); RepRows.Add(paid2.AsCopy("Pēc neapl.iemaks.PF")); } if (rpay.CASH <= payleft) { var rpay0 = new PayCalcRow(); rpay0.SetFrom(rpay); paid2.AddThat(rpay0); paid2.RecalcAndRound(); rpay.SetFrom(paid2); rpay.SubtractThat(paid); if (PreparingReport) { RepRows.Add(rpay0.AsCopy("Aprēķins")); RepRows.Add(paid2.AsCopy("Pēc aprēķina")); } return("OK"); } if (rpay.PAY_TAXED == 0.0M && rpay.PAY_NOSAI == 0.0M && rpay.PAY_NOTTAXED == 0.0M) { paid2.RecalcAndRound(); rpay.SetFrom(paid2); rpay.SubtractThat(paid); return("OK"); } } //not-paid-whats-left PayCalcRow rpayNP = null; decimal np = rpay.NOTPAID_TAXED + rpay.NOTPAID_NOSAI + rpay.NOTPAID_NOTTAXED; if (np > 0.0M) { var srNP = new PayCalcRow(); srNP.SetFrom(sr); srNP.PAY_TAXED = rpay.NOTPAID_TAXED; srNP.PAY_NOSAI = rpay.NOTPAID_NOSAI; srNP.PAY_NOTTAXED = rpay.NOTPAID_NOTTAXED; srNP.NOTPAID_TAXED = rpay.NOTPAID_TAXED; srNP.NOTPAID_NOSAI = rpay.NOTPAID_NOSAI; srNP.NOTPAID_NOTTAXED = rpay.NOTPAID_NOTTAXED; Calc1(srNP, paid2, pay - rpayNPNT.CASH, out rpayNP); paid2.AddThat(rpayNP); rpay.SetFrom(paid2); rpay.SubtractThat(paid); payleft = paya - paid2.CASH; if (PreparingReport) { RepRows.Add(rpayNP.AsCopy("Neizm.")); RepRows.Add(paid2.AsCopy("Pēc neizm.")); } if (rpay.CASH <= payleft) { var rpay0 = new PayCalcRow(); rpay0.SetFrom(rpay); paid2.AddThat(rpay0); paid2.RecalcAndRound(); rpay.SetFrom(paid2); rpay.SubtractThat(paid); if (PreparingReport) { RepRows.Add(rpay0.AsCopy("Aprēķins")); RepRows.Add(paid2.AsCopy("Pēc aprēķina")); } return("OK"); } if (rpay.PAY_TAXED == 0.0M && rpay.PAY_NOSAI == 0.0M && rpay.PAY_NOTTAXED == 0.0M) { paid2.RecalcAndRound(); rpay.SetFrom(paid2); rpay.SubtractThat(paid); return("OK"); } } //paid PayCalcRow rpayP = null; Calc1(sr, paid2, paya - paid2.CASH, out rpayP); paid2.AddThat(rpayP); if (PreparingReport) { RepRows.Add(rpayP.AsCopy("Aprēķins")); RepRows.Add(paid2.AsCopy("Pēc aprēķina")); } paid2.RecalcAndRound(); rpay.SetFrom(paid2); rpay.SubtractThat(paid); if (PreparingReport && ct1 > RepRows.Count + 2) { RepRows.Add(rpay.AsCopy("Kopā aprēķins")); } return("OK"); }