コード例 #1
0
        public IHttpActionResult GetBilledItems(int billId)
        {
            try
            {
                using (MaxMasterDbEntities db = new MaxMasterDbEntities())
                {
                    var billedItems = db.GetBilledItems(billId).OrderBy(x => x.Id).ToList();
                    var bill        = db.Bills.Find(billId);

                    //  var stock = db.Items.Where(x => x.BillNumber == billNumber).ToList();

                    decimal subtotal       = 0;
                    decimal?taxAmount      = 0;
                    decimal?tdsAmount      = 0;
                    decimal?courierCharges = 0;
                    decimal?discount       = 0;

                    BillModel billModel = new BillModel();

                    if (bill != null)
                    {
                        billModel.BillDate   = bill.BillDate;
                        billModel.BillNumber = bill.BillNumber;
                        if (bill.CourierCharges != null)
                        {
                            billModel.CourierCharges = bill.CourierCharges;
                        }

                        billModel.DueDate = bill.DueDate;
                        // billModel.Id = bill.Id;
                        billModel.Notes        = bill.Notes;
                        billModel.PaymentTerms = bill.PaymentTerms;
                        billModel.PONumber     = bill.PoNumber;
                        billModel.SupplierId   = bill.SupplierId;
                        billModel.Supplier     = db.Clients.Where(x => x.AspNetUserId == bill.SupplierId).FirstOrDefault().Name;
                        billModel.DueAmount    = bill.BalanceDue;
                        // billModel.TaxAmount = bill.TotalTaxAmount;
                        billModel.RoundOffNumber = bill.RoundOffNumber;
                    }


                    for (int j = 0; j < billedItems.Count(); j++)
                    {
                        subtotal += (billedItems[j].Quantity * billedItems[j].PricePerUnit);
                        billModel.TotalQuantity += billedItems[j].Quantity;
                    }

                    billModel.SubTotal = subtotal;

                    if (bill.TDSId != null)
                    {
                        billModel.TDSId     = bill.TDSId;
                        billModel.TDSLabel  = bill.TD.TaxName + "- [" + bill.TD.Rate + "%]";
                        billModel.TDSRate   = bill.TD.Rate;
                        billModel.TDSAmount = bill.TDSAmount;
                        tdsAmount           = billModel.TDSAmount;
                    }
                    else
                    {
                        tdsAmount = 0;
                    }

                    if (bill.CourierCharges != null)
                    {
                        billModel.CourierCharges = bill.CourierCharges;
                    }

                    if (bill.Discount != null)
                    {
                        if (bill.DiscountType == "Percent")
                        {
                            billModel.DiscountAmount = (bill.Discount * subtotal) / 100;
                        }
                        else
                        {
                            billModel.DiscountAmount = bill.Discount;
                        }
                        billModel.Discount     = bill.Discount;
                        billModel.DiscountType = bill.DiscountType;
                    }

                    billModel.Total = bill.Total;

                    return(Content(HttpStatusCode.OK, new { billedItems, billModel }));
                }
            }
            catch (Exception ex)
            {
                new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace);
                return(Content(HttpStatusCode.InternalServerError, "An error occured, please try again later"));
            }
        }