/// <summary>
 /// Christian Lopez
 /// 2017/03/29
 ///
 /// Move an item from the product lot table to the invoice line table
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnAddToInvoice_Click(object sender, RoutedEventArgs e)
 {
     if (dgSupplierProductLots.SelectedIndex >= 0)
     {
         ProductLot          productLot  = (ProductLot)dgSupplierProductLots.SelectedItem;
         SupplierInvoiceLine invoiceLine = new SupplierInvoiceLine()
         {
             ProductLotId = (int)productLot.ProductLotId,
             QuantitySold = (int)productLot.Quantity
         };
         try
         {
             invoiceLine.PriceEach    = Decimal.Parse(txtPriceEach.Text);
             invoiceLine.ItemDiscount = Decimal.Parse(txtDiscount.Text);
         }
         catch (Exception)
         {
             MessageBox.Show("Unable to convert to decimal");
         }
         invoiceLine.ItemTotal = (invoiceLine.PriceEach * invoiceLine.QuantitySold - invoiceLine.ItemDiscount);
         _invoiceLines.Add(invoiceLine);
         _productLots.Remove(productLot);
         updateDataGrids();
         txtDiscount.Text         = "0.00";
         txtPriceEach.Text        = "0.00";
         invoiceSubtotalCost     += invoiceLine.ItemTotal;
         invoiceTax               = Decimal.Round(invoiceSubtotalCost * (decimal)taxRate, 2, MidpointRounding.AwayFromZero);
         invoiceTotalCost         = invoiceSubtotalCost + invoiceTax;
         lblSubtotalValue.Content = invoiceSubtotalCost.ToString();
         lblTaxAmount.Content     = invoiceTax.ToString();
         lblTotalAmount.Content   = invoiceTotalCost.ToString();
     }
 }
 /// <summary>
 /// Christian Lopez
 /// 2017/03/29
 ///
 /// Remove the selected item from the invoice line back to the product lots
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnRemoveFromInvoice_Click(object sender, RoutedEventArgs e)
 {
     if (dgSupplierInvoiceLots.SelectedIndex >= 0)
     {
         SupplierInvoiceLine invoiceLine = (SupplierInvoiceLine)dgSupplierInvoiceLots.SelectedItem;
         try
         {
             _productLots.Add(_productLotManager.RetrieveProductLotById(invoiceLine.ProductLotId));
             _invoiceLines.Remove(invoiceLine);
             updateDataGrids();
             invoiceSubtotalCost     -= invoiceLine.ItemTotal;
             invoiceTax               = Decimal.Round(invoiceSubtotalCost * (decimal)taxRate, 2, MidpointRounding.AwayFromZero);
             invoiceTotalCost         = invoiceSubtotalCost + invoiceTax;
             lblSubtotalValue.Content = invoiceSubtotalCost.ToString();
             lblTaxAmount.Content     = invoiceTax.ToString();
             lblTotalAmount.Content   = invoiceTotalCost.ToString();
         }
         catch (Exception ex)
         {
             if (null != ex.InnerException)
             {
                 MessageBox.Show("Unable to remove the invoice line at this time. Error: " + ex.Message + "\n\n" + ex.InnerException.Message);
             }
             else
             {
                 MessageBox.Show("Unable to remove the invoice line at this time. Error: " + ex.Message);
             }
         }
     }
 }
        /// <summary>
        /// Christian Lopez
        /// Created:
        /// 2017/03/29
        ///
        /// Creates a line for a supplier invoice
        /// </summary>
        ///
        /// <remarks>
        /// Aaron Usher
        /// Updated:
        /// 2017/04/28
        ///
        /// Standardized method.
        /// </remarks>
        ///
        /// <param name="supplierInvoiceLine">The supplierInvoiceLine to create.</param>
        /// <returns>Rows affected.</returns>
        public static int CreateSupplierInvoiceLine(SupplierInvoiceLine supplierInvoiceLine)
        {
            int rows = 0;

            var conn    = DBConnection.GetConnection();
            var cmdText = @"sp_create_supplier_invoice_line";
            var cmd     = new SqlCommand(cmdText, conn);

            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.AddWithValue("@SUPPLIER_INVOICE_ID", supplierInvoiceLine.SupplierInvoiceId);
            cmd.Parameters.AddWithValue("@PRODUCT_LOT_ID", supplierInvoiceLine.ProductLotId);
            cmd.Parameters.AddWithValue("@QUANTITY_SOLD", supplierInvoiceLine.QuantitySold);
            cmd.Parameters.AddWithValue("@PRICE_EACH", supplierInvoiceLine.PriceEach);
            cmd.Parameters.AddWithValue("@ITEM_DISCOUNT", supplierInvoiceLine.ItemDiscount);
            cmd.Parameters.AddWithValue("@ITEM_TOTAL", supplierInvoiceLine.ItemTotal);

            try
            {
                conn.Open();
                rows = cmd.ExecuteNonQuery();
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                conn.Close();
            }

            return(rows);
        }
Example #4
0
        public JsonResult AddInvoiceLine(int Prod, int Qty, double Price, double Total)
        {
            SupplierInvoiceLine SIL = new SupplierInvoiceLine();

            SIL.ProductId = Prod;
            SIL.Qty       = Qty;
            SIL.Price     = Price;
            SIL.Total     = Total;
            return(SIL.Add().DataInJSON);
        }
 /// <summary>
 /// Christian Lopez
 /// 2017/03/29
 ///
 /// Adds a supplier invoice line
 /// </summary>
 /// <param name="line"></param>
 /// <returns></returns>
 public bool CreateSupplierInvoiceLine(SupplierInvoiceLine line)
 {
     try
     {
         return(1 == SupplierInvoiceAccessor.CreateSupplierInvoiceLine(line));
     }
     catch (SqlException ex)
     {
         throw new ApplicationException("There was a database error.", ex);
     }
     catch (Exception ex)
     {
         throw new ApplicationException("There was an unknown error.", ex);
     }
 }
Example #6
0
        public string RemoveInvoiceLine(int id)
        {
            SupplierInvoiceLine SIL = new SupplierInvoiceLine {
                Id = id
            };

            if (SIL.Remove().Message == Message.Invoice_Line_Removed_Successfully)
            {
                return("true");
            }
            else
            {
                return("false");
            }
        }
Example #7
0
        public string EditFullInvoice(int ISup, DateTime IDate, int ToAcc, int projId, string IRef, double IDis, double ITotal, double INet, string LineIds)
        {
            SupplierInvoice SI = new SupplierInvoice();

            SI.Id                   = (int)TempData["IID"];
            SI.Departed             = false;
            SI.InvoiceDate          = IDate;
            SI.InvoiceDiscount      = IDis;
            SI.InvoiceNet           = INet;
            SI.InvoiceTotal         = ITotal;
            SI.ProjectID            = projId;
            SI.LastEditBy           = (Session["User"] as User).ID;
            SI.SupplierID           = ISup;
            SI.InvoiceAccount       = ToAcc;
            SI.SupplierReferenaceNo = IRef;
            string[]      LOSIL = LineIds.Split(',');
            List <string> AIL   = new List <string>(LOSIL);

            AIL.Remove("");
            List <SupplierInvoiceLine> LOCILTS = new List <SupplierInvoiceLine>();
            int Skip         = 0;
            int ObjectsCount = AIL.Count / 5;

            for (int i = 1; i <= ObjectsCount; i++)
            {
                List <string> CurrentObject = new List <string>();
                CurrentObject = AIL.Skip(Skip).Take(5).ToList();
                SupplierInvoiceLine CILTS = new SupplierInvoiceLine();
                CILTS.Id        = Convert.ToInt32(CurrentObject[0]);
                CILTS.ProductId = Convert.ToInt32(CurrentObject[1]);
                CILTS.Qty       = Convert.ToDouble(CurrentObject[2]);
                CILTS.Price     = Convert.ToDouble(CurrentObject[3]);
                CILTS.Total     = Convert.ToDouble(CurrentObject[4]);
                LOCILTS.Add(CILTS);
                Skip += 5;
            }
            SI.Edit(LOCILTS);
            TempData.Keep();
            return("true");
        }