예제 #1
0
        // GET: MaterialBuy/Edit/5
        public async Task <ActionResult> Edit(int?id)
        {
            if (Session["LoginUserID"] == null)
            {
                return(RedirectToAction("Login", "Account"));
            }

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            MaterialBuy materialBuy = await db.MaterialBuys.FindAsync(id);

            if (materialBuy == null)
            {
                return(HttpNotFound());
            }

//            ViewBag.CompanyID = new SelectList(db.Companys, "ID", "Name", materialBuy.CompanyID);
            if (Convert.ToInt32(Session["CurrentCulture"]) == 2)
            {
                ViewBag.ProjectID = new SelectList(db.Projects.OrderByDescending(p => p.Date), "ID", "NameKr", materialBuy.ProjectID);
            }
            else
            {
                ViewBag.ProjectID = new SelectList(db.Projects.OrderByDescending(p => p.Date), "ID", "NameVn", materialBuy.ProjectID);
            }
            return(View(materialBuy));
        }
예제 #2
0
        public async Task <ActionResult> EditEditUnit(int id, int unitid)
        {
            if (Session["LoginUserID"] == null)
            {
                return(RedirectToAction("Login", "Account"));
            }

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            MaterialBuy materialBuy = await db.MaterialBuys.FindAsync(id);

            if (materialBuy == null)
            {
                return(HttpNotFound());
            }
            MaterialBuyUnit materialBuyUnit = await db.MaterialBuyUnits.FindAsync(unitid);

            if (materialBuyUnit == null)
            {
                return(HttpNotFound());
            }
            var materialBuyData = new MaterialBuyData();

            materialBuyData.MaterialBuy     = materialBuy;
            materialBuyData.MaterialBuyUnit = materialBuyUnit;
            materialBuyData.MaterialBuy.MaterialBuyUnits = materialBuyData.MaterialBuy.MaterialBuyUnits.OrderBy(p => p.ID).ToList();


            return(View(materialBuyData));
        }
예제 #3
0
        public async Task <ActionResult> EditDetailsPayment(int?id, int paymentid)
        {
            if (Session["LoginUserID"] == null)
            {
                return(RedirectToAction("Login", "Account"));
            }

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            MaterialBuy materialBuy = await db.MaterialBuys.FindAsync(id);

            if (materialBuy == null)
            {
                return(HttpNotFound());
            }
            Payment payment = await db.Payments.FindAsync(paymentid);

            if (payment == null)
            {
                return(HttpNotFound());
            }
            var materialBuyPayment = new MaterialBuyPaymentData();

            materialBuyPayment.MaterialBuy = materialBuy;
            materialBuyPayment.Payment     = payment;

            materialBuyPayment.MaterialBuy.Payments = materialBuyPayment.MaterialBuy.Payments.OrderBy(p => p.Date).ToList();


            return(View(materialBuyPayment));
        }
예제 #4
0
        public async Task <ActionResult> EditAddPayment(MaterialBuyPaymentData materialBuyPaymentData)
        {
            if (Session["LoginUserID"] == null)
            {
                return(RedirectToAction("Login", "Account"));
            }

            if (ModelState.IsValid)
            {
                //                db.Entry(materialBuyData).State = EntityState.Modified;
                MaterialBuy materialBuy = db.MaterialBuys.FirstOrDefault(m => m.ID == materialBuyPaymentData.MaterialBuy.ID);

                materialBuyPaymentData.Payment.EmployeeID = Convert.ToInt32(Session["LoginUserEmployeeID"]);
                materialBuyPaymentData.Payment.Employee   = db.Employees.FirstOrDefault(e => e.ID == materialBuyPaymentData.Payment.EmployeeID);
                materialBuyPaymentData.Payment.CompanyID  = materialBuyPaymentData.MaterialBuy.CompanyID;
                materialBuyPaymentData.Payment.ProjectID  = materialBuyPaymentData.MaterialBuy.ProjectID;

                db.Payments.Add(materialBuyPaymentData.Payment);
                materialBuy.Payments.Add(materialBuyPaymentData.Payment);

                await db.SaveChangesAsync();

                return(RedirectToAction("EditAddPayment", new { id = materialBuyPaymentData.MaterialBuy.ID }));
            }
            return(View(materialBuyPaymentData));
        }
예제 #5
0
        public async Task <ActionResult> DeleteMakeReceipt(int id, int makereceiptid)
        {
            if (Session["LoginUserID"] == null)
            {
                return(RedirectToAction("Login", "Account"));
            }

            if (makereceiptid == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            MaterialBuy materialBuy = await db.MaterialBuys.FindAsync(makereceiptid);

            if (materialBuy == null)
            {
                return(HttpNotFound());
            }

            if (materialBuy.MaterialBuyUnits.Count > 0)
            {
                var mtu = db.MaterialBuyUnits.Where(m => m.MaterialBuyID == makereceiptid).ToArray();

                foreach (var item in mtu)
                {
                    //db.MaterialBuyUnits.Remove(item);
                    //await DeleteUnit(materialBuy.ID, item.ID);
                    PreDeleteUnit(materialBuy.ID, item.ID);
                }
            }

            if (materialBuy.Payments.Count > 0)
            {
                var mtp = db.Payments.Where(p => p.MaterialBuys.Count(m => m.ID == makereceiptid) > 0).ToArray();

                foreach (var item in mtp)
                {
                    if (item.MaterialBuys.Count() > 1)
                    {
                        foreach (var mb in item.MaterialBuys)
                        {
                            if (mb.ID == makereceiptid)
                            {
                                item.MaterialBuys.Remove(mb);
                            }
                        }
                    }
                    else
                    {
                        db.Payments.Remove(item);
                    }
                }
            }

            db.MaterialBuys.Remove(materialBuy);
            await db.SaveChangesAsync();

            return(RedirectToAction("Details", new { id = id }));
        }
예제 #6
0
        public async Task <ActionResult> EditAddUnit(MaterialBuyData materialBuyData)
        {
            if (Session["LoginUserID"] == null)
            {
                return(RedirectToAction("Login", "Account"));
            }

            if (ModelState.IsValid)
            {
                //                db.Entry(materialBuyData).State = EntityState.Modified;
                MaterialName mName = db.MaterialNames.FirstOrDefault(m => m.NameVn.Equals(materialBuyData.MaterialBuyUnit.MaterialUnitPrice.MaterialName.NameVn) ||
                                                                     m.NameVn.Equals(materialBuyData.MaterialBuyUnit.MaterialUnitPrice.MaterialName.NameKr));
                if (mName != null)
                {
                    materialBuyData.MaterialBuyUnit.MaterialUnitPrice.MaterialNameID = mName.ID;
                    materialBuyData.MaterialBuyUnit.MaterialUnitPrice.MaterialName   = mName;
                }
                else
                {
                    if (materialBuyData.MaterialBuyUnit.MaterialUnitPrice.MaterialName.NameKr == null)
                    {
                        materialBuyData.MaterialBuyUnit.MaterialUnitPrice.MaterialName.NameKr = materialBuyData.MaterialBuyUnit.MaterialUnitPrice.MaterialName.NameVn;
                    }

                    db.MaterialNames.Add(materialBuyData.MaterialBuyUnit.MaterialUnitPrice.MaterialName);
                }
                MaterialBuy materialBuy = db.MaterialBuys.FirstOrDefault(m => m.ID == materialBuyData.MaterialBuy.ID);
                materialBuyData.MaterialBuyUnit.MaterialUnitPrice.CompanyID = materialBuy.CompanyID;
                materialBuyData.MaterialBuyUnit.MaterialUnitPrice.Date      = materialBuy.Date;

                MaterialUnitPrice muPrice = db.MaterialUnitPrices.OrderBy(m => m.Date)
                                            .FirstOrDefault(m => m.MaterialName.NameVn.Equals(materialBuyData.MaterialBuyUnit.MaterialUnitPrice.MaterialName.NameVn));

                if (muPrice == null || muPrice.Price != materialBuyData.MaterialBuyUnit.MaterialUnitPrice.Price)
                {
                    db.MaterialUnitPrices.Add(materialBuyData.MaterialBuyUnit.MaterialUnitPrice);
                }
                else
                {
                    materialBuyData.MaterialBuyUnit.MaterialUnitPrice   = muPrice;
                    materialBuyData.MaterialBuyUnit.MaterialUnitPriceID = muPrice.ID;
                }

                db.MaterialBuyUnits.Add(materialBuyData.MaterialBuyUnit);
                materialBuy.MaterialBuyUnits.Add(materialBuyData.MaterialBuyUnit);

                await db.SaveChangesAsync();

                return(RedirectToAction("EditAddUnit", new { id = materialBuyData.MaterialBuy.ID }));
            }
            return(View(materialBuyData));
        }
예제 #7
0
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            if (Session["LoginUserID"] == null)
            {
                return(RedirectToAction("Login", "Account"));
            }

            MaterialBuy materialBuy = await db.MaterialBuys.FindAsync(id);

            if (materialBuy.MaterialBuyUnits.Count > 0)
            {
                var mtu = db.MaterialBuyUnits.Where(m => m.MaterialBuyID == id).ToArray();

                foreach (var item in mtu)
                {
                    //db.MaterialBuyUnits.Remove(item);
                    //await DeleteUnit(materialBuy.ID, item.ID);
                    PreDeleteUnit(materialBuy.ID, item.ID);
                }
            }

            if (materialBuy.Payments.Count > 0)
            {
                var mtp = db.Payments.Where(p => p.MaterialBuys.Count(m => m.ID == id) > 0).ToArray();

                foreach (var item in mtp)
                {
                    if (item.MaterialBuys.Count() > 1)
                    {
                        foreach (var mb in item.MaterialBuys)
                        {
                            if (mb.ID == id)
                            {
                                item.MaterialBuys.Remove(mb);
                            }
                        }
                    }
                    else
                    {
                        db.Payments.Remove(item);
                    }
                }
            }

            db.MaterialBuys.Remove(materialBuy);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
예제 #8
0
        public async Task <ActionResult> Create([Bind(Include = "ID,Company,ProjectID,Date,NoteVn,NoteKr,VAT,VATPer,EmployeeID,Translate")] MaterialBuy materialBuy)
        {
            if (Session["LoginUserID"] == null)
            {
                return(RedirectToAction("Login", "Account"));
            }

            if (Convert.ToInt32(Session["LoginUserSecurity"]) < Convert.ToInt32(Security.Personnel))
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (ModelState.IsValid)
            {
                int eID = Convert.ToInt32(Session["LoginUserEmployeeID"]);
                materialBuy.Employee   = db.Employees.FirstOrDefault(e => e.ID == eID);
                materialBuy.EmployeeID = eID;

                materialBuy.Company   = db.Companys.FirstOrDefault(c => c.Name.Equals(materialBuy.Company.Name));
                materialBuy.CompanyID = materialBuy.Company.ID;

                if ((materialBuy.NoteVn != null && materialBuy.NoteVn.Length > 0) ||
                    (materialBuy.NoteKr != null && materialBuy.NoteKr.Length > 0))
                {
                    materialBuy.Translate = false;
                }
                else
                {
                    materialBuy.Translate = true;
                }

                db.MaterialBuys.Add(materialBuy);
                await db.SaveChangesAsync();

                return(RedirectToAction("EditAddUnit", new { id = materialBuy.ID }));
            }

            //           ViewBag.CompanyID = new SelectList(db.Companys, "ID", "Name", materialBuy.CompanyID);
            if (Convert.ToInt32(Session["CurrentCulture"]) == 2)
            {
                ViewBag.ProjectID = new SelectList(db.Projects.OrderByDescending(p => p.Date), "ID", "NameKr", materialBuy.ProjectID);
            }
            else
            {
                ViewBag.ProjectID = new SelectList(db.Projects.OrderByDescending(p => p.Date), "ID", "NameVn", materialBuy.ProjectID);
            }
            return(View(materialBuy));
        }
예제 #9
0
        public async Task <ActionResult> AddAllDeposit(int id, int makereceiptid)
        {
            if (Session["LoginUserID"] == null)
            {
                return(RedirectToAction("Login", "Account"));
            }

            if (Convert.ToInt32(Session["LoginUserSecurity"]) < Convert.ToInt32(Security.Personnel))
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (id == null || makereceiptid == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            MaterialBuy makeReceipt = await db.MaterialBuys.FindAsync(makereceiptid);

            if (makeReceipt == null)
            {
                return(HttpNotFound());
            }

            var paymentsum = makeReceipt.Payments.Sum(p => p.Amount);
            var price      = makeReceipt.MaterialBuyUnits.Sum(m => m.Quantity * m.MaterialUnitPrice.Price);
            var amount     = price + price * makeReceipt.VATPer - paymentsum;

            if (amount > 0)
            {
                Payment payment = new Payment();
                payment.CompanyID     = makeReceipt.CompanyID;
                payment.Date          = DateTime.Now;
                payment.EmployeeID    = Convert.ToInt32(Session["LoginUserEmployeeID"]);
                payment.ProjectID     = makeReceipt.ProjectID;
                payment.StatementType = Models.StatementType.Deposit;
                payment.Type          = PaymentType.Bank;
                payment.Amount        = (double)amount;
                payment.Currency      = makeReceipt.MaterialBuyUnits.FirstOrDefault().MaterialUnitPrice.Currency;

                db.Payments.Add(payment);
                makeReceipt.Payments.Add(payment);

                await db.SaveChangesAsync();
            }

            return(RedirectToAction("Details", new { id = id }));
        }
예제 #10
0
        // GET: MaterialBuy/Delete/5
        public async Task <ActionResult> Delete(int?id)
        {
            if (Session["LoginUserID"] == null)
            {
                return(RedirectToAction("Login", "Account"));
            }

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            MaterialBuy materialBuy = await db.MaterialBuys.FindAsync(id);

            if (materialBuy == null)
            {
                return(HttpNotFound());
            }
            return(View(materialBuy));
        }
예제 #11
0
        public async Task <ActionResult> EditEditPayment(int id, int paymentid, MaterialBuyPaymentData materialBuyPaymentData)
        {
            if (Session["LoginUserID"] == null)
            {
                return(RedirectToAction("Login", "Account"));
            }

            if (ModelState.IsValid)
            {
                //                db.Entry(materialBuyData).State = EntityState.Modified;
                MaterialBuy materialBuy = db.MaterialBuys.FirstOrDefault(m => m.ID == materialBuyPaymentData.MaterialBuy.ID);
                Payment     payment     = await db.Payments.FindAsync(paymentid);

                payment.Date         = materialBuyPaymentData.Payment.Date;
                payment.Type         = materialBuyPaymentData.Payment.Type;
                payment.Amount       = materialBuyPaymentData.Payment.Amount;
                payment.Currency     = materialBuyPaymentData.Payment.Currency;
                payment.AmountString = materialBuyPaymentData.Payment.AmountString;
                payment.CompanyID    = materialBuyPaymentData.MaterialBuy.CompanyID;
                payment.ProjectID    = materialBuyPaymentData.MaterialBuy.ProjectID;

                if (payment.NoteVn != null && !payment.NoteVn.Equals(materialBuyPaymentData.Payment.NoteVn))
                {
                    payment.NoteVn    = materialBuyPaymentData.Payment.NoteVn;
                    payment.Translate = false;
                }
                if (materialBuyPaymentData.Payment.NoteVn != null)
                {
                    payment.NoteVn    = materialBuyPaymentData.Payment.NoteVn;
                    payment.Translate = false;
                }
                if (payment.NoteVn == null || payment.NoteVn.Length <= 0)
                {
                    payment.Translate = true;
                }

                await db.SaveChangesAsync();

                return(RedirectToAction("EditAddPayment", new { id = materialBuyPaymentData.MaterialBuy.ID }));
            }
            return(View(materialBuyPaymentData));
        }
예제 #12
0
        public async Task <ActionResult> Edit([Bind(Include = "ID,Company,ProjectID,Date,NoteVn,NoteKr,VAT,VATPer,Translate")] MaterialBuy materialBuy)
        {
            if (Session["LoginUserID"] == null)
            {
                return(RedirectToAction("Login", "Account"));
            }

            if (ModelState.IsValid)
            {
                MaterialBuy smb = await db.MaterialBuys.FindAsync(materialBuy.ID);

                smb.Company   = db.Companys.FirstOrDefault(c => c.Name.Equals(materialBuy.Company.Name));
                smb.CompanyID = smb.Company.ID;

                smb.Project   = db.Projects.FirstOrDefault(p => p.ID == materialBuy.ProjectID);
                smb.ProjectID = smb.Project.ID;
                smb.Date      = materialBuy.Date;
                smb.NoteVn    = materialBuy.NoteVn;
                smb.NoteKr    = materialBuy.NoteKr;
                smb.VATPer    = materialBuy.VATPer;
                smb.Translate = materialBuy.Translate;


                db.Entry(smb).State = EntityState.Modified;
                await db.SaveChangesAsync();

//                return RedirectToAction("Index");
                return(RedirectToAction("Index", new { translate = Session["Translate"] }));
            }
//            ViewBag.CompanyID = new SelectList(db.Companys, "ID", "Name", materialBuy.CompanyID);
            if (Convert.ToInt32(Session["CurrentCulture"]) == 2)
            {
                ViewBag.ProjectID = new SelectList(db.Projects.OrderByDescending(p => p.Date), "ID", "NameKr", materialBuy.ProjectID);
            }
            else
            {
                ViewBag.ProjectID = new SelectList(db.Projects.OrderByDescending(p => p.Date), "ID", "NameVn", materialBuy.ProjectID);
            }
            return(View(materialBuy));
        }
예제 #13
0
        public async Task <ActionResult> EditEditMakeReceipt(int?id, int makereceiptid)
        {
            if (Session["LoginUserID"] == null)
            {
                return(RedirectToAction("Login", "Account"));
            }

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Project project = await db.Projects.FindAsync(id);

            if (project == null)
            {
                return(HttpNotFound());
            }
            MaterialBuy makeReceipt = await db.MaterialBuys.FindAsync(makereceiptid);

            if (makeReceipt == null)
            {
                return(HttpNotFound());
            }
            var projectMakeReceiptData = new ProjectMakeReceiptData();

            projectMakeReceiptData.Porject  = project;
            projectMakeReceiptData.Date     = makeReceipt.Date;
            projectMakeReceiptData.NoteVn   = makeReceipt.NoteVn;
            projectMakeReceiptData.NameVn   = makeReceipt.MaterialBuyUnits.FirstOrDefault().MaterialUnitPrice.MaterialName.NameVn;
            projectMakeReceiptData.Price    = makeReceipt.MaterialBuyUnits.FirstOrDefault().MaterialUnitPrice.Price;
            projectMakeReceiptData.Currency = makeReceipt.MaterialBuyUnits.FirstOrDefault().MaterialUnitPrice.Currency;
            projectMakeReceiptData.VATPer   = makeReceipt.VATPer;

            ViewBag.MakeReceiptID = makereceiptid;

            projectMakeReceiptData.Porject.MaterialBuys = projectMakeReceiptData.Porject.MaterialBuys.OrderByDescending(p => p.Date).ToList();

            return(View(projectMakeReceiptData));
        }
예제 #14
0
        public async Task <ActionResult> EditAddPayment(int?id)
        {
            if (Session["LoginUserID"] == null)
            {
                return(RedirectToAction("Login", "Account"));
            }

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            MaterialBuy materialBuy = await db.MaterialBuys.FindAsync(id);

            if (materialBuy == null)
            {
                return(HttpNotFound());
            }
            var materialBuyPayment = new MaterialBuyPaymentData();

            materialBuyPayment.MaterialBuy = materialBuy;

            return(View(materialBuyPayment));
        }
예제 #15
0
        // GET: MaterialBuy/Details/5
        public async Task <ActionResult> Details(int?id)
        {
            if (Session["LoginUserID"] == null)
            {
                return(RedirectToAction("Login", "Account"));
            }

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            MaterialBuy materialBuy = await db.MaterialBuys.FindAsync(id);

            if (materialBuy == null)
            {
                return(HttpNotFound());
            }
            int      eID      = Convert.ToInt32(Session["LoginUserEmployeeID"]);
            Employee employee = db.Employees.FirstOrDefault(e => e.ID == eID);

            ViewBag.eName       = employee.Name;
            ViewBag.eDepartment = employee.DepartmentVn;
            return(View(materialBuy));
        }
예제 #16
0
        public async Task <ActionResult> EditEditUnit(int id, int unitid, MaterialBuyData materialBuyData)
        {
            if (Session["LoginUserID"] == null)
            {
                return(RedirectToAction("Login", "Account"));
            }

            if (ModelState.IsValid)
            {
                //                db.Entry(materialBuyData).State = EntityState.Modified;
                MaterialBuyUnit sUnit = db.MaterialBuyUnits.FirstOrDefault(mbu => mbu.ID == unitid);
                MaterialName    sName = db.MaterialNames.FirstOrDefault(m => m.NameVn.Equals(sUnit.MaterialUnitPrice.MaterialName.NameVn));

                int nameCount  = db.MaterialUnitPrices.Where(m => m.MaterialName.NameVn.Equals(sUnit.MaterialUnitPrice.MaterialName.NameVn)).Count();
                int sunitCount = db.MaterialBuyUnits.Where(u => u.MaterialUnitPriceID == sUnit.MaterialUnitPriceID).Count();

                if (materialBuyData.MaterialBuyUnit.MaterialUnitPrice.Price != sUnit.MaterialUnitPrice.Price ||
                    materialBuyData.MaterialBuyUnit.MaterialUnitPrice.Currency != sUnit.MaterialUnitPrice.Currency ||
                    !materialBuyData.MaterialBuyUnit.MaterialUnitPrice.UnitString.Equals(sUnit.MaterialUnitPrice.UnitString))
                {
                    if (sunitCount == 1)
                    {
                        sUnit.MaterialUnitPrice.UnitString = materialBuyData.MaterialBuyUnit.MaterialUnitPrice.UnitString;
                        sUnit.MaterialUnitPrice.Price      = materialBuyData.MaterialBuyUnit.MaterialUnitPrice.Price;
                        sUnit.MaterialUnitPrice.Currency   = materialBuyData.MaterialBuyUnit.MaterialUnitPrice.Currency;
                        sUnit.MaterialUnitPrice.Date       = DateTime.Today;
                    }
                    else
                    {
                        MaterialUnitPrice muPrice = new MaterialUnitPrice();
                        muPrice.MaterialName   = sUnit.MaterialUnitPrice.MaterialName;
                        muPrice.MaterialNameID = sUnit.MaterialUnitPrice.MaterialNameID;
                        muPrice.Company        = sUnit.MaterialUnitPrice.Company;
                        muPrice.CompanyID      = sUnit.MaterialUnitPrice.CompanyID;
                        muPrice.UnitString     = materialBuyData.MaterialBuyUnit.MaterialUnitPrice.UnitString;
                        muPrice.Price          = materialBuyData.MaterialBuyUnit.MaterialUnitPrice.Price;
                        muPrice.Currency       = materialBuyData.MaterialBuyUnit.MaterialUnitPrice.Currency;
                        muPrice.Date           = DateTime.Today;

                        db.MaterialUnitPrices.Add(muPrice);
                        sUnit.MaterialUnitPrice = muPrice;
                    }
                }

                MaterialName newName = db.MaterialNames.FirstOrDefault(m => m.NameVn.Equals(materialBuyData.MaterialBuyUnit.MaterialUnitPrice.MaterialName.NameVn));

                if (!materialBuyData.MaterialBuyUnit.MaterialUnitPrice.MaterialName.NameVn.Equals(sName.NameVn))
                {
                    if (nameCount == 1)
                    {
                        if (newName == null)
                        {
                            newName = new MaterialName();
                            sUnit.MaterialUnitPrice.MaterialName.NameVn = materialBuyData.MaterialBuyUnit.MaterialUnitPrice.MaterialName.NameVn;
                            sUnit.MaterialUnitPrice.MaterialName.NameKr = materialBuyData.MaterialBuyUnit.MaterialUnitPrice.MaterialName.NameVn;
                            materialBuyData.MaterialBuyUnit.MaterialUnitPrice.MaterialName.Translate = false;
                        }
                        else
                        {
                            db.MaterialNames.Remove(sUnit.MaterialUnitPrice.MaterialName);
                            sUnit.MaterialUnitPrice.MaterialName = newName;
                        }
                    }
                    else
                    {
                        if (newName == null)
                        {
                            if (materialBuyData.MaterialBuyUnit.MaterialUnitPrice.MaterialName.NameKr == null)
                            {
                                materialBuyData.MaterialBuyUnit.MaterialUnitPrice.MaterialName.NameKr = materialBuyData.MaterialBuyUnit.MaterialUnitPrice.MaterialName.NameVn;
                            }
                            else if (materialBuyData.MaterialBuyUnit.MaterialUnitPrice.MaterialName.NameVn == null)
                            {
                                materialBuyData.MaterialBuyUnit.MaterialUnitPrice.MaterialName.NameVn = materialBuyData.MaterialBuyUnit.MaterialUnitPrice.MaterialName.NameKr;
                            }

                            sUnit.MaterialUnitPrice.MaterialName = materialBuyData.MaterialBuyUnit.MaterialUnitPrice.MaterialName;
                            db.MaterialNames.Add(materialBuyData.MaterialBuyUnit.MaterialUnitPrice.MaterialName);
                        }
                        else
                        {
                            sUnit.MaterialUnitPrice.MaterialName = newName;
                        }
                    }
                }

                MaterialBuy materialBuy = db.MaterialBuys.FirstOrDefault(m => m.ID == materialBuyData.MaterialBuy.ID);
                sUnit.Quantity = materialBuyData.MaterialBuyUnit.Quantity;

                await db.SaveChangesAsync();

                return(RedirectToAction("EditAddUnit", new { id = id }));
            }
            return(View(materialBuyData));
        }
예제 #17
0
        public async Task <ActionResult> EditEditMakeReceipt(int id, int makereceiptid, ProjectMakeReceiptData projectMakeReceiptData)
        {
            if (Session["LoginUserID"] == null)
            {
                return(RedirectToAction("Login", "Account"));
            }

            if (ModelState.IsValid)
            {
                //                db.Entry(materialBuyData).State = EntityState.Modified;
                Project     project     = db.Projects.FirstOrDefault(m => m.ID == projectMakeReceiptData.Porject.ID);
                MaterialBuy makeReceipt = await db.MaterialBuys.FindAsync(makereceiptid);


                if (makeReceipt.Date != projectMakeReceiptData.Date)
                {
                    makeReceipt.Date = projectMakeReceiptData.Date;
                    makeReceipt.MaterialBuyUnits.FirstOrDefault().MaterialUnitPrice.Date = projectMakeReceiptData.Date;
                }

                if (makeReceipt.VATPer != projectMakeReceiptData.VATPer)
                {
                    makeReceipt.VATPer = projectMakeReceiptData.VATPer;
                }

                if ((makeReceipt.NoteVn != null && !makeReceipt.NoteVn.Equals(projectMakeReceiptData.NoteVn)) ||
                    (makeReceipt.NoteVn == null && projectMakeReceiptData.NoteVn != null))
                {
                    makeReceipt.NoteVn    = projectMakeReceiptData.NoteVn;
                    makeReceipt.NoteKr    = projectMakeReceiptData.NoteVn;
                    makeReceipt.Translate = false;
                }

                if (makeReceipt.MaterialBuyUnits.FirstOrDefault().MaterialUnitPrice.Price != projectMakeReceiptData.Price ||
                    makeReceipt.MaterialBuyUnits.FirstOrDefault().MaterialUnitPrice.Currency != projectMakeReceiptData.Currency)
                {
                    makeReceipt.MaterialBuyUnits.FirstOrDefault().MaterialUnitPrice.Price = projectMakeReceiptData.Price;
                    makeReceipt.MaterialBuyUnits.FirstOrDefault().MaterialUnitPrice.Currency = projectMakeReceiptData.Currency;
                }

                if ((projectMakeReceiptData.NameVn != null && !projectMakeReceiptData.NameVn.Equals(makeReceipt.MaterialBuyUnits.FirstOrDefault().MaterialUnitPrice.MaterialName.NameVn)) ||
                    (projectMakeReceiptData.NameVn == null && makeReceipt.MaterialBuyUnits.FirstOrDefault().MaterialUnitPrice.MaterialName.NameVn != null))
                {
                    int          nameCount = db.MaterialUnitPrices.Where(m => m.MaterialName.NameVn.Equals(makeReceipt.MaterialBuyUnits.FirstOrDefault().MaterialUnitPrice.MaterialName.NameVn)).Count();
                    MaterialName oldName   = db.MaterialNames.FirstOrDefault(m => m.NameVn.Equals(makeReceipt.MaterialBuyUnits.FirstOrDefault().MaterialUnitPrice.MaterialName.NameVn) ||
                                                                             m.NameKr.Equals(makeReceipt.MaterialBuyUnits.FirstOrDefault().MaterialUnitPrice.MaterialName.NameVn));
                    MaterialName mName = db.MaterialNames.FirstOrDefault(m => m.NameVn.Equals(projectMakeReceiptData.NameVn) ||
                                                                         m.NameKr.Equals(projectMakeReceiptData.NameVn));
                    if (mName == null)
                    {
                        mName        = new MaterialName();
                        mName.NameKr = projectMakeReceiptData.NameVn;
                        mName.NameVn = projectMakeReceiptData.NameVn;
                        makeReceipt.MaterialBuyUnits.FirstOrDefault().MaterialUnitPrice.MaterialName = mName;
                        db.MaterialNames.Add(mName);
                    }
                    else
                    {
                        makeReceipt.MaterialBuyUnits.FirstOrDefault().MaterialUnitPrice.MaterialName = mName;
                    }

                    if (nameCount == 1)
                    {
                        db.MaterialNames.Remove(oldName);
                    }
                }

                await db.SaveChangesAsync();

                return(RedirectToAction("EditAddMakeReceipt", new { id = projectMakeReceiptData.Porject.ID }));
            }
            return(View(projectMakeReceiptData));
        }
예제 #18
0
        public async Task <ActionResult> EditAddMakeReceipt(ProjectMakeReceiptData projectMakeReceiptData)
        {
            if (Session["LoginUserID"] == null)
            {
                return(RedirectToAction("Login", "Account"));
            }

            if (ModelState.IsValid)
            {
                //                db.Entry(materialBuyData).State = EntityState.Modified;
                Project project = db.Projects.FirstOrDefault(m => m.ID == projectMakeReceiptData.Porject.ID);

                MaterialBuy receipt = new MaterialBuy();
                receipt.Company         = project.Company;
                receipt.CompanyID       = project.CompanyID;
                receipt.Date            = projectMakeReceiptData.Date;
                receipt.EmployeeID      = Convert.ToInt32(Session["LoginUserEmployeeID"]);
                receipt.Employee        = db.Employees.FirstOrDefault(e => e.ID == receipt.EmployeeID);
                receipt.MaterialBuyType = MaterialBuyType.MakeReceipt;
                receipt.NoteVn          = projectMakeReceiptData.NoteVn;
                receipt.NoteKr          = projectMakeReceiptData.NoteVn;
                receipt.Project         = project;
                receipt.ProjectID       = project.ID;
                receipt.VATPer          = projectMakeReceiptData.VATPer;

                MaterialBuyUnit unit = new MaterialBuyUnit();
                unit.MaterialBuy = receipt;
                unit.Quantity    = 1;


                MaterialName mName = db.MaterialNames.FirstOrDefault(m => m.NameVn.Equals(projectMakeReceiptData.NameVn) ||
                                                                     m.NameKr.Equals(projectMakeReceiptData.NameVn));
                if (mName == null)
                {
                    mName        = new MaterialName();
                    mName.NameKr = projectMakeReceiptData.NameVn;
                    mName.NameVn = projectMakeReceiptData.NameVn;
                    db.MaterialNames.Add(mName);
                }

                MaterialUnitPrice muPrice = db.MaterialUnitPrices.OrderBy(m => m.Date)
                                            .FirstOrDefault(mp => mp.MaterialName.NameVn.Equals(projectMakeReceiptData.NameVn) ||
                                                            mp.MaterialName.NameKr.Equals(projectMakeReceiptData.NameVn));

                if (muPrice == null || muPrice.Price != projectMakeReceiptData.Price)
                {
                    muPrice            = new MaterialUnitPrice();
                    muPrice.Company    = project.Company;
                    muPrice.CompanyID  = project.CompanyID;
                    muPrice.Date       = projectMakeReceiptData.Date;
                    muPrice.UnitString = "Set";
                    muPrice.Price      = projectMakeReceiptData.Price;
                    muPrice.Currency   = projectMakeReceiptData.Currency;

                    db.MaterialUnitPrices.Add(muPrice);
                }

                muPrice.MaterialName     = mName;
                unit.MaterialUnitPrice   = muPrice;
                receipt.MaterialBuyUnits = new List <MaterialBuyUnit>();
                receipt.MaterialBuyUnits.Add(unit);

                db.MaterialBuys.Add(receipt);
                db.MaterialBuyUnits.Add(unit);
                project.MaterialBuys.Add(receipt);

//                db.Payments.Add(projectDepositData.Deposit);
//                project.Deposits.Add(projectDepositData.Deposit);

                await db.SaveChangesAsync();

                return(RedirectToAction("EditAddMakeReceipt", new { id = projectMakeReceiptData.Porject.ID }));
            }
            return(View(projectMakeReceiptData));
        }
예제 #19
0
        public override async Task Handle(FlowSheet flowSheet)
        {
            await base.Handle(flowSheet);

            //数据处理
            var formObj     = Newtonsoft.Json.JsonConvert.DeserializeObject <JObject>(flowSheet.FlowInstance.FormData);
            var sheetData   = formObj["sheetData"];
            var sheetHeader = sheetData["header"];

            flowSheet.SheetDate = sheetHeader["sheetDate"].ToObjectWithDefault <DateTime>();
            flowSheet.Remarks   = sheetHeader["remarks"].ToObjectWithDefault <string>();
            var storeId  = sheetHeader["storeId"].ToObject <int>(); //调出仓库id;
            var unitId   = sheetHeader["unitId"].ToObject <int>();  //供货商id
            var totalFee = sheetHeader["totalFee"].ToObjectWithDefault <decimal>();

            flowSheet.UnitId = unitId;
            flowSheet.SetPropertyValue("StoreName", sheetHeader["storeName"].ToObjectWithDefault <string>());
            flowSheet.SetPropertyValue("Fee", totalFee);
            //是否从实物订货过来
            var fromSDR = sheetHeader["fromSDR"].ToObjectWithDefault <string>();

            if (!fromSDR.IsNullOrEmpty())
            {
                var SDRSheet = await FlowSheetManager.GetAll().Where(o => o.SheetSN == fromSDR).FirstOrDefaultAsync();

                if (SDRSheet != null)
                {
                    //SDRSheet.SetPropertyValue("PRHSheetSN", flowSheet.SheetSN);
                    SDRSheet.SetPropertyValue("PRHSheetId", flowSheet.Id);
                    await FlowSheetManager.UpdateAsync(SDRSheet);
                }
            }

            //更改往来单位金额
            await UnitManager.ChangeFee(unitId, null, totalFee, flowSheet);

            foreach (var sheetItem in sheetData["body"])
            {
                var materialId = Convert.ToInt32(sheetItem["id"]);            //对应的物料Id

                var number = sheetItem["number"].ToObjectWithDefault <int>(); //入库数量
                //记录采购
                var materialBuy = new MaterialBuy()
                {
                    UnitId           = unitId,
                    MaterialId       = materialId,
                    FlowSheetId      = flowSheet.Id,
                    BuyNumber        = number,
                    Price            = sheetItem["price"].ToObjectWithDefault <decimal>(),
                    Discount         = sheetItem["discount"].ToObjectWithDefault <decimal>(),
                    FeatureCode      = sheetItem["featureCode"].ToObjectWithDefault <string>(),
                    MaterialBuyCodes = new List <MaterialBuyCode>()
                                       //CodeStartNumber= sheetItem["codeStartNumber"].ToObjectWithDefault<string>(),
                                       //CodeEndNumber = sheetItem["codeEndNumber"].ToObjectWithDefault<string>(),
                };
                //code记录
                var codeNumber = sheetItem["codeNumber"].ToObjectWithDefault <string>();
                if (!string.IsNullOrWhiteSpace(codeNumber))
                {
                    var codeArr = codeNumber.Split(new char[] { ';', ';' });
                    codeArr.ToList().ForEach(o =>
                    {
                        var startNumber = 0M;
                        var endNumber   = 0M;
                        if (o.IndexOf('~') < 0)
                        {
                            startNumber = decimal.Parse(o);
                            endNumber   = decimal.Parse(o);
                        }
                        else
                        {
                            startNumber = decimal.Parse(o.Split('~')[0]);
                            endNumber   = decimal.Parse(o.Split('~')[1]);
                        }
                        materialBuy.MaterialBuyCodes.Add(new MaterialBuyCode()
                        {
                            CodeStartNumber = startNumber,
                            CodeEndNumber   = endNumber
                        });
                    });
                }
                await MaterialBuyManager.InsertAsync(materialBuy);

                //库存变化
                await StoreMaterialManager.CountMaterial(storeId, materialId, number, flowSheet);
            }
        }