Пример #1
0
        public void Submit(MainOrder order)
        {
            int sequence = 0;
            var envelope = new CommandEnvelope();
            envelope.Initialize(order);
           
            List<DocumentCommand> commandsToExecute = order.GetSubOrderCommandsToExecute();
            var createCommand = commandsToExecute.OfType<CreateCommand>().FirstOrDefault();
            if (createCommand != null)
                envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, createCommand));
            var lineItemCommands = commandsToExecute.OfType<AfterCreateCommand>();
            foreach (var _item in lineItemCommands)
            {
                envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, _item));
            }
            var editlineItemCommands = commandsToExecute.OfType<ChangeMainOrderLineItemCommand>();
            foreach (var _editeditem in editlineItemCommands)
            {
                envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, _editeditem));
            }
            var removedLineitem = commandsToExecute.OfType<RemoveMainOrderLineItemCommand>();
            foreach (var _removeditem in removedLineitem)
            {
                envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, _removeditem));
            }
            var co = commandsToExecute.OfType<ConfirmCommand>().FirstOrDefault();
            if (co != null)
                envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, co));
            var rco = commandsToExecute.OfType<RejectMainOrderCommand>().FirstOrDefault();
            if (rco != null)
                envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, rco));

            var approvedlineItemCommands = order.GetSubOrderCommandsToExecute().OfType<ApproveOrderLineItemCommand>();
            foreach (var _item in approvedlineItemCommands)
            {
                envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, _item));
            }

            var aop = commandsToExecute.OfType<ApproveCommand>().FirstOrDefault();
            if (aop != null)
                envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, aop));
            var closecommand = commandsToExecute.OfType<CloseOrderCommand>().FirstOrDefault();
            if (closecommand != null)
                envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, closecommand));
            _commandEnvelopeRouter.RouteCommandEnvelope(envelope);
        }
Пример #2
0
        public void Submit(MainOrder order)
        {
            List<DocumentCommand> commandsToExecute = order.GetSubOrderCommandsToExecute();
            var createCommand = commandsToExecute.OfType<CreateCommand>().FirstOrDefault();
            if (createCommand != null)
                _commandRouter.RouteDocumentCommand(createCommand);
            var lineItemCommands = commandsToExecute.OfType<AfterCreateCommand>();
            foreach (var _item in lineItemCommands)
            {
                _commandRouter.RouteDocumentCommand(_item);
            }
            var editlineItemCommands = commandsToExecute.OfType<ChangeMainOrderLineItemCommand>();
            foreach (var _editeditem in editlineItemCommands)
            {
                _commandRouter.RouteDocumentCommand(_editeditem);
            }
            var removedLineitem = commandsToExecute.OfType<RemoveMainOrderLineItemCommand>();
            foreach (var _removeditem in removedLineitem)
            {
                _commandRouter.RouteDocumentCommand(_removeditem);
            }
            var co = commandsToExecute.OfType<ConfirmCommand>().FirstOrDefault();
            if (co != null)
                _commandRouter.RouteDocumentCommand(co);

            //transfer inventory to pending warehouse
            HandleApprovedCommand(order);
            var aop = commandsToExecute.OfType<ApproveCommand>().FirstOrDefault();
            if (aop != null)
                _commandRouter.RouteDocumentCommand(aop);

            // transfer inventory to pending warehouse
            HandleDispatchLineItemsCommand(order);
            HandlePayments(order);
            var closecommand = commandsToExecute.OfType<CloseOrderCommand>().FirstOrDefault();
            if (closecommand != null)
                _commandRouter.RouteDocumentCommand(closecommand);
            var rco = commandsToExecute.OfType<RejectMainOrderCommand>().FirstOrDefault();
            if (rco != null)
            {
                _commandRouter.RouteDocumentCommand(rco);
                HandleLostSale(order);
            }
        }
Пример #3
0
        public void Submit(MainOrder order)
        {
            int sequence = 0;
            var envelope = new CommandEnvelope();
            envelope.GeneratedByCostCentreApplicationId = Guid.Empty;
            
            envelope.Initialize(order);
            List<DocumentCommand> commandsToExecute = order.GetSubOrderCommandsToExecute();
            var createCommand = commandsToExecute.OfType<CreateCommand>().FirstOrDefault();
            if (createCommand != null)
            {
                envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, createCommand));
                //AddToMongoDB(createCommand);
                
            }

            var lineItemCommands = commandsToExecute.OfType<AfterCreateCommand>();
            foreach (var _item in lineItemCommands)
            {
                  envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, _item));
                //AddToMongoDB(_item);
                //_busPublisher.WrapAndPublish(_item, (CommandType)Enum.Parse(typeof(CommandType), _item.CommandTypeRef));
              
               
            }
            var editlineItemCommands = commandsToExecute.OfType<ChangeMainOrderLineItemCommand>();
            foreach (var _editeditem in editlineItemCommands)
            {
                                  envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, _editeditem));

              
            }
            var removedLineitem = commandsToExecute.OfType<RemoveMainOrderLineItemCommand>();
            foreach (var _removeditem in removedLineitem)
            {
                   envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, _removeditem));

                
            }
            var co = commandsToExecute.OfType<ConfirmCommand>().FirstOrDefault();
            if (co != null)
            {
                 envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, co));

            }

            var rco = commandsToExecute.OfType<RejectMainOrderCommand>().FirstOrDefault();
            if (rco != null)
            {
                envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, rco));

            }

            var approvedlineItemCommands = order.GetSubOrderCommandsToExecute().OfType<ApproveOrderLineItemCommand>();
            foreach (var _item in approvedlineItemCommands)
            {
                  envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, _item));

            }
            var aop = commandsToExecute.OfType<ApproveCommand>().FirstOrDefault();
            if (aop != null)
            {
                envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, aop));
     
            }
            AddToMongoDB(envelope);
        }
Пример #4
0
        private void HandleApprovedCommand(MainOrder order)
        {
            Config config = _configService.Load();
            var approvedlineItemCommands = order.GetSubOrderCommandsToExecute().OfType<ApproveOrderLineItemCommand>();

            if (!approvedlineItemCommands.Any())
                return;
            CostCentre issuer = null;
            CostCentre recepient = null;
            if (order.DocumentIssuerCostCentre is Distributor)
            {
                recepient = order.DocumentIssuerCostCentre;
                issuer = order.DocumentRecipientCostCentre;
            }
           
            else
            {
                recepient = order.DocumentRecipientCostCentre;
                issuer = order.DocumentIssuerCostCentre;
            }
            var getAll = _costCentreRepository.GetAll().OfType<DistributorPendingDispatchWarehouse>();
            DistributorPendingDispatchWarehouse pendingDispatchWarehouse =
                getAll.FirstOrDefault(p => p.ParentCostCentre.Id == recepient.Id);
           
            InventoryTransferNote inventoryTransfernote = _inventoryTransferNoteFactory.Create(recepient,
                                                                              config.CostCentreApplicationId,
                                                                              order.DocumentIssuerUser,
                                                                              pendingDispatchWarehouse,
                                                                              order.IssuedOnBehalfOf,
                                                                              order.DocumentReference);
            inventoryTransfernote.DocumentParentId = inventoryTransfernote.Id;
            string invoiceRef = _getDocumentReference.GetDocReference("Inv", order.DocumentReference);
            if (order.IsEditable())
            {
                Invoice invoice = _invoiceFactory.Create(issuer, config.CostCentreApplicationId, recepient,
                                                         order.DocumentIssuerUser, invoiceRef, order.Id, order.Id);
                foreach (var _item in order.PendingApprovalLineItems)
                {
                    invoice.AddLineItem(_invoiceFactory.CreateLineItem(_item.Product.Id, _item.Qty,
                                                                       _item.Value, order.DocumentReference, 0,
                                                                       _item.LineItemVatValue, _item.ProductDiscount,
                                                                       _item.DiscountType));
                }
                invoice.Confirm();
                _invoiceWorkFlowManager.SubmitChanges(invoice);
                if (order.GetPayments.Any(a => a.IsConfirmed && !a.IsProcessed))
                {

                    Guid currentInvoice = invoice.Id;

                    string receiptRef = _getDocumentReference.GetDocReference("Rpt", order.DocumentReference);
                    Receipt receipt = _receiptFactory.Create(issuer,
                                                             config.CostCentreApplicationId,
                                                             recepient,
                                                             order.DocumentIssuerUser, receiptRef, order.Id, currentInvoice,
                                                             Guid.Empty);

                    foreach (var info in order.GetPayments.Where(s => s.IsConfirmed && !s.IsProcessed))
                    {
                        receipt.AddLineItem(_receiptFactory.CreateLineItem(info.Amount, info.PaymentRefId,
                                                                           info.MMoneyPaymentType,
                                                                           info.NotificationId, 0,
                                                                           info.PaymentModeUsed, info.Description, receipt.Id,
                                                                           info.IsConfirmed)
                            );
                    }
                    receipt.Confirm();
                    _receiptWorkFlowManager.SubmitChanges(receipt);
                }

            }

            foreach (var _item in approvedlineItemCommands)
            {
                ApproveOrderLineItemCommand ap = _item as ApproveOrderLineItemCommand;
                SubOrderLineItem soli = order.PendingApprovalLineItems.First(s => s.Id == ap.LineItemId);
                if (ap.ApprovedQuantity > 0)
                {
                    inventoryTransfernote.AddLineItem(_inventoryTransferNoteFactory.CreateLineItem(soli.Product.Id, ap.ApprovedQuantity, 0, 0, order.DocumentReference));

                }
                _commandRouter.RouteDocumentCommand(_item);
            }
            inventoryTransfernote.Confirm();
            _inventoryTransferNoteWfManager.SubmitChanges(inventoryTransfernote);

        }
Пример #5
0
        private void HandleDispatchLineItemsCommand(MainOrder order)
        {
            var dop = order.GetSubOrderCommandsToExecute().OfType<OrderDispatchApprovedLineItemsCommand>().FirstOrDefault();
            if (dop == null)
                return;
            Config config = _configService.Load();
            CostCentre recepient = null;
            if (order.DocumentIssuerCostCentre is DistributorSalesman)
                recepient = order.DocumentIssuerCostCentre;
            else
                recepient = order.DocumentRecipientCostCentre;
            CostCentre issuer = _costCentreRepository.GetAll().OfType<DistributorPendingDispatchWarehouse>().First();
            InventoryTransferNote _transferToPhone = _inventoryTransferNoteFactory.Create(issuer,
                                                                              config.CostCentreApplicationId,
                                                                              order.DocumentIssuerUser,
                                                                              recepient,
                                                                              order.IssuedOnBehalfOf,
                                                                              order.DocumentReference);
            _transferToPhone.DocumentParentId = order.Id;
            DispatchNote dispatctFromPhone = _dispatchNoteFactory.Create(issuer, config.CostCentreApplicationId,
                                                                         recepient, order.DocumentIssuerUser,
                                                                         order.IssuedOnBehalfOf,
                                                                         DispatchNoteType.DispatchToPhone,
                                                                         order.DocumentReference, order.ParentId,
                                                                         order.Id);

            foreach (var item in order.PendingDispatchLineItems)
            {
                _transferToPhone.AddLineItem(_inventoryTransferNoteFactory.CreateLineItem(item.Product.Id, item.ApprovedQuantity, 0, 0, order.DocumentReference));
                dispatctFromPhone.AddLineItem(_dispatchNoteFactory.CreateLineItem(item.Product.Id, item.ApprovedQuantity, 0, order.DocumentReference, 0, 0, item.ProductDiscount, item.DiscountType));
            }
            _transferToPhone.Confirm();
            _inventoryTransferNoteWfManager.SubmitChanges(_transferToPhone);


            _commandRouter.RouteDocumentCommand(dop);
            dispatctFromPhone.Confirm();
            _dispatchNoteWfManager.SubmitChanges(dispatctFromPhone);


        }
Пример #6
0
        private void HandlePayments(MainOrder order)
        {
            Config config = _configService.Load();
            var orderpaymentInfoitem = order.GetSubOrderCommandsToExecute().OfType<AddOrderPaymentInfoCommand>();
            foreach (var paymentInfo in orderpaymentInfoitem)
            {
                _commandRouter.RouteDocumentCommand(paymentInfo);
            }
            var invoice = _invoiceRepository.GetInvoiceByOrderId(order.Id);
            if (orderpaymentInfoitem.Any(s => s.IsConfirmed && !s.IsProcessed) && invoice != null)
            {
                Guid currentInvoice = invoice.Id;

                string receiptRef = _getDocumentReference.GetDocReference("Rpt", order.DocumentReference);
                Receipt receipt = _receiptFactory.Create(order.DocumentIssuerCostCentre,
                                                         config.CostCentreApplicationId,
                                                         order.DocumentRecipientCostCentre,
                                                         order.DocumentIssuerUser, receiptRef, order.Id, currentInvoice,
                                                         Guid.Empty);

                foreach (var info in orderpaymentInfoitem.Where(s => s.IsConfirmed && !s.IsProcessed))
                {
                    receipt.AddLineItem(_receiptFactory.CreateLineItem(info.ConfirmedAmount, info.PaymentRefId,
                                                                       info.MMoneyPaymentType,
                                                                       info.NotificationId, 0,
                                                                       (PaymentMode)info.PaymentModeId, info.Description, receipt.Id,
                                                                       info.IsConfirmed)
                        );
                }
                receipt.Confirm();
                _receiptWorkFlowManager.SubmitChanges(receipt);

            }


        }
Пример #7
0
       public void Submit(MainOrder order,BasicConfig config)
        {

            int sequence = 0;
            var envelope = new CommandEnvelope();
            envelope.Initialize(order);
            List<DocumentCommand> commandsToExecute = order.GetSubOrderCommandsToExecute();
            var createCommand = commandsToExecute.OfType<CreateCommand>().FirstOrDefault();
            if (createCommand != null)
                envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, createCommand));
            var lineItemCommands = commandsToExecute.OfType<AfterCreateCommand>();
            foreach (var _item in lineItemCommands)
            {
                envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, _item));
               // _commandRouter.RouteDocumentCommand(_item);
            }
            var editlineItemCommands = commandsToExecute.OfType<ChangeMainOrderLineItemCommand>();
            foreach (var _editeditem in editlineItemCommands)
            {
                envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, _editeditem));

                //_commandRouter.RouteDocumentCommand(_editeditem);
            }
            var removedLineitem = commandsToExecute.OfType<RemoveMainOrderLineItemCommand>();
            foreach (var _removeditem in removedLineitem)
            {
                envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, _removeditem));

            }
            var co = commandsToExecute.OfType<ConfirmCommand>().FirstOrDefault();
            if (co != null)
            {
                envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, co));
                //_commandRouter.RouteDocumentCommand(co);
                _notifyService.SubmitOrderSaleNotification(order);
            }
           var rco = commandsToExecute.OfType<RejectMainOrderCommand>().FirstOrDefault();
            if (rco != null)
                envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, rco));

            //adjust inventory from distributor
           Guid invoiceId;
           var approvedlineItemCommands = order.GetSubOrderCommandsToExecute().OfType<ApproveOrderLineItemCommand>();

           foreach (var _item in approvedlineItemCommands)
           {
               envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, _item));
           }
            HandleApprovedCommand(order,config,out invoiceId);
            var aop = commandsToExecute.OfType<ApproveCommand>().FirstOrDefault();
            if (aop != null)
                envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, aop));

            var closecommand = commandsToExecute.OfType<CloseOrderCommand>().FirstOrDefault();
            if (closecommand != null)
                envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, closecommand));
            var orderpaymentInfoitem = order.GetSubOrderCommandsToExecute().OfType<AddOrderPaymentInfoCommand>();
            foreach (var paymentInfo in orderpaymentInfoitem)
            {
                envelope.CommandsList.Add(new CommandEnvelopeItem(++sequence, paymentInfo));
       
                
            }
            HandlePayments(order,invoiceId, config);
            _commandEnvelopeRouter.RouteCommandEnvelope(envelope);
           
        }
Пример #8
0
       private void HandleApprovedCommand(MainOrder order ,BasicConfig config,  out Guid invoiceId)
       {
           

           invoiceId = Guid.Empty;
           var approvedlineItemCommands = order.GetSubOrderCommandsToExecute().OfType<ApproveOrderLineItemCommand>();

           if (!approvedlineItemCommands.Any())
               return;
           CostCentre issuer = _costCentreRepository.GetById(config.CostCentreId);
           CostCentre recepient = null;
           if (order.DocumentIssuerCostCentre is DistributorSalesman)
               recepient = order.DocumentIssuerCostCentre;
           else
               recepient = order.DocumentRecipientCostCentre;
           InventoryAdjustmentNote inventoryAdjustmentNote = 
               _inventoryAdjustmentNoteFactory.Create(issuer,
                                                       config.CostCentreApplicationId,
                                                        recepient,
                                                        order.DocumentIssuerUser,
                                                        order.DocumentReference,
                                                        InventoryAdjustmentNoteType.Available, 
                                                        order.ParentId);
           inventoryAdjustmentNote.DocumentParentId = order.Id;
           string invoiceRef = _getDocumentReference.GetDocReference("Inv",recepient.Id,order.IssuedOnBehalfOf.Id);
        
           Domain.Transactional.DocumentEntities.Invoice invoice = _invoiceFactory.Create(issuer, config.CostCentreApplicationId, recepient,
                                                    order.DocumentIssuerUser, invoiceRef, order.Id, order.Id);
           invoiceId = invoice.Id;
           
           foreach (var _item in approvedlineItemCommands)
           {
               ApproveOrderLineItemCommand ap = _item as ApproveOrderLineItemCommand;
               SubOrderLineItem soli = order.PendingApprovalLineItems.First(s => s.Id == ap.LineItemId);
               if (ap.ApprovedQuantity > 0)
               {
                   inventoryAdjustmentNote.AddLineItem(_inventoryAdjustmentNoteFactory.CreateLineItem(0,soli.Product.Id, ap.ApprovedQuantity,0, "Inventory adjustment"));
                   invoice.AddLineItem(_invoiceFactory.CreateLineItem(soli.Product.Id, ap.ApprovedQuantity, soli.Value, order.DocumentReference, 0, soli.LineItemVatValue, soli.ProductDiscount, soli.DiscountType));
               }
             //  _commandRouter.RouteDocumentCommand(_item);
           }
           inventoryAdjustmentNote.Confirm();
           _inventoryAdjustmentNoteWfManager.SubmitChanges(inventoryAdjustmentNote,config);
           invoice.Confirm();
           
           _invoiceWorkFlowManager.SubmitChanges(invoice,config);

           
               
               
           }
Пример #9
0
       private void HandlePayments(MainOrder order, Guid invoiceId,BasicConfig config)
       {
           var orderpaymentInfoitem = order.GetSubOrderCommandsToExecute().OfType<AddOrderPaymentInfoCommand>();
           foreach (var paymentInfo in orderpaymentInfoitem)
           {
               //TODO AJM resolve this section
               /*
               var notification = _notificationRepository.GetById(paymentInfo.InfoId);
               if (notification != null)
               {
                   foreach (var paymentNotificationListItem in notification.PaymentNotificationDetails.Where(s => !s.IsUsed))
                   {
                       _notificationRepository.ConfirmNotificationItem(paymentNotificationListItem.Id);
                   }
               }*/
           }
           
           if (orderpaymentInfoitem.Any(s => s.IsConfirmed && !s.IsProcessed))
           {
               if (invoiceId == Guid.Empty)
                   invoiceId = _invoiceRepository.GetInvoiceByOrderId(order.Id).Id;
               CostCentre recepient = null;
               if (order.DocumentIssuerCostCentre is DistributorSalesman)
                   recepient = order.DocumentIssuerCostCentre;
               else
                   recepient = order.DocumentRecipientCostCentre;
               string receiptRef = _getDocumentReference.GetDocReference("Rpt", recepient.Id,order.IssuedOnBehalfOf.Id);
               Receipt receipt = _receiptFactory.Create(order.DocumentIssuerCostCentre,
                                                        order.DocumentIssuerCostCentreApplicationId,
                                                        order.DocumentRecipientCostCentre,
                                                        order.DocumentIssuerUser, receiptRef, order.Id, invoiceId,
                                                        Guid.Empty);

               foreach (var info in orderpaymentInfoitem.Where(s => s.IsConfirmed && !s.IsProcessed))
               {
                   receipt.AddLineItem(_receiptFactory.CreateLineItem(info.ConfirmedAmount, info.PaymentRefId,
                                                                      info.MMoneyPaymentType,
                                                                      info.NotificationId, 0,
                                                                      (PaymentMode)info.PaymentModeId, info.Description, receipt.Id,
                                                                      info.IsConfirmed)
                       );
               }
               receipt.Confirm();
               _receiptWorkFlowManager.SubmitChanges(receipt,config);

           }

           
       }