示例#1
0
        public JsonResult DiscardLotSerialNumbers(int id)
        {
            var rqmt = LotSerialRequirement.Find(id);
            var qry  = from x in LotSerialTracking.Queryable
                       where x.Source == rqmt.Source &&
                       x.Reference == rqmt.Reference &&
                       x.Warehouse.Id == rqmt.Warehouse.Id &&
                       x.Product == rqmt.Product
                       select x;

            using (var scope = new TransactionScope()) {
                var entity = new LotSerialTracking {
                    Source    = rqmt.Source,
                    Reference = rqmt.Reference,
                    Date      = DateTime.Now,
                    Warehouse = rqmt.Warehouse,
                    Product   = rqmt.Product,
                    Quantity  = rqmt.Quantity
                };

                foreach (var item in qry)
                {
                    item.Delete();
                }

                entity.Create();
                rqmt.DeleteAndFlush();
            }

            return(Json(new {
                id = id,
                result = true
            }, JsonRequestBehavior.AllowGet));
        }
示例#2
0
        public JsonResult RemoveLotSerialNumber(int id)
        {
            var item = LotSerialTracking.Find(id);

            using (var scope = new TransactionScope()) {
                item.DeleteAndFlush();
            }

            return(Json(new {
                id = id,
                result = true
            }));
        }
示例#3
0
        public ActionResult PhysicalCountAdjustmentConfirmed(int id)
        {
            var    entity = InventoryReceipt.Find(id);
            string sql    = @"SELECT s.product ProductId, s.lot_number LotNumber, s.expiration_date ExpirationDate, s.serial_number SerialNumber, SUM(s.quantity) Quantity
                            FROM lot_serial_tracking s
                            INNER JOIN inventory_receipt_detail d ON s.product = d.product
                            WHERE d.receipt = :id AND s.warehouse = :warehouse AND s.date < :date
                            GROUP BY s.product, s.lot_number, s.expiration_date, s.serial_number
                            HAVING SUM(s.quantity) <> 0";

            var items = (IList <dynamic>) ActiveRecordMediator <Product> .Execute(delegate(ISession session, object instance) {
                var query = session.CreateSQLQuery(sql);

                query.AddScalar("ProductId", NHibernateUtil.Int32);
                query.AddScalar("LotNumber", NHibernateUtil.String);
                query.AddScalar("ExpirationDate", NHibernateUtil.Date);
                query.AddScalar("SerialNumber", NHibernateUtil.String);
                query.AddScalar("Quantity", NHibernateUtil.Decimal);

                query.SetInt32("id", entity.Id);
                query.SetInt32("warehouse", entity.Warehouse.Id);
                query.SetDateTime("date", entity.ModificationTime);

                return(query.DynamicList());
            }, null);

            using (var scope = new TransactionScope()) {
                var dt = entity.ModificationTime.AddMilliseconds(-1);

                foreach (var x in items)
                {
                    var item = new LotSerialTracking {
                        Source         = TransactionType.InventoryAdjustment,
                        Reference      = entity.Id,
                        Date           = dt,
                        Warehouse      = entity.Warehouse,
                        Product        = Product.Find(x.ProductId),
                        Quantity       = -x.Quantity,
                        LotNumber      = x.LotNumber,
                        ExpirationDate = x.ExpirationDate,
                        SerialNumber   = x.SerialNumber
                    };

                    item.Create();
                }

                scope.Flush();
            }

            return(RedirectToAction("Receipts"));
        }
示例#4
0
        static void KardexRegister(TransactionType source, int reference, DateTime dt,
		                            Warehouse warehouse, Product product, decimal quantity)
        {
            var item = new LotSerialTracking {
                Source = source,
                Reference = reference,
                Date = DateTime.Now,
                Warehouse = warehouse,
                Product = product,
                Quantity = quantity
            };

            item.Create ();
        }
示例#5
0
        static void KardexRegister(TransactionType source, int reference, DateTime dt,
                                   Warehouse warehouse, Product product, decimal quantity)
        {
            var item = new LotSerialTracking {
                Source    = source,
                Reference = reference,
                Date      = DateTime.Now,
                Warehouse = warehouse,
                Product   = product,
                Quantity  = quantity
            };

            item.Create();
        }
示例#6
0
        public ActionResult ConfirmLotSerialNumbers(int id)
        {
            var entity = LotSerialRequirement.Find(id);
            var qry    = from x in LotSerialTracking.Queryable
                         where x.Source == entity.Source &&
                         x.Reference == entity.Reference &&
                         x.Warehouse.Id == entity.Warehouse.Id &&
                         x.Product.Id == entity.Product.Id
                         select x;
            decimal sum = qry.Count() > 0 ? qry.Sum(x => x.Quantity) : 0;

            if (entity.Quantity != sum)
            {
                Response.StatusCode = 400;
                return(Content(Resources.ValidationFailed));
            }

            using (var scope = new TransactionScope()) {
                if (entity.Source == TransactionType.InventoryTransfer)
                {
                    var transfer = InventoryTransfer.Find(entity.Reference);

                    foreach (var serial in qry)
                    {
                        var item = new LotSerialTracking {
                            Source         = serial.Source,
                            Reference      = serial.Reference,
                            Date           = serial.Date,
                            Warehouse      = transfer.To,
                            Product        = serial.Product,
                            Quantity       = -serial.Quantity,
                            LotNumber      = serial.LotNumber,
                            ExpirationDate = serial.ExpirationDate,
                            SerialNumber   = serial.SerialNumber
                        };

                        item.Create();
                    }
                }

                entity.DeleteAndFlush();
            }

            return(Json(new {
                id = id,
                result = true
            }));
        }
示例#7
0
        public JsonResult AddLotSerialNumber(int id, decimal qty, string lot, DateTime?expiration, string serial)
        {
            var rqmt = LotSerialRequirement.Find(id);
            var item = GetLastLotSerial(rqmt.Product.Id, lot, serial);

            if (item == null)
            {
                item = new LotSerialTracking {
                    LotNumber      = lot,
                    ExpirationDate = expiration,
                    SerialNumber   = string.IsNullOrWhiteSpace(serial) ? null : serial
                };
            }
            else
            {
                item = new LotSerialTracking {
                    LotNumber      = item.LotNumber,
                    ExpirationDate = item.ExpirationDate,
                    SerialNumber   = string.IsNullOrWhiteSpace(serial) ? null : item.SerialNumber
                };
            }

            item.Source    = rqmt.Source;
            item.Reference = rqmt.Reference;
            item.Date      = DateTime.Now;
            item.Warehouse = rqmt.Warehouse;
            item.Product   = rqmt.Product;
            item.Quantity  = (rqmt.Quantity > 0 ? qty : -qty);

            using (var scope = new TransactionScope()) {
                item.CreateAndFlush();
            }

            return(Json(new {
                id = item.Id,
                result = true
            }));
        }
示例#8
0
        public ActionResult GetLotSerialNumber(int id)
        {
            var item = LotSerialTracking.Find(id);

            return(PartialView("_LotSerialNumber", item));
        }
示例#9
0
        public ActionResult PhysicalCountAdjustmentConfirmed(int id)
        {
            var entity = InventoryReceipt.Find (id);
            string sql = @"SELECT s.product ProductId, s.lot_number LotNumber, s.expiration_date ExpirationDate, s.serial_number SerialNumber, SUM(s.quantity) Quantity
                            FROM lot_serial_tracking s
                            INNER JOIN inventory_receipt_detail d ON s.product = d.product
                            WHERE d.receipt = :id AND s.warehouse = :warehouse AND s.date < :date
                            GROUP BY s.product, s.lot_number, s.expiration_date, s.serial_number
                            HAVING SUM(s.quantity) <> 0";

            var items = (IList<dynamic>) ActiveRecordMediator<Product>.Execute (delegate (ISession session, object instance) {
                var query = session.CreateSQLQuery (sql);

                query.AddScalar ("ProductId", NHibernateUtil.Int32);
                query.AddScalar ("LotNumber", NHibernateUtil.String);
                query.AddScalar ("ExpirationDate", NHibernateUtil.Date);
                query.AddScalar ("SerialNumber", NHibernateUtil.String);
                query.AddScalar ("Quantity", NHibernateUtil.Decimal);

                query.SetInt32 ("id", entity.Id);
                query.SetInt32 ("warehouse", entity.Warehouse.Id);
                query.SetDateTime ("date", entity.ModificationTime);

                return query.DynamicList ();
            }, null);

            using (var scope = new TransactionScope ()) {
                var dt = entity.ModificationTime.AddMilliseconds (-1);

                foreach (var x in items) {
                    var item = new LotSerialTracking {
                        Source = TransactionType.InventoryAdjustment,
                        Reference = entity.Id,
                        Date = dt,
                        Warehouse = entity.Warehouse,
                        Product = Product.Find (x.ProductId),
                        Quantity = -x.Quantity,
                        LotNumber = x.LotNumber,
                        ExpirationDate = x.ExpirationDate,
                        SerialNumber = x.SerialNumber
                    };

                    item.Create ();
                }

                scope.Flush ();
            }

            return RedirectToAction ("Receipts");
        }
示例#10
0
        public JsonResult AddLotSerialNumber(int id, decimal qty, string lot, DateTime? expiration, string serial)
        {
            var rqmt = LotSerialRequirement.Find (id);
            var item = GetLastLotSerial (rqmt.Product.Id, lot, serial);

            if (item == null) {
                item = new LotSerialTracking {
                    LotNumber = lot,
                    ExpirationDate = expiration,
                    SerialNumber = string.IsNullOrWhiteSpace (serial) ? null : serial
                };
            } else {
                item = new LotSerialTracking {
                    LotNumber = item.LotNumber,
                    ExpirationDate = item.ExpirationDate,
                    SerialNumber = string.IsNullOrWhiteSpace (serial) ? null : item.SerialNumber
                };
            }

            item.Source = rqmt.Source;
            item.Reference = rqmt.Reference;
            item.Date = DateTime.Now;
            item.Warehouse = rqmt.Warehouse;
            item.Product = rqmt.Product;
            item.Quantity = (rqmt.Quantity > 0 ? qty : -qty);

            using (var scope = new TransactionScope ()) {
                item.CreateAndFlush ();
            }

            return Json (new {
                id = item.Id,
                result = true
            });
        }
示例#11
0
        public JsonResult DiscardLotSerialNumbers(int id)
        {
            var rqmt = LotSerialRequirement.Find (id);
            var qry = from x in LotSerialTracking.Queryable
                  where x.Source == rqmt.Source &&
                        x.Reference == rqmt.Reference &&
                        x.Warehouse.Id == rqmt.Warehouse.Id &&
                        x.Product == rqmt.Product
                  select x;

            using (var scope = new TransactionScope ()) {
                var entity = new LotSerialTracking {
                    Source = rqmt.Source,
                    Reference = rqmt.Reference,
                    Date = DateTime.Now,
                    Warehouse = rqmt.Warehouse,
                    Product = rqmt.Product,
                    Quantity = rqmt.Quantity
                };

                foreach (var item in qry) {
                    item.Delete ();
                }

                entity.Create ();
                rqmt.DeleteAndFlush ();
            }

            return Json (new {
                id = id,
                result = true
            }, JsonRequestBehavior.AllowGet);
        }
示例#12
0
        public ActionResult ConfirmLotSerialNumbers(int id)
        {
            var entity = LotSerialRequirement.Find (id);
            var qry = from x in LotSerialTracking.Queryable
                  where x.Source == entity.Source &&
                        x.Reference == entity.Reference &&
                        x.Warehouse.Id == entity.Warehouse.Id &&
                        x.Product.Id == entity.Product.Id
                  select x;
            decimal sum = qry.Count () > 0 ? qry.Sum (x => x.Quantity) : 0;

            if (entity.Quantity != sum) {
                Response.StatusCode = 400;
                return Content (Resources.ValidationFailed);
            }

            using (var scope = new TransactionScope ()) {
                if (entity.Source == TransactionType.InventoryTransfer) {
                    var transfer = InventoryTransfer.Find (entity.Reference);

                    foreach (var serial in qry) {
                        var item = new LotSerialTracking {
                            Source = serial.Source,
                            Reference = serial.Reference,
                            Date = serial.Date,
                            Warehouse = transfer.To,
                            Product = serial.Product,
                            Quantity = -serial.Quantity,
                            LotNumber = serial.LotNumber,
                            ExpirationDate = serial.ExpirationDate,
                            SerialNumber = serial.SerialNumber
                        };

                        item.Create ();
                    }
                }

                entity.DeleteAndFlush ();
            }

            return Json (new {
                id = id,
                result = true
            });
        }