Exemplo n.º 1
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);

        }
Exemplo n.º 2
0
        private void HandleLostSale(MainOrder order)
        {
            if (!order.IsEditable())
            {
                Invoice invoice = _invoiceRepository.GetInvoiceByOrderId(order.Id);
                string creditnoteRef = _getDocumentReference.GetDocReference("CN", order.DocumentReference);
                CreditNote cn = _creditNoteFactory
                    .Create(order.DocumentIssuerCostCentre, order.DocumentIssuerCostCentreApplicationId, order.DocumentRecipientCostCentre, order.DocumentIssuerUser, creditnoteRef, order.Id, invoice.Id);
                foreach (var _item in order.PendingApprovalLineItems)
                {
                    cn.AddLineItem(_creditNoteFactory.CreateLineItem(_item.Product.Id, _item.Qty,
                                                                           _item.Value, order.DocumentReference, 0,
                                                                           _item.LineItemVatValue, _item.ProductDiscount
                                                                           ));

                }
                cn.Confirm();
                _confirmCreditNoteWFManager.SubmitChanges(cn);
            }
        }