public void Save(ExcessPartsSetDTO epsDTO)
        {
            ExcessPartsSet eps = new ExcessPartsSet();
            eps.No = epsRepo.GenerateEpsNo();
            eps.Date = DateTime.Now;

            eps.PreparedBy = Common.GetCurrentUser.Id;
            eps.ApprovedBy = Common.GetCurrentUser.GeneralManagerId;
            eps.CheckedBy = epsDTO.CheckedBy;

            context.ExcessPartsSets.Add(eps);
            context.SaveChanges();

            foreach (ExcessPartsSetDTO.Item dtoItem in epsDTO.Items)
            {
                ExcessPartsSetItem epsItem = new ExcessPartsSetItem();

                epsItem.ExcessPartsSetId = eps.Id;
                epsItem.ItemId = dtoItem.ItemId;
                epsItem.UnitCost = dtoItem.UnitCost;
                epsItem.Quantity = dtoItem.Quantity;
                epsItem.Remarks = dtoItem.Remarks;

                context.ExcessPartsSetItems.Add(epsItem);
                context.SaveChanges();

                InsertLogs(epsItem.ItemId, epsItem.Quantity);
            }
        }
예제 #2
0
        public void Save(RequisitionPurchaseDTO rpDTO)
        {
            PurchaseOrder rp = new PurchaseOrder();
            int           id;

            rp.No         = rpRepo.GenerateRpNo(rpDTO.Date);
            rp.Date       = rpDTO.Date;
            rp.CompanyId  = Sessions.CompanyId.Value;
            rp.VendorId   = rpDTO.VendorId;
            rp.ShipTo     = Sessions.CompanyId.Value;
            rp.PreparedBy = Common.GetCurrentUser.Id;
            rp.ApprovedBy = Common.GetCurrentUser.GeneralManagerId;
            rp.CheckedBy  = rpDTO.CheckedBy;
            rp.isRP       = true;

            context.PurchaseOrders.Add(rp);
            context.SaveChanges();

            id = rp.Id;

            rp.ItemPriceLogs = new List <ItemPriceLogs>();
            foreach (RequisitionPurchaseDTO.Item item in rpDTO.Items)
            {
                ItemPriceLogs itemLogs = new ItemPriceLogs();

                itemLogs.PurchaseOrderId = rp.Id;
                itemLogs.ItemId          = item.ItemId;
                itemLogs.UnitCost        = Convert.ToDecimal(item.UnitCost);
                itemLogs.Qty             = item.Quantity;
                itemLogs.Date            = DateTime.Now;

                rp.ItemPriceLogs.Add(itemLogs);
            }

            foreach (RequisitionPurchaseDTO.Item dtoItem in rpDTO.Items)
            {
                PurchaseOrderItem rpItem = new PurchaseOrderItem();

                rpItem.PurchaseOrderId = rp.Id;
                rpItem.ItemId          = dtoItem.ItemId;
                rpItem.UnitCost        = dtoItem.UnitCost;
                rpItem.Quantity        = dtoItem.Quantity;
                rpItem.Remarks         = dtoItem.Remarks;
                rpItem.Date            = DateTime.Now;

                context.PurchaseOrderItems.Add(rpItem);

                context.SaveChanges();

                InsertStockCard(rp.Id, dtoItem.ItemId, dtoItem.UnitCost, dtoItem.Quantity);
            }
        }
        public void ReceivingLogsSave(ReceivingLogsDTO receivingLogsDTO)
        {
            PurchaseOrderItem poItem = poItemRepo.Find(receivingLogsDTO.PurchaseOrderItemId);
            PurchaseOrder     po     = context.PurchaseOrders.Find(poItem.PurchaseOrderId);

            po.Status = (int)EPurchaseOrderStatus.Saved;

            bool poExist = context.PurchaseOrders.Count(p => p.RRNo == receivingLogsDTO.RRNo) > 0;

            if (!poExist)
            {
                try
                {
                    po.RRNo         = poRepo.GenerateReNumber(receivingLogsDTO.DateReceived);
                    po.ReceivedDate = receivingLogsDTO.DateReceived;
                }
                catch
                {
                    po.RRNo         = poRepo.GenerateReNumber(DateTime.Now);
                    po.ReceivedDate = DateTime.Now;
                }
            }
            else
            {
                po.RRNo         = receivingLogsDTO.RRNo;
                po.ReceivedDate = receivingLogsDTO.DateReceived;
            }
            context.SaveChanges();

            PurchaseOrderItem pItem = poItemRepo.Find(receivingLogsDTO.PurchaseOrderItemId);

            foreach (ReceivingLogsDTO.Item item in receivingLogsDTO.Items)
            {
                Receiving receiving = new Receiving();

                int poitem = poItem.ItemId;

                if (item.Id != 0)
                {
                    receiving.Id = item.Id;
                    receiving.TransactionLogId = item.TransLogId;
                }
                else
                {
                    receiving.TransactionLogId = InsertLogs(poItem.ItemId, item.Quantity, item.DateReceived, itemRepo.GetItemType(poItem.ItemId));
                }

                receiving.PurchaseOrderItemId = receivingLogsDTO.PurchaseOrderItemId;
                receiving.Quantity            = item.Quantity;
                receiving.SerialNo            = item.SerialNo;
                receiving.DrNo         = receivingLogsDTO.DrNo;
                receiving.DateReceived = item.DateReceived;

                receivingRepo.Save(receiving, pItem.ItemId, pItem.Item.UnitCost.ToString("N"));
            }
        }
        public void Save(Receiving receiving, int itemid, string unitcost)
        {
            if (receiving.Id == 0)
            {
                if (receiving.SerialNo == null)
                {
                    receiving.SerialNo = "N/A";
                }

                context.Receivings.Add(receiving);

                context.SaveChanges();
                int id;
                id = receiving.Id;

                InsertStockCard(id, itemid, Convert.ToDecimal(unitcost), receiving.Quantity, receiving.TransactionLogId);
            }
            else
            {
                Receiving dbEntry = context.Receivings.Find(receiving.Id);
                if (dbEntry != null)
                {
                    dbEntry.PurchaseOrderItemId = receiving.PurchaseOrderItemId;
                    dbEntry.Quantity            = receiving.Quantity;
                    dbEntry.SerialNo            = receiving.SerialNo;
                    dbEntry.DrNo             = receiving.DrNo;
                    dbEntry.DateReceived     = receiving.DateReceived;
                    dbEntry.TransactionLogId = receiving.TransactionLogId;

                    context.SaveChanges();

                    TransactionLogRepository transLogRepo = new TransactionLogRepository();
                    transLogRepo.Update(dbEntry.TransactionLogId.Value, receiving.Quantity, receiving.DateReceived.Value);
                    UpdateStockCard(receiving.Id, itemid, Convert.ToDecimal(unitcost), receiving.Quantity, receiving.TransactionLogId);
                }
            }

            context.SaveChanges();
        }
예제 #5
0
        static void Main(string[] args)
        {
            ItemRepository           itemRepo            = new ItemRepository();
            TransactionLogRepository transLogRepo        = new TransactionLogRepository();
            ItemAssignmentRepository itemAssignementRepo = new ItemAssignmentRepository();
            CNGDBContext             context             = new CNGDBContext();

            List <ItemDTO> lstItemDTO = new List <ItemDTO>();

            const Int32 BufferSize = 128;

            using (var fileStream = File.OpenRead(@"C:\fmt_inventory.csv"))
                using (var streamReader = new StreamReader(fileStream, Encoding.UTF8, true, BufferSize))
                {
                    String line;
                    int    lineCnt = 1;
                    while ((line = streamReader.ReadLine()) != null)
                    {
                        //if (lineCnt > 3)
                        //{
                        string[] strLine = line.Split(',');

                        //string itemCode = Convert.ToString(strLine[0]);
                        string itemDesc = Convert.ToString(strLine[0]);

                        //int n;
                        //bool isNumeric = int.TryParse(itemCode, out n);


                        Item item = new Item();
                        //item.Code = itemCode.PadLeft(3, '0');
                        item.Description      = Convert.ToString(strLine[0]);
                        item.TypeId           = 2;
                        item.ClassificationId = 1;
                        item.Brand            = "n/a";
                        item.UnitCost         = Convert.ToDecimal(strLine[2]);
                        item.Active           = true;

                        ItemDTO itemDTO = new ItemDTO();

                        itemDTO.item      = item;
                        itemDTO.Quantity  = Convert.ToInt32(strLine[1]);
                        itemDTO.CompanyId = 4;
                        itemDTO.UnitCost  = item.UnitCost;

                        lstItemDTO.Add(itemDTO);
                    }


                    lineCnt++;
                    //}
                }

            //foreach (ItemDTO _itemDTO in lstItemDTO)
            //{
            //   int itemid =  itemRepo.SaveByEncoder(_itemDTO.item);
            //    TransactionLog transLog = new TransactionLog
            //    {
            //        ItemId = itemid,
            //        CompanyId = _itemDTO.CompanyId,//cng
            //        TransactionMethodId = 7, //in
            //        Date = Convert.ToDateTime("01/01/17"),
            //        Quantity = _itemDTO.Quantity,
            //        UserId = 1 //admin
            //    };
            //    transLogRepo.Add(transLog);


            //    Console.WriteLine("Added " + _itemDTO.item.Code + " - " + _itemDTO.item.Description);
            //}



            List <ItemAssignment> lstItemAssignment = new List <ItemAssignment>();

            foreach (ItemDTO item in lstItemDTO)
            {
                int x = 0;

                if (item.item.Id == 0)
                {
                    x = itemRepo.GetItemId(item.item.Description);
                }
                else
                {
                    x = item.item.Id;
                }

                ItemAssignment itemAssignment = context.ItemAssignments.FirstOrDefault(p => p.ItemId == x && p.CompanyId == 4);

                itemAssignment.UnitCost = item.UnitCost;


                context.SaveChanges();

                //ItemAssignment itemAssignment = new ItemAssignment
                //{
                //    ItemId = x,
                //    CompanyId = item.CompanyId,
                //    UnitCost  = item.UnitCost//cng
                //};
                //lstItemAssignment.Add(itemAssignment);
            }

            //itemAssignementRepo.Save(lstItemAssignment);

            Console.WriteLine("Done!");

            Console.ReadLine();
        }
예제 #6
0
        public void Save(PurchaseOrderDTO entry)
        {
            PurchaseOrder po = new PurchaseOrder();

            //po.No = poRepo.GeneratePoNumber();
            po.No = entry.No;

            po.Date     = Convert.ToDateTime(entry.Date);
            po.VendorId = entry.VendorId;
            po.ShipTo   = entry.ShipTo;
            po.Terms    = vendorRepo.GetById(entry.VendorId).Terms;

            po.PreparedBy = Common.GetCurrentUser.Id;
            po.ApprovedBy = Common.GetCurrentUser.GeneralManagerId;
            po.CheckedBy  = entry.CheckedBy;
            po.isRP       = false;
            po.CompanyId  = Sessions.CompanyId.Value;

            po.PurchaseOrderItems = new List <PurchaseOrderItem>();
            foreach (PurchaseOrderDTO.Item item in entry.Items)
            {
                PurchaseOrderItem poItem = new PurchaseOrderItem();
                poItem.PurchaseOrderId = po.Id;
                poItem.ItemId          = item.Id;
                Item _item = itemRepo.GetById(item.Id);

                poItem.UnitCost             = Convert.ToDecimal(item.UnitCost);
                poItem.Quantity             = item.Quantity;
                poItem.Remarks              = item.Remarks;
                poItem.Date                 = Convert.ToDateTime(entry.Date);
                poItem.RemainingBalanceDate = null;

                po.PurchaseOrderItems.Add(poItem);
            }

            // for FIFO price
            po.ItemPriceLogs = new List <ItemPriceLogs>();
            foreach (PurchaseOrderDTO.Item item in entry.Items)
            {
                ItemPriceLogs itemLogs = new ItemPriceLogs();
                Item          _item    = itemRepo.GetById(item.Id);

                itemLogs.PurchaseOrderId = po.Id;
                itemLogs.ItemId          = item.Id;
                itemLogs.UnitCost        = Convert.ToDecimal(item.UnitCost);
                itemLogs.Qty             = item.Quantity;
                itemLogs.Date            = DateTime.Now;
                itemLogs.CompanyId       = Sessions.CompanyId.Value;

                po.ItemPriceLogs.Add(itemLogs);
                UpdateItemType(item.Id, _item.TypeId, item.TypeId);
            }


            poRepo.Save(po);

            foreach (PurchaseOrderDTO.Item item in entry.Items)
            {
                Item _item = context.Items.Find(item.Id);
                if (_item.TypeId != item.TypeId)
                {
                    _item.TypeId = item.TypeId;
                    context.SaveChanges();
                }
            }
        }