Beispiel #1
0
 private void CreateSubFolderDirectorySuccess(TransactionModelContainer container, string fullPath)
 {
     if (!Directory.Exists(fullPath))
     {
         Directory.CreateDirectory(fullPath);
     }
 }
        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),
            });
        }
        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);
            }
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        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);
            }
        }
Beispiel #7
0
        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);
        }
Beispiel #8
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 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);
        }
Beispiel #10
0
        public virtual string GetErrorLog(long id)
        {
            string msg = null;

            using (TransactionModelContainer container = new TransactionModelContainer())
            {
                ErrorLog log = container.ErrorLogs.Where(l => l.Id == id).FirstOrDefault();
                msg = log.IssuedMessage;
            }
            return(msg);
        }
Beispiel #11
0
        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");
        }
Beispiel #12
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);
            }
        }
Beispiel #13
0
        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
        private string MoveFileToFolder(TransactionModelContainer container, string moveToPath, string sourceFile, FileInfo fileInfo)
        {
            var folderName      = DateTime.Now.Year.ToString("0000") + DateTime.Now.Month.ToString("00");
            var fullPath        = moveToPath + folderName + "\\";
            var newFileName     = DateTime.Now.ToString("yyyyMMddHHmmss") + "_" + fileInfo.Name;
            var destinationPath = fullPath + newFileName;

            CreateSubFolderDirectorySuccess(container, fullPath);

            File.Move(sourceFile, destinationPath);

            return(destinationPath);
        }
Beispiel #15
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();
            }
        }
Beispiel #16
0
        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);
            }
        }
Beispiel #17
0
        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();
                }
            }
        }
Beispiel #18
0
        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);
        }
Beispiel #19
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 #20
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);
                }
            }
        }
Beispiel #21
0
        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);
        }
Beispiel #22
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);
        }
Beispiel #23
0
        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);
        }
Beispiel #24
0
        public void Initialize(Main main, long paymentId, long ticket)
        {
            TheMain = main;
            TheMain.SetUpUser(ticket);

            using (var container = new TransactionModelContainer())
            {
                var payment = container.Payments
                              .Include("PaymentItems")
                              .Include("Installments")
                              .FirstOrDefault(x => x.Id == paymentId &&
                                              x.CustomerIdmPartyId == TheMain.PartyId);

                if (payment == null)
                {
                    throw new ArgumentException("PAYMENT_NOT_NULL");
                }
                else
                {
                    RefreshWhenDomainModelChanged(payment);
                }
            }
        }
        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);
        }
Beispiel #26
0
        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 #27
0
        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 ReportItems[] CreateViewPaymentItems(IEnumerable <PaymentItem> input, TransactionModelContainer container)
        {
            string NumberFormat = ConfigurationManager.Format.Decimal_Format;

            var Items = new ReportItems[0];

            if (input.Count() > 0)
            {
                Items = new ReportItems[input.Count()];
                var item = input.ToArray();
                for (int i = 0; i < item.Count(); i++)
                {
                    Items[i] = new ReportItems
                    {
                        No = (i + 1).ToString("#,##0"),
                        //Name = item[i].ServiceName + item[i].ItemDescription,
                        Quantity              = item[i].Qty.ToString("#,##0"),
                        UnitPrice             = item[i].UnitAmount.ToString(NumberFormat),
                        SubTotal              = item[i].SubTotal().ToString(NumberFormat),
                        WithholdingTaxPercent = item[i].WithholdingTexPercent.ToString("0"),
                        WithholdingTaxAmount  = item[i].WithHoldingTaxAmount().ToString(NumberFormat),
                        VatPercent            = item[i].VatPercent.ToString("0"),
                        VatAmount             = item[i].VATAmount().ToString(NumberFormat),
                        NetAmount             = item[i].NetTotal().ToString(NumberFormat),
                    };
                }
            }
            return(Items);
        }