Beispiel #1
0
        public async Task <ActionResult> loadInvoice(int id)
        {
            Cls_Invoice_Cancel Cls_Invoice_Cancel = new Cls_Invoice_Cancel();
            Invoice_Cancel     Invoice_Cancel     = await db.Invoice_Cancel.FindAsync(id);

            Cls_Invoice_Cancel.ID                       = Invoice_Cancel.ID;
            Cls_Invoice_Cancel.Moshtary_id              = Invoice_Cancel.Moshtary_id;
            Cls_Invoice_Cancel.Moshtary_Name            = (Invoice_Cancel.Moshtary_id != null) ?Invoice_Cancel.Moshtary.Name:"";
            Cls_Invoice_Cancel.Date_Invoice             = Invoice_Cancel.Date_Invoice.ToString("yyyy-mm-dd");
            Cls_Invoice_Cancel.Date_Invoice_Hijri       = Invoice_Cancel.Date_Invoice_Hijri;
            Cls_Invoice_Cancel.Price                    = Invoice_Cancel.Price;
            Cls_Invoice_Cancel.Total_Sadad              = Invoice_Cancel.Total_Sadad;
            Cls_Invoice_Cancel.User_ID                  = Invoice_Cancel.User_ID;
            Cls_Invoice_Cancel.ComputerName             = Invoice_Cancel.ComputerName;
            Cls_Invoice_Cancel.ComputerUser             = Invoice_Cancel.ComputerUser;
            Cls_Invoice_Cancel.InDate                   = Invoice_Cancel.InDate.ToString("yyyy-mm-dd");
            Cls_Invoice_Cancel.ClsInvoiceCancel_Product = new List <ClsInvoiceCancel_Product>();
            foreach (var item in Invoice_Cancel.Invoice_Cancel_Product)
            {
                Cls_Invoice_Cancel.ClsInvoiceCancel_Product.Add(
                    new ClsInvoiceCancel_Product
                {
                    ID = item.ID,
                    Invoice_Cancel_Id     = item.Invoice_Cancel_Id,
                    Product_Id            = item.Product_Id,
                    Product_Name          = item.Product.Name,
                    Amount                = item.Amount,
                    Price                 = item.Price,
                    Taxes                 = item.Taxes,
                    TotalPrice            = item.TotalPrice,
                    Date_Poduction        = item.Date_Poduction.ToString("yyyy-mm-dd"),
                    Date_Poduction_Hijri  = item.Date_Poduction_Hijri,
                    Date_Expiration       = item.Date_Expiration.ToString("yyyy-mm-dd"),
                    Date_Expiration_Hijri = item.Date_Expiration_Hijri,
                }
                    );
            }

            var list = JsonConvert.SerializeObject(Cls_Invoice_Cancel,
                                                   Formatting.None,
                                                   new JsonSerializerSettings()
            {
                ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
            });

            return(Content(list, "application/json"));
        }
Beispiel #2
0
        public async Task <ActionResult> InsertInvoice(Cls_Invoice_Cancel Cls_Invoice_Cancel)
        {
            DateTime Date_Invoice = DateTime.Now;

            System.Globalization.DateTimeFormatInfo HijriDTFI;
            HijriDTFI                  = new System.Globalization.CultureInfo("ar-SA", false).DateTimeFormat;
            HijriDTFI.Calendar         = new System.Globalization.HijriCalendar();
            HijriDTFI.ShortDatePattern = "dd/MM/yyyy";
            string Date_Invoice_Hijri = Date_Invoice.Date.ToString("dd/MM/yyyy", HijriDTFI);

            WindowsIdentity identity        = HttpContext.Request.LogonUserIdentity;
            List <string>   computerDetails = identity.Name.Split('\\').ToList();

            Invoice_Cancel _Invoice_Cancel = new Invoice_Cancel
            {
                Moshtary_id        = Cls_Invoice_Cancel.Moshtary_id,
                Date_Invoice       = Date_Invoice,
                Date_Invoice_Hijri = Date_Invoice_Hijri,
                Price        = Cls_Invoice_Cancel.Price,
                Total_Sadad  = 0,
                User_ID      = int.Parse(Session["UserID"].ToString()),
                ComputerName = computerDetails[0],
                ComputerUser = computerDetails[1],
                InDate       = Date_Invoice
            };

            db.Invoice_Cancel.Add(_Invoice_Cancel);
            await db.SaveChangesAsync();

            foreach (var item in Cls_Invoice_Cancel.ClsInvoiceCancel_Product)
            {
                int index = Cls_Invoice_Cancel.ClsInvoiceCancel_Product.IndexOf(item);
                int count = Cls_Invoice_Cancel.ClsInvoiceCancel_Product.Count;

                if (index < (count - 1))
                {
                    DateTime Date_Poduction        = DateTime.ParseExact(item.Date_Poduction, "yyyy-MM-dd", CultureInfo.InvariantCulture);
                    DateTime Date_Expiration       = DateTime.ParseExact(item.Date_Expiration, "yyyy-MM-dd", CultureInfo.InvariantCulture);
                    string   Date_Poduction_Hijri  = Date_Poduction.Date.ToString("dd/MM/yyyy", HijriDTFI);
                    string   Date_Expiration_Hijri = Date_Expiration.Date.ToString("dd/MM/yyyy", HijriDTFI);
                    Invoice_Cancel_Product Invoice_Cancel_Product = new Invoice_Cancel_Product
                    {
                        Invoice_Cancel_Id     = _Invoice_Cancel.ID,
                        Product_Id            = item.Product_Id,
                        Amount                = item.Amount,
                        Price                 = item.Price,
                        Store_id              = 1, //// ** محتاج تعديل
                        Date_Poduction        = Date_Poduction,
                        Date_Poduction_Hijri  = Date_Poduction_Hijri,
                        Date_Expiration       = Date_Expiration,
                        Date_Expiration_Hijri = Date_Expiration_Hijri,
                    };
                    db.Invoice_Cancel_Product.Add(Invoice_Cancel_Product);
                }
            }
            await db.SaveChangesAsync();

            //db.Invoice_Cancel.Add(_Invoice_Cancel);

            Error.ErrorName = "تم الإضافة بنجاح ... جاري إعادة تحميل الصفحة";
            Error.ID        = _Invoice_Cancel.ID;
            return(Json(Error, JsonRequestBehavior.AllowGet));
        }