public static Reconciliation GetReconciliation(long Id, bool isRead) { using (var container = new TransactionModelContainer()) { return container.Reconciliations.FirstOrDefault(x => x.Id == Id && x.IsRead == isRead); } }
protected override void OnStart(string[] args) { try { var runners = new List<Runner>(); using (var container = new TransactionModelContainer()) { var basePaths = container.Configurations.Where(x => x.Group.ToLower() == "basepath").ToArray(); foreach (var path in basePaths) { if (!string.IsNullOrEmpty(path.Value1)) { var slip = new Runner(path.Value1); runners.Add(slip); } if (!string.IsNullOrEmpty(path.Value2)) { var credit = new Runner(path.Value2); runners.Add(credit); } } } if (runners.Count() > 0) { runners.ForEach(x => x.Start()); } } catch (Exception ex) { ErrorLog.Log("ReconciliationFileReader", ex, SystemError.ServiceReader); } }
public static ReconciliationFile GetReconciliationFile(long Id) { using (var container = new TransactionModelContainer()) { return container.ReconciliationFiles.FirstOrDefault(x => x.Id == Id); } }
public RefundResponse CreateRefund(RefundRequest req) { var response = new RefundResponse(); try { using (var container = new TransactionModelContainer()) { var refund = new Refund() { CreatedBy = req.CreateBy, CreatedDate = DateTime.Now, CustomerAddress = req.CustomerAddress, CustomerIdmPartyId = req.CustomerIdmPartyId, CustomerMobilePhoneNo = req.CustomerMobilePhoneNo, CustomerName = req.CustomerName, CustomerRefundAccountName = req.CustomerRefundAccountName, CustomerRefundAccountNo = req.CustomerRefundAccountNo, CustomerRefundBankId = req.CustomerRefundBankId, IsVoid = req.IsVoid, PaymentCode = req.PaymentCode, Ref1 = req.Ref1, Ref2 = req.Ref2, Ref3 = req.Ref3, Remark = req.Remark, Status = req.Status, UpdatedBy = req.UpdateBy, UpdatedDate = DateTime.Now, }; container.Refunds.AddObject(refund); foreach (var r in req.Items) { var refundItem = new RefundItem() { GroupRef1 = r.GroupRef1, GroupRef2 = r.GroupRef2, ItemDescription = r.ItemDescription, Qty = r.Qty, Remark = r.Remark, UnitAmount = r.UnitAmount, }; container.RefundItems.AddObject(refundItem); } container.SaveChanges(); //response.SetPaymentResponse(payment); response.Succeed(); } } catch (Exception ex) { response.Fail(ex); CreateLog(ex); } return response; }
public CalculatePaymentResponse CalculatePayment(CalculatePaymentRequest req) { var res = new CalculatePaymentResponse(); try { using (var container = new TransactionModelContainer()) { var payment = new Payment("SystemService", -1, req.CustomerName, "CARPASS", req.PaymentItems.CreatePaymentItems()); res.CustomerName = payment.CustomerName; res.GrandTotal = payment.GrandTotal(); res.RemainingAmount = payment.RemainingAmount(); res.TotalVatAmount = payment.TotalVat(); res.TotalWithholdingTaxAmount = payment.TotalWithholdingTax(); res.TotalBeforeAdjustment = payment.TotalNoDiscount(); res.TotalAdjustment = payment.TotalDiscount(); res.PaymentItems = payment.PaymentItems.CreateCalculatePaymentItems(); res.Succeed(); } } catch (Exception ex) { res.Fail(ex); CreateLog(ex); } return res; }
public static ReportHeader CreateViewPayment(Payment input, TransactionModelContainer container) { return new ReportHeader { No = string.Format("GAL-{0}-{1}", DateTime.Now.ToString("yyyy-MM"), input.Id), date = DateTime.Now.ToString(ConfigurationManager.Format.Date_Format), PaymentId = input.Id.ToString("0000000000"), PaymentCode = input.PaymentCode, PaymentStatus = input.Status, CustomerIdmId = input.CustomerIdmPartyId.ToString("0000000000"), CustomerName = input.CustomerName, CustomerAddress = input.CustomerAddress, CustomerMobilePhoneNo = input.CustomerMobilePhoneNo, CustomerAccountNo = input.CustomerRefundAccountNo, CustomerAccountName = input.CustomerRefundAccountName, Ref1 = input.Ref1, Ref2 = input.Ref2, Ref3 = input.Ref3, Remark = input.Remark, GrandTotal_SubTotal = input.TotalUnitAmount().ToString(ConfigurationManager.Format.Decimal_Format), GrandTotal_WH_Amount = input.TotalWithholdingTax().ToString(ConfigurationManager.Format.Decimal_Format), GrandTotal_VAT_Amount = input.TotalVat().ToString(ConfigurationManager.Format.Decimal_Format), GrandTotal_Net_Total = input.GrandTotal().ToString(ConfigurationManager.Format.Decimal_Format), Summary_Total = input.TotalNoDiscount().ToString(ConfigurationManager.Format.Decimal_Format), Summary_Adjustment = input.TotalDiscount().ToString(ConfigurationManager.Format.Decimal_Format), RemainingAmount = input.RemainingAmount().ToString(ConfigurationManager.Format.Decimal_Format), }; }
/// <summary> /// IsRead = false /// FileType = 'C','P' /// </summary> /// <returns></returns> public static List<ReconciliationFile> GetReconciliationFile() { using (var container = new TransactionModelContainer()) { string[] fileType = new string[] { "C", "P" }; return container.ReconciliationFiles.Where(x => x.IsRead == false && fileType.Contains(x.FileType)).ToList(); } }
public void UpdateInstallments() { try { using (var container = new TransactionModelContainer()) { var unreadReconciliations = container.Reconciliations.Where(r => !r.IsRead).ToList(); if (unreadReconciliations.Count <= 0) return; for (var i = 0; i < unreadReconciliations.Count(); i++) { var seq = (i + 1); UpdateInstallmentGalileo(unreadReconciliations[i], seq); } #region Old Code /* foreach (var r in unreadReconciliations) { switch (r.PaymentMethod) { case "C": { // An installment expected var installment = payment.Installments.Where(i => !i.ReconciliationId.HasValue && i.Method == PaymentMethodEnum.CREDIT_CARD.ToString() && i.Amount >= r.Amount && (r.PaymentDate - i.InstallmentDate).Days <= 2).FirstOrDefault(); if (installment != null) { installment.ReconciliationId = r.Id; r.IsRead = true; } } break; case "P": payment.AddInstallments(r.PaymentBy, new Installment(r.PaymentBy, r.Amount, r.PaymentMethod == "C" ? PaymentMethodEnum.CREDIT_CARD : PaymentMethodEnum.PAY_IN_SLIP, r.Id)); r.IsRead = true; break; } } */ #endregion } } catch (Exception exception) { ErrorLog.Log("System", exception, SystemError.ServiceReader); } }
/// <summary> /// Returns erorr logs by criteria /// </summary> /// <param name="criteria">The criteria</param> /// <param name="skip">Number of records to skip</param> /// <param name="take">Number of records to take</param> /// <remarks>Give a negative number to either skip or take, retrieves all records found</remarks> public static ErrorLog[] GetErrorLogs(TransactionModelContainer container, Predicate<ErrorLog>[] criteria, int skip = 0, int take = 1) { var errorLogs = new ErrorLog[0]; int i = 1; if (i == 1) { throw new NotImplementedException("THIS METHOD IS NOT IMPLEMENTED YET"); } return errorLogs; }
public void CreateReconciliationFile(string sourcePath) { try { using (var container = new TransactionModelContainer()) { var fileName = GetFileName(sourcePath); var fileinfo = new FileInfo(fileName); var contents = ReadFile(sourcePath); if (!IsValidFile(fileinfo)) { var newFileName = MoveFileToFolder(container, errPath, sourcePath, fileinfo); container.ReconciliationFiles.AddObject(new ReconciliationFile { FileName = fileinfo.Name, Contents = contents, CreateDate = DateTime.Now, CreateBy = "System", BackupPath = errPath + newFileName, IsValid = false, Source = null, IsRead = false, FileType = FileType.E.ToString(), }); } else { var parentFolder = new DirectoryInfo(successPath).Parent.Name; var newFileName = MoveFileToFolder(container, successPath, sourcePath, fileinfo); container.ReconciliationFiles.AddObject(new ReconciliationFile { FileName = fileinfo.Name, Contents = contents, CreateDate = DateTime.Now, CreateBy = "System", BackupPath = newFileName, //successPath + newFileName, IsValid = true, Source = null, IsRead = false, FileType = (parentFolder.ToLower().Contains("credit")) ? FileType.C.ToString() : FileType.P.ToString(), }); } container.SaveChanges(); } } catch (Exception ex) { ErrorLog.Log("System", ex, SystemError.ServiceReader); } }
/// <summary> /// Generate a payment code by CarPass rules /// [1-9][00-99][0000-9999][0-9] /// Era Gen Random Mod11 /// where the random part is garanteed not consecutive for any couple of calls /// </summary> /// <returns></returns> public static string NextPaymentCode(TransactionModelContainer container) { PaymentCode code = container.PaymentCodes.FirstOrDefault(pc => !pc.IsUsed); if (code == null) { throw new ApplicationException("NO_MORE_PAYMENT_CODE_AVAILABLE"); } code.IsUsed = true; return code.Code; }
static void Main(string[] args) { var runners = new List<Runner>(); using (var container = new TransactionModelContainer()) { var basePaths = container.Configurations.Where(x => x.Group.ToLower() == "basepath").ToArray(); foreach (var path in basePaths) { if (!string.IsNullOrEmpty(path.Value1)) { var slip = new Runner(path.Value1); runners.Add(slip); } if (!string.IsNullOrEmpty(path.Value2)) { var credit = new Runner(path.Value2); runners.Add(credit); } } //Runner bblRunner = new Runner(@"C:\Reconciliation\BBL\CreditCard\"); //Runner scbRunner = new Runner(@"C:\Reconciliation\SCB\CreditCard\"); //Runner bblRunner = new Runner(@"C:\Reconciliation\BBL\PayInSlip\"); //Runner scbRunner = new Runner(@"C:\Reconciliation\SCB\PayInSlip\"); } string cmd = null; do { Console.Write("Enter a command: "); cmd = Console.ReadLine(); switch (cmd) { case "Start": runners.ForEach(x => x.Start()); //bblRunner.Start(); //scbRunner.Start(); break; case "Stop": runners.ForEach(x => x.Stop()); //bblRunner.Stop(); //scbRunner.Stop(); break; default: Console.WriteLine("Wrong command!!!"); break; } } while (cmd != "Q"); Console.WriteLine("Thanks"); }
public static void UpdateFailReconciliationFile(ReconciliationFile recon) { using (var container = new TransactionModelContainer()) { var val = container.ReconciliationFiles.FirstOrDefault(x => x.Id == recon.Id); val.IsValid = false; val.IsRead = true; val.FileType = TransactionModel.Utils.FileType.E.ToString(); val.BackupPath = recon.BackupPath; container.SaveChanges(); } }
public void CreatePayment_Test() { using (TransactionModelContainer container = new TransactionModelContainer()) { Payment payment = new Payment("TESTER", 912, "LMG Insurance", "สุขุมวิท 5", new PaymentItem(1, 400, 7, 3, true, true, ""), new PaymentItem(1, 5000, 0, 0, false, true, "")); container.Payments.AddObject(payment); container.SaveChanges(); } }
public void TestCreateReconciliationFileReaderFile() { var watcher = new System.IO.FileSystemWatcher(); string path = @"C:\Reconciliation\CreditCard\In\testfile.txt"; Reader reader = new Reader(watcher, @"C:\Reconciliation\CreditCard\"); reader.CreateReconciliationFile(path); using (var container = new TransactionModelContainer()) { var reconci = container.ReconciliationFiles.FirstOrDefault(x => x.Id == 1); byte[] data = reconci.Contents; string s = System.Text.ASCIIEncoding.ASCII.GetString(data); } }
public static byte[] CreateTaxInvoiceReceipt(long paymentId) { byte[] pdf = new byte[0]; using (var idmContainer = new IDMServiceClient()) using (var container = new TransactionModelContainer()) { try { var payment = container.Payments.Where(x => x.Id == paymentId).FirstOrDefault(); if (payment != null) { var response = idmContainer.GetPersonByPartyId(new GetPersonByPartyIdRequest { PartyId = payment.CustomerIdmPartyId }); if (!response.IsSuccessful && response.Result == null) throw new Exception("Customer party not found."); if (string.IsNullOrEmpty(response.Result.CustomerCode)) throw new Exception("Not Customer"); var header = CreateViewPayment(payment, container); header.CustomerCode = response.Result.CustomerCode; TaxInvoice report = new TaxInvoice(); report.DataSource = header; report.PaymentDataSource.DataSource = CreateViewPaymentItems(payment.PaymentItems, container); var reportprocess = new ReportProcessor(); var result = reportprocess.RenderReport("PDF", report, null); pdf = result.DocumentBytes; payment.AddTaxInvoiceReceipt(DateTime.Now, payment.CustomerName, pdf, Convert.ToInt32(payment.Id), payment.PaymentCode); container.SaveChanges(); } else { throw new ArgumentException("PAYMENT_NOT_FOUND"); } } catch (Exception ex) { ErrorLog.Log("System", ex, SystemError.TransactionService); } } return pdf; }
public void GetPayment_Test() { using (TransactionModelContainer container = new TransactionModelContainer()) { Payment payment = container.Payments.Where(p => p.Id == 2).FirstOrDefault(); if (payment != null) { decimal grandTotal = payment.GrandTotal(); decimal totalUnitAmount = payment.TotalUnitAmount(); decimal totalVat = payment.TotalVat(); decimal totalWithholdingTax = payment.TotalWithholdingTax(); decimal remainingAmount = payment.RemainingAmount(); } } }
public CreatePaymentResponse CreatePayment(CreatePaymentRequest req) { var res = new CreatePaymentResponse(); try { using (var idmClient = new IDMServiceClient()) using (var container = new TransactionModelContainer()) { ValidateCreatePaymentRequest(idmClient, req); var payment = new Payment( req.CreateBy, req.CustomerIDMPartyID, req.CustomerName, req.CustomerAddress, req.PaymentItems.CreatePaymentItems() ); var grandTotal = payment.GrandTotal(); var credits = container.CustomerCredits.Where(x => x.CustomerIdmPartyId == req.CustomerIDMPartyID && x.IsUsedOrRefund == false).ToList(); var credit = credits.GetCustomerCredit(grandTotal); foreach (var c in credit) payment.AddPaymentItem(PaymentItem.CreateCustomerCredit(c.Id, c.Amount)); CustomerCredit.UpdateCustomerCredit(credit); container.Payments.AddObject(payment); container.SaveChanges(); res.SetPaymentResponse(payment); res.Succeed(); } } catch (Exception x) { res.Fail(x); CreateLog(req, x); } return res; }
public static bool SaveReconciliation(Reconciliation reconciliation) { Exception exception = null; try { using (var container = new TransactionModelContainer()) { container.Reconciliations.AddObject(reconciliation); container.SaveChanges(); } } catch (Exception ex) { CreateLogs(ex); exception = ex; } return exception == null; }
public static PaymentItem[] CreatePaymentItems(this CalculatePaymentItemRequest[] items) { var input = items.ToArray(); var result = new PaymentItem[input.Count()]; using (var container = new TransactionModelContainer()) { for (int i = 0; i < result.Length; i++) { //int serviceCode = input[i].ServiceCode.ToInt(); result[i] = new PaymentItem( //input[i].ServiceCode.ToInt(), //container.ServiceCodes.FirstOrDefault(t => t.Code == serviceCode).Name, input[i].Quantity, input[i].UnitAmount, input[i].VatPercent, input[i].WithholdingTaxPercent, input[i].ServiceIsRevenue, input[i].IsLegalPerson, input[i].ItemDescription); } } return result; }
/// <summary> /// Create a set of configurations /// *** SaveChanges is required to be called *** /// </summary> /// <param name="group">A group</param> /// <param name="names">Names, must be unique within the group</param> /// <param name="values1">A value, cannot be null</param> /// <param name="values2">A another value, can be null</param> /// <param name="values3">A the other value, can be null</param> /// <param name="descs">A description</param> /// <returns>Newly created configurations</returns> public static Configuration[] CreateConfigurationSet(TransactionModelContainer container, string createBy, string group, string[] names, string[] values1, string[] values2, string[] values3, string[] descs) { if (string.IsNullOrEmpty(group)) { throw new ArgumentException("NULL_OR_EMPTY_GROUP"); } if (names == null || names.Length <= 0) { throw new ArgumentException("NULL_OR_EMPTY_NAMES"); } if (values1 == null || values1.Length <= 0) { throw new ArgumentException("NULL_OR_EMPTY_VALUES1"); } if (names.Length != values1.Length) { throw new ArgumentException("NUMBER_OF_NAMES_AND_VALUES1_NOT_MATCH"); } Configuration[] configurations = new Configuration[names.Length]; for (int i = 0; i < names.Length; i++) { configurations[i] = new Configuration(createBy, group, names[i], values1[i]); configurations[i].Value2 = values2 != null && values2.Length >= (i + 1) ? values2[i] : null; configurations[i].Value3 = values3 != null && values3.Length >= (i + 1) ? values3[i] : null; configurations[i].Description = descs != null && descs.Length >= (i + 1) ? descs[i] : null; container.Configurations.AddObject(configurations[i]); } return configurations; }
public GetPaymentResponse GetPaymentByPaymentId(GetPaymentRequest req) { var res = new GetPaymentResponse(); try { long id = long.Parse(req.PaymentId); using (var container = new TransactionModelContainer()) { var payment = container.Payments .Include("PaymentItems") .FirstOrDefault(x => x.Id == id); if (payment == null) throw new Exception("Payment is not found"); res.SetPaymentResponse(payment); res.Succeed(); } } catch (Exception ex) { res.Fail(ex); CreateLog(ex); } return res; }
private static void SaveLog(string issuedBy, SeverityEnum severity, SystemError sys, string issuedMessage) { if (issuedMessage.Length >= 4000) { issuedMessage = issuedMessage.Substring(0, 4000); } var options = new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted }; using (var exceptionLogScope = new TransactionScope(TransactionScopeOption.RequiresNew, options)) { using (var container = new TransactionModelContainer()) { container.ErrorLogs.AddObject(new ErrorLog { IssuedBy = issuedBy, IssuedDate = DateTime.Now, IssuedMessage = issuedMessage, Severity = (byte)severity, SystemErrorId = (byte)sys, SystemErrorName = sys.ToString(), }); container.SaveChanges(); exceptionLogScope.Complete(); } } }
public GetPaymentCodeResponse GetPaymentByPaymentCode(GetPaymentCodeRequest req) { var res = new GetPaymentCodeResponse(); try { using (var container = new TransactionModelContainer()) { var payment = container.Payments .Include("PaymentItems") .FirstOrDefault(x => x.PaymentCode == req.PaymentCode); res.SetPaymentResponse(payment); res.Succeed(); } } catch (Exception ex) { res.Fail(ex); CreateLog(ex); } return res; }
/// <summary> /// Logs an occurring error to the system. The log will actually create after a SaveChanges call. /// </summary> /// <param name="issuedBy">Issuer</param> /// <param name="issuedMsg">Message to log</param> /// <param name="severity">Severity (default = LOW)</param> /// <remarks>container.SaveChanges is required</remarks> public static ErrorLog LogsError(TransactionModelContainer container, string issuedBy, string issuedMsg, SeverityEnum severity = SeverityEnum.LOW) { var log = new ErrorLog(issuedBy, issuedMsg, severity); container.ErrorLogs.AddObject(log); return log; }
public GetPaymentStatusResponse GetPaymentStatusByPaymentId(GetPaymentStatusRequest req) { var res = new GetPaymentStatusResponse(); try { long id = long.Parse(req.PaymentId); using (var container = new TransactionModelContainer()) { var payment = container.Payments.FirstOrDefault(x => x.Id == id); res.PaymentStatus = (PaymentStatusEnum)Enum.Parse(typeof(PaymentStatusEnum), payment.Status); res.Succeed(); } } catch (Exception ex) { res.Fail(ex); CreateLog(ex); } return res; }
public GetPaymentSummaryResponse GetPaymentSummary(GetPaymentSummaryRequest req) { var res = new GetPaymentSummaryResponse(); try { using (var container = new TransactionModelContainer()) { var payment = GetPaymentByPaymentId(new GetPaymentRequest { PaymentId = req.PaymentId.ToString() }); if (payment.IsSuccessful) { var installment = container.Installments.Where(i => i.PaymentId == req.PaymentId).ToList(); bool Ispaid = installment.Count() > 0; var paidAmount = (Ispaid) ? (double)installment.Sum(i => i.Amount) : 0.00; var remainingAmount = payment.RemainingAmount; var amount = payment.GrandTotal; res.PaymentId = req.PaymentId; res.IssuedDate = payment.CreateDate; res.PaymentStatus = payment.PaymentStatus; res.Amount = (double)amount; res.PaidAmount = (double)paidAmount; res.RemainingAmount = (double)remainingAmount; } else { throw new Exception(payment.Message); } } } catch (Exception ex) { res.Fail(ex); CreateLog(ex); } return res; }
public void TestCreateReconciliation() { using (var context = new TransactionModelContainer()) { ReconciliationFile reconcil = new ReconciliationFile("test", new byte[] { 1, 2 }, DateTime.Now, "system",null,true,null,false); context.ReconciliationFiles.AddObject(reconcil); context.SaveChanges(); } }
public GetReconciliationByPaymentCodeResponse[] GetReconciliationByPaymentCode(GetReconciliationByPaymentCodeRequest[] req) { var result = new List<GetReconciliationByPaymentCodeResponse>(); using (var ctx = new TransactionModelContainer()) { //var pCode = req.Select(s => s.PaymentCode).ToArray(); //var recons = ctx.Reconciliations.Where(s => pCode.Contains(s.PaymentCode) && s.IsRead == false).ToList(); var recons = ctx.Reconciliations.Where(s => s.IsRead == false).ToList(); if (recons.Count > 0) { foreach (var r in recons) { r.IsRead = true; var paymentMethod = r.PaymentMethod.ToUpper() == "C" ? PaymentMethodEnum.CREDIT_CARD : PaymentMethodEnum.PAY_IN_SLIP; //var payment = ctx.Payments.Select(x => new { PaymentId = x.Id, PaymentCode = x.PaymentCode }) // .FirstOrDefault(s => s.PaymentCode == r.PaymentCode); result.Add(new GetReconciliationByPaymentCodeResponse { ReconciliationId = r.Id, //PaymentId = payment.PaymentId, PaymentCode = r.PaymentCode, PaymentDate = r.PaymentDate, PaymentBy = r.PaymentBy, PaymentMethod = paymentMethod, Amount = r.Amount, }); } ctx.SaveChanges(); } } return result.ToArray(); }
public RetrievePaymentCodeResponse RetrievePaymentCode(RetrievePaymentCodeRequest req) { var res = new RetrievePaymentCodeResponse(); using (var ctx = new TransactionModelContainer()) { res.PaymentCode = PaymentCode.NextPaymentCode(ctx); ctx.SaveChanges(); } return res; }