コード例 #1
0
ファイル: EDI.cs プロジェクト: curt-labs/CURTeCommerce
        internal void ReadAcknowledgement(string editext) {
            List<string> purchaseOrderIDs = new List<string>();
            Cart order = new Cart();
            Settings settings = new Settings();
            string EDIPOPreface = settings.Get("EDIPOPreface");

            List<string> edilines = editext.Split('~').ToList<string>();
            foreach (string line in edilines) {
                List<string> lineelements = line.Split('*').ToList<string>();
                switch (lineelements[0]) {
                    case "AK1":
                        // Original Shipment Number from Shipper
                        string purchaseOrderID = lineelements[2];
                        if (EDIPOPreface != "") {
                            purchaseOrderID = purchaseOrderID.Replace(EDIPOPreface, "");
                        }
                        if(!String.IsNullOrWhiteSpace(purchaseOrderID)) {
                            purchaseOrderIDs.Add(purchaseOrderID);
                        }
                        break;
                }
            }
            foreach(string purchaseOrderID in purchaseOrderIDs) {
                if (!String.IsNullOrWhiteSpace(purchaseOrderID)) {
                    try {
                        order = new Cart().GetByPaymentID(Convert.ToInt32(purchaseOrderID));
                        order.SetStatus((int)OrderStatuses.Processed);
                        OrderEDI edi = new OrderEDI().GetByOrderID(order.ID);
                        if (edi != null && edi.ID > 0) {
                            edi.SetAcknowledged();
                        }
                    } catch { }
                }
            }
        }
コード例 #2
0
ファイル: EDI.cs プロジェクト: curt-labs/CURTeCommerce
 internal void CreateEDIHistory(int id = 0) {
     // if EDI processing is off, this ensures that if it ever gets turned on again,
     // it doesn't attempt to write PO files for every order prior to EDI being available
     try {
         Settings settings = new Settings();
         Cart order = new Cart().Get(id);
         if (order.CartItems.Count > 0) {
             OrderEDI orderedi = new OrderEDI {
                 orderID = order.ID,
                 editext = "",
                 filename = "",
                 dateAcknowledged = DateTime.UtcNow,
                 dateGenerated = DateTime.UtcNow,
             };
             orderedi.Save();
         }
     } catch { };
 }
コード例 #3
0
ファイル: EDI.cs プロジェクト: curt-labs/CURTeCommerce
        internal void CreatePurchaseOrder(int id = 0) {
                try {
                    Settings settings = new Settings();
                    Cart order = new Cart().Get(id);
                    Payment payment = order.getPayment();
                    if (order.CartItems.Count > 0) {
                        Customer cust = new Customer { ID = order.cust_id };
                        cust.Get();
                        order.BindAddresses();
                        string ponumber = settings.Get("EDIPOPreface") + order.payment_id.ToString();
                        CloudBlockBlob blob = null;
                        string edicontent = "";
                        int linecount = 1;
                        // linecount is just for the PO section and doesn't include the head or tail
                        // next two lines are head
                        edicontent += "ISA*00*          *00*          *12*" + settings.Get("EDIPhone") + "     *01*809988975      *" + String.Format("{0:yyMMdd}*{0:hhmm}", payment.created) + "*U*00401*" + order.payment_id.ToString("000000000") + "*0*P*>~" + Environment.NewLine;
                        edicontent += "GS*PO*" + settings.Get("EDIPhone") + "*809988975*" + String.Format("{0:yyyyMMdd}*{0:hhmm}", payment.created) + "*" + order.payment_id.ToString("000000000") + "*X*004010~" + Environment.NewLine;
                        // begin PO section
                        edicontent += "ST*850*000000001~" + Environment.NewLine;
                        linecount++;
                        edicontent += "BEG*00*DS*" + ponumber + "**" + String.Format("{0:yyyyMMdd}", payment.created) + "~" + Environment.NewLine;
                        linecount++;
                        edicontent += "CUR*BT*USD~" + Environment.NewLine;
                        linecount++;
                        edicontent += "REF*CO*" + ponumber + "~" + Environment.NewLine;
                        linecount++;
                        edicontent += "REF*IA*" + settings.Get("CURTAccount") + "~" + Environment.NewLine;
                        linecount++;
                        edicontent += "DTM*002*" + String.Format("{0:yyyyMMdd}", payment.created) + "~" + Environment.NewLine;
                        linecount++;
                        edicontent += "N1*ST*" + order.Shipping.first + " " + order.Shipping.last + "~" + Environment.NewLine;
                        linecount++;
                        edicontent += "N3*" + order.Shipping.street1 + ((order.Shipping.street2 != null && order.Shipping.street2 != "") ? "*" + order.Shipping.street2 : "") + "~" + Environment.NewLine;
                        linecount++;
                        edicontent += "N4*" + order.Shipping.city + "*" + order.Shipping.State1.abbr + "*" + order.Shipping.postal_code + "*" + order.Shipping.State1.Country.longAbbr + "~" + Environment.NewLine;
                        if (!String.IsNullOrEmpty(cust.phone)) {
                            linecount++;
                            edicontent += "PER*BD*" + cust.fname + " " + cust.lname + "*TE*" + cust.phone + "~" + Environment.NewLine;
                        }
                        linecount++;
                        edicontent += "PER*BD*" + cust.fname + " " + cust.lname + "*EM*" + cust.email + "~" + Environment.NewLine;
                        linecount++;
                        edicontent += "TD5**2*FDEG*P*" + order.shipping_type + "~" + Environment.NewLine;
                        for (int i = 0; i < order.CartItems.Count; i++) {
                            linecount++;
                            edicontent += "PO1*" + (i + 1).ToString("000") + "*" + order.CartItems[i].quantity + "*EA***BP*" + order.CartItems[i].partID + "*VP*" + order.CartItems[i].partID + "*UP*" + order.CartItems[i].upc + "~" + Environment.NewLine;
                            linecount++;
                            edicontent += "CTP*PUR*" + String.Format("{0:0.00}", order.CartItems[i].price) + "~" + Environment.NewLine;
                            linecount++;
                            edicontent += "PID*F*08***" + order.CartItems[i].shortDesc + "~" + Environment.NewLine;
                        }
                        linecount++;
                        edicontent += "CTT*" + order.CartItems.Count + "*" + order.getCount() + "~" + Environment.NewLine;
                        linecount++;
                        edicontent += "SE*" + linecount + "*000000001~" + Environment.NewLine;
                        // end PO section
                        // begin Tail section
                        edicontent += "GE*1*" + order.payment_id.ToString("000000000") + "~" + Environment.NewLine;
                        edicontent += "IEA*1*" + order.payment_id.ToString("000000000") + "~";

                        // write file
                        DiscountBlobContainer blobcontainer = BlobManagement.GetContainer("edi");
                        BlobContainerPermissions perms = new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob };
                        blobcontainer.Container.SetPermissions(perms);
                        string filename = "PO" + String.Format("{0:yyyyMMdd}_{0:HHmmss}", payment.created) + ".txt";
                        blob = blobcontainer.Container.GetBlockBlobReference("out\\" + filename);
                        byte[] edibytes = Encoding.ASCII.GetBytes(edicontent);
                        MemoryStream edistream = new MemoryStream(edibytes);
                        blob.UploadFromStream(edistream);
                        OrderEDI orderedi = new OrderEDI {
                            orderID = order.ID,
                            editext = edicontent,
                            filename = filename,
                            dateAcknowledged = null,
                        };
                        orderedi.Save();
                    }
                } catch { };
        }