예제 #1
0
        // =======================
        // Get Stock Transfer - IN
        // =======================
        public Task GetStockTransferIN(String apiUrlHost, String toBranchCode)
        {
            try
            {
                DateTime dateTimeToday     = DateTime.Now;
                String   stockTransferDate = Convert.ToDateTime(activityDate).ToString("MM-dd-yyyy", CultureInfo.InvariantCulture);

                // ============
                // Http Request
                // ============
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
                var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://" + apiUrlHost + "/api/get/POSIntegration/stockTransferItems/IN/" + stockTransferDate + "/" + toBranchCode);
                httpWebRequest.Method = "GET";
                httpWebRequest.Accept = "application/json";

                // ================
                // Process Response
                // ================
                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                {
                    var result = streamReader.ReadToEnd();
                    JavaScriptSerializer js = new JavaScriptSerializer();
                    List <Entities.ISPOSTrnStockTransfer> stockTransferLists = (List <Entities.ISPOSTrnStockTransfer>)js.Deserialize(result, typeof(List <Entities.ISPOSTrnStockTransfer>));

                    if (stockTransferLists.Any())
                    {
                        foreach (var stockTransfer in stockTransferLists)
                        {
                            var currentStockIn = from d in posdb.TrnStockIns where d.Remarks.Equals("ST-" + stockTransfer.BranchCode + "-" + stockTransfer.STNumber) && d.TrnStockInLines.Count() > 0 && d.IsLocked == true select d;
                            if (!currentStockIn.Any())
                            {
                                trnIntegrationForm.salesIntegrationLogMessages("Saving Stock Transfer (IN): ST-" + stockTransfer.BranchCode + "-" + stockTransfer.STNumber + "\r\n\n");

                                var defaultPeriod   = from d in posdb.MstPeriods select d;
                                var defaultSettings = from d in posdb.SysSettings select d;

                                var lastStockInNumber   = from d in posdb.TrnStockIns.OrderByDescending(d => d.Id) select d;
                                var stockInNumberResult = defaultPeriod.FirstOrDefault().Period + "-000001";

                                if (lastStockInNumber.Any())
                                {
                                    var   stockInNumberSplitStrings = lastStockInNumber.FirstOrDefault().StockInNumber;
                                    Int32 secondIndex = stockInNumberSplitStrings.IndexOf('-', stockInNumberSplitStrings.IndexOf('-'));
                                    var   stockInNumberSplitStringValue = stockInNumberSplitStrings.Substring(secondIndex + 1);
                                    var   stockInNumber = Convert.ToInt32(stockInNumberSplitStringValue) + 000001;
                                    stockInNumberResult = defaultPeriod.FirstOrDefault().Period + "-" + FillLeadingZeroes(stockInNumber, 6);
                                }

                                InnosoftPOSData.TrnStockIn newStockIn = new InnosoftPOSData.TrnStockIn
                                {
                                    PeriodId       = defaultPeriod.FirstOrDefault().Id,
                                    StockInDate    = Convert.ToDateTime(stockTransfer.STDate),
                                    StockInNumber  = stockInNumberResult,
                                    SupplierId     = defaultSettings.FirstOrDefault().PostSupplierId,
                                    Remarks        = "ST-" + stockTransfer.BranchCode + "-" + stockTransfer.STNumber,
                                    IsReturn       = false,
                                    PreparedBy     = defaultSettings.FirstOrDefault().PostUserId,
                                    CheckedBy      = defaultSettings.FirstOrDefault().PostUserId,
                                    ApprovedBy     = defaultSettings.FirstOrDefault().PostUserId,
                                    IsLocked       = true,
                                    EntryUserId    = defaultSettings.FirstOrDefault().PostUserId,
                                    EntryDateTime  = DateTime.Now,
                                    UpdateUserId   = defaultSettings.FirstOrDefault().PostUserId,
                                    UpdateDateTime = DateTime.Now
                                };

                                posdb.TrnStockIns.InsertOnSubmit(newStockIn);
                                posdb.SubmitChanges();

                                if (stockTransfer.ListPOSIntegrationTrnStockTransferItem.Any())
                                {
                                    foreach (var item in stockTransfer.ListPOSIntegrationTrnStockTransferItem.ToList())
                                    {
                                        var currentItem = from d in posdb.MstItems where d.BarCode.Equals(item.ItemCode) && d.MstUnit.Unit.Equals(item.Unit) select d;
                                        if (currentItem.Any())
                                        {
                                            InnosoftPOSData.TrnStockInLine newStockInLine = new InnosoftPOSData.TrnStockInLine
                                            {
                                                StockInId      = newStockIn.Id,
                                                ItemId         = currentItem.FirstOrDefault().Id,
                                                UnitId         = currentItem.FirstOrDefault().UnitId,
                                                Quantity       = item.Quantity,
                                                Cost           = item.Cost,
                                                Amount         = item.Amount,
                                                ExpiryDate     = currentItem.FirstOrDefault().ExpiryDate,
                                                LotNumber      = currentItem.FirstOrDefault().LotNumber,
                                                AssetAccountId = currentItem.FirstOrDefault().AssetAccountId,
                                                Price          = currentItem.FirstOrDefault().Price
                                            };

                                            posdb.TrnStockInLines.InsertOnSubmit(newStockInLine);

                                            var updateItem = currentItem.FirstOrDefault();
                                            updateItem.OnhandQuantity = currentItem.FirstOrDefault().OnhandQuantity + Convert.ToDecimal(item.Quantity);

                                            posdb.SubmitChanges();

                                            trnIntegrationForm.salesIntegrationLogMessages(" > " + currentItem.FirstOrDefault().ItemDescription + " * " + item.Quantity.ToString("#,##0.00") + "\r\n\n");
                                        }
                                    }
                                }

                                trnIntegrationForm.salesIntegrationLogMessages("Save Successful!" + "\r\n\n");
                                trnIntegrationForm.salesIntegrationLogMessages("Time Stamp: " + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss tt") + "\r\n\n");
                                trnIntegrationForm.salesIntegrationLogMessages("\r\n\n");
                            }
                        }
                    }
                }

                return(Task.FromResult(""));
            }
            catch (Exception e)
            {
                trnIntegrationForm.salesIntegrationLogMessages("Stock Transfer (In) Error: " + e.Message + "\r\n\n");
                trnIntegrationForm.salesIntegrationLogMessages("Time Stamp: " + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss tt") + "\r\n\n");
                trnIntegrationForm.salesIntegrationLogMessages("\r\n\n");

                return(Task.FromResult(""));
            }
        }
예제 #2
0
        // ================
        // Get Sales Return
        // ================
        public Task GetSalesReturn(String apiUrlHost, String branchCode, String userCode)
        {
            try
            {
                var stockIns = from d in posdb.TrnStockIns
                               where d.IsReturn == true &&
                               d.CollectionId != null &&
                               d.PostCode == null &&
                               d.IsLocked == true &&
                               d.TrnStockInLines.Any() == true
                               select d;

                if (stockIns.Any())
                {
                    var   stockIn   = stockIns.FirstOrDefault();
                    Int32 stockInId = stockIn.Id;

                    List <Entities.ISPOSTrnCollectionLines> listCollectionLines = new List <Entities.ISPOSTrnCollectionLines>();

                    var stockInLines = from d in stockIn.TrnStockInLines select d;
                    foreach (var stockInLine in stockInLines)
                    {
                        listCollectionLines.Add(new Entities.ISPOSTrnCollectionLines()
                        {
                            ItemManualArticleCode = stockInLine.MstItem.BarCode,
                            Particulars           = stockInLine.MstItem.ItemDescription,
                            Unit               = stockInLine.MstUnit.Unit,
                            Quantity           = stockInLine.Quantity * -1,
                            Price              = stockInLine.Cost,
                            Discount           = "Zero Discount",
                            DiscountAmount     = 0,
                            NetPrice           = stockInLine.Cost,
                            Amount             = (stockInLine.Quantity * -1) * stockInLine.Cost,
                            VAT                = stockInLine.MstItem.MstTax.Tax,
                            SalesItemTimeStamp = DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss.fff", CultureInfo.InvariantCulture)
                        });
                    }

                    var collectionData = new Entities.ISPOSTrnCollection()
                    {
                        SIDate     = stockIn.StockInDate.ToShortDateString(),
                        BranchCode = branchCode,
                        CustomerManualArticleCode = stockIn.TrnCollection.TrnSale.MstCustomer.CustomerCode,
                        CreatedBy         = userCode,
                        Term              = stockIn.TrnCollection.TrnSale.MstTerm.Term,
                        DocumentReference = stockIn.StockInNumber,
                        ManualSINumber    = "IN-" + stockIn.StockInNumber,
                        Remarks           = "Return from Customer, OR-" + stockIn.TrnCollection.CollectionNumber + ", SI-" + stockIn.TrnCollection.TrnSale.SalesNumber,
                        ListPOSIntegrationTrnSalesInvoiceItem = listCollectionLines.ToList()
                    };

                    String json = new JavaScriptSerializer().Serialize(collectionData);

                    trnIntegrationForm.salesIntegrationLogMessages("Sending Sales Return: " + collectionData.ManualSINumber + "\r\n\n");
                    trnIntegrationForm.salesIntegrationLogMessages("Amount: " + collectionData.ListPOSIntegrationTrnSalesInvoiceItem.Sum(d => d.Amount).ToString("#,##0.00") + "\r\n\n");
                    SendSalesReturn(apiUrlHost, json, stockInId);
                }

                return(Task.FromResult(""));
            }
            catch (Exception e)
            {
                trnIntegrationForm.salesIntegrationLogMessages("Sales Return Error: " + e.Message + "\r\n\n");
                trnIntegrationForm.salesIntegrationLogMessages("Time Stamp: " + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss tt") + "\r\n\n");
                trnIntegrationForm.salesIntegrationLogMessages("\r\n\n");

                return(Task.FromResult(""));
            }
        }
        // ==============
        // Get Collection
        // ==============
        public Task GetCollection(String apiUrlHost, String branchCode, String userCode)
        {
            try
            {
                var collections = from d in posdb.TrnCollections
                                  where (d.CollectionNumber != "NA" || d.CollectionNumber != "na") &&
                                  d.SalesId != null &&
                                  d.PostCode == null &&
                                  d.IsLocked == true
                                  select d;

                if (collections.Any())
                {
                    var   collection   = collections.FirstOrDefault();
                    Int32 collectionId = collection.Id;

                    var listPayTypes = new List <String>();
                    if (collection.TrnCollectionLines.Any())
                    {
                        foreach (var collectionLine in collection.TrnCollectionLines)
                        {
                            if (collectionLine.Amount > 0)
                            {
                                listPayTypes.Add(collectionLine.MstPayType.PayType + ": " + collectionLine.Amount.ToString("#,##0.00"));
                            }
                        }
                    }

                    String[] payTypes = listPayTypes.ToArray();
                    List <Entities.ISPOSTrnCollectionLines> listCollectionLines = new List <Entities.ISPOSTrnCollectionLines>();

                    foreach (var salesLine in collection.TrnSale.TrnSalesLines)
                    {
                        listCollectionLines.Add(new Entities.ISPOSTrnCollectionLines()
                        {
                            ItemManualArticleCode = salesLine.MstItem.BarCode,
                            Particulars           = salesLine.MstItem.ItemDescription,
                            Unit               = salesLine.MstUnit.Unit,
                            Quantity           = salesLine.Quantity,
                            Price              = salesLine.Price,
                            Discount           = salesLine.MstDiscount.Discount,
                            DiscountAmount     = salesLine.DiscountAmount,
                            NetPrice           = salesLine.NetPrice,
                            Amount             = salesLine.Amount,
                            VAT                = salesLine.MstTax.Tax,
                            SalesItemTimeStamp = salesLine.SalesLineTimeStamp.ToString("MM/dd/yyyy HH:mm:ss.fff", CultureInfo.InvariantCulture)
                        });
                    }

                    var collectionData = new Entities.ISPOSTrnCollection()
                    {
                        SIDate     = collection.CollectionDate.ToShortDateString(),
                        BranchCode = branchCode,
                        CustomerManualArticleCode = collection.TrnSale.MstCustomer.CustomerCode,
                        CreatedBy         = userCode,
                        Term              = collection.TrnSale.MstTerm.Term,
                        DocumentReference = collection.CollectionNumber,
                        ManualSINumber    = collection.TrnSale.SalesNumber,
                        Remarks           = "User: "******", " + String.Join(", ", payTypes),
                        ListPOSIntegrationTrnSalesInvoiceItem = listCollectionLines.ToList()
                    };

                    String json = new JavaScriptSerializer().Serialize(collectionData);

                    trnIntegrationForm.salesIntegrationLogMessages("Sending Collection: " + collectionData.DocumentReference + "\r\n\n");
                    trnIntegrationForm.salesIntegrationLogMessages("Amount: " + collectionData.ListPOSIntegrationTrnSalesInvoiceItem.Sum(d => d.Amount).ToString("#,##0.00") + "\r\n\n");
                    SendCollection(apiUrlHost, json, collectionId);
                }

                return(Task.FromResult(""));
            }
            catch (Exception e)
            {
                trnIntegrationForm.salesIntegrationLogMessages("Collection Error: " + e.Message + "\r\n\n");
                trnIntegrationForm.salesIntegrationLogMessages("Time Stamp: " + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss tt") + "\r\n\n");
                trnIntegrationForm.salesIntegrationLogMessages("\r\n\n");

                return(Task.FromResult(""));
            }
        }
        // ========
        // Get Item
        // ========
        public Task GetItem(String apiUrlHost)
        {
            try
            {
                DateTime dateTimeToday = DateTime.Now;
                String   currentDate   = Convert.ToDateTime(activityDate).ToString("MM-dd-yyyy", CultureInfo.InvariantCulture);

                // ============
                // Http Request
                // ============
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
                var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://" + apiUrlHost + "/api/get/POSIntegration/item/" + currentDate);
                httpWebRequest.Method = "GET";
                httpWebRequest.Accept = "application/json";

                // ================
                // Process Response
                // ================
                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                {
                    var result = streamReader.ReadToEnd();
                    JavaScriptSerializer         js        = new JavaScriptSerializer();
                    List <Entities.ISPOSMstItem> itemLists = (List <Entities.ISPOSMstItem>)js.Deserialize(result, typeof(List <Entities.ISPOSMstItem>));

                    if (itemLists.Any())
                    {
                        foreach (var item in itemLists)
                        {
                            var units = from d in posdb.MstUnits where d.Unit.Equals(item.Unit) select d;
                            if (units.Any())
                            {
                                var taxes = from d in posdb.MstTaxes where d.Tax.Equals(item.OutputTax) select d;
                                if (taxes.Any())
                                {
                                    var supplier = from d in posdb.MstSuppliers select d;
                                    if (supplier.Any())
                                    {
                                        var defaultSettings = from d in posdb.SysSettings select d;

                                        var currentItem = from d in posdb.MstItems where d.BarCode.Equals(item.ManualArticleCode) && d.MstUnit.Unit.Equals(item.Unit) && d.IsLocked == true select d;
                                        if (currentItem.Any())
                                        {
                                            Boolean foundChanges = false;

                                            if (!foundChanges)
                                            {
                                                if (!currentItem.FirstOrDefault().BarCode.Equals(item.ManualArticleCode))
                                                {
                                                    foundChanges = true;
                                                }
                                            }

                                            if (!foundChanges)
                                            {
                                                if (!currentItem.FirstOrDefault().ItemDescription.Equals(item.Article))
                                                {
                                                    foundChanges = true;
                                                }
                                            }

                                            if (!foundChanges)
                                            {
                                                if (!currentItem.FirstOrDefault().Category.Equals(item.Category))
                                                {
                                                    foundChanges = true;
                                                }
                                            }

                                            if (!foundChanges)
                                            {
                                                if (!currentItem.FirstOrDefault().MstUnit.Unit.Equals(item.Unit))
                                                {
                                                    foundChanges = true;
                                                }
                                            }

                                            if (!defaultSettings.FirstOrDefault().UseItemPrice)
                                            {
                                                if (!foundChanges)
                                                {
                                                    if (currentItem.FirstOrDefault().Price != item.Price)
                                                    {
                                                        foundChanges = true;
                                                    }
                                                }
                                            }

                                            if (!foundChanges)
                                            {
                                                if (currentItem.FirstOrDefault().Cost != item.Cost)
                                                {
                                                    foundChanges = true;
                                                }
                                            }

                                            if (!foundChanges)
                                            {
                                                if (currentItem.FirstOrDefault().IsInventory != item.IsInventory)
                                                {
                                                    foundChanges = true;
                                                }
                                            }

                                            if (!foundChanges)
                                            {
                                                if (currentItem.FirstOrDefault().Remarks != null)
                                                {
                                                    if (!currentItem.FirstOrDefault().Remarks.Equals(item.Particulars))
                                                    {
                                                        foundChanges = true;
                                                    }
                                                }
                                            }

                                            if (!foundChanges)
                                            {
                                                if (currentItem.FirstOrDefault().OutTaxId != taxes.FirstOrDefault().Id)
                                                {
                                                    foundChanges = true;
                                                }
                                            }

                                            if (!defaultSettings.FirstOrDefault().UseItemPrice)
                                            {
                                                if (!foundChanges)
                                                {
                                                    if (item.ListItemPrice.Any())
                                                    {
                                                        var posItemPrices = from d in posdb.MstItemPrices where d.MstItem.BarCode.Equals(item.ManualArticleCode) select d;
                                                        if (posItemPrices.Any())
                                                        {
                                                            if (item.ListItemPrice.Count() == posItemPrices.Count())
                                                            {
                                                                foreach (var itemPrice in item.ListItemPrice)
                                                                {
                                                                    if (!foundChanges)
                                                                    {
                                                                        var currentPOSItemPrices = from d in posItemPrices where d.PriceDescription.Equals(itemPrice.PriceDescription) && d.Price == itemPrice.Price select d;
                                                                        if (!currentPOSItemPrices.Any())
                                                                        {
                                                                            foundChanges = true;
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                            else
                                                            {
                                                                foundChanges = true;
                                                            }
                                                        }
                                                    }
                                                }
                                            }

                                            if (foundChanges)
                                            {
                                                trnIntegrationForm.salesIntegrationLogMessages("Updating Item: " + currentItem.FirstOrDefault().ItemDescription + "\r\n\n");
                                                trnIntegrationForm.salesIntegrationLogMessages("Barcode: " + currentItem.FirstOrDefault().BarCode + "\r\n\n");

                                                var updateItem = currentItem.FirstOrDefault();
                                                updateItem.BarCode         = item.ManualArticleCode;
                                                updateItem.ItemDescription = item.Article;
                                                updateItem.Alias           = item.Article;
                                                updateItem.GenericName     = item.Article;
                                                updateItem.Category        = item.Category;
                                                updateItem.UnitId          = units.FirstOrDefault().Id;
                                                updateItem.Price           = item.Price;
                                                updateItem.Cost            = item.Cost;
                                                updateItem.IsInventory     = item.IsInventory;
                                                updateItem.Remarks         = item.Particulars;
                                                updateItem.OutTaxId        = taxes.FirstOrDefault().Id;
                                                updateItem.UpdateUserId    = defaultSettings.FirstOrDefault().PostUserId;
                                                updateItem.UpdateDateTime  = DateTime.Now;
                                                posdb.SubmitChanges();

                                                if (!defaultSettings.FirstOrDefault().UseItemPrice)
                                                {
                                                    if (item.ListItemPrice.Any())
                                                    {
                                                        var posItemPrices = from d in posdb.MstItemPrices where d.ItemId == currentItem.FirstOrDefault().Id select d;
                                                        if (posItemPrices.Any())
                                                        {
                                                            posdb.MstItemPrices.DeleteAllOnSubmit(posItemPrices);
                                                            posdb.SubmitChanges();
                                                        }

                                                        List <InnosoftPOSData.MstItemPrice> newItemPrice = new List <InnosoftPOSData.MstItemPrice>();
                                                        foreach (var itemPrice in item.ListItemPrice)
                                                        {
                                                            newItemPrice.Add(new InnosoftPOSData.MstItemPrice
                                                            {
                                                                ItemId           = currentItem.FirstOrDefault().Id,
                                                                PriceDescription = itemPrice.PriceDescription,
                                                                Price            = itemPrice.Price,
                                                                TriggerQuantity  = 0
                                                            });
                                                        }

                                                        posdb.MstItemPrices.InsertAllOnSubmit(newItemPrice);
                                                        posdb.SubmitChanges();
                                                    }
                                                }

                                                trnIntegrationForm.salesIntegrationLogMessages("Update Successful!" + "\r\n\n");
                                                trnIntegrationForm.salesIntegrationLogMessages("Time Stamp: " + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss tt") + "\r\n\n");
                                                trnIntegrationForm.salesIntegrationLogMessages("\r\n\n");
                                            }
                                        }
                                        else
                                        {
                                            trnIntegrationForm.salesIntegrationLogMessages("Saving Item: " + item.Article + "\r\n\n");
                                            trnIntegrationForm.salesIntegrationLogMessages("Barcode: " + item.ManualArticleCode + "\r\n\n");

                                            var defaultItemCode = "000001";
                                            var lastItem        = from d in posdb.MstItems.OrderByDescending(d => d.Id) select d;
                                            if (lastItem.Any())
                                            {
                                                var OTNumber = Convert.ToInt32(lastItem.FirstOrDefault().ItemCode) + 000001;
                                                defaultItemCode = FillLeadingZeroes(OTNumber, 6);
                                            }

                                            InnosoftPOSData.MstItem newItem = new InnosoftPOSData.MstItem
                                            {
                                                ItemCode          = defaultItemCode,
                                                BarCode           = item.ManualArticleCode,
                                                ItemDescription   = item.Article,
                                                Alias             = item.Article,
                                                GenericName       = item.Article,
                                                Category          = item.Category,
                                                SalesAccountId    = 159,
                                                AssetAccountId    = 74,
                                                CostAccountId     = 238,
                                                InTaxId           = 4,
                                                OutTaxId          = taxes.FirstOrDefault().Id,
                                                UnitId            = units.FirstOrDefault().Id,
                                                DefaultSupplierId = supplier.FirstOrDefault().Id,
                                                Cost                 = item.Cost,
                                                MarkUp               = 0,
                                                Price                = item.Price,
                                                ImagePath            = "NA",
                                                ReorderQuantity      = 0,
                                                OnhandQuantity       = 0,
                                                IsInventory          = item.IsInventory,
                                                ExpiryDate           = null,
                                                LotNumber            = " ",
                                                Remarks              = item.Particulars,
                                                EntryUserId          = defaultSettings.FirstOrDefault().PostUserId,
                                                EntryDateTime        = DateTime.Now,
                                                UpdateUserId         = defaultSettings.FirstOrDefault().PostUserId,
                                                UpdateDateTime       = DateTime.Now,
                                                IsLocked             = true,
                                                DefaultKitchenReport = " ",
                                                IsPackage            = false
                                            };

                                            posdb.MstItems.InsertOnSubmit(newItem);
                                            posdb.SubmitChanges();

                                            if (item.ListItemPrice.Any())
                                            {
                                                List <InnosoftPOSData.MstItemPrice> newItemPrice = new List <InnosoftPOSData.MstItemPrice>();
                                                foreach (var itemPrice in item.ListItemPrice)
                                                {
                                                    newItemPrice.Add(new InnosoftPOSData.MstItemPrice
                                                    {
                                                        ItemId           = newItem.Id,
                                                        PriceDescription = itemPrice.PriceDescription,
                                                        Price            = itemPrice.Price,
                                                        TriggerQuantity  = 0
                                                    });
                                                }

                                                posdb.MstItemPrices.InsertAllOnSubmit(newItemPrice);
                                                posdb.SubmitChanges();
                                            }

                                            trnIntegrationForm.salesIntegrationLogMessages("Save Successful!" + "\r\n\n");
                                            trnIntegrationForm.salesIntegrationLogMessages("Time Stamp: " + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss tt") + "\r\n\n");
                                            trnIntegrationForm.salesIntegrationLogMessages("\r\n\n");
                                        }
                                    }
                                    else
                                    {
                                        trnIntegrationForm.salesIntegrationLogMessages("Cannot Save Item: " + item.Article + "\r\n\n");
                                        trnIntegrationForm.salesIntegrationLogMessages("Empty Supplier!" + "\r\n\n");
                                        trnIntegrationForm.salesIntegrationLogMessages("Save Failed!" + "\r\n\n");
                                        trnIntegrationForm.salesIntegrationLogMessages("Time Stamp: " + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss tt") + "\r\n\n");
                                        trnIntegrationForm.salesIntegrationLogMessages("\r\n\n");
                                    }
                                }
                                else
                                {
                                    trnIntegrationForm.salesIntegrationLogMessages("Cannot Save Item: " + item.Article + "\r\n\n");
                                    trnIntegrationForm.salesIntegrationLogMessages("Output Tax Mismatch!" + "\r\n\n");
                                    trnIntegrationForm.salesIntegrationLogMessages("Save Failed!" + "\r\n\n");
                                    trnIntegrationForm.salesIntegrationLogMessages("Time Stamp: " + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss tt") + "\r\n\n");
                                    trnIntegrationForm.salesIntegrationLogMessages("\r\n\n");
                                }
                            }
                            else
                            {
                                trnIntegrationForm.salesIntegrationLogMessages("Cannot Save Item: " + item.Article + "\r\n\n");
                                trnIntegrationForm.salesIntegrationLogMessages("Unit Mismatch!" + "\r\n\n");
                                trnIntegrationForm.salesIntegrationLogMessages("Save Failed!" + "\r\n\n");
                                trnIntegrationForm.salesIntegrationLogMessages("Time Stamp: " + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss tt") + "\r\n\n");
                                trnIntegrationForm.salesIntegrationLogMessages("\r\n\n");
                            }
                        }
                    }
                }

                return(Task.FromResult(""));
            }
            catch (Exception e)
            {
                trnIntegrationForm.salesIntegrationLogMessages("Item Error: " + e.Message + "\r\n\n");
                trnIntegrationForm.salesIntegrationLogMessages("Time Stamp: " + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss tt") + "\r\n\n");
                trnIntegrationForm.salesIntegrationLogMessages("\r\n\n");

                return(Task.FromResult(""));
            }
        }
        // ============
        // Get Supplier
        // ============
        public Task GetSupplier(String apiUrlHost)
        {
            try
            {
                DateTime dateTimeToday = DateTime.Now;
                String   currentDate   = Convert.ToDateTime(activityDate).ToString("MM-dd-yyyy", CultureInfo.InvariantCulture);

                // ============
                // Http Request
                // ============
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
                var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://" + apiUrlHost + "/api/get/POSIntegration/supplier/" + currentDate);
                httpWebRequest.Method = "GET";
                httpWebRequest.Accept = "application/json";

                // ================
                // Process Response
                // ================
                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                {
                    var result = streamReader.ReadToEnd();
                    JavaScriptSerializer             js            = new JavaScriptSerializer();
                    List <Entities.ISPOSMstSupplier> supplierLists = (List <Entities.ISPOSMstSupplier>)js.Deserialize(result, typeof(List <Entities.ISPOSMstSupplier>));

                    if (supplierLists.Any())
                    {
                        foreach (var supplier in supplierLists)
                        {
                            var terms = from d in posdb.MstTerms where d.Term.Equals(supplier.Term) select d;
                            if (terms.Any())
                            {
                                var defaultSettings = from d in posdb.SysSettings select d;

                                var currentSupplier = from d in posdb.MstSuppliers where d.Supplier.Equals(supplier.Article) && d.IsLocked == true select d;
                                if (currentSupplier.Any())
                                {
                                    Boolean foundChanges = false;

                                    if (!foundChanges)
                                    {
                                        if (!currentSupplier.FirstOrDefault().Supplier.Equals(supplier.Article))
                                        {
                                            foundChanges = true;
                                        }
                                    }

                                    if (!foundChanges)
                                    {
                                        if (!currentSupplier.FirstOrDefault().Address.Equals(supplier.Address))
                                        {
                                            foundChanges = true;
                                        }
                                    }

                                    if (!foundChanges)
                                    {
                                        if (!currentSupplier.FirstOrDefault().CellphoneNumber.Equals(supplier.ContactNumber))
                                        {
                                            foundChanges = true;
                                        }
                                    }

                                    if (!foundChanges)
                                    {
                                        if (!currentSupplier.FirstOrDefault().MstTerm.Term.Equals(supplier.Term))
                                        {
                                            foundChanges = true;
                                        }
                                    }

                                    if (!foundChanges)
                                    {
                                        if (!currentSupplier.FirstOrDefault().TIN.Equals(supplier.TaxNumber))
                                        {
                                            foundChanges = true;
                                        }
                                    }

                                    if (foundChanges)
                                    {
                                        trnIntegrationForm.salesIntegrationLogMessages("Updating Supplier: " + currentSupplier.FirstOrDefault().Supplier + "\r\n\n");
                                        trnIntegrationForm.salesIntegrationLogMessages("Contact No.: " + currentSupplier.FirstOrDefault().CellphoneNumber + "\r\n\n");

                                        var updateSupplier = currentSupplier.FirstOrDefault();
                                        updateSupplier.Supplier        = supplier.Article;
                                        updateSupplier.Address         = supplier.Address;
                                        updateSupplier.CellphoneNumber = supplier.ContactNumber;
                                        updateSupplier.TermId          = terms.FirstOrDefault().Id;
                                        updateSupplier.TIN             = supplier.TaxNumber;
                                        updateSupplier.UpdateUserId    = defaultSettings.FirstOrDefault().PostUserId;
                                        updateSupplier.UpdateDateTime  = DateTime.Now;
                                        posdb.SubmitChanges();

                                        trnIntegrationForm.salesIntegrationLogMessages("Update Successful!" + "\r\n\n");
                                        trnIntegrationForm.salesIntegrationLogMessages("Time Stamp: " + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss tt") + "\r\n\n");
                                        trnIntegrationForm.salesIntegrationLogMessages("\r\n\n");
                                    }
                                }
                                else
                                {
                                    trnIntegrationForm.salesIntegrationLogMessages("Saving Supplier: " + supplier.Article + "\r\n\n");
                                    trnIntegrationForm.salesIntegrationLogMessages("Contact No.: " + supplier.ContactNumber + "\r\n\n");

                                    InnosoftPOSData.MstSupplier newSupplier = new InnosoftPOSData.MstSupplier
                                    {
                                        Supplier        = supplier.Article,
                                        Address         = supplier.Address,
                                        TelephoneNumber = "NA",
                                        CellphoneNumber = supplier.ContactNumber,
                                        FaxNumber       = "NA",
                                        TermId          = terms.FirstOrDefault().Id,
                                        TIN             = supplier.TaxNumber,
                                        AccountId       = 254,
                                        EntryUserId     = defaultSettings.FirstOrDefault().PostUserId,
                                        EntryDateTime   = DateTime.Now,
                                        UpdateUserId    = defaultSettings.FirstOrDefault().PostUserId,
                                        UpdateDateTime  = DateTime.Now,
                                        IsLocked        = true,
                                    };

                                    posdb.MstSuppliers.InsertOnSubmit(newSupplier);
                                    posdb.SubmitChanges();

                                    trnIntegrationForm.salesIntegrationLogMessages("Save Successful!" + "\r\n\n");
                                    trnIntegrationForm.salesIntegrationLogMessages("Time Stamp: " + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss tt") + "\r\n\n");
                                    trnIntegrationForm.salesIntegrationLogMessages("\r\n\n");
                                }
                            }
                            else
                            {
                                trnIntegrationForm.salesIntegrationLogMessages("Cannot Save Supplier: " + supplier.Article + "\r\n\n");
                                trnIntegrationForm.salesIntegrationLogMessages("Term Mismatch!" + "\r\n\n");
                                trnIntegrationForm.salesIntegrationLogMessages("Save Failed!" + "\r\n\n");
                                trnIntegrationForm.salesIntegrationLogMessages("Time Stamp: " + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss tt") + "\r\n\n");
                                trnIntegrationForm.salesIntegrationLogMessages("\r\n\n");
                            }
                        }
                    }
                }

                return(Task.FromResult(""));
            }
            catch (Exception e)
            {
                trnIntegrationForm.salesIntegrationLogMessages("Supplier Error: " + e.Message + "\r\n\n");
                trnIntegrationForm.salesIntegrationLogMessages("Time Stamp: " + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss tt") + "\r\n\n");
                trnIntegrationForm.salesIntegrationLogMessages("\r\n\n");

                return(Task.FromResult(""));
            }
        }
예제 #6
0
        // ==============
        // Get Item Price
        // ==============
        public Task GetItemPrice(String apiUrlHost, String branchCode)
        {
            try
            {
                DateTime dateTimeToday = DateTime.Now;
                String   currentDate   = Convert.ToDateTime(activityDate).ToString("MM-dd-yyyy", CultureInfo.InvariantCulture);

                // ============
                // Http Request
                // ============
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
                var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://" + apiUrlHost + "/api/get/POSIntegration/itemPrice/" + branchCode + "/" + currentDate);
                httpWebRequest.Method = "GET";
                httpWebRequest.Accept = "application/json";

                // ================
                // Process Response
                // ================
                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                {
                    var result = streamReader.ReadToEnd();
                    JavaScriptSerializer js = new JavaScriptSerializer();
                    List <Entities.ISPOSTrnArticlePrice> itemPriceLists = (List <Entities.ISPOSTrnArticlePrice>)js.Deserialize(result, typeof(List <Entities.ISPOSTrnArticlePrice>));

                    if (itemPriceLists.Any())
                    {
                        foreach (var itemPrice in itemPriceLists)
                        {
                            var currentItem = from d in posdb.MstItems where d.BarCode.Equals(itemPrice.ItemCode) && d.IsLocked == true select d;
                            if (currentItem.Any())
                            {
                                var currentItemPrice = from d in posdb.MstItemPrices where d.ItemId == currentItem.FirstOrDefault().Id&& d.PriceDescription.Equals("IP-" + itemPrice.BranchCode + "-" + itemPrice.IPNumber + " (" + itemPrice.IPDate + ")") select d;
                                if (!currentItemPrice.Any())
                                {
                                    trnIntegrationForm.salesIntegrationLogMessages("Saving Item Price: IP-" + itemPrice.BranchCode + "-" + itemPrice.IPNumber + " (" + itemPrice.IPDate + ")" + "\r\n\n");
                                    trnIntegrationForm.salesIntegrationLogMessages("Current Item: " + currentItem.FirstOrDefault().ItemDescription + "\r\n\n");

                                    InnosoftPOSData.MstItemPrice newPrice = new InnosoftPOSData.MstItemPrice()
                                    {
                                        ItemId           = currentItem.FirstOrDefault().Id,
                                        PriceDescription = "IP-" + itemPrice.BranchCode + "-" + itemPrice.IPNumber + " (" + itemPrice.IPDate + ")",
                                        Price            = itemPrice.Price,
                                        TriggerQuantity  = itemPrice.TriggerQuantity
                                    };

                                    posdb.MstItemPrices.InsertOnSubmit(newPrice);

                                    var updateCurrentItem = currentItem.FirstOrDefault();
                                    updateCurrentItem.Price = itemPrice.Price;
                                    posdb.SubmitChanges();

                                    trnIntegrationForm.salesIntegrationLogMessages("Save Successful!" + "\r\n\n");
                                    trnIntegrationForm.salesIntegrationLogMessages("Time Stamp: " + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss tt") + "\r\n\n");
                                    trnIntegrationForm.salesIntegrationLogMessages("\r\n\n");
                                }
                            }
                            else
                            {
                                trnIntegrationForm.salesIntegrationLogMessages("Cannot Save Item Price: IP-" + itemPrice.BranchCode + "-" + itemPrice.IPNumber + " (" + itemPrice.IPDate + ")" + "..." + "\r\n\n");
                                trnIntegrationForm.salesIntegrationLogMessages("Price: " + itemPrice.Price + "\r\n\n");
                                trnIntegrationForm.salesIntegrationLogMessages("Item Not Found!" + "\r\n\n");
                                trnIntegrationForm.salesIntegrationLogMessages("Time Stamp: " + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss tt") + "\r\n\n");
                                trnIntegrationForm.salesIntegrationLogMessages("\r\n\n");
                            }
                        }
                    }
                }

                return(Task.FromResult(""));
            }
            catch (Exception e)
            {
                trnIntegrationForm.salesIntegrationLogMessages("Item Price Error: " + e.Message + "\r\n\n");
                trnIntegrationForm.salesIntegrationLogMessages("Time Stamp: " + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss tt") + "\r\n\n");
                trnIntegrationForm.salesIntegrationLogMessages("\r\n\n");

                return(Task.FromResult(""));
            }
        }