示例#1
0
        public async Task <int> SaveInvoiceProduct(InvoiceProduct invoiceProduct)
        {
            if (invoiceProduct == null)
            {
                throw new ArgumentNullException(nameof(invoiceProduct), "Parameter is null");
            }
            if (invoiceProduct.Id == 0)
            {
                dbContext.InvoiceProducts.Add(invoiceProduct);
            }
            else
            {
                InvoiceProduct dbEntry = dbContext.InvoiceProducts.Find(invoiceProduct.Id);
                if (dbEntry == null)
                {
                    throw new InvalidOperationException("Invoice product not found");
                }
                dbEntry.Quantity = invoiceProduct.Quantity;
                dbEntry.Price    = invoiceProduct.Price;
            }

            await dbContext.SaveChangesAsync();

            return(invoiceProduct.Id);
        }
        public void AddProductToInvoice(int invoiceId, int productId, int quantity)
        {
            var targetedInvoice = _context.Invoices
                                  .Where(i => i.InvoiceId == invoiceId)
                                  .SingleOrDefault();

            var targetedProduct = _context.Products
                                  .Where(p => p.ProductId == productId)
                                  .SingleOrDefault();

            var invoiceProduct = _context.InvoiceProduct
                                 .FirstOrDefault(ip => ip.Invoice.InvoiceId == targetedInvoice.InvoiceId &&
                                                 ip.Product.ProductId == targetedProduct.ProductId);

            if (invoiceProduct == null)
            {
                invoiceProduct = new InvoiceProduct()
                {
                    Invoice  = targetedInvoice,
                    Product  = targetedProduct,
                    Quantity = quantity
                };
                _context.InvoiceProduct.Add(invoiceProduct);
            }
            else
            {
                invoiceProduct.Quantity += quantity;
                _context.Entry(invoiceProduct).State = EntityState.Modified;
            }
            targetedInvoice.Total += targetedProduct.Price * quantity;
            _context.SaveChanges();
        }
示例#3
0
        private void items_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            ListViewItem item = this.items.GetItemAt(e.X, e.Y);

            if (item == null)
            {
                return;
            }
            InvoiceProduct product = (InvoiceProduct)item.Tag;

            QuantityForm form = new QuantityForm(product);

            if (form.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            int qte = (int)form.Quantity;

            if (product.Product.CurrentStock - qte < 0)
            {
                Utils.Error(string.Format("Impossible ! Le stock n'est pas suffisant !\nStock restant : {0}", product.Product.CurrentStock));
                return;
            }

            product.Quantity = qte;
            InvoiceProductManager.Instance.Save(product);
            ReloadProducts();
        }
示例#4
0
 public QuantityForm(InvoiceProduct product)
 {
     this.product = product;
     InitializeComponent();
     this.numericUpDown1.Value = product.Quantity;
     this.label1.Text          = product.Product.Designation;
 }
        public async Task <IActionResult> AddToCart(int productFeatureId)
        {
            var productFeature = dbProductFeature.FindById(productFeatureId);

            if (User.Identity.Name == null)
            {
                return(RedirectToAction("Login", "Account"));
            }
            var currentUser = await userManager.FindByNameAsync(User.Identity.Name);

            var invoiceUser        = dbInvoice.GetAll().Where(e => e.CustomerId == currentUser.Id && e.IsPaid == false).FirstOrDefault();
            int cartId             = InitializeCart(invoiceUser, currentUser);
            var invoiceProductUser = dbInvoiceProduct.GetAll().Where(e => e.InvoiceId == cartId && e.ProductFeatureId == productFeatureId).FirstOrDefault();

            if (invoiceProductUser != null)
            {
                return(RedirectToAction("ShowPurchuseCart"));
            }
            InvoiceProduct invoiceProduct = new InvoiceProduct()
            {
                ProductFeatureId = productFeatureId,
                InvoiceId        = cartId,
                Count            = 1,
                Status           = true,
            };

            dbInvoiceProduct.Insert(invoiceProduct);
            //Update CalculatedPrice
            var totalprice = TotalInvoicePrice(cartId);

            return(RedirectToAction("ShowPurchuseCart"));
        }
示例#6
0
 private void button8_Click(object sender, EventArgs e)
 {
     if (dataGridView2.Rows.Count > 1 && dataGridView1.SelectedRows.Count > 0 && dataGridView1.Enabled)
     {
         Invoice iv = new Invoice();
         iv.BillDate           = DateTime.Now.Date;
         iv.invoicestatus      = 0;
         iv.invoiceTypePriceID = 1;
         iv.InvoiceType_ID     = 4;
         iv.PaymentType_ID     = 1;
         iv.Pesron_ID          = int.Parse(comboBox1.SelectedValue.ToString());
         iv.TotalBill          = 0;
         iv.TotalCash          = 0;
         iv.TotalReset         = 0;
         for (int i = 0; i < dataGridView2.Rows.Count - 1; i++)
         {
             InvoiceProduct ivpd = new InvoiceProduct();
             ivpd.Product_ID   = int.Parse(dataGridView2.Rows[i].Cells[4].Value.ToString());
             ivpd.Quantity     = int.Parse(dataGridView2.Rows[i].Cells[2].Value.ToString());
             ivpd.SerialNumber = dataGridView2.Rows[i].Cells[3].Value.ToString();
             iv.InvoiceProduct.Add(ivpd);
         }
         context.invoices.Add(iv);
         int ivid = int.Parse(dataGridView1.SelectedRows[0].Cells[1].Value.ToString());
         context.invoices.FirstOrDefault(ivs => ivs.ID == ivid).invoicestatus = 2;
         context.SaveChanges();
         MessageBox.Show("تم عمل مرتجع للمنتجات");
         dataGridView1.Rows.Clear();
         dataGridView2.Rows.Clear();
     }
     else
     {
         MessageBox.Show("لا يوجد منتجات للمرتجع");
     }
 }
示例#7
0
        private void OnSaveInvoiceButtonAction(object sender, RoutedEventArgs e)
        {
            bool isNumberEmpty   = service.ValidateNumberTextField(numberTextField, numberErrorLabel);
            bool isCustomerEmpty = service.ValidateCustomerButton(addCustomerButton, customerErrorLabel);
            bool isProductEmpty  = service.ValidateProductButton(listProductsButton, productErrorLabel);

            if (!isNumberEmpty && !isCustomerEmpty && !isProductEmpty)
            {
                invoice.Number   = numberTextField.Text;
                invoice.Date     = datePicker.SelectedDate == null ? DateTime.Now : datePicker.SelectedDate.Value;
                invoice.Deadline = deadlinePicker.SelectedDate == null ? DateTime.Now : deadlinePicker.SelectedDate.Value;
                invoice.Customer = customer;
                invoice.Comment  = commentTextField.Text;
                invoice.Status   = Status.NOT_SENT;

                invoice.InvoiceProducts = new List <InvoiceProduct>();


                foreach (Product product in products)
                {
                    InvoiceProduct ip = new InvoiceProduct();
                    ip.Invoice = invoice;
                    ip.Product = product;

                    invoice.InvoiceProducts.Add(ip);
                }

                repository.AddInvoice(invoice, context, isUpdateFlag);
                invoiceWindow.RefreshInvoiceGridData();
                Close();
            }
        }
示例#8
0
        public void AddInvoice(InvoiceForCreationDto invoice, List <SelectingProductForSellDto> products)
        {
            // 1. add custom?
            var phoneNumber = invoice.PhoneNumber;

            // check if it's existing?
            var customer   = _customerRepository.GetCustomByPhoneNumber(phoneNumber);
            var customerId = -1;

            if (customer == null)
            {
                customer = new Customer {
                    Name = invoice.CustomerName, PhoneNumber = phoneNumber, CreationTime = DateTime.Now, AccumulatedPoint = invoice.Price / 100000
                };
                if (customer.AccumulatedPoint >= _customerLevelRepository.GetCustomerLevelByName("Hạng Vàng").PointLevel)
                {
                    customer.CustomerLevelId = 3;
                }
                else if (customer.AccumulatedPoint >= _customerLevelRepository.GetCustomerLevelByName("Hạng Bạc").PointLevel)
                {
                    customer.CustomerLevelId = 2;
                }
                else
                {
                    customer.CustomerLevelId = 1;
                }
                var storedCustomer = _customerRepository.Create(customer);
                customerId = storedCustomer.Id;
            }
            else
            {
                customerId = customer.Id;
            }

            // 2. add invoice
            var storedInvoice = _invoiceRepository.Create(new Invoice
            {
                CustomerId   = customerId,
                UserId       = Session.CurrentUser.Id,
                CreationTime = DateTime.Now,
                Total        = invoice.Total,
                Discount     = invoice.Discount,
                Price        = invoice.Price
            });;

            // 3. add invoice's products and decrease no. each product
            foreach (var product in products)
            {
                var invoiceProduct = new InvoiceProduct
                {
                    ProductId = product.Id,
                    Number    = product.SelectedNumber,
                    InvoiceId = storedInvoice.Id
                };

                _invoiceProductRepository.Create(invoiceProduct);
                _productRepository.UpdateNumberById(product.Id, product.SelectedNumber);
            }
        }
示例#9
0
 public static void SaveInvoiceProduct(InvoiceProduct invoiceProduct, int unitId)
 {
     using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString()))
     {
         string s1 = "IdInvoice, IdProduct, ProductName, Quantity, QuantityUnits, NettoPrice, BruttoPrice, Vat";
         cnn.Execute("insert into InvoicesProduct(" + s1 + ")values(@idInvoice, @idProduct, @productName, @quantity," + unitId.ToString() + ", @nettoPrice, @bruttoPrice, @vat)", invoiceProduct);
     }
 }
示例#10
0
 public static void DeleteProductFromInvoice(InvoiceProduct invoiceProduct)
 {
     using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString()))
     {
         String str    = "delete from InvoicesProduct where IdProduct=" + invoiceProduct.IdProduct;
         var    output = cnn.Query <Company>(str);
     }
 }
        /// <summary>
        /// Creates TextBlock with Invoice details
        /// </summary>
        /// <param name="ip">InvoiceProduct object</param>
        /// <param name="count">Number element in sequence</param>
        /// <returns>Returns TextBlock object</returns>
        public TextBlock CreateInvoiceTextBlock(InvoiceProduct ip, int count)
        {
            TextBlock text = new TextBlock();

            text.Text     = count + ". Number: " + ip.Invoice.Number + ", Date: " + ip.Invoice.Date + ", Deadline: " + ip.Invoice.Deadline;
            text.FontSize = 16;

            return(text);
        }
示例#12
0
 private bool CompareProperties(InvoiceProduct expected, InvoiceProduct actual)
 {
     return
         (
         expected.Number == actual.Number &&
         expected.ProductId == actual.ProductId &&
         expected.InvoiceId == actual.InvoiceId
         );
 }
示例#13
0
 public InvoiceProductView(InvoiceProduct ip)
 {
     Id        = ip.Id;
     InvoiceId = ip.InvoiceId;
     ProductId = ip.ProductId;
     Title     = ip.Title;
     Price     = ip.Price;
     Quantity  = ip.Quantity;
     Total     = ip.Total;
 }
        /// <summary>
        /// Creates StackPanel for product entity details
        /// </summary>
        /// <param name="ip">InvoiceProduct object</param>
        /// <param name="count">number element in sequence</param>
        /// <returns>Returns StackPanel object with product details</returns>
        public StackPanel CreateProductStackPanel(InvoiceProduct ip, int count)
        {
            StackPanel stackPanel = new StackPanel();

            stackPanel.Orientation = Orientation.Vertical;

            service.CreateTextBlock(stackPanel, count + ". " + ip.Product.Name, true);
            service.CreateTextBlock(stackPanel, "Amount: " + ip.Product.Amount);
            service.CreateTextBlock(stackPanel, "Price: " + ip.Product.Price + "$");

            return(stackPanel);
        }
示例#15
0
        public InvoiceProduct InsertInvoiceProduct([FromBody] InvoiceProduct invoiceProduct)
        {
            var items = new List <InvoiceProduct>();

            foreach (var item in items)
            {
                item.ProductId = 0;
                _invoiceProductRepository.Add(item);
            }

            return(new InvoiceProduct());
        }
示例#16
0
        public ActionResult <InvoiceProduct> AddInvoiceProduct([FromBody] InvoiceProduct invoiceProduct)
        {
            try
            {
                var newInvoiceProduct = _invoiceProductService.AddInvoiceProduct(invoiceProduct);

                return(Ok(newInvoiceProduct));
            }
            catch (Exception e)
            {
                return(BadRequest(e.GetBaseException().Message));
            }
        }
        public async Task <IActionResult> InsertInvoiveAsync([FromForm] InvoiceRequest invoice)
        {
            DataRespond data = new DataRespond();

            try
            {
                Invoices inv = new Invoices();
                inv.namecustomer   = invoice.namecustomer;
                inv.gender         = invoice.gender;
                inv.phonenumber    = invoice.phonenumber;
                inv.email          = invoice.email;
                inv.province       = invoice.province;
                inv.district       = invoice.district;
                inv.adress         = invoice.adress;
                inv.adressdelviver = invoice.adressdelviver;
                inv.timedeliver    = invoice.timedeliver;
                inv.typepay        = invoice.typepay;
                inv.totalmoney     = invoice.totalmoney;
                inv.money          = invoice.money;
                inv.codediscount   = invoice.codediscount;

                inv.usid        = invoice.usid;
                inv.codeinvoice = RandomString(20);
                inv.status      = 0; //don't acvite
                inv.isread      = 0; //don't view
                inv.createday   = DateTime.Now;
                Invoices newinv = m_invoiceResponcitory.InsetInvoice(inv);

                foreach (var i in invoice.invoiceproduct)
                {
                    InvoiceProductRequest invprd    = new InvoiceProductRequest(i);
                    InvoiceProduct        invoicers = new InvoiceProduct();
                    invoicers.prid  = invprd.prid;
                    invoicers.total = invprd.total;
                    invoicers.ivid  = newinv.ivid;
                    m_invoiceResponcitory.InsertInvoiceProduct(invoicers);
                }
                var invsocket = m_invoiceResponcitory.GetFirstInvoice(newinv.codeinvoice);
                await sendInvoidBySocket(invsocket);

                sendEmail(invoice.email, inv.codeinvoice);
                data.success = true;
                data.data    = newinv;
            }
            catch (Exception e)
            {
                data.success = false;
                data.error   = e;
            }
            return(Ok(new { data }));
        }
 public void UpdateInvoiceProduct(InvoiceProduct existingInvoiceProduct, InvoiceProduct newInvoiceProduct)
 {
     try
     {
         _repositoryWrapper.InvoiceProduct.BeginTransaction();
         _repositoryWrapper.InvoiceProduct.UpdateInvoiceProduct(existingInvoiceProduct, newInvoiceProduct);
         _repositoryWrapper.InvoiceProduct.CommitTransaction();
     }
     catch (Exception e)
     {
         _repositoryWrapper.InvoiceProduct.RollbackTransaction();
         throw e;
     }
 }
 public void SoftDelete(InvoiceProduct invoiceProduct)
 {
     try
     {
         _repositoryWrapper.InvoiceProduct.BeginTransaction();
         _repositoryWrapper.InvoiceProduct.SoftDelete(invoiceProduct);
         _repositoryWrapper.InvoiceProduct.CommitTransaction();
     }
     catch (Exception e)
     {
         _repositoryWrapper.InvoiceProduct.RollbackTransaction();
         throw e;
     }
 }
        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                if (checnk_form())
                {
                    Invoice invoice = new Invoice();

                    invoice.Pesron_ID      = int.Parse(comboBox1.SelectedValue.ToString());
                    invoice.InvoiceType_ID = 6;
                    invoice.PaymentType_ID = int.Parse(comboBox2.SelectedValue.ToString());
                    invoice.TotalBill      = numericUpDown4.Value;
                    invoice.TotalCash      = numericUpDown2.Value;
                    invoice.TotalReset     = numericUpDown3.Value;
                    invoice.BillDate       = DateTime.Now.Date;
                    for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
                    {
                        int id = int.Parse(dataGridView1.Rows[i].Cells[4].Value.ToString());

                        int            quantity = int.Parse(dataGridView1.Rows[i].Cells[2].Value.ToString());
                        InvoiceProduct ips      = new InvoiceProduct();
                        ips.Product_ID = id;

                        ips.Quantity     = quantity;
                        ips.SerialNumber = generate_code() + i;
                        invoice.InvoiceProduct.Add(ips);
                    }
                    Person p = context.person.FirstOrDefault(ps => ps.ID == invoice.Pesron_ID);
                    p.AccountMoney -= numericUpDown2.Value;
                    context.invoices.Add(invoice);
                    context.SaveChanges();
                    dataGridView1.Rows.Clear();
                    counter = 0;
                    numericUpDown4.Value = 0;
                    numericUpDown2.Value = 0;
                    numericUpDown3.Value = 0;
                    MessageBox.Show("تم حفظ الفاتورة");
                    dataGridView2.Rows.Clear();
                    showallbillin();
                    //numericUpDown2.Enabled = false;
                    //listBox2.Items.Clear();
                    listBox3.Items.Clear();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                MessageBox.Show("لقد حدث خطأ اثناء عملية حفظ البيانات يرجي المحاولة في وقت لاحق");
            }
        }
示例#21
0
        public async Task <InvoiceProduct> DeleteInvoiceProduct(int invoiceProductId)
        {
            InvoiceProduct dbEntry = dbContext.InvoiceProducts.Find(invoiceProductId);

            if (dbEntry == null)
            {
                throw new InvalidOperationException("Invoice product not found");
            }
            dbContext.InvoiceProducts.Remove(dbEntry);

            await dbContext.SaveChangesAsync();

            return(dbEntry);
        }
 public InvoiceProduct AddInvoiceProduct(InvoiceProduct invoiceProduct)
 {
     try
     {
         _repositoryWrapper.InvoiceProduct.BeginTransaction();
         _repositoryWrapper.InvoiceProduct.AddInvoiceProduct(invoiceProduct);
         _repositoryWrapper.InvoiceProduct.CommitTransaction();
         return(invoiceProduct);
     }
     catch (Exception e)
     {
         _repositoryWrapper.InvoiceProduct.RollbackTransaction();
         throw e;
     }
 }
示例#23
0
 public void AddInvoiceProducts(InvoiceProduct invoiceProduct)
 {
     Db.ExecuteNonQuery("usp_Invoice_InsertInvoiceProducts", CommandType.StoredProcedure,
                        new DbParameter[] {
         Db.CreateParameter("InvoiceId", invoiceProduct.InvoiceId),
         Db.CreateParameter("ProductId", invoiceProduct.ProductId),
         Db.CreateParameter("ProductName", invoiceProduct.ProductName),
         Db.CreateParameter("Description", invoiceProduct.Description),
         Db.CreateParameter("Quantity", invoiceProduct.Quantity),
         Db.CreateParameter("UnitPrice", invoiceProduct.UnitPrice),
         Db.CreateParameter("TotalPrice", invoiceProduct.TotalPrice),
         Db.CreateParameter("TaxId", invoiceProduct.TaxId),
         Db.CreateParameter("TaxValue", invoiceProduct.TaxValue)
     });
 }
示例#24
0
        public ActionResult UpdateInvoiceProduct(Guid id, [FromBody] InvoiceProduct newInvoiceProduct)
        {
            try
            {
                var existingInvoiceProduct = _invoiceProductService.AsQueryable().FirstOrDefault(x => x.Id == id);
                if (existingInvoiceProduct == null)
                {
                    return(NotFound());
                }

                _invoiceProductService.UpdateInvoiceProduct(existingInvoiceProduct, newInvoiceProduct);
                return(Ok());
            }
            catch (Exception e)
            {
                return(BadRequest(e.GetBaseException().Message));
            }
        }
示例#25
0
        private InvoiceProduct GenerateInput(bool generateId = false, int?id = null)
        {
            var input = new InvoiceProduct
            {
                Number    = 1,
                ProductId = 1,
                InvoiceId = 1,
            };

            if (generateId)
            {
                input.Id = 111_111_111;
            }
            if (id != null)
            {
                input.Id = (int)id;
            }
            return(input);
        }
示例#26
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            List <Tax> lstTax = masterService.GetAllTaxes();

            invoiceProduct = new InvoiceProduct();
            invoiceProduct.InvoiceProductId = lstInvoiceProduct.Count;
            invoiceProduct.InvoiceId        = String.IsNullOrEmpty(txtInvoiceNumber.Text) ? 0 : Convert.ToInt32(txtInvoiceNumber.Text);
            invoiceProduct.ProductId        = Convert.ToInt32(cmbProduct.SelectedValue);
            invoiceProduct.ProductName      = cmbProduct.Text.Trim();
            invoiceProduct.Description      = txtDescription.Text.Trim();
            invoiceProduct.Quantity         = String.IsNullOrEmpty(txtQuantity.Text) ? 0 : Convert.ToInt32(txtQuantity.Text);
            invoiceProduct.UnitPrice        = String.IsNullOrEmpty(txtUnitPrice.Text) ? decimal.Zero : Math.Round(Convert.ToDecimal(txtUnitPrice.Text), 2);
            invoiceProduct.TotalPrice       = Math.Round(invoiceProduct.Quantity * invoiceProduct.UnitPrice, 2);
            invoiceProduct.TaxId            = Convert.ToInt32(cmbTax.SelectedValue);
            var objTax = (from tax in lstTax
                          .Where(v => v.TaxId == invoiceProduct.TaxId)
                          select tax).SingleOrDefault();

            invoiceProduct.TaxValue = Math.Round((invoiceProduct.Quantity * invoiceProduct.UnitPrice) * objTax.TaxPercentage * (decimal)0.01, 2);
            lstInvoiceProduct.Add(invoiceProduct);
            BindInvoiceProductGrid();
            ClearProductControls();
            CalculateInvoice();
        }
示例#27
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != "" && textBox2.Text != "" && textBox2.Text != "0" && dataGridView1.SelectedRows.Count > 0)
            {
                int quantity;
                int.TryParse(textBox2.Text, out quantity);
                var queryProductFatora = (from productFatora in Our.invoice_products
                                          where productFatora.Products.Name == label3.Text
                                          select productFatora).FirstOrDefault();
                int?prodID     = queryProductFatora.Product_ID;
                var prodin     = Our.invoice_products.Where(iv => iv.SerialNumber == textBox1.Text && iv.Product_ID == prodID && iv.Invoice.InvoiceType_ID == 1).Sum(vs => (int?)vs.Quantity) ?? 0;
                var prodout1   = Our.invoice_products.Where(iv => iv.SerialNumber == textBox1.Text && iv.Product_ID == prodID && iv.Invoice.InvoiceType_ID == 5).Sum(vs => (int?)vs.Quantity) ?? 0;
                var prodout2   = Our.invoice_products.Where(iv => iv.SerialNumber == textBox1.Text && iv.Product_ID == prodID && iv.Invoice.InvoiceType_ID == 3).Sum(vs => (int?)vs.Quantity) ?? 0;
                var prodin2    = Our.invoice_products.Where(iv => iv.SerialNumber == textBox1.Text && iv.Product_ID == prodID && iv.Invoice.InvoiceType_ID == 4).Sum(vs => (int?)vs.Quantity) ?? 0;
                var totalfound = ((prodin + prodin2) - (prodout2 + prodout1));

                if (totalfound >= quantity || totalfound >= quantity)
                {
                    int index = dataGridView1.CurrentCell.RowIndex;
                    //queryProductFatora.Quantity -= quantity;
                    //queryProductFatora.Products.Quantity -= quantity;
                    InvoiceProduct add = new InvoiceProduct();
                    //string a = ;
                    //string a = DateTime.Now.ToShortDateString();
                    add.Quantity     = quantity;
                    add.SerialNumber = textBox1.Text;
                    string name = dataGridView1.Rows[index].Cells["personName"].Value.ToString();

                    Products productDetails = (from Product in Our.Products
                                               where Product.Name == label3.Text
                                               select Product).FirstOrDefault();
                    Person personDetails = (from person in Our.person
                                            where person.Name == name && person.PersonType_ID == 1
                                            select person).FirstOrDefault();
                    add.Product_ID = productDetails.ID;
                    Invoice x = new Invoice();
                    x.BillDate             = DateTime.Now.Date;//Convert.ToDateTime(DateTime.Today.ToString("yyyy-MM-dd"));
                    x.Pesron_ID            = personDetails.ID;
                    x.InvoiceType_ID       = 5;
                    x.PaymentType_ID       = 1;
                    x.invoicestatus        = 0;
                    x.invoiceTypePrice     = productDetails.InvoiceProduct.Select(ip => ip.Invoice.invoiceTypePrice).FirstOrDefault();
                    x.TotalBill            = (quantity * productDetails.PriceIn);
                    x.TotalCash            = (quantity * productDetails.PriceIn);
                    add.Invoice            = x;
                    x.Person.AccountMoney -= x.TotalCash;
                    //delete from orginal fatora
                    //int id;
                    //int.TryParse(dataGridView1.Rows[index].Cells["invoiceNumber"].Value.ToString(), out id);
                    //var queryFatora = (from fatora in Our.invoices
                    //                   where fatora.ID == id
                    //                   select fatora).FirstOrDefault();
                    //queryFatora.TotalBill -= x.TotalBill;
                    //if (queryFatora.TotalCash > queryFatora.TotalReset)
                    //{
                    //    queryFatora.TotalCash -= x.TotalCash;
                    //}
                    //else
                    //{
                    //    queryFatora.TotalReset -= x.TotalCash;

                    //}


                    Our.invoice_products.Add(add);
                    Our.SaveChanges();

                    MessageBox.Show("تمام ");
                    getall();
                    textBox1.Text            = "";
                    label3.Text              = "";
                    dataGridView1.DataSource = null;
                    textBox2.Text            = "0";
                }
                else
                {
                    MessageBox.Show("الكميه المرتجعه مش موجوده ف المخزن " + totalfound);
                }
            }
            else
            {
                MessageBox.Show("يرجي اختيار و ملئ البيانات صحيحة");
            }
        }
示例#28
0
 public void UpdateInvoiceProducts(InvoiceProduct invoiceProduct)
 {
     this.invoiceDBObj.UpdateInvoiceProducts(invoiceProduct);
 }
示例#29
0
 public void AddInvoiceProducts(InvoiceProduct invoiceProduct)
 {
     this.invoiceDBObj.AddInvoiceProducts(invoiceProduct);
 }
示例#30
0
        private void btnSaveInvoice_Click(object sender, EventArgs e)
        {
            try
            {
                int invoiceId      = string.IsNullOrEmpty(txtInvoiceNumber.Text) ? 0 : Convert.ToInt32(txtInvoiceNumber.Text);
                var invoiceDetails = invoiceService.GetInvoice(invoiceId);
                var comapnyDetails = (from company in companyService.GetAllCompany()
                                      .Where(v => v.Status == true)
                                      select company).SingleOrDefault();

                Invoice invoice = new Invoice();
                invoice.InvoiceId       = invoiceId;
                invoice.CompanyId       = comapnyDetails.CompanyId;
                invoice.ClientId        = ClientId;
                invoice.IssueDate       = dtpIssueDate.Value.Date;
                invoice.PurchaseOrderNo = string.IsNullOrEmpty(txtPONumber.Text) ? String.Empty : txtPONumber.Text;
                invoice.PaymentTermId   = Convert.ToInt32(cmbPaymentTerms.SelectedValue);
                invoice.DueDate         = dtpDueDate.Value.Date;
                invoice.Discount        = string.IsNullOrEmpty(txtDiscount.Text) ? decimal.Zero : Convert.ToDecimal(txtDiscount.Text);
                invoice.RoundOffTotal   = chkRoundOff.Checked;
                invoice.MarkInvoicePaid = chkMarkInvoicePaid.Checked;

                if (chkMarkInvoicePaid.Checked)
                {
                    invoice.PaymentTypeId = Convert.ToInt32(cmbPaymentType.SelectedValue);
                    invoice.AmountPaid    = string.IsNullOrEmpty(txtAmountPaid.Text) ? decimal.Zero : Convert.ToDecimal(txtAmountPaid.Text);

                    if (invoiceDetails == null || invoiceDetails.InvoiceId == 0)
                    {
                        invoice.PaymentDate = DateTime.Now.Date;
                    }
                    else
                    {
                        if (invoiceDetails.AmountPaid > 0)
                        {
                            if (invoiceDetails.AmountPaid == invoice.AmountPaid)
                            {
                                invoice.PaymentDate = invoiceDetails.PaymentDate;
                            }
                            else
                            {
                                invoice.PaymentDate = DateTime.Now.Date;
                            }
                        }
                    }
                    string paymentStatus = String.Empty;

                    if (invoice.AmountPaid == 0)
                    {
                        paymentStatus = ePaymentStatus.Unpaid.ToString();
                    }
                    else if (invoice.AmountPaid > 0)
                    {
                        if (invoice.AmountPaid < TotalValue)
                        {
                            paymentStatus = ePaymentStatus.Partial.ToString();
                        }
                        else if (invoice.AmountPaid == TotalValue)
                        {
                            paymentStatus = ePaymentStatus.Paid.ToString();
                        }
                        else
                        {
                            paymentStatus = ePaymentStatus.Paid.ToString();
                        }
                    }

                    if (invoice.PaymentDate.Date > invoice.DueDate.Date)
                    {
                        if (String.IsNullOrEmpty(paymentStatus))
                        {
                            paymentStatus = String.Concat(paymentStatus, ",", ePaymentStatus.Overdue.ToString());
                        }
                        else
                        {
                            paymentStatus = ePaymentStatus.Overdue.ToString();
                        }
                    }

                    invoice.PaymentStatus = paymentStatus;
                }
                else
                {
                    invoice.PaymentTypeId = 0;
                    invoice.AmountPaid    = decimal.Zero;
                }

                invoice.Notes          = string.IsNullOrEmpty(txtNotes.Text) ? String.Empty : txtNotes.Text;
                invoice.TotalAmount    = TotalValue;
                invoice.NotesForClient = string.IsNullOrEmpty(txtNoteForClient.Text) ? String.Empty : txtNoteForClient.Text;
                invoice.PrivateNotes   = string.IsNullOrEmpty(txtprivateNotes.Text) ? String.Empty : txtprivateNotes.Text;
                invoice.Status         = true;

                if (invoiceDetails == null || invoiceDetails.InvoiceId == 0)
                {
                    using (TransactionScope scope = new TransactionScope())
                    {
                        invoiceService.AddInvoice(invoice);
                        lstInvoiceProduct = lstInvoiceProduct.OrderBy(s => s.InvoiceProductId).ToList <InvoiceProduct>();

                        for (int i = 0; i < lstInvoiceProduct.Count; i++)
                        {
                            InvoiceProduct invoiceProduct = new InvoiceProduct();
                            invoiceProduct.InvoiceId   = lstInvoiceProduct[i].InvoiceId;
                            invoiceProduct.ProductId   = lstInvoiceProduct[i].ProductId;
                            invoiceProduct.ProductName = lstInvoiceProduct[i].ProductName;
                            invoiceProduct.Description = lstInvoiceProduct[i].Description;
                            invoiceProduct.Quantity    = lstInvoiceProduct[i].Quantity;
                            invoiceProduct.TaxId       = lstInvoiceProduct[i].TaxId;
                            invoiceProduct.TaxValue    = lstInvoiceProduct[i].TaxValue;
                            invoiceProduct.UnitPrice   = lstInvoiceProduct[i].UnitPrice;
                            invoiceProduct.TotalPrice  = lstInvoiceProduct[i].TotalPrice;
                            invoiceService.AddInvoiceProducts(invoiceProduct);
                        }

                        scope.Complete();
                    }
                }
                else
                {
                    using (TransactionScope scope = new TransactionScope())
                    {
                        invoiceService.UpdateInvoice(invoice);

                        for (int i = 0; i < lstInvoiceProduct.Count; i++)
                        {
                            InvoiceProduct invoiceProduct = new InvoiceProduct();
                            invoiceProduct.InvoiceId   = lstInvoiceProduct[i].InvoiceId;
                            invoiceProduct.ProductId   = lstInvoiceProduct[i].ProductId;
                            invoiceProduct.ProductName = lstInvoiceProduct[i].ProductName;
                            invoiceProduct.Description = lstInvoiceProduct[i].Description;
                            invoiceProduct.Quantity    = lstInvoiceProduct[i].Quantity;
                            invoiceProduct.TaxId       = lstInvoiceProduct[i].TaxId;
                            invoiceProduct.TaxValue    = lstInvoiceProduct[i].TaxValue;
                            invoiceProduct.UnitPrice   = lstInvoiceProduct[i].UnitPrice;
                            invoiceProduct.TotalPrice  = lstInvoiceProduct[i].TotalPrice;
                            invoiceService.UpdateInvoiceProducts(invoiceProduct);
                        }

                        scope.Complete();
                    }
                }

                CustomMessageBox.Show(string.Format(Constants.SUCCESSFULL_ADD_INVOICE_MESSAGE, invoice.InvoiceId),
                                      Constants.CONSTANT_INFORMATION,
                                      Sleek_Bill.Controls.CustomMessageBox.eDialogButtons.OK,
                                      CustomImages.GetDialogImage(Sleek_Bill.Controls.CustomImages.eCustomDialogImages.Success));
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error Saving invoice: " + ex.Message);
            }
        }