Пример #1
0
        partial void InsertsalesOrderLine(salesOrderLine instance)
        {
            instance.docType = "SO";

            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;
                }
            }

            this.ExecuteDynamicInsert(instance);
        }
Пример #2
0
        public static Boolean ProcessSalesOrder(string fileContent, out salesOrder document)
        {
            document = new salesOrder();

            DALPortalDataContext dc = new DALPortalDataContext();
            Boolean update;

            try
            {
                XDocument xmldoc = XDocument.Parse(fileContent);
                XElement docTypeElement = xmldoc.Element("ORDERS05");
                XElement iDocElement = docTypeElement.Element("IDOC");

                // Company
                XElement companyElement = iDocElement.Elements("E1EDK14").ToList().Where(c => c.Element("QUALF").Value.Equals("008")).FirstOrDefault();
                String sectionCode = companyElement.Element("ORGID").Value;
                String companyCode = CompanyClass.GetCompanyBasedOnSection(sectionCode, dc);

                String ecc6DocNum = RemoveLeadingZeros(iDocElement.Element("E1EDK01").Element("BELNR").Value);

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

                // Document Header info
                String sapECC6BusinessPartnerCode = Convert.ToInt32(iDocElement.Element("E1EDK01").Element("RECIPNT_NO").Value).ToString();
                businessPartner bp = Objects.BusinessPartnerClass.GetBusinessPartner(sapECC6BusinessPartnerCode, document.companyCode, dc);
                if (bp == null)
                    throw new Exception(String.Format("BusinessPartner {0} does not exists.", sapECC6BusinessPartnerCode));

                document.businessPartnerId = bp.businessPartnerId;
                document.currencyCode = iDocElement.Element("E1EDK01").Element("CURCY").Value;
                document.currencyRate = Convert.ToDecimal(iDocElement.Element("E1EDK01").Element("WKURS").Value, NumberFormatInfo.InvariantInfo);

                // Customer Reference
                XElement custRef = iDocElement.Elements("E1EDK02").ToList().Where(c => c.Element("QUALF").Value.Equals("001")).FirstOrDefault();
                document.customerReference = custRef.Element("BELNR").Value;

                // Dates
                XElement delDateElement = iDocElement.Elements("E1EDK03").ToList().Where(c => c.Element("IDDAT").Value.Equals("002")).FirstOrDefault();
                document.deliveryDate = DateTime.ParseExact(delDateElement.Element("DATUM").Value, "yyyyMMdd", CultureInfo.CurrentCulture);

                XElement del2DateElement = iDocElement.Elements("E1EDK03").ToList().Where(c => c.Element("IDDAT").Value.Equals("012")).FirstOrDefault();
                document.docDate = DateTime.ParseExact(del2DateElement.Element("DATUM").Value, "yyyyMMdd", CultureInfo.CurrentCulture);

                XElement del3DateElement = iDocElement.Elements("E1EDK03").ToList().Where(c => c.Element("IDDAT").Value.Equals("025")).FirstOrDefault();
                document.createDate = DateTime.ParseExact(del3DateElement.Element("DATUM").Value, "yyyyMMdd", CultureInfo.CurrentCulture);

                // Sales Order lines
                foreach (var orderLineElement in iDocElement.Elements("E1EDP01").ToList())
                {
                    salesOrderLine line = new salesOrderLine();

                    Int32 lineNum = Convert.ToInt32(orderLineElement.Element("POSEX").Value);

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

                    // Get Item (remove leading zero's)
                    XElement ItemCodeElement = orderLineElement.Elements("E1EDP19").ToList().Where(c => c.Element("QUALF").Value.Equals("002")).FirstOrDefault();

                    String itemCode = RemoveLeadingZeros(ItemCodeElement.Element("IDTNR").Value);
                    String itemName = ItemCodeElement.Element("KTEXT").Value;

                    item item = ItemClass.GetItem(itemCode, companyCode, dc);
                    if (item == null)
                        item = ItemClass.CreateItem(itemCode, itemName, companyCode);

                    line.itemId = item.itemId;
                    line.lineNum = Convert.ToInt32(orderLineElement.Element("POSEX").Value);
                    line.uomCodeOrg = orderLineElement.Element("MENEE").Value;
                    line.price = Convert.ToDecimal(orderLineElement.Element("VPREI").Value, NumberFormatInfo.InvariantInfo);
                    line.itemDescription = itemName;

                    if (orderLineElement.Element("MENGE") != null)
                        line.quantity = Convert.ToDecimal(orderLineElement.Element("MENGE").Value, NumberFormatInfo.InvariantInfo);
                    else
                        line.quantity = 0;

                    if (orderLineElement.Element("NTGEW") != null)
                        line.weight = Convert.ToDecimal(orderLineElement.Element("NTGEW").Value, NumberFormatInfo.InvariantInfo);
                    else
                        line.weight = 0;

                    line.lineTypeCode = orderLineElement.Element("PSTYV").Value;
                    line.lineStatusCode = "O";

                    line.customerReference = String.Empty;
                    line.customerItemCode = String.Empty;

                    XElement customerItemCodeElement = orderLineElement.Elements("E1EDP19").ToList().Where(c => c.Element("QUALF").Value.Equals("001")).FirstOrDefault();
                    if (customerItemCodeElement != null)
                    {
                        XElement customerItemCodeElement2 = customerItemCodeElement.Element("IDTNR");
                        if (customerItemCodeElement2 != null)
                            line.customerItemCode = RemoveLeadingZeros(customerItemCodeElement2.Value);
                    }

                    XElement customerReference = orderLineElement.Elements("E1EDPT1").ToList().Where(c => c.Element("TDID").Value.Equals("0002")).FirstOrDefault();
                    if (customerReference != null)
                    {
                        XElement customerReference2 = customerReference.Element("E1EDPT2");
                        if (customerReference2 != null)
                            line.customerReference = customerReference2.Element("TDLINE") != null ? customerReference2.Element("TDLINE").Value : String.Empty;
                    }

                    // Line is cancelled when field ABGRU is filled
                    var lineStatusElement = orderLineElement.Element("ABGRU"); ;
                    if (lineStatusElement != null)
                        if (!String.IsNullOrWhiteSpace(lineStatusElement.Value))
                            line.lineStatusCode = "C";

                    // ShipDate
                    String deliveryDate = GetSOLineDeliveryDate(orderLineElement);
                    if (!String.IsNullOrEmpty(deliveryDate))
                        line.deliveryDate = DateTime.ParseExact(deliveryDate, "yyyyMMdd", CultureInfo.CurrentCulture);

                    // Certificate as Ordered
                    Boolean certAsOrdered = orderLineElement.Elements("E1EDP02").ToList().Any(c => c.Element("QUALF").Value.Equals("902") && c.Element("BELNR").Value.Equals("ZCPT"));
                    line.certOrdered = certAsOrdered;

                    if (newLine)
                        document.salesOrderLines.Add(line);
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(String.Format("Error converting Sales Order {0} for company {1} from SAP ECC6 XML format. Error: {2}", document.documentNumber, document.companyCode, ex.Message), "ProcessSalesOrder");
                return false;
            }

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

            return true;
        }
Пример #3
0
 partial void UpdatesalesOrderLine(salesOrderLine instance)
 {
     instance.salesOrder.timeStampLastUpdate = DateTime.Now;
     this.ExecuteDynamicUpdate(instance);
 }
Пример #4
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);
        }
Пример #5
0
partial         void InsertsalesOrderLine(salesOrderLine instance)
        {
            instance.docType = "SO";

            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;

            this.ExecuteDynamicInsert(instance);
        }
Пример #6
0
partial         void UpdatesalesOrderLine(salesOrderLine instance)
        {
            instance.salesOrder.timeStampLastUpdate = DateTime.Now;
            this.ExecuteDynamicUpdate(instance);
        }
Пример #7
0
		private void attach_salesOrderLines(salesOrderLine entity)
		{
			this.SendPropertyChanging();
			entity.lineStatus = this;
		}
Пример #8
0
		private void detach_salesOrderLines(salesOrderLine entity)
		{
			this.SendPropertyChanging();
			entity.lineType = null;
		}
Пример #9
0
		private void attach_salesOrderLines(salesOrderLine entity)
		{
			this.SendPropertyChanging();
			entity.document = this;
		}
Пример #10
0
 partial void DeletesalesOrderLine(salesOrderLine instance);
Пример #11
0
 partial void UpdatesalesOrderLine(salesOrderLine instance);
Пример #12
0
 partial void InsertsalesOrderLine(salesOrderLine instance);
Пример #13
0
		private void detach_salesOrderLines(salesOrderLine entity)
		{
			this.SendPropertyChanging();
			entity.unitOfMeasure = null;
		}