Ejemplo n.º 1
0
        public ActionResult AddPurchase(string request)
        {
            tbl_Purchase tbl_Purchase = JsonConvert.DeserializeObject <tbl_Purchase>(request);

            if (PurchaseItemStock.Count > 0)
            {
                var t = JsonConvert.SerializeObject(tbl_Purchase);

                db.tbl_Purchase.Add(tbl_Purchase);
                db.SaveChanges();

                PurchaseItemStock.ForEach(q => q.tbl_Items = null);

                db.tbl_ItemStock.AddRange(PurchaseItemStock);
                db.SaveChanges();

                tbl_Sequence NewSequenceValue = Helper.GenericHelper.GetNextUpdatedData("tbl_Purchase");
                db.Entry(NewSequenceValue).State = EntityState.Modified;
                //db.SaveChanges();

                tbl_Sequence NewSequenceValueItemStock = Helper.GenericHelper.GetNextUpdatedData("tbl_ItemStock");
                db.Entry(NewSequenceValueItemStock).State = EntityState.Modified;
                db.SaveChanges();

                //return RedirectToAction("Index");
                return(JavaScript("window.location = '/purchase/index'"));
            }
            else
            {
                ViewBag.PaymentMode = new SelectList(db.tbl_PaymentMode, "ID", "Mode", tbl_Purchase.PaymentMode);
                ViewBag.PartyName   = new SelectList(db.tbl_vendor, "ID", "Name", tbl_Purchase.PartyName);
                throw new InvalidOperationException("Please add item to continue!!");
            }
            //return RedirectToAction("Index");
        }
Ejemplo n.º 2
0
        //public async Task<ActionResult> Create([Bind(Include = "ID,Name,HSN_SAC_NO,Type,MeasuringUnit,Manufacture,BarCode,ItemUniqueDescription,Supplier,Photo,UseBatchNo,UseMfgDate,UseExpiryDate,CreatedDatetime")] tbl_Items tbl_Items)
        public async Task <ActionResult> Create([Bind(Include = "ID,Name,HSN_SAC_NO,Type,MeasuringUnit,Manufacture,BarCode,ItemUniqueDescription,Supplier,Photo,UseBatchNo,UseMfgDate,UseExpiryDate,CreatedDatetime,GST")] tbl_Items tbl_Items, [Bind(Include = "OpeningStock")] int?OpeningStock)
        {
            if (ModelState.IsValid)
            {
                db.tbl_Items.Add(tbl_Items);
                await db.SaveChangesAsync();

                tbl_Sequence NewSequenceValue = Helper.GenericHelper.GetNextUpdatedData("tbl_Items");
                db.Entry(NewSequenceValue).State = EntityState.Modified;
                await db.SaveChangesAsync();

                if (OpeningStock > 0)
                {
                    tbl_ItemStock tbl_ItemStock = new tbl_ItemStock()
                    {
                        ID              = tbl_Items.ID + "-" + Helper.GenericHelper.GetMaxValue("tbl_ItemStock") + "-1",
                        StockType       = "IN",
                        InvoiceNo       = "Opening Stock",
                        ItemID          = tbl_Items.ID,
                        Qty             = OpeningStock,
                        CreatedDatetime = tbl_Items.CreatedDatetime.ToString() ?? DateTime.Now.Date.ToString()
                    };
                    db.tbl_ItemStock.Add(tbl_ItemStock);
                    await db.SaveChangesAsync();
                }

                return(RedirectToAction("Index"));
            }

            ViewBag.Type          = new SelectList(db.tbl_ItemType, "ItemTypeId", "ItemType", tbl_Items.Type);
            ViewBag.MeasuringUnit = new SelectList(db.tbl_ItemUnits, "MeasurintUnitID", "MeasuringUnits", tbl_Items.MeasuringUnit);
            ViewBag.Supplier      = new SelectList(db.tbl_vendor, "ID", "Name", tbl_Items.Supplier);
            ViewBag.GST           = new SelectList(db.tbl_GST, "ID", "GST", tbl_Items.GST);
            return(View(tbl_Items));
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            tbl_Sequence tbl_Sequence = await db.tbl_Sequence.FindAsync(id);

            db.tbl_Sequence.Remove(tbl_Sequence);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> Edit([Bind(Include = "ID,TableName,PreFix,RecordCount")] tbl_Sequence tbl_Sequence)
        {
            if (ModelState.IsValid)
            {
                db.Entry(tbl_Sequence).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(tbl_Sequence));
        }
Ejemplo n.º 5
0
        public async Task <ActionResult> Create([Bind(Include = "ID,TableName,PreFix,RecordCount")] tbl_Sequence tbl_Sequence)
        {
            if (ModelState.IsValid)
            {
                db.tbl_Sequence.Add(tbl_Sequence);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(tbl_Sequence));
        }
Ejemplo n.º 6
0
        // GET: Sequence/Delete/5
        public async Task <ActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tbl_Sequence tbl_Sequence = await db.tbl_Sequence.FindAsync(id);

            if (tbl_Sequence == null)
            {
                return(HttpNotFound());
            }
            return(View(tbl_Sequence));
        }
Ejemplo n.º 7
0
        public async Task <ActionResult> CreateSupplier([Bind(Include = "AutoID,ID,Name,ContactPerson,ContactNo,PhoneNo,VendorType,Type,Place,DOB,GSTNo,TINNo,PANNo,CINNo,AdhaarNo,OpeningBalance,OpeningBalanceType,OpeningBalanceDate,CreditLimit,CreditPeriod,CreditInterestRate,DebitInterestRate,CreatedDatetime,Photo,Remark,SuretyPerson,SuretyPersonContactNo,SuretyPersonAddress")] tbl_vendor tbl_vendor)
        {
            if (ModelState.IsValid)
            {
                db.tbl_vendor.Add(tbl_vendor);
                await db.SaveChangesAsync();

                tbl_Sequence NewSequenceValue = Helper.GenericHelper.GetNextUpdatedData("tbl_Supplier");
                db.Entry(NewSequenceValue).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(tbl_vendor));
        }
Ejemplo n.º 8
0
        public async Task <ActionResult> Create([Bind(Include = "AutoID,ID,PartyInvoiceDate,PurchaseDate,PartyInvoiceNo,PartyName,PaymentDueAfter,ReverseCharge,tbl_ItemStock,Remark,DiscountAmount,OtherCharge,TotalAmountBeforeTax,TaxAmount,TotalAmountAfterTax,RoundOff,GrandTotal,PurchaseBook,PaymentMode,ScanCopy,CreatedDatetime")] tbl_Purchase tbl_Purchase, tbl_ItemStock tbl_ItemStock)
        {
            if (ModelState.IsValid)
            {
                var t = JsonConvert.SerializeObject(tbl_Purchase);
                db.tbl_Purchase.Add(tbl_Purchase);
                await db.SaveChangesAsync();

                tbl_Sequence NewSequenceValue = Helper.GenericHelper.GetNextUpdatedData("tbl_Purchase");
                db.Entry(NewSequenceValue).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            ViewBag.PaymentMode = new SelectList(db.tbl_PaymentMode, "ID", "Mode", tbl_Purchase.PaymentMode);
            ViewBag.PartyName   = new SelectList(db.tbl_vendor, "ID", "Name", tbl_Purchase.PartyName);
            return(View(tbl_Purchase));
        }
Ejemplo n.º 9
0
        public ActionResult AddPurchase(string request)
        {
            using (var transaction = db.Database.BeginTransaction()) // new System.Transactions.TransactionScope())
            {
                tbl_Purchase tbl_Purchase = JsonConvert.DeserializeObject <tbl_Purchase>(request);
                if (PurchaseItemStock.Count > 0)
                {
                    var t = JsonConvert.SerializeObject(tbl_Purchase);

                    db.tbl_Purchase.Add(tbl_Purchase);

                    PurchaseItemStock.ForEach(q => q.tbl_Items = null);
                    db.tbl_ItemStock.AddRange(PurchaseItemStock);

                    tbl_Sequence NewSequenceValue = Helper.GenericHelper.GetNextUpdatedData(SequenceTable.tbl_Purchase.ToString());
                    db.Entry(NewSequenceValue).State = EntityState.Modified;

                    tbl_Sequence NewSequenceValueItemStock = Helper.GenericHelper.GetNextUpdatedData(SequenceTable.tbl_ItemStock.ToString());
                    db.Entry(NewSequenceValueItemStock).State = EntityState.Modified;

                    //db.SaveChanges();

                    // 1 hold --  only save purchase & Item with status hold

                    // 2  CREDIT PURCHASE --  one transaction entry with credit (out) with unpaid status

                    // 3  CASH PAY  -- one transaction entry with credit (out)/ Paid
                    //             one payment Entry with full amount
                    //             one transaction entry with Debit (in) with payment ID

                    // 4 MULTI MODE PAY -- one transaction entry with credit (out)
                    //             one payment Entry
                    //             one transaction entry with Debit (in)

                    if (tbl_Purchase.PaymentMode.Value != PaymentMode.HOLD)  // not hold
                    {
                        decimal         amount                = tbl_Purchase.Amount;
                        string          creditTID             = Helper.GenericHelper.GetMaxValue(SequenceTable.tbl_TransactionCredit.ToString());
                        tbl_Transaction tbl_Transactioncredit = new tbl_Transaction()
                        {
                            ID = creditTID,

                            CreatedDatetime = tbl_Purchase.CreatedDatetime,
                            EntryDate       = tbl_Purchase.PurchaseDate.ToString(),

                            EntryType       = TransactionEntryType.Purchase.ToString(), //"Purchase", // Purchase/Sales/Recipt/Payment
                            Status          = TransactionStatus.Unpaid,                 ///Paid/Unpaid/Pending/Paid Against entries : // Recive  Against entries
                            TransactionType = TransactionType.Credit.ToString(),        ///Debit/ credit --  For Real: Debit what comes in, credit what goes out.
                            //TransactionRef = null,

                            EntryID    = tbl_Purchase.ID,
                            PurchaseID = tbl_Purchase.ID,
                            //SalesID = null,

                            Amount = tbl_Purchase.GrandTotal,

                            VendorID = tbl_Purchase.PartyName
                        };
                        db.tbl_Transaction.Add(tbl_Transactioncredit);
                        //db.SaveChanges();

                        tbl_Sequence NewSequenceValuetbl_Transaction = Helper.GenericHelper.GetNextUpdatedData("tbl_TransactionCredit");
                        db.Entry(NewSequenceValuetbl_Transaction).State = EntityState.Modified;

                        //db.SaveChanges();
                        if (tbl_Purchase.PaymentMode == 2)  //CREDIT PURCHASE
                        {
                        }
                        else if (tbl_Purchase.PaymentMode == 3)  //CASH PAY
                        {
                            string      tbl_PaymentID = Helper.GenericHelper.GetMaxValue("tbl_Payment");
                            tbl_Payment tbl_Payment   = new tbl_Payment()
                            {
                                ID              = tbl_PaymentID,
                                Amount          = tbl_Purchase.GrandTotal,
                                CreatedDatetime = tbl_Purchase.CreatedDatetime,

                                PartyName   = tbl_Purchase.PartyName,
                                PaymentDate = tbl_Purchase.PurchaseDate.ToString(),
                                PaymentMode = "CASH",
                                //Remark = "",
                                //TransactionID = creditTID,
                            };
                            db.tbl_Payment.Add(tbl_Payment);

                            tbl_Sequence NewSequenceValuetbl_Payment = Helper.GenericHelper.GetNextUpdatedData("tbl_Payment");
                            db.Entry(NewSequenceValuetbl_Payment).State = EntityState.Modified;
                            //db.SaveChanges();

                            tbl_Transaction tbl_TransactionDebit = new tbl_Transaction()
                            {
                                ID = Helper.GenericHelper.GetMaxValue("tbl_TransactionDebit"),

                                CreatedDatetime = tbl_Purchase.CreatedDatetime,
                                EntryDate       = tbl_Purchase.PurchaseDate.ToString(),

                                EntryType       = TransactionEntryType.Purchase.ToString(),               // "Purchase", // Purchase/Sales/Recipt/Payment
                                Status          = TransactionStatus.PaidAgainstEntries + tbl_Purchase.ID, ///Paid/Unpaid/Pending/Paid Against entries : // Recive  Against entries
                                TransactionType = TransactionType.Debit.ToString(),                       ///Debit/ credit --  For Real: Debit what comes in, credit what goes out.
                                TransactionRef  = tbl_Purchase.ID,

                                EntryID = tbl_PaymentID,
                                //PurchaseID = null,
                                //SalesID = null,
                                PaymentID = tbl_PaymentID,

                                Amount = tbl_Purchase.GrandTotal,

                                VendorID = tbl_Purchase.PartyName
                            };
                            db.tbl_Transaction.Add(tbl_TransactionDebit);

                            tbl_Sequence NewSequenceValuetbl_Transaction2 = Helper.GenericHelper.GetNextUpdatedData("tbl_TransactionDebit");
                            db.Entry(NewSequenceValuetbl_Transaction2).State = EntityState.Modified;

                            //db.SaveChanges();

                            //var tbl_Transactionresult = db.tbl_Transaction.Where(q => q.ID == creditTID).FirstOrDefault();
                            tbl_Transactioncredit.Status = TransactionStatus.Paid;
                            //db.Entry(tbl_Transactionresult).State = EntityState.Modified;
                            //db.SaveChanges();
                        }
                        else if (tbl_Purchase.PaymentMode == 4)  //MULTI MODE PAY
                        {
                            string      tbl_PaymentID = Helper.GenericHelper.GetMaxValue("tbl_Payment");
                            tbl_Payment tbl_Payment   = new tbl_Payment()
                            {
                                ID              = tbl_PaymentID,
                                Amount          = amount,
                                CreatedDatetime = tbl_Purchase.CreatedDatetime,

                                PartyName   = tbl_Purchase.PartyName,
                                PaymentDate = tbl_Purchase.PurchaseDate.ToString(),
                                PaymentMode = "CASH",
                                //Remark = "",
                                //TransactionID = creditTID,
                            };
                            db.tbl_Payment.Add(tbl_Payment);

                            tbl_Sequence NewSequenceValuetbl_Payment = Helper.GenericHelper.GetNextUpdatedData("tbl_Payment");
                            db.Entry(NewSequenceValuetbl_Payment).State = EntityState.Modified;
                            //db.SaveChanges();

                            tbl_Transaction tbl_TransactionDebit = new tbl_Transaction()
                            {
                                ID = Helper.GenericHelper.GetMaxValue("tbl_TransactionDebit"),

                                CreatedDatetime = tbl_Purchase.CreatedDatetime,
                                EntryDate       = tbl_Purchase.PurchaseDate.ToString(),

                                EntryType       = TransactionEntryType.Purchase.ToString(),               // "Purchase", // Purchase/Sales/Recipt/Payment
                                Status          = TransactionStatus.PaidAgainstEntries + tbl_Purchase.ID, ///Paid/Unpaid/Pending/Paid Against entries : // Recive  Against entries
                                TransactionType = TransactionType.Debit.ToString(),                       ///Debit/ credit --  For Real: Debit what comes in, credit what goes out.
                                TransactionRef  = tbl_Purchase.ID,

                                EntryID = tbl_PaymentID,
                                //PurchaseID = null,
                                //SalesID = null,
                                PaymentID = tbl_PaymentID,

                                Amount = amount,

                                VendorID = tbl_Purchase.PartyName
                            };
                            db.tbl_Transaction.Add(tbl_TransactionDebit);

                            tbl_Sequence NewSequenceValuetbl_Transaction2 = Helper.GenericHelper.GetNextUpdatedData("tbl_TransactionDebit");
                            db.Entry(NewSequenceValuetbl_Transaction2).State = EntityState.Modified;
                        }
                    }

                    bool saved = false;

                    try
                    {
                        db.SaveChanges();
                        saved = true;
                    }
                    catch (Exception e)
                    {
                        throw new InvalidOperationException(e.Message);
                    }
                    finally
                    {
                        if (saved)
                        {
                            transaction.Commit();
                        }
                    }

                    //if (tbl_Purchase.PaymentMode == 4)  //MULTI MODE PAY
                    //    return JavaScript("window.location = '/purchase/index'");
                    //else
                    return(JavaScript("window.location = '/purchase/index'"));
                }
                else
                {
                    ViewBag.PaymentMode = new SelectList(db.tbl_PaymentMode, "ID", "Mode", tbl_Purchase.PaymentMode);
                    ViewBag.PartyName   = new SelectList(db.tbl_vendor, "ID", "Name", tbl_Purchase.PartyName);
                    throw new InvalidOperationException("Please add item to continue!!");
                }
            }
            //return RedirectToAction("Index");
        }