Example #1
0
        public ActionResult UpdateStatus(string status, int id, string note)
        {
            SameSoftWeb.Models.SameSoftwareWebEntities db = new SameSoftWeb.Models.SameSoftwareWebEntities();

            var p = db.tblProblems.Where(a => a.Problem_ID == id).FirstOrDefault();

            if (p != null)
            {
                p.Status        = status;
                p.Solution_Note = note;
                db.SaveChanges();
            }
            return(RedirectToAction("Details", "Issues", new { id = id }));
        }
Example #2
0
        public ActionResult add_sales_order(int[] item_id, float[] qty, string[] batch, float[] price, float discount, string payment_method, int?customer_id, DateTime?trandate, float?cash_payment)
        {
            //UsersController u = new UsersController();
            //u.checkaccess(33);

            if (cash_payment == null)
            {
                cash_payment = 0;
            }

            int userid            = (int)Session["UserID"];
            int business_division = (int)1;


            DateTime vdate = helper.sitemethods.getdate();

            if (trandate != null)
            {
                DateTime dt = (DateTime)trandate;
                if (dt.Date == vdate.Date)
                {
                    vdate = helper.sitemethods.getdate();
                }
                else
                {
                    vdate = dt;
                }
            }



            double balance      = 0;
            var    Cust_balance = db.sp_Get_Customer_with_Balance2(customer_id).FirstOrDefault();

            if (Cust_balance != null)
            {
                balance = Cust_balance.Total;
            }


            // Validate
            db.Database.BeginTransaction();
            int inventory_type_id = (int)db.Inventory_Types.Where(a => a.Inventory_Type == "Sales").Select(a => a.Inventory_type_id).FirstOrDefault();

            db.tblInventory_Transactions.Add(new Models.tblInventory_Transactions {
                Business_Division_Id = business_division, Total = 0, Tran_Date = vdate, Status = "Open", UserID = userid, Payment_Method = payment_method, Inventory_type_id = inventory_type_id, Tran_Nbr = "TRAN123", Discount = discount, Customer_ID = customer_id, Cash_Payment = cash_payment
            });
            db.SaveChanges();

            int last_inventory_id = 0;

            last_inventory_id = db.tblInventory_Transactions.Select(a => a.Inventory_Tran_ID).Max();

            for (int x = 0; x <= item_id.Length - 1; x++)
            {
                int itemid      = item_id[x];
                var item_Detail = db.Items.Where(a => a.Item_Id == itemid).FirstOrDefault();
                db.tblInventory_Transaction_Details.Add(new Models.tblInventory_Transaction_Details {
                    Inventory_Tran_ID = last_inventory_id, Item_Id = item_id[x], Qty_In = 0, Qty_Out = qty[x], Unit_Price = (float)item_Detail.Unit_Cost, Sales_price = price[x], Batch = batch[x]
                });
            }
            db.SaveChanges();
            float total = 0;

            total = (float)db.tblInventory_Transaction_Details.Where(a => a.Inventory_Tran_ID == last_inventory_id).Select(a => a.Qty_Out * a.Sales_price).Sum();
            var p = db.tblInventory_Transactions.Where(f => f.Inventory_Tran_ID == last_inventory_id).FirstOrDefault();

            p.Total = total;

            if (payment_method.Contains("Invoice"))
            {
            }
            else
            {
                p.Cash_Payment = total;
            }


            int serialno = 0;
            int?sr       = db.tblInvoices.Where(a => a.Invoice_id == 1).Select(a => a.Invoice_No).FirstOrDefault();

            if (sr == null || sr == 0)
            {
                serialno = int.Parse(db.tblSettings.Where(a => a.ID == 1).Select(a => a.Value).FirstOrDefault());
            }
            else
            {
                serialno = (int)sr + 1;
            }
            p.Invoice_No = serialno;

            db.SaveChanges();
            db.Database.CurrentTransaction.Commit();



            var InvoiceUpdate = db.tblInvoices.FirstOrDefault();

            if (InvoiceUpdate != null)
            {
                InvoiceUpdate.Invoice_No = serialno;
                db.SaveChanges();
            }



            //add log
            sitemethods.addlog("Add Data", "Add Sales Inv # (" + serialno + ")  Amonut of   " + total, business_division, userid);


            if (payment_method.Contains("Invoice"))
            {
                // Add Customer Transaction

                int Cust_Tran_Type = 0;
                Cust_Tran_Type = db.tblCustomer_Tran_Type.Where(a => a.Tran_Type == "Purchase").Select(a => a.Cust_Tran_Type_ID).FirstOrDefault();
                int?cust_tran_id = null;
                try
                {
                    cust_tran_id = db.tblCustomer_Transaction.Where(a => a.CustomerID == customer_id && a.Status == "Open").Select(a => a.Cust_Tran_ID).Max();
                }
                catch (Exception ex) { }


                if (cust_tran_id == null)
                {
                    db.tblCustomer_Transaction.Add(new tblCustomer_Transaction {
                        Amount = total - discount, CustomerID = (int)customer_id, Status = "Open", Tran_Date = vdate, UserID = userid
                    });
                    db.SaveChanges();
                    cust_tran_id = db.tblCustomer_Transaction.Where(a => a.UserID == userid).Select(a => a.Cust_Tran_ID).Max();
                }
                db.tblCustomer_Transaction_Detail.Add(new tblCustomer_Transaction_Detail {
                    Debit = total - discount, Credit = 0, Cust_Tran_Type_ID = Cust_Tran_Type, Status = "Open", UserID = userid, Description = "Custmer Invoice Order #" + serialno, Inventory_Tran_ID = last_inventory_id, Tran_Nbr = "N/A", Trans_Date = vdate, Cust_Tran_ID = (int)cust_tran_id, Invoice_No = serialno, Balance = (float)balance
                });
                db.SaveChanges();
                return(RedirectToAction("PrintInvoice", "Accounting", new { id = serialno }));
            }

            return(RedirectToAction("PrintInvoice", "Accounting", new { id = serialno }));
        }