public void btnCreateCashbook_AutoOffset_Click(object sender, EventArgs e) { var newCashbook = Sybiz.Vision.Platform.Cashbook.Transaction.Cashbook.NewObject(null); try { var bankAccountId = GetBankAccountId(); var customerId = GetCustomerAccountId(); var offsetAmount = GetOffSetAmount(); newCashbook.BankAccount = bankAccountId; newCashbook.OffsetMethod = Sybiz.Vision.Platform.Core.Enumerations.OffsetMethod.ByTransaction; newCashbook.DefaultGroupReference = GetCashBookGroupReference(); newCashbook.Description = GetCashBookDescription(); Sybiz.Vision.Platform.Cashbook.Transaction.ICashbookTransactionLine line = default(Sybiz.Vision.Platform.Cashbook.Transaction.ICashbookTransactionLine); line = CreateNewCashbookTransactionLine(newCashbook, Sybiz.Vision.Platform.Core.Enumerations.CashbookTransactionLineType.DR, customerId, offsetAmount, 0M, newCashbook.DefaultGroupReference, "DR OFFSET"); line.Description = "Customer Payment of Invoice"; Sybiz.Vision.Platform.Core.Transaction.ITransactionLineOffsets data = (Sybiz.Vision.Platform.Core.Transaction.ITransactionLineOffsets)line; data.AutomaticallyOffset(); //Only process transactions that are processable, otherwise check if valid before saving. //GetBrokenRuleInfo navigates to all children objects and gets all broken rules (including warnings and information messages) if (newCashbook.IsProcessable) { newCashbook = newCashbook.Process(); MessageBox.Show($"Transaction succesfully created/processed for [{newCashbook.TransactionNumber}]"); } else if (newCashbook.IsValid) { foreach (var rule in newCashbook.GetBrokenRuleInfo().Where(obj => obj.Severity == Csla.Validation.RuleSeverity.Error)) { MessageBox.Show($"{rule.PropertyName} is broken on object {rule.ObjectLevel} because '{rule.Description}'"); } newCashbook = newCashbook.Save(); MessageBox.Show($"Transaction succesfully saved for [{newCashbook.TransactionNumber}]"); } } catch (Exception ex) { foreach (var rule in newCashbook.GetBrokenRuleInfo().Where(obj => obj.Severity == Csla.Validation.RuleSeverity.Error)) { MessageBox.Show($"{rule.PropertyName} is broken on object {rule.ObjectLevel} because '{rule.Description}'"); } MessageBox.Show($"Error creating transaction {ex.Message}"); } }
public void btnCreateCashbook_ByOffset_Click(object sender, EventArgs e) { var newCashbook = Sybiz.Vision.Platform.Cashbook.Transaction.Cashbook.NewObject(null); try { var bankAccountId = GetBankAccountId(); var customerId = GetCustomerAccountId(); var transactionId = GetOffTransactionToOffset(); var offsetAmount = GetOffSetAmount(); newCashbook.BankAccount = bankAccountId; newCashbook.OffsetMethod = Sybiz.Vision.Platform.Core.Enumerations.OffsetMethod.ByOffset; newCashbook.DefaultGroupReference = GetCashBookGroupReference(); newCashbook.Description = GetCashBookDescription(); Sybiz.Vision.Platform.Cashbook.Transaction.ICashbookTransactionLine line = default(Sybiz.Vision.Platform.Cashbook.Transaction.ICashbookTransactionLine); line = CreateNewCashbookTransactionLine(newCashbook, Sybiz.Vision.Platform.Core.Enumerations.CashbookTransactionLineType.DR, customerId, 0M, 0M, newCashbook.DefaultGroupReference, "DR OFFSET"); line.Description = "Customer Payment of Invoice"; //do this to load the list of offsets var offsets = ((Sybiz.Vision.Platform.Cashbook.Transaction.CashbookLineDR)line).Offsets; var offsetRecord = offsets.FirstOrDefault(ofs => ofs.TransactionId == transactionId && ofs.TransactionType == Sybiz.Vision.Platform.Core.Enumerations.TransactionType.SalesInvoice); if (offsetRecord != null) { offsetRecord.Process = true; //setting this to true is optional as assigning a value will also set to true offsetRecord.Amount = offsetAmount; } else { MessageBox.Show("Invalid transaction selection - process cancelled"); return; } //Only process transactions that are processable, otherwise check if valid before saving. //GetBrokenRuleInfo navigates to all children objects and gets all broken rules (including warnings and information messages) if (newCashbook.IsProcessable) { newCashbook = newCashbook.Process(); MessageBox.Show($"Transaction succesfully created/processed for [{newCashbook.TransactionNumber}]"); } else if (newCashbook.IsValid) { foreach (var rule in newCashbook.GetBrokenRuleInfo().Where(obj => obj.Severity == Csla.Validation.RuleSeverity.Error)) { MessageBox.Show($"{rule.PropertyName} is broken on object {rule.ObjectLevel} because '{rule.Description}'"); } newCashbook = newCashbook.Save(); MessageBox.Show($"Transaction succesfully saved for [{newCashbook.TransactionNumber}]"); } } catch (Exception ex) { foreach (var rule in newCashbook.GetBrokenRuleInfo().Where(obj => obj.Severity == Csla.Validation.RuleSeverity.Error)) { MessageBox.Show($"{rule.PropertyName} is broken on object {rule.ObjectLevel} because '{rule.Description}'"); } MessageBox.Show($"Error creating transaction {ex.Message}"); } //Use linq for this instead //For Each offsetLine In offsets // If Not offsetLine.Process AndAlso offsetLine.TransactionNumber.Equals(transactionReference) Then // offsetLine.Process = True // offsetLine.Amount = line.Total 'set Amount to how much you wish to pay - setting process to true assumes whole amount // End If //Next }