Exemplo n.º 1
0
        public JsonResult ExpenseVouchers(voucherLine vm)
        {
            var result = false;

            if (vm != null)
            {
                int     count = db.Vouchers.Count(o => o.voucherNo == vm.voucherNo);
                Voucher vr    = db.Vouchers.Find(vm.voucherNo);
                if (count == 0)
                {
                    //post data to both tables
                    Voucher v = new Voucher();
                    v.voucherNo   = vm.voucherNo;
                    v.voucherDate = vm.voucherDate;
                    v.voucherType = vm.voucherType;
                    db.Vouchers.Add(v);
                    db.SaveChanges();
                    VoucherBody vb = new VoucherBody();
                    vb.voucherNo   = vm.voucherNo;
                    vb.accountNo   = vm.accountNo;
                    vb.accountName = vm.accountName;
                    vb.description = vm.description;
                    vb.debit       = vm.debit;
                    vb.credit      = vm.credit;
                    db.VoucherBodies.Add(vb);
                    db.SaveChanges();
                }
                else
                {
                    //add only to 2nd table
                    VoucherBody vb = new VoucherBody();
                    vb.voucherNo   = vm.voucherNo;
                    vb.accountNo   = vm.accountNo;
                    vb.accountName = vm.accountName;
                    vb.description = vm.description;
                    vb.debit       = vm.debit;
                    vb.credit      = vm.credit;
                    db.VoucherBodies.Add(vb);
                    db.SaveChanges();
                }
            }
            result = true;
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 2
0
        public JsonResult DeleteConfirmed(int?id)
        {
            bool        result = false;
            Voucher     v      = db.Vouchers.SingleOrDefault(f => f.voucherNo == id);
            VoucherBody vb     = db.VoucherBodies.SingleOrDefault(f => f.code == id);

            if (v != null)
            {
                db.Vouchers.Remove(v);
                db.VoucherBodies.RemoveRange(db.VoucherBodies.Where(f => f.voucherNo == id));
                db.SaveChanges();
                result = true;
            }
            else
            {
                db.VoucherBodies.Remove(vb);
                db.SaveChanges();
                result = true;
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public ActionResult voucher(purchaseViewModel pvm)
        {
            Voucher vo  = new Voucher();
            var     max = db.Vouchers.ToList().OrderByDescending(r => r.voucherNo).FirstOrDefault();

            vo.voucherNo   = max == null ? 1 : (max.voucherNo) + 1;
            vo.voucherDate = pvm.purchaseDate;
            vo.voucherType = 10; //Purchase Voucher
            db.Vouchers.Add(vo);
            db.SaveChanges();
            Purchase purchase = new Purchase();

            purchase.purchaseId   = pvm.purchaseId;
            purchase.purchaseDate = pvm.purchaseDate;
            purchase.vendorCode   = pvm.vendorCode;
            purchase.vendorName   = pvm.vendorName;
            purchase.purVoucherNo = vo.voucherNo;
            db.Purchases.Add(purchase);
            decimal cr = 0;

            foreach (var item in pvm.purchaseDetails)
            {
                PurchaseDetail pd = new PurchaseDetail();
                pd.serialNo = db.Purchases.Sum(r => r.purchaseId).ToString();
                Product uom = db.Products.Single(s => s.productCode == item.productCode);
                if (uom != null)
                {
                    uom.currentQuantity  += item.quantity;
                    uom.averagePrice      = uom.averagePrice + item.purchasePrice / 2;
                    uom.lastPurchasePrice = item.purchasePrice;
                    uom.price             = item.purchasePrice;
                }
                pd.purchaseDetailsId = pvm.purchaseId;
                pd.productCode       = item.productCode;
                pd.productName       = item.productName;
                pd.unitOfMeasure     = item.unitOfMeasure;
                pd.quantity          = item.quantity;
                pd.purchasePrice     = item.purchasePrice;
                pd.amount            = item.amount;
                db.PurchaseDetails.Add(pd);
                db.SaveChanges();
                VoucherBody    vbdp = new VoucherBody();
                ExpenseAccount ex   = new ExpenseAccount();
                ex               = db.ExpenseAccounts.Single(r => r.code == uom.chartOfAccCode);
                vbdp.accountNo   = ex.code;
                vbdp.accountName = ex.name;
                vbdp.debit       = item.amount;
                vbdp.credit      = 0;
                vbdp.description = "Item Purchased";
                vbdp.voucherNo   = vo.voucherNo;
                db.VoucherBodies.Add(vbdp);
                db.SaveChanges();
                cr += item.amount;
            }
            VoucherBody vbcp = new VoucherBody();
            var         ven  = db.Vendors.SingleOrDefault(r => r.vendorCode == pvm.vendorCode);
            var         ea   = db.ExpenseAccounts.Single(r => r.code == ven.chartOfAccCode);

            vbcp.accountNo   = ea.code;
            vbcp.accountName = ea.name;
            vbcp.credit      = cr;
            vbcp.debit       = 0;
            vbcp.description = "Item Purchased";
            vbcp.voucherNo   = vo.voucherNo;
            db.VoucherBodies.Add(vbcp);
            db.SaveChanges();
            if (pvm.transactionType == 1)
            {
                Voucher v       = new Voucher();
                var     maximum = db.Vouchers.ToList().OrderByDescending(r => r.voucherNo).FirstOrDefault();
                v.voucherNo   = max == null ? 1 : (maximum.voucherNo) + 1;
                v.voucherDate = pvm.purchaseDate;
                v.voucherType = 1; //Cash Payment
                db.Vouchers.Add(v);
                db.SaveChanges();
                VoucherBody vbd    = new VoucherBody();
                var         vender = db.Vendors.SingleOrDefault(r => r.vendorCode == pvm.vendorCode);
                var         exv    = db.ExpenseAccounts.Single(r => r.code == vender.chartOfAccCode);
                vbd.accountNo   = exv.code;
                vbd.accountName = exv.name;
                vbd.credit      = 0;
                vbd.debit       = pvm.netPayment;
                vbd.description = "Cash Payment";
                vbd.voucherNo   = v.voucherNo;
                db.VoucherBodies.Add(vbd);
                db.SaveChanges();
                VoucherBody    vbc = new VoucherBody();
                ExpenseAccount exp = db.ExpenseAccounts.Single(r => r.code == pvm.accountno);
                vbc.accountNo   = exp.code;
                vbc.accountName = exp.name;
                vbc.debit       = 0;
                vbc.credit      = pvm.netPayment;
                vbc.description = "Paid";
                vbc.voucherNo   = v.voucherNo;
                db.VoucherBodies.Add(vbc);
                db.SaveChanges();
            }
            return(Json(""));
        }
        public ActionResult voucher(saleViewModel svm)
        {
            Voucher vo  = new Voucher();
            var     max = db.Vouchers.ToList().OrderByDescending(r => r.voucherNo).FirstOrDefault();

            vo.voucherNo   = max == null ? 1 : (max.voucherNo) + 1;
            vo.voucherDate = svm.saleDate;
            vo.voucherType = 11; //Sale Voucher
            db.Vouchers.Add(vo);
            db.SaveChanges();
            Sale sale = new Sale();

            sale.saleId        = svm.saleId;
            sale.saleDate      = svm.saleDate;
            sale.customerCode  = svm.customerCode;
            sale.customerName  = svm.customerName;
            sale.saleVoucherNo = vo.voucherNo;
            db.Sales.Add(sale);
            db.SaveChanges();
            decimal dr = 0;

            foreach (var item in svm.saleDetails)
            {
                SaleDetail sd = new SaleDetail();
                sd.serialNo = db.Sales.Select(r => r.saleId).Sum().ToString();
                Product uom = db.Products.Single(r => r.productCode == item.productCode);
                if (uom != null)
                {
                    if (uom.currentQuantity > 0)
                    {
                        uom.currentQuantity -= item.quantity;
                    }
                    uom.price = item.salePrice;
                }
                sd.saleDetailsId = svm.saleId;
                sd.productCode   = item.productCode;
                sd.productName   = item.productName;
                sd.unitOfMeasure = item.unitOfMeasure;
                sd.quantity      = item.quantity;
                sd.salePrice     = item.salePrice;
                sd.amount        = item.amount;
                db.SaleDetails.Add(sd);
                db.SaveChanges();
                VoucherBody    vbcp = new VoucherBody();
                ExpenseAccount ea   = db.ExpenseAccounts.Single(r => r.code == uom.chartOfAccCode + 1);
                vbcp.accountNo   = ea.code;
                vbcp.accountName = ea.name;
                vbcp.credit      = item.amount;
                vbcp.debit       = 0;
                vbcp.description = "Item Sold";
                vbcp.voucherNo   = vo.voucherNo;
                dr += item.amount;
            }
            VoucherBody vbdp = new VoucherBody();
            var         cus  = db.Customers.SingleOrDefault(r => r.customerCode == svm.customerCode);
            var         ex   = db.ExpenseAccounts.Single(r => r.code == cus.chartOfAccCode);

            vbdp.accountNo   = ex.code;
            vbdp.accountName = ex.name;
            vbdp.credit      = 0;
            vbdp.debit       = dr;
            vbdp.description = "Item Sold";
            vbdp.voucherNo   = vo.voucherNo;
            db.VoucherBodies.Add(vbdp);
            db.SaveChanges();
            if (svm.transactionType == 1)
            {
                Voucher v       = new Voucher();
                var     maximum = db.Vouchers.ToList().OrderByDescending(r => r.voucherNo).FirstOrDefault();
                v.voucherNo   = maximum == null ? 1 : (maximum.voucherNo) + 1;
                v.voucherDate = svm.saleDate;
                v.voucherType = 2; //Cash Reciept
                db.Vouchers.Add(v);
                db.SaveChanges();
                VoucherBody vbd = new VoucherBody();
                var         exp = db.ExpenseAccounts.Single(r => r.code == svm.accountno);
                vbd.accountNo   = exp.code;
                vbd.accountName = exp.name;
                vbd.debit       = svm.netPayment;
                vbd.credit      = 0;
                vbd.description = "Cash Received";
                vbd.voucherNo   = v.voucherNo;
                db.VoucherBodies.Add(vbd);
                db.SaveChanges();
                VoucherBody vbc      = new VoucherBody();
                var         customer = db.Customers.SingleOrDefault(r => r.customerCode == svm.customerCode);
                var         exc      = db.ExpenseAccounts.Single(r => r.code == customer.chartOfAccCode);
                vbc.accountNo   = exc.code;
                vbc.accountName = exc.name;
                vbc.credit      = svm.netPayment;
                vbc.debit       = 0;
                vbc.description = "net Payment";
                vbc.voucherNo   = v.voucherNo;
                db.VoucherBodies.Add(vbc);
                db.SaveChanges();
            }
            return(Json(""));
        }