Esempio n. 1
0
        public ActionResult CreateInvoice(InvoiceCreateModel invoiceCreateModel)
        {
            SetBaseConfigurations(invoiceCreateModel);
            if (ModelState.IsValid)
            {
                SaddedClient client = new SaddedClient(invoiceCreateModel.BaseUrl,
                                                       invoiceCreateModel.ApiKey,
                                                       invoiceCreateModel.VendorId,
                                                       invoiceCreateModel.BranchId,
                                                       invoiceCreateModel.TerminalId);

                DateTime invoiceDate = invoiceCreateModel.Date != null ?
                                       invoiceCreateModel.Date.Value : DateTime.Now;

                SetDefaultSuccessErrorUrl(invoiceCreateModel, Request.Url.ToString());

                CreateInvoiceRequest request = new CreateInvoiceRequest()
                {
                    Amount            = invoiceCreateModel.Amount,
                    CustomerName      = invoiceCreateModel.CustomerName,
                    Date              = invoiceDate,
                    Description       = invoiceCreateModel.Description,
                    ExternalReference = invoiceCreateModel.ExternalReference,
                    SuccessUrl        = invoiceCreateModel.SuccessUrl,
                    ErrorUrl          = invoiceCreateModel.ErrorUrl,
                    Msisdn            = invoiceCreateModel.Msisdn,
                    Email             = invoiceCreateModel.Email,
                    NotificationMode  = invoiceCreateModel.NotificationMode
                };

                invoiceCreateModel.Response = client.createInvoiceLink(request);
            }
            AddNotificationModesInBag();
            return(View(invoiceCreateModel));
        }
        public ActionResult Create(string businessNumber)
        {
            InvoiceCreateModel invoiceCreateModel = new InvoiceCreateModel();

            invoiceCreateModel.Sender = _companyService.GetCompanies().First(c => c.BusinessNumber == businessNumber);
            return(View(invoiceCreateModel));
        }
        public HttpResponseMessage Insert(InvoiceCreateModel invoiceCreateModel)
        {
            InvoiceDto invoicesDto = this.mapper.Map <InvoiceCreateModel, InvoiceDto>(invoiceCreateModel);

            this.invoicesAppService.CreateNewInvoice(invoicesDto);
            return(new HttpResponseMessage(HttpStatusCode.OK));
        }
Esempio n. 4
0
        /// <summary>
        /// Get method for CreateInvoice page, passing base configurations to be displayed on page
        /// </summary>
        /// <returns>CreateInvoice view</returns>
        public ActionResult CreateInvoice()
        {
            InvoiceCreateModel invoiceCreateModel = new InvoiceCreateModel();

            SetBaseConfigurations(invoiceCreateModel);
            AddNotificationModesInBag();
            SetDefaultSuccessErrorUrl(invoiceCreateModel, Request.Url.ToString());
            return(View(invoiceCreateModel));
        }
Esempio n. 5
0
        public async Task <IActionResult> Create(InvoiceCreateModel model)
        {
            var id = await _service.Create(model.CustomerId);

            if (id == null)
            {
                return(NotFound());
            }
            return(Created(nameof(Create), id));
        }
Esempio n. 6
0
        public InvoiceCreateRequest(InvoiceCreateModel model) : this()
        {
            if (model != null)
            {
                if (!string.IsNullOrEmpty(model.Id))
                {
                    Id = model.Id;
                }

                Username       = model.Username;
                BuyerId        = model.BuyerId;
                BuyerCode      = model.BuyerCode;
                BuyerGroupId   = model.BuyerGroupId;
                BuyerGroupName = model.BuyerGroupName;
                BuyerGroupCode = model.BuyerGroupCode;
                Currency       = string.IsNullOrEmpty(model.Currency)
                                   ? "VN"
                                   : model.Currency;
                InvoiceDate     = model.InvoiceDate.ConvertToString();
                Note            = model.Note;
                TemplateNo      = model.TemplateNo;
                SerialNo        = model.SerialNo;
                InvoiceTypeCode = model.InvoiceTypeCode;
                ExchangeRate    = string.Equals(model.Currency,
                                                "VN")
                                       ? 1
                                       : model.ExchangeRate ?? 1;
                PaymentMethod = model.PaymentMethod.ConvertToString();
                PaymentDate   = model.PaymentDate.ConvertToString();

                TotalDiscountPercentAfterTax = model.TotalDiscountPercentAfterTax;
                TotalDiscountAmountAfterTax  = model.TotalDiscountAmountAfterTax;

                BuyerEmail        = model.BuyerEmail;
                BuyerFullName     = model.BuyerFullName;
                BuyerLegalName    = model.BuyerLegalName;
                BuyerTaxCode      = model.BuyerTaxCode;
                BuyerAddressLine  = model.BuyerAddressLine;
                BuyerPostalCode   = model.BuyerPostalCode;
                BuyerDistrictName = model.BuyerDistrictName;
                BuyerCityName     = model.BuyerCityName;
                BuyerCountryCode  = model.BuyerCountryCode;
                BuyerPhoneNumber  = model.BuyerPhoneNumber;
                BuyerFaxNumber    = model.BuyerFaxNumber;
                BuyerBankName     = model.BuyerBankName;
                BuyerBankAccount  = model.BuyerBankAccount;
            }
        }
Esempio n. 7
0
        public string AddInvoice(InvoiceCreateModel model)
        {
            if (ModelState.IsValid)
            {
                InvoiceModel invoice = new InvoiceModel();

                try
                {
                    invoice.Name        = model.Name;
                    invoice.Surname     = model.Surname;
                    invoice.Email       = model.Email;
                    invoice.Phone       = model.Phone;
                    invoice.Address     = model.Address;
                    invoice.InvoiceDate = model.InvoiceDate;
                    invoice.InvoiceNo   = model.InvoiceNo;
                    invoice.Products    = model.Products;
                    decimal totalPrice = 0;
                    foreach (var item in model.Products)
                    {
                        totalPrice += item.UnitPrice * item.Piece;
                    }
                    invoice.TotalPrice = totalPrice;
                    using (var db = new SanalogiDbContext())
                    {
                        db.Invoices.Add(invoice);
                        db.SaveChanges();
                    }
                    return("Kayıt başarılı!");
                }
                catch (Exception ex)
                {
                    return("Kayıt başarısız:" + ex.Message);
                }
            }
            return("Hatalı bilgi girdiniz.");
        }
Esempio n. 8
0
        /// <summary>
        ///     Tạo mới hóa đơn.
        /// </summary>
        /// <param name="authentication"></param>
        /// <param name="model"></param>
        /// <returns></returns>
        public MessageResult Create(Authentication authentication,
                                    InvoiceCreateModel model)
        {
            MessageResult result = new MessageResult();

            try
            {
                var token = GetToken(authentication);

                if (!string.IsNullOrEmpty(token))
                {
                    string apiLink = $"{authentication.DomainName}/api/invoices/create-batch";

                    InvoiceCreateRequest request = new InvoiceCreateRequest(model);

                    List <InvoiceDetail> invoiceDetails = new List <InvoiceDetail>();
                    if (model.Details != null)
                    {
                        invoiceDetails.AddRange(model.Details.Select(c => new InvoiceDetail(c)));
                    }

                    request.Details = invoiceDetails;

                    List <InvoiceTaxBreakdown> taxBreakdowns = new List <InvoiceTaxBreakdown>();
                    if (model.InvoiceTaxBreakdowns != null)
                    {
                        taxBreakdowns.AddRange(model.InvoiceTaxBreakdowns.Select(c => new InvoiceTaxBreakdown(c)));
                    }

                    request.InvoiceTaxBreakdowns = taxBreakdowns;

                    request.TotalAmount    = request.Details.Sum(c => c.Amount);
                    request.TotalVatAmount = request.Details.Sum(c => c.VatAmount);
                    request.TotalDiscountAmountBeforeTax = request.Details.Sum(c => c.DiscountAmountBeforeTax);

                    if (request.TotalDiscountAmountAfterTax == 0)
                    {
                        if (request.TotalDiscountPercentAfterTax > 0)
                        {
                            request.TotalDiscountAmountAfterTax = request.TotalAmount * request.TotalDiscountPercentAfterTax / 100;
                        }
                    }

                    request.TotalPaymentAmount = request.TotalAmount + request.TotalVatAmount - request.TotalDiscountAmountAfterTax;

                    var rawResponse = AppUtil.CreateRequest(apiLink,
                                                            request.ToJson(),
                                                            token);
                    var response = rawResponse.ToObject <BaseResponse <InvoiceCreateResponse> >();
                    if (response != null)
                    {
                        result.Code      = response.Code;
                        result.Succeeded = response.Succeeded;
                        result.Data      = response.Data;
                    }
                }
                else
                {
                    result.CannotLogin();
                }
            }
            catch (Exception)
            {
                result.ErrorApi();
            }

            return(result);
        }
Esempio n. 9
0
 private void SetDefaultSuccessErrorUrl(InvoiceCreateModel model, string websiteBaseUrl)
 {
     model.SuccessUrl = model.SuccessUrl ?? string.Format(paymentGatewayResponsePage, websiteBaseUrl);
     model.ErrorUrl   = model.ErrorUrl ?? string.Format(paymentGatewayResponsePage, websiteBaseUrl);
 }