Пример #1
0
        public void WriteComment()
        {
            JTokenWriter writer = new JTokenWriter();

            writer.WriteStartArray();
            writer.WriteComment("fail");
            writer.WriteEndArray();

            StringAssert.AreEqual(@"[
  /*fail*/]", writer.Token.ToString());
        }
Пример #2
0
        internal static JObject GetCashReceiptsJson()
        {
            AccountingEntities db = new AccountingEntities();

            var receiptList = db.ArCashDepositViews.OrderByDescending(x => x.CreateDate).ToList();


            JTokenWriter pJTokenWriter = new JTokenWriter();
            JObject      ordersJson    = new JObject();

            pJTokenWriter.WriteStartObject();
            pJTokenWriter.WritePropertyName("data");
            pJTokenWriter.WriteStartArray();

            foreach (var item in receiptList)
            {
                pJTokenWriter.WriteStartObject();

                pJTokenWriter.WritePropertyName("ReceiptId");
                pJTokenWriter.WriteValue(item.ReceiptId);

                pJTokenWriter.WritePropertyName("ReceiptCode");
                pJTokenWriter.WriteValue(item.ReceiptCode);

                pJTokenWriter.WritePropertyName("ReceiptDate");
                pJTokenWriter.WriteValue(item.ReceiptDate.ToString("dd/MM/yyyy"));

                pJTokenWriter.WritePropertyName("ReceiptAmount");
                pJTokenWriter.WriteValue(item.ReceiptAmount.ToString() + " " + item.CurrencySign);

                pJTokenWriter.WritePropertyName("Notes");
                pJTokenWriter.WriteValue(item.Notes ?? "");

                pJTokenWriter.WritePropertyName("Client");
                pJTokenWriter.WriteValue(string.IsNullOrEmpty(item.ShipperNameEn) ? item.ConsigneeNameEn : item.ShipperNameEn);

                pJTokenWriter.WritePropertyName("CreateDate");
                pJTokenWriter.WriteValue(item.CreateDate.ToString("dd/MM/yyyy"));

                pJTokenWriter.WritePropertyName("UserName");
                pJTokenWriter.WriteValue(item.UserName);

                pJTokenWriter.WritePropertyName("PaymentTermEn");
                pJTokenWriter.WriteValue(item.PaymentTermEn);

                pJTokenWriter.WriteEndObject();
            }


            pJTokenWriter.WriteEndArray();
            pJTokenWriter.WriteEndObject();
            ordersJson = (JObject)pJTokenWriter.Token;
            return(ordersJson);
        }
Пример #3
0
        public static JObject GetAccTransByAccId(string accId, string fromDate = null, string toDate = null)
        {
            List <AccountSummary>     accSummary = new List <AccountSummary>();
            ReportsAccountingEntities db         = new ReportsAccountingEntities();
            var spResult = db.GetAccountDetailsByAccId(accId, fromDate == "" ? null : fromDate, toDate == "" ? null : toDate).ToList();

            JTokenWriter pJTokenWriter = new JTokenWriter();
            JObject      ordersJson    = new JObject();

            pJTokenWriter.WriteStartObject();
            pJTokenWriter.WritePropertyName("data");
            pJTokenWriter.WriteStartArray();
            foreach (var item in spResult)
            {
                pJTokenWriter.WriteStartObject();
                pJTokenWriter.WritePropertyName("AccountId");
                pJTokenWriter.WriteValue(item.AccountId);

                pJTokenWriter.WritePropertyName("CreateDate");
                pJTokenWriter.WriteValue(item.CreateDate.ToString("dd/MM/yyyy"));

                pJTokenWriter.WritePropertyName("CreateBy");
                pJTokenWriter.WriteValue(item.UserName);

                pJTokenWriter.WritePropertyName("DebitAmount");
                pJTokenWriter.WriteValue(item.DebitAmount);

                pJTokenWriter.WritePropertyName("CreditAmount");
                pJTokenWriter.WriteValue(item.CreditAmount);

                pJTokenWriter.WritePropertyName("CurrencySign");
                pJTokenWriter.WriteValue(item.CurrencySign);

                pJTokenWriter.WritePropertyName("TransactionName");
                pJTokenWriter.WriteValue(item.TransactionName);

                pJTokenWriter.WritePropertyName("TransactionNameAr");
                pJTokenWriter.WriteValue(item.TransactionNameAr);

                pJTokenWriter.WritePropertyName("ReceiptNotes");
                //pJTokenWriter.WriteValue(item.ReceiptNotes);
                pJTokenWriter.WriteValue("");

                pJTokenWriter.WriteEndObject();
            }

            pJTokenWriter.WriteEndArray();
            pJTokenWriter.WriteEndObject();
            ordersJson = (JObject)pJTokenWriter.Token;
            return(ordersJson);
        }
Пример #4
0
        internal static JObject GetCarrierRates(System.Web.Mvc.FormCollection form)
        {
            List <CarrierRateVm> carrRateList = CarrierRateHelper.GetCarrierRatesInquiry(form);

            JTokenWriter pJTokenWriter = new JTokenWriter();
            JObject      ordersJson    = new JObject();

            pJTokenWriter.WriteStartObject();
            pJTokenWriter.WritePropertyName("data");
            pJTokenWriter.WriteStartArray();

            foreach (var item in carrRateList)
            {
                pJTokenWriter.WriteStartObject();

                pJTokenWriter.WritePropertyName("CarrierRateId");
                pJTokenWriter.WriteValue(item.CarrierRateId);

                pJTokenWriter.WritePropertyName("CarrierName");
                pJTokenWriter.WriteValue(item.CarrierName);

                pJTokenWriter.WritePropertyName("ContainerTypeName");
                pJTokenWriter.WriteValue(item.ContainerTypeName);

                pJTokenWriter.WritePropertyName("FromPort");
                pJTokenWriter.WriteValue(item.FromCountryName + " / " + item.FromPortName);

                pJTokenWriter.WritePropertyName("ToPort");
                pJTokenWriter.WriteValue(item.ToCountryName + " / " + item.ToPortName);

                pJTokenWriter.WritePropertyName("FreightCost");
                pJTokenWriter.WriteValue(item.FreightCostAmount + "  " + item.FreighCurrencySign);

                pJTokenWriter.WritePropertyName("ThcCost");
                pJTokenWriter.WriteValue(item.ThcCostAmount + "  " + item.ThcCurrencySign);

                pJTokenWriter.WritePropertyName("ValidToDate");
                pJTokenWriter.WriteValue(item.ValidToDate == null ? "" : item.ValidToDate.Value.ToString("dd/MM/yyyy"));

                pJTokenWriter.WritePropertyName("CarrierId");
                pJTokenWriter.WriteValue(item.CarrierId);

                pJTokenWriter.WriteEndObject();
            }

            pJTokenWriter.WriteEndArray();
            pJTokenWriter.WriteEndObject();
            ordersJson = (JObject)pJTokenWriter.Token;
            return(ordersJson);
        }
Пример #5
0
        public void WriteRawValue()
        {
            JTokenWriter writer = new JTokenWriter();

            writer.WriteStartArray();
            writer.WriteRawValue("fail");
            writer.WriteRawValue("fail");
            writer.WriteEndArray();

            Assert.AreEqual(@"[
  fail,
  fail
]", writer.Token.ToString());
        }
Пример #6
0
        public static JObject StoredProcXMLToJObject(string xml)
        {
            XDocument xmlContent;

            try
            {
                xmlContent = XDocument.Load(new System.IO.StringReader(xml));
            }
            catch (Exception)
            {
                return(new JObject());
            }

            if (xmlContent.ElementExists("NewDataSet"))
            {
                JTokenWriter jWriter = new JTokenWriter();
                jWriter.WriteStartObject();
                int    i         = 0;
                string tableName = "Table";
                while (xmlContent.Element("NewDataSet").ElementExists(tableName))
                {
                    //write a property for each table
                    jWriter.WritePropertyName(tableName);
                    //write an array for each collection of table entities
                    jWriter.WriteStartArray();

                    foreach (XElement item in xmlContent.Element("NewDataSet").Elements(tableName))
                    {
                        jWriter.WriteStartObject();
                        foreach (XElement prop in item.Elements())
                        {
                            jWriter.WritePropertyName(prop.Name.LocalName);
                            jWriter.WriteValue(prop.Value);
                        }
                        jWriter.WriteEndObject();
                    }
                    jWriter.WriteEndArray();

                    i++;
                    tableName = $"Table{i}";
                }

                jWriter.WriteEndObject();

                return((JObject)jWriter.Token);
            }

            return(new JObject());
        }
Пример #7
0
        public void WriteBigInteger()
        {
            JTokenWriter writer = new JTokenWriter();

            writer.WriteStartArray();
            writer.WriteValue(new BigInteger(123));
            writer.WriteEndArray();

            JValue i = (JValue)writer.Token[0];

            Assert.AreEqual(new BigInteger(123), i.Value);
            Assert.AreEqual(JTokenType.Integer, i.Type);

            StringAssert.AreEqual(@"[
  123
]", writer.Token.ToString());
        }
Пример #8
0
        public void WriteRaw()
        {
            JTokenWriter writer = new JTokenWriter();

            writer.WriteStartArray();
            writer.WriteRaw("fail");
            writer.WriteRaw("fail");
            writer.WriteEndArray();

            // this is a bug. write raw shouldn't be autocompleting like this
            // hard to fix without introducing Raw and RawValue token types
            // meh
            Assert.AreEqual(@"[
  fail,
  fail
]", writer.Token.ToString());
        }
Пример #9
0
        public static JArray ForceToArray(this JToken token)
        {
            if (token is JArray)
            {
                return((JArray)token);
            }
            if (token is JObject)
            {
                var writer = new JTokenWriter();
                writer.WriteStartArray();
                writer.WriteToken(new JTokenReader(token));
                writer.WriteEndArray();
                return((JArray)writer.Token);
            }

            throw new ArgumentException("token should be either JArray or JObject", nameof(token));
        }
Пример #10
0
        public static string BuildJson(string Value, bool leaveOpen = true)
        {
            JTokenWriter writer = new JTokenWriter();

            writer.WriteStartObject();
            writer.WritePropertyName("Workflows");
            writer.WriteStartArray();
            writer.WriteStartObject();
            writer.WritePropertyName("FirmID");
            writer.WriteValue(470);
            writer.WritePropertyName("Procedure");
            writer.WriteValue("Accounts.New");
            writer.WritePropertyName("Description");
            writer.WriteValue(Value);
            writer.WritePropertyName("DueDate");
            writer.WriteValue(DateTime.Now.ToUniversalTime());
            writer.WritePropertyName("App");
            writer.WriteValue("Ingestion");
            writer.WritePropertyName("Type");
            writer.WriteValue("Info");
            writer.WritePropertyName("Remediation");
            writer.WriteValue("Feed.Acc.Insert");
            writer.WritePropertyName("ClosedDate");
            if (leaveOpen)
            {
                writer.WriteValue(DateTime.Now.ToUniversalTime());
            }
            else
            {
                writer.WriteValue(string.Empty);
            }
            writer.WritePropertyName("CreateEmail");
            writer.WriteValue("*****@*****.**");
            writer.WritePropertyName("Responsibility");
            writer.WriteValue("Internal.Ops");
            writer.WritePropertyName("Cause");
            writer.WriteValue("Feed.Acc.Created");
            writer.WritePropertyName("Group_UID");
            writer.WriteValue("2CBEF1AC-82C0-4452-B119-A6A18F1BCC41");
            writer.WriteEndObject();
            writer.WriteEndArray();
            writer.WriteEndObject();

            return(writer.Token.ToString());
        }
Пример #11
0
        public void WriteValueTokenWithParent()
        {
            JValue v = new JValue(1);

            JTokenWriter writer = new JTokenWriter();

            writer.WriteStartArray();

            writer.WriteToken(v.CreateReader());

            Assert.AreEqual(WriteState.Array, writer.WriteState);

            writer.WriteEndArray();

            StringAssert.AreEqual(@"[
  1
]", writer.Token.ToString());
        }
Пример #12
0
        public void ValueFormatting()
        {
            byte[] data = Encoding.UTF8.GetBytes("Hello world.");

            JToken root;

            using (JTokenWriter jsonWriter = new JTokenWriter())
            {
                jsonWriter.WriteStartArray();
                jsonWriter.WriteValue('@');
                jsonWriter.WriteValue("\r\n\t\f\b?{\\r\\n\"\'");
                jsonWriter.WriteValue(true);
                jsonWriter.WriteValue(10);
                jsonWriter.WriteValue(10.99);
                jsonWriter.WriteValue(0.99);
                jsonWriter.WriteValue(0.000000000000000001d);
                jsonWriter.WriteValue(0.000000000000000001m);
                jsonWriter.WriteValue((string)null);
                jsonWriter.WriteValue("This is a string.");
                jsonWriter.WriteNull();
                jsonWriter.WriteUndefined();
                jsonWriter.WriteValue(data);
                jsonWriter.WriteEndArray();

                root = jsonWriter.Token;
            }

            CustomAssert.IsInstanceOfType(typeof(JArray), root);
            Assert.AreEqual(13, root.Children().Count());
            Assert.AreEqual("@", (string)root[0]);
            Assert.AreEqual("\r\n\t\f\b?{\\r\\n\"\'", (string)root[1]);
            Assert.AreEqual(true, (bool)root[2]);
            Assert.AreEqual(10, (int)root[3]);
            Assert.AreEqual(10.99, (double)root[4]);
            Assert.AreEqual(0.99, (double)root[5]);
            Assert.AreEqual(0.000000000000000001d, (double)root[6]);
            Assert.AreEqual(0.000000000000000001m, (decimal)root[7]);
            Assert.AreEqual(string.Empty, (string)root[8]);
            Assert.AreEqual("This is a string.", (string)root[9]);
            Assert.AreEqual(null, ((JValue)root[10]).Value);
            Assert.AreEqual(null, ((JValue)root[11]).Value);
            Assert.AreEqual(data, (byte[])root[12]);
        }
Пример #13
0
        public void WriteDuplicatePropertyName()
        {
            JTokenWriter writer = new JTokenWriter();

            writer.WriteStartObject();

            writer.WritePropertyName("prop1");
            writer.WriteStartObject();
            writer.WriteEndObject();

            writer.WritePropertyName("prop1");
            writer.WriteStartArray();
            writer.WriteEndArray();

            writer.WriteEndObject();

            StringAssert.AreEqual(@"{
  ""prop1"": []
}", writer.Token.ToString());
        }
Пример #14
0
        public void WriteEmptyToken()
        {
            JObject    o      = new JObject();
            JsonReader reader = o.CreateReader();

            while (reader.Read())
            {
            }

            JTokenWriter writer = new JTokenWriter();

            writer.WriteStartArray();

            writer.WriteToken(reader);

            Assert.AreEqual(WriteState.Array, writer.WriteState);

            writer.WriteEndArray();

            StringAssert.AreEqual(@"[]", writer.Token.ToString());
        }
        private void SetPostedTransaction(HttpClient http, List <string> lstParameter)
        {
            string metodo         = "api/v1/jobs/Transactions/SetPosted";
            int    page           = 1;
            int    totalPages     = (int)Decimal.Ceiling(lstParameter.Count / 100);
            int    posicaoLista   = 0;
            int    registrosLidos = 1;

            do
            {
                JTokenWriter writerJson = new JTokenWriter();

                writerJson.WriteStartObject();
                writerJson.WritePropertyName("Assignments");
                writerJson.WriteStartArray();

                for (int index = posicaoLista; index < lstParameter.Count; index++)
                {
                    writerJson.WriteStartObject();
                    writerJson.WritePropertyName("TransactionId");
                    writerJson.WriteValue(lstParameter[index]);
                    writerJson.WritePropertyName("PostedDate");
                    writerJson.WriteValue(DateTime.Now.ToString("yyyy-MM-dd'T'HH:mm:sszzz"));
                    writerJson.WriteEndObject();
                    registrosLidos++;
                    if (registrosLidos > 100)
                    {
                        posicaoLista += (registrosLidos - 1);
                        break;
                    }
                }
                writerJson.WriteEndArray();
                writerJson.WriteEndObject();

                JObject json = (JObject)writerJson.Token;
                PostSyncApi(metodo, http, json);
                page++;
            } while (page <= totalPages);
        }
Пример #16
0
        private static object WriteJToken(IEnumerable <List <object> > data, IReadOnlyList <string> headers)
        {
            using (var writer = new JTokenWriter())
            {
                writer.Formatting = Formatting.Indented;
                writer.Culture    = _culture;
                writer.WriteStartArray();
                foreach (var row in data)
                {
                    writer.WriteStartObject();

                    for (var i = 0; i < headers.Count; i++)
                    {
                        writer.WritePropertyName(headers[i]);
                        writer.WriteValue(row[i]);
                    }
                    writer.WriteEndObject();
                }
                writer.WriteEndArray();
                return(writer.Token);
            }
        }
Пример #17
0
        public static JObject GetEmpList(System.Web.Mvc.FormCollection form)
        {
            HREntities   db            = new HREntities();
            var          empListDb     = db.Employees.Include("Department").OrderBy(x => x.EmpNameEn).ToList();
            JTokenWriter pJTokenWriter = new JTokenWriter();
            JObject      ordersJson    = new JObject();

            pJTokenWriter.WriteStartObject();
            pJTokenWriter.WritePropertyName("data");
            pJTokenWriter.WriteStartArray();

            foreach (var item in empListDb)
            {
                pJTokenWriter.WriteStartObject();

                pJTokenWriter.WritePropertyName("EmpId");
                pJTokenWriter.WriteValue(item.EmpId);

                pJTokenWriter.WritePropertyName("EmpCode");
                pJTokenWriter.WriteValue(item.EmpCode);

                pJTokenWriter.WritePropertyName("EmpNameEn");
                pJTokenWriter.WriteValue(item.EmpNameEn);

                pJTokenWriter.WritePropertyName("EmpNameAr");
                pJTokenWriter.WriteValue(item.EmpNameAr);

                pJTokenWriter.WritePropertyName("DepNameEn");
                pJTokenWriter.WriteValue(item.Department.DepNameEn);

                pJTokenWriter.WriteEndObject();
            }
            pJTokenWriter.WriteEndArray();
            pJTokenWriter.WriteEndObject();
            ordersJson = (JObject)pJTokenWriter.Token;
            return(ordersJson);
        }
Пример #18
0
        public void Example()
        {
            #region Usage
            JTokenWriter writer = new JTokenWriter();
            writer.WriteStartObject();
            writer.WritePropertyName("name1");
            writer.WriteValue("value1");
            writer.WritePropertyName("name2");
            writer.WriteStartArray();
            writer.WriteValue(1);
            writer.WriteValue(2);
            writer.WriteEndArray();
            writer.WriteEndObject();

            JObject o = (JObject)writer.Token;

            Console.WriteLine(o.ToString());
            // {
            //   "name1": "value1",
            //   "name2": [
            //     1,
            //     2
            //   ]
            // }
            #endregion

            StringAssert.AreEqual(
                @"{
  ""name1"": ""value1"",
  ""name2"": [
    1,
    2
  ]
}",
                o.ToString()
                );
        }
Пример #19
0
        public static JObject GetAccSummaryByParentAccIdJObj(string parentAccId, bool isCreditAccount = false,
                                                             DateTime?fromDate = null, DateTime?toDate = null, int bId = 0)
        {
            List <AccountSummary> accSummary = GetAccSummaryByParentAccId(parentAccId, isCreditAccount, fromDate, toDate);

            JTokenWriter pJTokenWriter = new JTokenWriter();
            JObject      ordersJson    = new JObject();

            pJTokenWriter.WriteStartObject();
            pJTokenWriter.WritePropertyName("data");
            pJTokenWriter.WriteStartArray();
            List <string> Ids     = new List <string>();
            bool          isFound = false;

            //Cash in Bank .. get for specific bank ID
            if (parentAccId == "193" && bId != 0)
            {
                AccountingEntities db = new AccountingEntities();

                var accIdsForBank = db.BankAccounts.Where(x => x.BankId == bId).Select(x => x.AccountId).ToList();

                accSummary = accSummary.Where(x => accIdsForBank.Contains(x.AccountId)).ToList();
            }

            foreach (var item in accSummary)
            {
                isFound = Ids.FindIndex(s => s == item.AccountId) > -1;
                if (!isFound)
                {
                    Ids.Add(item.AccountId);
                    pJTokenWriter.WriteStartObject();

                    pJTokenWriter.WritePropertyName("AccountId");
                    pJTokenWriter.WriteValue(item.AccountId);

                    pJTokenWriter.WritePropertyName("AccountNameEn");
                    pJTokenWriter.WriteValue(item.AccountNameEn);

                    foreach (string cur in Enum.GetNames(typeof(UsedCurrencies)))
                    {
                        pJTokenWriter.WritePropertyName(cur);
                        // pJTokenWriter.WriteValue(accSummary.Where(x=>x.AccountId == .item.AccountId && x.CurrencySign == cur).FirstOrDefault()?.DiffAmount.ToString("N"));


                        if (accSummary.Where(x => x.AccountId == item.AccountId && x.CurrencySign == cur).FirstOrDefault() != null)
                        {
                            pJTokenWriter.WriteValue(accSummary.Where(x => x.AccountId == item.AccountId && x.CurrencySign == cur).FirstOrDefault().DiffAmount.ToString("N"));
                        }
                        else
                        {
                            pJTokenWriter.WriteValue(0.0.ToString("N"));
                        }
                    }

                    //pJTokenWriter.WritePropertyName("DiffAmount");
                    //pJTokenWriter.WriteValue(item.DiffAmount.ToString("N"));

                    //pJTokenWriter.WritePropertyName("CurrencySign");
                    //pJTokenWriter.WriteValue(item.CurrencySign);

                    pJTokenWriter.WriteEndObject();
                }
            }

            pJTokenWriter.WriteEndArray();
            pJTokenWriter.WriteEndObject();
            ordersJson = (JObject)pJTokenWriter.Token;
            return(ordersJson);
        }
Пример #20
0
        /// <summary>
        /// Get all actions done by the patners drawing and payments from cash tables
        /// </summary>
        /// <param name="form">Advanced search</param>
        /// <returns>json to fill jquery datatable</returns>
        internal static JObject GetPartnersDrawingJson(System.Web.Mvc.FormCollection form)
        {
            AccountingEntities db = new AccountingEntities();
            //Get Only cash out receipts for expenses
            var cashoutReceiptIds = db.CashOutReceipts.Where(x => x.PartnerAccountId != string.Empty)
                                    .Select(x => x.ReceiptId).Distinct();

            var cashinReceiptIds = db.CashInReceipts.Where(x => x.PartnerAccountId != string.Empty)
                                   .Select(x => x.ReceiptId).Distinct();


            var cashtReceiptList = (from c in db.CashOutReceipts
                                    join u in db.AspNetUserAccs
                                    on c.CreateBy equals u.Id
                                    join cu in db.CurrencyAccs
                                    on c.CurrencyId equals cu.CurrencyId
                                    join ch in db.AccountingCharts
                                    on c.PartnerAccountId equals ch.AccountId
                                    where cashoutReceiptIds.Contains(c.ReceiptId) && c.IsDeleted == false
                                    select new TempList
            {
                ReceiptId = c.ReceiptId,
                ReceiptDate = c.ReceiptDate,
                ReceiptCode = c.ReceiptCode,
                ReceiptAmount = c.ReceiptAmount,
                Notes = c.Notes,
                CreateDate = c.CreateDate,
                CreateBy = c.CreateBy,
                CurrencySign = cu.CurrencySign,
                UserName = u.UserName,
                AccountNameEn = ch.AccountNameEn,
                ReceiptType = "Cash Out"
            }).ToList();

            var cashinReceiptList = (from c in db.CashInReceipts
                                     join u in db.AspNetUserAccs
                                     on c.CreateBy equals u.Id
                                     join cu in db.CurrencyAccs
                                     on c.CurrencyId equals cu.CurrencyId
                                     join ch in db.AccountingCharts
                                     on c.PartnerAccountId equals ch.AccountId
                                     where cashinReceiptIds.Contains(c.ReceiptId) && c.IsDeleted == false
                                     select new TempList
            {
                ReceiptId = c.ReceiptId,
                ReceiptDate = c.ReceiptDate,
                ReceiptCode = c.ReceiptCode,
                ReceiptAmount = c.ReceiptAmount,
                Notes = c.Notes,
                CreateDate = c.CreateDate,
                CreateBy = c.CreateBy,
                CurrencySign = cu.CurrencySign,
                UserName = u.UserName,
                AccountNameEn = ch.AccountNameEn,
                ReceiptType = "Cash In"
            }).ToList();

            cashtReceiptList.AddRange(cashinReceiptList);

            if (!string.IsNullOrEmpty(form["ReceiptDateStart"]))
            {
                DateTime date = DateTime.Parse(form["ReceiptDateStart"]);
                cashtReceiptList = cashtReceiptList.Where(x => x.ReceiptDate >= date).ToList();
            }

            if (!string.IsNullOrEmpty(form["ReceiptDateEnd"]))
            {
                DateTime date = DateTime.Parse(form["ReceiptDateEnd"]);
                cashtReceiptList = cashtReceiptList.Where(x => x.ReceiptDate <= date).ToList();
            }

            if (!string.IsNullOrEmpty(form["CreateDateStart"]))
            {
                DateTime date = DateTime.Parse(form["CreateDateStart"]);
                cashtReceiptList = cashtReceiptList.Where(x => x.CreateDate >= date).ToList();
            }

            if (!string.IsNullOrEmpty(form["CreateDateEnd"]))
            {
                DateTime date = DateTime.Parse(form["CreateDateEnd"]);
                cashtReceiptList = cashtReceiptList.Where(x => x.CreateDate <= date).ToList();
            }

            JTokenWriter pJTokenWriter = new JTokenWriter();
            JObject      ordersJson    = new JObject();

            pJTokenWriter.WriteStartObject();
            pJTokenWriter.WritePropertyName("data");
            pJTokenWriter.WriteStartArray();

            foreach (var item in cashtReceiptList)
            {
                pJTokenWriter.WriteStartObject();

                pJTokenWriter.WritePropertyName("ReceiptId");
                pJTokenWriter.WriteValue(item.ReceiptId);

                pJTokenWriter.WritePropertyName("ReceiptCode");
                pJTokenWriter.WriteValue(item.ReceiptCode);

                pJTokenWriter.WritePropertyName("ReceiptDate");
                pJTokenWriter.WriteValue(item.ReceiptDate.ToString("dd/MM/yyyy"));

                pJTokenWriter.WritePropertyName("ReceiptAmount");
                pJTokenWriter.WriteValue(item.ReceiptAmount.ToString() + " " + item.CurrencySign);

                pJTokenWriter.WritePropertyName("Notes");
                pJTokenWriter.WriteValue(item.Notes);

                pJTokenWriter.WritePropertyName("CreateDate");
                pJTokenWriter.WriteValue(item.CreateDate.ToString("dd/MM/yyyy"));

                pJTokenWriter.WritePropertyName("UserName");
                pJTokenWriter.WriteValue(item.UserName);

                pJTokenWriter.WritePropertyName("AccountNameEn");
                pJTokenWriter.WriteValue(item.AccountNameEn);

                pJTokenWriter.WritePropertyName("ReceiptType");
                pJTokenWriter.WriteValue(item.ReceiptType);

                pJTokenWriter.WritePropertyName("ReceiptTypeShort");
                if (item.ReceiptType == "Cash In")
                {
                    pJTokenWriter.WriteValue("in");
                }
                else
                {
                    pJTokenWriter.WriteValue("out");
                }


                pJTokenWriter.WriteEndObject();
            }

            pJTokenWriter.WriteEndArray();
            pJTokenWriter.WriteEndObject();
            ordersJson = (JObject)pJTokenWriter.Token;
            return(ordersJson);
        }
Пример #21
0
        public IActionResult ImportProjectAjax(string method)
        {
            var result  = false;
            var message = "";
            var array   = new JTokenWriter();

            array.WriteStartArray();

            try
            {
                switch (method)
                {
                case "gitlab":
                    var gitlabImportRequest = new GitlabImportRequest(Request);
                    if (string.IsNullOrWhiteSpace(gitlabImportRequest.GroupName))
                    {
                        throw new ImportRequestException("Missing group name");
                    }
                    if (string.IsNullOrWhiteSpace(gitlabImportRequest.PrivateToken))
                    {
                        throw new ImportRequestException("Missing private token");
                    }

                    var client = new RestClient("https://gitlab.com/api/v4/");

                    client.DefaultParameters.Add(new Parameter("private_token", gitlabImportRequest.PrivateToken, ParameterType.QueryString));

                    int       itemsCount = -1;
                    int       page       = 1;
                    const int perPage    = 100;
                    int       itemsAdded = 0;
                    do
                    {
                        var request = new RestRequest("groups/{username}/projects", Method.GET, DataFormat.Json);

                        request.Parameters.Add(new Parameter("username", gitlabImportRequest.GroupName, ParameterType.UrlSegment));
                        request.Parameters.Add(new Parameter("per_page", perPage, ParameterType.QueryString));
                        request.Parameters.Add(new Parameter("page", page++, ParameterType.QueryString));

                        var response = client.Execute(request);

                        var json = response.Content;

                        var projects = (JToken)JsonConvert.DeserializeObject(json);

                        if (!(projects is JArray))
                        {
                            throw new ImportRequestException("Unexpected response from server");
                        }

                        var projectsArray = (JArray)projects;

                        foreach (var project in projectsArray)
                        {
                            array.WriteStartObject();

                            array.WritePropertyName("name");
                            var name = project.Value <string>("name");
                            array.WriteValue(name);

                            array.WritePropertyName("url");
                            var url = project.Value <string>("http_url_to_repo");
                            array.WriteValue(url);

                            array.WritePropertyName("added");
                            array.WriteValue(mainService.ProjectExists(name, url));

                            array.WriteEndObject();

                            itemsAdded++;
                        }
                    } while (itemsCount == perPage);

                    message = $"{itemsAdded} projects fetched";
                    result  = true;
                    break;

                default:
                    throw new ImportRequestException("Unknown provider: " + method);
                }
            }
            catch (ImportRequestException ex)
            {
                result  = false;
                message = ex.Message;
            }
            catch (Exception ex)
            {
                result  = false;
                message = "Unexpected exception: " + ex.Message;
            }

            var writer = new JTokenWriter();

            array.WriteEndArray();

            writer.WriteStartObject();

            writer.WritePropertyName("status");
            writer.WriteValue(result ? "OK" : "ERROR");

            writer.WritePropertyName("message");
            writer.WriteValue(message);

            writer.WritePropertyName("projects");
            writer.WriteToken(new JTokenReader(array.Token));

            writer.WriteEndObject();

            var content = writer.Token.ToString(Program.Debug ? Formatting.Indented : Formatting.None);

            return(Content(content, "text/javascript"));
        }
Пример #22
0
        internal static JObject GetAPChecksListJson(System.Web.Mvc.FormCollection form)
        {
            AccountingEntities db = new AccountingEntities();

            var checkDbList = db.CashOutReceiptViews
                              .Where(x => !string.IsNullOrEmpty(x.CheckNumber) && x.IsDeleted == false)
                              .Select(x => new
            {
                x.ReceiptId,
                x.CheckNumber,
                x.CheckDueDate,
                x.CarrierId,
                x.CarrierNameEn,
                x.ContractorId,
                x.ContractorNameEn,
                x.IsCollected,
                x.ReceiptCode,
                x.ReceiptDate,
                x.ReceiptAmount,
                x.CurrencySign,
                x.AgentId,
                x.AgentNameEn
            })
                              .ToList();

            if (form != null)
            {
                //filter data here
            }

            JTokenWriter pJTokenWriter = new JTokenWriter();
            JObject      ordersJson    = new JObject();

            pJTokenWriter.WriteStartObject();
            pJTokenWriter.WritePropertyName("data");
            pJTokenWriter.WriteStartArray();

            foreach (var item in checkDbList)
            {
                pJTokenWriter.WriteStartObject();

                pJTokenWriter.WritePropertyName("ReceiptId");
                pJTokenWriter.WriteValue(item.ReceiptId);

                pJTokenWriter.WritePropertyName("CheckNumber");
                pJTokenWriter.WriteValue(item.CheckNumber);

                pJTokenWriter.WritePropertyName("CheckDueDate");
                pJTokenWriter.WriteValue(item.CheckDueDate.ToString("dd/MM/yyyy"));


                if (item.IsCollected)
                {
                    pJTokenWriter.WritePropertyName("IsPaid");
                    pJTokenWriter.WriteValue("Paid");

                    pJTokenWriter.WritePropertyName("Status");
                    pJTokenWriter.WriteValue("1");
                }

                else
                {
                    pJTokenWriter.WritePropertyName("IsPaid");
                    pJTokenWriter.WriteValue("Not Paids");

                    pJTokenWriter.WritePropertyName("Status");
                    pJTokenWriter.WriteValue("0");
                }


                pJTokenWriter.WritePropertyName("ReceiptCode");
                pJTokenWriter.WriteValue(item.ReceiptCode);

                pJTokenWriter.WritePropertyName("ReceiptDate");
                pJTokenWriter.WriteValue(item.ReceiptDate.ToString("dd/MM/yyyy"));

                pJTokenWriter.WritePropertyName("CustomerName");

                if (item.CarrierId != null && item.CarrierId != 0)
                {
                    pJTokenWriter.WriteValue(item.CarrierNameEn);
                }
                else if (item.ContractorId != null && item.ContractorId != 0)
                {
                    pJTokenWriter.WriteValue(item.ContractorNameEn);
                }
                else if (item.AgentId != null && item.AgentId != 0)
                {
                    pJTokenWriter.WriteValue(item.AgentNameEn);
                }
                else
                {
                    pJTokenWriter.WriteValue("");
                }


                pJTokenWriter.WritePropertyName("ReceiptAmount");
                pJTokenWriter.WriteValue(item.ReceiptAmount + " (" + item.CurrencySign + ")");

                pJTokenWriter.WritePropertyName("CurrencySign");
                pJTokenWriter.WriteValue(item.CurrencySign);


                pJTokenWriter.WriteEndObject();
            }

            pJTokenWriter.WriteEndArray();
            pJTokenWriter.WriteEndObject();
            ordersJson = (JObject)pJTokenWriter.Token;
            return(ordersJson);
        }
Пример #23
0
        internal static JObject GetExpensesCashOutJson(System.Web.Mvc.FormCollection form)
        {
            AccountingEntities db = new AccountingEntities();
            //Get Only cash out receipts for expenses
            var receiptIds = db.CashOutReceiptExpenses.Select(x => x.ReceiptId).Distinct();


            var receiptList = (from c in db.CashOutReceipts
                               join u in db.AspNetUserAccs
                               on c.CreateBy equals u.Id
                               join cu in db.CurrencyAccs
                               on c.CurrencyId equals cu.CurrencyId
                               where receiptIds.Contains(c.ReceiptId) && c.IsDeleted == false
                               select new
            {
                c.ReceiptId,
                c.ReceiptDate,
                c.ReceiptCode,
                c.ReceiptAmount,
                c.Notes,
                c.CreateDate,
                c.CreateBy,
                cu.CurrencySign,
                u.UserName
            }).ToList();

            if (!string.IsNullOrEmpty(form["ReceiptDateStart"]))
            {
                DateTime date = DateTime.Parse(form["ReceiptDateStart"]);
                receiptList = receiptList.Where(x => x.ReceiptDate >= date).ToList();
            }

            if (!string.IsNullOrEmpty(form["ReceiptDateEnd"]))
            {
                DateTime date = DateTime.Parse(form["ReceiptDateEnd"]);
                receiptList = receiptList.Where(x => x.ReceiptDate <= date).ToList();
            }

            if (!string.IsNullOrEmpty(form["CreateDateStart"]))
            {
                DateTime date = DateTime.Parse(form["CreateDateStart"]);
                receiptList = receiptList.Where(x => x.CreateDate >= date).ToList();
            }

            if (!string.IsNullOrEmpty(form["CreateDateEnd"]))
            {
                DateTime date = DateTime.Parse(form["CreateDateEnd"]);
                receiptList = receiptList.Where(x => x.CreateDate <= date).ToList();
            }

            JTokenWriter pJTokenWriter = new JTokenWriter();
            JObject      ordersJson    = new JObject();

            pJTokenWriter.WriteStartObject();
            pJTokenWriter.WritePropertyName("data");
            pJTokenWriter.WriteStartArray();

            foreach (var item in receiptList)
            {
                pJTokenWriter.WriteStartObject();

                pJTokenWriter.WritePropertyName("ReceiptId");
                pJTokenWriter.WriteValue(item.ReceiptId);

                pJTokenWriter.WritePropertyName("ReceiptCode");
                pJTokenWriter.WriteValue(item.ReceiptCode);

                pJTokenWriter.WritePropertyName("ReceiptDate");
                pJTokenWriter.WriteValue(item.ReceiptDate.ToString("dd/MM/yyyy"));

                pJTokenWriter.WritePropertyName("ReceiptAmount");
                pJTokenWriter.WriteValue(item.ReceiptAmount.ToString() + " " + item.CurrencySign);

                pJTokenWriter.WritePropertyName("Notes");
                pJTokenWriter.WriteValue(item.Notes);

                pJTokenWriter.WritePropertyName("CreateDate");
                pJTokenWriter.WriteValue(item.CreateDate.ToString("dd/MM/yyyy"));

                pJTokenWriter.WritePropertyName("UserName");
                pJTokenWriter.WriteValue(item.UserName);

                pJTokenWriter.WriteEndObject();
            }

            pJTokenWriter.WriteEndArray();
            pJTokenWriter.WriteEndObject();
            ordersJson = (JObject)pJTokenWriter.Token;
            return(ordersJson);
        }
Пример #24
0
        internal static JObject GetInvListJson(System.Web.Mvc.FormCollection form)
        {
            AccountingEntities db        = new AccountingEntities();
            InvoiceView        invViewDb = new InvoiceView();

            string where = CommonHelper.AdvancedSearch <InvoiceView>(form, invViewDb);
            if (string.IsNullOrEmpty(where))
            {
                where = "1 = 1"; //instead of make if condition
            }
            where = where + " and IsDeleted = null ";

            var invoiceList = db.InvoiceViews.Where(where.ToString()).ToList();

            List <int> invIds    = invoiceList.Select(x => x.InvoiceId).ToList();
            var        cashInvDb = db.CashInReceiptInvs
                                   .Where(x => invIds.Contains(x.InvoiceId))
                                   .GroupBy(x => x.InvoiceId)
                                   .ToList();
            decimal      collectedAmount, amountDue;
            JTokenWriter pJTokenWriter = new JTokenWriter();
            JObject      ordersJson    = new JObject();

            pJTokenWriter.WriteStartObject();
            pJTokenWriter.WritePropertyName("data");
            pJTokenWriter.WriteStartArray();
            foreach (var item in invoiceList)
            {
                pJTokenWriter.WriteStartObject();

                pJTokenWriter.WritePropertyName("InvoiceId");
                pJTokenWriter.WriteValue(item.InvoiceId);

                pJTokenWriter.WritePropertyName("HouseBillId");
                pJTokenWriter.WriteValue(item.HouseBillId);

                pJTokenWriter.WritePropertyName("InvoiceCode");
                pJTokenWriter.WriteValue(item.InvoiceCode);

                pJTokenWriter.WritePropertyName("DueDate");
                pJTokenWriter.WriteValue(item.DueDate.Value.ToString("dd/MM/yyyy"));

                pJTokenWriter.WritePropertyName("InvoiceDate");
                pJTokenWriter.WriteValue(item.InvoiceDate.ToString("dd/MM/yyyy"));

                switch (item.OrderFrom)
                {
                case 1:
                    pJTokenWriter.WritePropertyName("OrderFromImg");
                    pJTokenWriter.WriteValue("<i class='fa fa-level-up'></i>");

                    pJTokenWriter.WritePropertyName("ClientName");
                    pJTokenWriter.WriteValue(item.ShipperNameEn);
                    break;

                case 2:
                    pJTokenWriter.WritePropertyName("OrderFromImg");
                    pJTokenWriter.WriteValue("<i class='fa fa-level-down'></i>");

                    pJTokenWriter.WritePropertyName("ClientName");
                    pJTokenWriter.WriteValue(item.ConsigneeNameEn);
                    break;
                }

                pJTokenWriter.WritePropertyName("OperationCode");
                pJTokenWriter.WriteValue(item.OperationCode);

                pJTokenWriter.WritePropertyName("HouseBL");
                pJTokenWriter.WriteValue(item.HouseBL);



                pJTokenWriter.WritePropertyName("TotalAmount");
                pJTokenWriter.WriteValue(item.TotalAmount + " (" + item.CurrencySign + ")");

                collectedAmount = cashInvDb.Where(x => x.Key == item.InvoiceId)
                                  .Select(x => x.Sum(y => y.PaidAmount)).FirstOrDefault();
                amountDue = item.TotalAmount - collectedAmount;


                pJTokenWriter.WritePropertyName("AmountDue"); //Modify this after make payment
                pJTokenWriter.WriteValue(amountDue + " (" + item.CurrencySign + ")");

                pJTokenWriter.WritePropertyName("InvStatusId");
                pJTokenWriter.WriteValue(item.InvStatusId);

                pJTokenWriter.WritePropertyName("InvStatusName");
                pJTokenWriter.WriteValue(item.InvStatusNameEn.Replace("Paid", "Collected"));

                pJTokenWriter.WriteEndObject();
            }

            pJTokenWriter.WriteEndArray();
            pJTokenWriter.WriteEndObject();
            ordersJson = (JObject)pJTokenWriter.Token;
            return(ordersJson);
        }
Пример #25
0
        public static JObject GetAllAgentsByCountry(int countryId = 0)
        {
            EasyFreightEntities db = new EasyFreightEntities();



            var selectedAgents = db.Agents.Include("Countries").Where(c => c.CountryId == (countryId > 0 ? countryId : c.CountryId))
                                 .Select(x => new
            {
                x.AgentAddressEn,
                x.AgentCode,
                x.AgentId,
                x.AgentNameEn,
                x.Country.CountryNameEn,
                x.CountryId,
                x.Email,
                x.FaxNumber,
                x.PhoneNumber,
                x.WebSite
            }).ToList();



            JTokenWriter pJTokenWriter = new JTokenWriter();
            JObject      ordersJson    = new JObject();

            pJTokenWriter.WriteStartObject();
            pJTokenWriter.WritePropertyName("data");
            pJTokenWriter.WriteStartArray();
            foreach (var item in selectedAgents)
            {
                pJTokenWriter.WriteStartObject();
                pJTokenWriter.WritePropertyName("AgentCode");
                pJTokenWriter.WriteValue(item.AgentCode);

                pJTokenWriter.WritePropertyName("AgentAddressEn");
                pJTokenWriter.WriteValue(item.AgentAddressEn);

                pJTokenWriter.WritePropertyName("AgentNameEn");
                pJTokenWriter.WriteValue(item.AgentNameEn);



                pJTokenWriter.WritePropertyName("Country");
                pJTokenWriter.WriteValue(item.CountryNameEn);

                pJTokenWriter.WritePropertyName("CountryId");
                pJTokenWriter.WriteValue(item.CountryId);

                pJTokenWriter.WritePropertyName("Email");
                pJTokenWriter.WriteValue(item.Email);

                pJTokenWriter.WritePropertyName("FaxNumber");
                pJTokenWriter.WriteValue(item.FaxNumber);

                pJTokenWriter.WritePropertyName("PhoneNumber");
                pJTokenWriter.WriteValue(item.PhoneNumber);

                pJTokenWriter.WritePropertyName("WebSite");
                pJTokenWriter.WriteValue(item.WebSite);

                pJTokenWriter.WriteEndObject();
            }

            pJTokenWriter.WriteEndArray();
            pJTokenWriter.WriteEndObject();
            ordersJson = (JObject)pJTokenWriter.Token;
            return(ordersJson);
        }
Пример #26
0
        public static JObject GetOperationsCountLineChart(int year = 0)
        {
            OperationsEntities db = new OperationsEntities();
            var serviceUsageList  = db.Operations
                                    .Where(x => x.StatusId != 4).Select(x => new { x.OperationDate, x.CreateDate }).ToList();

            if (year == 0)
            {
                year = DateTime.Now.Year;
            }

            int[] monthsNums = serviceUsageList.Where(x => x.OperationDate.Year == year)
                               .Select(X => X.OperationDate.Month).Distinct().OrderBy(x => x).ToArray();

            JTokenWriter pJTokenWriter = new JTokenWriter();
            JObject      ordersJson    = new JObject();

            pJTokenWriter.WriteStartObject();
            pJTokenWriter.WritePropertyName("labels");
            pJTokenWriter.WriteStartArray();
            // pJTokenWriter.WriteValue(minDate.ToString("dd/MM/yyyy"));

            for (int i = 0; i < monthsNums.Length; i++)
            {
                pJTokenWriter.WriteValue(((MonthNameEnum)monthsNums[i]).ToString());
            }

            pJTokenWriter.WriteEndArray();

            pJTokenWriter.WritePropertyName("datasets");
            pJTokenWriter.WriteStartArray();  //datasets array
            pJTokenWriter.WriteStartObject(); //datasets Object

            pJTokenWriter.WritePropertyName("label");
            pJTokenWriter.WriteValue(" عدد العمليات");
            pJTokenWriter.WritePropertyName("fill");
            pJTokenWriter.WriteValue(false);
            pJTokenWriter.WritePropertyName("lineTension");
            pJTokenWriter.WriteValue(0.1);
            pJTokenWriter.WritePropertyName("backgroundColor");
            pJTokenWriter.WriteValue("rgba(75,192,192,0.4)");
            pJTokenWriter.WritePropertyName("borderColor");
            pJTokenWriter.WriteValue("rgba(75,192,192,1)");
            pJTokenWriter.WritePropertyName("borderCapStyle");
            pJTokenWriter.WriteValue("butt");
            //pJTokenWriter.WritePropertyName("borderDash");
            //pJTokenWriter.WriteValue([]);
            pJTokenWriter.WritePropertyName("borderDashOffset");
            pJTokenWriter.WriteValue(0.0);
            pJTokenWriter.WritePropertyName("borderJoinStyle");
            pJTokenWriter.WriteValue("miter");
            pJTokenWriter.WritePropertyName("pointBorderColor");
            pJTokenWriter.WriteValue("rgba(75,192,192,1)");
            pJTokenWriter.WritePropertyName("pointBackgroundColor");
            pJTokenWriter.WriteValue("#fff");
            pJTokenWriter.WritePropertyName("pointBorderWidth");
            pJTokenWriter.WriteValue(1);
            pJTokenWriter.WritePropertyName("pointHoverRadius");
            pJTokenWriter.WriteValue(5);
            pJTokenWriter.WritePropertyName("pointHoverBackgroundColor");
            pJTokenWriter.WriteValue("rgba(75,192,192,1)");
            pJTokenWriter.WritePropertyName("pointHoverBorderColor");
            pJTokenWriter.WriteValue("rgba(220,220,220,1)");
            pJTokenWriter.WritePropertyName("pointHoverBorderWidth");
            pJTokenWriter.WriteValue(2);
            pJTokenWriter.WritePropertyName("pointRadius");
            pJTokenWriter.WriteValue(1);
            pJTokenWriter.WritePropertyName("pointHitRadius");
            pJTokenWriter.WriteValue(10);
            pJTokenWriter.WritePropertyName("spanGaps");
            pJTokenWriter.WriteValue(false);

            pJTokenWriter.WritePropertyName("data");
            pJTokenWriter.WriteStartArray();
            int count;

            for (int i = 0; i < monthsNums.Length; i++)
            {
                count = serviceUsageList
                        .Where(x => x.OperationDate.Month == monthsNums[i] && x.OperationDate.Year == DateTime.Now.Year).Count();

                pJTokenWriter.WriteValue(count);
            }


            pJTokenWriter.WriteEndArray();

            pJTokenWriter.WriteEndObject(); //datasets Object
            pJTokenWriter.WriteEndArray();  //datasets array

            pJTokenWriter.WriteEndObject();
            ordersJson = (JObject)pJTokenWriter.Token;
            return(ordersJson);
        }
Пример #27
0
        public static JObject GetOperationOrders(FormCollection form)
        {
            OperationsEntities db = new OperationsEntities();

            OperationView oprObj = new OperationView();

            string where = CommonHelper.AdvancedSearch <OperationView>(form, oprObj);
            var operationList = db.OperationViews.Where(where.ToString())
                                .Select(x => new
            {
                x.OperationId,
                x.CarrierType,
                x.QuoteId,
                x.CreateDate,
                x.OperationCode,
                x.ShipperNameEn,
                x.ConsigneeNameEn,
                x.CarrierNameEn,
                x.FromPort,
                x.ToPort,
                x.DateOfDeparture,
                x.StatusName,
                x.StatusId,
                x.IsConsolidation,
                x.OrderFrom,
                x.AgentNameEn
            })
                                .ToList();

            JTokenWriter pJTokenWriter = new JTokenWriter();
            JObject      ordersJson    = new JObject();

            pJTokenWriter.WriteStartObject();
            pJTokenWriter.WritePropertyName("data");
            pJTokenWriter.WriteStartArray();
            foreach (var item in operationList)
            {
                pJTokenWriter.WriteStartObject();

                pJTokenWriter.WritePropertyName("OperationId");
                pJTokenWriter.WriteValue(item.OperationId);

                pJTokenWriter.WritePropertyName("CarrierTypeImg");
                switch (item.CarrierType)
                {
                case 1:
                    pJTokenWriter.WriteValue("<i class='fa fa-ship'></i>");
                    break;

                case 2:
                    pJTokenWriter.WriteValue("<i class='fa fa-plane'></i>");
                    break;
                }

                pJTokenWriter.WritePropertyName("ConsolidationImg");
                switch (item.IsConsolidation)
                {
                case true:
                    pJTokenWriter.WriteValue("<i class='fa fa-users'></i>");
                    break;

                case false:
                    pJTokenWriter.WriteValue("<i class='fa fa-user'></i>");
                    break;
                }


                switch (item.OrderFrom)
                {
                case 1:
                    pJTokenWriter.WritePropertyName("OrderFromImg");
                    pJTokenWriter.WriteValue("<i class='fa fa-level-up'></i>");

                    pJTokenWriter.WritePropertyName("ClientName");
                    pJTokenWriter.WriteValue(item.ShipperNameEn);
                    break;

                case 2:
                    pJTokenWriter.WritePropertyName("OrderFromImg");
                    pJTokenWriter.WriteValue("<i class='fa fa-level-down'></i>");

                    pJTokenWriter.WritePropertyName("ClientName");
                    pJTokenWriter.WriteValue(item.ConsigneeNameEn);
                    break;
                }

                pJTokenWriter.WritePropertyName("QuoteId");
                if (item.QuoteId != null)
                {
                    pJTokenWriter.WriteValue(item.QuoteId);
                }
                else
                {
                    pJTokenWriter.WriteValue("");
                }

                pJTokenWriter.WritePropertyName("CarrierType");
                pJTokenWriter.WriteValue(item.CarrierType);

                pJTokenWriter.WritePropertyName("CreateDate");
                pJTokenWriter.WriteValue(item.CreateDate.ToString("dd/MM/yyyy"));

                pJTokenWriter.WritePropertyName("OperationCode");
                pJTokenWriter.WriteValue(item.OperationCode);

                pJTokenWriter.WritePropertyName("ShipperName");
                pJTokenWriter.WriteValue(item.ShipperNameEn);

                pJTokenWriter.WritePropertyName("ConsigneeName");
                pJTokenWriter.WriteValue(item.ConsigneeNameEn);

                pJTokenWriter.WritePropertyName("CarrierName");
                pJTokenWriter.WriteValue(item.CarrierNameEn);

                pJTokenWriter.WritePropertyName("FromPort");
                pJTokenWriter.WriteValue(item.FromPort);

                pJTokenWriter.WritePropertyName("ToPort");
                pJTokenWriter.WriteValue(item.ToPort);

                pJTokenWriter.WritePropertyName("DateOfDeparture");
                pJTokenWriter.WriteValue(item.DateOfDeparture != null ? item.DateOfDeparture.Value.ToString("dd/MM/yyyy") : "");

                pJTokenWriter.WritePropertyName("StatusName");
                pJTokenWriter.WriteValue(item.StatusName);

                pJTokenWriter.WritePropertyName("StatusId");
                pJTokenWriter.WriteValue(item.StatusId);

                pJTokenWriter.WritePropertyName("OrderFrom");
                pJTokenWriter.WriteValue(item.OrderFrom);

                pJTokenWriter.WritePropertyName("AgentName");
                pJTokenWriter.WriteValue(item.AgentNameEn);

                pJTokenWriter.WriteEndObject();
            }

            pJTokenWriter.WriteEndArray();
            pJTokenWriter.WriteEndObject();
            ordersJson = (JObject)pJTokenWriter.Token;
            return(ordersJson);
        }
Пример #28
0
        private void BuildJsonRecursive(XElement elementComplexType, JTokenWriter writer, string parentTrail, bool includeTexts = true, bool includeRestrictions = true, bool includeAttributes = true)
        {
            if (elementComplexType != null && elementComplexType.Element(XDocName.Sequence) != null)
            {
                List <string> propertyNamesUsed = new List <string>();
                foreach (XElement refElement in elementComplexType.Element(XDocName.Sequence).Elements())
                {
                    string   refName           = refElement.AttributeValue("ref");
                    string   classShortRefName = refName.Split('-')[0];
                    string   newTrail          = $"{parentTrail}/{refName}";
                    XElement element           = GetXElementByNameAttribute(refName);
                    XElement nextComplexType   = element.Element(XDocName.ComplexType);

                    // handle "bad" xsd with duplicate names in same group
                    if (propertyNamesUsed.Contains(classShortRefName))
                    {
                        classShortRefName += "2";
                    }

                    propertyNamesUsed.Add(classShortRefName);

                    writer.WritePropertyName(classShortRefName);
                    writer.WriteStartObject();

                    if (includeAttributes)
                    {
                        if (nextComplexType != null && nextComplexType.Element(XDocName.Attribute) != null)
                        {
                            string groupId = nextComplexType.Element(XDocName.Attribute).AttributeValue("fixed");
                            writer.WritePropertyName("gruppeid");
                            writer.WriteValue(int.Parse(groupId));
                        }

                        writer.WritePropertyName("serializedName");
                        writer.WriteValue(refName);

                        writer.WritePropertyName("xpath");
                        writer.WriteValue(newTrail);
                    }

                    if (includeRestrictions)
                    {
                        writer.WritePropertyName("minOccurs");
                        string minOccurs = refElement.AttributeValue("minOccurs");
                        writer.WriteValue(string.IsNullOrEmpty(minOccurs) ? 1 : int.Parse(minOccurs));

                        writer.WritePropertyName("maxOccurs");
                        string maxOccurs = refElement.AttributeValue("maxOccurs");
                        writer.WriteValue(string.IsNullOrEmpty(maxOccurs) ? 1 : int.Parse(maxOccurs));
                    }

                    XElement simpleTypeAnnotationElement = null;
                    if (nextComplexType != null && nextComplexType.Element(XDocName.SimpleContent) != null)
                    {
                        XElement extension      = nextComplexType.Element(XDocName.SimpleContent).Element(XDocName.Extension);
                        string   simpleTypeName = extension.AttributeValue("base");
                        XElement simpleType     = xsd.Descendants(XDocName.SimpleType).FirstOrDefault(p => XmlToLinqExtensions.AttributeValue(p, "name") == simpleTypeName);
                        simpleTypeAnnotationElement = simpleType.Element(XDocName.Annotation);
                        XElement restriction = simpleType.Element(XDocName.Restriction);

                        if (includeAttributes)
                        {
                            int orid = int.Parse(extension.Element(XDocName.Attribute).AttributeValue("fixed"));
                            writer.WritePropertyName("orid");
                            writer.WriteValue(orid);
                        }

                        if (includeRestrictions)
                        {
                            string xsdDataType = restriction.AttributeValue("base");
                            writer.WritePropertyName("xsdDataType");
                            writer.WriteValue(xsdDataType);

                            string length = restriction.Element(XDocName.Length).AttributeValue("value");
                            if (!string.IsNullOrEmpty(length))
                            {
                                writer.WritePropertyName("length");
                                writer.WriteValue(int.Parse(length));
                            }

                            string minLength = restriction.Element(XDocName.MinLength).AttributeValue("value");
                            if (!string.IsNullOrEmpty(minLength))
                            {
                                writer.WritePropertyName("minLength");
                                writer.WriteValue(int.Parse(minLength));
                            }

                            string maxLength = restriction.Element(XDocName.MaxLength).AttributeValue("value");
                            if (!string.IsNullOrEmpty(maxLength))
                            {
                                writer.WritePropertyName("maxLength");
                                writer.WriteValue(int.Parse(maxLength));
                            }

                            string minInclusive = restriction.Element(XDocName.MinInclusive).AttributeValue("value");
                            if (!string.IsNullOrEmpty(minInclusive))
                            {
                                writer.WritePropertyName("minInclusive");
                                writer.WriteValue(int.Parse(minInclusive));
                            }

                            string maxInclusive = restriction.Element(XDocName.MaxInclusive).AttributeValue("value");
                            if (!string.IsNullOrEmpty(maxInclusive))
                            {
                                writer.WritePropertyName("maxInclusive");
                                writer.WriteValue(int.Parse(maxInclusive));
                            }

                            string totalDigits = restriction.Element(XDocName.TotalDigits).AttributeValue("value");
                            if (!string.IsNullOrEmpty(totalDigits))
                            {
                                writer.WritePropertyName("totalDigits");
                                writer.WriteValue(int.Parse(totalDigits));
                            }

                            string pattern = restriction.Element(XDocName.Pattern).AttributeValue("value");
                            if (!string.IsNullOrEmpty(pattern))
                            {
                                writer.WritePropertyName("pattern");
                                writer.WriteValue(pattern);
                            }

                            IEnumerable <XElement> enumerations = restriction.Elements(XDocName.Enumeration);
                            if (enumerations != null && enumerations.Count() > 0)
                            {
                                writer.WritePropertyName("enums");
                                writer.WriteStartArray();
                                foreach (var enumeration in enumerations)
                                {
                                    writer.WriteValue(enumeration.AttributeValue("value"));
                                }

                                writer.WriteEndArray();
                            }
                        }
                    }

                    // Prefer annotation from ref element
                    XElement annotationElement = refElement.Element(XDocName.Annotation) ?? element.Element(XDocName.Annotation);
                    if (annotationElement != null && includeTexts)
                    {
                        CultureString labels = CreateCultureStringFromXElement(annotationElement, "LEDE");
                        if (labels.Count > 0)
                        {
                            writer.WritePropertyName("caption");
                            writer.WriteStartObject();
                            foreach (var label in labels)
                            {
                                writer.WritePropertyName(label.Key.ToString());
                                writer.WriteValue(label.Value);
                            }

                            writer.WriteEndObject();
                        }

                        CultureString helptexts = CreateCultureStringFromXElement(annotationElement, "HJELP");
                        if (helptexts.Count > 0)
                        {
                            writer.WritePropertyName("help");
                            writer.WriteStartObject();
                            foreach (var text in helptexts)
                            {
                                writer.WritePropertyName(text.Key.ToString());
                                writer.WriteValue(text.Value);
                            }

                            writer.WriteEndObject();
                        }

                        CultureString hinttexts = CreateCultureStringFromXElement(annotationElement, "HINT");
                        if (hinttexts.Count > 0)
                        {
                            writer.WritePropertyName("hint");
                            writer.WriteStartObject();
                            foreach (var text in hinttexts)
                            {
                                writer.WritePropertyName(text.Key.ToString());
                                writer.WriteValue(text.Value);
                            }

                            writer.WriteEndObject();
                        }

                        CultureString errortexts = CreateCultureStringFromXElement(annotationElement, "FEIL");
                        if (simpleTypeAnnotationElement != null && errortexts.Count == 0)
                        {
                            errortexts = CreateCultureStringFromXElement(simpleTypeAnnotationElement, "FEIL");
                        }

                        if (errortexts.Count > 0)
                        {
                            writer.WritePropertyName("error");
                            writer.WriteStartObject();
                            foreach (var text in errortexts)
                            {
                                writer.WritePropertyName(text.Key.ToString());
                                writer.WriteValue(text.Value);
                            }

                            writer.WriteEndObject();
                        }
                    }

                    // Magic
                    BuildJsonRecursive(nextComplexType, writer, newTrail, includeTexts, includeRestrictions, includeAttributes);

                    writer.WriteEndObject();
                }
            }
        }
Пример #29
0
        public static JObject GetAllOrders(FormCollection form = null)
        {
            OperationsEntities db = new OperationsEntities();
            //List<TruckingOrdersView> truckingOrders = new List<TruckingOrdersView>();
            TruckingOrdersView truckObj = new TruckingOrdersView();

            //  if (form.Count > 0)
            //  {
            string where = CommonHelper.AdvancedSearch <TruckingOrdersView>(form, truckObj);
            var truckingOrders = db.TruckingOrdersViews.Where(where.ToString())
                                 .Select(x => new
            {
                x.ArriveDate,
                x.TruckingOrderId,
                x.OperationId,
                x.OrderFrom,
                x.StatusId,
                x.OperationCode,
                x.CreateDate,
                x.ShipperNameEn,
                x.ConsigneeNameEn,
                x.BookingNo,
                x.ContractorNameEn,
                x.NeedArriveDate,
                x.NeedArriveTime,
                x.ArriveTime,
                x.StatusName,
                x.HouseBL
            }).ToList();
            //  }
            //else
            //{
            //    truckingOrders = db.TruckingOrdersViews.Where(x => x.StatusId == 1 || x.StatusId == 2)
            //        .OrderByDescending(x => x.CreateDate).ToList();

            //}

            //truckingOrders = truckingOrders.OrderByDescending(x => x.CreateDate).ToList();

            //if (orderFrom != 0)
            //    truckingOrders = truckingOrders.Where(x => x.OrderFrom == orderFrom).ToList();

            JTokenWriter pJTokenWriter = new JTokenWriter();
            JObject      ordersJson    = new JObject();

            pJTokenWriter.WriteStartObject();
            pJTokenWriter.WritePropertyName("data");
            pJTokenWriter.WriteStartArray();
            foreach (var item in truckingOrders)
            {
                pJTokenWriter.WriteStartObject();
                pJTokenWriter.WritePropertyName("TruckingOrderId");
                pJTokenWriter.WriteValue(item.TruckingOrderId);

                pJTokenWriter.WritePropertyName("OperationId");
                pJTokenWriter.WriteValue(item.OperationId);

                pJTokenWriter.WritePropertyName("OrderFromImg");
                switch (item.OrderFrom)
                {
                case 1:
                    pJTokenWriter.WriteValue("<i class='fa fa-level-up'></i>");
                    break;

                case 2:
                    pJTokenWriter.WriteValue("<i class='fa fa-level-down'></i>");
                    break;
                }

                pJTokenWriter.WritePropertyName("StatusId");
                pJTokenWriter.WriteValue(item.StatusId);

                pJTokenWriter.WritePropertyName("OperationCode");
                pJTokenWriter.WriteValue(item.OperationCode);

                pJTokenWriter.WritePropertyName("HouseBL");
                pJTokenWriter.WriteValue(item.HouseBL);

                pJTokenWriter.WritePropertyName("CreateDate");
                pJTokenWriter.WriteValue(item.CreateDate.Value.ToString("dd/MM/yyyy"));

                pJTokenWriter.WritePropertyName("Client");
                if (!string.IsNullOrEmpty(item.ShipperNameEn))
                {
                    pJTokenWriter.WriteValue(item.ShipperNameEn);
                }
                else if (!string.IsNullOrEmpty(item.ConsigneeNameEn))
                {
                    pJTokenWriter.WriteValue(item.ConsigneeNameEn);
                }
                else
                {
                    pJTokenWriter.WriteValue("");
                }

                pJTokenWriter.WritePropertyName("BookingNo");
                pJTokenWriter.WriteValue(item.BookingNo);

                pJTokenWriter.WritePropertyName("ContractorName");
                pJTokenWriter.WriteValue(item.ContractorNameEn);

                pJTokenWriter.WritePropertyName("NeedArrive");
                pJTokenWriter.WriteValue(item.NeedArriveDate.ToString("dd/MM/yyyy") + " " + item.NeedArriveTime.ToString(@"h\:mm"));

                pJTokenWriter.WritePropertyName("ArriveTime");
                if (item.ArriveDate != null && item.ArriveTime != null)
                {
                    pJTokenWriter.WriteValue(item.ArriveDate.Value.ToString("dd/MM/yyyy") + " " + item.ArriveTime.Value.ToString(@"h\:mm"));
                }
                else
                {
                    pJTokenWriter.WriteValue("");
                }

                pJTokenWriter.WritePropertyName("StatusName");
                pJTokenWriter.WriteValue(item.StatusName);

                pJTokenWriter.WriteEndObject();
            }

            pJTokenWriter.WriteEndArray();
            pJTokenWriter.WriteEndObject();
            ordersJson = (JObject)pJTokenWriter.Token;
            return(ordersJson);
        }
Пример #30
0
        internal static JObject GetAgNoteListJson(System.Web.Mvc.FormCollection form)
        {
            AccountingEntities db        = new AccountingEntities();
            AgentNoteView      invViewDb = new AgentNoteView();

            string where = CommonHelper.AdvancedSearch <AgentNoteView>(form, invViewDb);
            if (string.IsNullOrEmpty(where))
            {
                where = "1 = 1"; //instead of make if condition
            }
            var agNoteList = db.AgentNoteViews.Where(where.ToString()).ToList();
            //fi moseba hena :D .. This table schema should be changed to Indentity PK and two FK
            //From Invoice or From Agent Note .. The other option is to create another table for Agent Note collection :)

            List <int> invIds    = agNoteList.Select(x => x.AgentNoteId).ToList();
            var        cashInvDb = db.CashInReceiptAgNotes
                                   .Where(x => invIds.Contains(x.AgentNoteId))
                                   .GroupBy(x => x.AgentNoteId)
                                   .ToList();

            var cashOutInvDb = db.CashOutReceiptAgNotes
                               .Where(x => invIds.Contains(x.AgentNoteId))
                               .GroupBy(x => x.AgentNoteId)
                               .ToList();

            decimal collectedAmount, amountDue;

            JTokenWriter pJTokenWriter = new JTokenWriter();
            JObject      ordersJson    = new JObject();

            pJTokenWriter.WriteStartObject();
            pJTokenWriter.WritePropertyName("data");
            pJTokenWriter.WriteStartArray();
            foreach (var item in agNoteList)
            {
                pJTokenWriter.WriteStartObject();

                pJTokenWriter.WritePropertyName("AgentNoteId");
                pJTokenWriter.WriteValue(item.AgentNoteId);

                pJTokenWriter.WritePropertyName("OperationId");
                pJTokenWriter.WriteValue(item.OperationId);

                pJTokenWriter.WritePropertyName("AgentNoteCode");
                pJTokenWriter.WriteValue(item.AgentNoteCode);

                pJTokenWriter.WritePropertyName("OperationCode");
                pJTokenWriter.WriteValue(item.OperationCode);

                pJTokenWriter.WritePropertyName("AgentNoteType"); //1 Debit  2 Credit
                pJTokenWriter.WriteValue(item.AgentNoteType);

                pJTokenWriter.WritePropertyName("DueDate");
                pJTokenWriter.WriteValue(item.DueDate.Value.ToString("dd/MM/yyyy"));

                pJTokenWriter.WritePropertyName("AgentNoteDate");
                pJTokenWriter.WriteValue(item.AgentNoteDate.ToString("dd/MM/yyyy"));

                switch (item.OrderFrom)
                {
                case 1:
                    pJTokenWriter.WritePropertyName("OrderFromImg");
                    pJTokenWriter.WriteValue("<i class='fa fa-level-up'></i>");

                    break;

                case 2:
                    pJTokenWriter.WritePropertyName("OrderFromImg");
                    pJTokenWriter.WriteValue("<i class='fa fa-level-down'></i>");

                    break;
                }

                pJTokenWriter.WritePropertyName("MBL");
                pJTokenWriter.WriteValue(item.MBL);

                pJTokenWriter.WritePropertyName("AgentName");
                pJTokenWriter.WriteValue(item.AgentNameEn);

                pJTokenWriter.WritePropertyName("TotalAmount");
                pJTokenWriter.WriteValue(item.TotalAmount + " (" + item.CurrencySign + ")");
                if (item.AgentNoteType == 1) //Debit .. Get prev collected from cash in
                {
                    collectedAmount = cashInvDb.Where(x => x.Key == item.AgentNoteId)
                                      .Select(x => x.Sum(y => y.PaidAmount)).FirstOrDefault();
                    amountDue = item.TotalAmount - collectedAmount;
                }
                else //Credit .. Get prev Paid from Cash out
                {
                    collectedAmount = cashOutInvDb.Where(x => x.Key == item.AgentNoteId)
                                      .Select(x => x.Sum(y => y.PaidAmount)).FirstOrDefault();
                    amountDue = item.TotalAmount - collectedAmount;
                }



                pJTokenWriter.WritePropertyName("AmountDue"); //Modify this after make payment
                pJTokenWriter.WriteValue(amountDue + " (" + item.CurrencySign + ")");

                pJTokenWriter.WritePropertyName("InvStatusName");
                if (item.AgentNoteType == 1) //Debit .. will collect
                {
                    pJTokenWriter.WriteValue(item.InvStatusNameEn.Replace("Paid", "Collected"));
                }
                else
                {
                    pJTokenWriter.WriteValue(item.InvStatusNameEn);
                }

                pJTokenWriter.WritePropertyName("InvStatusId");
                pJTokenWriter.WriteValue(item.InvStatusId);


                pJTokenWriter.WriteEndObject();
            }

            pJTokenWriter.WriteEndArray();
            pJTokenWriter.WriteEndObject();
            ordersJson = (JObject)pJTokenWriter.Token;
            return(ordersJson);
        }