Ejemplo n.º 1
0
        public ActionResult DebitVoucher(VoucherCustom vc)
        {
            VoucherCustom v = vc;
            Voucher voucher = vc.voucher;

            voucher.VoucherTypeId = 1;

            var user = uService.GetSingleUserByEmail(HttpContext.User.Identity.Name);
            var AccSet = sService.GetAllByUserId(user.Id);
            int branchId = AccSet.Companies.Id;

            if (vService.CreateVoucher(voucher))
            {
                List<VoucherDetail> vds = vc.voucherDetails;

                foreach (var voucherDetail in vds)
                {
                    voucherDetail.VoucherId = voucher.Id;
                    try
                    {
                        if (!vdService.CreateVoucherDetail(voucherDetail))
                            return Content("One or more Voucher details could not added Successfully");
                    }
                    catch (Exception)
                    {
                        return Content("Voucher Details problem");
                    }
                }
            }

            else
            {
                return Content("Failed To Add Voucher!!!!");
            }

            return Content("Success");
        }
Ejemplo n.º 2
0
        public ActionResult RepeatingJournal(VoucherCustom vc)
        {
            VoucherCustom v = vc;
            Voucher voucher = vc.voucher;

            var vtObj = _voucherType.GetVoucherTypeByCode("04");
            if (vtObj != null)
            {
                voucher.VoucherTypeId = vtObj.Id;
            }
            else
            {
                TempData.Add("errMsg", "Please Add voucher type as RepeatingJournal with 04 Code.");
                return RedirectToAction("RepeatingJournal", "Voucher", new { area = "Accounts" });
            }

            var user = _uService.GetSingleUserByEmail(HttpContext.User.Identity.Name);
            var accSet = _sService.GetAllByUserId(user.Id);

            var empObj = _empService.GetEmployeeByUserIdAndCompanyId(user.Id, (int)accSet.CompanyId);
            if (empObj != null)
            {
                voucher.EmployeeId = empObj.Id;
            }
            else
            {
                TempData.Add("errMsg", "User must be a employee for this Transaction.");
                return RedirectToAction("RepeatingJournal", "Voucher", new { area = "Accounts" });
                //return Content("User must be a employee for this Transaction.");
            }

            if (accSet.CompanyId != null) voucher.BranchId = (int)accSet.CompanyId;
            if (Request.Form["post"] != null)
            {
                voucher.Posted = 1;
            }
            else if (Request.Form["draft"] != null)
            {
                voucher.Posted = 0;
            }
            voucher.BillNo = Request.Form["billnop1"] + " " + Request.Form["billnop2"]; //I have no Idea why??
            if (_vService.CreateVoucher(voucher))
            {
                List<VoucherDetail> vds = vc.voucherDetails;

                foreach (var voucherDetail in vds)
                {
                    voucherDetail.VoucherId = voucher.Id;
                    try
                    {
                        if (!_vdService.CreateVoucherDetail(voucherDetail))
                        {
                            TempData.Add("errMsg", "One or more Voucher details could not added Successfully");
                            return RedirectToAction("RepeatingJournal", "Voucher", new { area = "Accounts" });

                        }
                          //  return Content("One or more Voucher details could not added Successfully");
                    }
                    catch (Exception)
                    {
                        TempData.Add("errMsg", "Voucher Details problem");
                        return RedirectToAction("RepeatingJournal", "Voucher", new { area = "Accounts" });
                        //return Content("Voucher Details problem");
                    }
                }
                string data = Request.Form["note_data"];

                if (Request.Form["note_data"] != "")
                {
                    JArray noteData = JArray.Parse(data);

                    var VDoc = new VoucherDocument();
                    for (int i = 0; i < noteData.Count(); i++)
                    {

                        VDoc.CreatedDate = Convert.ToDateTime(noteData[i]["date"].ToString());
                        VDoc.Description = noteData[i]["des"].ToString();
                        VDoc.DocumentType = noteData[i]["type"].ToString();
                        VDoc.EmployeeId = empObj.Id;
                        VDoc.VoucherId = voucher.Id;
                        _vDocSar.AddDocument(VDoc);
                    }
                }

                string documentName;
                string documentLocation;
                for (int i = 0; i < Request.Files.Count; i++)
                {
                    if ("documentLocation[]" == Request.Files.GetKey(i))
                    {
                        documentName = "Document_" + voucher.Id + "_" + i + Path.GetRandomFileName() + Path.GetExtension(Request.Files[i].FileName);
                        documentLocation = Server.MapPath("~/Uploads/" + accSet.Companies.TradingName.Replace(" ", "_") + "/VoucherDocuments/");
                        if (fileUpload(Request.Files[i], documentName, documentLocation))
                        {
                            VoucherDocument VDoc = new VoucherDocument();
                            VDoc.CreatedDate = DateTime.Now;
                            VDoc.DocumentType = "File";
                            VDoc.EmployeeId =  empObj.Id;
                            VDoc.VoucherId = voucher.Id;
                            VDoc.FileLocation = "Uploads/" + accSet.Companies.TradingName.Replace(" ", "_") + "/VoucherDocuments/"+ documentName;
                            _vDocSar.AddDocument(VDoc);
                        }
                    }

                }
            }

            else
            {
                TempData.Add("errMsg", "Failed To Add Voucher");
                return RedirectToAction("RepeatingJournal", "Voucher", new { area = "Accounts" });
                //return Content("Failed To Add Voucher!!!!");
            }

            TempData.Add("SucMasg", "Voucher Added Successfully");
            return RedirectToAction("ManualJournals");
        }