Example #1
0
 public override bool DeleteData(int id, out Library.DTO.Notification notification)
 {
     notification = new Library.DTO.Notification {
         Type = Library.DTO.NotificationType.Success
     };
     try
     {
         using (WarehouseTransferMngEntities context = CreateContext())
         {
             var dbItem = context.WarehouseTransfer.Where(o => o.WarehouseTransferID == id).FirstOrDefault();
             context.WarehouseTransfer.Remove(dbItem);
             context.SaveChanges();
         }
         return(true);
     }
     catch (Exception ex)
     {
         Exception iEx = Library.Helper.GetInnerException(ex);
         notification.Type    = Library.DTO.NotificationType.Error;
         notification.Message = iEx.Message;
         return(false);
     }
 }
Example #2
0
        public override bool UpdateData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification)
        {
            notification      = new Library.DTO.Notification();
            notification.Type = Library.DTO.NotificationType.Success;

            DTO.WarehouseTransferDTO dtoWarehouseTransfer = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.WarehouseTransferDTO>();

            try
            {
                // Get company
                Framework.DAL.DataFactory frameworkFactory = new Framework.DAL.DataFactory();
                int?companyID = frameworkFactory.GetCompanyID(userId);

                using (WarehouseTransferMngEntities context = CreateContext())
                {
                    WarehouseTransfer dbWarehouseTransfer;

                    if (id == 0)
                    {
                        dbWarehouseTransfer = new WarehouseTransfer();
                        context.WarehouseTransfer.Add(dbWarehouseTransfer);
                    }
                    else
                    {
                        dbWarehouseTransfer = context.WarehouseTransfer.FirstOrDefault(o => o.WarehouseTransferID == id);
                    }

                    if (dbWarehouseTransfer == null)
                    {
                        notification.Type    = Library.DTO.NotificationType.Error;
                        notification.Message = "Can not find WarehouseTransfer!";

                        return(false);
                    }

                    converter.DTO2DB_WarehouseTransfer(userId, companyID, dtoWarehouseTransfer, ref dbWarehouseTransfer);

                    // Remove local WarehouseTransferDetail
                    context.WarehouseTransferDetail.Local.Where(o => o.WarehouseTransfer == null).ToList().ForEach(o => context.WarehouseTransferDetail.Remove(o));
                    context.SaveChanges();

                    // Generate code WarehouseTransfer
                    if (id == 0)
                    {
                        context.WarehouseTransferMng_function_GenerateReceiptCode(dbWarehouseTransfer.WarehouseTransferID, dbWarehouseTransfer.CompanyID, dbWarehouseTransfer.ReceiptDate.Value.Year, dbWarehouseTransfer.ReceiptDate.Value.Month);
                    }

                    // Get data WarehouseTransfer to reload
                    dtoItem = GetData(userId, dbWarehouseTransfer.WarehouseTransferID, out notification).Data;
                }

                return(true);
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = Library.Helper.GetInnerException(ex).Message;

                return(false);
            }
        }
Example #3
0
        public object ConfirmDelivering(int userID, int id, out Library.DTO.Notification notification)
        {
            notification      = new Library.DTO.Notification();
            notification.Type = Library.DTO.NotificationType.Success;

            try
            {
                Framework.DAL.DataFactory frameworkFactory = new Framework.DAL.DataFactory();
                int?companyID = frameworkFactory.GetCompanyID(userID);

                // Update confirm receiving in WarehouseTransfer
                using (WarehouseTransferMngEntities context = CreateContext())
                {
                    WarehouseTransfer dbWarehouseTransfer = context.WarehouseTransfer.FirstOrDefault(o => o.WarehouseTransferID == id);

                    if (dbWarehouseTransfer == null)
                    {
                        notification.Type    = Library.DTO.NotificationType.Error;
                        notification.Message = "Can not find WarehouseTransfer!";

                        return(null);
                    }

                    dbWarehouseTransfer.IsConfirmDelivering = true;
                    dbWarehouseTransfer.UpdatedBy           = userID;
                    dbWarehouseTransfer.UpdatedDate         = DateTime.Now;

                    // Create receiving note new with WarehouseTransferID.
                    DeliveryNote dbDeliveryNote = new DeliveryNote();
                    context.DeliveryNote.Add(dbDeliveryNote);

                    dbDeliveryNote.DeliveryNoteDate    = DateTime.Now;
                    dbDeliveryNote.CompanyID           = companyID;
                    dbDeliveryNote.WarehouseTransferID = dbWarehouseTransfer.WarehouseTransferID;
                    dbDeliveryNote.ViewName            = "SaleOrderWithoutWorkOrder";
                    dbDeliveryNote.CreatedBy           = userID;
                    dbDeliveryNote.CreatedDate         = DateTime.Now;
                    dbDeliveryNote.UpdatedBy           = userID;
                    dbDeliveryNote.UpdatedDate         = DateTime.Now;
                    dbDeliveryNote.IsApproved          = true;
                    dbDeliveryNote.ApprovedBy          = userID;
                    dbDeliveryNote.ApprovedDate        = DateTime.Now;
                    dbDeliveryNote.Description         = dbWarehouseTransfer.ReceiptNo;
                    dbDeliveryNote.StatusTypeID        = 7; //From Transfer Warehouse

                    // Update receiving note detail with warehouse transfer detail
                    foreach (WarehouseTransferDetail dbWarehouseTransferDetail in dbWarehouseTransfer.WarehouseTransferDetail.ToList())
                    {
                        DeliveryNoteDetail dbDeliveryNoteDetail = new DeliveryNoteDetail();
                        dbDeliveryNote.DeliveryNoteDetail.Add(dbDeliveryNoteDetail);

                        // Update value important
                        dbDeliveryNoteDetail.ProductionItemID = dbWarehouseTransferDetail.ProductionItemID;
                        dbDeliveryNoteDetail.Qty       = dbWarehouseTransferDetail.ReceivedQnt;
                        dbDeliveryNoteDetail.QtyByUnit = dbWarehouseTransferDetail.ReceivedQnt;
                        dbDeliveryNoteDetail.FromFactoryWarehouseID = dbWarehouseTransferDetail.FromFactoryWarehouseID;
                        dbDeliveryNoteDetail.UnitID = dbWarehouseTransferDetail.UnitID;
                    }

                    context.SaveChanges();

                    // Create delivery note code
                    context.DeliveryNoteMng_function_GenerateDeliveryNoteUD(dbDeliveryNote.DeliveryNoteID, companyID, dbDeliveryNote.DeliveryNoteDate.Value.Year, dbDeliveryNote.DeliveryNoteDate.Value.Month);
                }

                // Get warehouse transfer after confirm receiving note
                return(GetData(id, out notification));
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = Library.Helper.GetInnerException(ex).Message;

                return(null);
            }
        }