Beispiel #1
0
partial         void InsertdeliveryLine(deliveryLine instance)
        {
            instance.docType = "DL";

            if (!String.IsNullOrEmpty(instance.uomCodeOrg))
                if (this.unitOfMeasureLinks.Any(c => c.uomCodeOrg.Equals(instance.uomCodeOrg)))
                    instance.uomCode = this.unitOfMeasureLinks.Where(c => c.uomCodeOrg.Equals(instance.uomCodeOrg)).FirstOrDefault().uomCode;

            if (instance.baseDocId != null && instance.baseLineNum != null)
            {
                // Copy LineInformation from base document
                if (instance.baseDocType.Equals("SO"))
                {
                    salesOrderLine soLine = this.salesOrderLines.Where(c => c.docId.Equals(instance.baseDocId) && c.lineNum.Equals(instance.baseLineNum)).FirstOrDefault();
                    if (soLine != null)
                    {
                        if (instance.itemId == null)
                            instance.itemId = soLine.itemId;

                        if (String.IsNullOrEmpty(instance.lineTypeCode))
                            instance.lineTypeCode = soLine.lineTypeCode;

                        if (instance.price == null)
                            instance.price = soLine.price;

                        if (String.IsNullOrEmpty(instance.customerReference))
                            instance.customerReference = soLine.customerReference;

                        if (String.IsNullOrEmpty(instance.uomCode))
                            instance.uomCode = soLine.uomCode;

                        if (String.IsNullOrEmpty(instance.uomCodeOrg))
                            instance.uomCodeOrg = soLine.uomCodeOrg;

                        if (String.IsNullOrEmpty(instance.uomCodeOrg))
                            instance.uomCodeOrg = soLine.uomCodeOrg;

                        if (String.IsNullOrEmpty(instance.customerItemCode))
                            instance.customerItemCode = soLine.customerItemCode;
                    }
                    else
                    {
                        throw new Exception(String.Format("Base Sales order {0} line {1} does not exists!", instance.baseDocId, instance.baseLineNum));
                    }
                }

            }

            this.ExecuteDynamicInsert(instance);
        }
        public static Boolean ProcessDelivery(String fileContent, out delivery deliveryDocument)
        {
            deliveryDocument = new delivery();
            List<batch> batches = new List<batch>();
            String sapECC6DocNum = String.Empty;

            DALPortalDataContext dc = new DALPortalDataContext();
            Boolean update;
            Boolean returnValue = true;

            try
            {
                List<String> items = new List<String>();

                XDocument xmldoc = XDocument.Parse(fileContent);
                XElement docTypeElement = xmldoc.Element("DELVRY03");
                XElement iDocElement = docTypeElement.Element("IDOC");
                XElement deliveryElement = iDocElement.Element("E1EDL20");

                // Company
                String sectionCode = deliveryElement.Element("VKORG").Value;
                String companyCode = CompanyClass.GetCompanyBasedOnSection(sectionCode, dc);

                sapECC6DocNum = RemoveLeadingZeros(deliveryElement.Element("VBELN").Value);

                // Check if Sales Order already exists
                deliveryDocument = dc.deliveries.Where(c => c.documentNumber.Equals(sapECC6DocNum) && c.companyCode.Equals(companyCode)).FirstOrDefault();
                if (deliveryDocument == null)
                {
                    deliveryDocument = new delivery();
                    deliveryDocument.companyCode = companyCode;
                    deliveryDocument.documentNumber = sapECC6DocNum;
                    deliveryDocument.docStatusCode = "O";
                    update = false;
                }
                else
                {
                    update = true;
                }

                // Document Header info
                String sapECC6BusinessPartnerCode = RemoveLeadingZeros(deliveryElement.Elements("E1ADRM1").Where(c => c.Element("PARTNER_Q").Value.Equals("AG")).FirstOrDefault().Element("PARTNER_ID").Value);
                businessPartner bp = Objects.BusinessPartnerClass.GetBusinessPartner(sapECC6BusinessPartnerCode, deliveryDocument.companyCode, dc);
                if (bp == null)
                    throw new Exception(String.Format("BusinessPartner {0} does not exists.", sapECC6BusinessPartnerCode));

                // Get BusinessPartnerID
                deliveryDocument.businessPartnerId = bp.businessPartnerId;

                // Dates
                XElement delDateElement = deliveryElement.Elements("E1EDT13").ToList().Where(c => c.Element("QUALF").Value.Equals("007")).FirstOrDefault();
                deliveryDocument.deliveryDate = DateTime.ParseExact(delDateElement.Element("NTEND").Value, "yyyyMMdd", CultureInfo.CurrentCulture);

                XElement del2DateElement = deliveryElement.Elements("E1EDT13").ToList().Where(c => c.Element("QUALF").Value.Equals("015")).FirstOrDefault();
                deliveryDocument.docDate = DateTime.ParseExact(del2DateElement.Element("NTEND").Value, "yyyyMMdd", CultureInfo.CurrentCulture);
                deliveryDocument.createDate = DateTime.ParseExact(del2DateElement.Element("NTEND").Value, "yyyyMMdd", CultureInfo.CurrentCulture);

                if (deliveryDocument.deliveryDate < DateTime.Now.AddYears(-50))
                    deliveryDocument.deliveryDate = deliveryDocument.docDate;

                //// Delivery lines
                List<XElement> deliveryLines = deliveryElement.Elements("E1EDL24").Where(c => c.Element("HIPOS") == null).ToList();
                List<XElement> deliverySubLines = deliveryElement.Elements("E1EDL24").Where(c => c.Element("HIPOS") != null).ToList();

                foreach (var deliveryLineElement in deliveryLines)
                {
                    deliveryLine line = new deliveryLine();

                    String lineNumString = deliveryLineElement.Element("POSNR").Value;
                    Int32 lineNum = Convert.ToInt32(lineNumString);

                    Boolean newLine = false;
                    if (update && deliveryDocument.deliveryLines.Any(c => c.lineNum.Equals(lineNum)))
                    {
                        line = deliveryDocument.deliveryLines.Where(c => c.lineNum.Equals(lineNum)).FirstOrDefault();
                    }
                    else
                    {
                        line.lineNum = lineNum;
                        newLine = true;
                    }

                    // DeliveryLine is not connected to a Sales Order
                    if (deliveryLineElement.Element("VGBEL") == null)
                        continue;

                    String sapSODocNum = RemoveLeadingZeros(deliveryLineElement.Element("VGBEL").Value);
                    Int32 sapSOLineNum = Convert.ToInt32(deliveryLineElement.Element("VGPOS").Value);

                    salesOrderLine salesOrderLine = Objects.SalesOrderClass.GetSalesOrderLine(sapSODocNum, lineNum, companyCode, dc);

                    if (salesOrderLine == null)
                    {
                        Trace.WriteLine(String.Format("Cannot find Sales Order {0}, Line {1} for Delivery {2}.", sapSODocNum, sapSOLineNum, sapECC6DocNum), "MapDeliveryXMLToSBO");
                        returnValue = false;
                        continue;
                    }

                    String itemCode = RemoveLeadingZeros(deliveryLineElement.Element("MATNR").Value);
                    item item = Objects.ItemClass.GetItem(itemCode, companyCode, dc);

                    // Get POSTYPE
                    String posType = deliveryLineElement.Element("E1EDL26").Element("PSTYV").Value;
                    XElement baseLineNum = deliveryLineElement.Element("HIPOS");

                    // Add Batchinfo
                    Decimal quantity = Convert.ToDecimal(deliveryLineElement.Element("LFIMG").Value, NumberFormatInfo.InvariantInfo);

                    if (lineNumString.Substring(0, 1).Equals("9"))
                        continue;

                    if (Serac.BasicFunctions.Right(itemCode, 1).Equals("B") && (posType == "ZBNI" || posType == "ZCNI"))
                    {
                        // Get Quantity and Batches from Treatment line
                        GetBatchesTreatmentLine(ref batches, ref quantity, line.lineNum, deliverySubLines, item.itemId);
                    }
                    else if (quantity > 0)
                    {
                        GetBatch(ref batches, line.lineNum, deliveryLineElement, quantity, item.itemId);
                    }
                    else
                    {
                        // Get Quantity and Batches from "Charge Splitsing"
                        GetBatchesChargeSplitsing(ref batches, ref quantity, line.lineNum, deliverySubLines, item.itemId);
                    }

                    // Update Currency from base document
                    if (deliveryDocument.currencyCode == null)
                    {
                        deliveryDocument.currencyCode = salesOrderLine.salesOrder.currencyCode;
                        deliveryDocument.currencyRate = salesOrderLine.salesOrder.currencyRate;
                    }

                    line.baseDocId = salesOrderLine.salesOrder.docId;
                    line.baseLineNum = Convert.ToInt32(deliveryLineElement.Element("VGPOS").Value);
                    line.baseDocType = "SO";

                    line.quantity = quantity;
                    line.itemId = item.itemId;
                    line.lineStatusCode = "O";
                    line.itemDescription = salesOrderLine.itemDescription;

                    // Get Certificates as ordered from base document
                    line.certOrdered = salesOrderLine.certOrdered;

                    // Add Line to SBO delivery line
                    if (newLine)
                        deliveryDocument.deliveryLines.Add(line);
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(String.Format("Error Converting Delivery XML to WebPortal format. Error: {0}", ex.Message), "ProcessDelivery");
                return false;
            }

            if (deliveryDocument.deliveryLines.Count == 0)
                return false;

            if (update)
            {
                try
                {
                    dc.SubmitChanges();
                    Trace.WriteLine(String.Format("Updating Delivery {0} for company {1} Successfull.", deliveryDocument.documentNumber, deliveryDocument.companyCode), "ProcessDelivery");
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(String.Format("Error Updating Delivery {0} for company {1}. Error: {2}", deliveryDocument.documentNumber, deliveryDocument.companyCode, ex.Message), "ProcessDelivery");
                    return false;
                }
            }
            else
            {
                try
                {
                    dc.deliveries.InsertOnSubmit(deliveryDocument);
                    dc.SubmitChanges();
                    Trace.WriteLine(String.Format("Creating Delivery {0} for company {1} Successfull.", deliveryDocument.documentNumber, deliveryDocument.companyCode), "ProcessDelivery");
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(String.Format("Error Creating Delivery {0} for company {1}. Error: {2}", deliveryDocument.documentNumber, deliveryDocument.companyCode, ex.Message), "ProcessDelivery");
                    return false;
                }
            }

            if (!ProcessBatches(deliveryDocument, batches))
                return false;

            return returnValue;
        }
Beispiel #3
0
partial         void UpdatedeliveryLine(deliveryLine instance)
        {
            instance.delivery.timeStampLastUpdate = DateTime.Now;
            this.ExecuteDynamicUpdate(instance);
        }
		private void attach_deliveryLines(deliveryLine entity)
		{
			this.SendPropertyChanging();
			entity.lineStatus = this;
		}
		private void detach_deliveryLines(deliveryLine entity)
		{
			this.SendPropertyChanging();
			entity.lineType = null;
		}
		private void attach_deliveryLines(deliveryLine entity)
		{
			this.SendPropertyChanging();
			entity.document = this;
		}
 partial void DeletedeliveryLine(deliveryLine instance);
 partial void UpdatedeliveryLine(deliveryLine instance);
 partial void InsertdeliveryLine(deliveryLine instance);
		private void detach_deliveryLines(deliveryLine entity)
		{
			this.SendPropertyChanging();
			entity.unitOfMeasure = null;
		}