예제 #1
0
        private void Import()
        {
            if (txtPath.HasFile)
            {
                string fn = System.IO.Path.GetFileName(txtPath.PostedFile.FileName);

                if (fn.Contains("_" + Constants.PURCHASE_ORDER_CODE) == false)
                {
                    string stScript = "<Script>";
                    stScript += "window.alert('Please select a VALID Transfer In file to upload.')";
                    stScript += "</Script>";
                    Response.Write(stScript);
                    return;
                }

                string SaveLocation = "/RetailPlus/temp/uploaded_" + fn;

                txtPath.PostedFile.SaveAs(SaveLocation);
                XmlTextReader xmlReader = new XmlTextReader(SaveLocation);
                xmlReader.WhitespaceHandling = WhitespaceHandling.None;

                TransferIn clsTransferIn = new TransferIn();
                clsTransferIn.GetConnection();
                TransferInDetails clsTransferInDetails = new TransferInDetails();

                TransferInItem clsTransferInItem = new TransferInItem(clsTransferIn.Connection, clsTransferIn.Transaction);
                TransferInItemDetails clsTransferInItemDetails;

                Contacts clsContact = new Contacts(clsTransferIn.Connection, clsTransferIn.Transaction);
                ContactDetails clsContactDetails;

                ContactGroups clsContactGroup = new ContactGroups(clsTransferIn.Connection, clsTransferIn.Transaction);
                ContactGroupDetails clsContactGroupDetails;

                Data.Unit clsUnit = new Data.Unit(clsTransferIn.Connection, clsTransferIn.Transaction);
                UnitDetails clsUnitDetails;

                ProductGroup clsProductGroup = new Data.ProductGroup(clsTransferIn.Connection, clsTransferIn.Transaction);
                ProductGroupDetails clsProductGroupDetails;

                ProductSubGroup clsProductSubGroup = new Data.ProductSubGroup(clsTransferIn.Connection, clsTransferIn.Transaction);
                ProductSubGroupDetails clsProductSubGroupDetails;

                Products clsProduct = new Products(clsTransferIn.Connection, clsTransferIn.Transaction);
                ProductDetails clsProductDetails;

                ProductVariations clsProductVariation = new ProductVariations(clsTransferIn.Connection, clsTransferIn.Transaction);
                ProductVariationDetails clsProductVariationDetails;

                Branch clsBranch = new Branch(clsTransferIn.Connection, clsTransferIn.Transaction);
                BranchDetails clsBranchDetails;

                long lngProductID = 0; long lngProductCtr = 0;

                while (xmlReader.Read())
                {
                    switch (xmlReader.NodeType)
                    {
                        case XmlNodeType.Element:

                            if (xmlReader.Name == "TransferInDetails")
                            {
                                clsTransferInDetails.TransferInNo = lnkTransferInNo.Text;
                                clsTransferInDetails.TransferInDate = DateTime.Parse(lblTransferInDate.Text);

                                clsTransferInDetails.SupplierCode = xmlReader.GetAttribute("SupplierCode").ToString();
                                clsTransferInDetails.SupplierContact = xmlReader.GetAttribute("SupplierContact").ToString();
                                clsTransferInDetails.SupplierAddress = xmlReader.GetAttribute("SupplierAddress").ToString();
                                clsTransferInDetails.SupplierTelephoneNo = xmlReader.GetAttribute("SupplierTelephoneNo").ToString();
                                clsTransferInDetails.SupplierModeOfTerms = int.Parse(xmlReader.GetAttribute("SupplierModeOfTerms").ToString());
                                clsTransferInDetails.SupplierTerms = int.Parse(xmlReader.GetAttribute("SupplierTerms").ToString());
                                clsTransferInDetails.SupplierID = clsContact.Details(xmlReader.GetAttribute("SupplierCode").ToString()).ContactID;
                                if (clsTransferInDetails.SupplierID == 0)
                                {
                                    clsContactDetails = new ContactDetails();
                                    clsContactDetails.ContactCode = clsTransferInDetails.SupplierCode;
                                    clsContactDetails.ContactName = xmlReader.GetAttribute("SupplierName").ToString();
                                    clsContactDetails.BusinessName = clsTransferInDetails.SupplierContact;
                                    clsContactDetails.Address = clsTransferInDetails.SupplierAddress;
                                    clsContactDetails.TelephoneNo = clsTransferInDetails.SupplierTelephoneNo;
                                    clsContactDetails.ModeOfTerms = (ModeOfTerms)Enum.Parse(typeof(ModeOfTerms), clsTransferInDetails.SupplierModeOfTerms.ToString());
                                    clsContactDetails.Terms = clsTransferInDetails.SupplierTerms;
                                    clsContactDetails.Remarks = "Added in from Imported TransferIn #";
                                    clsContactDetails.ContactGroupID = int.Parse(Contacts.DEFAULT_SUPPLIER_ID.ToString("d"));
                                    clsContactDetails.DateCreated = DateTime.Now;
                                    clsTransferInDetails.SupplierID = clsContact.Insert(clsContactDetails);
                                }
                                clsTransferInDetails.RequiredDeliveryDate = DateTime.Parse(xmlReader.GetAttribute("RequiredDeliveryDate").ToString());
                                clsTransferInDetails.BranchID = clsBranch.Details(xmlReader.GetAttribute("BranchCode")).BranchID;
                                if (clsTransferInDetails.BranchID == 0)
                                {
                                    clsBranchDetails = new BranchDetails();
                                    clsBranchDetails.BranchCode = xmlReader.GetAttribute("BranchCode");
                                    clsBranchDetails.BranchName = xmlReader.GetAttribute("BranchName");
                                    clsBranchDetails.Address = xmlReader.GetAttribute("BranchAddress");
                                    clsBranchDetails.DBIP = xmlReader.GetAttribute("BranchDBIP");
                                    clsBranchDetails.DBPort = xmlReader.GetAttribute("BranchDBPort");
                                    clsBranchDetails.Remarks = xmlReader.GetAttribute("BranchRemarks");
                                    clsTransferInDetails.BranchID = clsBranch.Insert(clsBranchDetails);
                                }

                                clsTransferInDetails.TransferrerID = long.Parse(xmlReader.GetAttribute("TransferrerID"));
                                clsTransferInDetails.TransferrerName = xmlReader.GetAttribute("TransferrerName");

                                clsTransferInDetails.SubTotal = decimal.Parse(xmlReader.GetAttribute("SubTotal"));
                                clsTransferInDetails.Discount = decimal.Parse(xmlReader.GetAttribute("Discount"));
                                clsTransferInDetails.DiscountApplied = decimal.Parse(xmlReader.GetAttribute("DiscountApplied"));
                                clsTransferInDetails.DiscountType = (DiscountTypes)Enum.Parse(typeof(DiscountTypes), xmlReader.GetAttribute("DiscountType"));
                                clsTransferInDetails.VAT = decimal.Parse(xmlReader.GetAttribute("VAT"));
                                clsTransferInDetails.VatableAmount = decimal.Parse(xmlReader.GetAttribute("VatableAmount"));
                                clsTransferInDetails.EVAT = decimal.Parse(xmlReader.GetAttribute("EVAT"));
                                clsTransferInDetails.EVatableAmount = decimal.Parse(xmlReader.GetAttribute("EVatableAmount"));
                                clsTransferInDetails.LocalTax = decimal.Parse(xmlReader.GetAttribute("LocalTax"));
                                clsTransferInDetails.Freight = decimal.Parse(xmlReader.GetAttribute("Freight"));
                                clsTransferInDetails.Deposit = decimal.Parse(xmlReader.GetAttribute("Deposit"));
                                clsTransferInDetails.UnpaidAmount = decimal.Parse(xmlReader.GetAttribute("UnpaidAmount"));
                                clsTransferInDetails.PaidAmount = decimal.Parse(xmlReader.GetAttribute("PaidAmount"));
                                clsTransferInDetails.TotalItemDiscount = decimal.Parse(xmlReader.GetAttribute("TotalItemDiscount"));
                                clsTransferInDetails.Status = (TransferInStatus)Enum.Parse(typeof(TransferInStatus), xmlReader.GetAttribute("Status"));
                                clsTransferInDetails.Remarks = xmlReader.GetAttribute("Remarks");
                                clsTransferInDetails.SupplierDRNo = xmlReader.GetAttribute("SupplierDRNo");
                                clsTransferInDetails.DeliveryDate = DateTime.Parse(xmlReader.GetAttribute("DeliveryDate"));
                                clsTransferInDetails.CancelledDate = DateTime.Parse(xmlReader.GetAttribute("CancelledDate"));
                                clsTransferInDetails.Remarks = xmlReader.GetAttribute("Remarks");
                                clsTransferInDetails.CancelledRemarks = xmlReader.GetAttribute("CancelledRemarks");
                                clsTransferInDetails.CancelledByID = long.Parse(xmlReader.GetAttribute("CancelledByID"));

                                clsTransferIn.Update(clsTransferInDetails);

                            }
                            else if (xmlReader.Name == "TransferInItem")
                            {
                                clsTransferInItemDetails = new TransferInItemDetails();
                                clsTransferInItemDetails.TransferInID = long.Parse(lblTransferInID.Text);

                                clsTransferInItemDetails.ProductCode = xmlReader.GetAttribute("ProductCode");
                                clsTransferInItemDetails.BarCode = xmlReader.GetAttribute("BarCode");
                                clsTransferInItemDetails.Description = xmlReader.GetAttribute("ProductDesc");
                                clsTransferInItemDetails.ProductSubGroup = xmlReader.GetAttribute("ItemProductSubGroup");
                                clsTransferInItemDetails.ProductGroup = xmlReader.GetAttribute("ItemProductGroup");
                                clsTransferInItemDetails.ProductUnitID = Convert.ToInt32(xmlReader.GetAttribute("ItemProductUnitID"));
                                clsTransferInItemDetails.ProductUnitCode = xmlReader.GetAttribute("ItemProductUnitCode");
                                clsTransferInItemDetails.Quantity = Convert.ToDecimal(xmlReader.GetAttribute("ItemQuantity"));
                                clsTransferInItemDetails.UnitCost = Convert.ToDecimal(xmlReader.GetAttribute("ItemUnitCost"));
                                clsTransferInItemDetails.Discount = Convert.ToDecimal(xmlReader.GetAttribute("ItemDiscount"));
                                clsTransferInItemDetails.DiscountApplied = Convert.ToDecimal(xmlReader.GetAttribute("ItemDiscountApplied"));
                                clsTransferInItemDetails.DiscountType = (DiscountTypes)Enum.Parse(typeof(DiscountTypes), xmlReader.GetAttribute("ItemDiscountType"));
                                clsTransferInItemDetails.Amount = Convert.ToDecimal(xmlReader.GetAttribute("ItemAmount"));
                                clsTransferInItemDetails.IsVatable = Convert.ToBoolean(Convert.ToInt16(xmlReader.GetAttribute("ItemIsVatable")));
                                clsTransferInItemDetails.VatableAmount = Convert.ToDecimal(xmlReader.GetAttribute("ItemVatableAmount"));
                                clsTransferInItemDetails.EVatableAmount = Convert.ToDecimal(xmlReader.GetAttribute("ItemEVatableAmount"));
                                clsTransferInItemDetails.LocalTax = Convert.ToDecimal(xmlReader.GetAttribute("ItemLocalTax"));
                                clsTransferInItemDetails.VAT = Convert.ToDecimal(xmlReader.GetAttribute("ItemVAT"));
                                clsTransferInItemDetails.EVAT = Convert.ToDecimal(xmlReader.GetAttribute("ItemEVAT"));
                                clsTransferInItemDetails.LocalTax = Convert.ToDecimal(xmlReader.GetAttribute("ItemLocalTax"));
                                clsTransferInItemDetails.isVATInclusive = Convert.ToBoolean(Convert.ToInt16(xmlReader.GetAttribute("ItemisVATInclusive")));
                                clsTransferInItemDetails.IsVatable = Convert.ToBoolean(Convert.ToInt16(xmlReader.GetAttribute("ItemIsVatable")));
                                clsTransferInItemDetails.TransferInItemStatus = (TransferInItemStatus)Enum.Parse(typeof(TransferInItemStatus), xmlReader.GetAttribute("ItemTransferInItemStatus"));
                                clsTransferInItemDetails.VariationMatrixID = Convert.ToInt64(xmlReader.GetAttribute("ItemVariationMatrixID"));
                                clsTransferInItemDetails.MatrixDescription = xmlReader.GetAttribute("ItemBaseVariationDescription");
                                clsTransferInItemDetails.ProductGroup = xmlReader.GetAttribute("ProductGroup");
                                clsTransferInItemDetails.ProductSubGroup = xmlReader.GetAttribute("ProductSubGroup");
                                clsTransferInItemDetails.Remarks = xmlReader.GetAttribute("ItemRemarks");
                                clsTransferInItemDetails.SellingPrice = Convert.ToDecimal(xmlReader.GetAttribute("ItemSellingPrice"));
                                clsTransferInItemDetails.SellingVAT = Convert.ToDecimal(xmlReader.GetAttribute("ItemSellingVAT"));
                                clsTransferInItemDetails.SellingEVAT = Convert.ToDecimal(xmlReader.GetAttribute("ItemSellingEVAT"));
                                clsTransferInItemDetails.SellingLocalTax = Convert.ToDecimal(xmlReader.GetAttribute("ItemSellingLocalTax"));
                                clsTransferInItemDetails.OldSellingPrice = Convert.ToDecimal(xmlReader.GetAttribute("ItemOldSellingPrice"));

                                clsTransferInItemDetails.ProductID = clsProduct.Details(clsTransferInItemDetails.BarCode).ProductID;
                                lngProductID = clsTransferInItemDetails.ProductID;
                                if (clsTransferInItemDetails.ProductID == 0)
                                {
                                    clsTransferInItemDetails.ProductID = clsProduct.Details(clsTransferInItemDetails.ProductCode).ProductID;
                                    if (clsTransferInItemDetails.ProductID == 0)
                                    {
                                        //insert new product
                                        clsProductDetails = new ProductDetails();
                                        clsProductDetails.BarCode = clsTransferInItemDetails.BarCode;
                                        clsProductDetails.ProductCode = clsTransferInItemDetails.ProductCode;
                                        clsProductDetails.ProductDesc = clsTransferInItemDetails.Description;
                                        clsProductDetails.ProductGroupCode = xmlReader.GetAttribute("ProductGroupCode");
                                        clsProductDetails.ProductGroupName = xmlReader.GetAttribute("ProductGroupName");
                                        clsProductDetails.ProductSubGroupCode = xmlReader.GetAttribute("ProductSubGroupCode");
                                        clsProductDetails.ProductSubGroupName = xmlReader.GetAttribute("ProductSubGroupName");
                                        clsProductDetails.BaseUnitCode = xmlReader.GetAttribute("BaseUnitCode");
                                        clsProductDetails.BaseUnitName = xmlReader.GetAttribute("BaseUnitName");
                                        clsProductDetails.DateCreated = DateTime.Now;
                                        clsProductDetails.Price = Convert.ToDecimal(xmlReader.GetAttribute("Price"));
                                        clsProductDetails.PurchasePrice = Convert.ToDecimal(xmlReader.GetAttribute("PurchasePrice"));
                                        clsProductDetails.IncludeInSubtotalDiscount = Convert.ToBoolean(xmlReader.GetAttribute("IncludeInSubtotalDiscount"));
                                        clsProductDetails.VAT = Convert.ToDecimal(xmlReader.GetAttribute("VAT"));
                                        clsProductDetails.EVAT = Convert.ToDecimal(xmlReader.GetAttribute("EVAT"));
                                        clsProductDetails.LocalTax = Convert.ToDecimal(xmlReader.GetAttribute("LocalTax"));
                                        clsProductDetails.Quantity = 0;
                                        clsProductDetails.MinThreshold = Convert.ToDecimal(xmlReader.GetAttribute("MinThreshold"));
                                        clsProductDetails.MaxThreshold = Convert.ToDecimal(xmlReader.GetAttribute("MaxThreshold"));
                                        clsProductDetails.ChartOfAccountIDPurchase = int.Parse(xmlReader.GetAttribute("ChartOfAccountIDPurchase"));
                                        clsProductDetails.ChartOfAccountIDSold = int.Parse(xmlReader.GetAttribute("ChartOfAccountIDSold"));
                                        clsProductDetails.ChartOfAccountIDInventory = int.Parse(xmlReader.GetAttribute("ChartOfAccountIDInventory"));
                                        clsProductDetails.ChartOfAccountIDTaxPurchase = int.Parse(xmlReader.GetAttribute("ChartOfAccountIDTaxPurchase"));
                                        clsProductDetails.ChartOfAccountIDTaxSold = int.Parse(xmlReader.GetAttribute("ChartOfAccountIDTaxSold"));
                                        clsProductDetails.IsItemSold = Convert.ToBoolean(xmlReader.GetAttribute("IsItemSold"));
                                        clsProductDetails.WillPrintProductComposition = Convert.ToBoolean(xmlReader.GetAttribute("WillPrintProductComposition"));
                                        clsProductDetails.UpdatedBy = long.Parse(xmlReader.GetAttribute("UpdatedBy"));
                                        clsProductDetails.UpdatedOn = Convert.ToDateTime(xmlReader.GetAttribute("UpdatedOn"));
                                        clsProductDetails.PercentageCommision = decimal.Parse(xmlReader.GetAttribute("PercentageCommision"));
                                        clsProductDetails.QuantityIN = clsProductDetails.Quantity;
                                        clsProductDetails.QuantityOUT = 0;

                                        clsProductDetails.SupplierCode = clsTransferInDetails.SupplierCode;
                                        clsProductDetails.SupplierID = clsContact.Details(clsProductDetails.SupplierCode).ContactID;
                                        if (clsProductDetails.SupplierID == 0)
                                        {
                                            clsContactDetails = new ContactDetails();
                                            clsContactDetails.ContactGroupID = clsContactGroup.Details(int.Parse(ContactGroupCategory.SUPPLIER.ToString("d"))).ContactGroupID;
                                            if (clsContactDetails.ContactGroupID == 0)
                                            {
                                                clsContactGroupDetails = new ContactGroupDetails();
                                                clsContactGroupDetails.ContactGroupCode = xmlReader.GetAttribute("SUP");
                                                clsContactGroupDetails.ContactGroupName = xmlReader.GetAttribute("Default Supplier Group");
                                                clsContactGroupDetails.ContactGroupCategory = ContactGroupCategory.SUPPLIER;
                                                clsContactDetails.ContactGroupID = clsContactGroup.Insert(clsContactGroupDetails);
                                            }

                                            clsContactDetails.ContactCode = clsTransferInDetails.SupplierCode;
                                            clsContactDetails.ContactName = clsTransferInDetails.SupplierContact;

                                            clsContactDetails.ModeOfTerms = (ModeOfTerms)Enum.Parse(typeof(ModeOfTerms), clsTransferInDetails.SupplierModeOfTerms.ToString());
                                            clsContactDetails.Terms = clsTransferInDetails.SupplierTerms;
                                            clsContactDetails.Address = clsTransferInDetails.SupplierAddress;
                                            clsContactDetails.BusinessName = clsTransferInDetails.SupplierContact;
                                            clsContactDetails.TelephoneNo = clsTransferInDetails.SupplierTelephoneNo;
                                            clsContactDetails.Remarks = "Added in XML import";
                                            clsContactDetails.Debit = 0;
                                            clsContactDetails.Credit = 0;
                                            clsContactDetails.IsCreditAllowed = false;
                                            clsContactDetails.CreditLimit = 0;
                                            clsProductDetails.SupplierID = clsContact.Insert(clsContactDetails);
                                        }

                                        clsProductDetails.BaseUnitID = clsUnit.Details(clsProductDetails.BaseUnitCode).UnitID;
                                        if (clsProductDetails.BaseUnitID == 0)
                                        {
                                            clsUnitDetails = new UnitDetails();
                                            clsUnitDetails.UnitCode = clsProductDetails.BaseUnitCode;
                                            clsUnitDetails.UnitName = clsProductDetails.BaseUnitName;
                                            clsProductDetails.BaseUnitID = clsUnit.Insert(clsUnitDetails);
                                        }

                                        clsProductDetails.ProductGroupID = clsProductGroup.Details(clsProductDetails.ProductGroupCode).ProductGroupID;
                                        if (clsProductDetails.ProductGroupID == 0)
                                        {
                                            clsProductGroupDetails = new ProductGroupDetails();
                                            clsProductGroupDetails.ProductGroupCode = clsProductDetails.ProductGroupCode;
                                            clsProductGroupDetails.ProductGroupName = clsProductDetails.ProductGroupName;
                                            clsProductGroupDetails.UnitDetails = new UnitDetails
                                            {
                                                UnitID = clsProductDetails.BaseUnitID
                                            };
                                            clsProductGroupDetails.Price = clsProductDetails.Price;
                                            clsProductGroupDetails.PurchasePrice = clsProductDetails.PurchasePrice;
                                            clsProductGroupDetails.IncludeInSubtotalDiscount = clsProductDetails.IncludeInSubtotalDiscount;
                                            clsProductGroupDetails.VAT = clsProductDetails.VAT;
                                            clsProductGroupDetails.EVAT = clsProductDetails.EVAT;
                                            clsProductGroupDetails.LocalTax = clsProductDetails.LocalTax;
                                            clsProductDetails.ProductGroupID = clsProductGroup.Insert(clsProductGroupDetails);
                                        }

                                        clsProductDetails.ProductSubGroupID = clsProductSubGroup.Details(clsProductDetails.ProductSubGroupCode).ProductSubGroupID;
                                        if (clsProductDetails.ProductSubGroupID == 0)
                                        {
                                            clsProductSubGroupDetails = new ProductSubGroupDetails();
                                            clsProductSubGroupDetails.ProductGroupID = clsProductDetails.ProductGroupID;
                                            clsProductSubGroupDetails.ProductSubGroupCode = clsProductDetails.ProductSubGroupCode;
                                            clsProductSubGroupDetails.ProductSubGroupName = clsProductDetails.ProductSubGroupName;
                                            clsProductSubGroupDetails.BaseUnitID = clsProductDetails.BaseUnitID;
                                            clsProductSubGroupDetails.Price = clsProductDetails.Price;
                                            clsProductSubGroupDetails.PurchasePrice = clsProductDetails.PurchasePrice;
                                            clsProductSubGroupDetails.IncludeInSubtotalDiscount = clsProductDetails.IncludeInSubtotalDiscount;
                                            clsProductSubGroupDetails.VAT = clsProductDetails.VAT;
                                            clsProductSubGroupDetails.EVAT = clsProductDetails.EVAT;
                                            clsProductSubGroupDetails.LocalTax = clsProductDetails.LocalTax;
                                            clsProductDetails.ProductSubGroupID = clsProductSubGroup.Insert(clsProductSubGroupDetails);
                                        }

                                        clsTransferInItemDetails.ProductID = clsProduct.Insert(clsProductDetails);
                                    }
                                    else
                                    {
                                        //product code already exist but not the same barcode
                                        clsProduct.UpdateBarcode(clsTransferInItemDetails.ProductID, clsTransferInItemDetails.BarCode);
                                    }
                                    lngProductID = clsTransferInItemDetails.ProductID;
                                }

                                clsTransferInItem.Insert(clsTransferInItemDetails);

                                clsTransferInDetails = new TransferInDetails();
                                clsTransferInDetails.TransferInID = clsTransferInItemDetails.TransferInID;
                                clsTransferInDetails.DiscountApplied = Convert.ToDecimal(txtTransferInDiscountApplied.Text);
                                clsTransferInDetails.DiscountType = (DiscountTypes)Enum.Parse(typeof(DiscountTypes), cboTransferInDiscountType.SelectedItem.Value);

                                clsTransferInDetails.Discount2Applied = Convert.ToDecimal(txtTransferInDiscount2Applied.Text);
                                clsTransferInDetails.Discount2Type = (DiscountTypes)Enum.Parse(typeof(DiscountTypes), cboTransferInDiscount2Type.SelectedItem.Value);

                                clsTransferInDetails.Discount3Applied = Convert.ToDecimal(txtTransferInDiscount2Applied.Text);
                                clsTransferInDetails.Discount3Type = (DiscountTypes)Enum.Parse(typeof(DiscountTypes), cboTransferInDiscount3Type.SelectedItem.Value);

                                clsTransferIn = new TransferIn(clsTransferInItem.Connection, clsTransferInItem.Transaction);
                                clsTransferIn.UpdateDiscount(clsTransferInItemDetails.TransferInID, clsTransferInDetails.DiscountApplied, clsTransferInDetails.DiscountType, clsTransferInDetails.Discount2Applied, clsTransferInDetails.Discount2Type, clsTransferInDetails.Discount3Applied, clsTransferInDetails.Discount3Type);

                                clsTransferInDetails = clsTransferIn.Details(clsTransferInItemDetails.TransferInID);
                                UpdateFooter(clsTransferInDetails);

                                lngProductCtr++;
                            }
                            else if (xmlReader.Name == "Variation")
                            {
                                if (lngProductID != 0)
                                {
                                    clsProductVariationDetails = new ProductVariationDetails();

                                    clsProductVariationDetails.VariationID = clsProductVariation.Details(lngProductID, xmlReader.GetAttribute("VariationCode")).VariationID;
                                    if (clsProductVariationDetails.VariationID == 0)
                                    {
                                        clsProductVariationDetails.ProductID = lngProductID;
                                        clsProductVariationDetails.VariationCode = xmlReader.GetAttribute("VariationCode");
                                        clsProductVariationDetails.VariationType = xmlReader.GetAttribute("VariationType");

                                        clsProductVariation.Insert(clsProductVariationDetails);
                                    }
                                }
                            }
                            else
                            {
                                //lblError.Text += "<b>" + xmlReader.Name + ":</b>" + xmlReader.Value + "<br />";
                            }
                            break;
                        case XmlNodeType.Text:
                            //lblError.Text += "<b>" + xmlReader.LocalName + ":</b>" + xmlReader.Value + "<br />";
                            break;
                    }
                }
                xmlReader.Close();

                clsTransferIn.CommitAndDispose();
                LoadRecord();
                LoadItems();
            }
            else
            {
                string stScript = "<Script>";
                stScript += "window.alert('Please select Transfer In file to upload.')";
                stScript += "</Script>";
                Response.Write(stScript);
            }
        }
예제 #2
0
		private void SaveRecord()
		{
			TransferInItemDetails clsDetails = new TransferInItemDetails();

			Products clsProducts = new Products();
            ProductDetails clsProductDetails = clsProducts.Details1(Constants.BRANCH_ID_MAIN, Convert.ToInt64(cboProductCode.SelectedItem.Value));
			
			Terminal clsTerminal = new Terminal(clsProducts.Connection, clsProducts.Transaction);
            TerminalDetails clsTerminalDetails = clsTerminal.Details(Int32.Parse(Session["BranchID"].ToString()), Session["TerminalNo"].ToString());
			clsProducts.CommitAndDispose();

            clsDetails.TransferInID = Convert.ToInt64(lblTransferInID.Text);
            clsDetails.ProductID = Convert.ToInt64(cboProductCode.SelectedItem.Value);
            clsDetails.ProductCode = clsProductDetails.ProductCode;
            clsDetails.BarCode = clsProductDetails.BarCode;
            clsDetails.Description = clsProductDetails.ProductDesc;
            clsDetails.ProductUnitID = Convert.ToInt32(cboProductUnit.SelectedItem.Value);
            clsDetails.ProductUnitCode = cboProductUnit.SelectedItem.Text;
            clsDetails.Quantity = Convert.ToDecimal(txtQuantity.Text);
            clsDetails.UnitCost = Convert.ToDecimal(txtPrice.Text);
            clsDetails.Discount = getItemTotalDiscount();
            clsDetails.DiscountApplied = Convert.ToDecimal(txtDiscount.Text);
            if (clsDetails.DiscountApplied == 0)
            {
                clsDetails.DiscountType = DiscountTypes.NotApplicable;
            }
            else
            {
                if (chkInPercent.Checked == true)
                    clsDetails.DiscountType = DiscountTypes.Percentage;
                else
                    clsDetails.DiscountType = DiscountTypes.FixedValue;
            }

            clsDetails.IsVatable = chkIsTaxable.Checked;
            clsDetails.Amount = ComputeItemAmount();

            if (clsDetails.IsVatable)
            {
                clsDetails.VatableAmount = clsDetails.Amount;
                clsDetails.EVatableAmount = clsDetails.Amount;
                clsDetails.LocalTax = clsDetails.Amount;

                if (clsTerminalDetails.IsVATInclusive == false)
                {
                    if (clsDetails.VatableAmount < clsDetails.Discount) clsDetails.VatableAmount = 0;
                    if (clsDetails.EVatableAmount < clsDetails.Discount) clsDetails.EVatableAmount = 0;
                    if (clsDetails.LocalTax < clsDetails.Discount) clsDetails.LocalTax = 0;
                }
                else
                {
                    if (clsDetails.VatableAmount >= clsDetails.Discount) clsDetails.VatableAmount = (clsDetails.VatableAmount) / (1 + (clsTerminalDetails.VAT / 100)); else clsDetails.VatableAmount = 0;
                    if (clsDetails.EVatableAmount >= clsDetails.Discount) clsDetails.EVatableAmount = (clsDetails.EVatableAmount) / (1 + (clsTerminalDetails.VAT / 100)); else clsDetails.EVatableAmount = 0;
                    if (clsDetails.LocalTax >= clsDetails.Discount) clsDetails.LocalTax = (clsDetails.LocalTax) / (1 + (clsTerminalDetails.LocalTax / 100)); else clsDetails.LocalTax = 0;
                }

                clsDetails.VAT = clsDetails.VatableAmount * (clsTerminalDetails.VAT / 100);
                clsDetails.EVAT = clsDetails.EVatableAmount * (clsTerminalDetails.EVAT / 100);
                clsDetails.LocalTax = clsDetails.LocalTax * (clsTerminalDetails.LocalTax / 100);

                //if (!clsTerminalDetails.IsVATInclusive) clsDetails.Amount += (clsDetails.VAT + clsDetails.LocalTax);
                //if (!clsTerminalDetails.EnableEVAT) clsDetails.Amount += clsDetails.EVAT;
            }
            else
            {
                clsDetails.VAT = 0;
                clsDetails.VatableAmount = 0;
                clsDetails.EVAT = 0;
                clsDetails.EVatableAmount = 0;
                clsDetails.LocalTax = 0;
            }

            clsDetails.isVATInclusive = clsTerminalDetails.IsVATInclusive;
            clsDetails.VariationMatrixID = Convert.ToInt64(cboVariation.SelectedItem.Value);
            if (clsDetails.VariationMatrixID != 0)
                clsDetails.MatrixDescription = cboVariation.SelectedItem.Text;
            clsDetails.ProductGroup = clsProductDetails.ProductGroupCode;
            clsDetails.ProductSubGroup = clsProductDetails.ProductSubGroupCode;
            clsDetails.Remarks = txtRemarks.Text;

            // Added jan 1, 2010 4:20PM : for selling information
            clsDetails.SellingPrice = decimal.Parse(txtSellingPrice.Text);
            clsDetails.SellingVAT = decimal.Parse(txtVAT.Text);
            clsDetails.SellingEVAT = decimal.Parse(txtEVAT.Text);
            clsDetails.SellingLocalTax = decimal.Parse(txtLocalTax.Text);
            clsDetails.OldSellingPrice = decimal.Parse(txtOldSellingPrice.Text);

            // Aug 9, 2011 : Lemu
            // For Required Inventory Days
            //clsDetails.RID = long.Parse(txtRID.Text);

            TransferInItem clsTransferInItem = new TransferInItem();
            if (lblTransferInItemID.Text != "0")
            {
                clsDetails.TransferInItemID = Convert.ToInt64(lblTransferInItemID.Text);
                clsTransferInItem.Update(clsDetails);
            }
            else
                clsTransferInItem.Insert(clsDetails);

            TransferInDetails clsTransferInDetails = new TransferInDetails();
            clsTransferInDetails.TransferInID = clsDetails.TransferInID;
            clsTransferInDetails.DiscountApplied = Convert.ToDecimal(txtTransferInDiscountApplied.Text);
            clsTransferInDetails.DiscountType = (DiscountTypes)Enum.Parse(typeof(DiscountTypes), cboTransferInDiscountType.SelectedItem.Value);

            clsTransferInDetails.Discount2Applied = Convert.ToDecimal(txtTransferInDiscount2Applied.Text);
            clsTransferInDetails.Discount2Type = (DiscountTypes)Enum.Parse(typeof(DiscountTypes), cboTransferInDiscount2Type.SelectedItem.Value);

            clsTransferInDetails.Discount3Applied = Convert.ToDecimal(txtTransferInDiscount3Applied.Text);
            clsTransferInDetails.Discount3Type = (DiscountTypes)Enum.Parse(typeof(DiscountTypes), cboTransferInDiscount3Type.SelectedItem.Value);

            TransferIn clsTransferIn = new TransferIn(clsTransferInItem.Connection, clsTransferInItem.Transaction);
            clsTransferIn.UpdateDiscount(clsDetails.TransferInID, clsTransferInDetails.DiscountApplied, clsTransferInDetails.DiscountType, clsTransferInDetails.Discount2Applied, clsTransferInDetails.Discount2Type, clsTransferInDetails.Discount3Applied, clsTransferInDetails.Discount3Type);

            clsTransferInDetails = clsTransferIn.Details(clsDetails.TransferInID);
            clsTransferInItem.CommitAndDispose();

            UpdateFooter(clsTransferInDetails);
		}
예제 #3
0
        public void GenerateItemsForReorder(Int32 BranchID, string TerminalNo, long TransferInID)
        {
            try
            {
                base.GetConnection();

                Terminal clsTerminal = new Terminal(base.Connection, base.Transaction);
                TerminalDetails clsTerminalDetails = clsTerminal.Details(BranchID, TerminalNo);

                TransferInDetails clsTransferInDetails = Details(TransferInID);

                Products clsProduct = new Products(base.Connection, base.Transaction);
                System.Data.DataTable dt = clsProduct.ForReorder(clsTransferInDetails.SupplierID);

                TransferInItem clsTransferInItem = new TransferInItem(base.Connection, base.Transaction);
                ProductVariationsMatrix clsProductVariationsMatrix = new ProductVariationsMatrix(base.Connection, base.Transaction);

                foreach (System.Data.DataRow dr in dt.Rows)
                {
                    TransferInItemDetails clsDetails = new TransferInItemDetails();

                    clsDetails.TransferInID = TransferInID;
                    clsDetails.ProductID = Convert.ToInt64(dr["ProductID"].ToString());
                    clsDetails.ProductCode = dr["ProductCode"].ToString();
                    clsDetails.BarCode = dr["BarCode"].ToString();
                    clsDetails.Description = dr["ProductDesc"].ToString();
                    clsDetails.ProductGroup = dr["ProductGroupCode"].ToString();
                    clsDetails.ProductSubGroup = dr["ProductSubGroupCode"].ToString();
                    clsDetails.ProductUnitID = Convert.ToInt32(dr["UnitID"].ToString());
                    clsDetails.ProductUnitCode = dr["UnitName"].ToString();
                    clsDetails.Quantity = Convert.ToDecimal(dr["ReorderQty"].ToString());
                    clsDetails.UnitCost = Convert.ToDecimal(dr["Price"].ToString());
                    clsDetails.Discount = 0;
                    clsDetails.DiscountApplied = 0;
                    clsDetails.DiscountType = DiscountTypes.Percentage;
                    clsDetails.Remarks = "added using auto generation";

                    decimal amount = clsDetails.Quantity * clsDetails.UnitCost;

                    if (Convert.ToDecimal(dr["VAT"]) > 0)
                    {
                        clsDetails.VatableAmount = amount;
                        clsDetails.EVatableAmount = amount;
                        clsDetails.LocalTax = amount;

                        clsDetails.VAT = clsDetails.VatableAmount * (clsTerminalDetails.VAT / 100);
                        clsDetails.EVAT = clsDetails.EVatableAmount * (clsTerminalDetails.EVAT / 100);
                        clsDetails.LocalTax = clsDetails.LocalTax * (clsTerminalDetails.LocalTax / 100);
                        clsDetails.IsVatable = true;
                    }
                    else
                    {
                        clsDetails.VAT = 0;
                        clsDetails.VatableAmount = 0;
                        clsDetails.EVAT = 0;
                        clsDetails.EVatableAmount = 0;
                        clsDetails.LocalTax = 0;
                        clsDetails.IsVatable = false;
                    }
                    clsDetails.Amount = amount + clsDetails.VAT;

                    System.Data.DataTable dtmatrix = clsProductVariationsMatrix.ForReorder(clsDetails.ProductID, clsTransferInDetails.SupplierID);
                    if (dtmatrix.Rows.Count > 0)
                        foreach (System.Data.DataRow drmatrix in dtmatrix.Rows)
                        {
                            amount = clsDetails.Quantity * clsDetails.UnitCost;

                            clsDetails.ProductUnitID = Convert.ToInt32(drmatrix["UnitID"]);
                            clsDetails.ProductUnitCode = drmatrix["UnitName"].ToString();
                            clsDetails.Quantity = Convert.ToDecimal(drmatrix["ReorderQty"]);
                            clsDetails.UnitCost = Convert.ToDecimal(drmatrix["Price"]);

                            if (Convert.ToDecimal(drmatrix["VAT"]) > 0)
                            {
                                clsDetails.VatableAmount = amount;
                                clsDetails.EVatableAmount = amount;
                                clsDetails.LocalTax = amount;

                                clsDetails.VAT = clsDetails.VatableAmount * (clsTerminalDetails.VAT / 100);
                                clsDetails.EVAT = clsDetails.EVatableAmount * (clsTerminalDetails.EVAT / 100);
                                clsDetails.LocalTax = clsDetails.LocalTax * (clsTerminalDetails.LocalTax / 100);
                                clsDetails.IsVatable = true;
                            }
                            else
                            {
                                clsDetails.VAT = 0;
                                clsDetails.VatableAmount = 0;
                                clsDetails.EVAT = 0;
                                clsDetails.EVatableAmount = 0;
                                clsDetails.LocalTax = 0;
                                clsDetails.IsVatable = false;
                            }
                            clsDetails.Amount = amount + clsDetails.VAT;

                            clsDetails.VariationMatrixID = Convert.ToInt64(drmatrix["MatrixID"]);
                            clsDetails.MatrixDescription = drmatrix["VariationDesc"].ToString();
                            clsTransferInItem.Insert(clsDetails);
                        }
                    else
                    {
                        clsDetails.VariationMatrixID = 0;
                        clsDetails.MatrixDescription = string.Empty;
                        clsTransferInItem.Insert(clsDetails);
                    }

                }
            }

            catch (Exception ex)
            {
                throw base.ThrowException(ex);
            }
        }