Example #1
0
        internal bool UpdateOrderLine(sales_flat_order order, InvoiceOrderDetail line)
        {
            using (var cm = Connection.CreateCommand())
            {
                cm.CommandText = "UPDATE sales_flat_order_item SET qty_invoiced = ?qty_invoiced WHERE order_id = ?order_id AND sku = '?sku'";
                cm.CommandType = CommandType.Text;
                cm.Parameters.AddWithValue("?order_id", order.entity_id);
                cm.Parameters.AddWithValue("?sku", line.ProductIdentifier.ManufacturerItemID);

                cm.Parameters.AddWithValue("?qty_invoiced", line.Quantity.QuantityShipped);

                return(cm.ExecuteNonQuery() > 0);
            }
        }
        public InvoiceNotification GenerateInvoiceNotification(EdiOrderResponse response, IEdiProcessor processor, System.Configuration.Configuration config)
        {
            List <EdiOrderResponseLine> responseLines = response.EdiOrderResponseLines.ToList();
            EdiOrder order = response.EdiOrder;

            if (order == null)
            {
                order = processor.GetOrderInformation(response, config);
            }

            List <InvoiceOrderDetail> replyItems = new List <InvoiceOrderDetail>();

            foreach (var line in responseLines)
            {
                InvoiceOrderDetail lineItem = new InvoiceOrderDetail();
                if (line.EdiOrderLineID.HasValue)
                {
                    lineItem.ProductIdentifier = new Concentrator.Web.Objects.EDI.ProductIdentifier();
                    lineItem.ProductIdentifier.ProductNumber = line.EdiOrderLine.ProductID.HasValue ? line.EdiOrderLine.ProductID.Value.ToString() : line.EdiOrderLine.CustomerItemNumber;
                    //lineItem.ProductIdentifier.ManufacturerItemID = line.EdiOrderLine.ProductID.HasValue ? line.EdiOrderLine.Product.VendorItemNumber : string.Empty;
                    //if (line.EdiOrderLine.ProductID.HasValue && line.EdiOrderLine.Product.ProductBarcodes.Count > 0)
                    //  lineItem.ProductIdentifier.EANIdentifier = line.EdiOrderLine.Product.ProductBarcodes.FirstOrDefault().Barcode;

                    lineItem.CustomerReference = new Concentrator.Web.Objects.EDI.CustomerReference();
                    lineItem.CustomerReference.CustomerItemNumber = line.EdiOrderLine.CustomerItemNumber;
                    lineItem.CustomerReference.CustomerOrder      = line.EdiOrderLine.CustomerOrderNr;
                    lineItem.CustomerReference.CustomerOrderLine  = line.EdiOrderLine.CustomerEdiOrderLineNr;
                    lineItem.LineNumber = line.EdiOrderLineID.ToString();
                }
                else
                {
                    lineItem.ProductIdentifier = new Concentrator.Web.Objects.EDI.ProductIdentifier();
                    lineItem.ProductIdentifier.ProductNumber = line.VendorItemNumber;
                    //lineItem.ProductIdentifier.ManufacturerItemID = line.EdiOrderLine.ProductID.HasValue ? line.EdiOrderLine.Product.VendorItemNumber : string.Empty;
                    //if (line.EdiOrderLine.ProductID.HasValue && line.EdiOrderLine.Product.ProductBarcodes.Count > 0)
                    //  lineItem.ProductIdentifier.EANIdentifier = line.EdiOrderLine.Product.ProductBarcodes.FirstOrDefault().Barcode;

                    lineItem.CustomerReference = new Concentrator.Web.Objects.EDI.CustomerReference();
                    lineItem.CustomerReference.CustomerItemNumber = string.Empty;
                    lineItem.CustomerReference.CustomerOrder      = line.Remark;
                    lineItem.CustomerReference.CustomerOrderLine  = line.VendorLineNumber;
                }

                if (line.DeliveryDate.HasValue)
                {
                    lineItem.PromissedDeliveryDate = line.DeliveryDate.Value;
                }

                if (line.RequestDate.HasValue)
                {
                    lineItem.RequestedDate = line.RequestDate.Value;
                }
                else if (order.RequestDate.HasValue)
                {
                    lineItem.RequestedDate = order.RequestDate.Value;
                }

                lineItem.Quantity = new Quantity();
                lineItem.Quantity.QuantityBackordered          = line.Backordered;
                lineItem.Quantity.QuantityBackorderedSpecified = true;
                lineItem.Quantity.QuantityCancelled            = line.Cancelled;
                lineItem.Quantity.QuantityCancelledSpecified   = true;
                lineItem.Quantity.QuantityOrdered          = line.Ordered;
                lineItem.Quantity.QuantityShipped          = line.Invoiced;
                lineItem.Quantity.QuantityShippedSpecified = true;

                if (string.IsNullOrEmpty(line.EdiOrderResponse.VendorDocumentNumber))
                {
                    lineItem.StatusCode = StatusCode.Reject;
                }
                else if (line.Cancelled == line.Ordered)
                {
                    lineItem.StatusCode = StatusCode.Delete;
                }
                else if (line.Ordered != line.Shipped)
                {
                    lineItem.StatusCode = StatusCode.Change;
                }
                else
                {
                    lineItem.StatusCode = StatusCode.Accept;
                }

                if (line.VatAmount.HasValue)
                {
                    lineItem.TaxAmount = line.VatAmount.Value;
                }

                lineItem.UnitOfMeasure = InvoiceOrderDetailUnitOfMeasure.EA;
                lineItem.UnitPrice     = line.Price;

                lineItem.ShipmentInformation                     = new ShipmentInformation();
                lineItem.ShipmentInformation.CarrierCode         = line.CarrierCode;
                lineItem.ShipmentInformation.NumberOfColli       = line.NumberOfUnits.HasValue ? line.NumberOfUnits.Value.ToString() : "1";
                lineItem.ShipmentInformation.NumberOfPallet      = line.NumberOfPallets.HasValue ? line.NumberOfPallets.Value.ToString() : "0";
                lineItem.ShipmentInformation.TrackAndTraceNumber = line.TrackAndTrace;

                lineItem.ExtendedPrice          = line.Price;
                lineItem.ExtendedPriceSpecified = false;

                lineItem.InvoiceNumber = response.InvoiceDocumentNumber;
                if (!string.IsNullOrEmpty(line.SerialNumbers))
                {
                    lineItem.SerialNumbers = line.SerialNumbers.Split(';');
                }

                replyItems.Add(lineItem);
            }

            InvoiceOrderHeader header = new InvoiceOrderHeader()
            {
                BSKIdentifier          = order.ConnectorRelationID.HasValue ? order.ConnectorRelationID.Value : 0,
                CustomerOrder          = order.CustomerOrderReference,
                OrderNumber            = response.VendorDocumentNumber,
                RequestedDate          = response.ReqDeliveryDate.HasValue ? response.ReqDeliveryDate.Value : order.ReceivedDate,
                RequestedDateSpecified = response.ReqDeliveryDate.HasValue,
                WebSiteOrderNumber     = order.WebSiteOrderNumber,
            };

            header.PackingInformation = new PackingInformation();
            header.PackingInformation.PackingDateTime = response.ReceiveDate;
            header.PackingInformation.PackingNumber   = response.ShippingNumber;

            if (response.PartialDelivery.HasValue && response.PartialDelivery.Value)
            {
                header.FullfillmentCode = InvoiceOrderHeaderFullfillmentCode.Partial;
            }
            else
            {
                header.FullfillmentCode = InvoiceOrderHeaderFullfillmentCode.Complete;
            }

            if (response.ShippedToCustomer != null)
            {
                header.ShipToCustomer   = FillShipToCustomer(response.ShippedToCustomer);
                header.CustomerOverride = FillCustomerOverride(response.ShippedToCustomer);
            }
            else
            {
                header.ShipToCustomer   = FillShipToCustomer(order.ShippedToCustomer);
                header.CustomerOverride = FillCustomerOverride(order.ShippedToCustomer);
            }

            if (response.SoldToCustomer != null)
            {
                header.SoldToCustomer = FillShipToCustomer(response.SoldToCustomer);
            }
            else
            {
                header.SoldToCustomer = FillShipToCustomer(order.SoldToCustomer);
            }

            if (response.InvoiceDate.HasValue)
            {
                header.InvoiceDate = response.InvoiceDate.Value;
            }

            header.InvoiceNumber = response.InvoiceDocumentNumber;
            if (response.VatAmount.HasValue)
            {
                header.InvoiceTax = response.VatAmount.Value.ToString();
            }
            if (response.TotalExVat.HasValue)
            {
                header.InvoiceTaxableAmount = response.TotalExVat.Value.ToString();
            }
            if (response.TotalAmount.HasValue)
            {
                header.InvoiceTotalInc = response.TotalAmount.Value.ToString();
            }
            if (!string.IsNullOrEmpty(response.PaymentConditionDiscount))
            {
                header.DisountAmount = response.PaymentConditionDiscount;
            }

            InvoiceNotification invoiceNotification = new InvoiceNotification()
            {
                InvoiceOrderDetails = replyItems.ToArray(),
                InvoiceOrderHeader  = header,
                Version             = "1.0"
            };

            return(invoiceNotification);
        }