Esempio n. 1
0
        public async Task <ActionResult <TblInstallment> > PostTblInstallment(TblInstallment tblInstallment)
        {
            _context.TblInstallment.Add(tblInstallment);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetTblInstallment", new { id = tblInstallment.Id }, tblInstallment));
        }
Esempio n. 2
0
        public async Task <IActionResult> PutTblInstallment(long id, TblInstallment tblInstallment)
        {
            if (id != tblInstallment.Id)
            {
                return(BadRequest());
            }

            _context.Entry(tblInstallment).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TblInstallmentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 3
0
        public async Task <ApiResponse> AddSale(TblInvoice tblInvoice)
        {
            //
            //[NotMapped] Sample Code
            // public object InstallmentDetail { get; set; }
            //
            //
            //[NotMapped]
            //public string PaymentMode { get; set; }
            //
            //List<Testcalss> res = tblInvoice.InstallmentDetail as List<Testcalss>;
            List <TblInstallment> installmentDetail = JsonConvert.DeserializeObject <List <TblInstallment> >(tblInvoice.InstallmentDetail.ToString());

            try
            {
                for (int i = 0; i < installmentDetail.Count; i++)
                {
                    TblInvoice objInvoice = new TblInvoice();
                    objInvoice.UserId      = tblInvoice.UserId;
                    objInvoice.CurrencyId  = tblInvoice.CurrencyId;
                    objInvoice.CountryId   = tblInvoice.CountryId;
                    objInvoice.CustomerId  = tblInvoice.CustomerId;
                    objInvoice.Comment     = tblInvoice.Comment;
                    objInvoice.PaymentMode = installmentDetail[i].PaymentMode;
                    objInvoice.StockNumber = installmentDetail[i].StockNumber;
                    objInvoice.SalePrice   = Convert.ToDecimal(installmentDetail[i].SalePrice);
                    objInvoice.SaleDate    = DateTime.Now;
                    if (installmentDetail[i].PaymentMode == "CASH")
                    {
                        objInvoice.PaymentStatus = "Paid";
                    }
                    else
                    {
                        objInvoice.PaymentStatus = "INSTALLMENT";
                    }
                    objInvoice.PaidAmount    = Convert.ToDecimal(installmentDetail[i].SalePrice);
                    objInvoice.BalanceAmount = 0;
                    objInvoice.Status        = "Sale";
                    long lastInvoiceid = 0;
                    try
                    {
                        // _context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT [dbo].[tbl_Invoice] ON");

                        _context.TblInvoice.Add(objInvoice);
                        await _context.SaveChangesAsync();

                        lastInvoiceid = objInvoice.Id;
                        var currentmonthShort = DateTime.Now.ToString("MMM-dd");
                        var invoiceNumber     = "INV-" + currentmonthShort + "-" + String.Format("{0:D4}", lastInvoiceid);
                        objInvoice.InvoiceNumber = invoiceNumber;
                        _context.Entry(objInvoice).Property(x => x.InvoiceNumber).IsModified = true;
                        await _context.SaveChangesAsync();

                        //tblInvoice.Id=0;
                        // _context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT [dbo].[tbl_Invoice] OFF");


                        if (installmentDetail[i].PaymentMode == "INSTALLMENT")
                        {
                            TblInstallment objInstallment = new TblInstallment();
                            objInstallment.InvoiceNumber     = lastInvoiceid.ToString();
                            objInstallment.StockNumber       = installmentDetail[i].StockNumber;
                            objInstallment.CustomerId        = tblInvoice.CustomerId;
                            objInstallment.SalemanId         = tblInvoice.UserId;
                            objInstallment.SalePrice         = installmentDetail[i].SalePrice;
                            objInstallment.DownPayment       = installmentDetail[i].DownPayment;
                            objInstallment.TimeDurationYears = installmentDetail[i].TimeDurationYears;
                            objInstallment.TotalInstallment  = installmentDetail[i].TotalInstallment;
                            objInstallment.TaxPer            = installmentDetail[i].TaxPer;
                            objInstallment.TaxAmount         = installmentDetail[i].TaxAmount;
                            objInstallment.FinalAmount       = installmentDetail[i].FinalAmount;
                            objInstallment.InstallAmount     = installmentDetail[i].InstallAmount;
                            objInstallment.Installmentmode   = installmentDetail[i].Installmentmode;
                            objInstallment.Day         = installmentDetail[i].Day;
                            objInstallment.CreatedDate = DateTime.Now;
                            _context.TblInstallment.Add(objInstallment);
                            await _context.SaveChangesAsync();

                            var      Currentyear     = DateTime.Now.Year;
                            var      currentmonth    = DateTime.Now.Month;
                            var      currday         = DateTime.Now.Day;
                            DateTime installmentDate = new DateTime();
                            for (int j = 0; j < installmentDetail[i].TotalInstallment; j++)
                            {
                                TblInstallmentDetail objinstallmentDetail = new TblInstallmentDetail();

                                decimal TaxAmount      = 0;
                                decimal pendingPayment = Convert.ToDecimal(installmentDetail[i].SalePrice - installmentDetail[i].DownPayment);
                                int     timeperiod     = Convert.ToInt32(installmentDetail[i].TimeDurationYears);
                                switch (installmentDetail[i].Installmentmode)
                                {
                                case
                                    "YEAR":
                                    Currentyear++;
                                    installmentDate = new DateTime(Currentyear, currentmonth, Convert.ToInt32(installmentDetail[i].Day));
                                    // TimeSpan aMonth = new System.TimeSpan(365, 0, 0, 0);
                                    //installmentDate.Add(aMonth);
                                    TaxAmount = Convert.ToDecimal((pendingPayment / timeperiod) * Convert.ToDecimal(installmentDetail[i].TaxPer) / 100);
                                    break;

                                case
                                    "HALFYEAR":
                                    currentmonth = currentmonth + 6;
                                    if (currentmonth > 12)
                                    {
                                        Currentyear++;
                                        var addcurrentmonth = currentmonth % 12;
                                        installmentDate = new DateTime(Currentyear, addcurrentmonth, Convert.ToInt32(installmentDetail[i].Day));
                                    }
                                    else
                                    {
                                        installmentDate = new DateTime(Currentyear, currentmonth, Convert.ToInt32(installmentDetail[i].Day));
                                    }
                                    //  TimeSpan aMonthHalf = new System.TimeSpan(180, 0, 0, 0);
                                    //installmentDate.Add(aMonthHalf);
                                    TaxAmount = Convert.ToDecimal((pendingPayment / (timeperiod * 2)) * Convert.ToDecimal(installmentDetail[i].TaxPer) / 100);

                                    break;

                                case
                                    "MONTHLY":
                                    currentmonth++;
                                    if (currentmonth > 12)
                                    {
                                        currentmonth = currentmonth % 12;
                                        Currentyear++;
                                        installmentDate = new DateTime(Currentyear, currentmonth, Convert.ToInt32(installmentDetail[i].Day));
                                    }
                                    else
                                    {
                                        installmentDate = new DateTime(Currentyear, currentmonth, Convert.ToInt32(installmentDetail[i].Day));
                                    }
                                    //TimeSpan aMonthM = new System.TimeSpan(30, 0, 0, 0);
                                    //installmentDate.Add(aMonthM);
                                    TaxAmount = Convert.ToDecimal((pendingPayment / (timeperiod * 12)) * Convert.ToDecimal(installmentDetail[i].TaxPer) / 100);

                                    break;
                                }
                                objinstallmentDetail.InstallmentDate = installmentDate;
                                objinstallmentDetail.InstallmentId   = objInstallment.Id;
                                objinstallmentDetail.DueDate         = installmentDate.AddDays(15);
                                objinstallmentDetail.PaymentStatus   = "PENDING";
                                objinstallmentDetail.TaxPer          = installmentDetail[i].TaxPer;
                                objinstallmentDetail.TaxAmount       = TaxAmount;
                                objinstallmentDetail.FinalAmount     = installmentDetail[i].InstallAmount;
                                objinstallmentDetail.PaidAmount      = 0;
                                objinstallmentDetail.CreatedDate     = DateTime.Now;

                                _context.TblInstallmentDetail.Add(objinstallmentDetail);
                                await _context.SaveChangesAsync();
                            }
                        }
                        //tblInvoice.Id = 0;
                    }
                    catch (DbUpdateConcurrencyException ex)
                    {
                        var ApiResponseCatch = await response.ApiResult("FAILED", ex, "Error ");

                        return(ApiResponseCatch);
                    }
                }
                var ApiResponse = await response.ApiResult("OK", "Data Save Installment", "Success ");

                return(ApiResponse);
            }
            catch (DbUpdateConcurrencyException ex)
            {
                var ApiResponseCatch = await response.ApiResult("FAILED", ex, "Error ");

                return(ApiResponseCatch);
            }

            //  return CreatedAtAction("GetTblInvoice", new { id = tblInvoice.Id }, tblInvoice);
        }