/// <summary> /// Open an Account record from the database. /// </summary> /// <param name="Id">The id (primary key) of the Account to open.</param> /// <remarks>Created: Werner Scheffer 27/02/2012</remarks> public override void OpenRecord(Int64 Id) { try { glxTax = BL.GLX.GLX_Tax.Load(Id, DataContext); } catch (Exception ex) { if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex)) { throw ex; } } }
/// <summary> /// The binding source is bound to a new instance of an Tax. This is for the instances where a new record is to be created. /// </summary> /// <remarks>Created: Theo Crous 17/11/2011</remarks> protected override void OnNewRecord() { try { base.OnNewRecord(); glxTax = BL.GLX.GLX_Tax.New; } catch (Exception ex) { if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex)) { throw ex; } } }
internal static String Save(DB.GLX_Tax entry, DataContext dataContext) { try { if (dataContext.EntityAccountingContext.GetEntityState(entry) == System.Data.Entity.EntityState.Detached) { dataContext.EntityAccountingContext.GLX_Tax.Add(entry); } } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { return(dataContext.PackageValidationException()); } return("Success"); }
/// <summary> /// Loads and opens the previous Tax record. The current record is not saved. /// </summary> /// <remarks>Created: Theo Crous 01/08/2012</remarks> protected override void OnPreviousRecord() { try { base.OnPreviousRecord(); DB.GLX_Tax glxTax = BL.GLX.GLX_Tax.GetPreviousItem((DB.GLX_Tax)BindingSource.DataSource, DataContext); if (glxTax != null) { BindingSource.DataSource = glxTax; } } catch (Exception ex) { if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex)) { throw ex; } } }
public static List <DB.GLX_Header> CreateReceipts(DataRow[] rows, Dictionary <Int64, String> accountsColumns, Dictionary <string, GLX.PaymentAccount> paymentAccounts, DataContext dataContext) { List <DB.GLX_Header> headers = new List <DB.GLX_Header>(); foreach (DataRow row in rows) { // Make a new header entry DB.GLX_Header header = GLX.GLX_Header.New; //GET PERIOD FROM DATE header.PeriodId = SYS.SYS_Period.Load(Convert.ToDateTime(row["colEntryDate"]), dataContext).Id; header.Date = Convert.ToDateTime(row["colEntryDate"]); header.PostedDate = Convert.ToDateTime(row["colEntryDate"]).Date; header.Reference = Convert.ToString(row["colEntryReference"]); header.StatusId = (byte)SYS.SYS_Status.Posted; if (Convert.ToDecimal(row["colTotal"]) >= 0) { header.Description = "DEBTOR PAYMENT RECEIVED"; header.JournalTypeId = (byte)GLX.GLX_JournalType.Receipts; } else { header.Description = "DEBTOR PAYMENT REVERSAL"; header.JournalTypeId = (byte)GLX.GLX_JournalType.Reversal; } if (row["TrackNumber"] != DBNull.Value && Convert.ToInt64(row["TrackNumber"]) != -1) { header.TrackId = Convert.ToInt64(row["TrackNumber"]); } else { header.TrackId = -1; } // Add the lines DB.GLX_Line linedebtor = GLX.GLX_Line.New; linedebtor.EntityId = Convert.ToInt64(row["AccountId"]); header.ReferencePeriodId = header.PeriodId; linedebtor.AgingId = Convert.ToByte(row["colEntryAging"]); linedebtor.Amount = 0; header.GLX_Line.Add(linedebtor); Dictionary <Int64, Decimal> taxAccounts = new Dictionary <Int64, Decimal>(); foreach (var pair in accountsColumns) { GLX.PaymentAccount pa = paymentAccounts[pair.Value]; Decimal val = Convert.ToDecimal(row[pair.Value]); if (val != 0) { DB.GLX_Line line = GLX.GLX_Line.New; header.GLX_Line.Add(line); line.EntityId = pair.Key; line.AgingId = !dataContext.EntityAccountingContext.GLX_Account.Where(n => n.Id.Equals(pair.Key)).Select(n => n.AgingAccount).FirstOrDefault() ? (byte)1 : linedebtor.AgingId; DB.GLX_Tax taxType = dataContext.EntityAccountingContext.GLX_Tax.FirstOrDefault(n => n.Id == pa.TaxId); if (taxType != null && taxType.Percentage != 0) { line.Amount = Math.Round(val / (1 + taxType.Percentage), 2, MidpointRounding.AwayFromZero); taxAccounts.Add(taxType.EntityId.Value, Math.Round(val - line.Amount, 2, MidpointRounding.AwayFromZero)); } else { line.Amount = val; } linedebtor.Amount -= val; // Credit the debtor with the indicated amount } } foreach (var account in taxAccounts.GroupBy(account => account.Key).Select(amount => new { id = amount.Key, amount = amount.Sum(account => account.Value) })) { DB.GLX_Line line = GLX.GLX_Line.New; line.EntityId = account.id; line.AgingId = linedebtor.AgingId; line.Amount = account.amount; header.GLX_Line.Add(line); } headers.Add(header); } return(headers); }
protected override bool SaveSuccessful() { try { using (new CDS.Client.Desktop.Essential.UTL.WaitCursor()) { this.OnSaveRecord(); if (!IsValid) { return(false); } foreach (BulkPaymentEntry mainLine in BulkPaymentEntries) { Int64 trackingNumber = -1; // Make a new header entry DB.GLX_Header header = BL.GLX.GLX_Header.New; header.TrackId = -1; header.PeriodId = mainLine.PeriodId.Value; header.ReferencePeriodId = mainLine.PeriodId.Value; header.Date = mainLine.Date.Value; header.PostedDate = BL.ApplicationDataContext.Instance.ServerDateTime.Date; header.Reference = mainLine.Reference; header.Description = mainLine.Description; header.StatusId = 52; if (mainLine.Amount >= 0) { // header.Description = "CREDITOR PAYMENT RECEIVED"; header.JournalTypeId = (byte)BL.GLX.GLX_JournalType.Payment; } else { // header.Description = "CREDITOR PAYMENT REVERSAL"; header.JournalTypeId = (byte)BL.GLX.GLX_JournalType.Reversal; } //Double check if this has a use if (!trackingNumber.Equals(-1)) { header.TrackId = trackingNumber; } //Loop through INV or C/N or BBF (Agings) foreach (var agingAmount in mainLine.BulkPaymentItems.Where(n => n.Checked.Equals(true)).GroupBy(g => g.AgingId).Select(l => new { AgingId = l.Key, Balance = l.Sum(i => i.Balance) })) { //DEBTOR LINE DB.GLX_Line linecreditor = BL.GLX.GLX_Line.New; //TODO: ACCOUNT NOT LOADING ON subLine linecreditor.EntityId = mainLine.AccountId.Value; linecreditor.AgingId = agingAmount.AgingId; linecreditor.Amount = -agingAmount.Balance; header.GLX_Line.Add(linecreditor); } //BANK LINE DB.GLX_Line linebank = BL.GLX.GLX_Line.New; linebank.EntityId = Convert.ToInt64(ddlAccount.EditValue); linebank.AgingId = 1; linebank.Amount = mainLine.Amount; header.GLX_Line.Add(linebank); //SETTLEMENT DISCOUNT TAX LINE DB.GLX_Line linesettlementtax = BL.GLX.GLX_Line.New; DB.GLX_Tax taxType = DataContext.EntityAccountingContext .GLX_Tax.FirstOrDefault(n => n.Id == PaymentAccounts .Where(nn => nn.AccountId.Equals(((DB.GLX_Account)ddlSettlementAccount.GetSelectedDataRow()).Id)) .Select(nn => nn.TaxId).FirstOrDefault()); if (taxType != null && taxType.Percentage != 0) { linesettlementtax.Amount = mainLine.Settlement * (1 - taxType.Percentage); } else { linesettlementtax.Amount = mainLine.Settlement; } header.GLX_Line.Add(linesettlementtax); //SETTLEMENT DISCOUNT LINE DB.GLX_Line linesettlement = BL.GLX.GLX_Line.New; linesettlement.EntityId = Convert.ToInt64(ddlSettlementAccount.EditValue); linesettlement.AgingId = 1; linesettlement.Amount = mainLine.Settlement - linesettlementtax.Amount; header.GLX_Line.Add(linesettlement); //Change the subLines's tracking number to the new tracking number foreach (var subLine in mainLine.BulkPaymentItems.Where(n => n.Checked.Equals(true))) { BL.GLX.GLX_Header.UpdateTrackNumber(subLine.HeaderId, trackingNumber, DataContext); } } return(true); } } catch (Exception ex) { HasErrors = true; if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex)) { throw ex; } return(false); } }
public static DB.GLX_Tax GetPreviousItem(DB.GLX_Tax glx_tax, DataContext dataContext) { return(dataContext.EntityAccountingContext.GLX_Tax.OrderByDescending(o => o.Name).Where(n => n.Name.CompareTo(glx_tax.Name) < 0 && n.Name.CompareTo(glx_tax.Name) != 0).FirstOrDefault()); }