예제 #1
0
        public JsonResult GenerateSalesTaxInvoice(FormCollection form)
        {
            if (ModelState.IsValid)
            {
                var js = new JavaScriptSerializer();
                try
                {
                    int stPt_Id = 0;

                    var stPt = JsonConvert.DeserializeObject <SalesTax_Pt>(form["SalesTax_PtObj"]);
                    stPt.Customer   = db.Customers.Where(c => c.Customer_Id == stPt.CustomerId).SingleOrDefault();
                    stPt.STP_Date   = DateTime.Now;
                    stPt.STP_Status = true;
                    db.SalesTax_Pts.Add(stPt);
                    db.SaveChanges();

                    stPt_Id = db.SalesTax_Pts.Max(s => s.STP_Id);

                    try
                    {
                        List <SalesTax_Ch> soCh_list = js.Deserialize <SalesTax_Ch[]>(form["SalesTax_ChList"]).ToList();
                        foreach (var soCh in soCh_list)
                        {
                            SalesTax_Ch saleTaxCh = new SalesTax_Ch();
                            saleTaxCh.STP_Id      = stPt_Id;
                            saleTaxCh.SalesTax_Pt = db.SalesTax_Pts.Find(stPt_Id);
                            saleTaxCh.SOC_Id      = soCh.SOC_Id;
                            var saleOrderChObj = db.SaleOrder_Ches.Find(soCh.SOC_Id);
                            saleTaxCh.SaleOrder_Ch = saleOrderChObj;
                            db.SalesTax_Ches.Add(saleTaxCh);
                            db.SaveChanges();

                            // convert sale order ch status from pending to complete
                            saleOrderChObj.SOC_SalesTaxStatus = ds.Status_Complete;
                            db.Entry(saleOrderChObj).State    = EntityState.Modified;
                            db.SaveChanges();
                        }
                    }
                    catch (Exception e)
                    { }

                    SalePurchaseInvoiceType mSalePurchaseInvoiceType = new SalePurchaseInvoiceType();
                    Invoice invoice = new Invoice()
                    {
                        Invoice_No         = js.Deserialize <int>(form["InvoiceNo"]),
                        Invoice_DocumentNo = js.Deserialize <int>(form["Invoice_DocumentNo"]),
                        Invoice_Type       = ds.SalesTax_InvoiceType,
                        SalePurchase_Id    = stPt_Id,
                        Invoice_Date       = DateTime.Now,
                        Invoice_Status     = true
                    };
                    db.Invoices.Add(invoice);
                    db.SaveChanges();

                    return(Json("Save", JsonRequestBehavior.AllowGet));
                }
                catch (Exception e)
                { }
            }
            return(Json("", JsonRequestBehavior.AllowGet));
        }
예제 #2
0
        public JsonResult CreateSaleOrder(FormCollection form)
        {
            string userId = Session["UserId"].ToString();

            if (ModelState.IsValid)
            {
                var js = new JavaScriptSerializer();
                try
                {
                    //OrderNumber oNo = new OrderNumber();
                    int soPt_Id = 0;

                    var soPt = JsonConvert.DeserializeObject <SaleOrder_Pt>(form["SaleOrder_PtObj"]);
                    if (User.IsInRole(ds.Role_Customer))
                    {
                        soPt.CustomerId = db.Customers.Where(c => c.ApplicationUser.Id == userId).SingleOrDefault().Customer_Id;
                        soPt.Customer   = db.Customers.Where(c => c.ApplicationUser.Id == userId).SingleOrDefault();
                    }
                    else if (User.IsInRole(ds.Role_Admin) && soPt.CustomerId > 0)
                    {
                        soPt.Customer = db.Customers.Where(c => c.Customer_Id == soPt.CustomerId).SingleOrDefault();
                    }
                    else
                    {
                        return(Json("Not Saved", JsonRequestBehavior.AllowGet));
                    }

                    soPt.SOP_Date             = DateTime.Now;
                    soPt.SOP_ModificationDate = DateTime.Now;
                    soPt.SOP_DeliveryDate     = Convert.ToDateTime(js.Deserialize <string>(form["DeliveryDate"]));
                    soPt.SOP_Status           = ds.Status_Pending;
                    //soPt.SOP_SO = oNo.GenerateSaleOrderNumber().ToString();
                    db.SaleOrder_Pts.Add(soPt);
                    db.SaveChanges();

                    soPt_Id = db.SaleOrder_Pts.Max(s => s.SOP_Id);

                    try
                    {
                        List <SaleOrder_Ch> soCh_list = js.Deserialize <SaleOrder_Ch[]>(form["SaleOrder_ChList"].ToString()).ToList();
                        foreach (var soCh in soCh_list)
                        {
                            soCh.Product            = db.Products.Where(p => p.Product_Id == soCh.Product_Id).SingleOrDefault();
                            soCh.SOP_Id             = soPt_Id;
                            soCh.SaleOrder_Pt       = db.SaleOrder_Pts.Find(soPt_Id);
                            soCh.SOC_SalesTaxStatus = ds.Status_Pending;
                            db.SaleOrder_Ches.Add(soCh);
                            db.SaveChanges();
                        }
                    }
                    catch (Exception e)
                    {  }

                    SalePurchaseInvoiceType mSalePurchaseInvoiceType = new SalePurchaseInvoiceType();
                    Invoice invoice = new Invoice()
                    {
                        //Invoice_No = mSalePurchaseInvoiceType.GenerateInvoiceNo(ds.SaleInvoiceType),
                        Invoice_No         = js.Deserialize <int>(form["InvoiceNo"]),
                        Invoice_DocumentNo = js.Deserialize <int>(form["Invoice_DocumentNo"]),
                        Invoice_Type       = ds.SaleInvoiceType,
                        SalePurchase_Id    = soPt_Id,
                        Invoice_Date       = DateTime.Now,
                        Invoice_Status     = true
                    };
                    db.Invoices.Add(invoice);
                    db.SaveChanges();

                    Notification noti = new Notification();
                    noti.Notification_Detail = "New Sale Order of SO #: '" + soPt.SOP_SO + "' has been created by customer.";
                    if (User.IsInRole(ds.Role_Customer))
                    {
                        noti.Id = userId;
                        noti.ApplicationUser = db.Users.Where(u => u.Id == userId).SingleOrDefault();
                    }
                    else
                    {
                        noti.Id = soPt.Customer.ApplicationUser.Id;
                        noti.ApplicationUser = soPt.Customer.ApplicationUser;
                    }
                    noti.Notification_ItemId   = soPt_Id;
                    noti.Notification_ItemType = ds.Role_Admin;
                    noti.Notification_Date     = DateTime.Now;
                    noti.Notification_IsSeen   = false;
                    noti.Notification_Status   = true;
                    db.Notifications.Add(noti);
                    db.SaveChanges();

                    return(Json("Save", JsonRequestBehavior.AllowGet));
                }
                catch (Exception e)
                {  }
            }
            return(Json("", JsonRequestBehavior.AllowGet));
        }
예제 #3
0
        public JsonResult CreatePurchaseOrder(FormCollection form)
        {
            if (ModelState.IsValid)
            {
                var js = new JavaScriptSerializer();
                try
                {
                    int poPt_Id = 0;

                    var poPt = JsonConvert.DeserializeObject <PurchaseOrder_Pt>(form["PurchaseOrder_PtObj"]);
                    poPt.Vendor               = db.Vendors.Where(v => v.Vendor_Id == poPt.Vendor_Id).SingleOrDefault();
                    poPt.POP_Date             = DateTime.Now;
                    poPt.POP_ModificationDate = DateTime.Now;
                    poPt.POP_DeliveryDate     = Convert.ToDateTime(js.Deserialize <string>(form["DeliveryDate"]));
                    poPt.POP_Status           = ds.Status_Pending;
                    db.PurchaseOrder_Pts.Add(poPt);
                    db.SaveChanges();

                    poPt_Id = db.PurchaseOrder_Pts.Max(s => s.POP_Id);

                    try
                    {
                        List <PurchaseOrder_Ch> poCh_list = js.Deserialize <PurchaseOrder_Ch[]>(form["PurchaseOrder_ChList"].ToString()).ToList();
                        foreach (var poCh in poCh_list)
                        {
                            poCh.Product          = db.Products.Where(p => p.Product_Id == poCh.Product_Id).SingleOrDefault();
                            poCh.POP_Id           = poPt_Id;
                            poCh.PurchaseOrder_Pt = db.PurchaseOrder_Pts.Find(poPt_Id);
                            db.PurchaseOrder_Ches.Add(poCh);
                            db.SaveChanges();
                        }
                    }
                    catch (Exception e)
                    { }

                    SalePurchaseInvoiceType mSalePurchaseInvoiceType = new SalePurchaseInvoiceType();
                    Invoice invoice = new Invoice()
                    {
                        //Invoice_No = mSalePurchaseInvoiceType.GenerateInvoiceNo(ds.PurchaseInvoiceType),
                        Invoice_No         = js.Deserialize <int>(form["InvoiceNo"]),
                        Invoice_DocumentNo = js.Deserialize <int>(form["Invoice_DocumentNo"]),
                        Invoice_Type       = ds.PurchaseInvoiceType,
                        SalePurchase_Id    = poPt_Id,
                        Invoice_Date       = DateTime.Now,
                        Invoice_Status     = true
                    };
                    db.Invoices.Add(invoice);
                    db.SaveChanges();

                    var          user = db.Users.Where(u => u.Id == poPt.Vendor.Id).SingleOrDefault();
                    Notification noti = new Notification();
                    noti.Notification_Detail = "New Purchase Order of PO #: '" + poPt.POP_PO + "' has been created by admin.";
                    noti.Id = user.Id;
                    noti.ApplicationUser       = user;
                    noti.Notification_ItemId   = poPt_Id;
                    noti.Notification_ItemType = ds.Role_Vendor;
                    noti.Notification_Date     = DateTime.Now;
                    noti.Notification_IsSeen   = false;
                    noti.Notification_Status   = true;
                    db.Notifications.Add(noti);
                    db.SaveChanges();

                    return(Json("Save", JsonRequestBehavior.AllowGet));
                }
                catch (Exception e)
                { }
            }
            return(Json("", JsonRequestBehavior.AllowGet));
        }