private OriginalInvoiceData BuildOriginalInvoiceData(DictionaryDataSet ds)
        {
            var row = Session.CompanyInfo;
            OriginalInvoiceData invoiceData = new OriginalInvoiceData();

            invoiceData.RefID = Guid.NewGuid().ToString();
            //0313686411
            invoiceData.SellerTaxCode     = "0101243150-999";
            invoiceData.SellerLegalName   = row.Name;
            invoiceData.SellerAddressLine = row.Address;
            //
            invoiceData.BuyerLegalName   = ds.Customer.Rows[0]["CustomerName"].ToString();
            invoiceData.BuyerAddressLine = ds.Customer.Rows[0]["Address"].ToString();

            invoiceData.TemplateCode      = "01GTKT0/157";
            invoiceData.InvoiceType       = "01GTKT0";
            invoiceData.InvoiceSeries     = "AB/21E";
            invoiceData.PaymentMethodName = "Tiền mặt";
            invoiceData.AdjustmentType    = 1;
            invoiceData.IsSendEmail       = false;

            invoiceData.ExchangeRate = 1;

            invoiceData.TotalAmountWithoutVAT = Decimal.Parse(ds.SAInvoice.Rows[0]["TotalAmount"].ToString());
            invoiceData.VatPercentage         = 0;
            invoiceData.TotalVATAmount        = invoiceData.TotalAmountWithoutVAT * invoiceData.VatPercentage / 100;
            invoiceData.TotalAmountWithVAT    = invoiceData.TotalAmountWithoutVAT + invoiceData.TotalVATAmount;

            int count = 1;
            List <OriginalInvoiceDetail> detail = new List <OriginalInvoiceDetail>();

            BLSAInvoice bLSAInvoice = new BLSAInvoice();
            DataTable   table       = bLSAInvoice.GetSAInvoiceDetailAll(Guid.Parse(ds.SAInvoice.Rows[0]["RefID"].ToString()));

            for (int i = 0; i < table.Rows.Count; i++)
            {
                OriginalInvoiceDetail newDetail = new OriginalInvoiceDetail();
                newDetail.LineNumber    = count;
                newDetail.ItemCode      = table.Rows[0]["InventoryItemCode"].ToString();
                newDetail.ItemName      = table.Rows[0]["InventoryItemName"].ToString();
                newDetail.UnitName      = table.Rows[0]["UnitName"].ToString();
                newDetail.Quantity      = decimal.Parse(table.Rows[0]["UnitPrice"].ToString());
                newDetail.Amount        = decimal.Parse(table.Rows[0]["SaleAmount"].ToString());;
                newDetail.VatPercentage = 0;
                newDetail.VatAmount     = 0;
                newDetail.UnitPrice     = decimal.Parse(table.Rows[0]["UnitPrice"].ToString());

                detail.Add(newDetail);
            }

            invoiceData.OriginalInvoiceDetail = detail;

            return(invoiceData);
        }
Example #2
0
        public DictionaryDataSet.InventoryItemRow GetByID(Guid objectID)
        {
            var table = new DataTable();

            using (var sqlAdapter = new SqlDataAdapter())
            {
                using (var sqlCommand = CreateSqlCommand("Proc_GetInventoryItemByID"))
                {
                    sqlCommand.Parameters.AddWithValue("InventoryItemID", objectID);
                    sqlAdapter.SelectCommand = sqlCommand;
                    sqlAdapter.Fill(table);
                    sqlCommand.Connection.Close();
                }
            }
            if (table != null && table.Rows.Count > 0)
            {
                var ds = new DictionaryDataSet();
                ds.InventoryItem.Merge(table);
                DictionaryDataSet.InventoryItemRow result = (DictionaryDataSet.InventoryItemRow)ds.InventoryItem[0];
                return(result);
            }
            return(null);
        }
        /// <summary>
        /// Thêm mới hóa đơn
        /// </summary>
        /// <param name="ds"></param>
        /// <returns></returns>
        public DictionaryDataSet InitSAInvoice(DictionaryDataSet ds)
        {
            var orderRow = ds.Order.FirstOrDefault();

            DictionaryDataSet.SAInvoiceRow masterRow = ds.SAInvoice.NewSAInvoiceRow();
            if (orderRow == null)
            {
                var saRow = ds.SAInvoice.FirstOrDefault();
                masterRow.RefID        = Guid.NewGuid();
                masterRow.RefNo        = saRow.RefNo;
                masterRow.RefDate      = DateTime.Now;
                masterRow.OrderID      = saRow.OrderID;
                masterRow.CustomerID   = saRow.CustomerID;
                masterRow.EmployeeID   = Session.UserLogin.EmployeeID;
                masterRow.CreatedDate  = DateTime.Now;
                masterRow.CreatedBy    = Session.UserLogin.UserName;
                masterRow.ModifiedDate = DateTime.Now;
                masterRow.ModifiedBy   = Session.UserLogin.UserName;
                //var table = new DL.DLTableMapping().GetTableMappingDetailByTableID(saRow., saRow.RefDate);
                //if (table != null)
                //    if (table.Rows.Count > 0)
                //    {
                //        var row = table.Rows[0];
                //        masterRow.JournalMemo = row["TableName"] + " - " + row["AreaName"];
                //    }
                // Gán tổng tiền mua trước
                masterRow.TotalSaleAmount     = 0;
                masterRow.TotalDiscountAmount = 0;

                BLInventoryItem oBLInventoryItem = new BLInventoryItem();
                // Duyệt chi tiết
                foreach (DictionaryDataSet.OrderDetailRow orderDetailRow in ds.OrderDetail)
                {
                    // Tìm xem có dòng nào trùng Mặt hàng thì tăng số lượng thôi
                    DictionaryDataSet.SAInvoiceDetailRow findRow = ds.SAInvoiceDetail.FirstOrDefault((t) => t.ItemID == orderDetailRow.InventoryItemID);
                    if (findRow != null)
                    {
                        findRow.Quantity          += orderDetailRow.Quantity;
                        findRow.SaleAmount        += orderDetailRow.Quantity * findRow.UnitPrice;
                        masterRow.TotalSaleAmount += orderDetailRow.Quantity * findRow.UnitPrice;
                    }
                    // Chưa có thì thêm mới vào hóa đơn
                    else
                    {
                        DictionaryDataSet.SAInvoiceDetailRow detailRow = ds.SAInvoiceDetail.NewSAInvoiceDetailRow();
                        detailRow.RefDetailID = Guid.NewGuid();
                        detailRow.RefID       = masterRow.RefID;
                        detailRow.ItemID      = orderDetailRow.InventoryItemID;
                        detailRow.Quantity    = orderDetailRow.Quantity;
                        var inventory = oBLInventoryItem.GetByID(orderDetailRow.InventoryItemID);
                        if (ds.InventoryItem.FindByInventoryItemID(inventory.InventoryItemID) == null)
                        {
                            ds.InventoryItem.Merge(oBLInventoryItem.GetByID_SAInvoice(orderDetailRow.InventoryItemID));
                        }
                        detailRow.UnitPrice        = inventory != null ? inventory.UnitPrice : 0;
                        detailRow.SaleAmount       = detailRow.Quantity * detailRow.UnitPrice;
                        masterRow.TotalSaleAmount += detailRow.SaleAmount;
                        detailRow.DiscountRate     = 0;
                        detailRow.DiscountAmount   = 0;
                        detailRow.OrderDetailID    = orderDetailRow.OrderDetailID;
                        detailRow.SortOrder        = ds.SAInvoiceDetail.Count + 1;
                        ds.SAInvoiceDetail.Rows.InsertAt(detailRow, ds.SAInvoiceDetail.Rows.Count);
                    }
                }

                masterRow.TotalDiscountAmount   = 0;
                masterRow.ServiceRate           = 0;
                masterRow.ServiceAmount         = masterRow.TotalSaleAmount * masterRow.ServiceRate;
                masterRow.TotalAmount           = masterRow.TotalSaleAmount - masterRow.TotalDiscountAmount + masterRow.ServiceAmount;
                masterRow.VATRate               = 0;
                masterRow.VATAmount             = masterRow.TotalAmount * masterRow.VATRate;
                masterRow.PaymentAmount         = masterRow.TotalAmount + masterRow.VATAmount;
                masterRow.ReceiveAmount         = 0;
                masterRow.ReturnAmount          = 0;
                masterRow.PaymentStatus         = 0;
                masterRow.IsApplyTaxWhenRequire = false;

                ds.SAInvoice.Rows.InsertAt(masterRow, 0);

                return(ds);
            }
            else
            {
                masterRow.RefID        = Guid.NewGuid();
                masterRow.RefNo        = orderRow.OrderNo;
                masterRow.RefDate      = DateTime.Now;
                masterRow.OrderID      = orderRow.OrderID;
                masterRow.CustomerID   = orderRow.CustomerID;
                masterRow.EmployeeID   = Session.UserLogin.EmployeeID;
                masterRow.CreatedDate  = DateTime.Now;
                masterRow.CreatedBy    = Session.UserLogin.UserName;
                masterRow.ModifiedDate = DateTime.Now;
                masterRow.ModifiedBy   = Session.UserLogin.UserName;
                var table = new DL.DLTableMapping().GetTableMappingDetailByTableID(orderRow.TableID, orderRow.OrderDate);
                if (table != null)
                {
                    if (table.Rows.Count > 0)
                    {
                        var row = table.Rows[0];
                        masterRow.JournalMemo = row["TableName"] + " - " + row["AreaName"];
                    }
                }
                // Gán tổng tiền mua trước
                masterRow.TotalSaleAmount     = 0;
                masterRow.TotalDiscountAmount = 0;

                BLInventoryItem oBLInventoryItem = new BLInventoryItem();
                // Duyệt chi tiết
                foreach (DictionaryDataSet.OrderDetailRow orderDetailRow in ds.OrderDetail)
                {
                    // Tìm xem có dòng nào trùng Mặt hàng thì tăng số lượng thôi
                    DictionaryDataSet.SAInvoiceDetailRow findRow = ds.SAInvoiceDetail.FirstOrDefault((t) => t.ItemID == orderDetailRow.InventoryItemID);
                    if (findRow != null)
                    {
                        findRow.Quantity          += orderDetailRow.Quantity;
                        findRow.SaleAmount        += orderDetailRow.Quantity * findRow.UnitPrice;
                        masterRow.TotalSaleAmount += orderDetailRow.Quantity * findRow.UnitPrice;
                    }
                    // Chưa có thì thêm mới vào hóa đơn
                    else
                    {
                        DictionaryDataSet.SAInvoiceDetailRow detailRow = ds.SAInvoiceDetail.NewSAInvoiceDetailRow();
                        detailRow.RefDetailID = Guid.NewGuid();
                        detailRow.RefID       = masterRow.RefID;
                        detailRow.ItemID      = orderDetailRow.InventoryItemID;
                        detailRow.Quantity    = orderDetailRow.Quantity;
                        var inventory = oBLInventoryItem.GetByID(orderDetailRow.InventoryItemID);
                        if (ds.InventoryItem.FindByInventoryItemID(inventory.InventoryItemID) == null)
                        {
                            ds.InventoryItem.Merge(oBLInventoryItem.GetByID_SAInvoice(orderDetailRow.InventoryItemID));
                        }
                        detailRow.UnitPrice        = inventory != null ? inventory.UnitPrice : 0;
                        detailRow.SaleAmount       = detailRow.Quantity * detailRow.UnitPrice;
                        masterRow.TotalSaleAmount += detailRow.SaleAmount;
                        detailRow.DiscountRate     = 0;
                        detailRow.DiscountAmount   = 0;
                        detailRow.OrderDetailID    = orderDetailRow.OrderDetailID;
                        detailRow.SortOrder        = ds.SAInvoiceDetail.Count + 1;
                        ds.SAInvoiceDetail.Rows.InsertAt(detailRow, ds.SAInvoiceDetail.Rows.Count);
                    }
                }

                masterRow.TotalDiscountAmount   = 0;
                masterRow.ServiceRate           = 0;
                masterRow.ServiceAmount         = masterRow.TotalSaleAmount * masterRow.ServiceRate;
                masterRow.TotalAmount           = masterRow.TotalSaleAmount - masterRow.TotalDiscountAmount + masterRow.ServiceAmount;
                masterRow.VATRate               = 0;
                masterRow.VATAmount             = masterRow.TotalAmount * masterRow.VATRate;
                masterRow.PaymentAmount         = masterRow.TotalAmount + masterRow.VATAmount;
                masterRow.ReceiveAmount         = 0;
                masterRow.ReturnAmount          = 0;
                masterRow.PaymentStatus         = 0;
                masterRow.IsApplyTaxWhenRequire = false;

                ds.SAInvoice.Rows.InsertAt(masterRow, 0);

                return(ds);
            }
        }
Example #4
0
 /// <summary>
 /// Cập nhật dữ liệu
 /// </summary>
 /// <param name="ds"></param>
 public bool InsertUpdateOrder(DataRow masterData, DictionaryDataSet ds)
 {
     return(oDL.InsertUpdateDataMasterDetail(masterData, ds.Tables["OrderDetail"]));
 }
Example #5
0
 /// <summary>
 /// Cập nhật dữ liệu
 /// </summary>
 /// <param name="ds"></param>
 public bool InsertUpdate(DictionaryDataSet ds, int positionMaster = 0)
 {
     return(oDL.InsertUpdateDataMasterDetail(ds.Tables[TableMasterName].Rows[positionMaster], ds.Tables[TableDetailName]));
 }