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),
            };
        }
Beispiel #3
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 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 void SetPaymentResponse(this GetPaymentCodeResponse res, Payment payment)
        {
            res.PaymentId = payment.Id;
            res.PaymentCode = payment.PaymentCode;
            res.CreateBy = payment.CreatedBy;
            res.CreateDate = payment.CreatedDate;
            res.UpdateBy = payment.UpdatedBy;
            res.UpdateDate = payment.UpdatedDate;
            res.CustomerIDMPartyID = payment.CustomerIdmPartyId;
            res.CustomerCode = null;
            res.CustomerName = payment.CustomerName;
            res.CustomerAddress = payment.CustomerAddress;
            res.CustomerAccountNumber = payment.CustomerRefundAccountNo;
            res.CustomerAccountName = payment.CustomerRefundAccountName;
            res.CustomerAccountBankId = payment.CustomerRefundBankId;
            res.CustomerMobilePhoneNumber = payment.CustomerMobilePhoneNo;
            res.Remark = payment.Remark;
            res.Ref1 = payment.Ref1;
            res.Ref2 = payment.Ref2;
            res.Ref3 = payment.Ref3;
            res.PaymentStatus = payment.Status;
            res.RemainingAmount = payment.RemainingAmount();
            res.GrandTotal = payment.GrandTotal();
            res.TotalVatAmount = payment.TotalVat();
            res.TotalWithholdingTaxAmount = payment.TotalWithholdingTax();
            res.TotalBeforeAdjustment = payment.TotalNoDiscount();
            res.TotalAdjustment = payment.TotalDiscount();

            var input = payment.PaymentItems.ToArray();
            var result = new PaymentItemResponse[input.Count()];
            for (int i = 0; i < result.Length; i++)
            {
                result[i] = new PaymentItemResponse
                {
                    //ServiceCode = input[i].ServiceCode.ToString(),
                    //ServiceName = input[i].ServiceName,
                    ItemDescription = input[i].ItemDescription,
                    Quantity = input[i].Qty,
                    UnitAmount = input[i].UnitAmount,
                    VatPercent = input[i].VatPercent,
                    WithholdingTaxPercent = input[i].WithholdingTexPercent,
                    WithholdingTaxAmount = input[i].WithHoldingTaxAmount(),
                    IsRevenue = input[i].ServiceIsRevenue,
                    IsLegalPerson = input[i].IsLegalPerson,
                    VatAmount = input[i].VATAmount(),
                    Remark = input[i].Remark,
                    SubTotal = input[i].SubTotal(),
                    PaymentItemId = input[i].Id,
                    GroupRef1 = input[i].GroupRef1,
                    GroupRef2 = input[i].GroupRef2,
                    GroupRef3 = input[i].GroupRef3,
                    NetTotal = input[i].NetTotal()
                };
            }
        }
 public static void SetPaymentResponse(this CreatePaymentResponse res, Payment payment)
 {
     res.PaymentId = payment.Id;
     res.PaymentCode = payment.PaymentCode;
     res.CreateBy = payment.CreatedBy;
     res.CreateDate = payment.CreatedDate;
     res.UpdateBy = payment.UpdatedBy;
     res.UpdateDate = payment.UpdatedDate;
     res.CustomerIDMPartyID = payment.CustomerIdmPartyId;
     res.CustomerCode = null;
     res.CustomerName = payment.CustomerName;
     res.CustomerAddress = payment.CustomerAddress;
     res.CustomerAccountNumber = payment.CustomerRefundAccountNo;
     res.CustomerAccountName = payment.CustomerRefundAccountName;
     res.CustomerAccountBankId = payment.CustomerRefundBankId;
     res.CustomerMobilePhoneNumber = payment.CustomerMobilePhoneNo;
     res.Remark = payment.Remark;
     res.Ref1 = payment.Ref1;
     res.Ref2 = payment.Ref2;
     res.Ref3 = payment.Ref3;
     res.PaymentStatus = payment.Status;
     res.RemainingAmount = payment.RemainingAmount();
     res.GrandTotal = payment.GrandTotal();
     res.TotalVatAmount = payment.TotalVat();
     res.TotalWithholdingTaxAmount = payment.TotalWithholdingTax();
     res.TotalBeforeAdjustment = payment.TotalNoDiscount();
     res.TotalAdjustment = payment.TotalDiscount();
     res.PaymentItems = payment.PaymentItems.CreatePaymentResponseItem();
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Payments EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToPayments(Payment payment)
 {
     base.AddObject("Payments", payment);
 }
 /// <summary>
 /// Create a new Payment object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="createdDate">Initial value of the CreatedDate property.</param>
 /// <param name="createdBy">Initial value of the CreatedBy property.</param>
 /// <param name="updatedDate">Initial value of the UpdatedDate property.</param>
 /// <param name="updatedBy">Initial value of the UpdatedBy property.</param>
 /// <param name="version">Initial value of the Version property.</param>
 /// <param name="paymentCode">Initial value of the PaymentCode property.</param>
 /// <param name="status">Initial value of the Status property.</param>
 /// <param name="isVoid">Initial value of the IsVoid property.</param>
 /// <param name="customerIdmPartyId">Initial value of the CustomerIdmPartyId property.</param>
 /// <param name="customerName">Initial value of the CustomerName property.</param>
 /// <param name="customerAddress">Initial value of the CustomerAddress property.</param>
 public static Payment CreatePayment(global::System.Int64 id, global::System.DateTime createdDate, global::System.String createdBy, global::System.DateTime updatedDate, global::System.String updatedBy, global::System.Byte[] version, global::System.String paymentCode, global::System.String status, global::System.Boolean isVoid, global::System.Int64 customerIdmPartyId, global::System.String customerName, global::System.String customerAddress)
 {
     Payment payment = new Payment();
     payment.Id = id;
     payment.CreatedDate = createdDate;
     payment.CreatedBy = createdBy;
     payment.UpdatedDate = updatedDate;
     payment.UpdatedBy = updatedBy;
     payment.Version = version;
     payment.PaymentCode = paymentCode;
     payment.Status = status;
     payment.IsVoid = isVoid;
     payment.CustomerIdmPartyId = customerIdmPartyId;
     payment.CustomerName = customerName;
     payment.CustomerAddress = customerAddress;
     return payment;
 }
Beispiel #9
0
        public void RefreshWhenDomainModelChanged(Payment payment)
        {
            string NumberFormat = ConfigurationManager.Format.Decimal_Format;

            PaymentId = payment.Id.ToString("0000000000");
            PaymentCode = payment.PaymentCode;
            PaymentStatus = payment.Status;

            CustomerIdmId = payment.CustomerIdmPartyId.ToString("0000000000");
            CustomerName = payment.CustomerName;
            CustomerAddress = payment.CustomerAddress;
            CustomerMobilePhoneNo = payment.CustomerMobilePhoneNo;
            CustomerAccountNo = payment.CustomerRefundAccountNo;
            CustomerAccountName = payment.CustomerRefundAccountName;

            Ref1 = payment.Ref1;
            Ref2 = payment.Ref2;
            Ref3 = payment.Ref3;
            Remark = payment.Remark;

            GrandTotal_SubTotal = payment.TotalUnitAmount().ToString(NumberFormat);
            GrandTotal_WH_Amount = payment.TotalWithholdingTax().ToString(NumberFormat);
            GrandTotal_VAT_Amount = payment.TotalVat().ToString(NumberFormat);
            GrandTotal_Net_Total = payment.GrandTotal().ToString(NumberFormat);

            Summary_Total = payment.TotalNoDiscount().ToString(NumberFormat);
            Summary_Adjustment = payment.TotalDiscount().ToString(NumberFormat);

            Installment_Total = payment.InstallmentAmount().ToString(NumberFormat);
            RemainingAmount = payment.RemainingAmount().ToString(NumberFormat);

            // PaymentItems
            Items = payment.PaymentItems.CreateViewPaymentItems();
            // Installments
            InstallmentItems = payment.Installments.CreateInstallment();
        }
 private void ValidatePaymentAggregate(Payment payment)
 {
     if (payment.PaymentItems == null || payment.PaymentItems.Count < 1)
         throw new ApplicationException("AT_LEAST_ONE_ITEM_REQUIRED");
 }