Beispiel #1
0
partial         void Insertdelivery(delivery instance)
        {
            instance.timeStampCreated = DateTime.Now;
            instance.docType = "DL";

            this.ExecuteDynamicInsert(instance);
        }
        private static Boolean ProcessBatches(delivery deliveryDocument, List<batch> batches)
        {
            DALPortalDataContext dc = new DALPortalDataContext();
            Boolean returnValue = true;

            // Remove all batches attached to this document
            BatchClass.RemoveBatchesDocument(deliveryDocument.docId, deliveryDocument.docType, dc);

            foreach (batch batchLine in batches)
            {
                try
                {
                    batch batch = BatchClass.GetBatch(batchLine.batchNumber, batchLine.heatNumber, batchLine.itemId, deliveryDocument.companyCode, dc);

                    Boolean newBatch = false;
                    if (batch == null)
                    {
                        batch = new batch();
                        newBatch = true;
                    }

                    if (newBatch)
                    {
                        batch.batchNumber = batchLine.batchNumber;
                        batch.companyCode = deliveryDocument.companyCode;
                    }

                    batch.itemId = batchLine.itemId;
                    batch.certificateIndexNumber = batchLine.certificateIndexNumber;
                    batch.heatNumber = batchLine.heatNumber;
                    batch.ixosArchiveId = batchLine.ixosArchiveId;

                    if (newBatch)
                    {
                        // Check if certificate is already on the server
                        String fileName = "CERT_" + batchLine.ixosArchiveId + ".pdf";
                        String filePath = Path.Combine(Parameters_DataProcessor.CompanyFilesRoot, "Certificates", fileName);
                        String dbPath = Path.Combine(@"~\Files\Certificates", fileName);

                        if (File.Exists(filePath))
                            batch.certificateLink = dbPath;
                    }

                    foreach (batchDocument batchDocLine in batchLine.batchDocuments)
                    {
                        // Check if Batch relates to document
                        batchDocument batchDoc = batch.batchDocuments.Where(c => c.baseDocId.Equals(deliveryDocument.docId) && c.baseLineNum.Equals(batchDocLine.baseLineNum) && c.baseDocType.Equals("DL")).FirstOrDefault();
                        Boolean newBatchDoc = false;
                        if (batchDoc == null)
                        {
                            newBatchDoc = true;
                            batchDoc = new batchDocument();
                            batchDoc.baseDocId = deliveryDocument.docId;
                            batchDoc.baseLineNum = batchDocLine.baseLineNum;
                            batchDoc.baseDocType = "DL";
                        }

                        batchDoc.quantity = batchDocLine.quantity;

                        if (newBatchDoc)
                            batch.batchDocuments.Add(batchDoc);
                    }

                    if (newBatch)
                        dc.batches.InsertOnSubmit(batch);

                    dc.SubmitChanges();
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(String.Format("Error Processing Batches for Delivery {0} for company {1}. Error: {2}", deliveryDocument.documentNumber, deliveryDocument.companyCode, ex.Message), "ProcessBatches");
                    returnValue = false;
                }
            }

            return returnValue;
        }
        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 #4
0
partial         void Updatedelivery(delivery instance)
        {
            instance.timeStampLastUpdate = DateTime.Now;
            this.ExecuteDynamicUpdate(instance);
        }
		private void detach_deliveries(delivery entity)
		{
			this.SendPropertyChanging();
			entity.document = null;
		}
        public Boolean ProcessDataFromXML(String databaseName, String fileContent)
        {
            Boolean returnValue = true;

              try
              {
            // Check xml type

            // SAPECC6
            if (fileContent.Contains("IDOC"))
            {
              businessPartner customer = new businessPartner();
              DALPortalDataContext dc = new DALPortalDataContext();
                    String companyCode;

              //Customer
              if (fileContent.Contains("DEBMAS03"))
              {
            if (!XMLSAPECC6Processor.ProcessCustomer(fileContent, out customer, out companyCode))
              return false;

            CreateUsers(customer, companyCode, dc);
              }
              //SalesOrder
              if (fileContent.Contains("ORDERS05"))
              {
            salesOrder document = new salesOrder();

            if (!XMLSAPECC6Processor.ProcessSalesOrder(fileContent, out document))
              return false;
              }
              //Delivery
              if (fileContent.Contains("DELVRY03"))
              {
            delivery document = new delivery();

            if (!XMLSAPECC6Processor.ProcessDelivery(fileContent, out document))
              return false;
              }

                    //Item
                    if (fileContent.Contains("MATMAS05"))
                    {
                        if (!XMLSAPECC6Processor.ProcessItem(fileContent))
                            return false;
                    }
            }
              }
              catch (Exception ex)
              {
            Trace.WriteLine(String.Format("Process XML file Failed. Error: {0}", ex.Message), "ProcessDataFromXML");
            return false;
              }

              return returnValue;
        }
		private void detach_deliveries(delivery entity)
		{
			this.SendPropertyChanging();
			entity.currency = null;
		}
		private void attach_deliveries(delivery entity)
		{
			this.SendPropertyChanging();
			entity.docStatus = this;
		}
		private void attach_deliveries(delivery entity)
		{
			this.SendPropertyChanging();
			entity.company = this;
		}
		private void detach_deliveries(delivery entity)
		{
			this.SendPropertyChanging();
			entity.businessPartner = null;
		}
 partial void Deletedelivery(delivery instance);
 partial void Updatedelivery(delivery instance);
 partial void Insertdelivery(delivery instance);