Beispiel #1
0
        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 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 static void UpdateSuccessReconciliationFile(long id)
        {
            using (var container = new TransactionModelContainer())
            {
                var val = container.ReconciliationFiles.FirstOrDefault(x => x.Id == id);
                val.IsRead = true;

                container.SaveChanges();
            }
        }
Beispiel #4
0
        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 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 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 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 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 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();
            }
        }
Beispiel #11
0
        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();
                }
            }
        }
Beispiel #12
0
        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 RetrievePaymentCodeResponse RetrievePaymentCode(RetrievePaymentCodeRequest req)
        {
            var res = new RetrievePaymentCodeResponse();

            using (var ctx = new TransactionModelContainer())
            {
                res.PaymentCode = PaymentCode.NextPaymentCode(ctx);
                ctx.SaveChanges();
            }

            return res;
        }
Beispiel #14
0
        public virtual long LogsError(Exception x)
        {
            long id = -1;
            using (TransactionModelContainer container = new TransactionModelContainer())
            {
                string message = x.Message;
                if (x.InnerException != null)
                    message = x.InnerException.Message;

                ErrorLog log = container.LogsError(UserName + "(" + UserAccountId + ")",
                    message, SeverityEnum.HIGH);

                container.SaveChanges();
                id = log.Id;
            }
            return id;
        }
        public static void UpdateSuccessReconciliationFile(long id)
        {
            using (var container = new TransactionModelContainer())
            {
                var val = container.ReconciliationFiles.FirstOrDefault(x => x.Id == id);
                val.IsRead = true;

                container.SaveChanges();
            }
        }
Beispiel #16
0
        public virtual byte[] CreatePayInSlip()
        {
            byte[] pdf = new byte[0];
            using (var container = new TransactionModelContainer())
            {
                long id = long.Parse(PaymentId);
                Payment payment = container.Payments.Where(x => x.Id == id).FirstOrDefault();

                if (payment != null)
                {
                    var config = container.Configurations.Where(x => x.Group == "Pay_In").ToList();

                    PayInSlipReport report = new PayInSlipReport();
                    report.DataSource = PayInSlipDetail.CreatePayInSlipSource(
                        config.Where(x => x.Name.ToLower() == "companyname").FirstOrDefault().Value1,
                        config.Where(x => x.Name.ToLower() == "companyname").FirstOrDefault().Value2,
                        config.Where(x => x.Name.ToLower() == "companyname").FirstOrDefault().Value3,
                        config.Where(x => x.Name.ToLower() == "taxno").FirstOrDefault().Value1,
                        config.Where(x => x.Name.ToLower() == "accno").FirstOrDefault().Value1,
                        config.Where(x => x.Name.ToLower() == "accno").FirstOrDefault().Value2,
                        config.Where(x => x.Name.ToLower() == "accno").FirstOrDefault().Value3,
                        DateTime.Now.ToString("dd/MM/yyyy"),
                        config.Where(x => x.Name.ToLower() == "servicecode").FirstOrDefault().Value1,
                        payment.CustomerName,
                        payment.PaymentCode,
                        payment.CustomerIdmPartyId.ToString(),
                        payment.RemainingAmount().ToString(ConfigurationManager.Format.Decimal_Format)
                    );

                    var reportprocess = new ReportProcessor();
                    var result = reportprocess.RenderReport("PDF", report, null);
                    pdf = result.DocumentBytes;

                    payment.AddPayInSlip(DateTime.Now, payment.CustomerName, pdf,
                        Convert.ToInt32(payment.Id), payment.PaymentCode);

                    container.SaveChanges();
                    RefreshWhenDomainModelChanged(payment);
                }
                else
                {
                    throw new ArgumentException("PAYMENT_NOT_FOUND");
                }
            }
            return pdf;
        }
Beispiel #17
0
        public virtual void CreateCreditCardSuccess()
        {
            using (var container = new TransactionModelContainer())
            {
                long id = long.Parse(PaymentId);
                var payment = container.Payments.Where(x => x.Id == id).FirstOrDefault();
                if (payment != null)
                {
                    string fullname = TheMain.FirstName + " " + TheMain.LastName;
                    payment.AddInstallments(payment.CustomerName,
                        new Installment(fullname, payment.GrandTotal(), PaymentMethodEnum.CREDIT_CARD, null));

                    container.SaveChanges();

                    RefreshWhenDomainModelChanged(payment);
                }
            }
        }
        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();
        }
Beispiel #19
0
        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);
            }
        }