Пример #1
0
        private dynamic GetEzcountRes(dynamic Params, List <dynamic> listProduct, List <dynamic> Payment, int DocType, string IsProduction, DocCreation doc, ref Logs lg, decimal p)
        {
            var reqObjZikuy = new
            {
                api_key   = (string)Params.api_key,
                api_email = (string)Params.api_email,
                ua_uuid   = (string)Params.ua_uuid,

                developer_email = "*****@*****.**",
                developer_phone = "0505913817",
                type            = DocType,
                description     = "",//(bool)Params.isMasKabala ? "" : (string)Params.InvoiceDetails,

                customer_email   = (string)Params.customer_email,
                customer_address = (string)Params.customer_address,
                comment          = (string)Params.comment,
                parent           = (string)Params.parents,

                customer_name    = (string)Params.customer_name,
                customerAction   = "ASSOC_CREATE",
                customer_crn     = (string)Params.customer_crn,
                c_accounting_num = (string)Params.c_accounting_num,
                tag_id           = (string)Params.tag_id,


                item = listProduct,

                payment     = Payment,
                price_total = p,
            };

            lg.Details = " הנפקת זיכוי " + (string)Params.payment_type;
            dynamic responseZikuy = doc.execute(((IsProduction == "0") ? Constants.ENV_TEST : Constants.ENV_PRODUCTION), reqObjZikuy);

            lg.Response = responseZikuy.ToString();
            return(responseZikuy);
        }
Пример #2
0
        public void InsertSchedularToken()
        {
            string IsProduction        = ConfigurationSettings.AppSettings["IsProduction"].ToString();
            string SlikaUrlChargeToken = ConfigurationSettings.AppSettings["SlikaUrlChargeToken"].ToString();

            DateTime CurrentDate = DateTime.Now;
            int      Day         = CurrentDate.Day;
            int      Month       = CurrentDate.Month;


            using (var Context = new Context())
            {
                var UsersToPay = Context.Users.Where(x => x.Active == "active" &&
                                                     x.DateForMonthlyPay.Value.Day == Day &&
                                                     x.DateForMonthlySum > 0 &&
                                                     x.DateForMonthlySeq != x.DateForMonthlyPrev && // ההסטוריה שונה
                                                     x.cc_token != null &&
                                                     x.cc_token != ""
                                                     ).ToList();

                foreach (User up in UsersToPay)
                {
                    if (up.Rivoni)
                    {
                        if (Month != 1 && Month != 4 && Month != 7 && Month != 10)
                        {
                            continue;
                        }
                    }


                    AutoPayObj ap = GetAutoPayObj(up);

                    var    Farm      = Context.Farms.Where(y => y.Id == up.Farm_Id).FirstOrDefault();
                    var    Meta      = JObject.Parse(Farm.Meta);
                    string api_key   = Meta["api_key"].ToString();
                    string api_email = Meta["api_email"].ToString();
                    var    ua_uuid   = Meta["ua_uuid"];


                    var reqObjAshrai = new
                    {
                        api_key         = api_key,
                        developer_email = "*****@*****.**",
                        sum             = up.DateForMonthlySum,
                        cc_token        = up.cc_token,
                        cc_4_digits     = up.cc_4_digits,
                        cc_payer_name   = up.cc_payer_name,
                        cc_payer_id     = up.cc_payer_id,
                        cc_expire_month = up.cc_expire_month,
                        cc_expire_year  = up.cc_expire_year,
                        cc_type_id      = up.cc_type_id,
                        cc_type_name    = up.cc_type_name,
                    };

                    string              DATA     = Newtonsoft.Json.JsonConvert.SerializeObject(reqObjAshrai);
                    var                 SlikaUrl = SlikaUrlChargeToken;
                    var                 client   = new HttpClient();
                    HttpContent         content  = new StringContent(DATA, UTF8Encoding.UTF8, "application/json");
                    HttpResponseMessage messge   = client.PostAsync(SlikaUrl, content).Result;

                    dynamic responseToken = "";



                    if (messge.IsSuccessStatusCode)
                    {
                        responseToken = JsonConvert.DeserializeObject(messge.Content.ReadAsStringAsync().Result);

                        if (responseToken.success == "true")
                        {
                            DocCreation    doc     = new DocCreation();
                            List <dynamic> Payment = new List <dynamic>();
                            Payment.Add(new
                            {
                                payment_type = 3,
                                date         = up.DateForMonthlyPay.Value.ToString("dd/MM/yyyy"),
                                payment      = up.DateForMonthlySum,

                                cc_type            = up.cc_type_id,
                                cc_type_name       = up.cc_type_name,
                                cc_number          = up.cc_4_digits,
                                cc_deal_type       = 1,
                                cc_num_of_payments = 1,
                                cc_payment_num     = 1,
                            });

                            var reqObj = new
                            {
                                api_key   = api_key,
                                api_email = api_email,
                                ua_uuid   = ua_uuid,

                                developer_email  = "*****@*****.**",
                                developer_phone  = "0505913817",
                                type             = 320,//קבלה חשבונית מס
                                description      = ap.InvoiceTitle,
                                customer_name    = up.FirstName + " " + up.LastName,
                                customer_email   = up.AnotherEmail,
                                customer_address = up.Address,
                                comment          = "מס לקוח: " + up.ClientNumber + ", ת.ז.: " + up.IdNumber,


                                item = new dynamic[] {
                                    new {
                                        details       = " תאריכי שיעורים: " + ap.InvoiceDates,
                                        amount        = 1,
                                        price         = up.DateForMonthlySum,
                                        price_inc_vat = true
                                    }
                                },

                                payment     = Payment,
                                price_total = up.DateForMonthlySum,
                            };


                            dynamic response = doc.execute(((IsProduction == "0") ? Constants.ENV_TEST : Constants.ENV_PRODUCTION), reqObj);

                            // אם זה הצליח
                            if (response[5].ToString() == "True")
                            {
                                Payments p = new Payments();
                                p.Date       = CurrentDate;
                                p.doc_type   = "MasKabala";
                                p.InvoiceNum = response[2].ToString();
                                p.InvoicePdf = response[0].ToString();

                                p.Price          = up.DateForMonthlySum;
                                p.InvoiceDetails = " חיוב אוטמטי תאריכי שיעורים: " + ap.InvoiceDates;
                                p.UserId         = up.Id;
                                p.InvoiceSum     = up.DateForMonthlySum;

                                p.lessons    = ap.lessons;
                                p.month      = ap.month;
                                p.untilmonth = ap.untilmonth;


                                Context.Payments.Add(p);

                                up.DateForMonthlyPrev   = ((up.DateForMonthlyPrev == null) ? 0 : up.DateForMonthlyPrev) + 1;
                                Context.Entry(up).State = System.Data.Entity.EntityState.Modified;

                                Context.SaveChanges();
                            }
                        }
                    }
                }


                // זה נועד לאפס את העסק שאם ירצה להוסיף

                var UsersToDeleteAuto = Context.Users.Where(x => x.Active == "active" &&
                                                            x.DateForMonthlyPay.Value.Day == Day &&
                                                            x.DateForMonthlySum > 0 &&
                                                            x.DateForMonthlySeq == x.DateForMonthlyPrev && // ההסטוריה שונה
                                                            x.cc_token != null &&
                                                            x.cc_token != ""
                                                            ).ToList();
                foreach (User upd in UsersToDeleteAuto)
                {
                    upd.DateForMonthlyPay    = null;
                    upd.DateForMonthlySum    = null;
                    upd.DateForMonthlySeq    = null;
                    upd.DateForMonthlyPrev   = null;
                    upd.Rivoni               = false;
                    Context.Entry(upd).State = System.Data.Entity.EntityState.Modified;

                    Context.SaveChanges();
                }
            }
        }
Пример #3
0
        public void InsertChecksToMas()
        {
            string IsProduction = ConfigurationSettings.AppSettings["IsProduction"].ToString();


            DateTime CurrentDate = DateTime.Now.Date;

            using (var Context = new Context())
            {
                var UsersChecks = Context.Checks.Where(x => x.checks_date == CurrentDate && x.checks_auto).ToList();



                foreach (var uc in UsersChecks)
                {
                    var User        = Context.Users.Where(y => y.Id == uc.UserId).FirstOrDefault();
                    var PaymentUser = Context.Payments.Where(y => y.Id == uc.PaymentsId && !y.Deleted && y.ZikuyNumber == null).FirstOrDefault();
                    var Farm        = Context.Farms.Where(y => y.Id == User.Farm_Id).FirstOrDefault();
                    var Meta        = JObject.Parse(Farm.Meta);
                    var api_key     = Meta["api_key"];
                    var api_email   = Meta["api_email"];
                    var ua_uuid     = Meta["ua_uuid"];

                    if (User == null || PaymentUser == null ||
                        (PaymentUser.canceled != null && PaymentUser.canceled != "") ||
                        api_key == null
                        )
                    {
                        continue;
                    }



                    if (!string.IsNullOrEmpty(PaymentUser.InvoicePdf))
                    {
                        DocCreation    doc     = new DocCreation();
                        List <dynamic> Payment = new List <dynamic>();
                        Payment.Add(new
                        {
                            payment_type     = 2,
                            date             = uc.checks_date.Value.ToString("dd/MM/yyyy"),
                            payment          = uc.checks_sum,
                            checks_bank_name = uc.checks_bank_name,
                            checks_number    = uc.checks_number,
                        });

                        var reqObj = new
                        {
                            api_key   = (string)api_key,
                            api_email = (string)api_email,
                            ua_uuid   = (string)ua_uuid,

                            developer_email  = "*****@*****.**",
                            developer_phone  = "0505913817",
                            type             = 305,// חשבונית מס
                            description      = "פירעון שיק",
                            customer_name    = User.FirstName + " " + User.LastName,
                            customer_email   = User.AnotherEmail,
                            customer_address = User.Address,
                            comment          = "מס לקוח: " + User.ClientNumber + ", ת.ז.: " + User.IdNumber,
                            parent           = PaymentUser.doc_uuid,

                            item = new dynamic[] {
                                new {
                                    details       = "פירעון שיק" + uc.checks_number,
                                    amount        = 1,
                                    price         = uc.checks_sum,
                                    price_inc_vat = true
                                }
                            },

                            payment = Payment,
                            //  details = Params.checks_date != null ? "תאריך פרעון צ'ק: " + ((DateTime)Params.checks_date).ToLocalTime().ToShortDateString() : "",
                            price_total = uc.checks_sum,
                        };



                        Logs lg = new Logs();
                        lg.Type      = 2;// החזרת צק
                        lg.TimeStamp = DateTime.Now;
                        lg.Request   = reqObj.ToString();
                        lg.StudentId = uc.UserId;
                        lg.UserId    = UsersService.GetCurrentUser().Id;



                        dynamic response = doc.execute(((IsProduction == "0") ? Constants.ENV_TEST : Constants.ENV_PRODUCTION), reqObj);

                        lg.Response = response.ToString();
                        Context.Logs.Add(lg);

                        Context.SaveChanges();

                        // אם זה הצליח
                        if (response[5].ToString() == "True")
                        {
                            Payments p = new Payments();
                            p.Date               = uc.checks_date;
                            p.doc_type           = "Mas";
                            p.InvoiceNum         = response[2].ToString();
                            p.InvoicePdf         = response[0].ToString();
                            p.ParentInvoiceNum   = PaymentUser.InvoiceNum;
                            p.ParentInvoicePdf   = PaymentUser.InvoicePdf;
                            p.SelectedForInvoice = true;
                            p.Price              = uc.checks_sum;
                            p.InvoiceDetails     = " פירעון שיק " + uc.checks_number;
                            p.UserId             = User.Id;
                            p.InvoiceSum         = uc.checks_sum;

                            uc.checks_auto = false;
                            Context.Payments.Add(p);
                            //  Context.SaveChanges();
                            PaymentUser.SelectedForInvoice   = true;
                            Context.Entry(PaymentUser).State = System.Data.Entity.EntityState.Modified;


                            lg           = new Logs();
                            lg.Type      = 4; // חשבונית חדשה חשבונית אצלינו
                            lg.TimeStamp = DateTime.Now;
                            lg.Request   = p.InvoiceNum;
                            lg.StudentId = uc.UserId;
                            lg.UserId    = UsersService.GetCurrentUser().Id;
                            lg.Response  = p.InvoicePdf;
                            Context.Logs.Add(lg);


                            Context.SaveChanges();
                        }
                    }
                    else
                    {
                        Payments p = new Payments();
                        p.Date               = uc.checks_date;
                        p.doc_type           = "Mas";
                        p.InvoiceNum         = uc.checks_number;
                        p.InvoicePdf         = "";
                        p.ParentInvoiceNum   = PaymentUser.InvoiceNum;
                        p.ParentInvoicePdf   = PaymentUser.InvoicePdf;
                        p.SelectedForInvoice = true;
                        p.Price              = uc.checks_sum;
                        p.InvoiceDetails     = " פירעון שיק " + uc.checks_number;
                        p.UserId             = User.Id;
                        p.InvoiceSum         = uc.checks_sum;

                        uc.checks_auto = false;
                        Context.Payments.Add(p);
                        //  Context.SaveChanges();
                        PaymentUser.SelectedForInvoice   = true;
                        Context.Entry(PaymentUser).State = System.Data.Entity.EntityState.Modified;
                        Context.SaveChanges();
                    }
                }
            }
        }
Пример #4
0
        public IHttpActionResult sendInvoice(dynamic Params)
        {
            Logs lg = new Logs();

            lg.Type      = 1;
            lg.TimeStamp = DateTime.Now;
            lg.Request   = Params.ToString();
            lg.StudentId = (int)Params.UserId;
            lg.UserId    = UsersService.GetCurrentUser().Id;

            try
            {
                string IsProduction = ConfigurationSettings.AppSettings["IsProduction"].ToString();

                string SlikaUrlAsraiValidate = ConfigurationSettings.AppSettings["SlikaUrlAsraiValidate"].ToString();
                string SuccessUrlAshrai      = ConfigurationSettings.AppSettings["SuccessUrlAshrai"].ToString();
                string SlikaUrlAshrai        = ConfigurationSettings.AppSettings["SlikaUrlAshrai"].ToString();


                string SuccessUrlToken     = ConfigurationSettings.AppSettings["SuccessUrlToken"].ToString();
                string SlikaUrlToken       = ConfigurationSettings.AppSettings["SlikaUrlToken"].ToString();
                string SlikaUrlChargeToken = ConfigurationSettings.AppSettings["SlikaUrlChargeToken"].ToString();


                var CurrentUserFarmId = UsersService.GetCurrentUser().Farm_Id;
                var UserIdByEmail     = UsersService.GetUserIdByEmail((string)Params.customer_crn, CurrentUserFarmId);

                // צחי הוסיף בכדי למנוע עדכון של ת"ז קיים לחווה מסויימת
                if ((string)Params.UserId != UserIdByEmail.ToString() && UserIdByEmail != 0)
                {
                    return(Ok("-1"));
                }



                DocCreation doc = new DocCreation();

                Params.payment      = Params.InvoiceSum;
                Params.payment_date = Params.Date.ToString("dd/MM/yyyy");

                if ((string)Params.payment_type == "validate")
                {
                    var reqObjValidate = new
                    {
                        developer_email = "*****@*****.**",
                        api_key         = (string)Params.api_key
                    };


                    string DATA = Newtonsoft.Json.JsonConvert.SerializeObject(reqObjValidate);

                    var                 SlikaUrl = SlikaUrlAsraiValidate + Params.ksys_token;
                    var                 client   = new HttpClient();
                    HttpContent         content  = new StringContent(DATA, UTF8Encoding.UTF8, "application/json");
                    HttpResponseMessage messge   = client.PostAsync(SlikaUrl, content).Result;

                    dynamic response = "";
                    if (messge.IsSuccessStatusCode)
                    {
                        response = JsonConvert.DeserializeObject(messge.Content.ReadAsStringAsync().Result);
                    }

                    lg.Details  = "סליקה באשראי ולידציה";
                    lg.Response = response.ToString();
                    return(Ok(response));
                }

                else if ((string)Params.payment_type == "ashrai")
                {
                    var reqObjAshrai = new
                    {
                        api_key = (string)Params.api_key,
                        //   api_email = (string)Params.api_email,
                        developer_email = "*****@*****.**",
                        sum             = (decimal)Params.payment,
                        successUrl      = SuccessUrlAshrai
                    };


                    string DATA = Newtonsoft.Json.JsonConvert.SerializeObject(reqObjAshrai);

                    var                 SlikaUrl = SlikaUrlAshrai;
                    var                 client   = new HttpClient();
                    HttpContent         content  = new StringContent(DATA, UTF8Encoding.UTF8, "application/json");
                    HttpResponseMessage messge   = client.PostAsync(SlikaUrl, content).Result;

                    dynamic response = "";
                    if (messge.IsSuccessStatusCode)
                    {
                        response = JsonConvert.DeserializeObject(messge.Content.ReadAsStringAsync().Result);
                    }
                    lg.Details  = "אשראי קבלת קישור לחלון";
                    lg.Response = response.ToString();
                    return(Ok(response));
                }

                else if ((string)Params.payment_type == "token")
                {
                    var reqObjAshrai = new
                    {
                        api_key = (string)Params.api_key,

                        developer_email = "*****@*****.**",

                        successUrl = SuccessUrlToken + "&UserId=" + (string)Params.UserId
                    };


                    string DATA = Newtonsoft.Json.JsonConvert.SerializeObject(reqObjAshrai);

                    var                 SlikaUrl = SlikaUrlToken;
                    var                 client   = new HttpClient();
                    HttpContent         content  = new StringContent(DATA, UTF8Encoding.UTF8, "application/json");
                    HttpResponseMessage messge   = client.PostAsync(SlikaUrl, content).Result;

                    dynamic response = "";
                    if (messge.IsSuccessStatusCode)
                    {
                        response = JsonConvert.DeserializeObject(messge.Content.ReadAsStringAsync().Result);
                    }
                    lg.Details  = "הגדרת טוקן";
                    lg.Response = response.ToString();
                    return(Ok(response));
                }

                else if ((string)Params.payment_type == "tokenBuy")
                {
                    var reqObjAshrai = new
                    {
                        api_key         = (string)Params.api_key,
                        developer_email = "*****@*****.**",
                        sum             = (decimal)Params.payment,
                        cc_token        = (string)Params.cc_token,
                        cc_4_digits     = (string)Params.cc_4_digits,
                        cc_payer_name   = (string)Params.cc_payer_name,
                        cc_payer_id     = (string)Params.cc_payer_id,
                        cc_expire_month = (string)Params.cc_expire_month,
                        cc_expire_year  = (string)Params.cc_expire_year,
                        cc_type_id      = (string)Params.cc_type_id,
                        cc_type_name    = (string)Params.cc_type_name,
                    };

                    string              DATA     = Newtonsoft.Json.JsonConvert.SerializeObject(reqObjAshrai);
                    var                 SlikaUrl = SlikaUrlChargeToken;
                    var                 client   = new HttpClient();
                    HttpContent         content  = new StringContent(DATA, UTF8Encoding.UTF8, "application/json");
                    HttpResponseMessage messge   = client.PostAsync(SlikaUrl, content).Result;

                    dynamic responseToken = "";



                    if (messge.IsSuccessStatusCode)
                    {
                        responseToken = JsonConvert.DeserializeObject(messge.Content.ReadAsStringAsync().Result);

                        if (responseToken.success == "true")
                        {
                            Params.payment_type       = "credit card";
                            Params.cc_type            = (int)Params.cc_type_id;
                            Params.cc_type_name       = (string)Params.cc_type_name;
                            Params.cc_number          = (string)Params.cc_4_digits;
                            Params.cc_num_of_payments = 1;
                            Params.cc_deal_type       = 1;
                            Params.cc_payment_num     = 1;
                            lg.Details  = "סליקה טוקן";
                            lg.Response = responseToken.ToString();
                            return(sendInvoice(Params));
                        }
                        else
                        {
                            lg.Details  = "סליקה טוקן";
                            lg.Response = responseToken.ToString();
                        }
                    }
                    responseToken = "false";
                    return(Ok(responseToken));
                }

                else
                {
                    //try
                    //{

                    List <dynamic> Payment = new List <dynamic>();
                    switch ((string)Params.payment_type)
                    {
                    case "cash":

                        Payment.Add(
                            new
                        {
                            payment_type = 1,
                            date         = (string)Params.payment_date,
                            payment      = (decimal)Params.payment
                        }

                            );


                        break;

                    case "check":

                        JObject Checks = JObject.Parse((Newtonsoft.Json.JsonConvert.SerializeObject(Params.Checks)));
                        for (int i = 0; i < Checks.Count; i++)
                        {
                            Payment.Add(new
                            {
                                payment_type = 2,
                                date         = ((DateTime)Checks[i.ToString()]["checks_date"]).ToLocalTime().ToShortDateString(), // tzahi change//Params.payment_date,
                                payment      = (decimal)(Checks[i.ToString()]["checks_sum"]),                                     //(decimal)Params.payment,

                                checks_bank_name = Checks[i.ToString()]["checks_bank_name"].ToString(),                           //(string)Params.checks_bank_name,
                                checks_number    = Checks[i.ToString()]["checks_number"].ToString(),                              // (string)Params.checks_number,
                            });
                        }



                        break;

                    case "credit card":
                        Payment.Add(new
                        {
                            payment_type = 3,
                            date         = (string)Params.payment_date,
                            payment      = (decimal)Params.payment,

                            cc_type            = (int)Params.cc_type,
                            cc_type_name       = (string)Params.cc_type_name,
                            cc_number          = (string)Params.cc_number,
                            cc_deal_type       = (int)Params.cc_deal_type,
                            cc_num_of_payments = (int)Params.cc_num_of_payments,
                            cc_payment_num     = (int)Params.cc_payment_num,
                        });
                        break;

                    //case "tokenBuy":



                    //    Payment.Add(new
                    //    {
                    //        payment_type = 3,
                    //        date = (string)Params.payment_date,
                    //        payment = (decimal)Params.payment,

                    //        cc_type = (int)Params.cc_type,
                    //        cc_type_name = (string)Params.cc_type_name,
                    //        cc_number = (string)Params.cc_number,
                    //        cc_deal_type = (int)Params.cc_deal_type,
                    //        cc_num_of_payments = (int)Params.cc_num_of_payments,
                    //        cc_payment_num = (int)Params.cc_payment_num,

                    //    });
                    //    break;


                    case "bank transfer":
                        Payment.Add(new
                        {
                            payment_type = 4,
                            date         = (string)Params.payment_date,
                            payment      = (decimal)Params.payment,

                            bt_bank_account = (string)Params.bt_bank_account,
                            bt_bank_branch  = (string)Params.bt_bank_branch,
                            bt_bank_name    = (string)Params.bt_bank_name,
                        });
                        break;
                    }

                    int DocType = 405;
                    try
                    {
                        DocType = ((bool)Params.isMasKabala) ? 320 : ((bool)Params.isKabala ? 400 : ((bool)Params.isMas ? 305 : 405));
                        if ((bool)Params.isZikuy)
                        {
                            DocType = 330;
                        }
                    }
                    catch (Exception ex)
                    {
                        Params.isMasKabala = false;
                    }


                    //*************************** חלוקה לרשימות
                    List <dynamic> listProduct         = new List <dynamic>();
                    string         InvoiceDetailsArray = Newtonsoft.Json.JsonConvert.SerializeObject(Params.InvoiceDetailsArray);
                    List <JsonObj> items = JsonConvert.DeserializeObject <List <JsonObj> >(InvoiceDetailsArray);
                    foreach (var product in items)
                    {
                        dynamic temp = new
                        {
                            details       = product.details,
                            amount        = 1,
                            price         = product.price,
                            price_inc_vat = true
                        };

                        listProduct.Add(temp);
                    }

                    if (items.Count == 0)
                    {
                        dynamic temp = new
                        {
                            details       = (string)Params.InvoiceDetails,
                            amount        = 1,
                            price         = (decimal)Params.payment,
                            price_inc_vat = true
                        };

                        listProduct.Add(temp);
                    }

                    //********************************************

                    try
                    {
                        if ((bool)Params.isZikuy)
                        {
                            using (var Context = new Context())
                            {
                                dynamic responseZikuy = null;


                                string parentList = (string)Params.parents;
                                var    Pays       = Context.Payments.Where(x => (parentList).Contains(x.doc_uuid)).ToList();
                                foreach (var item in Pays)
                                {
                                    var doc_type = item.doc_type;

                                    if (doc_type == "Mas" || doc_type == "MasKabala")
                                    {
                                        decimal p = (decimal)Params.payment;
                                        DocType = 330;
                                        //Payment = null;
                                        dynamic temp = new
                                        {
                                            details       = (string)Params.InvoiceDetails,
                                            amount        = 1,
                                            price         = p,
                                            price_inc_vat = true
                                        };

                                        listProduct[0] = temp;


                                        responseZikuy = GetEzcountRes(Params, listProduct, Payment, DocType, IsProduction, doc, ref lg, p);
                                    }

                                    if (doc_type == "Kabala" || doc_type == "MasKabala")
                                    {
                                        DocType = 400;

                                        decimal p = -1 * (decimal)Params.payment;

                                        dynamic temp = new
                                        {
                                            details       = (string)Params.InvoiceDetails,
                                            amount        = 1,
                                            price         = p,
                                            price_inc_vat = true
                                        };

                                        listProduct[0] = temp;



                                        Payment.Add(
                                            new
                                        {
                                            payment_type = 1,
                                            date         = (string)Params.payment_date,
                                            payment      = p
                                        }

                                            );

                                        responseZikuy = GetEzcountRes(Params, listProduct, Payment, DocType, IsProduction, doc, ref lg, p);
                                    }
                                }


                                return(Ok(responseZikuy));
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                    }



                    var reqObj = new
                    {
                        api_key   = (string)Params.api_key,
                        api_email = (string)Params.api_email,
                        ua_uuid   = (string)Params.ua_uuid,

                        developer_email = "*****@*****.**",
                        developer_phone = "0505913817",
                        type            = DocType,
                        description     = (DocType != 400) ? "": (string)Params.InvoiceDetails,

                        customer_email   = (string)Params.customer_email,
                        customer_address = (string)Params.customer_address,
                        comment          = (string)Params.comment,
                        parent           = (string)Params.parents,

                        customer_name    = (string)Params.customer_name,
                        customerAction   = "ASSOC_CREATE",
                        customer_crn     = (string)Params.customer_crn,
                        c_accounting_num = (string)Params.c_accounting_num,
                        tag_id           = (string)Params.tag_id,


                        item = listProduct,

                        payment = Payment,
                        //  details = Params.checks_date != null ? "תאריך פרעון צ'ק: " + ((DateTime)Params.checks_date).ToLocalTime().ToShortDateString() : "",
                        price_total = (decimal)Params.payment,
                    };

                    lg.Details = " הנפקת חשבונית " + (string)Params.payment_type;
                    dynamic response = doc.execute(((IsProduction == "0") ? Constants.ENV_TEST : Constants.ENV_PRODUCTION), reqObj);
                    lg.Response = response.ToString();
                    return(Ok(response));
                }
            }
            catch (Exception ex)
            {
                lg.Exception = ex.Message;
                DocCreation doc      = new DocCreation();
                dynamic     response = doc.execute(Constants.ENV_TEST, null); // "{errMsg:2220}";
                return(Ok(response));
            }
            finally
            {
                using (var Context = new Context())
                {
                    Context.Logs.Add(lg);
                    Context.SaveChanges();
                }
            }
        }