예제 #1
0
        public void Save(ReturnsNote documentEntity)
        {
            tblDocument docToSave = SaveDocument(documentEntity);
            ReturnsNote rn = documentEntity;
            docToSave.OrderOrderTypeId = (int)rn.ReturnsNoteType;

            foreach (ReturnsNoteLineItem lineItem in rn._lineItems)
            {
                tblLineItems ll = null;
                if (docToSave.tblLineItems.Any(p => p.id == lineItem.Id))
                    ll = docToSave.tblLineItems.First(p => p.id.ToString() == lineItem.Id.ToString());
                else
                {
                    ll = new tblLineItems();
                    ll.id = lineItem.Id;
                    docToSave.tblLineItems.Add(ll);
                }
                if (lineItem.Product != null)
                    ll.ProductID = lineItem.Product.Id;
                ll.DocumentID = documentEntity.Id;
                ll.Description = lineItem.Description;
                ll.Quantity = lineItem.Qty;
                ll.IAN_Actual = lineItem.Actual;
                ll.LineItemSequenceNo = lineItem.LineItemSequenceNo;
                ll.Value = lineItem.Value;
                ll.Receipt_PaymentTypeId = (int)lineItem.ReturnType;
                ll.OrderLineItemType = (int)lineItem.LossType;
                ll.ReturnsNoteReason = lineItem.Reason;
                ll.Other = lineItem.Other;
            }
            _ctx.SaveChanges();
        }
        public void SubmitChanges(ReturnsNote document,BasicConfig config)
        {
            int sequence = 0;
            var envelope = new CommandEnvelope();
            envelope.Initialize(document);
            List<DocumentCommand> commandsToExecute = document.GetDocumentCommandsToExecute();
            var createCommand = commandsToExecute.OfType<CreateCommand>().FirstOrDefault();
            if (createCommand != null)
                envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, createCommand));
            //_commandRouter.RouteDocumentCommand(createCommand);
            _auditLogWFManager.AuditLogEntry("Return Note", string.Format("Created Return Note: {0}; From: {1}; To: {2}", document.Id, document.DocumentIssuerCostCentre.Name, document.DocumentRecipientCostCentre.Name));

            var lineItemCommands = commandsToExecute.OfType<AfterCreateCommand>();
            foreach (var _item in lineItemCommands)
            {
                var item = _item as AddInventoryTransferNoteLineItemCommand;
                envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, item));
                // _commandRouter.RouteDocumentCommand(_item);
                _auditLogWFManager.AuditLogEntry("Inventory Transfer", string.Format("Return Note: {0}; Quantity: {1}; for Return Note: {2};", item.ProductId, item.Qty, document.Id));
            }
            var co = commandsToExecute.OfType<ConfirmCommand>().FirstOrDefault();
            if (co != null)
                envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, co));
            //_commandRouter.RouteDocumentCommand(co);
            var clo = commandsToExecute.OfType<CloseReturnsNoteCommand>().FirstOrDefault();
            if (clo != null)
            {
                envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, clo));
            }
            _commandEnvelopeRouter.RouteCommandEnvelope(envelope);
            _auditLogWFManager.AuditLogEntry("Return Note", string.Format("Confirmed IReturn Note: {0}; From: {1}; To: {2}", document.Id, document.DocumentIssuerCostCentre.Name, document.DocumentRecipientCostCentre.Name));
     
        }
예제 #3
0
        public Document CreateDocument(Guid id, DocumentType documentType, CostCentre documentIssuerCC, CostCentre documentRecipientCC, User documentIssuerUser, string DocumentReference, double? longitude=null, double? latitude=null)
        {
            Document doc = null;
            switch (documentType)
            {
                case DocumentType.Order:
                    doc = new Order(id);
                    doc = Map(doc, documentType, documentIssuerCC, documentRecipientCC, /*null, */documentIssuerUser, DocumentReference, longitude, latitude);
                    break;
                case DocumentType.DispatchNote://
                    doc = new DispatchNote(id);
                    doc = Map(doc, documentType, documentIssuerCC, documentRecipientCC, /*null, */documentIssuerUser, DocumentReference, longitude, latitude);
                    break;
                
                case DocumentType.Receipt:
                    doc = new Receipt(id);
                    doc = Map(doc, documentType, documentIssuerCC, documentRecipientCC, documentIssuerUser, DocumentReference, longitude, latitude);
                    break;
                case DocumentType.DisbursementNote:
                    doc = new DisbursementNote(id);
                    doc = Map(doc, documentType, documentIssuerCC, documentRecipientCC, documentIssuerUser, DocumentReference, longitude, latitude);
                    break;
                case DocumentType.CreditNote:
                    doc = new CreditNote(id);
                    doc = Map(doc, documentType, documentIssuerCC, documentRecipientCC, documentIssuerUser, DocumentReference, longitude, latitude);
                    break;
                case DocumentType.ReturnsNote:
                  
                    doc = new ReturnsNote(id);
                    doc = Map(doc, documentType, documentIssuerCC, documentRecipientCC, documentIssuerUser, DocumentReference, longitude, latitude);
                    break;
                case DocumentType.PaymentNote:
                    doc = new PaymentNote(id);
                    doc = Map(doc, documentType, documentIssuerCC, documentRecipientCC, documentIssuerUser, DocumentReference, longitude, latitude);
                    break;


            }

            return doc;
        }
예제 #4
0
        private ArchiveItemViewModel MapReturns(ReturnsNote returnsNote,RetireType type, DocumentType documentType)
        {
            if (returnsNote != null)
            {
                ArchiveItemViewModel item = new ArchiveItemViewModel();
                item.ArchiveMode = type.ToString();
                item.IsArchive = false;
                item.OrderId = returnsNote.DocumentParentId;
                item.OrderReference = returnsNote.DocumentReference;
                item.RecipientCostCentreId = returnsNote.DocumentRecipientCostCentre.Id;
                item.IssuerCostCentreId = returnsNote.DocumentIssuerCostCentre.Id;
                item.DocumentType = documentType;
                //item.OutletName = order.DocumentIssuerCostCentre.Name;
                return item;

            }
            return null;
        }
예제 #5
0
        private InventoryAdjustmentNote CreateDistributrIAN(ReturnsNote returnnote)
        {
            using (var container = NestedContainer)
            {

                IConfigService _configService = Using<IConfigService>(container);


                var _inventoryService = Using<IInventoryRepository>(container);


                InventoryAdjustmentNote note = Using<IInventoryAdjustmentNoteFactory>(container).Create(
                    returnnote.DocumentRecipientCostCentre,_configService.Load().CostCentreApplicationId,
                    returnnote.DocumentRecipientCostCentre,returnnote.DocumentIssuerUser,"",
                    InventoryAdjustmentNoteType.Available, Guid.Empty);

                List<InventoryAdjustmentNoteLineItem> ListianLineitem = new List<InventoryAdjustmentNoteLineItem>();
                foreach (var item in returnnote._lineItems)
                {
                    if (item.ReturnType != ReturnsType.Inventory && item.Product == null) continue;
                    var inventory = _inventoryService.GetByProductIdAndWarehouseId(item.Product.Id,
                                                                     returnnote.DocumentRecipientCostCentre.Id);
                    decimal expected = inventory != null ? inventory.Balance : 0;
                    InventoryAdjustmentNoteLineItem ianLineitem = Using<IInventoryAdjustmentNoteFactory>(container)
                        .CreateLineItem(expected + item.Qty, item.Product.Id, expected, 0, item.Reason);
                    ListianLineitem.Add(ianLineitem);
                }
                foreach (var i in ListianLineitem)
                {
                    note.AddLineItem(i);
                }
                //note._SetLineItems(ListianLineitem);
                note.Confirm();
                return note;
            }

        }
예제 #6
0
        public PaymentNote CreatePaymentReturnDocument(ReturnsNote returnnote)
        {
           
                using (var container = NestedContainer)
                {

                    IConfigService _configService = Using<IConfigService>(container);


                    PaymentNote note = new PaymentNote(Guid.NewGuid());

                    note.DocumentDateIssued = DateTime.Now;
                    note.DocumentIssuerCostCentre = returnnote.DocumentIssuerCostCentre;
                    note.DocumentIssuerCostCentreApplicationId = _configService.Load().CostCentreApplicationId;
                    note.DocumentIssuerUser = returnnote.DocumentIssuerUser;
                    note.DocumentRecipientCostCentre = returnnote.DocumentRecipientCostCentre;
                    note.DocumentReference = "";
                    note.DocumentType = DocumentType.PaymentNote;
                    note.PaymentNoteType = PaymentNoteType.Returns;


                    foreach (var item in returnnote._lineItems)
                    {
                        if (item.ReturnType == ReturnsType.Inventory && item.Product == null) continue;

                        PaymentNoteLineItem ianLineitem = new PaymentNoteLineItem(Guid.NewGuid())
                        {
                            Amount = item.Value,
                            Description = item.Reason,
                            LineItemSequenceNo = 0,
                            PaymentMode = (PaymentMode) (int) item.ReturnType,
                        };
                        note.AddLineItem(ianLineitem);
                    }

                    return note;
                }
            
            
        }
예제 #7
0
        void ProcessReturnNote(ReturnsNote returnnote)
        {
            using (var container = NestedContainer)
            {
                BasicConfig config = container.GetInstance<IConfigService>().Load();
               
                var confirmInventoryAdjustmentNoteWfManager = Using<IInventoryAdjustmentNoteWfManager>(container);
                var confirmPaymentNoteWfManager = Using<IConfirmPaymentNoteWFManager>(container);

                if (returnnote._lineItems.All(s => s.ReturnType == ReturnsType.Inventory))
                {
                    var distributrAdjustInventory = CreateDistributrIAN(returnnote);
                    confirmInventoryAdjustmentNoteWfManager.SubmitChanges(distributrAdjustInventory,config);
                    var salesmanAdjustInventory = CreateSalesmanIAN(returnnote);
                    confirmInventoryAdjustmentNoteWfManager.SubmitChanges(salesmanAdjustInventory,config);
                }
                if (returnnote._lineItems.Any(s => s.ReturnType != ReturnsType.Inventory))
                {
                    var paymentNote = CreatePaymentReturnDocument(returnnote);
                    paymentNote.Confirm();
                    confirmPaymentNoteWfManager.SubmitChanges(paymentNote,config);
                    
                }
                
            }

        }
예제 #8
0
        void GenerateReturnNote()
        {
            Distributor dist = _costCentreService.GetAll().OfType<Distributor>().FirstOrDefault();
            DistributorSalesman salesman = _costCentreService.GetAll().OfType<DistributorSalesman>().FirstOrDefault();
            Config con = _configService.Load();
            User user = _userService.GetByCostCentre(salesman.Id).First();
            Product product = _productService.GetAll().FirstOrDefault();
            ReturnsNote doc = new ReturnsNote(Guid.NewGuid())
                                  {
                                      DocumentDateIssued = DateTime.Now,
                                      DocumentIssuerCostCentre = salesman,
                                      DocumentIssuerCostCentreApplicationId = con.CostCentreApplicationId,
                                      DocumentIssuerUser = user,
                                      DocumentRecipientCostCentre=dist,
                                      DocumentReference=Guid.NewGuid().ToString(),
                                      DocumentType=DocumentType.ReturnsNote,
                                      EndDate = DateTime.Now,
                                      StartDate = DateTime.Now,
                                      Status=DocumentStatus.New,
                                      
                                  };
            doc.Add(new ReturnsNoteLineItem(Guid.NewGuid())
                        {
                            Actual = 4,
                            Description = "tests",
                            IsNew=true,
                            LineItemSequenceNo=1,
                            Product = product,
                            Qty=4,
                            ReturnType=ReturnsType.Inventory,
                            Value=0,
                           
                        });
            //doc.Add(new ReturnsNoteLineItem(Guid.NewGuid())
            //{
            //    Actual = 20,
            //    Description = "tests",
            //    IsNew = true,
            //    LineItemSequenceNo = 1,
            //    Qty = 90,
            //    ReturnType = ReturnsType.Cash,
            //    Value = 2000,

            //});

            _confirmReturnsNoteWFManager.SubmitChanges(doc, _configService.Load());
           
           // _confirmReturnsNoteWFManager.Close(doc.Id);
            MessageBox.Show("Close Returns note Done");

        }
        private ReturnInventoryExportDocument Map(ReturnsNote returnsNote, Guid id)
        {
            var exportReturnedInventory = new ReturnInventoryExportDocument();
            
            exportReturnedInventory.Id = id;
            exportReturnedInventory.DocumentRef = returnsNote.DocumentReference;
            exportReturnedInventory.SalesmanCode = returnsNote.DocumentIssuerCostCentre.CostCentreCode; //returnsNote.DocumentIssuerUser.Username;
            exportReturnedInventory.SalesmanName = returnsNote.DocumentIssuerCostCentre.Name; //returnsNote.DocumentIssuerUser.Username
            exportReturnedInventory.DocumentDateIssued = returnsNote.DocumentDateIssued;

            foreach (var item in returnsNote._lineItems)
            {
                var exportReturnedInventoryItem = new ReturnInventoryExportDocumentItem();
                exportReturnedInventoryItem.Id = item.Id;
                exportReturnedInventoryItem.ProductCode = item.Product.ProductCode;
                exportReturnedInventoryItem.ProductName = item.Product.Description;
                exportReturnedInventoryItem.Quantity = item.Qty;
                exportReturnedInventoryItem.LossTypeId = (int) item.LossType;
                
                exportReturnedInventory.LineItems.Add(exportReturnedInventoryItem);
            }
            return exportReturnedInventory;
        }
        ReturnsNote CreateReturnsNote()
        {
            using (StructureMap.IContainer c = NestedContainer)
            {
                var thisCostCentre = Using<ICostCentreRepository>(c).GetById(Using<IConfigService>(c).Load().CostCentreId);
                var thisUser = Using<IUserRepository>(c).GetById(Using<IConfigService>(c).ViewModelParameters.CurrentUserId);
                ReturnsNote rn = new ReturnsNote(Guid.NewGuid())
                    {
                        DocumentDateIssued = DateTime.Now,
                        DocumentIssuerCostCentre = thisCostCentre,
                        DocumentIssuerCostCentreApplicationId = Using<IConfigService>(c).Load().CostCentreApplicationId,
                        DocumentIssuerUser = thisUser,
                        DocumentRecipientCostCentre = thisCostCentre,
                        DocumentReference =
                        Using<IGetDocumentReference>(c).GetDocReference("RN", thisUser.Id, thisCostCentre.Id),
                        DocumentType = DocumentType.ReturnsNote,
                        Status = DocumentStatus.New,
                        ReturnsNoteType = ReturnsNoteType.DistributorToHQ
                    };
                foreach (DispatchProductLineItem item in LineItems)
                {
                    var li = new ReturnsNoteLineItem(Guid.NewGuid())
                        {
                            Actual = item.Qty,
                            Qty = item.Qty,
                            Description = item.ProductDesc,
                            Product = Using<IProductRepository>(c).GetById(item.ProductId),
                            ReturnType = ReturnsType.Inventory,
                            LineItemSequenceNo = rn._lineItems.Count + 1,
                            IsNew = true,
                            Reason = item.Reason,
                            Other = item.OtherReason
                        };
                    rn.Add(li);
                }

                return rn;
            }
        }